hid-cp2112.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. /*
  2. * hid-cp2112.c - Silicon Labs HID USB to SMBus master bridge
  3. * Copyright (c) 2013,2014 Uplogix, Inc.
  4. * David Barksdale <dbarksdale@uplogix.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. /*
  16. * The Silicon Labs CP2112 chip is a USB HID device which provides an
  17. * SMBus controller for talking to slave devices and 8 GPIO pins. The
  18. * host communicates with the CP2112 via raw HID reports.
  19. *
  20. * Data Sheet:
  21. * http://www.silabs.com/Support%20Documents/TechnicalDocs/CP2112.pdf
  22. * Programming Interface Specification:
  23. * http://www.silabs.com/Support%20Documents/TechnicalDocs/AN495.pdf
  24. */
  25. #include <linux/gpio.h>
  26. #include <linux/hid.h>
  27. #include <linux/i2c.h>
  28. #include <linux/module.h>
  29. #include <linux/nls.h>
  30. #include <linux/usb/ch9.h>
  31. #include "hid-ids.h"
  32. enum {
  33. CP2112_GPIO_CONFIG = 0x02,
  34. CP2112_GPIO_GET = 0x03,
  35. CP2112_GPIO_SET = 0x04,
  36. CP2112_GET_VERSION_INFO = 0x05,
  37. CP2112_SMBUS_CONFIG = 0x06,
  38. CP2112_DATA_READ_REQUEST = 0x10,
  39. CP2112_DATA_WRITE_READ_REQUEST = 0x11,
  40. CP2112_DATA_READ_FORCE_SEND = 0x12,
  41. CP2112_DATA_READ_RESPONSE = 0x13,
  42. CP2112_DATA_WRITE_REQUEST = 0x14,
  43. CP2112_TRANSFER_STATUS_REQUEST = 0x15,
  44. CP2112_TRANSFER_STATUS_RESPONSE = 0x16,
  45. CP2112_CANCEL_TRANSFER = 0x17,
  46. CP2112_LOCK_BYTE = 0x20,
  47. CP2112_USB_CONFIG = 0x21,
  48. CP2112_MANUFACTURER_STRING = 0x22,
  49. CP2112_PRODUCT_STRING = 0x23,
  50. CP2112_SERIAL_STRING = 0x24,
  51. };
  52. enum {
  53. STATUS0_IDLE = 0x00,
  54. STATUS0_BUSY = 0x01,
  55. STATUS0_COMPLETE = 0x02,
  56. STATUS0_ERROR = 0x03,
  57. };
  58. enum {
  59. STATUS1_TIMEOUT_NACK = 0x00,
  60. STATUS1_TIMEOUT_BUS = 0x01,
  61. STATUS1_ARBITRATION_LOST = 0x02,
  62. STATUS1_READ_INCOMPLETE = 0x03,
  63. STATUS1_WRITE_INCOMPLETE = 0x04,
  64. STATUS1_SUCCESS = 0x05,
  65. };
  66. struct cp2112_smbus_config_report {
  67. u8 report; /* CP2112_SMBUS_CONFIG */
  68. __be32 clock_speed; /* Hz */
  69. u8 device_address; /* Stored in the upper 7 bits */
  70. u8 auto_send_read; /* 1 = enabled, 0 = disabled */
  71. __be16 write_timeout; /* ms, 0 = no timeout */
  72. __be16 read_timeout; /* ms, 0 = no timeout */
  73. u8 scl_low_timeout; /* 1 = enabled, 0 = disabled */
  74. __be16 retry_time; /* # of retries, 0 = no limit */
  75. } __packed;
  76. struct cp2112_usb_config_report {
  77. u8 report; /* CP2112_USB_CONFIG */
  78. __le16 vid; /* Vendor ID */
  79. __le16 pid; /* Product ID */
  80. u8 max_power; /* Power requested in 2mA units */
  81. u8 power_mode; /* 0x00 = bus powered
  82. 0x01 = self powered & regulator off
  83. 0x02 = self powered & regulator on */
  84. u8 release_major;
  85. u8 release_minor;
  86. u8 mask; /* What fields to program */
  87. } __packed;
  88. struct cp2112_read_req_report {
  89. u8 report; /* CP2112_DATA_READ_REQUEST */
  90. u8 slave_address;
  91. __be16 length;
  92. } __packed;
  93. struct cp2112_write_read_req_report {
  94. u8 report; /* CP2112_DATA_WRITE_READ_REQUEST */
  95. u8 slave_address;
  96. __be16 length;
  97. u8 target_address_length;
  98. u8 target_address[16];
  99. } __packed;
  100. struct cp2112_write_req_report {
  101. u8 report; /* CP2112_DATA_WRITE_REQUEST */
  102. u8 slave_address;
  103. u8 length;
  104. u8 data[61];
  105. } __packed;
  106. struct cp2112_force_read_report {
  107. u8 report; /* CP2112_DATA_READ_FORCE_SEND */
  108. __be16 length;
  109. } __packed;
  110. struct cp2112_xfer_status_report {
  111. u8 report; /* CP2112_TRANSFER_STATUS_RESPONSE */
  112. u8 status0; /* STATUS0_* */
  113. u8 status1; /* STATUS1_* */
  114. __be16 retries;
  115. __be16 length;
  116. } __packed;
  117. struct cp2112_string_report {
  118. u8 dummy; /* force .string to be aligned */
  119. u8 report; /* CP2112_*_STRING */
  120. u8 length; /* length in bytes of everyting after .report */
  121. u8 type; /* USB_DT_STRING */
  122. wchar_t string[30]; /* UTF16_LITTLE_ENDIAN string */
  123. } __packed;
  124. /* Number of times to request transfer status before giving up waiting for a
  125. transfer to complete. This may need to be changed if SMBUS clock, retries,
  126. or read/write/scl_low timeout settings are changed. */
  127. static const int XFER_STATUS_RETRIES = 10;
  128. /* Time in ms to wait for a CP2112_DATA_READ_RESPONSE or
  129. CP2112_TRANSFER_STATUS_RESPONSE. */
  130. static const int RESPONSE_TIMEOUT = 50;
  131. static const struct hid_device_id cp2112_devices[] = {
  132. { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_CP2112) },
  133. { }
  134. };
  135. MODULE_DEVICE_TABLE(hid, cp2112_devices);
  136. struct cp2112_device {
  137. struct i2c_adapter adap;
  138. struct hid_device *hdev;
  139. wait_queue_head_t wait;
  140. u8 read_data[61];
  141. u8 read_length;
  142. u8 hwversion;
  143. int xfer_status;
  144. atomic_t read_avail;
  145. atomic_t xfer_avail;
  146. struct gpio_chip gc;
  147. };
  148. static int gpio_push_pull = 0xFF;
  149. module_param(gpio_push_pull, int, S_IRUGO | S_IWUSR);
  150. MODULE_PARM_DESC(gpio_push_pull, "GPIO push-pull configuration bitmask");
  151. static int cp2112_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
  152. {
  153. struct cp2112_device *dev = container_of(chip, struct cp2112_device,
  154. gc);
  155. struct hid_device *hdev = dev->hdev;
  156. u8 buf[5];
  157. int ret;
  158. ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
  159. sizeof(buf), HID_FEATURE_REPORT,
  160. HID_REQ_GET_REPORT);
  161. if (ret != sizeof(buf)) {
  162. hid_err(hdev, "error requesting GPIO config: %d\n", ret);
  163. return ret;
  164. }
  165. buf[1] &= ~(1 << offset);
  166. buf[2] = gpio_push_pull;
  167. ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf),
  168. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  169. if (ret < 0) {
  170. hid_err(hdev, "error setting GPIO config: %d\n", ret);
  171. return ret;
  172. }
  173. return 0;
  174. }
  175. static void cp2112_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  176. {
  177. struct cp2112_device *dev = container_of(chip, struct cp2112_device,
  178. gc);
  179. struct hid_device *hdev = dev->hdev;
  180. u8 buf[3];
  181. int ret;
  182. buf[0] = CP2112_GPIO_SET;
  183. buf[1] = value ? 0xff : 0;
  184. buf[2] = 1 << offset;
  185. ret = hid_hw_raw_request(hdev, CP2112_GPIO_SET, buf, sizeof(buf),
  186. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  187. if (ret < 0)
  188. hid_err(hdev, "error setting GPIO values: %d\n", ret);
  189. }
  190. static int cp2112_gpio_get(struct gpio_chip *chip, unsigned offset)
  191. {
  192. struct cp2112_device *dev = container_of(chip, struct cp2112_device,
  193. gc);
  194. struct hid_device *hdev = dev->hdev;
  195. u8 buf[2];
  196. int ret;
  197. ret = hid_hw_raw_request(hdev, CP2112_GPIO_GET, buf, sizeof(buf),
  198. HID_FEATURE_REPORT, HID_REQ_GET_REPORT);
  199. if (ret != sizeof(buf)) {
  200. hid_err(hdev, "error requesting GPIO values: %d\n", ret);
  201. return ret;
  202. }
  203. return (buf[1] >> offset) & 1;
  204. }
  205. static int cp2112_gpio_direction_output(struct gpio_chip *chip,
  206. unsigned offset, int value)
  207. {
  208. struct cp2112_device *dev = container_of(chip, struct cp2112_device,
  209. gc);
  210. struct hid_device *hdev = dev->hdev;
  211. u8 buf[5];
  212. int ret;
  213. ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf,
  214. sizeof(buf), HID_FEATURE_REPORT,
  215. HID_REQ_GET_REPORT);
  216. if (ret != sizeof(buf)) {
  217. hid_err(hdev, "error requesting GPIO config: %d\n", ret);
  218. return ret;
  219. }
  220. buf[1] |= 1 << offset;
  221. buf[2] = gpio_push_pull;
  222. ret = hid_hw_raw_request(hdev, CP2112_GPIO_CONFIG, buf, sizeof(buf),
  223. HID_FEATURE_REPORT, HID_REQ_SET_REPORT);
  224. if (ret < 0) {
  225. hid_err(hdev, "error setting GPIO config: %d\n", ret);
  226. return ret;
  227. }
  228. /*
  229. * Set gpio value when output direction is already set,
  230. * as specified in AN495, Rev. 0.2, cpt. 4.4
  231. */
  232. cp2112_gpio_set(chip, offset, value);
  233. return 0;
  234. }
  235. static int cp2112_hid_get(struct hid_device *hdev, unsigned char report_number,
  236. u8 *data, size_t count, unsigned char report_type)
  237. {
  238. u8 *buf;
  239. int ret;
  240. buf = kmalloc(count, GFP_KERNEL);
  241. if (!buf)
  242. return -ENOMEM;
  243. ret = hid_hw_raw_request(hdev, report_number, buf, count,
  244. report_type, HID_REQ_GET_REPORT);
  245. memcpy(data, buf, count);
  246. kfree(buf);
  247. return ret;
  248. }
  249. static int cp2112_hid_output(struct hid_device *hdev, u8 *data, size_t count,
  250. unsigned char report_type)
  251. {
  252. u8 *buf;
  253. int ret;
  254. buf = kmemdup(data, count, GFP_KERNEL);
  255. if (!buf)
  256. return -ENOMEM;
  257. if (report_type == HID_OUTPUT_REPORT)
  258. ret = hid_hw_output_report(hdev, buf, count);
  259. else
  260. ret = hid_hw_raw_request(hdev, buf[0], buf, count, report_type,
  261. HID_REQ_SET_REPORT);
  262. kfree(buf);
  263. return ret;
  264. }
  265. static int cp2112_wait(struct cp2112_device *dev, atomic_t *avail)
  266. {
  267. int ret = 0;
  268. /* We have sent either a CP2112_TRANSFER_STATUS_REQUEST or a
  269. * CP2112_DATA_READ_FORCE_SEND and we are waiting for the response to
  270. * come in cp2112_raw_event or timeout. There will only be one of these
  271. * in flight at any one time. The timeout is extremely large and is a
  272. * last resort if the CP2112 has died. If we do timeout we don't expect
  273. * to receive the response which would cause data races, it's not like
  274. * we can do anything about it anyway.
  275. */
  276. ret = wait_event_interruptible_timeout(dev->wait,
  277. atomic_read(avail), msecs_to_jiffies(RESPONSE_TIMEOUT));
  278. if (-ERESTARTSYS == ret)
  279. return ret;
  280. if (!ret)
  281. return -ETIMEDOUT;
  282. atomic_set(avail, 0);
  283. return 0;
  284. }
  285. static int cp2112_xfer_status(struct cp2112_device *dev)
  286. {
  287. struct hid_device *hdev = dev->hdev;
  288. u8 buf[2];
  289. int ret;
  290. buf[0] = CP2112_TRANSFER_STATUS_REQUEST;
  291. buf[1] = 0x01;
  292. atomic_set(&dev->xfer_avail, 0);
  293. ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT);
  294. if (ret < 0) {
  295. hid_warn(hdev, "Error requesting status: %d\n", ret);
  296. return ret;
  297. }
  298. ret = cp2112_wait(dev, &dev->xfer_avail);
  299. if (ret)
  300. return ret;
  301. return dev->xfer_status;
  302. }
  303. static int cp2112_read(struct cp2112_device *dev, u8 *data, size_t size)
  304. {
  305. struct hid_device *hdev = dev->hdev;
  306. struct cp2112_force_read_report report;
  307. int ret;
  308. if (size > sizeof(dev->read_data))
  309. size = sizeof(dev->read_data);
  310. report.report = CP2112_DATA_READ_FORCE_SEND;
  311. report.length = cpu_to_be16(size);
  312. atomic_set(&dev->read_avail, 0);
  313. ret = cp2112_hid_output(hdev, &report.report, sizeof(report),
  314. HID_OUTPUT_REPORT);
  315. if (ret < 0) {
  316. hid_warn(hdev, "Error requesting data: %d\n", ret);
  317. return ret;
  318. }
  319. ret = cp2112_wait(dev, &dev->read_avail);
  320. if (ret)
  321. return ret;
  322. hid_dbg(hdev, "read %d of %zd bytes requested\n",
  323. dev->read_length, size);
  324. if (size > dev->read_length)
  325. size = dev->read_length;
  326. memcpy(data, dev->read_data, size);
  327. return dev->read_length;
  328. }
  329. static int cp2112_read_req(void *buf, u8 slave_address, u16 length)
  330. {
  331. struct cp2112_read_req_report *report = buf;
  332. if (length < 1 || length > 512)
  333. return -EINVAL;
  334. report->report = CP2112_DATA_READ_REQUEST;
  335. report->slave_address = slave_address << 1;
  336. report->length = cpu_to_be16(length);
  337. return sizeof(*report);
  338. }
  339. static int cp2112_write_read_req(void *buf, u8 slave_address, u16 length,
  340. u8 command, u8 *data, u8 data_length)
  341. {
  342. struct cp2112_write_read_req_report *report = buf;
  343. if (length < 1 || length > 512
  344. || data_length > sizeof(report->target_address) - 1)
  345. return -EINVAL;
  346. report->report = CP2112_DATA_WRITE_READ_REQUEST;
  347. report->slave_address = slave_address << 1;
  348. report->length = cpu_to_be16(length);
  349. report->target_address_length = data_length + 1;
  350. report->target_address[0] = command;
  351. memcpy(&report->target_address[1], data, data_length);
  352. return data_length + 6;
  353. }
  354. static int cp2112_write_req(void *buf, u8 slave_address, u8 command, u8 *data,
  355. u8 data_length)
  356. {
  357. struct cp2112_write_req_report *report = buf;
  358. if (data_length > sizeof(report->data) - 1)
  359. return -EINVAL;
  360. report->report = CP2112_DATA_WRITE_REQUEST;
  361. report->slave_address = slave_address << 1;
  362. report->length = data_length + 1;
  363. report->data[0] = command;
  364. memcpy(&report->data[1], data, data_length);
  365. return data_length + 4;
  366. }
  367. static int cp2112_i2c_write_req(void *buf, u8 slave_address, u8 *data,
  368. u8 data_length)
  369. {
  370. struct cp2112_write_req_report *report = buf;
  371. if (data_length > sizeof(report->data))
  372. return -EINVAL;
  373. report->report = CP2112_DATA_WRITE_REQUEST;
  374. report->slave_address = slave_address << 1;
  375. report->length = data_length;
  376. memcpy(report->data, data, data_length);
  377. return data_length + 3;
  378. }
  379. static int cp2112_i2c_write_read_req(void *buf, u8 slave_address,
  380. u8 *addr, int addr_length,
  381. int read_length)
  382. {
  383. struct cp2112_write_read_req_report *report = buf;
  384. if (read_length < 1 || read_length > 512 ||
  385. addr_length > sizeof(report->target_address))
  386. return -EINVAL;
  387. report->report = CP2112_DATA_WRITE_READ_REQUEST;
  388. report->slave_address = slave_address << 1;
  389. report->length = cpu_to_be16(read_length);
  390. report->target_address_length = addr_length;
  391. memcpy(report->target_address, addr, addr_length);
  392. return addr_length + 5;
  393. }
  394. static int cp2112_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs,
  395. int num)
  396. {
  397. struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data;
  398. struct hid_device *hdev = dev->hdev;
  399. u8 buf[64];
  400. ssize_t count;
  401. ssize_t read_length = 0;
  402. u8 *read_buf = NULL;
  403. unsigned int retries;
  404. int ret;
  405. hid_dbg(hdev, "I2C %d messages\n", num);
  406. if (num == 1) {
  407. if (msgs->flags & I2C_M_RD) {
  408. hid_dbg(hdev, "I2C read %#04x len %d\n",
  409. msgs->addr, msgs->len);
  410. read_length = msgs->len;
  411. read_buf = msgs->buf;
  412. count = cp2112_read_req(buf, msgs->addr, msgs->len);
  413. } else {
  414. hid_dbg(hdev, "I2C write %#04x len %d\n",
  415. msgs->addr, msgs->len);
  416. count = cp2112_i2c_write_req(buf, msgs->addr,
  417. msgs->buf, msgs->len);
  418. }
  419. if (count < 0)
  420. return count;
  421. } else if (dev->hwversion > 1 && /* no repeated start in rev 1 */
  422. num == 2 &&
  423. msgs[0].addr == msgs[1].addr &&
  424. !(msgs[0].flags & I2C_M_RD) && (msgs[1].flags & I2C_M_RD)) {
  425. hid_dbg(hdev, "I2C write-read %#04x wlen %d rlen %d\n",
  426. msgs[0].addr, msgs[0].len, msgs[1].len);
  427. read_length = msgs[1].len;
  428. read_buf = msgs[1].buf;
  429. count = cp2112_i2c_write_read_req(buf, msgs[0].addr,
  430. msgs[0].buf, msgs[0].len, msgs[1].len);
  431. if (count < 0)
  432. return count;
  433. } else {
  434. hid_err(hdev,
  435. "Multi-message I2C transactions not supported\n");
  436. return -EOPNOTSUPP;
  437. }
  438. ret = hid_hw_power(hdev, PM_HINT_FULLON);
  439. if (ret < 0) {
  440. hid_err(hdev, "power management error: %d\n", ret);
  441. return ret;
  442. }
  443. ret = cp2112_hid_output(hdev, buf, count, HID_OUTPUT_REPORT);
  444. if (ret < 0) {
  445. hid_warn(hdev, "Error starting transaction: %d\n", ret);
  446. goto power_normal;
  447. }
  448. for (retries = 0; retries < XFER_STATUS_RETRIES; ++retries) {
  449. ret = cp2112_xfer_status(dev);
  450. if (-EBUSY == ret)
  451. continue;
  452. if (ret < 0)
  453. goto power_normal;
  454. break;
  455. }
  456. if (XFER_STATUS_RETRIES <= retries) {
  457. hid_warn(hdev, "Transfer timed out, cancelling.\n");
  458. buf[0] = CP2112_CANCEL_TRANSFER;
  459. buf[1] = 0x01;
  460. ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT);
  461. if (ret < 0)
  462. hid_warn(hdev, "Error cancelling transaction: %d\n",
  463. ret);
  464. ret = -ETIMEDOUT;
  465. goto power_normal;
  466. }
  467. for (count = 0; count < read_length;) {
  468. ret = cp2112_read(dev, read_buf + count, read_length - count);
  469. if (ret < 0)
  470. goto power_normal;
  471. if (ret == 0) {
  472. hid_err(hdev, "read returned 0\n");
  473. ret = -EIO;
  474. goto power_normal;
  475. }
  476. count += ret;
  477. if (count > read_length) {
  478. /*
  479. * The hardware returned too much data.
  480. * This is mostly harmless because cp2112_read()
  481. * has a limit check so didn't overrun our
  482. * buffer. Nevertheless, we return an error
  483. * because something is seriously wrong and
  484. * it shouldn't go unnoticed.
  485. */
  486. hid_err(hdev, "long read: %d > %zd\n",
  487. ret, read_length - count + ret);
  488. ret = -EIO;
  489. goto power_normal;
  490. }
  491. }
  492. /* return the number of transferred messages */
  493. ret = num;
  494. power_normal:
  495. hid_hw_power(hdev, PM_HINT_NORMAL);
  496. hid_dbg(hdev, "I2C transfer finished: %d\n", ret);
  497. return ret;
  498. }
  499. static int cp2112_xfer(struct i2c_adapter *adap, u16 addr,
  500. unsigned short flags, char read_write, u8 command,
  501. int size, union i2c_smbus_data *data)
  502. {
  503. struct cp2112_device *dev = (struct cp2112_device *)adap->algo_data;
  504. struct hid_device *hdev = dev->hdev;
  505. u8 buf[64];
  506. __le16 word;
  507. ssize_t count;
  508. size_t read_length = 0;
  509. unsigned int retries;
  510. int ret;
  511. hid_dbg(hdev, "%s addr 0x%x flags 0x%x cmd 0x%x size %d\n",
  512. read_write == I2C_SMBUS_WRITE ? "write" : "read",
  513. addr, flags, command, size);
  514. switch (size) {
  515. case I2C_SMBUS_BYTE:
  516. read_length = 1;
  517. if (I2C_SMBUS_READ == read_write)
  518. count = cp2112_read_req(buf, addr, read_length);
  519. else
  520. count = cp2112_write_req(buf, addr, command, NULL,
  521. 0);
  522. break;
  523. case I2C_SMBUS_BYTE_DATA:
  524. read_length = 1;
  525. if (I2C_SMBUS_READ == read_write)
  526. count = cp2112_write_read_req(buf, addr, read_length,
  527. command, NULL, 0);
  528. else
  529. count = cp2112_write_req(buf, addr, command,
  530. &data->byte, 1);
  531. break;
  532. case I2C_SMBUS_WORD_DATA:
  533. read_length = 2;
  534. word = cpu_to_le16(data->word);
  535. if (I2C_SMBUS_READ == read_write)
  536. count = cp2112_write_read_req(buf, addr, read_length,
  537. command, NULL, 0);
  538. else
  539. count = cp2112_write_req(buf, addr, command,
  540. (u8 *)&word, 2);
  541. break;
  542. case I2C_SMBUS_PROC_CALL:
  543. size = I2C_SMBUS_WORD_DATA;
  544. read_write = I2C_SMBUS_READ;
  545. read_length = 2;
  546. word = cpu_to_le16(data->word);
  547. count = cp2112_write_read_req(buf, addr, read_length, command,
  548. (u8 *)&word, 2);
  549. break;
  550. case I2C_SMBUS_I2C_BLOCK_DATA:
  551. size = I2C_SMBUS_BLOCK_DATA;
  552. /* fallthrough */
  553. case I2C_SMBUS_BLOCK_DATA:
  554. if (I2C_SMBUS_READ == read_write) {
  555. count = cp2112_write_read_req(buf, addr,
  556. I2C_SMBUS_BLOCK_MAX,
  557. command, NULL, 0);
  558. } else {
  559. count = cp2112_write_req(buf, addr, command,
  560. data->block,
  561. data->block[0] + 1);
  562. }
  563. break;
  564. case I2C_SMBUS_BLOCK_PROC_CALL:
  565. size = I2C_SMBUS_BLOCK_DATA;
  566. read_write = I2C_SMBUS_READ;
  567. count = cp2112_write_read_req(buf, addr, I2C_SMBUS_BLOCK_MAX,
  568. command, data->block,
  569. data->block[0] + 1);
  570. break;
  571. default:
  572. hid_warn(hdev, "Unsupported transaction %d\n", size);
  573. return -EOPNOTSUPP;
  574. }
  575. if (count < 0)
  576. return count;
  577. ret = hid_hw_power(hdev, PM_HINT_FULLON);
  578. if (ret < 0) {
  579. hid_err(hdev, "power management error: %d\n", ret);
  580. return ret;
  581. }
  582. ret = cp2112_hid_output(hdev, buf, count, HID_OUTPUT_REPORT);
  583. if (ret < 0) {
  584. hid_warn(hdev, "Error starting transaction: %d\n", ret);
  585. goto power_normal;
  586. }
  587. for (retries = 0; retries < XFER_STATUS_RETRIES; ++retries) {
  588. ret = cp2112_xfer_status(dev);
  589. if (-EBUSY == ret)
  590. continue;
  591. if (ret < 0)
  592. goto power_normal;
  593. break;
  594. }
  595. if (XFER_STATUS_RETRIES <= retries) {
  596. hid_warn(hdev, "Transfer timed out, cancelling.\n");
  597. buf[0] = CP2112_CANCEL_TRANSFER;
  598. buf[1] = 0x01;
  599. ret = cp2112_hid_output(hdev, buf, 2, HID_OUTPUT_REPORT);
  600. if (ret < 0)
  601. hid_warn(hdev, "Error cancelling transaction: %d\n",
  602. ret);
  603. ret = -ETIMEDOUT;
  604. goto power_normal;
  605. }
  606. if (I2C_SMBUS_WRITE == read_write) {
  607. ret = 0;
  608. goto power_normal;
  609. }
  610. if (I2C_SMBUS_BLOCK_DATA == size)
  611. read_length = ret;
  612. ret = cp2112_read(dev, buf, read_length);
  613. if (ret < 0)
  614. goto power_normal;
  615. if (ret != read_length) {
  616. hid_warn(hdev, "short read: %d < %zd\n", ret, read_length);
  617. ret = -EIO;
  618. goto power_normal;
  619. }
  620. switch (size) {
  621. case I2C_SMBUS_BYTE:
  622. case I2C_SMBUS_BYTE_DATA:
  623. data->byte = buf[0];
  624. break;
  625. case I2C_SMBUS_WORD_DATA:
  626. data->word = le16_to_cpup((__le16 *)buf);
  627. break;
  628. case I2C_SMBUS_BLOCK_DATA:
  629. if (read_length > I2C_SMBUS_BLOCK_MAX) {
  630. ret = -EPROTO;
  631. goto power_normal;
  632. }
  633. memcpy(data->block, buf, read_length);
  634. break;
  635. }
  636. ret = 0;
  637. power_normal:
  638. hid_hw_power(hdev, PM_HINT_NORMAL);
  639. hid_dbg(hdev, "transfer finished: %d\n", ret);
  640. return ret;
  641. }
  642. static u32 cp2112_functionality(struct i2c_adapter *adap)
  643. {
  644. return I2C_FUNC_I2C |
  645. I2C_FUNC_SMBUS_BYTE |
  646. I2C_FUNC_SMBUS_BYTE_DATA |
  647. I2C_FUNC_SMBUS_WORD_DATA |
  648. I2C_FUNC_SMBUS_BLOCK_DATA |
  649. I2C_FUNC_SMBUS_I2C_BLOCK |
  650. I2C_FUNC_SMBUS_PROC_CALL |
  651. I2C_FUNC_SMBUS_BLOCK_PROC_CALL;
  652. }
  653. static const struct i2c_algorithm smbus_algorithm = {
  654. .master_xfer = cp2112_i2c_xfer,
  655. .smbus_xfer = cp2112_xfer,
  656. .functionality = cp2112_functionality,
  657. };
  658. static int cp2112_get_usb_config(struct hid_device *hdev,
  659. struct cp2112_usb_config_report *cfg)
  660. {
  661. int ret;
  662. ret = cp2112_hid_get(hdev, CP2112_USB_CONFIG, (u8 *)cfg, sizeof(*cfg),
  663. HID_FEATURE_REPORT);
  664. if (ret != sizeof(*cfg)) {
  665. hid_err(hdev, "error reading usb config: %d\n", ret);
  666. if (ret < 0)
  667. return ret;
  668. return -EIO;
  669. }
  670. return 0;
  671. }
  672. static int cp2112_set_usb_config(struct hid_device *hdev,
  673. struct cp2112_usb_config_report *cfg)
  674. {
  675. int ret;
  676. BUG_ON(cfg->report != CP2112_USB_CONFIG);
  677. ret = cp2112_hid_output(hdev, (u8 *)cfg, sizeof(*cfg),
  678. HID_FEATURE_REPORT);
  679. if (ret != sizeof(*cfg)) {
  680. hid_err(hdev, "error writing usb config: %d\n", ret);
  681. if (ret < 0)
  682. return ret;
  683. return -EIO;
  684. }
  685. return 0;
  686. }
  687. static void chmod_sysfs_attrs(struct hid_device *hdev);
  688. #define CP2112_CONFIG_ATTR(name, store, format, ...) \
  689. static ssize_t name##_store(struct device *kdev, \
  690. struct device_attribute *attr, const char *buf, \
  691. size_t count) \
  692. { \
  693. struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \
  694. struct cp2112_usb_config_report cfg; \
  695. int ret = cp2112_get_usb_config(hdev, &cfg); \
  696. if (ret) \
  697. return ret; \
  698. store; \
  699. ret = cp2112_set_usb_config(hdev, &cfg); \
  700. if (ret) \
  701. return ret; \
  702. chmod_sysfs_attrs(hdev); \
  703. return count; \
  704. } \
  705. static ssize_t name##_show(struct device *kdev, \
  706. struct device_attribute *attr, char *buf) \
  707. { \
  708. struct hid_device *hdev = container_of(kdev, struct hid_device, dev); \
  709. struct cp2112_usb_config_report cfg; \
  710. int ret = cp2112_get_usb_config(hdev, &cfg); \
  711. if (ret) \
  712. return ret; \
  713. return scnprintf(buf, PAGE_SIZE, format, ##__VA_ARGS__); \
  714. } \
  715. static DEVICE_ATTR_RW(name);
  716. CP2112_CONFIG_ATTR(vendor_id, ({
  717. u16 vid;
  718. if (sscanf(buf, "%hi", &vid) != 1)
  719. return -EINVAL;
  720. cfg.vid = cpu_to_le16(vid);
  721. cfg.mask = 0x01;
  722. }), "0x%04x\n", le16_to_cpu(cfg.vid));
  723. CP2112_CONFIG_ATTR(product_id, ({
  724. u16 pid;
  725. if (sscanf(buf, "%hi", &pid) != 1)
  726. return -EINVAL;
  727. cfg.pid = cpu_to_le16(pid);
  728. cfg.mask = 0x02;
  729. }), "0x%04x\n", le16_to_cpu(cfg.pid));
  730. CP2112_CONFIG_ATTR(max_power, ({
  731. int mA;
  732. if (sscanf(buf, "%i", &mA) != 1)
  733. return -EINVAL;
  734. cfg.max_power = (mA + 1) / 2;
  735. cfg.mask = 0x04;
  736. }), "%u mA\n", cfg.max_power * 2);
  737. CP2112_CONFIG_ATTR(power_mode, ({
  738. if (sscanf(buf, "%hhi", &cfg.power_mode) != 1)
  739. return -EINVAL;
  740. cfg.mask = 0x08;
  741. }), "%u\n", cfg.power_mode);
  742. CP2112_CONFIG_ATTR(release_version, ({
  743. if (sscanf(buf, "%hhi.%hhi", &cfg.release_major, &cfg.release_minor)
  744. != 2)
  745. return -EINVAL;
  746. cfg.mask = 0x10;
  747. }), "%u.%u\n", cfg.release_major, cfg.release_minor);
  748. #undef CP2112_CONFIG_ATTR
  749. struct cp2112_pstring_attribute {
  750. struct device_attribute attr;
  751. unsigned char report;
  752. };
  753. static ssize_t pstr_store(struct device *kdev,
  754. struct device_attribute *kattr, const char *buf,
  755. size_t count)
  756. {
  757. struct hid_device *hdev = container_of(kdev, struct hid_device, dev);
  758. struct cp2112_pstring_attribute *attr =
  759. container_of(kattr, struct cp2112_pstring_attribute, attr);
  760. struct cp2112_string_report report;
  761. int ret;
  762. memset(&report, 0, sizeof(report));
  763. ret = utf8s_to_utf16s(buf, count, UTF16_LITTLE_ENDIAN,
  764. report.string, ARRAY_SIZE(report.string));
  765. report.report = attr->report;
  766. report.length = ret * sizeof(report.string[0]) + 2;
  767. report.type = USB_DT_STRING;
  768. ret = cp2112_hid_output(hdev, &report.report, report.length + 1,
  769. HID_FEATURE_REPORT);
  770. if (ret != report.length + 1) {
  771. hid_err(hdev, "error writing %s string: %d\n", kattr->attr.name,
  772. ret);
  773. if (ret < 0)
  774. return ret;
  775. return -EIO;
  776. }
  777. chmod_sysfs_attrs(hdev);
  778. return count;
  779. }
  780. static ssize_t pstr_show(struct device *kdev,
  781. struct device_attribute *kattr, char *buf)
  782. {
  783. struct hid_device *hdev = container_of(kdev, struct hid_device, dev);
  784. struct cp2112_pstring_attribute *attr =
  785. container_of(kattr, struct cp2112_pstring_attribute, attr);
  786. struct cp2112_string_report report;
  787. u8 length;
  788. int ret;
  789. ret = cp2112_hid_get(hdev, attr->report, &report.report,
  790. sizeof(report) - 1, HID_FEATURE_REPORT);
  791. if (ret < 3) {
  792. hid_err(hdev, "error reading %s string: %d\n", kattr->attr.name,
  793. ret);
  794. if (ret < 0)
  795. return ret;
  796. return -EIO;
  797. }
  798. if (report.length < 2) {
  799. hid_err(hdev, "invalid %s string length: %d\n",
  800. kattr->attr.name, report.length);
  801. return -EIO;
  802. }
  803. length = report.length > ret - 1 ? ret - 1 : report.length;
  804. length = (length - 2) / sizeof(report.string[0]);
  805. ret = utf16s_to_utf8s(report.string, length, UTF16_LITTLE_ENDIAN, buf,
  806. PAGE_SIZE - 1);
  807. buf[ret++] = '\n';
  808. return ret;
  809. }
  810. #define CP2112_PSTR_ATTR(name, _report) \
  811. static struct cp2112_pstring_attribute dev_attr_##name = { \
  812. .attr = __ATTR(name, (S_IWUSR | S_IRUGO), pstr_show, pstr_store), \
  813. .report = _report, \
  814. };
  815. CP2112_PSTR_ATTR(manufacturer, CP2112_MANUFACTURER_STRING);
  816. CP2112_PSTR_ATTR(product, CP2112_PRODUCT_STRING);
  817. CP2112_PSTR_ATTR(serial, CP2112_SERIAL_STRING);
  818. #undef CP2112_PSTR_ATTR
  819. static const struct attribute_group cp2112_attr_group = {
  820. .attrs = (struct attribute *[]){
  821. &dev_attr_vendor_id.attr,
  822. &dev_attr_product_id.attr,
  823. &dev_attr_max_power.attr,
  824. &dev_attr_power_mode.attr,
  825. &dev_attr_release_version.attr,
  826. &dev_attr_manufacturer.attr.attr,
  827. &dev_attr_product.attr.attr,
  828. &dev_attr_serial.attr.attr,
  829. NULL
  830. }
  831. };
  832. /* Chmoding our sysfs attributes is simply a way to expose which fields in the
  833. * PROM have already been programmed. We do not depend on this preventing
  834. * writing to these attributes since the CP2112 will simply ignore writes to
  835. * already-programmed fields. This is why there is no sense in fixing this
  836. * racy behaviour.
  837. */
  838. static void chmod_sysfs_attrs(struct hid_device *hdev)
  839. {
  840. struct attribute **attr;
  841. u8 buf[2];
  842. int ret;
  843. ret = cp2112_hid_get(hdev, CP2112_LOCK_BYTE, buf, sizeof(buf),
  844. HID_FEATURE_REPORT);
  845. if (ret != sizeof(buf)) {
  846. hid_err(hdev, "error reading lock byte: %d\n", ret);
  847. return;
  848. }
  849. for (attr = cp2112_attr_group.attrs; *attr; ++attr) {
  850. umode_t mode = (buf[1] & 1) ? S_IWUSR | S_IRUGO : S_IRUGO;
  851. ret = sysfs_chmod_file(&hdev->dev.kobj, *attr, mode);
  852. if (ret < 0)
  853. hid_err(hdev, "error chmoding sysfs file %s\n",
  854. (*attr)->name);
  855. buf[1] >>= 1;
  856. }
  857. }
  858. static int cp2112_probe(struct hid_device *hdev, const struct hid_device_id *id)
  859. {
  860. struct cp2112_device *dev;
  861. u8 buf[3];
  862. struct cp2112_smbus_config_report config;
  863. int ret;
  864. ret = hid_parse(hdev);
  865. if (ret) {
  866. hid_err(hdev, "parse failed\n");
  867. return ret;
  868. }
  869. ret = hid_hw_start(hdev, HID_CONNECT_HIDRAW);
  870. if (ret) {
  871. hid_err(hdev, "hw start failed\n");
  872. return ret;
  873. }
  874. ret = hid_hw_open(hdev);
  875. if (ret) {
  876. hid_err(hdev, "hw open failed\n");
  877. goto err_hid_stop;
  878. }
  879. ret = hid_hw_power(hdev, PM_HINT_FULLON);
  880. if (ret < 0) {
  881. hid_err(hdev, "power management error: %d\n", ret);
  882. goto err_hid_close;
  883. }
  884. ret = cp2112_hid_get(hdev, CP2112_GET_VERSION_INFO, buf, sizeof(buf),
  885. HID_FEATURE_REPORT);
  886. if (ret != sizeof(buf)) {
  887. hid_err(hdev, "error requesting version\n");
  888. if (ret >= 0)
  889. ret = -EIO;
  890. goto err_power_normal;
  891. }
  892. hid_info(hdev, "Part Number: 0x%02X Device Version: 0x%02X\n",
  893. buf[1], buf[2]);
  894. ret = cp2112_hid_get(hdev, CP2112_SMBUS_CONFIG, (u8 *)&config,
  895. sizeof(config), HID_FEATURE_REPORT);
  896. if (ret != sizeof(config)) {
  897. hid_err(hdev, "error requesting SMBus config\n");
  898. if (ret >= 0)
  899. ret = -EIO;
  900. goto err_power_normal;
  901. }
  902. config.retry_time = cpu_to_be16(1);
  903. ret = cp2112_hid_output(hdev, (u8 *)&config, sizeof(config),
  904. HID_FEATURE_REPORT);
  905. if (ret != sizeof(config)) {
  906. hid_err(hdev, "error setting SMBus config\n");
  907. if (ret >= 0)
  908. ret = -EIO;
  909. goto err_power_normal;
  910. }
  911. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  912. if (!dev) {
  913. ret = -ENOMEM;
  914. goto err_power_normal;
  915. }
  916. hid_set_drvdata(hdev, (void *)dev);
  917. dev->hdev = hdev;
  918. dev->adap.owner = THIS_MODULE;
  919. dev->adap.class = I2C_CLASS_HWMON;
  920. dev->adap.algo = &smbus_algorithm;
  921. dev->adap.algo_data = dev;
  922. dev->adap.dev.parent = &hdev->dev;
  923. snprintf(dev->adap.name, sizeof(dev->adap.name),
  924. "CP2112 SMBus Bridge on hiddev%d", hdev->minor);
  925. dev->hwversion = buf[2];
  926. init_waitqueue_head(&dev->wait);
  927. hid_device_io_start(hdev);
  928. ret = i2c_add_adapter(&dev->adap);
  929. hid_device_io_stop(hdev);
  930. if (ret) {
  931. hid_err(hdev, "error registering i2c adapter\n");
  932. goto err_free_dev;
  933. }
  934. hid_dbg(hdev, "adapter registered\n");
  935. dev->gc.label = "cp2112_gpio";
  936. dev->gc.direction_input = cp2112_gpio_direction_input;
  937. dev->gc.direction_output = cp2112_gpio_direction_output;
  938. dev->gc.set = cp2112_gpio_set;
  939. dev->gc.get = cp2112_gpio_get;
  940. dev->gc.base = -1;
  941. dev->gc.ngpio = 8;
  942. dev->gc.can_sleep = 1;
  943. dev->gc.dev = &hdev->dev;
  944. ret = gpiochip_add(&dev->gc);
  945. if (ret < 0) {
  946. hid_err(hdev, "error registering gpio chip\n");
  947. goto err_free_i2c;
  948. }
  949. ret = sysfs_create_group(&hdev->dev.kobj, &cp2112_attr_group);
  950. if (ret < 0) {
  951. hid_err(hdev, "error creating sysfs attrs\n");
  952. goto err_gpiochip_remove;
  953. }
  954. chmod_sysfs_attrs(hdev);
  955. hid_hw_power(hdev, PM_HINT_NORMAL);
  956. return ret;
  957. err_gpiochip_remove:
  958. gpiochip_remove(&dev->gc);
  959. err_free_i2c:
  960. i2c_del_adapter(&dev->adap);
  961. err_free_dev:
  962. kfree(dev);
  963. err_power_normal:
  964. hid_hw_power(hdev, PM_HINT_NORMAL);
  965. err_hid_close:
  966. hid_hw_close(hdev);
  967. err_hid_stop:
  968. hid_hw_stop(hdev);
  969. return ret;
  970. }
  971. static void cp2112_remove(struct hid_device *hdev)
  972. {
  973. struct cp2112_device *dev = hid_get_drvdata(hdev);
  974. sysfs_remove_group(&hdev->dev.kobj, &cp2112_attr_group);
  975. gpiochip_remove(&dev->gc);
  976. i2c_del_adapter(&dev->adap);
  977. /* i2c_del_adapter has finished removing all i2c devices from our
  978. * adapter. Well behaved devices should no longer call our cp2112_xfer
  979. * and should have waited for any pending calls to finish. It has also
  980. * waited for device_unregister(&adap->dev) to complete. Therefore we
  981. * can safely free our struct cp2112_device.
  982. */
  983. hid_hw_close(hdev);
  984. hid_hw_stop(hdev);
  985. kfree(dev);
  986. }
  987. static int cp2112_raw_event(struct hid_device *hdev, struct hid_report *report,
  988. u8 *data, int size)
  989. {
  990. struct cp2112_device *dev = hid_get_drvdata(hdev);
  991. struct cp2112_xfer_status_report *xfer = (void *)data;
  992. switch (data[0]) {
  993. case CP2112_TRANSFER_STATUS_RESPONSE:
  994. hid_dbg(hdev, "xfer status: %02x %02x %04x %04x\n",
  995. xfer->status0, xfer->status1,
  996. be16_to_cpu(xfer->retries), be16_to_cpu(xfer->length));
  997. switch (xfer->status0) {
  998. case STATUS0_IDLE:
  999. dev->xfer_status = -EAGAIN;
  1000. break;
  1001. case STATUS0_BUSY:
  1002. dev->xfer_status = -EBUSY;
  1003. break;
  1004. case STATUS0_COMPLETE:
  1005. dev->xfer_status = be16_to_cpu(xfer->length);
  1006. break;
  1007. case STATUS0_ERROR:
  1008. switch (xfer->status1) {
  1009. case STATUS1_TIMEOUT_NACK:
  1010. case STATUS1_TIMEOUT_BUS:
  1011. dev->xfer_status = -ETIMEDOUT;
  1012. break;
  1013. default:
  1014. dev->xfer_status = -EIO;
  1015. break;
  1016. }
  1017. break;
  1018. default:
  1019. dev->xfer_status = -EINVAL;
  1020. break;
  1021. }
  1022. atomic_set(&dev->xfer_avail, 1);
  1023. break;
  1024. case CP2112_DATA_READ_RESPONSE:
  1025. hid_dbg(hdev, "read response: %02x %02x\n", data[1], data[2]);
  1026. dev->read_length = data[2];
  1027. if (dev->read_length > sizeof(dev->read_data))
  1028. dev->read_length = sizeof(dev->read_data);
  1029. memcpy(dev->read_data, &data[3], dev->read_length);
  1030. atomic_set(&dev->read_avail, 1);
  1031. break;
  1032. default:
  1033. hid_err(hdev, "unknown report\n");
  1034. return 0;
  1035. }
  1036. wake_up_interruptible(&dev->wait);
  1037. return 1;
  1038. }
  1039. static struct hid_driver cp2112_driver = {
  1040. .name = "cp2112",
  1041. .id_table = cp2112_devices,
  1042. .probe = cp2112_probe,
  1043. .remove = cp2112_remove,
  1044. .raw_event = cp2112_raw_event,
  1045. };
  1046. module_hid_driver(cp2112_driver);
  1047. MODULE_DESCRIPTION("Silicon Labs HID USB to SMBus master bridge");
  1048. MODULE_AUTHOR("David Barksdale <dbarksdale@uplogix.com>");
  1049. MODULE_LICENSE("GPL");