Skip to content

Commit 7035f3a

Browse files
aduggan-synaJiri Kosina
authored andcommitted
HID: rmi: Write updated F11 control registers after reset
When a device is reset the values of control registers will be reset to the defaults. This patch reapplies the control register values set for F11 by the driver. Signed-off-by: Andrew Duggan <[email protected]> Tested-by: Gabriele Mazzotta <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 0925636 commit 7035f3a

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

drivers/hid/hid-rmi.c

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@
4040
#define RMI_DEVICE BIT(0)
4141
#define RMI_DEVICE_HAS_PHYS_BUTTONS BIT(1)
4242

43+
/*
44+
* retrieve the ctrl registers
45+
* the ctrl register has a size of 20 but a fw bug split it into 16 + 4,
46+
* and there is no way to know if the first 20 bytes are here or not.
47+
* We use only the first 12 bytes, so get only them.
48+
*/
49+
#define RMI_F11_CTRL_REG_COUNT 12
50+
4351
enum rmi_mode_type {
4452
RMI_MODE_OFF = 0,
4553
RMI_MODE_ATTN_REPORTS = 1,
@@ -116,6 +124,8 @@ struct rmi_data {
116124
unsigned int max_y;
117125
unsigned int x_size_mm;
118126
unsigned int y_size_mm;
127+
bool read_f11_ctrl_regs;
128+
u8 f11_ctrl_regs[RMI_F11_CTRL_REG_COUNT];
119129

120130
unsigned int gpio_led_count;
121131
unsigned int button_count;
@@ -557,6 +567,18 @@ static int rmi_set_sleep_mode(struct hid_device *hdev, int sleep_mode)
557567

558568
static int rmi_suspend(struct hid_device *hdev, pm_message_t message)
559569
{
570+
struct rmi_data *data = hid_get_drvdata(hdev);
571+
int ret;
572+
u8 buf[RMI_F11_CTRL_REG_COUNT];
573+
574+
ret = rmi_read_block(hdev, data->f11.control_base_addr, buf,
575+
RMI_F11_CTRL_REG_COUNT);
576+
if (ret)
577+
hid_warn(hdev, "can not read F11 control registers\n");
578+
else
579+
memcpy(data->f11_ctrl_regs, buf, RMI_F11_CTRL_REG_COUNT);
580+
581+
560582
if (!device_may_wakeup(hdev->dev.parent))
561583
return rmi_set_sleep_mode(hdev, RMI_SLEEP_DEEP_SLEEP);
562584

@@ -565,6 +587,7 @@ static int rmi_suspend(struct hid_device *hdev, pm_message_t message)
565587

566588
static int rmi_post_reset(struct hid_device *hdev)
567589
{
590+
struct rmi_data *data = hid_get_drvdata(hdev);
568591
int ret;
569592

570593
ret = rmi_set_mode(hdev, RMI_MODE_ATTN_REPORTS);
@@ -573,6 +596,14 @@ static int rmi_post_reset(struct hid_device *hdev)
573596
return ret;
574597
}
575598

599+
if (data->read_f11_ctrl_regs) {
600+
ret = rmi_write_block(hdev, data->f11.control_base_addr,
601+
data->f11_ctrl_regs, RMI_F11_CTRL_REG_COUNT);
602+
if (ret)
603+
hid_warn(hdev,
604+
"can not write F11 control registers after reset\n");
605+
}
606+
576607
if (!device_may_wakeup(hdev->dev.parent)) {
577608
ret = rmi_set_sleep_mode(hdev, RMI_SLEEP_NORMAL);
578609
if (ret) {
@@ -957,24 +988,23 @@ static int rmi_populate_f11(struct hid_device *hdev)
957988
if (has_data40)
958989
data->f11.report_size += data->max_fingers * 2;
959990

960-
/*
961-
* retrieve the ctrl registers
962-
* the ctrl register has a size of 20 but a fw bug split it into 16 + 4,
963-
* and there is no way to know if the first 20 bytes are here or not.
964-
* We use only the first 12 bytes, so get only them.
965-
*/
966-
ret = rmi_read_block(hdev, data->f11.control_base_addr, buf, 12);
991+
ret = rmi_read_block(hdev, data->f11.control_base_addr,
992+
data->f11_ctrl_regs, RMI_F11_CTRL_REG_COUNT);
967993
if (ret) {
968994
hid_err(hdev, "can not read ctrl block of size 11: %d.\n", ret);
969995
return ret;
970996
}
971997

972-
data->max_x = buf[6] | (buf[7] << 8);
973-
data->max_y = buf[8] | (buf[9] << 8);
998+
/* data->f11_ctrl_regs now contains valid register data */
999+
data->read_f11_ctrl_regs = true;
1000+
1001+
data->max_x = data->f11_ctrl_regs[6] | (data->f11_ctrl_regs[7] << 8);
1002+
data->max_y = data->f11_ctrl_regs[8] | (data->f11_ctrl_regs[9] << 8);
9741003

9751004
if (has_dribble) {
976-
buf[0] = buf[0] & ~BIT(6);
977-
ret = rmi_write(hdev, data->f11.control_base_addr, buf);
1005+
data->f11_ctrl_regs[0] = data->f11_ctrl_regs[0] & ~BIT(6);
1006+
ret = rmi_write(hdev, data->f11.control_base_addr,
1007+
data->f11_ctrl_regs);
9781008
if (ret) {
9791009
hid_err(hdev, "can not write to control reg 0: %d.\n",
9801010
ret);
@@ -983,9 +1013,9 @@ static int rmi_populate_f11(struct hid_device *hdev)
9831013
}
9841014

9851015
if (has_palm_detect) {
986-
buf[11] = buf[11] & ~BIT(0);
1016+
data->f11_ctrl_regs[11] = data->f11_ctrl_regs[11] & ~BIT(0);
9871017
ret = rmi_write(hdev, data->f11.control_base_addr + 11,
988-
&buf[11]);
1018+
&data->f11_ctrl_regs[11]);
9891019
if (ret) {
9901020
hid_err(hdev, "can not write to control reg 11: %d.\n",
9911021
ret);

0 commit comments

Comments
 (0)