From: "Derek J. Clark" <derekjohn.clark@gmail.com>
To: Jiri Kosina <jikos@kernel.org>, Benjamin Tissoires <bentiss@kernel.org>
Cc: Richard Hughes <hughsient@gmail.com>,
Mario Limonciello <mario.limonciello@amd.com>,
Zhixin Zhang <zhangzx36@lenovo.com>,
Mia Shao <shaohz1@lenovo.com>,
Mark Pearson <mpearson-lenovo@squebb.ca>,
"Pierre-Loup A . Griffais" <pgriffais@valvesoftware.com>,
"Derek J . Clark" <derekjohn.clark@gmail.com>,
linux-input@vger.kernel.org, linux-doc@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH v6 11/19] HID: hid-lenovo-go-s: Add MCU ID Attribute
Date: Tue, 10 Mar 2026 07:29:29 +0000 [thread overview]
Message-ID: <20260310072937.3295875-12-derekjohn.clark@gmail.com> (raw)
In-Reply-To: <20260310072937.3295875-1-derekjohn.clark@gmail.com>
Adds command to probe for the MCU ID of the Lenovo Legion Go S
Controller and assign it to a device attribute.
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
---
v6:
- Use NULL instead of 0 in mcu_propery_out when there is no data.
---
drivers/hid/hid-lenovo-go-s.c | 56 +++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/drivers/hid/hid-lenovo-go-s.c b/drivers/hid/hid-lenovo-go-s.c
index c9f57dfa145a..8ee75f724b5b 100644
--- a/drivers/hid/hid-lenovo-go-s.c
+++ b/drivers/hid/hid-lenovo-go-s.c
@@ -18,6 +18,7 @@
#include <linux/mutex.h>
#include <linux/printk.h>
#include <linux/string.h>
+#include <linux/sysfs.h>
#include <linux/types.h>
#include <linux/unaligned.h>
#include <linux/usb.h>
@@ -34,8 +35,13 @@ static struct hid_gos_cfg {
struct completion send_cmd_complete;
struct hid_device *hdev;
struct mutex cfg_mutex; /*ensure single synchronous output report*/
+ u8 mcu_id[12];
} drvdata;
+struct gos_cfg_attr {
+ u8 index;
+};
+
struct command_report {
u8 cmd;
u8 sub_cmd;
@@ -70,6 +76,14 @@ static int hid_gos_version_event(u8 *data)
return 0;
}
+static int hid_gos_mcu_id_event(struct command_report *cmd_rep)
+{
+ drvdata.mcu_id[0] = cmd_rep->sub_cmd;
+ memcpy(&drvdata.mcu_id[1], cmd_rep->data, 11);
+
+ return 0;
+}
+
static int get_endpoint_address(struct hid_device *hdev)
{
struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
@@ -103,6 +117,9 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,
case GET_VERSION:
ret = hid_gos_version_event(data);
break;
+ case GET_MCU_ID:
+ ret = hid_gos_mcu_id_event(cmd_rep);
+ break;
default:
ret = -EINVAL;
break;
@@ -157,10 +174,41 @@ static int mcu_property_out(struct hid_device *hdev, u8 command, u8 index,
return 0;
}
+static ssize_t mcu_id_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ return sysfs_emit(buf, "%*phN\n", 12, &drvdata.mcu_id);
+}
+
+/* MCU */
+static DEVICE_ATTR_RO(mcu_id);
+
+static struct attribute *legos_mcu_attrs[] = {
+ &dev_attr_mcu_id.attr,
+ NULL,
+};
+
+static const struct attribute_group mcu_attr_group = {
+ .attrs = legos_mcu_attrs,
+};
+
+static const struct attribute_group *top_level_attr_groups[] = {
+ &mcu_attr_group,
+ NULL,
+};
+
static void cfg_setup(struct work_struct *work)
{
int ret;
+ /* MCU */
+ ret = mcu_property_out(drvdata.hdev, GET_MCU_ID, FEATURE_NONE, NULL, 0);
+ if (ret) {
+ dev_err(&drvdata.hdev->dev, "Failed to retrieve MCU ID: %i\n",
+ ret);
+ return;
+ }
+
ret = mcu_property_out(drvdata.hdev, GET_VERSION, FEATURE_NONE, NULL, 0);
if (ret) {
dev_err(&drvdata.hdev->dev, "Failed to retrieve MCU Version: %i\n", ret);
@@ -177,6 +225,13 @@ static int hid_gos_cfg_probe(struct hid_device *hdev,
drvdata.hdev = hdev;
mutex_init(&drvdata.cfg_mutex);
+ ret = sysfs_create_groups(&hdev->dev.kobj, top_level_attr_groups);
+ if (ret) {
+ dev_err_probe(&hdev->dev, ret,
+ "Failed to create gamepad configuration attributes\n");
+ return ret;
+ }
+
init_completion(&drvdata.send_cmd_complete);
/* Executing calls prior to returning from probe will lock the MCU. Schedule
@@ -196,6 +251,7 @@ static void hid_gos_cfg_remove(struct hid_device *hdev)
{
guard(mutex)(&drvdata.cfg_mutex);
cancel_delayed_work_sync(&drvdata.gos_cfg_setup);
+ sysfs_remove_groups(&hdev->dev.kobj, top_level_attr_groups);
hid_hw_close(hdev);
hid_hw_stop(hdev);
hid_set_drvdata(hdev, NULL);
--
2.53.0
next prev parent reply other threads:[~2026-03-10 7:29 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 7:29 [PATCH v6 00/19] HID: Add Legion Go and Go S Drivers Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 01/19] include: device.h: Add named device attributes Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 02/19] HID: hid-lenovo-go: Add Lenovo Legion Go Series HID Driver Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 03/19] HID: hid-lenovo-go: Add Feature Status Attributes Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 04/19] HID: hid-lenovo-go: Add Rumble and Haptic Settings Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 05/19] HID: hid-lenovo-go: Add FPS Mode DPI settings Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 06/19] HID: hid-lenovo-go: Add RGB LED control interface Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 07/19] HID: hid-lenovo-go: Add Calibration Settings Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 08/19] HID: hid-lenovo-go: Add OS Mode Toggle Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 09/19] HID: Include firmware version in the uevent Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 10/19] HID: hid-lenovo-go-s: Add Lenovo Legion Go S Series HID Driver Derek J. Clark
2026-03-10 7:29 ` Derek J. Clark [this message]
2026-03-10 7:29 ` [PATCH v6 12/19] HID: hid-lenovo-go-s: Add Feature Status Attributes Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 13/19] HID: hid-lenovo-go-s: Add Touchpad Mode Attributes Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 14/19] HID: hid-lenovo-go-s: Add RGB LED control interface Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 15/19] HID: hid-lenovo-go-s: Add IMU and Touchpad RO Attributes Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 16/19] HID: Add documentation for Lenovo Legion Go drivers Derek J. Clark
2026-03-12 2:44 ` Akira Yokosawa
2026-03-12 22:57 ` Derek John Clark
2026-03-10 7:29 ` [PATCH v6 17/19] HID: hid-lenovo-go-s: Remove unneeded semicolon Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 18/19] HID: hid-lenovo-go: " Derek J. Clark
2026-03-10 7:29 ` [PATCH v6 19/19] HID: hid-lenovo-go-s: Fix spelling mistake "configuratiion" -> "configuration" Derek J. Clark
2026-03-10 16:55 ` [PATCH v6 00/19] HID: Add Legion Go and Go S Drivers Jiri Kosina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260310072937.3295875-12-derekjohn.clark@gmail.com \
--to=derekjohn.clark@gmail.com \
--cc=bentiss@kernel.org \
--cc=hughsient@gmail.com \
--cc=jikos@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=pgriffais@valvesoftware.com \
--cc=shaohz1@lenovo.com \
--cc=zhangzx36@lenovo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.