i2c-hid.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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. #include <linux/module.h>
  21. #include <linux/i2c.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/input.h>
  24. #include <linux/irq.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/regulator/consumer.h>
  41. #include <linux/i2c/i2c-hid.h>
  42. #include "../hid-ids.h"
  43. /* quirks to control the device */
  44. #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
  45. /* flags */
  46. #define I2C_HID_STARTED 0
  47. #define I2C_HID_RESET_PENDING 1
  48. #define I2C_HID_READ_PENDING 2
  49. #define I2C_HID_PWR_ON 0x00
  50. #define I2C_HID_PWR_SLEEP 0x01
  51. /* debug option */
  52. static bool debug;
  53. module_param(debug, bool, 0444);
  54. MODULE_PARM_DESC(debug, "print a lot of debug information");
  55. #define i2c_hid_dbg(ihid, fmt, arg...) \
  56. do { \
  57. if (debug) \
  58. dev_printk(KERN_DEBUG, &(ihid)->client->dev, fmt, ##arg); \
  59. } while (0)
  60. struct i2c_hid_desc {
  61. __le16 wHIDDescLength;
  62. __le16 bcdVersion;
  63. __le16 wReportDescLength;
  64. __le16 wReportDescRegister;
  65. __le16 wInputRegister;
  66. __le16 wMaxInputLength;
  67. __le16 wOutputRegister;
  68. __le16 wMaxOutputLength;
  69. __le16 wCommandRegister;
  70. __le16 wDataRegister;
  71. __le16 wVendorID;
  72. __le16 wProductID;
  73. __le16 wVersionID;
  74. __le32 reserved;
  75. } __packed;
  76. struct i2c_hid_cmd {
  77. unsigned int registerIndex;
  78. __u8 opcode;
  79. unsigned int length;
  80. bool wait;
  81. };
  82. union command {
  83. u8 data[0];
  84. struct cmd {
  85. __le16 reg;
  86. __u8 reportTypeID;
  87. __u8 opcode;
  88. } __packed c;
  89. };
  90. #define I2C_HID_CMD(opcode_) \
  91. .opcode = opcode_, .length = 4, \
  92. .registerIndex = offsetof(struct i2c_hid_desc, wCommandRegister)
  93. /* fetch HID descriptor */
  94. static const struct i2c_hid_cmd hid_descr_cmd = { .length = 2 };
  95. /* fetch report descriptors */
  96. static const struct i2c_hid_cmd hid_report_descr_cmd = {
  97. .registerIndex = offsetof(struct i2c_hid_desc,
  98. wReportDescRegister),
  99. .opcode = 0x00,
  100. .length = 2 };
  101. /* commands */
  102. static const struct i2c_hid_cmd hid_reset_cmd = { I2C_HID_CMD(0x01),
  103. .wait = true };
  104. static const struct i2c_hid_cmd hid_get_report_cmd = { I2C_HID_CMD(0x02) };
  105. static const struct i2c_hid_cmd hid_set_report_cmd = { I2C_HID_CMD(0x03) };
  106. static const struct i2c_hid_cmd hid_set_power_cmd = { I2C_HID_CMD(0x08) };
  107. static const struct i2c_hid_cmd hid_no_cmd = { .length = 0 };
  108. /*
  109. * These definitions are not used here, but are defined by the spec.
  110. * Keeping them here for documentation purposes.
  111. *
  112. * static const struct i2c_hid_cmd hid_get_idle_cmd = { I2C_HID_CMD(0x04) };
  113. * static const struct i2c_hid_cmd hid_set_idle_cmd = { I2C_HID_CMD(0x05) };
  114. * static const struct i2c_hid_cmd hid_get_protocol_cmd = { I2C_HID_CMD(0x06) };
  115. * static const struct i2c_hid_cmd hid_set_protocol_cmd = { I2C_HID_CMD(0x07) };
  116. */
  117. static DEFINE_MUTEX(i2c_hid_open_mut);
  118. /* The main device structure */
  119. struct i2c_hid {
  120. struct i2c_client *client; /* i2c client */
  121. struct hid_device *hid; /* pointer to corresponding HID dev */
  122. union {
  123. __u8 hdesc_buffer[sizeof(struct i2c_hid_desc)];
  124. struct i2c_hid_desc hdesc; /* the HID Descriptor */
  125. };
  126. __le16 wHIDDescRegister; /* location of the i2c
  127. * register of the HID
  128. * descriptor. */
  129. unsigned int bufsize; /* i2c buffer size */
  130. char *inbuf; /* Input buffer */
  131. char *rawbuf; /* Raw Input buffer */
  132. char *cmdbuf; /* Command buffer */
  133. char *argsbuf; /* Command arguments buffer */
  134. unsigned long flags; /* device flags */
  135. unsigned long quirks; /* Various quirks */
  136. wait_queue_head_t wait; /* For waiting the interrupt */
  137. struct i2c_hid_platform_data pdata;
  138. bool irq_wake_enabled;
  139. struct mutex reset_lock;
  140. };
  141. static const struct i2c_hid_quirks {
  142. __u16 idVendor;
  143. __u16 idProduct;
  144. __u32 quirks;
  145. } i2c_hid_quirks[] = {
  146. { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752,
  147. I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
  148. { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755,
  149. I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
  150. { 0, 0 }
  151. };
  152. /*
  153. * i2c_hid_lookup_quirk: return any quirks associated with a I2C HID device
  154. * @idVendor: the 16-bit vendor ID
  155. * @idProduct: the 16-bit product ID
  156. *
  157. * Returns: a u32 quirks value.
  158. */
  159. static u32 i2c_hid_lookup_quirk(const u16 idVendor, const u16 idProduct)
  160. {
  161. u32 quirks = 0;
  162. int n;
  163. for (n = 0; i2c_hid_quirks[n].idVendor; n++)
  164. if (i2c_hid_quirks[n].idVendor == idVendor &&
  165. (i2c_hid_quirks[n].idProduct == (__u16)HID_ANY_ID ||
  166. i2c_hid_quirks[n].idProduct == idProduct))
  167. quirks = i2c_hid_quirks[n].quirks;
  168. return quirks;
  169. }
  170. static int __i2c_hid_command(struct i2c_client *client,
  171. const struct i2c_hid_cmd *command, u8 reportID,
  172. u8 reportType, u8 *args, int args_len,
  173. unsigned char *buf_recv, int data_len)
  174. {
  175. struct i2c_hid *ihid = i2c_get_clientdata(client);
  176. union command *cmd = (union command *)ihid->cmdbuf;
  177. int ret;
  178. struct i2c_msg msg[2];
  179. int msg_num = 1;
  180. int length = command->length;
  181. bool wait = command->wait;
  182. unsigned int registerIndex = command->registerIndex;
  183. /* special case for hid_descr_cmd */
  184. if (command == &hid_descr_cmd) {
  185. cmd->c.reg = ihid->wHIDDescRegister;
  186. } else {
  187. cmd->data[0] = ihid->hdesc_buffer[registerIndex];
  188. cmd->data[1] = ihid->hdesc_buffer[registerIndex + 1];
  189. }
  190. if (length > 2) {
  191. cmd->c.opcode = command->opcode;
  192. cmd->c.reportTypeID = reportID | reportType << 4;
  193. }
  194. memcpy(cmd->data + length, args, args_len);
  195. length += args_len;
  196. i2c_hid_dbg(ihid, "%s: cmd=%*ph\n", __func__, length, cmd->data);
  197. msg[0].addr = client->addr;
  198. msg[0].flags = client->flags & I2C_M_TEN;
  199. msg[0].len = length;
  200. msg[0].buf = cmd->data;
  201. if (data_len > 0) {
  202. msg[1].addr = client->addr;
  203. msg[1].flags = client->flags & I2C_M_TEN;
  204. msg[1].flags |= I2C_M_RD;
  205. msg[1].len = data_len;
  206. msg[1].buf = buf_recv;
  207. msg_num = 2;
  208. set_bit(I2C_HID_READ_PENDING, &ihid->flags);
  209. }
  210. if (wait)
  211. set_bit(I2C_HID_RESET_PENDING, &ihid->flags);
  212. ret = i2c_transfer(client->adapter, msg, msg_num);
  213. if (data_len > 0)
  214. clear_bit(I2C_HID_READ_PENDING, &ihid->flags);
  215. if (ret != msg_num)
  216. return ret < 0 ? ret : -EIO;
  217. ret = 0;
  218. if (wait) {
  219. i2c_hid_dbg(ihid, "%s: waiting...\n", __func__);
  220. if (!wait_event_timeout(ihid->wait,
  221. !test_bit(I2C_HID_RESET_PENDING, &ihid->flags),
  222. msecs_to_jiffies(5000)))
  223. ret = -ENODATA;
  224. i2c_hid_dbg(ihid, "%s: finished.\n", __func__);
  225. }
  226. return ret;
  227. }
  228. static int i2c_hid_command(struct i2c_client *client,
  229. const struct i2c_hid_cmd *command,
  230. unsigned char *buf_recv, int data_len)
  231. {
  232. return __i2c_hid_command(client, command, 0, 0, NULL, 0,
  233. buf_recv, data_len);
  234. }
  235. static int i2c_hid_get_report(struct i2c_client *client, u8 reportType,
  236. u8 reportID, unsigned char *buf_recv, int data_len)
  237. {
  238. struct i2c_hid *ihid = i2c_get_clientdata(client);
  239. u8 args[3];
  240. int ret;
  241. int args_len = 0;
  242. u16 readRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
  243. i2c_hid_dbg(ihid, "%s\n", __func__);
  244. if (reportID >= 0x0F) {
  245. args[args_len++] = reportID;
  246. reportID = 0x0F;
  247. }
  248. args[args_len++] = readRegister & 0xFF;
  249. args[args_len++] = readRegister >> 8;
  250. ret = __i2c_hid_command(client, &hid_get_report_cmd, reportID,
  251. reportType, args, args_len, buf_recv, data_len);
  252. if (ret) {
  253. dev_err(&client->dev,
  254. "failed to retrieve report from device.\n");
  255. return ret;
  256. }
  257. return 0;
  258. }
  259. /**
  260. * i2c_hid_set_or_send_report: forward an incoming report to the device
  261. * @client: the i2c_client of the device
  262. * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
  263. * @reportID: the report ID
  264. * @buf: the actual data to transfer, without the report ID
  265. * @len: size of buf
  266. * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
  267. */
  268. static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
  269. u8 reportID, unsigned char *buf, size_t data_len, bool use_data)
  270. {
  271. struct i2c_hid *ihid = i2c_get_clientdata(client);
  272. u8 *args = ihid->argsbuf;
  273. const struct i2c_hid_cmd *hidcmd;
  274. int ret;
  275. u16 dataRegister = le16_to_cpu(ihid->hdesc.wDataRegister);
  276. u16 outputRegister = le16_to_cpu(ihid->hdesc.wOutputRegister);
  277. u16 maxOutputLength = le16_to_cpu(ihid->hdesc.wMaxOutputLength);
  278. u16 size;
  279. int args_len;
  280. int index = 0;
  281. i2c_hid_dbg(ihid, "%s\n", __func__);
  282. if (data_len > ihid->bufsize)
  283. return -EINVAL;
  284. size = 2 /* size */ +
  285. (reportID ? 1 : 0) /* reportID */ +
  286. data_len /* buf */;
  287. args_len = (reportID >= 0x0F ? 1 : 0) /* optional third byte */ +
  288. 2 /* dataRegister */ +
  289. size /* args */;
  290. if (!use_data && maxOutputLength == 0)
  291. return -ENOSYS;
  292. if (reportID >= 0x0F) {
  293. args[index++] = reportID;
  294. reportID = 0x0F;
  295. }
  296. /*
  297. * use the data register for feature reports or if the device does not
  298. * support the output register
  299. */
  300. if (use_data) {
  301. args[index++] = dataRegister & 0xFF;
  302. args[index++] = dataRegister >> 8;
  303. hidcmd = &hid_set_report_cmd;
  304. } else {
  305. args[index++] = outputRegister & 0xFF;
  306. args[index++] = outputRegister >> 8;
  307. hidcmd = &hid_no_cmd;
  308. }
  309. args[index++] = size & 0xFF;
  310. args[index++] = size >> 8;
  311. if (reportID)
  312. args[index++] = reportID;
  313. memcpy(&args[index], buf, data_len);
  314. ret = __i2c_hid_command(client, hidcmd, reportID,
  315. reportType, args, args_len, NULL, 0);
  316. if (ret) {
  317. dev_err(&client->dev, "failed to set a report to device.\n");
  318. return ret;
  319. }
  320. return data_len;
  321. }
  322. static int i2c_hid_set_power(struct i2c_client *client, int power_state)
  323. {
  324. struct i2c_hid *ihid = i2c_get_clientdata(client);
  325. int ret;
  326. i2c_hid_dbg(ihid, "%s\n", __func__);
  327. /*
  328. * Some devices require to send a command to wakeup before power on.
  329. * The call will get a return value (EREMOTEIO) but device will be
  330. * triggered and activated. After that, it goes like a normal device.
  331. */
  332. if (power_state == I2C_HID_PWR_ON &&
  333. ihid->quirks & I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV) {
  334. ret = i2c_hid_command(client, &hid_set_power_cmd, NULL, 0);
  335. /* Device was already activated */
  336. if (!ret)
  337. goto set_pwr_exit;
  338. }
  339. ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
  340. 0, NULL, 0, NULL, 0);
  341. if (ret)
  342. dev_err(&client->dev, "failed to change power setting.\n");
  343. set_pwr_exit:
  344. return ret;
  345. }
  346. static int i2c_hid_hwreset(struct i2c_client *client)
  347. {
  348. struct i2c_hid *ihid = i2c_get_clientdata(client);
  349. int ret;
  350. i2c_hid_dbg(ihid, "%s\n", __func__);
  351. /*
  352. * This prevents sending feature reports while the device is
  353. * being reset. Otherwise we may lose the reset complete
  354. * interrupt.
  355. */
  356. mutex_lock(&ihid->reset_lock);
  357. ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
  358. if (ret)
  359. goto out_unlock;
  360. /*
  361. * The HID over I2C specification states that if a DEVICE needs time
  362. * after the PWR_ON request, it should utilise CLOCK stretching.
  363. * However, it has been observered that the Windows driver provides a
  364. * 1ms sleep between the PWR_ON and RESET requests and that some devices
  365. * rely on this.
  366. */
  367. usleep_range(1000, 5000);
  368. i2c_hid_dbg(ihid, "resetting...\n");
  369. ret = i2c_hid_command(client, &hid_reset_cmd, NULL, 0);
  370. if (ret) {
  371. dev_err(&client->dev, "failed to reset device.\n");
  372. i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
  373. }
  374. out_unlock:
  375. mutex_unlock(&ihid->reset_lock);
  376. return ret;
  377. }
  378. static void i2c_hid_get_input(struct i2c_hid *ihid)
  379. {
  380. int ret, ret_size;
  381. int size = le16_to_cpu(ihid->hdesc.wMaxInputLength);
  382. if (size > ihid->bufsize)
  383. size = ihid->bufsize;
  384. ret = i2c_master_recv(ihid->client, ihid->inbuf, size);
  385. if (ret != size) {
  386. if (ret < 0)
  387. return;
  388. dev_err(&ihid->client->dev, "%s: got %d data instead of %d\n",
  389. __func__, ret, size);
  390. return;
  391. }
  392. ret_size = ihid->inbuf[0] | ihid->inbuf[1] << 8;
  393. if (!ret_size) {
  394. /* host or device initiated RESET completed */
  395. if (test_and_clear_bit(I2C_HID_RESET_PENDING, &ihid->flags))
  396. wake_up(&ihid->wait);
  397. return;
  398. }
  399. if (ret_size > size) {
  400. dev_err(&ihid->client->dev, "%s: incomplete report (%d/%d)\n",
  401. __func__, size, ret_size);
  402. return;
  403. }
  404. i2c_hid_dbg(ihid, "input: %*ph\n", ret_size, ihid->inbuf);
  405. if (test_bit(I2C_HID_STARTED, &ihid->flags))
  406. hid_input_report(ihid->hid, HID_INPUT_REPORT, ihid->inbuf + 2,
  407. ret_size - 2, 1);
  408. return;
  409. }
  410. static irqreturn_t i2c_hid_irq(int irq, void *dev_id)
  411. {
  412. struct i2c_hid *ihid = dev_id;
  413. if (test_bit(I2C_HID_READ_PENDING, &ihid->flags))
  414. return IRQ_HANDLED;
  415. i2c_hid_get_input(ihid);
  416. return IRQ_HANDLED;
  417. }
  418. static int i2c_hid_get_report_length(struct hid_report *report)
  419. {
  420. return ((report->size - 1) >> 3) + 1 +
  421. report->device->report_enum[report->type].numbered + 2;
  422. }
  423. static void i2c_hid_init_report(struct hid_report *report, u8 *buffer,
  424. size_t bufsize)
  425. {
  426. struct hid_device *hid = report->device;
  427. struct i2c_client *client = hid->driver_data;
  428. struct i2c_hid *ihid = i2c_get_clientdata(client);
  429. unsigned int size, ret_size;
  430. size = i2c_hid_get_report_length(report);
  431. if (i2c_hid_get_report(client,
  432. report->type == HID_FEATURE_REPORT ? 0x03 : 0x01,
  433. report->id, buffer, size))
  434. return;
  435. i2c_hid_dbg(ihid, "report (len=%d): %*ph\n", size, size, buffer);
  436. ret_size = buffer[0] | (buffer[1] << 8);
  437. if (ret_size != size) {
  438. dev_err(&client->dev, "error in %s size:%d / ret_size:%d\n",
  439. __func__, size, ret_size);
  440. return;
  441. }
  442. /* hid->driver_lock is held as we are in probe function,
  443. * we just need to setup the input fields, so using
  444. * hid_report_raw_event is safe. */
  445. hid_report_raw_event(hid, report->type, buffer + 2, size - 2, 1);
  446. }
  447. /*
  448. * Initialize all reports
  449. */
  450. static void i2c_hid_init_reports(struct hid_device *hid)
  451. {
  452. struct hid_report *report;
  453. struct i2c_client *client = hid->driver_data;
  454. struct i2c_hid *ihid = i2c_get_clientdata(client);
  455. u8 *inbuf = kzalloc(ihid->bufsize, GFP_KERNEL);
  456. if (!inbuf) {
  457. dev_err(&client->dev, "can not retrieve initial reports\n");
  458. return;
  459. }
  460. /*
  461. * The device must be powered on while we fetch initial reports
  462. * from it.
  463. */
  464. pm_runtime_get_sync(&client->dev);
  465. list_for_each_entry(report,
  466. &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
  467. i2c_hid_init_report(report, inbuf, ihid->bufsize);
  468. pm_runtime_put(&client->dev);
  469. kfree(inbuf);
  470. }
  471. /*
  472. * Traverse the supplied list of reports and find the longest
  473. */
  474. static void i2c_hid_find_max_report(struct hid_device *hid, unsigned int type,
  475. unsigned int *max)
  476. {
  477. struct hid_report *report;
  478. unsigned int size;
  479. /* We should not rely on wMaxInputLength, as some devices may set it to
  480. * a wrong length. */
  481. list_for_each_entry(report, &hid->report_enum[type].report_list, list) {
  482. size = i2c_hid_get_report_length(report);
  483. if (*max < size)
  484. *max = size;
  485. }
  486. }
  487. static void i2c_hid_free_buffers(struct i2c_hid *ihid)
  488. {
  489. kfree(ihid->inbuf);
  490. kfree(ihid->rawbuf);
  491. kfree(ihid->argsbuf);
  492. kfree(ihid->cmdbuf);
  493. ihid->inbuf = NULL;
  494. ihid->rawbuf = NULL;
  495. ihid->cmdbuf = NULL;
  496. ihid->argsbuf = NULL;
  497. ihid->bufsize = 0;
  498. }
  499. static int i2c_hid_alloc_buffers(struct i2c_hid *ihid, size_t report_size)
  500. {
  501. /* the worst case is computed from the set_report command with a
  502. * reportID > 15 and the maximum report length */
  503. int args_len = sizeof(__u8) + /* optional ReportID byte */
  504. sizeof(__u16) + /* data register */
  505. sizeof(__u16) + /* size of the report */
  506. report_size; /* report */
  507. ihid->inbuf = kzalloc(report_size, GFP_KERNEL);
  508. ihid->rawbuf = kzalloc(report_size, GFP_KERNEL);
  509. ihid->argsbuf = kzalloc(args_len, GFP_KERNEL);
  510. ihid->cmdbuf = kzalloc(sizeof(union command) + args_len, GFP_KERNEL);
  511. if (!ihid->inbuf || !ihid->rawbuf || !ihid->argsbuf || !ihid->cmdbuf) {
  512. i2c_hid_free_buffers(ihid);
  513. return -ENOMEM;
  514. }
  515. ihid->bufsize = report_size;
  516. return 0;
  517. }
  518. static int i2c_hid_get_raw_report(struct hid_device *hid,
  519. unsigned char report_number, __u8 *buf, size_t count,
  520. unsigned char report_type)
  521. {
  522. struct i2c_client *client = hid->driver_data;
  523. struct i2c_hid *ihid = i2c_get_clientdata(client);
  524. size_t ret_count, ask_count;
  525. int ret;
  526. if (report_type == HID_OUTPUT_REPORT)
  527. return -EINVAL;
  528. /* +2 bytes to include the size of the reply in the query buffer */
  529. ask_count = min(count + 2, (size_t)ihid->bufsize);
  530. ret = i2c_hid_get_report(client,
  531. report_type == HID_FEATURE_REPORT ? 0x03 : 0x01,
  532. report_number, ihid->rawbuf, ask_count);
  533. if (ret < 0)
  534. return ret;
  535. ret_count = ihid->rawbuf[0] | (ihid->rawbuf[1] << 8);
  536. if (ret_count <= 2)
  537. return 0;
  538. ret_count = min(ret_count, ask_count);
  539. /* The query buffer contains the size, dropping it in the reply */
  540. count = min(count, ret_count - 2);
  541. memcpy(buf, ihid->rawbuf + 2, count);
  542. return count;
  543. }
  544. static int i2c_hid_output_raw_report(struct hid_device *hid, __u8 *buf,
  545. size_t count, unsigned char report_type, bool use_data)
  546. {
  547. struct i2c_client *client = hid->driver_data;
  548. struct i2c_hid *ihid = i2c_get_clientdata(client);
  549. int report_id = buf[0];
  550. int ret;
  551. if (report_type == HID_INPUT_REPORT)
  552. return -EINVAL;
  553. mutex_lock(&ihid->reset_lock);
  554. if (report_id) {
  555. buf++;
  556. count--;
  557. }
  558. ret = i2c_hid_set_or_send_report(client,
  559. report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
  560. report_id, buf, count, use_data);
  561. if (report_id && ret >= 0)
  562. ret++; /* add report_id to the number of transfered bytes */
  563. mutex_unlock(&ihid->reset_lock);
  564. return ret;
  565. }
  566. static int i2c_hid_output_report(struct hid_device *hid, __u8 *buf,
  567. size_t count)
  568. {
  569. return i2c_hid_output_raw_report(hid, buf, count, HID_OUTPUT_REPORT,
  570. false);
  571. }
  572. static int i2c_hid_raw_request(struct hid_device *hid, unsigned char reportnum,
  573. __u8 *buf, size_t len, unsigned char rtype,
  574. int reqtype)
  575. {
  576. switch (reqtype) {
  577. case HID_REQ_GET_REPORT:
  578. return i2c_hid_get_raw_report(hid, reportnum, buf, len, rtype);
  579. case HID_REQ_SET_REPORT:
  580. if (buf[0] != reportnum)
  581. return -EINVAL;
  582. return i2c_hid_output_raw_report(hid, buf, len, rtype, true);
  583. default:
  584. return -EIO;
  585. }
  586. }
  587. static int i2c_hid_parse(struct hid_device *hid)
  588. {
  589. struct i2c_client *client = hid->driver_data;
  590. struct i2c_hid *ihid = i2c_get_clientdata(client);
  591. struct i2c_hid_desc *hdesc = &ihid->hdesc;
  592. unsigned int rsize;
  593. char *rdesc;
  594. int ret;
  595. int tries = 3;
  596. i2c_hid_dbg(ihid, "entering %s\n", __func__);
  597. rsize = le16_to_cpu(hdesc->wReportDescLength);
  598. if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
  599. dbg_hid("weird size of report descriptor (%u)\n", rsize);
  600. return -EINVAL;
  601. }
  602. do {
  603. ret = i2c_hid_hwreset(client);
  604. if (ret)
  605. msleep(1000);
  606. } while (tries-- > 0 && ret);
  607. if (ret)
  608. return ret;
  609. rdesc = kzalloc(rsize, GFP_KERNEL);
  610. if (!rdesc) {
  611. dbg_hid("couldn't allocate rdesc memory\n");
  612. return -ENOMEM;
  613. }
  614. i2c_hid_dbg(ihid, "asking HID report descriptor\n");
  615. ret = i2c_hid_command(client, &hid_report_descr_cmd, rdesc, rsize);
  616. if (ret) {
  617. hid_err(hid, "reading report descriptor failed\n");
  618. kfree(rdesc);
  619. return -EIO;
  620. }
  621. i2c_hid_dbg(ihid, "Report Descriptor: %*ph\n", rsize, rdesc);
  622. ret = hid_parse_report(hid, rdesc, rsize);
  623. kfree(rdesc);
  624. if (ret) {
  625. dbg_hid("parsing report descriptor failed\n");
  626. return ret;
  627. }
  628. return 0;
  629. }
  630. static int i2c_hid_start(struct hid_device *hid)
  631. {
  632. struct i2c_client *client = hid->driver_data;
  633. struct i2c_hid *ihid = i2c_get_clientdata(client);
  634. int ret;
  635. unsigned int bufsize = HID_MIN_BUFFER_SIZE;
  636. i2c_hid_find_max_report(hid, HID_INPUT_REPORT, &bufsize);
  637. i2c_hid_find_max_report(hid, HID_OUTPUT_REPORT, &bufsize);
  638. i2c_hid_find_max_report(hid, HID_FEATURE_REPORT, &bufsize);
  639. if (bufsize > ihid->bufsize) {
  640. disable_irq(client->irq);
  641. i2c_hid_free_buffers(ihid);
  642. ret = i2c_hid_alloc_buffers(ihid, bufsize);
  643. enable_irq(client->irq);
  644. if (ret)
  645. return ret;
  646. }
  647. if (!(hid->quirks & HID_QUIRK_NO_INIT_REPORTS))
  648. i2c_hid_init_reports(hid);
  649. return 0;
  650. }
  651. static void i2c_hid_stop(struct hid_device *hid)
  652. {
  653. hid->claimed = 0;
  654. }
  655. static int i2c_hid_open(struct hid_device *hid)
  656. {
  657. struct i2c_client *client = hid->driver_data;
  658. struct i2c_hid *ihid = i2c_get_clientdata(client);
  659. int ret = 0;
  660. mutex_lock(&i2c_hid_open_mut);
  661. if (!hid->open++) {
  662. ret = pm_runtime_get_sync(&client->dev);
  663. if (ret < 0) {
  664. hid->open--;
  665. goto done;
  666. }
  667. set_bit(I2C_HID_STARTED, &ihid->flags);
  668. }
  669. done:
  670. mutex_unlock(&i2c_hid_open_mut);
  671. return ret < 0 ? ret : 0;
  672. }
  673. static void i2c_hid_close(struct hid_device *hid)
  674. {
  675. struct i2c_client *client = hid->driver_data;
  676. struct i2c_hid *ihid = i2c_get_clientdata(client);
  677. /* protecting hid->open to make sure we don't restart
  678. * data acquistion due to a resumption we no longer
  679. * care about
  680. */
  681. mutex_lock(&i2c_hid_open_mut);
  682. if (!--hid->open) {
  683. clear_bit(I2C_HID_STARTED, &ihid->flags);
  684. /* Save some power */
  685. pm_runtime_put(&client->dev);
  686. }
  687. mutex_unlock(&i2c_hid_open_mut);
  688. }
  689. static int i2c_hid_power(struct hid_device *hid, int lvl)
  690. {
  691. struct i2c_client *client = hid->driver_data;
  692. struct i2c_hid *ihid = i2c_get_clientdata(client);
  693. i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);
  694. switch (lvl) {
  695. case PM_HINT_FULLON:
  696. pm_runtime_get_sync(&client->dev);
  697. break;
  698. case PM_HINT_NORMAL:
  699. pm_runtime_put(&client->dev);
  700. break;
  701. }
  702. return 0;
  703. }
  704. static struct hid_ll_driver i2c_hid_ll_driver = {
  705. .parse = i2c_hid_parse,
  706. .start = i2c_hid_start,
  707. .stop = i2c_hid_stop,
  708. .open = i2c_hid_open,
  709. .close = i2c_hid_close,
  710. .power = i2c_hid_power,
  711. .output_report = i2c_hid_output_report,
  712. .raw_request = i2c_hid_raw_request,
  713. };
  714. static int i2c_hid_init_irq(struct i2c_client *client)
  715. {
  716. struct i2c_hid *ihid = i2c_get_clientdata(client);
  717. unsigned long irqflags = 0;
  718. int ret;
  719. dev_dbg(&client->dev, "Requesting IRQ: %d\n", client->irq);
  720. if (!irq_get_trigger_type(client->irq))
  721. irqflags = IRQF_TRIGGER_LOW;
  722. ret = request_threaded_irq(client->irq, NULL, i2c_hid_irq,
  723. irqflags | IRQF_ONESHOT, client->name, ihid);
  724. if (ret < 0) {
  725. dev_warn(&client->dev,
  726. "Could not register for %s interrupt, irq = %d,"
  727. " ret = %d\n",
  728. client->name, client->irq, ret);
  729. return ret;
  730. }
  731. return 0;
  732. }
  733. static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid)
  734. {
  735. struct i2c_client *client = ihid->client;
  736. struct i2c_hid_desc *hdesc = &ihid->hdesc;
  737. unsigned int dsize;
  738. int ret;
  739. /* i2c hid fetch using a fixed descriptor size (30 bytes) */
  740. i2c_hid_dbg(ihid, "Fetching the HID descriptor\n");
  741. ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer,
  742. sizeof(struct i2c_hid_desc));
  743. if (ret) {
  744. dev_err(&client->dev, "hid_descr_cmd failed\n");
  745. return -ENODEV;
  746. }
  747. /* Validate the length of HID descriptor, the 4 first bytes:
  748. * bytes 0-1 -> length
  749. * bytes 2-3 -> bcdVersion (has to be 1.00) */
  750. /* check bcdVersion == 1.0 */
  751. if (le16_to_cpu(hdesc->bcdVersion) != 0x0100) {
  752. dev_err(&client->dev,
  753. "unexpected HID descriptor bcdVersion (0x%04hx)\n",
  754. le16_to_cpu(hdesc->bcdVersion));
  755. return -ENODEV;
  756. }
  757. /* Descriptor length should be 30 bytes as per the specification */
  758. dsize = le16_to_cpu(hdesc->wHIDDescLength);
  759. if (dsize != sizeof(struct i2c_hid_desc)) {
  760. dev_err(&client->dev, "weird size of HID descriptor (%u)\n",
  761. dsize);
  762. return -ENODEV;
  763. }
  764. i2c_hid_dbg(ihid, "HID Descriptor: %*ph\n", dsize, ihid->hdesc_buffer);
  765. return 0;
  766. }
  767. #ifdef CONFIG_ACPI
  768. static int i2c_hid_acpi_pdata(struct i2c_client *client,
  769. struct i2c_hid_platform_data *pdata)
  770. {
  771. static u8 i2c_hid_guid[] = {
  772. 0xF7, 0xF6, 0xDF, 0x3C, 0x67, 0x42, 0x55, 0x45,
  773. 0xAD, 0x05, 0xB3, 0x0A, 0x3D, 0x89, 0x38, 0xDE,
  774. };
  775. union acpi_object *obj;
  776. struct acpi_device *adev;
  777. acpi_handle handle;
  778. handle = ACPI_HANDLE(&client->dev);
  779. if (!handle || acpi_bus_get_device(handle, &adev))
  780. return -ENODEV;
  781. obj = acpi_evaluate_dsm_typed(handle, i2c_hid_guid, 1, 1, NULL,
  782. ACPI_TYPE_INTEGER);
  783. if (!obj) {
  784. dev_err(&client->dev, "device _DSM execution failed\n");
  785. return -ENODEV;
  786. }
  787. pdata->hid_descriptor_address = obj->integer.value;
  788. ACPI_FREE(obj);
  789. return 0;
  790. }
  791. static const struct acpi_device_id i2c_hid_acpi_match[] = {
  792. {"ACPI0C50", 0 },
  793. {"PNP0C50", 0 },
  794. { },
  795. };
  796. MODULE_DEVICE_TABLE(acpi, i2c_hid_acpi_match);
  797. #else
  798. static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
  799. struct i2c_hid_platform_data *pdata)
  800. {
  801. return -ENODEV;
  802. }
  803. #endif
  804. #ifdef CONFIG_OF
  805. static int i2c_hid_of_probe(struct i2c_client *client,
  806. struct i2c_hid_platform_data *pdata)
  807. {
  808. struct device *dev = &client->dev;
  809. u32 val;
  810. int ret;
  811. ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
  812. if (ret) {
  813. dev_err(&client->dev, "HID register address not provided\n");
  814. return -ENODEV;
  815. }
  816. if (val >> 16) {
  817. dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
  818. val);
  819. return -EINVAL;
  820. }
  821. pdata->hid_descriptor_address = val;
  822. return 0;
  823. }
  824. static const struct of_device_id i2c_hid_of_match[] = {
  825. { .compatible = "hid-over-i2c" },
  826. {},
  827. };
  828. MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
  829. #else
  830. static inline int i2c_hid_of_probe(struct i2c_client *client,
  831. struct i2c_hid_platform_data *pdata)
  832. {
  833. return -ENODEV;
  834. }
  835. #endif
  836. static int i2c_hid_probe(struct i2c_client *client,
  837. const struct i2c_device_id *dev_id)
  838. {
  839. int ret;
  840. struct i2c_hid *ihid;
  841. struct hid_device *hid;
  842. __u16 hidRegister;
  843. struct i2c_hid_platform_data *platform_data = client->dev.platform_data;
  844. dbg_hid("HID probe called for i2c 0x%02x\n", client->addr);
  845. if (!client->irq) {
  846. dev_err(&client->dev,
  847. "HID over i2c has not been provided an Int IRQ\n");
  848. return -EINVAL;
  849. }
  850. if (client->irq < 0) {
  851. if (client->irq != -EPROBE_DEFER)
  852. dev_err(&client->dev,
  853. "HID over i2c doesn't have a valid IRQ\n");
  854. return client->irq;
  855. }
  856. ihid = kzalloc(sizeof(struct i2c_hid), GFP_KERNEL);
  857. if (!ihid)
  858. return -ENOMEM;
  859. if (client->dev.of_node) {
  860. ret = i2c_hid_of_probe(client, &ihid->pdata);
  861. if (ret)
  862. goto err;
  863. } else if (!platform_data) {
  864. ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
  865. if (ret) {
  866. dev_err(&client->dev,
  867. "HID register address not provided\n");
  868. goto err;
  869. }
  870. } else {
  871. ihid->pdata = *platform_data;
  872. }
  873. i2c_set_clientdata(client, ihid);
  874. ihid->client = client;
  875. hidRegister = ihid->pdata.hid_descriptor_address;
  876. ihid->wHIDDescRegister = cpu_to_le16(hidRegister);
  877. init_waitqueue_head(&ihid->wait);
  878. mutex_init(&ihid->reset_lock);
  879. /* we need to allocate the command buffer without knowing the maximum
  880. * size of the reports. Let's use HID_MIN_BUFFER_SIZE, then we do the
  881. * real computation later. */
  882. ret = i2c_hid_alloc_buffers(ihid, HID_MIN_BUFFER_SIZE);
  883. if (ret < 0)
  884. goto err;
  885. pm_runtime_get_noresume(&client->dev);
  886. pm_runtime_set_active(&client->dev);
  887. pm_runtime_enable(&client->dev);
  888. device_enable_async_suspend(&client->dev);
  889. ret = i2c_hid_fetch_hid_descriptor(ihid);
  890. if (ret < 0)
  891. goto err_pm;
  892. ret = i2c_hid_init_irq(client);
  893. if (ret < 0)
  894. goto err_pm;
  895. hid = hid_allocate_device();
  896. if (IS_ERR(hid)) {
  897. ret = PTR_ERR(hid);
  898. goto err_irq;
  899. }
  900. ihid->hid = hid;
  901. hid->driver_data = client;
  902. hid->ll_driver = &i2c_hid_ll_driver;
  903. hid->dev.parent = &client->dev;
  904. hid->bus = BUS_I2C;
  905. hid->version = le16_to_cpu(ihid->hdesc.bcdVersion);
  906. hid->vendor = le16_to_cpu(ihid->hdesc.wVendorID);
  907. hid->product = le16_to_cpu(ihid->hdesc.wProductID);
  908. snprintf(hid->name, sizeof(hid->name), "%s %04hX:%04hX",
  909. client->name, hid->vendor, hid->product);
  910. strlcpy(hid->phys, dev_name(&client->dev), sizeof(hid->phys));
  911. ihid->quirks = i2c_hid_lookup_quirk(hid->vendor, hid->product);
  912. ret = hid_add_device(hid);
  913. if (ret) {
  914. if (ret != -ENODEV)
  915. hid_err(client, "can't add hid device: %d\n", ret);
  916. goto err_mem_free;
  917. }
  918. pm_runtime_put(&client->dev);
  919. return 0;
  920. err_mem_free:
  921. hid_destroy_device(hid);
  922. err_irq:
  923. free_irq(client->irq, ihid);
  924. err_pm:
  925. pm_runtime_put_noidle(&client->dev);
  926. pm_runtime_disable(&client->dev);
  927. err:
  928. i2c_hid_free_buffers(ihid);
  929. kfree(ihid);
  930. return ret;
  931. }
  932. static int i2c_hid_remove(struct i2c_client *client)
  933. {
  934. struct i2c_hid *ihid = i2c_get_clientdata(client);
  935. struct hid_device *hid;
  936. pm_runtime_get_sync(&client->dev);
  937. pm_runtime_disable(&client->dev);
  938. pm_runtime_set_suspended(&client->dev);
  939. pm_runtime_put_noidle(&client->dev);
  940. hid = ihid->hid;
  941. hid_destroy_device(hid);
  942. free_irq(client->irq, ihid);
  943. if (ihid->bufsize)
  944. i2c_hid_free_buffers(ihid);
  945. kfree(ihid);
  946. return 0;
  947. }
  948. static void i2c_hid_shutdown(struct i2c_client *client)
  949. {
  950. struct i2c_hid *ihid = i2c_get_clientdata(client);
  951. i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
  952. free_irq(client->irq, ihid);
  953. }
  954. #ifdef CONFIG_PM_SLEEP
  955. static int i2c_hid_suspend(struct device *dev)
  956. {
  957. struct i2c_client *client = to_i2c_client(dev);
  958. struct i2c_hid *ihid = i2c_get_clientdata(client);
  959. struct hid_device *hid = ihid->hid;
  960. int ret;
  961. int wake_status;
  962. if (hid->driver && hid->driver->suspend) {
  963. /*
  964. * Wake up the device so that IO issues in
  965. * HID driver's suspend code can succeed.
  966. */
  967. ret = pm_runtime_resume(dev);
  968. if (ret < 0)
  969. return ret;
  970. ret = hid->driver->suspend(hid, PMSG_SUSPEND);
  971. if (ret < 0)
  972. return ret;
  973. }
  974. if (!pm_runtime_suspended(dev)) {
  975. /* Save some power */
  976. i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
  977. disable_irq(client->irq);
  978. }
  979. if (device_may_wakeup(&client->dev)) {
  980. wake_status = enable_irq_wake(client->irq);
  981. if (!wake_status)
  982. ihid->irq_wake_enabled = true;
  983. else
  984. hid_warn(hid, "Failed to enable irq wake: %d\n",
  985. wake_status);
  986. }
  987. return 0;
  988. }
  989. static int i2c_hid_resume(struct device *dev)
  990. {
  991. int ret;
  992. struct i2c_client *client = to_i2c_client(dev);
  993. struct i2c_hid *ihid = i2c_get_clientdata(client);
  994. struct hid_device *hid = ihid->hid;
  995. int wake_status;
  996. if (device_may_wakeup(&client->dev) && ihid->irq_wake_enabled) {
  997. wake_status = disable_irq_wake(client->irq);
  998. if (!wake_status)
  999. ihid->irq_wake_enabled = false;
  1000. else
  1001. hid_warn(hid, "Failed to disable irq wake: %d\n",
  1002. wake_status);
  1003. }
  1004. /* We'll resume to full power */
  1005. pm_runtime_disable(dev);
  1006. pm_runtime_set_active(dev);
  1007. pm_runtime_enable(dev);
  1008. enable_irq(client->irq);
  1009. ret = i2c_hid_hwreset(client);
  1010. if (ret)
  1011. return ret;
  1012. if (hid->driver && hid->driver->reset_resume) {
  1013. ret = hid->driver->reset_resume(hid);
  1014. return ret;
  1015. }
  1016. return 0;
  1017. }
  1018. #endif
  1019. #ifdef CONFIG_PM
  1020. static int i2c_hid_runtime_suspend(struct device *dev)
  1021. {
  1022. struct i2c_client *client = to_i2c_client(dev);
  1023. i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
  1024. disable_irq(client->irq);
  1025. return 0;
  1026. }
  1027. static int i2c_hid_runtime_resume(struct device *dev)
  1028. {
  1029. struct i2c_client *client = to_i2c_client(dev);
  1030. enable_irq(client->irq);
  1031. i2c_hid_set_power(client, I2C_HID_PWR_ON);
  1032. return 0;
  1033. }
  1034. #endif
  1035. static const struct dev_pm_ops i2c_hid_pm = {
  1036. SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
  1037. SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume,
  1038. NULL)
  1039. };
  1040. static const struct i2c_device_id i2c_hid_id_table[] = {
  1041. { "hid", 0 },
  1042. { "hid-over-i2c", 0 },
  1043. { },
  1044. };
  1045. MODULE_DEVICE_TABLE(i2c, i2c_hid_id_table);
  1046. static struct i2c_driver i2c_hid_driver = {
  1047. .driver = {
  1048. .name = "i2c_hid",
  1049. .pm = &i2c_hid_pm,
  1050. .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
  1051. .of_match_table = of_match_ptr(i2c_hid_of_match),
  1052. },
  1053. .probe = i2c_hid_probe,
  1054. .remove = i2c_hid_remove,
  1055. .shutdown = i2c_hid_shutdown,
  1056. .id_table = i2c_hid_id_table,
  1057. };
  1058. module_i2c_driver(i2c_hid_driver);
  1059. MODULE_DESCRIPTION("HID over I2C core driver");
  1060. MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
  1061. MODULE_LICENSE("GPL");