Skip to content

Commit 39e509a

Browse files
committed
[FROM-ML] HID: hid-lenovo-go-s: Add IMU and Touchpad RO Attributes
Adds attributes for reporting the touchpad manufacturer, version, and IMU manufacturer. Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
1 parent 9c8cc81 commit 39e509a

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

drivers/hid/hid-lenovo-go-s.c

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct hid_gos_cfg {
4343
u8 gp_mode;
4444
u8 gp_poll_rate;
4545
u8 imu_bypass_en;
46+
u8 imu_manufacturer;
4647
u8 imu_sensor_en;
4748
u8 mcu_id[12];
4849
u8 mouse_step;
@@ -54,6 +55,8 @@ struct hid_gos_cfg {
5455
u8 rgb_speed;
5556
u8 tp_en;
5657
u8 tp_linux_mode;
58+
u8 tp_manufacturer;
59+
u8 tp_version;
5760
u8 tp_windows_mode;
5861
} drvdata;
5962

@@ -201,6 +204,36 @@ enum rgb_config_index {
201204
USR_LIGHT_PROFILE_3,
202205
};
203206

207+
enum test_command_index {
208+
TEST_TP_MFR = 0x02,
209+
TEST_IMU_MFR,
210+
TEST_TP_VER,
211+
};
212+
213+
enum tp_mfr_index {
214+
TP_NONE,
215+
TP_BETTERLIFE,
216+
TP_SIPO,
217+
};
218+
219+
static const char *const touchpad_manufacturer_text[] = {
220+
[TP_NONE] = "none",
221+
[TP_BETTERLIFE] = "BetterLife",
222+
[TP_SIPO] = "SIPO",
223+
};
224+
225+
enum imu_mfr_index {
226+
IMU_NONE,
227+
IMU_BOSCH,
228+
IMU_ST,
229+
};
230+
231+
static const char *const imu_manufacturer_text[] = {
232+
[IMU_NONE] = "none",
233+
[IMU_BOSCH] = "Bosch",
234+
[IMU_ST] = "ST",
235+
};
236+
204237
static int hid_gos_version_event(u8 *data)
205238
{
206239
struct version_report *ver_rep = (struct version_report *)data;
@@ -279,6 +312,30 @@ static int hid_gos_touchpad_event(struct command_report *cmd_rep)
279312
return ret;
280313
}
281314

315+
static int hid_gos_pl_test_event(struct command_report *cmd_rep)
316+
{
317+
int ret = 0;
318+
319+
switch (cmd_rep->sub_cmd) {
320+
case TEST_TP_MFR:
321+
drvdata.tp_manufacturer = cmd_rep->data[0];
322+
ret = 0;
323+
break;
324+
case TEST_IMU_MFR:
325+
drvdata.imu_manufacturer = cmd_rep->data[0];
326+
ret = 0;
327+
break;
328+
case TEST_TP_VER:
329+
drvdata.tp_version = cmd_rep->data[0];
330+
ret = 0;
331+
break;
332+
default:
333+
ret = -EINVAL;
334+
break;
335+
}
336+
return ret;
337+
}
338+
282339
static int hid_gos_light_event(struct command_report *cmd_rep)
283340
{
284341
struct led_classdev_mc *mc_cdev;
@@ -362,6 +419,9 @@ static int hid_gos_raw_event(struct hid_device *hdev, struct hid_report *report,
362419
case GET_TP_PARAM:
363420
ret = hid_gos_touchpad_event(cmd_rep);
364421
break;
422+
case GET_PL_TEST:
423+
ret = hid_gos_pl_test_event(cmd_rep);
424+
break;
365425
case GET_RGB_CFG:
366426
ret = hid_gos_light_event(cmd_rep);
367427
break;
@@ -742,6 +802,42 @@ static ssize_t touchpad_property_options(struct device *dev,
742802
return count;
743803
}
744804

805+
static ssize_t test_property_show(struct device *dev,
806+
struct device_attribute *attr, char *buf,
807+
enum test_command_index index)
808+
{
809+
size_t count = 0;
810+
int ret;
811+
u8 i;
812+
813+
ret = mcu_property_out(drvdata.hdev, GET_PL_TEST, index, 0, 0);
814+
if (ret)
815+
return ret;
816+
817+
switch (index) {
818+
case TEST_TP_MFR:
819+
i = drvdata.tp_manufacturer;
820+
if (i >= ARRAY_SIZE(touchpad_manufacturer_text))
821+
return -EINVAL;
822+
count = sysfs_emit(buf, "%s\n", touchpad_manufacturer_text[i]);
823+
break;
824+
case TEST_IMU_MFR:
825+
i = drvdata.imu_manufacturer;
826+
if (i >= ARRAY_SIZE(imu_manufacturer_text))
827+
return -EINVAL;
828+
count = sysfs_emit(buf, "%s\n", imu_manufacturer_text[i]);
829+
break;
830+
case TEST_TP_VER:
831+
count = sysfs_emit(buf, "%u\n", drvdata.tp_version);
832+
break;
833+
default:
834+
count = -EINVAL;
835+
break;
836+
}
837+
838+
return count;
839+
}
840+
745841
static ssize_t mcu_id_show(struct device *dev, struct device_attribute *attr,
746842
char *buf)
747843
{
@@ -1085,13 +1181,17 @@ struct gos_cfg_attr imu_bypass_enabled = { FEATURE_IMU_BYPASS };
10851181
LEGOS_DEVICE_ATTR_RW(imu_bypass_enabled, "bypass_enabled", index, gamepad);
10861182
static DEVICE_ATTR_RO_NAMED(imu_bypass_enabled_index, "bypass_enabled_index");
10871183

1184+
struct gos_cfg_attr imu_manufacturer = { TEST_IMU_MFR };
1185+
LEGOS_DEVICE_ATTR_RO(imu_manufacturer, "manufacturer", test);
1186+
10881187
struct gos_cfg_attr imu_sensor_enabled = { FEATURE_IMU_ENABLE };
10891188
LEGOS_DEVICE_ATTR_RW(imu_sensor_enabled, "sensor_enabled", index, gamepad);
10901189
static DEVICE_ATTR_RO_NAMED(imu_sensor_enabled_index, "sensor_enabled_index");
10911190

10921191
static struct attribute *legos_imu_attrs[] = {
10931192
&dev_attr_imu_bypass_enabled.attr,
10941193
&dev_attr_imu_bypass_enabled_index.attr,
1194+
&dev_attr_imu_manufacturer.attr,
10951195
&dev_attr_imu_sensor_enabled.attr,
10961196
&dev_attr_imu_sensor_enabled_index.attr,
10971197
NULL,
@@ -1145,6 +1245,12 @@ struct gos_cfg_attr touchpad_linux_mode = { CFG_LINUX_MODE };
11451245
LEGOS_DEVICE_ATTR_RW(touchpad_linux_mode, "linux_mode", index, touchpad);
11461246
static DEVICE_ATTR_RO_NAMED(touchpad_linux_mode_index, "linux_mode_index");
11471247

1248+
struct gos_cfg_attr touchpad_manufacturer = { TEST_TP_MFR };
1249+
LEGOS_DEVICE_ATTR_RO(touchpad_manufacturer, "manufacturer", test);
1250+
1251+
struct gos_cfg_attr touchpad_version = { TEST_TP_VER };
1252+
LEGOS_DEVICE_ATTR_RO(touchpad_version, "version", test);
1253+
11481254
struct gos_cfg_attr touchpad_windows_mode = { CFG_WINDOWS_MODE };
11491255
LEGOS_DEVICE_ATTR_RW(touchpad_windows_mode, "windows_mode", index, touchpad);
11501256
static DEVICE_ATTR_RO_NAMED(touchpad_windows_mode_index, "windows_mode_index");
@@ -1154,6 +1260,8 @@ static struct attribute *legos_touchpad_attrs[] = {
11541260
&dev_attr_touchpad_enabled_index.attr,
11551261
&dev_attr_touchpad_linux_mode.attr,
11561262
&dev_attr_touchpad_linux_mode_index.attr,
1263+
&dev_attr_touchpad_manufacturer.attr,
1264+
&dev_attr_touchpad_version.attr,
11571265
&dev_attr_touchpad_windows_mode.attr,
11581266
&dev_attr_touchpad_windows_mode_index.attr,
11591267
NULL,

0 commit comments

Comments
 (0)