GNU Linux-libre 4.9.308-gnu1
[releases.git] / drivers / hid / i2c-hid / i2c-hid-core.c
1 /*
2  * HID over I2C protocol implementation
3  *
4  * Copyright (c) 2012 Benjamin Tissoires <benjamin.tissoires@gmail.com>
5  * Copyright (c) 2012 Ecole Nationale de l'Aviation Civile, France
6  * Copyright (c) 2012 Red Hat, Inc
7  *
8  * This code is partly based on "USB HID support for Linux":
9  *
10  *  Copyright (c) 1999 Andreas Gal
11  *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
12  *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
13  *  Copyright (c) 2007-2008 Oliver Neukum
14  *  Copyright (c) 2006-2010 Jiri Kosina
15  *
16  * This file is subject to the terms and conditions of the GNU General Public
17  * License.  See the file COPYING in the main directory of this archive for
18  * more details.
19  */
20
21 #include <linux/module.h>
22 #include <linux/i2c.h>
23 #include <linux/interrupt.h>
24 #include <linux/input.h>
25 #include <linux/delay.h>
26 #include <linux/slab.h>
27 #include <linux/pm.h>
28 #include <linux/pm_runtime.h>
29 #include <linux/device.h>
30 #include <linux/wait.h>
31 #include <linux/err.h>
32 #include <linux/string.h>
33 #include <linux/list.h>
34 #include <linux/jiffies.h>
35 #include <linux/kernel.h>
36 #include <linux/hid.h>
37 #include <linux/mutex.h>
38 #include <linux/acpi.h>
39 #include <linux/of.h>
40 #include <linux/gpio/consumer.h>
41
42 #include <linux/i2c/i2c-hid.h>
43
44 #include "../hid-ids.h"
45 #include "i2c-hid.h"
46
47 /* quirks to control the device */
48 #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV        BIT(0)
49
50 /* flags */
51 #define I2C_HID_STARTED         0
52 #define I2C_HID_RESET_PENDING   1
53 #define I2C_HID_READ_PENDING    2
54
55 #define I2C_HID_PWR_ON          0x00
56 #define I2C_HID_PWR_SLEEP       0x01
57
58 /* debug option */
59 static bool debug;
60 module_param(debug, bool, 0444);
61 MODULE_PARM_DESC(debug, "print a lot of debug information");
62
63 #define i2c_hid_dbg(ihid, fmt, arg...)                                    \
64 do {                                                                      \
65         if (debug)                                                        \
66                 dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
67 } while (0)
68
69 struct i2c_hid_desc {
70         __le16 wHIDDescLength;
71         __le16 bcdVersion;
72         __le16 wReportDescLength;
73         __le16 wReportDescRegister;
74         __le16 wInputRegister;
75         __le16 wMaxInputLength;
76         __le16 wOutputRegister;
77         __le16 wMaxOutputLength;
78         __le16 wCommandRegister;
79         __le16 wDataRegister;
80         __le16 wVendorID;
81         __le16 wProductID;
82         __le16 wVersionID;
83         __le32 reserved;
84 } __packed;
85
86 struct i2c_hid_cmd {
87         unsigned int registerIndex;
88         __u8 opcode;
89         unsigned int length;
90         bool wait;
91 };
92
93 union command {
94         u8 data[0];
95         struct cmd {
96                 __le16 reg;
97                 __u8 reportTypeID;
98                 __u8 opcode;
99         } __packed c;
100 };
101
102 #define I2C_HID_CMD(opcode_) \
103         .opcode = opcode_, .length = 4, \
104         .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister)
105
106 /* fetch HID descriptor */
107 static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 };
108 /* fetch report descriptors */
109 static const struct i2c_hid_cmd hid_report_descr_cmd = {
110                 .registerIndex = offsetof(struct i2c_hid_desc,
111                         wReportDescRegister),
112                 .opcode = 0x00,
113                 .length = 2 };
114 /* commands */
115 static const struct i2c_hid_cmd hid_reset_cmd =         { I2C_HID_CMD(0x01),
116                                                           .wait = true };
117 static const struct i2c_hid_cmd hid_get_report_cmd =    { I2C_HID_CMD(0x02) };
118 static const struct i2c_hid_cmd hid_set_report_cmd =    { I2C_HID_CMD(0x03) };
119 static const struct i2c_hid_cmd hid_set_power_cmd =     { I2C_HID_CMD(0x08) };
120 static const struct i2c_hid_cmd hid_no_cmd =            { .length = 0 };
121
122 /*
123  * These definitions are not used here, but are defined by the spec.
124  * Keeping them here for documentation purposes.
125  *
126  * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) };
127  * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) };
128  * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) };
129  * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
130  */
131
132 static DEFINE_MUTEX(i2c_hid_open_mut);
133
134 /* The main device structure */
135 struct i2c_hid {
136         struct i2c_client       *client;        /* i2c client */
137         struct hid_device       *hid;   /* pointer to corresponding HID dev */
138         union {
139                 __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)];
140                 struct i2c_hid_desc hdesc;      /* the HID Descriptor */
141         };
142         __le16                  wHIDDescRegister; /* location of the i2c
143                                                    * register of the HID
144                                                    * descriptor. */
145         unsigned int            bufsize;        /* i2c buffer size */
146         u8                      *inbuf;         /* Input buffer */
147         u8                      *rawbuf;        /* Raw Input buffer */
148         u8                      *cmdbuf;        /* Command buffer */
149         u8                      *argsbuf;       /* Command arguments buffer */
150
151         unsigned long           flags;          /* device flags */
152         unsigned long           quirks;         /* Various quirks */
153
154         wait_queue_head_t       wait;           /* For waiting the interrupt */
155         struct gpio_desc        *desc;
156         int                     irq;
157
158         struct i2c_hid_platform_data pdata;
159
160         bool                    irq_wake_enabled;
161         struct mutex            reset_lock;
162 };
163
164 static const struct i2c_hid_quirks {
165         __u16 idVendor;
166         __u16 idProduct;
167         __u32 quirks;
168 } i2c_hid_quirks[] = {
169         { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752,
170                 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
171         { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755,
172                 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
173         { 0, 0 }
174 };
175
176 /*
177  * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device
178  * @idVendor: the 16-bit vendor ID
179  * @idProduct: the 16-bit product ID
180  *
181  * Returns: a u32 quirks value.
182  */
183 static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
184 {
185         u32 quirks = 0;
186         int n;
187
188         for (n = 0; i2c_hid_quirks[n].idVendor; n++)
189                 if (i2c_hid_quirks[n].idVendor == idVendor &&
190                     (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID ||
191                      i2c_hid_quirks[n].idProduct == idProduct))
192                         quirks = i2c_hid_quirks[n].quirks;
193
194         return quirks;
195 }
196
197 static int __i2c_hid_command(struct i2c_client *client,
198                 const struct i2c_hid_cmd *command, u8 reportID,
199                 u8 reportType, u8 *args, int args_len,
200                 unsigned char *buf_recv, int data_len)
201 {
202         struct i2c_hid *ihid = i2c_get_clientdata(client);
203         union command *cmd = (union command *)ihid->cmdbuf;
204         int ret;
205         struct i2c_msg msg[2];
206         int msg_num = 1;
207
208         int length = command->length;
209         bool wait = command->wait;
210         unsigned int registerIndex = command->registerIndex;
211
212         /* special case for hid_descr_cmd */
213         if (command == &hid_descr_cmd) {
214                 cmd->c.reg = ihid->wHIDDescRegister;
215         } else {
216                 cmd->data[0] = ihid->hdesc_buffer[registerIndex];
217                 cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1];
218         }
219
220         if (length > 2) {
221                 cmd->c.opcode = command->opcode;
222                 cmd->c.reportTypeID = reportID | reportType << 4;
223         }
224
225         memcpy(cmd->data + length, args, args_len);
226         length += args_len;
227
228         i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data);
229
230         msg[0].addr = client->addr;
231         msg[0].flags = client->flags & I2C_M_TEN;
232         msg[0].len = length;
233         msg[0].buf = cmd->data;
234         if (data_len > 0) {
235                 msg[1].addr = client->addr;
236                 msg[1].flags = client->flags & I2C_M_TEN;
237                 msg[1].flags |= I2C_M_RD;
238                 msg[1].len = data_len;
239                 msg[1].buf = buf_recv;
240                 msg_num = 2;
241                 set_bit(I2C_HID_READ_PENDING, &ihid->flags);
242         }
243
244         if (wait)
245                 set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
246
247         ret = i2c_transfer(client->adapter, msg, msg_num);
248
249         if (data_len > 0)
250                 clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
251
252         if (ret != msg_num)
253                 return ret < 0 ? ret : -EIO;
254
255         ret = 0;
256
257         if (wait) {
258                 i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
259                 if (!wait_event_timeout(ihid->wait,
260                                 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
261                                 msecs_to_jiffies(5000)))
262                         ret = -ENODATA;
263                 i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
264         }
265
266         return ret;
267 }
268
269 static int i2c_hid_command(struct i2c_client *client,
270                 const struct i2c_hid_cmd *command,
271                 unsigned char *buf_recv, int data_len)
272 {
273         return __i2c_hid_command(client, command, 0, 0, NULL, 0,
274                                 buf_recv, data_len);
275 }
276
277 static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
278                 u8 reportID, unsigned char *buf_recv, int data_len)
279 {
280         struct i2c_hid *ihid = i2c_get_clientdata(client);
281         u8 args[3];
282         int ret;
283         int args_len = 0;
284         u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
285
286         i2c_hid_dbg(ihid, "%s\n", __func__);
287
288         if (reportID >= 0x0F) {
289                 args[args_len++] = reportID;
290                 reportID = 0x0F;
291         }
292
293         args[args_len++] = readRegister & 0xFF;
294         args[args_len++] = readRegister >> 8;
295
296         ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
297                 reportType, args, args_len, buf_recv, data_len);
298         if (ret) {
299                 dev_err(&client->dev,
300                         "failed to retrieve report from device.\n");
301                 return ret;
302         }
303
304         return 0;
305 }
306
307 /**
308  * i2c_hid_set_or_send_report: forward an incoming report to the device
309  * @client: the i2c_client of the device
310  * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
311  * @reportID: the report ID
312  * @buf: the actual data to transfer, without the report ID
313  * @len: size of buf
314  * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
315  */
316 static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
317                 u8 reportID, unsigned char *buf, size_t data_len, bool use_data)
318 {
319         struct i2c_hid *ihid = i2c_get_clientdata(client);
320         u8 *args = ihid->argsbuf;
321         const struct i2c_hid_cmd *hidcmd;
322         int ret;
323         u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
324         u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister);
325         u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength);
326         u16 size;
327         int args_len;
328         int index = 0;
329
330         i2c_hid_dbg(ihid, "%s\n", __func__);
331
332         if (data_len > ihid->bufsize)
333                 return -EINVAL;
334
335         size =          2                       /* size */ +
336                         (reportID ? 1 : 0)      /* reportID */ +
337                         data_len                /* buf */;
338         args_len =      (reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
339                         2                       /* dataRegister */ +
340                         size                    /* args */;
341
342         if (!use_data && maxOutputLength == 0)
343                 return -ENOSYS;
344
345         if (reportID >= 0x0F) {
346                 args[index++] = reportID;
347                 reportID = 0x0F;
348         }
349
350         /*
351          * use the data register for feature reports or if the device does not
352          * support the output register
353          */
354         if (use_data) {
355                 args[index++] = dataRegister & 0xFF;
356                 args[index++] = dataRegister >> 8;
357                 hidcmd = &hid_set_report_cmd;
358         } else {
359                 args[index++] = outputRegister & 0xFF;
360                 args[index++] = outputRegister >> 8;
361                 hidcmd = &hid_no_cmd;
362         }
363
364         args[index++] = size & 0xFF;
365         args[index++] = size >> 8;
366
367         if (reportID)
368                 args[index++] = reportID;
369
370         memcpy(&args[index], buf, data_len);
371
372         ret = __i2c_hid_command(client, hidcmd, reportID,
373                 reportType, args, args_len, NULL, 0);
374         if (ret) {
375                 dev_err(&client->dev, "failed to set a report to device.\n");
376                 return ret;
377         }
378
379         return data_len;
380 }
381
382 static int i2c_hid_set_power(struct i2c_client *client, int power_state)
383 {
384         struct i2c_hid *ihid = i2c_get_clientdata(client);
385         int ret;
386
387         i2c_hid_dbg(ihid, "%s\n", __func__);
388
389         /*
390          * Some devices require to send a command to wakeup before power on.
391          * The call will get a return value (EREMOTEIO) but device will be
392          * triggered and activated. After that, it goes like a normal device.
393          */
394         if (power_state == I2C_HID_PWR_ON &&
395             ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
396                 ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0);
397
398                 /* Device was already activated */
399                 if (!ret)
400                         goto set_pwr_exit;
401         }
402
403         ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
404                 0, NULL, 0, NULL, 0);
405
406         if (ret)
407                 dev_err(&client->dev, "failed to change power setting.\n");
408
409 set_pwr_exit:
410
411         /*
412          * The HID over I2C specification states that if a DEVICE needs time
413          * after the PWR_ON request, it should utilise CLOCK stretching.
414          * However, it has been observered that the Windows driver provides a
415          * 1ms sleep between the PWR_ON and RESET requests.
416          * According to Goodix Windows even waits 60 ms after (other?)
417          * PWR_ON requests. Testing has confirmed that several devices
418          * will not work properly without a delay after a PWR_ON request.
419          */
420         if (!ret && power_state == I2C_HID_PWR_ON)
421                 msleep(60);
422
423         return ret;
424 }
425
426 static int i2c_hid_hwreset(struct i2c_client *client)
427 {
428         struct i2c_hid *ihid = i2c_get_clientdata(client);
429         int ret;
430
431         i2c_hid_dbg(ihid, "%s\n", __func__);
432
433         /*
434          * This prevents sending feature reports while the device is
435          * being reset. Otherwise we may lose the reset complete
436          * interrupt.
437          */
438         mutex_lock(&ihid->reset_lock);
439
440         ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
441         if (ret)
442                 goto out_unlock;
443
444         i2c_hid_dbg(ihid, "resetting...\n");
445
446         ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
447         if (ret) {
448                 dev_err(&client->dev, "failed to reset device.\n");
449                 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
450         }
451
452 out_unlock:
453         mutex_unlock(&ihid->reset_lock);
454         return ret;
455 }
456
457 static void i2c_hid_get_input(struct i2c_hid *ihid)
458 {
459         int ret;
460         u32 ret_size;
461         int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
462
463         if (size > ihid->bufsize)
464                 size = ihid->bufsize;
465
466         ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
467         if (ret != size) {
468                 if (ret < 0)
469                         return;
470
471                 dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n",
472                         __func__, ret, size);
473                 return;
474         }
475
476         ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8;
477
478         if (!ret_size) {
479                 /* host or device initiated RESET completed */
480                 if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
481                         wake_up(&ihid->wait);
482                 return;
483         }
484
485         if ((ret_size > size) || (ret_size < 2)) {
486                 dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
487                         __func__, size, ret_size);
488                 return;
489         }
490
491         i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);
492
493         if (test_bit(I2C_HID_STARTED, &ihid->flags))
494                 hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2,
495                                 ret_size - 2, 1);
496
497         return;
498 }
499
500 static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
501 {
502         struct i2c_hid *ihid = dev_id;
503
504         if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
505                 return IRQ_HANDLED;
506
507         i2c_hid_get_input(ihid);
508
509         return IRQ_HANDLED;
510 }
511
512 static int i2c_hid_get_report_length(struct hid_report *report)
513 {
514         return ((report->size - 1) >> 3) + 1 +
515                 report->device->report_enum[report->type].numbered + 2;
516 }
517
518 static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,
519         size_t bufsize)
520 {
521         struct hid_device *hid = report->device;
522         struct i2c_client *client = hid->driver_data;
523         struct i2c_hid *ihid = i2c_get_clientdata(client);
524         unsigned int size, ret_size;
525
526         size = i2c_hid_get_report_length(report);
527         if (i2c_hid_get_report(client,
528                         report->type == HID_FEATURE_REPORT ? 0x03 : 0x01,
529                         report->id, buffer, size))
530                 return;
531
532         i2c_hid_dbg(ihid, "report (len=%d): %*ph\n", size, size, buffer);
533
534         ret_size = buffer[0] | (buffer[1] << 8);
535
536         if (ret_size != size) {
537                 dev_err(&client->dev, "error in %s size:%d / ret_size:%d\n",
538                         __func__, size, ret_size);
539                 return;
540         }
541
542         /* hid->driver_lock is held as we are in probe function,
543          * we just need to setup the input fields, so using
544          * hid_report_raw_event is safe. */
545         hid_report_raw_event(hid, report->type, buffer + 2, size - 2, 1);
546 }
547
548 /*
549  * Initialize all reports
550  */
551 static void i2c_hid_init_reports(struct hid_device *hid)
552 {
553         struct hid_report *report;
554         struct i2c_client *client = hid->driver_data;
555         struct i2c_hid *ihid = i2c_get_clientdata(client);
556         u8 *inbuf = kzalloc(ihid->bufsize, GFP_KERNEL);
557
558         if (!inbuf) {
559                 dev_err(&client->dev, "can not retrieve initial reports\n");
560                 return;
561         }
562
563         /*
564          * The device must be powered on while we fetch initial reports
565          * from it.
566          */
567         pm_runtime_get_sync(&client->dev);
568
569         list_for_each_entry(report,
570                 &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
571                 i2c_hid_init_report(report, inbuf, ihid->bufsize);
572
573         pm_runtime_put(&client->dev);
574
575         kfree(inbuf);
576 }
577
578 /*
579  * Traverse the supplied list of reports and find the longest
580  */
581 static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type,
582                 unsigned int *max)
583 {
584         struct hid_report *report;
585         unsigned int size;
586
587         /* We should not rely on wMaxInputLength, as some devices may set it to
588          * a wrong length. */
589         list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
590                 size = i2c_hid_get_report_length(report);
591                 if (*max < size)
592                         *max = size;
593         }
594 }
595
596 static void i2c_hid_free_buffers(struct i2c_hid *ihid)
597 {
598         kfree(ihid->inbuf);
599         kfree(ihid->rawbuf);
600         kfree(ihid->argsbuf);
601         kfree(ihid->cmdbuf);
602         ihid->inbuf = NULL;
603         ihid->rawbuf = NULL;
604         ihid->cmdbuf = NULL;
605         ihid->argsbuf = NULL;
606         ihid->bufsize = 0;
607 }
608
609 static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size)
610 {
611         /* the worst case is computed from the set_report command with a
612          * reportID > 15 and the maximum report length */
613         int args_len = sizeof(__u8) + /* ReportID */
614                        sizeof(__u8) + /* optional ReportID byte */
615                        sizeof(__u16) + /* data register */
616                        sizeof(__u16) + /* size of the report */
617                        report_size; /* report */
618
619         ihid->inbuf = kzalloc(report_size, GFP_KERNEL);
620         ihid->rawbuf = kzalloc(report_size, GFP_KERNEL);
621         ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
622         ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);
623
624         if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) {
625                 i2c_hid_free_buffers(ihid);
626                 return -ENOMEM;
627         }
628
629         ihid->bufsize = report_size;
630
631         return 0;
632 }
633
634 static int i2c_hid_get_raw_report(struct hid_device *hid,
635                 unsigned char report_number, __u8 *buf, size_t count,
636                 unsigned char report_type)
637 {
638         struct i2c_client *client = hid->driver_data;
639         struct i2c_hid *ihid = i2c_get_clientdata(client);
640         size_t ret_count, ask_count;
641         int ret;
642
643         if (report_type == HID_OUTPUT_REPORT)
644                 return -EINVAL;
645
646         /* +2 bytes to include the size of the reply in the query buffer */
647         ask_count = min(count + 2, (size_t)ihid->bufsize);
648
649         ret = i2c_hid_get_report(client,
650                         report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
651                         report_number, ihid->rawbuf, ask_count);
652
653         if (ret < 0)
654                 return ret;
655
656         ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8);
657
658         if (ret_count <= 2)
659                 return 0;
660
661         ret_count = min(ret_count, ask_count);
662
663         /* The query buffer contains the size, dropping it in the reply */
664         count = min(count, ret_count - 2);
665         memcpy(buf, ihid->rawbuf + 2, count);
666
667         return count;
668 }
669
670 static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
671                 size_t count, unsigned char report_type, bool use_data)
672 {
673         struct i2c_client *client = hid->driver_data;
674         struct i2c_hid *ihid = i2c_get_clientdata(client);
675         int report_id = buf[0];
676         int ret;
677
678         if (report_type == HID_INPUT_REPORT)
679                 return -EINVAL;
680
681         mutex_lock(&ihid->reset_lock);
682
683         if (report_id) {
684                 buf++;
685                 count--;
686         }
687
688         ret = i2c_hid_set_or_send_report(client,
689                                 report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
690                                 report_id, buf, count, use_data);
691
692         if (report_id && ret >= 0)
693                 ret++; /* add report_id to the number of transfered bytes */
694
695         mutex_unlock(&ihid->reset_lock);
696
697         return ret;
698 }
699
700 static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf,
701                 size_t count)
702 {
703         return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT,
704                         false);
705 }
706
707 static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
708                                __u8 *buf, size_t len, unsigned char rtype,
709                                int reqtype)
710 {
711         switch (reqtype) {
712         case HID_REQ_GET_REPORT:
713                 return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype);
714         case HID_REQ_SET_REPORT:
715                 if (buf[0] != reportnum)
716                         return -EINVAL;
717                 return i2c_hid_output_raw_report(hid, buf, len, rtype, true);
718         default:
719                 return -EIO;
720         }
721 }
722
723 static int i2c_hid_parse(struct hid_device *hid)
724 {
725         struct i2c_client *client = hid->driver_data;
726         struct i2c_hid *ihid = i2c_get_clientdata(client);
727         struct i2c_hid_desc *hdesc = &ihid->hdesc;
728         unsigned int rsize;
729         char *rdesc;
730         int ret;
731         int tries = 3;
732         char *use_override;
733
734         i2c_hid_dbg(ihid, "entering %s\n", __func__);
735
736         rsize = le16_to_cpu(hdesc->wReportDescLength);
737         if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
738                 dbg_hid("weird size of report descriptor (%u)\n", rsize);
739                 return -EINVAL;
740         }
741
742         do {
743                 ret = i2c_hid_hwreset(client);
744                 if (ret)
745                         msleep(1000);
746         } while (tries-- > 0 && ret);
747
748         if (ret)
749                 return ret;
750
751         use_override = i2c_hid_get_dmi_hid_report_desc_override(client->name,
752                                                                 &rsize);
753
754         if (use_override) {
755                 rdesc = use_override;
756                 i2c_hid_dbg(ihid, "Using a HID report descriptor override\n");
757         } else {
758                 rdesc = kzalloc(rsize, GFP_KERNEL);
759
760                 if (!rdesc) {
761                         dbg_hid("couldn't allocate rdesc memory\n");
762                         return -ENOMEM;
763                 }
764
765                 i2c_hid_dbg(ihid, "asking HID report descriptor\n");
766
767                 ret = i2c_hid_command(client, &hid_report_descr_cmd,
768                                       rdesc, rsize);
769                 if (ret) {
770                         hid_err(hid, "reading report descriptor failed\n");
771                         kfree(rdesc);
772                         return -EIO;
773                 }
774         }
775
776         i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
777
778         ret = hid_parse_report(hid, rdesc, rsize);
779         if (!use_override)
780                 kfree(rdesc);
781
782         if (ret) {
783                 dbg_hid("parsing report descriptor failed\n");
784                 return ret;
785         }
786
787         return 0;
788 }
789
790 static int i2c_hid_start(struct hid_device *hid)
791 {
792         struct i2c_client *client = hid->driver_data;
793         struct i2c_hid *ihid = i2c_get_clientdata(client);
794         int ret;
795         unsigned int bufsize = HID_MIN_BUFFER_SIZE;
796
797         i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize);
798         i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize);
799         i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize);
800
801         if (bufsize > ihid->bufsize) {
802                 i2c_hid_free_buffers(ihid);
803
804                 ret = i2c_hid_alloc_buffers(ihid, bufsize);
805
806                 if (ret)
807                         return ret;
808         }
809
810         if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS))
811                 i2c_hid_init_reports(hid);
812
813         return 0;
814 }
815
816 static void i2c_hid_stop(struct hid_device *hid)
817 {
818         hid->claimed = 0;
819 }
820
821 static int i2c_hid_open(struct hid_device *hid)
822 {
823         struct i2c_client *client = hid->driver_data;
824         struct i2c_hid *ihid = i2c_get_clientdata(client);
825         int ret = 0;
826
827         mutex_lock(&i2c_hid_open_mut);
828         if (!hid->open++) {
829                 ret = pm_runtime_get_sync(&client->dev);
830                 if (ret < 0) {
831                         hid->open--;
832                         goto done;
833                 }
834                 set_bit(I2C_HID_STARTED, &ihid->flags);
835         }
836 done:
837         mutex_unlock(&i2c_hid_open_mut);
838         return ret < 0 ? ret : 0;
839 }
840
841 static void i2c_hid_close(struct hid_device *hid)
842 {
843         struct i2c_client *client = hid->driver_data;
844         struct i2c_hid *ihid = i2c_get_clientdata(client);
845
846         /* protecting hid->open to make sure we don't restart
847          * data acquistion due to a resumption we no longer
848          * care about
849          */
850         mutex_lock(&i2c_hid_open_mut);
851         if (!--hid->open) {
852                 clear_bit(I2C_HID_STARTED, &ihid->flags);
853
854                 /* Save some power */
855                 pm_runtime_put(&client->dev);
856         }
857         mutex_unlock(&i2c_hid_open_mut);
858 }
859
860 static int i2c_hid_power(struct hid_device *hid, int lvl)
861 {
862         struct i2c_client *client = hid->driver_data;
863         struct i2c_hid *ihid = i2c_get_clientdata(client);
864
865         i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);
866
867         switch (lvl) {
868         case PM_HINT_FULLON:
869                 pm_runtime_get_sync(&client->dev);
870                 break;
871         case PM_HINT_NORMAL:
872                 pm_runtime_put(&client->dev);
873                 break;
874         }
875         return 0;
876 }
877
878 struct hid_ll_driver i2c_hid_ll_driver = {
879         .parse = i2c_hid_parse,
880         .start = i2c_hid_start,
881         .stop = i2c_hid_stop,
882         .open = i2c_hid_open,
883         .close = i2c_hid_close,
884         .power = i2c_hid_power,
885         .output_report = i2c_hid_output_report,
886         .raw_request = i2c_hid_raw_request,
887 };
888 EXPORT_SYMBOL_GPL(i2c_hid_ll_driver);
889
890 static int i2c_hid_init_irq(struct i2c_client *client)
891 {
892         struct i2c_hid *ihid = i2c_get_clientdata(client);
893         int ret;
894
895         dev_dbg(&client->dev, "Requesting IRQ: %d\n", ihid->irq);
896
897         ret = request_threaded_irq(ihid->irq, NULL, i2c_hid_irq,
898                         IRQF_TRIGGER_LOW | IRQF_ONESHOT,
899                         client->name, ihid);
900         if (ret < 0) {
901                 dev_warn(&client->dev,
902                         "Could not register for %s interrupt, irq = %d,"
903                         " ret = %d\n",
904                         client->name, ihid->irq, ret);
905
906                 return ret;
907         }
908
909         return 0;
910 }
911
912 static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
913 {
914         struct i2c_client *client = ihid->client;
915         struct i2c_hid_desc *hdesc = &ihid->hdesc;
916         unsigned int dsize;
917         int ret;
918
919         /* i2c hid fetch using a fixed descriptor size (30 bytes) */
920         if (i2c_hid_get_dmi_i2c_hid_desc_override(client->name)) {
921                 i2c_hid_dbg(ihid, "Using a HID descriptor override\n");
922                 ihid->hdesc =
923                         *i2c_hid_get_dmi_i2c_hid_desc_override(client->name);
924         } else {
925                 i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
926                 ret = i2c_hid_command(client, &hid_descr_cmd,
927                                       ihid->hdesc_buffer,
928                                       sizeof(struct i2c_hid_desc));
929                 if (ret) {
930                         dev_err(&client->dev, "hid_descr_cmd failed\n");
931                         return -ENODEV;
932                 }
933         }
934
935         /* Validate the length of HID descriptor, the 4 first bytes:
936          * bytes 0-1 -> length
937          * bytes 2-3 -> bcdVersion (has to be 1.00) */
938         /* check bcdVersion == 1.0 */
939         if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
940                 dev_err(&client->dev,
941                         "unexpected HID descriptor bcdVersion (0x%04hx)\n",
942                         le16_to_cpu(hdesc->bcdVersion));
943                 return -ENODEV;
944         }
945
946         /* Descriptor length should be 30 bytes as per the specification */
947         dsize = le16_to_cpu(hdesc->wHIDDescLength);
948         if (dsize != sizeof(struct i2c_hid_desc)) {
949                 dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
950                         dsize);
951                 return -ENODEV;
952         }
953         i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
954         return 0;
955 }
956
957 #ifdef CONFIG_ACPI
958
959 /* Default GPIO mapping */
960 static const struct acpi_gpio_params i2c_hid_irq_gpio = { 0, 0, true };
961 static const struct acpi_gpio_mapping i2c_hid_acpi_gpios[] = {
962         { "gpios", &i2c_hid_irq_gpio, 1 },
963         { },
964 };
965
966 static int i2c_hid_acpi_pdata(struct i2c_client *client,
967                 struct i2c_hid_platform_data *pdata)
968 {
969         static u8 i2c_hid_guid[] = {
970                 0xF7, 0xF6, 0xDF, 0x3C, 0x67, 0x42, 0x55, 0x45,
971                 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE,
972         };
973         union acpi_object *obj;
974         struct acpi_device *adev;
975         acpi_handle handle;
976         int ret;
977
978         handle = ACPI_HANDLE(&client->dev);
979         if (!handle || acpi_bus_get_device(handle, &adev))
980                 return -ENODEV;
981
982         obj = acpi_evaluate_dsm_typed(handle, i2c_hid_guid, 1, 1, NULL,
983                                       ACPI_TYPE_INTEGER);
984         if (!obj) {
985                 dev_err(&client->dev, "device _DSM execution failed\n");
986                 return -ENODEV;
987         }
988
989         pdata->hid_descriptor_address = obj->integer.value;
990         ACPI_FREE(obj);
991
992         /* GPIOs are optional */
993         ret = acpi_dev_add_driver_gpios(adev, i2c_hid_acpi_gpios);
994         return ret < 0 && ret != -ENXIO ? ret : 0;
995 }
996
997 static void i2c_hid_acpi_fix_up_power(struct device *dev)
998 {
999         acpi_handle handle = ACPI_HANDLE(dev);
1000         struct acpi_device *adev;
1001
1002         if (handle && acpi_bus_get_device(handle, &adev) == 0)
1003                 acpi_device_fix_up_power(adev);
1004 }
1005
1006 static const struct acpi_device_id i2c_hid_acpi_match[] = {
1007         {"ACPI0C50", 0 },
1008         {"PNP0C50", 0 },
1009         { },
1010 };
1011 MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
1012 #else
1013 static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
1014                 struct i2c_hid_platform_data *pdata)
1015 {
1016         return -ENODEV;
1017 }
1018
1019 static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
1020 #endif
1021
1022 #ifdef CONFIG_OF
1023 static int i2c_hid_of_probe(struct i2c_client *client,
1024                 struct i2c_hid_platform_data *pdata)
1025 {
1026         struct device *dev = &client->dev;
1027         u32 val;
1028         int ret;
1029
1030         ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
1031         if (ret) {
1032                 dev_err(&client->dev, "HID register address not provided\n");
1033                 return -ENODEV;
1034         }
1035         if (val >> 16) {
1036                 dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
1037                         val);
1038                 return -EINVAL;
1039         }
1040         pdata->hid_descriptor_address = val;
1041
1042         return 0;
1043 }
1044
1045 static const struct of_device_id i2c_hid_of_match[] = {
1046         { .compatible = "hid-over-i2c" },
1047         {},
1048 };
1049 MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
1050 #else
1051 static inline int i2c_hid_of_probe(struct i2c_client *client,
1052                 struct i2c_hid_platform_data *pdata)
1053 {
1054         return -ENODEV;
1055 }
1056 #endif
1057
1058 static int i2c_hid_probe(struct i2c_client *client,
1059                          const struct i2c_device_id *dev_id)
1060 {
1061         int ret;
1062         struct i2c_hid *ihid;
1063         struct hid_device *hid;
1064         __u16 hidRegister;
1065         struct i2c_hid_platform_data *platform_data = client->dev.platform_data;
1066
1067         dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);
1068
1069         ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
1070         if (!ihid)
1071                 return -ENOMEM;
1072
1073         if (client->dev.of_node) {
1074                 ret = i2c_hid_of_probe(client, &ihid->pdata);
1075                 if (ret)
1076                         goto err;
1077         } else if (!platform_data) {
1078                 ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
1079                 if (ret) {
1080                         dev_err(&client->dev,
1081                                 "HID register address not provided\n");
1082                         goto err;
1083                 }
1084         } else {
1085                 ihid->pdata = *platform_data;
1086         }
1087
1088         if (client->irq > 0) {
1089                 ihid->irq = client->irq;
1090         } else if (ACPI_COMPANION(&client->dev)) {
1091                 ihid->desc = gpiod_get(&client->dev, NULL, GPIOD_IN);
1092                 if (IS_ERR(ihid->desc)) {
1093                         dev_err(&client->dev, "Failed to get GPIO interrupt\n");
1094                         return PTR_ERR(ihid->desc);
1095                 }
1096
1097                 ihid->irq = gpiod_to_irq(ihid->desc);
1098                 if (ihid->irq < 0) {
1099                         gpiod_put(ihid->desc);
1100                         dev_err(&client->dev, "Failed to convert GPIO to IRQ\n");
1101                         return ihid->irq;
1102                 }
1103         }
1104
1105         i2c_set_clientdata(client, ihid);
1106
1107         ihid->client = client;
1108
1109         hidRegister = ihid->pdata.hid_descriptor_address;
1110         ihid->wHIDDescRegister = cpu_to_le16(hidRegister);
1111
1112         init_waitqueue_head(&ihid->wait);
1113         mutex_init(&ihid->reset_lock);
1114
1115         /* we need to allocate the command buffer without knowing the maximum
1116          * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the
1117          * real computation later. */
1118         ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE);
1119         if (ret < 0)
1120                 goto err;
1121
1122         i2c_hid_acpi_fix_up_power(&client->dev);
1123
1124         pm_runtime_get_noresume(&client->dev);
1125         pm_runtime_set_active(&client->dev);
1126         pm_runtime_enable(&client->dev);
1127         device_enable_async_suspend(&client->dev);
1128
1129         /* Make sure there is something at this address */
1130         ret = i2c_smbus_read_byte(client);
1131         if (ret < 0) {
1132                 dev_dbg(&client->dev, "nothing at this address: %d\n", ret);
1133                 ret = -ENXIO;
1134                 goto err_pm;
1135         }
1136
1137         ret = i2c_hid_fetch_hid_descriptor(ihid);
1138         if (ret < 0)
1139                 goto err_pm;
1140
1141         ret = i2c_hid_init_irq(client);
1142         if (ret < 0)
1143                 goto err_pm;
1144
1145         hid = hid_allocate_device();
1146         if (IS_ERR(hid)) {
1147                 ret = PTR_ERR(hid);
1148                 goto err_irq;
1149         }
1150
1151         ihid->hid = hid;
1152
1153         hid->driver_data = client;
1154         hid->ll_driver = &i2c_hid_ll_driver;
1155         hid->dev.parent = &client->dev;
1156         hid->bus = BUS_I2C;
1157         hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
1158         hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
1159         hid->product = le16_to_cpu(ihid->hdesc.wProductID);
1160
1161         snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X",
1162                  client->name, (u16)hid->vendor, (u16)hid->product);
1163         strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys));
1164
1165         ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product);
1166
1167         ret = hid_add_device(hid);
1168         if (ret) {
1169                 if (ret != -ENODEV)
1170                         hid_err(client, "can't add hid device: %d\n", ret);
1171                 goto err_mem_free;
1172         }
1173
1174         pm_runtime_put(&client->dev);
1175         return 0;
1176
1177 err_mem_free:
1178         hid_destroy_device(hid);
1179
1180 err_irq:
1181         free_irq(ihid->irq, ihid);
1182
1183 err_pm:
1184         pm_runtime_put_noidle(&client->dev);
1185         pm_runtime_disable(&client->dev);
1186
1187 err:
1188         if (ihid->desc)
1189                 gpiod_put(ihid->desc);
1190
1191         i2c_hid_free_buffers(ihid);
1192         kfree(ihid);
1193         return ret;
1194 }
1195
1196 static int i2c_hid_remove(struct i2c_client *client)
1197 {
1198         struct i2c_hid *ihid = i2c_get_clientdata(client);
1199         struct hid_device *hid;
1200
1201         pm_runtime_get_sync(&client->dev);
1202         pm_runtime_disable(&client->dev);
1203         pm_runtime_set_suspended(&client->dev);
1204         pm_runtime_put_noidle(&client->dev);
1205
1206         hid = ihid->hid;
1207         hid_destroy_device(hid);
1208
1209         free_irq(ihid->irq, ihid);
1210
1211         if (ihid->bufsize)
1212                 i2c_hid_free_buffers(ihid);
1213
1214         if (ihid->desc)
1215                 gpiod_put(ihid->desc);
1216
1217         kfree(ihid);
1218
1219         acpi_dev_remove_driver_gpios(ACPI_COMPANION(&client->dev));
1220
1221         return 0;
1222 }
1223
1224 static void i2c_hid_shutdown(struct i2c_client *client)
1225 {
1226         struct i2c_hid *ihid = i2c_get_clientdata(client);
1227
1228         i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1229         free_irq(client->irq, ihid);
1230 }
1231
1232 #ifdef CONFIG_PM_SLEEP
1233 static int i2c_hid_suspend(struct device *dev)
1234 {
1235         struct i2c_client *client = to_i2c_client(dev);
1236         struct i2c_hid *ihid = i2c_get_clientdata(client);
1237         struct hid_device *hid = ihid->hid;
1238         int ret;
1239         int wake_status;
1240
1241         if (hid->driver && hid->driver->suspend) {
1242                 /*
1243                  * Wake up the device so that IO issues in
1244                  * HID driver's suspend code can succeed.
1245                  */
1246                 ret = pm_runtime_resume(dev);
1247                 if (ret < 0)
1248                         return ret;
1249
1250                 ret = hid->driver->suspend(hid, PMSG_SUSPEND);
1251                 if (ret < 0)
1252                         return ret;
1253         }
1254
1255         if (!pm_runtime_suspended(dev)) {
1256                 /* Save some power */
1257                 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1258
1259                 disable_irq(ihid->irq);
1260         }
1261
1262         if (device_may_wakeup(&client->dev)) {
1263                 wake_status = enable_irq_wake(ihid->irq);
1264                 if (!wake_status)
1265                         ihid->irq_wake_enabled = true;
1266                 else
1267                         hid_warn(hid, "Failed to enable irq wake: %d\n",
1268                                 wake_status);
1269         }
1270
1271         return 0;
1272 }
1273
1274 static int i2c_hid_resume(struct device *dev)
1275 {
1276         int ret;
1277         struct i2c_client *client = to_i2c_client(dev);
1278         struct i2c_hid *ihid = i2c_get_clientdata(client);
1279         struct hid_device *hid = ihid->hid;
1280         int wake_status;
1281
1282         if (device_may_wakeup(&client->dev) && ihid->irq_wake_enabled) {
1283                 wake_status = disable_irq_wake(ihid->irq);
1284                 if (!wake_status)
1285                         ihid->irq_wake_enabled = false;
1286                 else
1287                         hid_warn(hid, "Failed to disable irq wake: %d\n",
1288                                 wake_status);
1289         }
1290
1291         /* We'll resume to full power */
1292         pm_runtime_disable(dev);
1293         pm_runtime_set_active(dev);
1294         pm_runtime_enable(dev);
1295
1296         enable_irq(ihid->irq);
1297         ret = i2c_hid_hwreset(client);
1298         if (ret)
1299                 return ret;
1300
1301         if (hid->driver && hid->driver->reset_resume) {
1302                 ret = hid->driver->reset_resume(hid);
1303                 return ret;
1304         }
1305
1306         return 0;
1307 }
1308 #endif
1309
1310 #ifdef CONFIG_PM
1311 static int i2c_hid_runtime_suspend(struct device *dev)
1312 {
1313         struct i2c_client *client = to_i2c_client(dev);
1314         struct i2c_hid *ihid = i2c_get_clientdata(client);
1315
1316         i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1317         disable_irq(ihid->irq);
1318         return 0;
1319 }
1320
1321 static int i2c_hid_runtime_resume(struct device *dev)
1322 {
1323         struct i2c_client *client = to_i2c_client(dev);
1324         struct i2c_hid *ihid = i2c_get_clientdata(client);
1325
1326         enable_irq(ihid->irq);
1327         i2c_hid_set_power(client, I2C_HID_PWR_ON);
1328         return 0;
1329 }
1330 #endif
1331
1332 static const struct dev_pm_ops i2c_hid_pm = {
1333         SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
1334         SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume,
1335                            NULL)
1336 };
1337
1338 static const struct i2c_device_id i2c_hid_id_table[] = {
1339         { "hid", 0 },
1340         { "hid-over-i2c", 0 },
1341         { },
1342 };
1343 MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table);
1344
1345
1346 static struct i2c_driver i2c_hid_driver = {
1347         .driver = {
1348                 .name   = "i2c_hid",
1349                 .pm     = &i2c_hid_pm,
1350                 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1351                 .of_match_table = of_match_ptr(i2c_hid_of_match),
1352         },
1353
1354         .probe          = i2c_hid_probe,
1355         .remove         = i2c_hid_remove,
1356         .shutdown       = i2c_hid_shutdown,
1357         .id_table       = i2c_hid_id_table,
1358 };
1359
1360 module_i2c_driver(i2c_hid_driver);
1361
1362 MODULE_DESCRIPTION("HID over I2C core driver");
1363 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
1364 MODULE_LICENSE("GPL");