Skip to content

Commit f29d882

Browse files
committed
[FROM-ML] HID: hid-lenovo-go: Add FPS Mode DPI settings
Adds attribute that enables selection of the DPI of the optical sensor when the right handle toggle is set to FPS mode. Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca> Signed-off-by: Derek J. Clark <derekjohn.clark@gmail.com>
1 parent 15b79ee commit f29d882

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

drivers/hid/hid-lenovo-go.c

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct hid_go_cfg {
6464
u32 mcu_version_hardware;
6565
u32 mcu_version_product;
6666
u32 mcu_version_protocol;
67+
u32 mouse_dpi;
6768
u8 rgb_en;
6869
u8 tp_en;
6970
u8 tp_vibration_en;
@@ -217,6 +218,8 @@ static const char *const rumble_mode_text[] = {
217218
[RUMBLE_MODE_RPG] = "rpg",
218219
};
219220

221+
#define FPS_MODE_DPI 0x02
222+
220223
static int hid_go_version_event(struct command_report *cmd_rep)
221224
{
222225
switch (cmd_rep->sub_cmd) {
@@ -424,6 +427,16 @@ static int hid_go_motor_event(struct command_report *cmd_rep)
424427
return -EINVAL;
425428
}
426429

430+
static int hid_go_fps_dpi_event(struct command_report *cmd_rep)
431+
{
432+
if (cmd_rep->sub_cmd != FPS_MODE_DPI)
433+
return -EINVAL;
434+
435+
drvdata.mouse_dpi = get_unaligned_le32(cmd_rep->data);
436+
437+
return 0;
438+
}
439+
427440
static int hid_go_set_event_return(struct command_report *cmd_rep)
428441
{
429442
if (cmd_rep->data[0] != 0)
@@ -474,8 +487,12 @@ static int hid_go_raw_event(struct hid_device *hdev, struct hid_report *report,
474487
case GET_MOTOR_CFG:
475488
ret = hid_go_motor_event(cmd_rep);
476489
break;
490+
case GET_DPI_CFG:
491+
ret = hid_go_fps_dpi_event(cmd_rep);
492+
break;
477493
case SET_FEATURE_STATUS:
478494
case SET_MOTOR_CFG:
495+
case SET_DPI_CFG:
479496
ret = hid_go_set_event_return(cmd_rep);
480497
break;
481498
default:
@@ -1014,6 +1031,52 @@ static ssize_t motor_config_options(struct device *dev,
10141031
return count;
10151032
}
10161033

1034+
static ssize_t fps_mode_dpi_store(struct device *dev,
1035+
struct device_attribute *attr,
1036+
const char *buf, size_t count)
1037+
1038+
{
1039+
size_t size = 4;
1040+
u32 value;
1041+
u8 val[4];
1042+
int ret;
1043+
1044+
ret = kstrtou32(buf, 10, &value);
1045+
if (ret)
1046+
return ret;
1047+
1048+
if (value != 500 && value != 800 && value != 1200 && value != 1800)
1049+
return -EINVAL;
1050+
1051+
put_unaligned_le32(value, val);
1052+
1053+
ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, SET_DPI_CFG,
1054+
FPS_MODE_DPI, UNSPECIFIED, val, size);
1055+
if (ret < 0)
1056+
return ret;
1057+
1058+
return count;
1059+
}
1060+
1061+
static ssize_t fps_mode_dpi_show(struct device *dev,
1062+
struct device_attribute *attr, char *buf)
1063+
{
1064+
int ret;
1065+
1066+
ret = mcu_property_out(drvdata.hdev, MCU_CONFIG_DATA, GET_DPI_CFG,
1067+
FPS_MODE_DPI, UNSPECIFIED, 0, 0);
1068+
if (ret < 0)
1069+
return ret;
1070+
1071+
return sysfs_emit(buf, "%u\n", drvdata.mouse_dpi);
1072+
}
1073+
1074+
static ssize_t fps_mode_dpi_index_show(struct device *dev,
1075+
struct device_attribute *attr, char *buf)
1076+
{
1077+
return sysfs_emit(buf, "500 800 1200 1800\n");
1078+
}
1079+
10171080
#define LEGO_DEVICE_ATTR_RW(_name, _attrname, _dtype, _rtype, _group) \
10181081
static ssize_t _name##_store(struct device *dev, \
10191082
struct device_attribute *attr, \
@@ -1085,7 +1148,12 @@ LEGO_DEVICE_ATTR_RW(gamepad_rumble_intensity, "rumble_intensity", UNSPECIFIED,
10851148
static DEVICE_ATTR_RO_NAMED(gamepad_rumble_intensity_index,
10861149
"rumble_intensity_index");
10871150

1151+
static DEVICE_ATTR_RW(fps_mode_dpi);
1152+
static DEVICE_ATTR_RO(fps_mode_dpi_index);
1153+
10881154
static struct attribute *mcu_attrs[] = {
1155+
&dev_attr_fps_mode_dpi.attr,
1156+
&dev_attr_fps_mode_dpi_index.attr,
10891157
&dev_attr_fps_switch_status.attr,
10901158
&dev_attr_gamepad_mode.attr,
10911159
&dev_attr_gamepad_mode_index.attr,

0 commit comments

Comments
 (0)