i2c-hid.c 31 KB

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