2 * HID over I2C protocol implementation
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
8 * This code is partly based on "USB HID support for Linux":
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
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
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>
28 #include <linux/device.h>
29 #include <linux/wait.h>
30 #include <linux/err.h>
31 #include <linux/string.h>
32 #include <linux/list.h>
33 #include <linux/jiffies.h>
34 #include <linux/kernel.h>
35 #include <linux/bug.h>
36 #include <linux/hid.h>
38 #include <linux/i2c/i2c-hid.h>
41 #define I2C_HID_STARTED (1 << 0)
42 #define I2C_HID_RESET_PENDING (1 << 1)
43 #define I2C_HID_READ_PENDING (1 << 2)
45 #define I2C_HID_PWR_ON 0x00
46 #define I2C_HID_PWR_SLEEP 0x01
50 module_param(debug, bool, 0444);
51 MODULE_PARM_DESC(debug, "print a lot of debug information");
53 #define i2c_hid_dbg(ihid, fmt, arg...) \
56 dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
60 __le16 wHIDDescLength;
62 __le16 wReportDescLength;
63 __le16 wReportDescRegister;
64 __le16 wInputRegister;
65 __le16 wMaxInputLength;
66 __le16 wOutputRegister;
67 __le16 wMaxOutputLength;
68 __le16 wCommandRegister;
76 unsigned int registerIndex;
91 #define I2C_HID_CMD(opcode_) \
92 .opcode = opcode_, .length = 4, \
93 .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister)
95 /* fetch HID descriptor */
96 static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 };
97 /* fetch report descriptors */
98 static const struct i2c_hid_cmd hid_report_descr_cmd = {
99 .registerIndex = offsetof(struct i2c_hid_desc,
100 wReportDescRegister),
104 static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01),
106 static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) };
107 static const struct i2c_hid_cmd hid_set_report_cmd = { I2C_HID_CMD(0x03) };
108 static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) };
109 static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) };
110 static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) };
111 static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
112 static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) };
113 /* read/write data register */
114 static const struct i2c_hid_cmd hid_data_cmd = {
115 .registerIndex = offsetof(struct i2c_hid_desc, wDataRegister),
118 /* write output reports */
119 static const struct i2c_hid_cmd hid_out_cmd = {
120 .registerIndex = offsetof(struct i2c_hid_desc,
125 /* The main device structure */
127 struct i2c_client *client; /* i2c client */
128 struct hid_device *hid; /* pointer to corresponding HID dev */
130 __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)];
131 struct i2c_hid_desc hdesc; /* the HID Descriptor */
133 __le16 wHIDDescRegister; /* location of the i2c
134 * register of the HID
136 unsigned int bufsize; /* i2c buffer size */
137 char *inbuf; /* Input buffer */
138 char *cmdbuf; /* Command buffer */
139 char *argsbuf; /* Command arguments buffer */
141 unsigned long flags; /* device flags */
143 int irq; /* the interrupt line irq */
145 wait_queue_head_t wait; /* For waiting the interrupt */
148 static int __i2c_hid_command(struct i2c_client *client,
149 const struct i2c_hid_cmd *command, u8 reportID,
150 u8 reportType, u8 *args, int args_len,
151 unsigned char *buf_recv, int data_len)
153 struct i2c_hid *ihid = i2c_get_clientdata(client);
154 union command *cmd = (union command *)ihid->cmdbuf;
156 struct i2c_msg msg[2];
159 int length = command->length;
160 bool wait = command->wait;
161 unsigned int registerIndex = command->registerIndex;
163 /* special case for hid_descr_cmd */
164 if (command == &hid_descr_cmd) {
165 cmd->c.reg = ihid->wHIDDescRegister;
167 cmd->data[0] = ihid->hdesc_buffer[registerIndex];
168 cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1];
172 cmd->c.opcode = command->opcode;
173 cmd->c.reportTypeID = reportID | reportType << 4;
176 memcpy(cmd->data + length, args, args_len);
179 i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data);
181 msg[0].addr = client->addr;
182 msg[0].flags = client->flags & I2C_M_TEN;
184 msg[0].buf = cmd->data;
186 msg[1].addr = client->addr;
187 msg[1].flags = client->flags & I2C_M_TEN;
188 msg[1].flags |= I2C_M_RD;
189 msg[1].len = data_len;
190 msg[1].buf = buf_recv;
192 set_bit(I2C_HID_READ_PENDING, &ihid->flags);
196 set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
198 ret = i2c_transfer(client->adapter, msg, msg_num);
201 clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
204 return ret < 0 ? ret : -EIO;
209 i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
210 if (!wait_event_timeout(ihid->wait,
211 !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
212 msecs_to_jiffies(5000)))
214 i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
220 static int i2c_hid_command(struct i2c_client *client,
221 const struct i2c_hid_cmd *command,
222 unsigned char *buf_recv, int data_len)
224 return __i2c_hid_command(client, command, 0, 0, NULL, 0,
228 static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
229 u8 reportID, unsigned char *buf_recv, int data_len)
231 struct i2c_hid *ihid = i2c_get_clientdata(client);
235 u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
237 i2c_hid_dbg(ihid, "%s\n", __func__);
239 if (reportID >= 0x0F) {
240 args[args_len++] = reportID;
244 args[args_len++] = readRegister & 0xFF;
245 args[args_len++] = readRegister >> 8;
247 ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
248 reportType, args, args_len, buf_recv, data_len);
250 dev_err(&client->dev,
251 "failed to retrieve report from device.\n");
258 static int i2c_hid_set_report(struct i2c_client *client, u8 reportType,
259 u8 reportID, unsigned char *buf, size_t data_len)
261 struct i2c_hid *ihid = i2c_get_clientdata(client);
262 u8 *args = ihid->argsbuf;
264 u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
266 /* hidraw already checked that data_len < HID_MAX_BUFFER_SIZE */
267 u16 size = 2 /* size */ +
268 (reportID ? 1 : 0) /* reportID */ +
270 int args_len = (reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
271 2 /* dataRegister */ +
275 i2c_hid_dbg(ihid, "%s\n", __func__);
277 if (reportID >= 0x0F) {
278 args[index++] = reportID;
282 args[index++] = dataRegister & 0xFF;
283 args[index++] = dataRegister >> 8;
285 args[index++] = size & 0xFF;
286 args[index++] = size >> 8;
289 args[index++] = reportID;
291 memcpy(&args[index], buf, data_len);
293 ret = __i2c_hid_command(client, &hid_set_report_cmd, reportID,
294 reportType, args, args_len, NULL, 0);
296 dev_err(&client->dev, "failed to set a report to device.\n");
303 static int i2c_hid_set_power(struct i2c_client *client, int power_state)
305 struct i2c_hid *ihid = i2c_get_clientdata(client);
308 i2c_hid_dbg(ihid, "%s\n", __func__);
310 ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
311 0, NULL, 0, NULL, 0);
313 dev_err(&client->dev, "failed to change power setting.\n");
318 static int i2c_hid_hwreset(struct i2c_client *client)
320 struct i2c_hid *ihid = i2c_get_clientdata(client);
323 i2c_hid_dbg(ihid, "%s\n", __func__);
325 ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
329 i2c_hid_dbg(ihid, "resetting...\n");
331 ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
333 dev_err(&client->dev, "failed to reset device.\n");
334 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
341 static int i2c_hid_get_input(struct i2c_hid *ihid)
344 int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
346 ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
351 dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n",
352 __func__, ret, size);
356 ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8;
359 /* host or device initiated RESET completed */
360 if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
361 wake_up(&ihid->wait);
365 if (ret_size > size) {
366 dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
367 __func__, size, ret_size);
371 i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);
373 if (test_bit(I2C_HID_STARTED, &ihid->flags))
374 hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2,
380 static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
382 struct i2c_hid *ihid = dev_id;
384 if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
387 i2c_hid_get_input(ihid);
392 static int i2c_hid_get_report_length(struct hid_report *report)
394 return ((report->size - 1) >> 3) + 1 +
395 report->device->report_enum[report->type].numbered + 2;
398 static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,
401 struct hid_device *hid = report->device;
402 struct i2c_client *client = hid->driver_data;
403 struct i2c_hid *ihid = i2c_get_clientdata(client);
404 unsigned int size, ret_size;
406 size = i2c_hid_get_report_length(report);
407 i2c_hid_get_report(client,
408 report->type == HID_FEATURE_REPORT ? 0x03 : 0x01,
409 report->id, buffer, size);
411 i2c_hid_dbg(ihid, "report (len=%d): %*ph\n", size, size, ihid->inbuf);
413 ret_size = buffer[0] | (buffer[1] << 8);
415 if (ret_size != size) {
416 dev_err(&client->dev, "error in %s size:%d / ret_size:%d\n",
417 __func__, size, ret_size);
421 /* hid->driver_lock is held as we are in probe function,
422 * we just need to setup the input fields, so using
423 * hid_report_raw_event is safe. */
424 hid_report_raw_event(hid, report->type, buffer + 2, size - 2, 1);
428 * Initialize all reports
430 static void i2c_hid_init_reports(struct hid_device *hid)
432 struct hid_report *report;
433 struct i2c_client *client = hid->driver_data;
434 struct i2c_hid *ihid = i2c_get_clientdata(client);
435 u8 *inbuf = kzalloc(ihid->bufsize, GFP_KERNEL);
440 list_for_each_entry(report,
441 &hid->report_enum[HID_INPUT_REPORT].report_list, list)
442 i2c_hid_init_report(report, inbuf, ihid->bufsize);
444 list_for_each_entry(report,
445 &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
446 i2c_hid_init_report(report, inbuf, ihid->bufsize);
452 * Traverse the supplied list of reports and find the longest
454 static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type,
457 struct hid_report *report;
460 /* We should not rely on wMaxInputLength, as some devices may set it to
462 list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
463 size = i2c_hid_get_report_length(report);
469 static int i2c_hid_alloc_buffers(struct i2c_hid *ihid)
471 /* the worst case is computed from the set_report command with a
472 * reportID > 15 and the maximum report length */
473 int args_len = sizeof(__u8) + /* optional ReportID byte */
474 sizeof(__u16) + /* data register */
475 sizeof(__u16) + /* size of the report */
476 ihid->bufsize; /* report */
478 ihid->inbuf = kzalloc(ihid->bufsize, GFP_KERNEL);
483 ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
485 if (!ihid->argsbuf) {
490 ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);
494 kfree(ihid->argsbuf);
496 ihid->argsbuf = NULL;
503 static void i2c_hid_free_buffers(struct i2c_hid *ihid)
506 kfree(ihid->argsbuf);
510 ihid->argsbuf = NULL;
513 static int i2c_hid_get_raw_report(struct hid_device *hid,
514 unsigned char report_number, __u8 *buf, size_t count,
515 unsigned char report_type)
517 struct i2c_client *client = hid->driver_data;
518 struct i2c_hid *ihid = i2c_get_clientdata(client);
521 if (report_type == HID_OUTPUT_REPORT)
524 if (count > ihid->bufsize)
525 count = ihid->bufsize;
527 ret = i2c_hid_get_report(client,
528 report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
529 report_number, ihid->inbuf, count);
534 count = ihid->inbuf[0] | (ihid->inbuf[1] << 8);
536 memcpy(buf, ihid->inbuf + 2, count);
541 static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
542 size_t count, unsigned char report_type)
544 struct i2c_client *client = hid->driver_data;
545 int report_id = buf[0];
547 if (report_type == HID_INPUT_REPORT)
550 return i2c_hid_set_report(client,
551 report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
552 report_id, buf, count);
555 static int i2c_hid_parse(struct hid_device *hid)
557 struct i2c_client *client = hid->driver_data;
558 struct i2c_hid *ihid = i2c_get_clientdata(client);
559 struct i2c_hid_desc *hdesc = &ihid->hdesc;
565 i2c_hid_dbg(ihid, "entering %s\n", __func__);
567 rsize = le16_to_cpu(hdesc->wReportDescLength);
568 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
569 dbg_hid("weird size of report descriptor (%u)\n", rsize);
574 ret = i2c_hid_hwreset(client);
577 } while (tries-- > 0 && ret);
582 rdesc = kzalloc(rsize, GFP_KERNEL);
585 dbg_hid("couldn't allocate rdesc memory\n");
589 i2c_hid_dbg(ihid, "asking HID report descriptor\n");
591 ret = i2c_hid_command(client, &hid_report_descr_cmd, rdesc, rsize);
593 hid_err(hid, "reading report descriptor failed\n");
598 i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
600 ret = hid_parse_report(hid, rdesc, rsize);
603 dbg_hid("parsing report descriptor failed\n");
610 static int i2c_hid_start(struct hid_device *hid)
612 struct i2c_client *client = hid->driver_data;
613 struct i2c_hid *ihid = i2c_get_clientdata(client);
615 int old_bufsize = ihid->bufsize;
617 ihid->bufsize = HID_MIN_BUFFER_SIZE;
618 i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &ihid->bufsize);
619 i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &ihid->bufsize);
620 i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &ihid->bufsize);
622 if (ihid->bufsize > old_bufsize || !ihid->inbuf || !ihid->cmdbuf) {
623 i2c_hid_free_buffers(ihid);
625 ret = i2c_hid_alloc_buffers(ihid);
628 ihid->bufsize = old_bufsize;
633 if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS))
634 i2c_hid_init_reports(hid);
639 static void i2c_hid_stop(struct hid_device *hid)
641 struct i2c_client *client = hid->driver_data;
642 struct i2c_hid *ihid = i2c_get_clientdata(client);
646 i2c_hid_free_buffers(ihid);
649 static int i2c_hid_open(struct hid_device *hid)
651 struct i2c_client *client = hid->driver_data;
652 struct i2c_hid *ihid = i2c_get_clientdata(client);
656 ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
661 set_bit(I2C_HID_STARTED, &ihid->flags);
666 static void i2c_hid_close(struct hid_device *hid)
668 struct i2c_client *client = hid->driver_data;
669 struct i2c_hid *ihid = i2c_get_clientdata(client);
671 /* protecting hid->open to make sure we don't restart
672 * data acquistion due to a resumption we no longer
676 clear_bit(I2C_HID_STARTED, &ihid->flags);
678 /* Save some power */
679 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
683 static int i2c_hid_power(struct hid_device *hid, int lvl)
685 struct i2c_client *client = hid->driver_data;
686 struct i2c_hid *ihid = i2c_get_clientdata(client);
689 i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);
693 ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
696 ret = i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
702 static int i2c_hid_hidinput_input_event(struct input_dev *dev,
703 unsigned int type, unsigned int code, int value)
705 struct hid_device *hid = input_get_drvdata(dev);
706 struct hid_field *field;
710 return input_ff_event(dev, type, code, value);
715 offset = hidinput_find_field(hid, type, code, &field);
718 hid_warn(dev, "event field not found\n");
722 hid_set_field(field, offset, value);
727 static struct hid_ll_driver i2c_hid_ll_driver = {
728 .parse = i2c_hid_parse,
729 .start = i2c_hid_start,
730 .stop = i2c_hid_stop,
731 .open = i2c_hid_open,
732 .close = i2c_hid_close,
733 .power = i2c_hid_power,
734 .hidinput_input_event = i2c_hid_hidinput_input_event,
737 static int __devinit i2c_hid_init_irq(struct i2c_client *client)
739 struct i2c_hid *ihid = i2c_get_clientdata(client);
742 dev_dbg(&client->dev, "Requesting IRQ: %d\n", client->irq);
744 ret = request_threaded_irq(client->irq, NULL, i2c_hid_irq,
745 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
748 dev_dbg(&client->dev,
749 "Could not register for %s interrupt, irq = %d,"
751 client->name, client->irq, ret);
756 ihid->irq = client->irq;
761 static int __devinit i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
763 struct i2c_client *client = ihid->client;
764 struct i2c_hid_desc *hdesc = &ihid->hdesc;
768 /* Fetch the length of HID description, retrieve the 4 first bytes:
769 * bytes 0-1 -> length
770 * bytes 2-3 -> bcdVersion (has to be 1.00) */
771 ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, 4);
773 i2c_hid_dbg(ihid, "%s, ihid->hdesc_buffer: %*ph\n",
774 __func__, 4, ihid->hdesc_buffer);
777 dev_err(&client->dev, "HID_DESCR_LENGTH_CMD Fail (ret=%d)\n",
782 dsize = le16_to_cpu(hdesc->wHIDDescLength);
783 if (!dsize || dsize > HID_MAX_DESCRIPTOR_SIZE) {
784 dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
789 /* check bcdVersion == 1.0 */
790 if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
791 dev_err(&client->dev,
792 "unexpected HID descriptor bcdVersion (0x%04x)\n",
793 le16_to_cpu(hdesc->bcdVersion));
797 i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
799 ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer,
802 dev_err(&client->dev, "hid_descr_cmd Fail\n");
806 i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
811 static int __devinit i2c_hid_probe(struct i2c_client *client,
812 const struct i2c_device_id *dev_id)
815 struct i2c_hid *ihid;
816 struct hid_device *hid;
818 struct i2c_hid_platform_data *platform_data = client->dev.platform_data;
820 dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);
822 if (!platform_data) {
823 dev_err(&client->dev, "HID register address not provided\n");
828 dev_err(&client->dev,
829 "HID over i2c has not been provided an Int IRQ\n");
833 ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
837 i2c_set_clientdata(client, ihid);
839 ihid->client = client;
841 hidRegister = platform_data->hid_descriptor_address;
842 ihid->wHIDDescRegister = cpu_to_le16(hidRegister);
844 init_waitqueue_head(&ihid->wait);
846 /* we need to allocate the command buffer without knowing the maximum
847 * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the
848 * real computation later. */
849 ihid->bufsize = HID_MIN_BUFFER_SIZE;
850 i2c_hid_alloc_buffers(ihid);
852 ret = i2c_hid_fetch_hid_descriptor(ihid);
856 ret = i2c_hid_init_irq(client);
860 hid = hid_allocate_device();
868 hid->driver_data = client;
869 hid->ll_driver = &i2c_hid_ll_driver;
870 hid->hid_get_raw_report = i2c_hid_get_raw_report;
871 hid->hid_output_raw_report = i2c_hid_output_raw_report;
872 hid->dev.parent = &client->dev;
874 hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
875 hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
876 hid->product = le16_to_cpu(ihid->hdesc.wProductID);
878 snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X",
879 client->name, hid->vendor, hid->product);
881 ret = hid_add_device(hid);
884 hid_err(client, "can't add hid device: %d\n", ret);
891 hid_destroy_device(hid);
895 free_irq(ihid->irq, ihid);
897 i2c_hid_free_buffers(ihid);
902 static int __devexit i2c_hid_remove(struct i2c_client *client)
904 struct i2c_hid *ihid = i2c_get_clientdata(client);
905 struct hid_device *hid;
911 hid_destroy_device(hid);
913 free_irq(client->irq, ihid);
920 #ifdef CONFIG_PM_SLEEP
921 static int i2c_hid_suspend(struct device *dev)
923 struct i2c_client *client = to_i2c_client(dev);
924 struct i2c_hid *ihid = i2c_get_clientdata(client);
926 if (device_may_wakeup(&client->dev))
927 enable_irq_wake(ihid->irq);
929 /* Save some power */
930 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
935 static int i2c_hid_resume(struct device *dev)
938 struct i2c_client *client = to_i2c_client(dev);
940 ret = i2c_hid_hwreset(client);
944 if (device_may_wakeup(&client->dev))
945 disable_irq_wake(client->irq);
951 static SIMPLE_DEV_PM_OPS(i2c_hid_pm, i2c_hid_suspend, i2c_hid_resume);
953 static const struct i2c_device_id i2c_hid_id_table[] = {
957 MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table);
960 static struct i2c_driver i2c_hid_driver = {
963 .owner = THIS_MODULE,
967 .probe = i2c_hid_probe,
968 .remove = __devexit_p(i2c_hid_remove),
970 .id_table = i2c_hid_id_table,
973 module_i2c_driver(i2c_hid_driver);
975 MODULE_DESCRIPTION("HID over I2C core driver");
976 MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
977 MODULE_LICENSE("GPL");