From patchwork Tue Nov 12 07:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13871832 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (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 7CC171990AF for ; Tue, 12 Nov 2024 07:55:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398121; cv=none; b=YcecqL1ddLUZHlKRjVXkgqR88w6+emMkRuV4pprZb6z/h0gjBqO3GxdqFp14PUzXMk/Gj/RZx31tINdMZ18CtK2wBS7WIHyDcdLhhnAj6r67g/ZpptEByogbhpbysf3PVcPnOCJNEMWpcVwbFh7Lqid+fQVIMqT5gbCLqPXtjgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398121; c=relaxed/simple; bh=BlH+9tn2R1y+wkh7a/e0MgzMOWgQlmCJcSO5ZHAmeKM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=AR1oG8ckdx04UWDVvlFXxPRVWxkKa8FEZtiucP/Lbkj6l+2IYCVc5n5Yy+Ij6AOAXsH8JSY44zr3IoNeKT7JxSEPKTEEGbOHbVAupfW/a/fq3JhOp1naImkGNYXXxgwvR0sT3f/A52Dnd39JnqC5QUdhOgHOZmsqSpFraGSUf3o= 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=QLzFJdR9; arc=none smtp.client-ip=198.175.65.14 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="QLzFJdR9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731398120; x=1762934120; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BlH+9tn2R1y+wkh7a/e0MgzMOWgQlmCJcSO5ZHAmeKM=; b=QLzFJdR9FLULnzMdtlRXss9Omzp1hO6BiiXmAxZA1uy5LJF02SLXRFUr hB21B4lBavmnuCqcohUbY6mvGOUwLJiT71Cn4N7Y1eL7YtA53HyMEvMjQ MQBG35PitGimYRxt/aLaF2e1w/QIIFa/7cg7ymgCbogwZG73jIc4nBRl/ vo6QKWKIlxCdYRsCB18fQWxnPMT/Knbzu91pmJM4u84FCqF9KvLwxfXgi vSGU340QL5KV0EvVuu4hVCaWDgfVGmrO1uqgeJEt2PSWuqiXUJlcU9/pP aC7xkCgWLCCV+JZYmgyh91JKVHP5yBUvAGy1cQJkUPW0g5zbJhtl3rjej w==; X-CSE-ConnectionGUID: AAWiQH4wQDWKQJMkw1O/vw== X-CSE-MsgGUID: /Lfg2CZIR4uLEpG6QuCuFw== X-IronPort-AV: E=McAfee;i="6700,10204,11253"; a="35003192" X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="35003192" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:19 -0800 X-CSE-ConnectionGUID: tnOfJVLdS9uLrkKuI2ylyg== X-CSE-MsgGUID: vnwls4wtQxu0LyPJGn4/UA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="110597820" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.246.8.237]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:17 -0800 From: Stanislaw Gruszka To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Wentong Wu , Sakari Ailus , Hans de Goede Subject: [PATCH v4 1/3] usb: misc: ljca: move usb_autopm_put_interface() after wait for response Date: Tue, 12 Nov 2024 08:55:12 +0100 Message-Id: <20241112075514.680712-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 --- v3 -> v4: no change in this patch v2 -> v3: add A-b tag from Sakari v1 -> v2: fix handing error of usb_autopm_get_interface(), add R-b, T-b tags from Hans 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 Tue Nov 12 07:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13871833 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 2ACD91990AF for ; Tue, 12 Nov 2024 07:55:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398126; cv=none; b=GSZllG6yiLPSTyCf2EoC17B7Wgcp80+OB87h6l1J+vbTSQ6KNatgvn4C3apVFKpoYHUZvtym+h5LKlh7nI2Dnr6T8HlgJS6EqrJooENnT/YBSju+MSU//t9c8xFItZ5b4bmCbAy0I862ZvqJXVTuadyrRJunUaBVk1nN7WeapmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398126; c=relaxed/simple; bh=8VxSQRcDnrhCOEVwLwHQkdlznsGu+FCajYsaALnrWf0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EIh7pmTQY1lLWsHey6RmP91NreXR2AvgWlV8aHXGsT/1X+Zc3uhuxG2QrxUdL5Ysdoba5xyl8pIWnZAInJ/PcMHwlfN0dILkvQ8eE3uvFCT7aRrVDcE/ln2DFIMukpId6YsK88XV4ek61aKz6BUQFXuLISzIz84+0uN2h5bfRjE= 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=JnG2xbT5; arc=none smtp.client-ip=192.198.163.17 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="JnG2xbT5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731398125; x=1762934125; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8VxSQRcDnrhCOEVwLwHQkdlznsGu+FCajYsaALnrWf0=; b=JnG2xbT5QitTS9yvu7kctEG4pkLhvbwZSwm0ng6t97VQCHTar+EtMlfb eLqzZPY0nKnGiO6mrRUkySqR9bNvwZVbv4nN2xvJTr3R3QipO+pgmKxTY TEELu2hrr55R3cQEU0whnesxj+Kkbw74qbO02rNl1xLH4zPuEkroZoyd6 c9nWNHUP0hMT7K0nHCaWWqlivcAQyAVeFudbl3e6bI4DKw4RZhr13ZZWt m0ZY4/Lnpw7NEalZIobRrdD5ux/vBeJbhcIxsd1WKenhe+P6nxKHxokSb YlQxOyGLCJaqMHfZM8x15iVnwe4Db5OrE4LnIn70fgPkumwtqjlx9K0au Q==; X-CSE-ConnectionGUID: YB3WsstATQGdPK9TNfggSA== X-CSE-MsgGUID: vxGfPhCuS+qEvJMQefcUOA== X-IronPort-AV: E=McAfee;i="6700,10204,11253"; a="31092711" X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="31092711" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:25 -0800 X-CSE-ConnectionGUID: 6XR+du3ISsWduS4vJtvyBw== X-CSE-MsgGUID: Us+pYUmhQOuLVhzj7mmt9g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="87215359" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.246.8.237]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:22 -0800 From: Stanislaw Gruszka To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Wentong Wu , Sakari Ailus , Hans de Goede Subject: [PATCH v4 2/3] usb: misc: ljca: set small runtime autosuspend delay Date: Tue, 12 Nov 2024 08:55:13 +0100 Message-Id: <20241112075514.680712-2-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241112075514.680712-1-stanislaw.gruszka@linux.intel.com> References: <20241112075514.680712-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 works around 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 --- v3 -> v4: no change in this patch v2 -> v3: add A-b tag from Sakari v1 -> v2: add R-b, T-b tags from Hans 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 Tue Nov 12 07:55:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stanislaw Gruszka X-Patchwork-Id: 13871834 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (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 34EAF20B1FD for ; Tue, 12 Nov 2024 07:55:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398147; cv=none; b=jckWL0CSjeu7pbTe5GENRvVolMtdJwnfc3H4OW+n5dJqHbNL6xXTAVBMmGbOnDWVrUG4rK+f9iMjm/hlfSgL8dL7YutTOZK99joq6FxvJoU7se2OhvM+dHf7qivnA8/6YgTGPAOqZf7Dkaa0MKfj8sul8TzbfJnkilqCXZL8NJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731398147; c=relaxed/simple; bh=RDhleBrsFBrHe9APLakRu2zYjwhLAEuSM7P9rH/TNm4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z6Z38dUwXTeJhVVYacRmPwzmRVddKp9SebqBrK9H5A2wxqZAOvRbKYiXO+MuRTRhg4hGCAKaVJclK9h7mhUyaY66DIhTwhnqcj/zXcJI5rULwskEAbQGscL+uzBwk4Z1LPoN+awFVWdyJrH7dwn4spW1zBvcQEe6Bp6/Soa9vdg= 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=GT8AvXFM; arc=none smtp.client-ip=192.198.163.17 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="GT8AvXFM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1731398146; x=1762934146; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RDhleBrsFBrHe9APLakRu2zYjwhLAEuSM7P9rH/TNm4=; b=GT8AvXFMikVlSG9MwxIoStbHSWJPtFDE8m47qdq2ypRbVo2q1pS9R0hv gDbPYNIYrD7oUKsbdMR03JswQxAmnTPc/kntpyoz0Ji9snFWj4K2xdC8F J5+Iy8O6cgV7eUmLYxhd990J9z0g8ijrEXMT01TvI83FQxNHuSdkb/LNp 5Rn4Np8erLtkuZgDCjdbGr8eOHjF78FRYaaXlVMCNONKuw6j65Oy2Jt0e x+aSQYBncCGOsvcpBG+v5MDLBtyOdwJj99xjlPJDP43v1QLMjmzK4WuMl /MTtL/Qf2d4JiSoRXylOl/nb3LVq3byYjrYfnVEgrX/4QKmJZN7OkgnJ7 A==; X-CSE-ConnectionGUID: gUHiPw1WQv++gK1+E2h2jQ== X-CSE-MsgGUID: nCNrRrWmTYa59M7qLUaurg== X-IronPort-AV: E=McAfee;i="6700,10204,11253"; a="31092759" X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="31092759" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:45 -0800 X-CSE-ConnectionGUID: JyYEpu4IRQibmV+hwatwDg== X-CSE-MsgGUID: hK5AYeOhRXWWzBJ7HmmnMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,147,1728975600"; d="scan'208";a="87215394" Received: from sgruszka-mobl.ger.corp.intel.com (HELO localhost) ([10.246.8.237]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Nov 2024 23:55:28 -0800 From: Stanislaw Gruszka To: Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, Wentong Wu , Sakari Ailus , Hans de Goede Subject: [PATCH v4 3/3] usb: misc: ljca: add firmware version sysfs attribute Date: Tue, 12 Nov 2024 08:55:14 +0100 Message-Id: <20241112075514.680712-3-stanislaw.gruszka@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241112075514.680712-1-stanislaw.gruszka@linux.intel.com> References: <20241112075514.680712-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 purpose read firmware version during probe and add sysfs attribute to make that information available. Acked-by: Sakari Ailus Signed-off-by: Stanislaw Gruszka --- v3->v4: use sysfs attribute to provide firmware version, drop tags from Hans since the code changed v2->v3: use dev_dbg() for printing the firmware version v1->v2: fix 80-chars line wrap .../ABI/testing/sysfs-bus-usb-devices-ljca | 9 ++++ drivers/usb/misc/usb-ljca.c | 53 +++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-usb-devices-ljca diff --git a/Documentation/ABI/testing/sysfs-bus-usb-devices-ljca b/Documentation/ABI/testing/sysfs-bus-usb-devices-ljca new file mode 100644 index 000000000000..f5eb38bf99a8 --- /dev/null +++ b/Documentation/ABI/testing/sysfs-bus-usb-devices-ljca @@ -0,0 +1,9 @@ +What: /sys/bus/usb/devices/.../ljca_version +Date: November 2024 +KernelVersion: 6.13 +Contact: Sakari Ailus +Description: + Provides the firmware version of LJCA device. + The format is Major.Minor.Patch.Build, where + Major, Minor, Patch, and Build are decimal numbers. + For example: 1.0.0.256 diff --git a/drivers/usb/misc/usb-ljca.c b/drivers/usb/misc/usb-ljca.c index d9c21f783055..4b5bd5b27b2a 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; @@ -152,8 +160,10 @@ struct ljca_adapter { struct mutex mutex; struct list_head client_list; + struct ljca_fw_version fw_version; bool disconnect; + bool fw_version_valid; u32 reset_id; }; @@ -740,6 +750,24 @@ static int ljca_enumerate_clients(struct ljca_adapter *adap) return ret; } +static void ljca_read_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; + } + + adap->fw_version = version; + adap->fw_version_valid = true; +} + static int ljca_probe(struct usb_interface *interface, const struct usb_device_id *id) { @@ -811,6 +839,8 @@ static int ljca_probe(struct usb_interface *interface, if (ret) goto err_free; + ljca_read_fw_version(adap); + /* * This works around problems with ov2740 initialization on some * Lenovo platforms. The autosuspend delay, has to be smaller than @@ -874,6 +904,28 @@ static int ljca_resume(struct usb_interface *interface) return usb_submit_urb(adap->rx_urb, GFP_KERNEL); } +static ssize_t ljca_version_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct usb_interface *intf = to_usb_interface(dev); + struct ljca_adapter *adap = usb_get_intfdata(intf); + struct ljca_fw_version ver = adap->fw_version; + + if (!adap->fw_version_valid) + return -ENODATA; + + return sysfs_emit(buf, "%d.%d.%d.%d\n", ver.major, ver.minor, + le16_to_cpu(ver.patch), le16_to_cpu(ver.build)); +} + +static DEVICE_ATTR_RO(ljca_version); + +static struct attribute *ljca_attrs[] = { + &dev_attr_ljca_version.attr, +}; + +ATTRIBUTE_GROUPS(ljca); + static const struct usb_device_id ljca_table[] = { { USB_DEVICE(0x8086, 0x0b63) }, { /* sentinel */ } @@ -888,6 +940,7 @@ static struct usb_driver ljca_driver = { .suspend = ljca_suspend, .resume = ljca_resume, .supports_autosuspend = 1, + .dev_groups = ljca_groups, }; module_usb_driver(ljca_driver);