From patchwork Wed Nov 6 12:34:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13864702 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF1291DFD90 for ; Wed, 6 Nov 2024 12:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896484; cv=none; b=IT9Ab55FKL4LZmKu4gOSPbFXWOj1kXh6CnD+08YsPhykgxMhDvi3YIThb8O4F2YPzqD1o0xzH5b/P6wqarEb/k+XW1nA79dI1Rhu041GzRX1DcrcuO7WFc9gIQ+hyDmvv3b1lVv6NcHMLqFOPhUdkXJMKbROP6pJlhNv1PF4UqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896484; c=relaxed/simple; bh=Wj8ynEqftScmjq5jRn5C6iWEcFuZteoFPDg+ntmxLoU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=mCQN0ShwGWwrg0iMlIFFuL4H6MQldGT441+jXPCmb95H5597xxneR8/fW8xahnnRRvC6FUY/TeEtWUCYx51pkgpqwkTZRVfcAxPQd1sDI77Ls943Y/cO/oXiSsjXS8Go6B6jva1LCItW4wQhXnHUaDg3b79+CZeFKnaHu9TCQ7I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=JGXIhO3V; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="JGXIhO3V" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730896483; x=1762432483; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Wj8ynEqftScmjq5jRn5C6iWEcFuZteoFPDg+ntmxLoU=; b=JGXIhO3VsvO8GYQvqLprqkAh0x7oKrruaWV0/LRIGC6xgFSJ5892tdi/ UJ/gRHfH73taiHiORk2WY7UFSXs3F17zqq7nyrNAxg2m+lwR4nHx7Bm0z SMq7y5ljlUjfr16T5fWAAC0gbX8xkLP5ZGH0v/SapqykfeAzA57o2F+OQ ekPdlNuNTRn61MG/fH52wjJKmwvVVeFTST2PUd+7F4KDs1mjv+pjHqD3A 8nXMUxBJwmXdegjespoHZcNb+A30ghSjJYjYn5PyY8Vh3OFA3gINHVAif oiaddhuKaqSENgzpp+1x1pfmNpGRLR0sePBciJoCNHbBSMKe1mhFwrnWn Q==; X-CSE-ConnectionGUID: 7PGtWZCQTfmtucr92DLG0Q== X-CSE-MsgGUID: v56Y/TFfREKariOMMkOtWA== X-IronPort-AV: E=McAfee;i="6700,10204,11248"; a="42071818" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42071818" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:42 -0800 X-CSE-ConnectionGUID: JHMH4+JJS0WbyhQCSLRPZw== X-CSE-MsgGUID: IBhOQy7zQX+c3hqzLSlJtg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84061815" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.97.183]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:41 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v2 1/3] usb: misc: ljca: move usb_autopm_put_interface() after wait for response Date: Wed, 6 Nov 2024 13:34:36 +0100 Message-Id: <20241106123438.337117-1-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Do not mark interface as ready to suspend when we are still waiting for response messages from the device. Fixes: acd6199f195d ("usb: Add support for Intel LJCA device") Cc: stable@vger.kernel.org Reviewed-by: Hans de Goede Tested-by: Hans de Goede # ThinkPad X1 Yoga Gen 8, ov2740 Signed-off-by: Stanislaw Gruszka Acked-by: Sakari Ailus --- drivers/usb/misc/usb-ljca.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c index 01ceafc4ab78..8056c65e4548 100644 --- a/drivers/usb/misc/usb-ljca.c +++ b/drivers/usb/misc/usb-ljca.c @@ -332,14 +332,11 @@ static int ljca_send(struct ljca_adapter *adap, u8 type, u8 cmd, ret = usb_bulk_msg(adap->usb_dev, adap->tx_pipe, header, msg_len, &transferred, LJCA_WRITE_TIMEOUT_MS); - - usb_autopm_put_interface(adap->intf); - if (ret < 0) - goto out; + goto out_put; if (transferred != msg_len) { ret = -EIO; - goto out; + goto out_put; } if (ack) { @@ -347,11 +344,14 @@ static int ljca_send(struct ljca_adapter *adap, u8 type, u8 cmd, timeout); if (!ret) { ret = -ETIMEDOUT; - goto out; + goto out_put; } } ret = adap->actual_length; +out_put: + usb_autopm_put_interface(adap->intf); + out: spin_lock_irqsave(&adap->lock, flags); adap->ex_buf = NULL; From patchwork Wed Nov 6 12:34:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13864703 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 317A81DFE35 for ; Wed, 6 Nov 2024 12:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896490; cv=none; b=t/KU43EZi5kSLRC66ikhGmdbBITrQ09/R2AD1ASgJcoDsriyukFoFZC9TrcojrWXrRMUmuKxpX0HoFWBGSVGAtxgSlG4gyi+3buuOAuhPqIaBhpx98Z+STd58tWOwINBocKlkqUJAGdVSySw1aW7ogfh+3b0WjgAdrY+DK66MFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896490; c=relaxed/simple; bh=VR8bHnlb53VRD6tqb0PEvNWVYdoYbrkwHHw0yTxMb6k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XyGfq7V3vlnPHahfYLQK04zxRX7Wp6XHjqmNZ82o30JKHKkVku3ytuS3ztuV8FpLSpkVyvClLKlj4h0Ym6fF0pP0arflHe+pZUukkX7D9gVONM12IFvjg/fGQhh8Bw4i41aXpSUJE6vnZcUOUrd6ir6x0/gqHy0kABPZhim36zI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=VoN+qKU4; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="VoN+qKU4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730896488; x=1762432488; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VR8bHnlb53VRD6tqb0PEvNWVYdoYbrkwHHw0yTxMb6k=; b=VoN+qKU4mka4jyTxFOjqgs7p7Dmuz4UmqYHY6X2lltS99Za3XqvMupux JGN0fG/YVDZN7Efi81XCYaglIAK6aH/0AEU+2G76ezoqE+pGvtlUTFjZO COcKARJ6CWMGOJ/2JyXPOLbmaYfW0TpdcAuw2oHFVSkQsFG1h3sGdQdt0 3e3667HPpTBLpu2VIQl4Ryg/EGbocw3Nx7KJt5B0KDHVY9HeNH2DGgBD9 JfbiXn0JAB/7HpvT1tbsbQzf/8WyDu9uG6hcbELrvkhlORIZmaawQxlne UlhXY/LeYq6fm0ly2Nz5vfEmNyEQKcdwxeEYfsdTztUuvherrSqiJgUEE g==; X-CSE-ConnectionGUID: 2/KOR4OeTDK5iJzdgwe1HA== X-CSE-MsgGUID: Neq34McbTXOZk0S22V5t9g== X-IronPort-AV: E=McAfee;i="6700,10204,11248"; a="42071831" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42071831" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:46 -0800 X-CSE-ConnectionGUID: bkKLVYEJSg+t/0cC0a0cnw== X-CSE-MsgGUID: m7rxneHTTo+eM0D63SGurA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84061827" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.97.183]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:44 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v2 2/3] usb: misc: ljca: set small runtime autosuspend delay Date: Wed, 6 Nov 2024 13:34:37 +0100 Message-Id: <20241106123438.337117-2-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106123438.337117-1-stanislaw.gruszka@linux.intel.com> References: <20241106123438.337117-1-stanislaw.gruszka@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On some Lenovo platforms, the patch workarounds problems with ov2740 sensor initialization, which manifest themself like below: [ 4.540476] ov2740 i2c-INT3474:01: error -EIO: failed to find sensor [ 4.542066] ov2740 i2c-INT3474:01: probe with driver ov2740 failed with error -5 or [ 7.742633] ov2740 i2c-INT3474:01: chip id mismatch: 2740 != 0 [ 7.742638] ov2740 i2c-INT3474:01: error -ENXIO: failed to find sensor and also by random failures of video stream start. Issue can be reproduced by this script: n=0 k=0 while [ $n -lt 50 ] ; do sudo modprobe -r ov2740 sleep `expr $RANDOM % 5` sudo modprobe ov2740 if media-ctl -p | grep -q ov2740 ; then let k++ fi let n++ done echo Success rate $k/$n Without the patch, success rate is approximately 15 or 50 tries. With the patch it does not fail. This problem is some hardware or firmware malfunction, that can not be easy debug and fix. While setting small autosuspend delay is not perfect workaround as user can configure it to any value, it will prevent the failures by default. Additionally setting small autosuspend delay should have positive effect on power consumption as for most ljca workloads device is used for just a few milliseconds flowed by long periods of at least 100ms of inactivity (usually more). Fixes: acd6199f195d ("usb: Add support for Intel LJCA device") Cc: stable@vger.kernel.org Reviewed-by: Hans de Goede Tested-by: Hans de Goede # ThinkPad X1 Yoga Gen 8, ov2740 Signed-off-by: Stanislaw Gruszka Acked-by: Sakari Ailus --- drivers/usb/misc/usb-ljca.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c index 8056c65e4548..d9c21f783055 100644 --- a/drivers/usb/misc/usb-ljca.c +++ b/drivers/usb/misc/usb-ljca.c @@ -811,6 +811,14 @@ static int ljca_probe(struct usb_interface *interface, if (ret) goto err_free; + /* + * This works around problems with ov2740 initialization on some + * Lenovo platforms. The autosuspend delay, has to be smaller than + * the delay after setting the reset_gpio line in ov2740_resume(). + * Otherwise the sensor randomly fails to initialize. + */ + pm_runtime_set_autosuspend_delay(&usb_dev->dev, 10); + usb_enable_autosuspend(usb_dev); return 0; From patchwork Wed Nov 6 12:34:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13864704 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5C2C1E00B1 for ; Wed, 6 Nov 2024 12:34:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896491; cv=none; b=NvIWYbvYecTLtrYXYm2oXKRiCLaltA/D5a7dAbjCYw14U+JjxV+3fr5J8YbIVox8xTuMgKTflCYYHORLtAUXv1oPvAXxHYOz9SwzyEbPW/PaDFKRJw1e/MLPtvJKXf5Sv1u8ASdMWnIya7XuFgnotiEkKuwSpFra4RRm4/tTQTY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730896491; c=relaxed/simple; bh=ufdTnFBLz28bhLVxNkqtpDIXx6I/eqxQe0s9Vzy7oSQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ifhSjFi3Aa7dsEjS3Mp68qkqqtSEfsZWoI92s8lbUkkrMjnKYMMR2Y25lMz1vtTqWJhl6FJn8fDlON9ERRqfnttCIV8CwNhKSvPtu/5OR1Bvzm6Gesmi9tqy070XITwP++dtc2TS9jEJDLyj0YHFTnZYsB3UOzZgbolriSZagXI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=GCXvHF/W; arc=none smtp.client-ip=192.198.163.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="GCXvHF/W" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730896490; x=1762432490; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ufdTnFBLz28bhLVxNkqtpDIXx6I/eqxQe0s9Vzy7oSQ=; b=GCXvHF/WfuYrCSFWou8gM96ydMtLZ9tWhnq+JBjWsNI9wOIAoAYS6Zjn oLf1AVkWmQ+IKnWOOA57zNNp9eo1ouNTx2cC2nk5AN21HGPT6kuOAygdD k3pmDHc16lqljFIayv7OhtQoLbAUVUFuMBYtLOlQPLY66kL4MixYDIwev g0RI7jaeKILuA8QJi1U0NG3RG6njVgayIJoEf16+Ped8jt6sSuzJgYLN9 swydN9MZ2hkjoNJqlGejWBIE6SYC1H/6p5v1YWK41+ucUo/4UU03SYor0 FybuhuKKjVOWUsYM30J8fT2UITq0cP+eoxYnsetvJR2K/aw3mr7mQvPdB A==; X-CSE-ConnectionGUID: +IAoBrMeQUSXKKVxj7SEhw== X-CSE-MsgGUID: ahPDXwVjSoC2bB7BqSZZuQ== X-IronPort-AV: E=McAfee;i="6700,10204,11248"; a="42071832" X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="42071832" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:49 -0800 X-CSE-ConnectionGUID: kGEjZbhKTy++0rMgM2Vqgg== X-CSE-MsgGUID: AyxAEU7JSpWk6xDhGour6g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,262,1725346800"; d="scan'208";a="84061839" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.97.183]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 04:34:48 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v2 3/3] usb: misc: ljca: print firmware version Date: Wed, 6 Nov 2024 13:34:38 +0100 Message-Id: <20241106123438.337117-3-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106123438.337117-1-stanislaw.gruszka@linux.intel.com> References: <20241106123438.337117-1-stanislaw.gruszka@linux.intel.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For diagnostics purposes read firmware version from device and print it to dmesg during initialization. Reviewed-by: Hans de Goede Tested-by: Hans de Goede # ThinkPad X1 Yoga Gen 8, ov2740 Signed-off-by: Stanislaw Gruszka --- drivers/usb/misc/usb-ljca.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c index d9c21f783055..e698a1075a40 100644 --- a/drivers/usb/misc/usb-ljca.c +++ b/drivers/usb/misc/usb-ljca.c @@ -43,6 +43,7 @@ enum ljca_client_type { /* MNG client commands */ enum ljca_mng_cmd { + LJCA_MNG_GET_VERSION = 1, LJCA_MNG_RESET = 2, LJCA_MNG_ENUM_GPIO = 4, LJCA_MNG_ENUM_I2C = 5, @@ -68,6 +69,13 @@ struct ljca_msg { u8 data[] __counted_by(len); } __packed; +struct ljca_fw_version { + u8 major; + u8 minor; + __le16 patch; + __le16 build; +} __packed; + struct ljca_i2c_ctr_info { u8 id; u8 capacity; @@ -695,6 +703,25 @@ static int ljca_reset_handshake(struct ljca_adapter *adap) return 0; } +static void ljca_print_fw_version(struct ljca_adapter *adap) +{ + struct ljca_fw_version version = {}; + int ret; + + ret = ljca_send(adap, LJCA_CLIENT_MNG, LJCA_MNG_GET_VERSION, NULL, 0, + (u8 *)&version, sizeof(version), true, + LJCA_WRITE_ACK_TIMEOUT_MS); + + if (ret != sizeof(version)) { + dev_err(adap->dev, "Get version failed, ret: %d\n", ret); + return; + } + + dev_info(adap->dev, "Firmware version: %d.%d.%d.%d\n", + version.major, version.minor, + le16_to_cpu(version.patch), le16_to_cpu(version.build)); +} + static int ljca_enumerate_clients(struct ljca_adapter *adap) { struct ljca_client *client, *next; @@ -811,6 +838,8 @@ static int ljca_probe(struct usb_interface *interface, if (ret) goto err_free; + ljca_print_fw_version(adap); + /* * This works around problems with ov2740 initialization on some * Lenovo platforms. The autosuspend delay, has to be smaller than