summaryrefslogtreecommitdiff
path: root/drivers/hid
diff options
context:
space:
mode:
authorDmitry Torokhov <dmitry.torokhov@gmail.com>2022-01-18 10:26:23 +0300
committerJiri Kosina <jkosina@suse.cz>2022-02-14 12:51:08 +0300
commitacb8dd95974dda4b6072410bfe09bc83d2c22d23 (patch)
treee20780960dd400b2c08a03f1e0b06efeca797467 /drivers/hid
parent8399bd01026eab803d6ebb5372cf28b5e1f335f8 (diff)
downloadlinux-acb8dd95974dda4b6072410bfe09bc83d2c22d23.tar.xz
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>
Diffstat (limited to 'drivers/hid')
-rw-r--r--drivers/hid/i2c-hid/i2c-hid-core.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/drivers/hid/i2c-hid/i2c-hid-core.c b/drivers/hid/i2c-hid/i2c-hid-core.c
index 32d275d2d5dc..7b7127534e24 100644
--- a/drivers/hid/i2c-hid/i2c-hid-core.c
+++ b/drivers/hid/i2c-hid/i2c-hid-core.c
@@ -107,7 +107,6 @@ struct i2c_hid_cmd {
/* commands */
static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01) };
static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) };
-static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) };
/*
* 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,
return data_len;
}
+static int i2c_hid_set_power_command(struct i2c_hid *ihid, int power_state)
+{
+ size_t length;
+
+ /* SET_POWER uses command register */
+ *(__le16 *)ihid->cmdbuf = ihid->hdesc.wCommandRegister;
+ length = sizeof(__le16);
+
+ /* Now the command itself */
+ length += i2c_hid_encode_command(ihid->cmdbuf + length,
+ I2C_HID_OPCODE_SET_POWER,
+ 0, power_state);
+
+ return i2c_hid_xfer(ihid, ihid->cmdbuf, length, NULL, 0);
+}
+
static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
{
int ret;
@@ -409,15 +424,14 @@ static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
*/
if (power_state == I2C_HID_PWR_ON &&
ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
- ret = i2c_hid_command(ihid, &hid_set_power_cmd, NULL, 0);
+ ret = i2c_hid_set_power_command(ihid, I2C_HID_PWR_ON);
/* Device was already activated */
if (!ret)
goto set_pwr_exit;
}
- ret = __i2c_hid_command(ihid, &hid_set_power_cmd, power_state,
- 0, NULL, 0, NULL, 0);
+ ret = i2c_hid_set_power_command(ihid, power_state);
if (ret)
dev_err(&ihid->client->dev,
"failed to change power setting.\n");