Skip to content

Commit d34c610

Browse files
dtorJiri Kosina
authored andcommitted
HID: i2c-hid: use "struct i2c_hid" as argument in most calls
The main object in the driver is struct i2c_hid so it makes more sense to pass it around instead of passing i2c_client and then fetching i2c_hid associated with it. 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 a5e5e03 commit d34c610

1 file changed

Lines changed: 36 additions & 39 deletions

File tree

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

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
208208
return quirks;
209209
}
210210

211-
static int __i2c_hid_command(struct i2c_client *client,
211+
static int __i2c_hid_command(struct i2c_hid *ihid,
212212
const struct i2c_hid_cmd *command, u8 reportID,
213213
u8 reportType, u8 *args, int args_len,
214214
unsigned char *buf_recv, int data_len)
215215
{
216-
struct i2c_hid *ihid = i2c_get_clientdata(client);
216+
struct i2c_client *client = ihid->client;
217217
union command *cmd = (union command *)ihid->cmdbuf;
218218
int ret;
219219
struct i2c_msg msg[2];
@@ -288,18 +288,17 @@ static int __i2c_hid_command(struct i2c_client *client,
288288
return ret;
289289
}
290290

291-
static int i2c_hid_command(struct i2c_client *client,
291+
static int i2c_hid_command(struct i2c_hid *ihid,
292292
const struct i2c_hid_cmd *command,
293293
unsigned char *buf_recv, int data_len)
294294
{
295-
return __i2c_hid_command(client, command, 0, 0, NULL, 0,
295+
return __i2c_hid_command(ihid, command, 0, 0, NULL, 0,
296296
buf_recv, data_len);
297297
}
298298

299-
static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
299+
static int i2c_hid_get_report(struct i2c_hid *ihid, u8 reportType,
300300
u8 reportID, unsigned char *buf_recv, int data_len)
301301
{
302-
struct i2c_hid *ihid = i2c_get_clientdata(client);
303302
u8 args[2];
304303
int ret;
305304
int args_len = 0;
@@ -310,10 +309,10 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
310309
args[args_len++] = readRegister & 0xFF;
311310
args[args_len++] = readRegister >> 8;
312311

313-
ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
312+
ret = __i2c_hid_command(ihid, &hid_get_report_cmd, reportID,
314313
reportType, args, args_len, buf_recv, data_len);
315314
if (ret) {
316-
dev_err(&client->dev,
315+
dev_err(&ihid->client->dev,
317316
"failed to retrieve report from device.\n");
318317
return ret;
319318
}
@@ -323,17 +322,16 @@ static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
323322

324323
/**
325324
* i2c_hid_set_or_send_report: forward an incoming report to the device
326-
* @client: the i2c_client of the device
325+
* @ihid: the i2c hid device
327326
* @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
328327
* @reportID: the report ID
329328
* @buf: the actual data to transfer, without the report ID
330329
* @data_len: size of buf
331330
* @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
332331
*/
333-
static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
332+
static int i2c_hid_set_or_send_report(struct i2c_hid *ihid, u8 reportType,
334333
u8 reportID, unsigned char *buf, size_t data_len, bool use_data)
335334
{
336-
struct i2c_hid *ihid = i2c_get_clientdata(client);
337335
u8 *args = ihid->argsbuf;
338336
const struct i2c_hid_cmd *hidcmd;
339337
int ret;
@@ -380,19 +378,19 @@ static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
380378

381379
memcpy(&args[index], buf, data_len);
382380

383-
ret = __i2c_hid_command(client, hidcmd, reportID,
381+
ret = __i2c_hid_command(ihid, hidcmd, reportID,
384382
reportType, args, args_len, NULL, 0);
385383
if (ret) {
386-
dev_err(&client->dev, "failed to set a report to device.\n");
384+
dev_err(&ihid->client->dev,
385+
"failed to set a report to device.\n");
387386
return ret;
388387
}
389388

390389
return data_len;
391390
}
392391

393-
static int i2c_hid_set_power(struct i2c_client *client, int power_state)
392+
static int i2c_hid_set_power(struct i2c_hid *ihid, int power_state)
394393
{
395-
struct i2c_hid *ihid = i2c_get_clientdata(client);
396394
int ret;
397395

398396
i2c_hid_dbg(ihid, "%s\n", __func__);
@@ -404,18 +402,18 @@ static int i2c_hid_set_power(struct i2c_client *client, int power_state)
404402
*/
405403
if (power_state == I2C_HID_PWR_ON &&
406404
ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
407-
ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0);
405+
ret = i2c_hid_command(ihid, &hid_set_power_cmd, NULL, 0);
408406

409407
/* Device was already activated */
410408
if (!ret)
411409
goto set_pwr_exit;
412410
}
413411

414-
ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
412+
ret = __i2c_hid_command(ihid, &hid_set_power_cmd, power_state,
415413
0, NULL, 0, NULL, 0);
416-
417414
if (ret)
418-
dev_err(&client->dev, "failed to change power setting.\n");
415+
dev_err(&ihid->client->dev,
416+
"failed to change power setting.\n");
419417

420418
set_pwr_exit:
421419

@@ -434,9 +432,8 @@ static int i2c_hid_set_power(struct i2c_client *client, int power_state)
434432
return ret;
435433
}
436434

437-
static int i2c_hid_hwreset(struct i2c_client *client)
435+
static int i2c_hid_hwreset(struct i2c_hid *ihid)
438436
{
439-
struct i2c_hid *ihid = i2c_get_clientdata(client);
440437
int ret;
441438

442439
i2c_hid_dbg(ihid, "%s\n", __func__);
@@ -448,22 +445,22 @@ static int i2c_hid_hwreset(struct i2c_client *client)
448445
*/
449446
mutex_lock(&ihid->reset_lock);
450447

451-
ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
448+
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
452449
if (ret)
453450
goto out_unlock;
454451

455452
i2c_hid_dbg(ihid, "resetting...\n");
456453

457-
ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
454+
ret = i2c_hid_command(ihid, &hid_reset_cmd, NULL, 0);
458455
if (ret) {
459-
dev_err(&client->dev, "failed to reset device.\n");
460-
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
456+
dev_err(&ihid->client->dev, "failed to reset device.\n");
457+
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
461458
goto out_unlock;
462459
}
463460

464461
/* At least some SIS devices need this after reset */
465462
if (!(ihid->quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET))
466-
ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
463+
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
467464

468465
out_unlock:
469466
mutex_unlock(&ihid->reset_lock);
@@ -628,7 +625,7 @@ static int i2c_hid_get_raw_report(struct hid_device *hid,
628625
/* +2 bytes to include the size of the reply in the query buffer */
629626
ask_count = min(count + 2, (size_t)ihid->bufsize);
630627

631-
ret = i2c_hid_get_report(client,
628+
ret = i2c_hid_get_report(ihid,
632629
report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
633630
report_number, ihid->rawbuf, ask_count);
634631

@@ -672,7 +669,7 @@ static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
672669
* to i2c_hid_set_or_send_report which takes care of encoding
673670
* everything properly.
674671
*/
675-
ret = i2c_hid_set_or_send_report(client,
672+
ret = i2c_hid_set_or_send_report(ihid,
676673
report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
677674
report_id, buf + 1, count - 1, use_data);
678675

@@ -727,7 +724,7 @@ static int i2c_hid_parse(struct hid_device *hid)
727724
}
728725

729726
do {
730-
ret = i2c_hid_hwreset(client);
727+
ret = i2c_hid_hwreset(ihid);
731728
if (ret)
732729
msleep(1000);
733730
} while (tries-- > 0 && ret);
@@ -751,7 +748,7 @@ static int i2c_hid_parse(struct hid_device *hid)
751748

752749
i2c_hid_dbg(ihid, "asking HID report descriptor\n");
753750

754-
ret = i2c_hid_command(client, &hid_report_descr_cmd,
751+
ret = i2c_hid_command(ihid, &hid_report_descr_cmd,
755752
rdesc, rsize);
756753
if (ret) {
757754
hid_err(hid, "reading report descriptor failed\n");
@@ -871,11 +868,11 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
871868
*i2c_hid_get_dmi_i2c_hid_desc_override(client->name);
872869
} else {
873870
i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
874-
ret = i2c_hid_command(client, &hid_descr_cmd,
871+
ret = i2c_hid_command(ihid, &hid_descr_cmd,
875872
ihid->hdesc_buffer,
876873
sizeof(struct i2c_hid_desc));
877874
if (ret) {
878-
dev_err(&client->dev, "hid_descr_cmd failed\n");
875+
dev_err(&ihid->client->dev, "hid_descr_cmd failed\n");
879876
return -ENODEV;
880877
}
881878
}
@@ -885,7 +882,7 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
885882
* bytes 2-3 -> bcdVersion (has to be 1.00) */
886883
/* check bcdVersion == 1.0 */
887884
if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
888-
dev_err(&client->dev,
885+
dev_err(&ihid->client->dev,
889886
"unexpected HID descriptor bcdVersion (0x%04hx)\n",
890887
le16_to_cpu(hdesc->bcdVersion));
891888
return -ENODEV;
@@ -894,8 +891,8 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
894891
/* Descriptor length should be 30 bytes as per the specification */
895892
dsize = le16_to_cpu(hdesc->wHIDDescLength);
896893
if (dsize != sizeof(struct i2c_hid_desc)) {
897-
dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
898-
dsize);
894+
dev_err(&ihid->client->dev,
895+
"weird size of HID descriptor (%u)\n", dsize);
899896
return -ENODEV;
900897
}
901898
i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
@@ -1064,7 +1061,7 @@ void i2c_hid_core_shutdown(struct i2c_client *client)
10641061
{
10651062
struct i2c_hid *ihid = i2c_get_clientdata(client);
10661063

1067-
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1064+
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
10681065
free_irq(client->irq, ihid);
10691066

10701067
i2c_hid_core_shutdown_tail(ihid);
@@ -1085,7 +1082,7 @@ static int i2c_hid_core_suspend(struct device *dev)
10851082
return ret;
10861083

10871084
/* Save some power */
1088-
i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1085+
i2c_hid_set_power(ihid, I2C_HID_PWR_SLEEP);
10891086

10901087
disable_irq(client->irq);
10911088

@@ -1133,9 +1130,9 @@ static int i2c_hid_core_resume(struct device *dev)
11331130
* let's still reset them here.
11341131
*/
11351132
if (ihid->quirks & I2C_HID_QUIRK_RESET_ON_RESUME)
1136-
ret = i2c_hid_hwreset(client);
1133+
ret = i2c_hid_hwreset(ihid);
11371134
else
1138-
ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
1135+
ret = i2c_hid_set_power(ihid, I2C_HID_PWR_ON);
11391136

11401137
if (ret)
11411138
return ret;

0 commit comments

Comments
 (0)