Skip to content

Commit acb8dd9

Browse files
dtorJiri Kosina
authored andcommitted
HID: i2c-hid: create a helper for SET_POWER command
Another case where creating a dedicated helper allows for cleaner code that shows exactly what communication happens with the device when toggling its power. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Tested-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 8399bd0 commit acb8dd9

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

drivers/hid/i2c-hid/i2c-hid-core.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ struct i2c_hid_cmd {
107107
/* commands */
108108
static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01) };
109109
static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) };
110-
static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) };
111110

112111
/*
113112
* These definitions are not used here, but are defined by the spec.
@@ -396,6 +395,22 @@ static int i2c_hid_set_or_send_report(struct i2c_hid *ihid,
396395
return data_len;
397396
}
398397

398+
static int i2c_hid_set_power_command(struct i2c_hid *ihid, int power_state)
399+
{
400+
size_t length;
401+
402+
/* SET_POWER uses command register */
403+
*(__le16 *)ihid->cmdbuf = ihid->hdesc.wCommandRegister;
404+
length = sizeof(__le16);
405+
406+
/* Now the command itself */
407+
length += i2c_hid_encode_command(ihid->cmdbuf + length,
408+
I2C_HID_OPCODE_SET_POWER,
409+
0, power_state);
410+
411+
return i2c_hid_xfer(ihid, ihid->cmdbuf, length, NULL, 0);
412+
}
413+
399414
static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
400415
{
401416
int ret;
@@ -409,15 +424,14 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
409424
*/
410425
if (power_state == I2C_HID_PWR_ON &&
411426
ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
412-
ret = i2c_hid_command(ihid, &hid_set_power_cmd, NULL, 0);
427+
ret = i2c_hid_set_power_command(ihid, I2C_HID_PWR_ON);
413428

414429
/* Device was already activated */
415430
if (!ret)
416431
goto set_pwr_exit;
417432
}
418433

419-
ret = __i2c_hid_command(ihid, &hid_set_power_cmd, power_state,
420-
0, NULL, 0, NULL, 0);
434+
ret = i2c_hid_set_power_command(ihid, power_state);
421435
if (ret)
422436
dev_err(&ihid->client->dev,
423437
"failed to change power setting.\n");

0 commit comments

Comments
 (0)