From patchwork Thu Nov 7 07:37:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13865961 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.11]) (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 9D911194AD5 for ; Thu, 7 Nov 2024 07:37:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965061; cv=none; b=WXL7GzcujouFpSC4BkQq6VTMkw/K9zkwIRBDFOjtvMWhmdE+9hihHqJAR2MfmiU/x2klmL2n7EJLp8fF733RhpATQ8FYFlroTR+nVKxDp6h1gH9SQYf+tqQxP9NJ+FGT7hem/a2P7PduUsPAjH97nWcWZvvk6N+i10/yuJ+acSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965061; c=relaxed/simple; bh=gXvuCCyfm17JLJyqM7NjWakoDhd0RMGAQTY8yxwGmZk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=pHs7p4zHL0GeTLY0/l9/cxYx42cG250pwzg05E/xLAMib8QJQg0tkQMExuGbqByR4bwg4QyKfToxYHQsaIiFqxh1M0c57jQCFHFY78eRYTFkYLqe+JW9XJ6ztm05xxwOJzr0vt36LlmNN0raYu/S7gy6CceEJR9Puf8W2kaSW1k= 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=F64eJqn+; arc=none smtp.client-ip=192.198.163.11 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="F64eJqn+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730965060; x=1762501060; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=gXvuCCyfm17JLJyqM7NjWakoDhd0RMGAQTY8yxwGmZk=; b=F64eJqn+RcCmttFizrVekQ3UaF9zs7cpJFiTcR10fmivI9vYH8p3dlbk NCZ5VQBpMlLKPEzwDzgd0pRpBg8Xiixrv9dM1o0ggv/rCgx52pwpyEGGP IezjVK1yWa4lZ+/fUiwuwvN71HUmS5+Vjn4ubJr1/jIKWToq3pkw0aIqB fqjGPfRDgX4Rd6L0aIPq6gqPGO4/y3oDMh1D83MI9X6rEj8jNRQMT1MPf VW5muROfFkE6/r0yNUCpkkb321ZqhO0PlvXvJegOtV0qfa6YgN3AuIo5v +4hXWGQ2/xmdWY9cCsP0gVqOFjKtIySC9h9GY29TnUBzLu/fq+YQl9+gy Q==; X-CSE-ConnectionGUID: OlqKnuhcTMiCptzJgoetag== X-CSE-MsgGUID: dlaDEL+VS8WAchzUfVPdwg== X-IronPort-AV: E=McAfee;i="6700,10204,11248"; a="41390543" X-IronPort-AV: E=Sophos;i="6.11,265,1725346800"; d="scan'208";a="41390543" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:22 -0800 X-CSE-ConnectionGUID: PO0lNcpYTa+cPUELzflAQg== X-CSE-MsgGUID: cVqHe0wKQwi68sy1aJ8WBA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,265,1725346800"; d="scan'208";a="85155136" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.83.36]) by fmviesa009-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:21 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v3 1/3] usb: misc: ljca: move usb_autopm_put_interface() after wait for response Date: Thu, 7 Nov 2024 08:37:16 +0100 Message-Id: <20241107073718.405208-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 Acked-by: Sakari Ailus Signed-off-by: Stanislaw Gruszka --- v2: fix handing error of usb_autopm_get_interface(), add R-b, T-b tags from Hans v3: add A-b tag from Sakari 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 Thu Nov 7 07:37:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13865959 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 1B1A61993B5 for ; Thu, 7 Nov 2024 07:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965048; cv=none; b=fdNe2CSK7N3Ex0jDjFQm4LULCYEEQx5lbQWjUGO9YCkWSIld7TCWQhEu7sQHjvGlMtKzOrhegemtN37s57YRHlehHlRaLBDStyxH+4zBAcckMw/NPGyN1RHGFqaLFMZJhry1N/cyF82ckZtJ52OWNsS5buvJYld32bgKXLKuMyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965048; c=relaxed/simple; bh=zLJkrERlnm3UH2W5JevIYMtRjMm03F4UqbP7LYv5JPM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZTyZ52lMIF2dp43lD7jMRNX1Cu4r9ilzU+cyVYDiUUiXDEyUFFjGdWp9FVlNiJ9Xm2dTWpBNsKpc2GWDHujXHLkN3Z6i4g3sX+P91WfY+cwonGkXRmPRBx8BXeaZ6C4Du13Z0qaWtBCUnvdLcj5rCp91caQoNlIj9cNnyIOkJJ8= 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=Qjx/dnEW; arc=none smtp.client-ip=198.175.65.15 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="Qjx/dnEW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730965047; x=1762501047; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zLJkrERlnm3UH2W5JevIYMtRjMm03F4UqbP7LYv5JPM=; b=Qjx/dnEWeoikHkg2lvM1IXYyKkZVkyVsCnSYJoP2yStN8UwAPnV7qXCX eQ/oWId1Og3J2TBDt9Xk7e2BlwFrSiYd1IMySb4OpAtRl5ZoUk6d7wgJ/ fgHQ0otsum3Sh//ZrEjWC4NBsz9it8AoxXmWNoqO0aiY17bZLvdC3i3c1 Qylq1eXItz8U6bY/U1hggLuWxKLbxUfL3GCeDHCITwlGNb8agXhLft6be kVplWWcALfZ0Il6KXetmbuGKvKMoJ5DUPIClqxbJMZgq8XFpy/wwQZD99 MXtSYMZil3VFxzVUyWCW9hHCitLSMHT84TsrxlA3dcoaBzuLHaInHtXUu w==; X-CSE-ConnectionGUID: 74UYpB6bRbOfEqqKk3LZPA== X-CSE-MsgGUID: I6umDBXiRBejTMxO/3+1Ag== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="34490727" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="34490727" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:26 -0800 X-CSE-ConnectionGUID: 4IO9WX7fQoOB9EwkszwtKQ== X-CSE-MsgGUID: ums8omIjSD6YZDBI6zNTsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,265,1725346800"; d="scan'208";a="122477427" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.83.36]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:25 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v3 2/3] usb: misc: ljca: set small runtime autosuspend delay Date: Thu, 7 Nov 2024 08:37:17 +0100 Message-Id: <20241107073718.405208-2-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107073718.405208-1-stanislaw.gruszka@linux.intel.com> References: <20241107073718.405208-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 Acked-by: Sakari Ailus Signed-off-by: Stanislaw Gruszka --- v2: add R-b, T-b tags from Hans v3: add A-b tag from Sakari 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 Thu Nov 7 07:37:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13865960 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 7DE6C19F120 for ; Thu, 7 Nov 2024 07:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965051; cv=none; b=jte3qqkF2RxjN5/9fqCQ6g0LHpBOWX18gRvPvSeNwQFMI8AfXarP3858JTF4hfpHt1O+u8fHOabijBgAZjKOcDJQa/yZ/C/ZJTodJZSPvYfLMWbFiUA7aNykeSRdeniYJdQLKrQImWOudEeHEykccCcFi6Ei3xLC0Pm4AtXYBfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730965051; c=relaxed/simple; bh=kGZmf33Z4DffRLkdoRhuakHaBHAsP1JaSugPYaX8aAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pmgdUEsgOXMcnEViOmDAIEHsa/+0o2pcua/FE68LN7v0wAl2LUHwLGcCzLi4crkjDUr7zf9LyOBcxwoMifDYpX0ddZ3AG2UHAD0PrLORnmQIPxw2l1gtwuEaGNhPqwkYCtX+SsW8BHVHpFzXt+CIcQfXBNgCkLY2WWEp/fh6XwA= 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=YHKJI4dK; arc=none smtp.client-ip=198.175.65.15 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="YHKJI4dK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730965050; x=1762501050; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kGZmf33Z4DffRLkdoRhuakHaBHAsP1JaSugPYaX8aAU=; b=YHKJI4dKvI7xU8dhD17rg1PrN1AbhvMPwYJhkVK+3T1Ias5wHRI6EAFJ ws6ru/gb3CN9UHWhZ8+mJVDuEcvr9VT4qsCjUlJnuasYbpKb5gTuxnlm1 vpM8YRhN6L6E2yIzF+Jub8rh+ES2zANKh93wR72a6he0SY0wHcJKRMFiO 1sYqyKae9hJmONkTK+vmc/4UF0jB21m1VkEOWXyNnGWcNI3PsDpOpOuZe U5t79phNSGz3ERvenIoeqRiheTpoOc2rjqcgryVlgYnDABGoTwtPYlNyW BgfnzWD3riFajFinlPj88JOqyVjSXOsLzSOgDTo2W8l7FAfaqe4sKdBgs g==; X-CSE-ConnectionGUID: YE3HKaV5QNOxmn53k7GQ1g== X-CSE-MsgGUID: t8+xBacfRDmWEexR6c9XBw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="34490733" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="34490733" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:30 -0800 X-CSE-ConnectionGUID: n46/zdrFQlqLYxYk6oME0w== X-CSE-MsgGUID: baK308H9QvGwGVd9auB+3A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,265,1725346800"; d="scan'208";a="122477435" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.245.83.36]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 23:37:28 -0800 From: Stanislaw Gruszka To: linux-usb@vger.kernel.org Cc: Wentong Wu , Sakari Ailus Subject: [PATCH v3 3/3] usb: misc: ljca: print firmware version Date: Thu, 7 Nov 2024 08:37:18 +0100 Message-Id: <20241107073718.405208-3-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241107073718.405208-1-stanislaw.gruszka@linux.intel.com> References: <20241107073718.405208-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 --- v2: 80-chars line wrap v3: use dev_dbg for printing the firmware version 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..9a44acc48898 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_dbg(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