hid-logitech-hidpp.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. /*
  2. * HIDPP protocol for Logitech Unifying receivers
  3. *
  4. * Copyright (c) 2011 Logitech (c)
  5. * Copyright (c) 2012-2013 Google (c)
  6. * Copyright (c) 2013-2014 Red Hat Inc.
  7. */
  8. /*
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; version 2 of the License.
  12. */
  13. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  14. #include <linux/device.h>
  15. #include <linux/hid.h>
  16. #include <linux/module.h>
  17. #include <linux/slab.h>
  18. #include <linux/sched.h>
  19. #include <linux/kfifo.h>
  20. #include <linux/input/mt.h>
  21. #include <asm/unaligned.h>
  22. #include "hid-ids.h"
  23. MODULE_LICENSE("GPL");
  24. MODULE_AUTHOR("Benjamin Tissoires <benjamin.tissoires@gmail.com>");
  25. MODULE_AUTHOR("Nestor Lopez Casado <nlopezcasad@logitech.com>");
  26. #define REPORT_ID_HIDPP_SHORT 0x10
  27. #define REPORT_ID_HIDPP_LONG 0x11
  28. #define HIDPP_REPORT_SHORT_LENGTH 7
  29. #define HIDPP_REPORT_LONG_LENGTH 20
  30. #define HIDPP_QUIRK_CLASS_WTP BIT(0)
  31. /* bits 1..20 are reserved for classes */
  32. #define HIDPP_QUIRK_DELAYED_INIT BIT(21)
  33. #define HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS BIT(22)
  34. #define HIDPP_QUIRK_MULTI_INPUT BIT(23)
  35. /*
  36. * There are two hidpp protocols in use, the first version hidpp10 is known
  37. * as register access protocol or RAP, the second version hidpp20 is known as
  38. * feature access protocol or FAP
  39. *
  40. * Most older devices (including the Unifying usb receiver) use the RAP protocol
  41. * where as most newer devices use the FAP protocol. Both protocols are
  42. * compatible with the underlying transport, which could be usb, Unifiying, or
  43. * bluetooth. The message lengths are defined by the hid vendor specific report
  44. * descriptor for the HIDPP_SHORT report type (total message lenth 7 bytes) and
  45. * the HIDPP_LONG report type (total message length 20 bytes)
  46. *
  47. * The RAP protocol uses both report types, whereas the FAP only uses HIDPP_LONG
  48. * messages. The Unifying receiver itself responds to RAP messages (device index
  49. * is 0xFF for the receiver), and all messages (short or long) with a device
  50. * index between 1 and 6 are passed untouched to the corresponding paired
  51. * Unifying device.
  52. *
  53. * The paired device can be RAP or FAP, it will receive the message untouched
  54. * from the Unifiying receiver.
  55. */
  56. struct fap {
  57. u8 feature_index;
  58. u8 funcindex_clientid;
  59. u8 params[HIDPP_REPORT_LONG_LENGTH - 4U];
  60. };
  61. struct rap {
  62. u8 sub_id;
  63. u8 reg_address;
  64. u8 params[HIDPP_REPORT_LONG_LENGTH - 4U];
  65. };
  66. struct hidpp_report {
  67. u8 report_id;
  68. u8 device_index;
  69. union {
  70. struct fap fap;
  71. struct rap rap;
  72. u8 rawbytes[sizeof(struct fap)];
  73. };
  74. } __packed;
  75. struct hidpp_device {
  76. struct hid_device *hid_dev;
  77. struct mutex send_mutex;
  78. void *send_receive_buf;
  79. wait_queue_head_t wait;
  80. bool answer_available;
  81. u8 protocol_major;
  82. u8 protocol_minor;
  83. void *private_data;
  84. struct work_struct work;
  85. struct kfifo delayed_work_fifo;
  86. atomic_t connected;
  87. struct input_dev *delayed_input;
  88. unsigned long quirks;
  89. };
  90. #define HIDPP_ERROR 0x8f
  91. #define HIDPP_ERROR_SUCCESS 0x00
  92. #define HIDPP_ERROR_INVALID_SUBID 0x01
  93. #define HIDPP_ERROR_INVALID_ADRESS 0x02
  94. #define HIDPP_ERROR_INVALID_VALUE 0x03
  95. #define HIDPP_ERROR_CONNECT_FAIL 0x04
  96. #define HIDPP_ERROR_TOO_MANY_DEVICES 0x05
  97. #define HIDPP_ERROR_ALREADY_EXISTS 0x06
  98. #define HIDPP_ERROR_BUSY 0x07
  99. #define HIDPP_ERROR_UNKNOWN_DEVICE 0x08
  100. #define HIDPP_ERROR_RESOURCE_ERROR 0x09
  101. #define HIDPP_ERROR_REQUEST_UNAVAILABLE 0x0a
  102. #define HIDPP_ERROR_INVALID_PARAM_VALUE 0x0b
  103. #define HIDPP_ERROR_WRONG_PIN_CODE 0x0c
  104. static void hidpp_connect_event(struct hidpp_device *hidpp_dev);
  105. static int __hidpp_send_report(struct hid_device *hdev,
  106. struct hidpp_report *hidpp_report)
  107. {
  108. int fields_count, ret;
  109. switch (hidpp_report->report_id) {
  110. case REPORT_ID_HIDPP_SHORT:
  111. fields_count = HIDPP_REPORT_SHORT_LENGTH;
  112. break;
  113. case REPORT_ID_HIDPP_LONG:
  114. fields_count = HIDPP_REPORT_LONG_LENGTH;
  115. break;
  116. default:
  117. return -ENODEV;
  118. }
  119. /*
  120. * set the device_index as the receiver, it will be overwritten by
  121. * hid_hw_request if needed
  122. */
  123. hidpp_report->device_index = 0xff;
  124. ret = hid_hw_raw_request(hdev, hidpp_report->report_id,
  125. (u8 *)hidpp_report, fields_count, HID_OUTPUT_REPORT,
  126. HID_REQ_SET_REPORT);
  127. return ret == fields_count ? 0 : -1;
  128. }
  129. /**
  130. * hidpp_send_message_sync() returns 0 in case of success, and something else
  131. * in case of a failure.
  132. * - If ' something else' is positive, that means that an error has been raised
  133. * by the protocol itself.
  134. * - If ' something else' is negative, that means that we had a classic error
  135. * (-ENOMEM, -EPIPE, etc...)
  136. */
  137. static int hidpp_send_message_sync(struct hidpp_device *hidpp,
  138. struct hidpp_report *message,
  139. struct hidpp_report *response)
  140. {
  141. int ret;
  142. mutex_lock(&hidpp->send_mutex);
  143. hidpp->send_receive_buf = response;
  144. hidpp->answer_available = false;
  145. /*
  146. * So that we can later validate the answer when it arrives
  147. * in hidpp_raw_event
  148. */
  149. *response = *message;
  150. ret = __hidpp_send_report(hidpp->hid_dev, message);
  151. if (ret) {
  152. dbg_hid("__hidpp_send_report returned err: %d\n", ret);
  153. memset(response, 0, sizeof(struct hidpp_report));
  154. goto exit;
  155. }
  156. if (!wait_event_timeout(hidpp->wait, hidpp->answer_available,
  157. 5*HZ)) {
  158. dbg_hid("%s:timeout waiting for response\n", __func__);
  159. memset(response, 0, sizeof(struct hidpp_report));
  160. ret = -ETIMEDOUT;
  161. }
  162. if (response->report_id == REPORT_ID_HIDPP_SHORT &&
  163. response->fap.feature_index == HIDPP_ERROR) {
  164. ret = response->fap.params[1];
  165. dbg_hid("__hidpp_send_report got hidpp error %02X\n", ret);
  166. goto exit;
  167. }
  168. exit:
  169. mutex_unlock(&hidpp->send_mutex);
  170. return ret;
  171. }
  172. static int hidpp_send_fap_command_sync(struct hidpp_device *hidpp,
  173. u8 feat_index, u8 funcindex_clientid, u8 *params, int param_count,
  174. struct hidpp_report *response)
  175. {
  176. struct hidpp_report *message;
  177. int ret;
  178. if (param_count > sizeof(message->fap.params))
  179. return -EINVAL;
  180. message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
  181. if (!message)
  182. return -ENOMEM;
  183. message->report_id = REPORT_ID_HIDPP_LONG;
  184. message->fap.feature_index = feat_index;
  185. message->fap.funcindex_clientid = funcindex_clientid;
  186. memcpy(&message->fap.params, params, param_count);
  187. ret = hidpp_send_message_sync(hidpp, message, response);
  188. kfree(message);
  189. return ret;
  190. }
  191. static int hidpp_send_rap_command_sync(struct hidpp_device *hidpp_dev,
  192. u8 report_id, u8 sub_id, u8 reg_address, u8 *params, int param_count,
  193. struct hidpp_report *response)
  194. {
  195. struct hidpp_report *message;
  196. int ret;
  197. if ((report_id != REPORT_ID_HIDPP_SHORT) &&
  198. (report_id != REPORT_ID_HIDPP_LONG))
  199. return -EINVAL;
  200. if (param_count > sizeof(message->rap.params))
  201. return -EINVAL;
  202. message = kzalloc(sizeof(struct hidpp_report), GFP_KERNEL);
  203. if (!message)
  204. return -ENOMEM;
  205. message->report_id = report_id;
  206. message->rap.sub_id = sub_id;
  207. message->rap.reg_address = reg_address;
  208. memcpy(&message->rap.params, params, param_count);
  209. ret = hidpp_send_message_sync(hidpp_dev, message, response);
  210. kfree(message);
  211. return ret;
  212. }
  213. static void delayed_work_cb(struct work_struct *work)
  214. {
  215. struct hidpp_device *hidpp = container_of(work, struct hidpp_device,
  216. work);
  217. hidpp_connect_event(hidpp);
  218. }
  219. static inline bool hidpp_match_answer(struct hidpp_report *question,
  220. struct hidpp_report *answer)
  221. {
  222. return (answer->fap.feature_index == question->fap.feature_index) &&
  223. (answer->fap.funcindex_clientid == question->fap.funcindex_clientid);
  224. }
  225. static inline bool hidpp_match_error(struct hidpp_report *question,
  226. struct hidpp_report *answer)
  227. {
  228. return (answer->fap.feature_index == HIDPP_ERROR) &&
  229. (answer->fap.funcindex_clientid == question->fap.feature_index) &&
  230. (answer->fap.params[0] == question->fap.funcindex_clientid);
  231. }
  232. static inline bool hidpp_report_is_connect_event(struct hidpp_report *report)
  233. {
  234. return (report->report_id == REPORT_ID_HIDPP_SHORT) &&
  235. (report->rap.sub_id == 0x41);
  236. }
  237. /**
  238. * hidpp_prefix_name() prefixes the current given name with "Logitech ".
  239. */
  240. static void hidpp_prefix_name(char **name, int name_length)
  241. {
  242. #define PREFIX_LENGTH 9 /* "Logitech " */
  243. int new_length;
  244. char *new_name;
  245. if (name_length > PREFIX_LENGTH &&
  246. strncmp(*name, "Logitech ", PREFIX_LENGTH) == 0)
  247. /* The prefix has is already in the name */
  248. return;
  249. new_length = PREFIX_LENGTH + name_length;
  250. new_name = kzalloc(new_length, GFP_KERNEL);
  251. if (!new_name)
  252. return;
  253. snprintf(new_name, new_length, "Logitech %s", *name);
  254. kfree(*name);
  255. *name = new_name;
  256. }
  257. /* -------------------------------------------------------------------------- */
  258. /* HIDP++ 1.0 commands */
  259. /* -------------------------------------------------------------------------- */
  260. #define HIDPP_SET_REGISTER 0x80
  261. #define HIDPP_GET_REGISTER 0x81
  262. #define HIDPP_SET_LONG_REGISTER 0x82
  263. #define HIDPP_GET_LONG_REGISTER 0x83
  264. #define HIDPP_REG_PAIRING_INFORMATION 0xB5
  265. #define DEVICE_NAME 0x40
  266. static char *hidpp_get_unifying_name(struct hidpp_device *hidpp_dev)
  267. {
  268. struct hidpp_report response;
  269. int ret;
  270. /* hid-logitech-dj is in charge of setting the right device index */
  271. u8 params[1] = { DEVICE_NAME };
  272. char *name;
  273. int len;
  274. ret = hidpp_send_rap_command_sync(hidpp_dev,
  275. REPORT_ID_HIDPP_SHORT,
  276. HIDPP_GET_LONG_REGISTER,
  277. HIDPP_REG_PAIRING_INFORMATION,
  278. params, 1, &response);
  279. if (ret)
  280. return NULL;
  281. len = response.rap.params[1];
  282. if (2 + len > sizeof(response.rap.params))
  283. return NULL;
  284. name = kzalloc(len + 1, GFP_KERNEL);
  285. if (!name)
  286. return NULL;
  287. memcpy(name, &response.rap.params[2], len);
  288. /* include the terminating '\0' */
  289. hidpp_prefix_name(&name, len + 1);
  290. return name;
  291. }
  292. /* -------------------------------------------------------------------------- */
  293. /* 0x0000: Root */
  294. /* -------------------------------------------------------------------------- */
  295. #define HIDPP_PAGE_ROOT 0x0000
  296. #define HIDPP_PAGE_ROOT_IDX 0x00
  297. #define CMD_ROOT_GET_FEATURE 0x01
  298. #define CMD_ROOT_GET_PROTOCOL_VERSION 0x11
  299. static int hidpp_root_get_feature(struct hidpp_device *hidpp, u16 feature,
  300. u8 *feature_index, u8 *feature_type)
  301. {
  302. struct hidpp_report response;
  303. int ret;
  304. u8 params[2] = { feature >> 8, feature & 0x00FF };
  305. ret = hidpp_send_fap_command_sync(hidpp,
  306. HIDPP_PAGE_ROOT_IDX,
  307. CMD_ROOT_GET_FEATURE,
  308. params, 2, &response);
  309. if (ret)
  310. return ret;
  311. *feature_index = response.fap.params[0];
  312. *feature_type = response.fap.params[1];
  313. return ret;
  314. }
  315. static int hidpp_root_get_protocol_version(struct hidpp_device *hidpp)
  316. {
  317. struct hidpp_report response;
  318. int ret;
  319. ret = hidpp_send_fap_command_sync(hidpp,
  320. HIDPP_PAGE_ROOT_IDX,
  321. CMD_ROOT_GET_PROTOCOL_VERSION,
  322. NULL, 0, &response);
  323. if (ret == HIDPP_ERROR_INVALID_SUBID) {
  324. hidpp->protocol_major = 1;
  325. hidpp->protocol_minor = 0;
  326. return 0;
  327. }
  328. /* the device might not be connected */
  329. if (ret == HIDPP_ERROR_RESOURCE_ERROR)
  330. return -EIO;
  331. if (ret > 0) {
  332. hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
  333. __func__, ret);
  334. return -EPROTO;
  335. }
  336. if (ret)
  337. return ret;
  338. hidpp->protocol_major = response.fap.params[0];
  339. hidpp->protocol_minor = response.fap.params[1];
  340. return ret;
  341. }
  342. static bool hidpp_is_connected(struct hidpp_device *hidpp)
  343. {
  344. int ret;
  345. ret = hidpp_root_get_protocol_version(hidpp);
  346. if (!ret)
  347. hid_dbg(hidpp->hid_dev, "HID++ %u.%u device connected.\n",
  348. hidpp->protocol_major, hidpp->protocol_minor);
  349. return ret == 0;
  350. }
  351. /* -------------------------------------------------------------------------- */
  352. /* 0x0005: GetDeviceNameType */
  353. /* -------------------------------------------------------------------------- */
  354. #define HIDPP_PAGE_GET_DEVICE_NAME_TYPE 0x0005
  355. #define CMD_GET_DEVICE_NAME_TYPE_GET_COUNT 0x01
  356. #define CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME 0x11
  357. #define CMD_GET_DEVICE_NAME_TYPE_GET_TYPE 0x21
  358. static int hidpp_devicenametype_get_count(struct hidpp_device *hidpp,
  359. u8 feature_index, u8 *nameLength)
  360. {
  361. struct hidpp_report response;
  362. int ret;
  363. ret = hidpp_send_fap_command_sync(hidpp, feature_index,
  364. CMD_GET_DEVICE_NAME_TYPE_GET_COUNT, NULL, 0, &response);
  365. if (ret > 0) {
  366. hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
  367. __func__, ret);
  368. return -EPROTO;
  369. }
  370. if (ret)
  371. return ret;
  372. *nameLength = response.fap.params[0];
  373. return ret;
  374. }
  375. static int hidpp_devicenametype_get_device_name(struct hidpp_device *hidpp,
  376. u8 feature_index, u8 char_index, char *device_name, int len_buf)
  377. {
  378. struct hidpp_report response;
  379. int ret, i;
  380. int count;
  381. ret = hidpp_send_fap_command_sync(hidpp, feature_index,
  382. CMD_GET_DEVICE_NAME_TYPE_GET_DEVICE_NAME, &char_index, 1,
  383. &response);
  384. if (ret > 0) {
  385. hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
  386. __func__, ret);
  387. return -EPROTO;
  388. }
  389. if (ret)
  390. return ret;
  391. if (response.report_id == REPORT_ID_HIDPP_LONG)
  392. count = HIDPP_REPORT_LONG_LENGTH - 4;
  393. else
  394. count = HIDPP_REPORT_SHORT_LENGTH - 4;
  395. if (len_buf < count)
  396. count = len_buf;
  397. for (i = 0; i < count; i++)
  398. device_name[i] = response.fap.params[i];
  399. return count;
  400. }
  401. static char *hidpp_get_device_name(struct hidpp_device *hidpp)
  402. {
  403. u8 feature_type;
  404. u8 feature_index;
  405. u8 __name_length;
  406. char *name;
  407. unsigned index = 0;
  408. int ret;
  409. ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_GET_DEVICE_NAME_TYPE,
  410. &feature_index, &feature_type);
  411. if (ret)
  412. return NULL;
  413. ret = hidpp_devicenametype_get_count(hidpp, feature_index,
  414. &__name_length);
  415. if (ret)
  416. return NULL;
  417. name = kzalloc(__name_length + 1, GFP_KERNEL);
  418. if (!name)
  419. return NULL;
  420. while (index < __name_length) {
  421. ret = hidpp_devicenametype_get_device_name(hidpp,
  422. feature_index, index, name + index,
  423. __name_length - index);
  424. if (ret <= 0) {
  425. kfree(name);
  426. return NULL;
  427. }
  428. index += ret;
  429. }
  430. /* include the terminating '\0' */
  431. hidpp_prefix_name(&name, __name_length + 1);
  432. return name;
  433. }
  434. /* -------------------------------------------------------------------------- */
  435. /* 0x6100: TouchPadRawXY */
  436. /* -------------------------------------------------------------------------- */
  437. #define HIDPP_PAGE_TOUCHPAD_RAW_XY 0x6100
  438. #define CMD_TOUCHPAD_GET_RAW_INFO 0x01
  439. #define CMD_TOUCHPAD_SET_RAW_REPORT_STATE 0x21
  440. #define EVENT_TOUCHPAD_RAW_XY 0x00
  441. #define TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT 0x01
  442. #define TOUCHPAD_RAW_XY_ORIGIN_UPPER_LEFT 0x03
  443. struct hidpp_touchpad_raw_info {
  444. u16 x_size;
  445. u16 y_size;
  446. u8 z_range;
  447. u8 area_range;
  448. u8 timestamp_unit;
  449. u8 maxcontacts;
  450. u8 origin;
  451. u16 res;
  452. };
  453. struct hidpp_touchpad_raw_xy_finger {
  454. u8 contact_type;
  455. u8 contact_status;
  456. u16 x;
  457. u16 y;
  458. u8 z;
  459. u8 area;
  460. u8 finger_id;
  461. };
  462. struct hidpp_touchpad_raw_xy {
  463. u16 timestamp;
  464. struct hidpp_touchpad_raw_xy_finger fingers[2];
  465. u8 spurious_flag;
  466. u8 end_of_frame;
  467. u8 finger_count;
  468. u8 button;
  469. };
  470. static int hidpp_touchpad_get_raw_info(struct hidpp_device *hidpp,
  471. u8 feature_index, struct hidpp_touchpad_raw_info *raw_info)
  472. {
  473. struct hidpp_report response;
  474. int ret;
  475. u8 *params = (u8 *)response.fap.params;
  476. ret = hidpp_send_fap_command_sync(hidpp, feature_index,
  477. CMD_TOUCHPAD_GET_RAW_INFO, NULL, 0, &response);
  478. if (ret > 0) {
  479. hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n",
  480. __func__, ret);
  481. return -EPROTO;
  482. }
  483. if (ret)
  484. return ret;
  485. raw_info->x_size = get_unaligned_be16(&params[0]);
  486. raw_info->y_size = get_unaligned_be16(&params[2]);
  487. raw_info->z_range = params[4];
  488. raw_info->area_range = params[5];
  489. raw_info->maxcontacts = params[7];
  490. raw_info->origin = params[8];
  491. /* res is given in unit per inch */
  492. raw_info->res = get_unaligned_be16(&params[13]) * 2 / 51;
  493. return ret;
  494. }
  495. static int hidpp_touchpad_set_raw_report_state(struct hidpp_device *hidpp_dev,
  496. u8 feature_index, bool send_raw_reports,
  497. bool sensor_enhanced_settings)
  498. {
  499. struct hidpp_report response;
  500. /*
  501. * Params:
  502. * bit 0 - enable raw
  503. * bit 1 - 16bit Z, no area
  504. * bit 2 - enhanced sensitivity
  505. * bit 3 - width, height (4 bits each) instead of area
  506. * bit 4 - send raw + gestures (degrades smoothness)
  507. * remaining bits - reserved
  508. */
  509. u8 params = send_raw_reports | (sensor_enhanced_settings << 2);
  510. return hidpp_send_fap_command_sync(hidpp_dev, feature_index,
  511. CMD_TOUCHPAD_SET_RAW_REPORT_STATE, &params, 1, &response);
  512. }
  513. static void hidpp_touchpad_touch_event(u8 *data,
  514. struct hidpp_touchpad_raw_xy_finger *finger)
  515. {
  516. u8 x_m = data[0] << 2;
  517. u8 y_m = data[2] << 2;
  518. finger->x = x_m << 6 | data[1];
  519. finger->y = y_m << 6 | data[3];
  520. finger->contact_type = data[0] >> 6;
  521. finger->contact_status = data[2] >> 6;
  522. finger->z = data[4];
  523. finger->area = data[5];
  524. finger->finger_id = data[6] >> 4;
  525. }
  526. static void hidpp_touchpad_raw_xy_event(struct hidpp_device *hidpp_dev,
  527. u8 *data, struct hidpp_touchpad_raw_xy *raw_xy)
  528. {
  529. memset(raw_xy, 0, sizeof(struct hidpp_touchpad_raw_xy));
  530. raw_xy->end_of_frame = data[8] & 0x01;
  531. raw_xy->spurious_flag = (data[8] >> 1) & 0x01;
  532. raw_xy->finger_count = data[15] & 0x0f;
  533. raw_xy->button = (data[8] >> 2) & 0x01;
  534. if (raw_xy->finger_count) {
  535. hidpp_touchpad_touch_event(&data[2], &raw_xy->fingers[0]);
  536. hidpp_touchpad_touch_event(&data[9], &raw_xy->fingers[1]);
  537. }
  538. }
  539. /* ************************************************************************** */
  540. /* */
  541. /* Device Support */
  542. /* */
  543. /* ************************************************************************** */
  544. /* -------------------------------------------------------------------------- */
  545. /* Touchpad HID++ devices */
  546. /* -------------------------------------------------------------------------- */
  547. #define WTP_MANUAL_RESOLUTION 39
  548. struct wtp_data {
  549. struct input_dev *input;
  550. u16 x_size, y_size;
  551. u8 finger_count;
  552. u8 mt_feature_index;
  553. u8 button_feature_index;
  554. u8 maxcontacts;
  555. bool flip_y;
  556. unsigned int resolution;
  557. };
  558. static int wtp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  559. struct hid_field *field, struct hid_usage *usage,
  560. unsigned long **bit, int *max)
  561. {
  562. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  563. if ((hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT) &&
  564. (field->application == HID_GD_KEYBOARD))
  565. return 0;
  566. return -1;
  567. }
  568. static void wtp_populate_input(struct hidpp_device *hidpp,
  569. struct input_dev *input_dev, bool origin_is_hid_core)
  570. {
  571. struct wtp_data *wd = hidpp->private_data;
  572. if ((hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT) && origin_is_hid_core)
  573. /* this is the generic hid-input call */
  574. return;
  575. __set_bit(EV_ABS, input_dev->evbit);
  576. __set_bit(EV_KEY, input_dev->evbit);
  577. __clear_bit(EV_REL, input_dev->evbit);
  578. __clear_bit(EV_LED, input_dev->evbit);
  579. input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, wd->x_size, 0, 0);
  580. input_abs_set_res(input_dev, ABS_MT_POSITION_X, wd->resolution);
  581. input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, wd->y_size, 0, 0);
  582. input_abs_set_res(input_dev, ABS_MT_POSITION_Y, wd->resolution);
  583. /* Max pressure is not given by the devices, pick one */
  584. input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 50, 0, 0);
  585. input_set_capability(input_dev, EV_KEY, BTN_LEFT);
  586. if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS)
  587. input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
  588. else
  589. __set_bit(INPUT_PROP_BUTTONPAD, input_dev->propbit);
  590. input_mt_init_slots(input_dev, wd->maxcontacts, INPUT_MT_POINTER |
  591. INPUT_MT_DROP_UNUSED);
  592. wd->input = input_dev;
  593. }
  594. static void wtp_touch_event(struct wtp_data *wd,
  595. struct hidpp_touchpad_raw_xy_finger *touch_report)
  596. {
  597. int slot;
  598. if (!touch_report->finger_id || touch_report->contact_type)
  599. /* no actual data */
  600. return;
  601. slot = input_mt_get_slot_by_key(wd->input, touch_report->finger_id);
  602. input_mt_slot(wd->input, slot);
  603. input_mt_report_slot_state(wd->input, MT_TOOL_FINGER,
  604. touch_report->contact_status);
  605. if (touch_report->contact_status) {
  606. input_event(wd->input, EV_ABS, ABS_MT_POSITION_X,
  607. touch_report->x);
  608. input_event(wd->input, EV_ABS, ABS_MT_POSITION_Y,
  609. wd->flip_y ? wd->y_size - touch_report->y :
  610. touch_report->y);
  611. input_event(wd->input, EV_ABS, ABS_MT_PRESSURE,
  612. touch_report->area);
  613. }
  614. }
  615. static void wtp_send_raw_xy_event(struct hidpp_device *hidpp,
  616. struct hidpp_touchpad_raw_xy *raw)
  617. {
  618. struct wtp_data *wd = hidpp->private_data;
  619. int i;
  620. for (i = 0; i < 2; i++)
  621. wtp_touch_event(wd, &(raw->fingers[i]));
  622. if (raw->end_of_frame &&
  623. !(hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS))
  624. input_event(wd->input, EV_KEY, BTN_LEFT, raw->button);
  625. if (raw->end_of_frame || raw->finger_count <= 2) {
  626. input_mt_sync_frame(wd->input);
  627. input_sync(wd->input);
  628. }
  629. }
  630. static int wtp_mouse_raw_xy_event(struct hidpp_device *hidpp, u8 *data)
  631. {
  632. struct wtp_data *wd = hidpp->private_data;
  633. u8 c1_area = ((data[7] & 0xf) * (data[7] & 0xf) +
  634. (data[7] >> 4) * (data[7] >> 4)) / 2;
  635. u8 c2_area = ((data[13] & 0xf) * (data[13] & 0xf) +
  636. (data[13] >> 4) * (data[13] >> 4)) / 2;
  637. struct hidpp_touchpad_raw_xy raw = {
  638. .timestamp = data[1],
  639. .fingers = {
  640. {
  641. .contact_type = 0,
  642. .contact_status = !!data[7],
  643. .x = get_unaligned_le16(&data[3]),
  644. .y = get_unaligned_le16(&data[5]),
  645. .z = c1_area,
  646. .area = c1_area,
  647. .finger_id = data[2],
  648. }, {
  649. .contact_type = 0,
  650. .contact_status = !!data[13],
  651. .x = get_unaligned_le16(&data[9]),
  652. .y = get_unaligned_le16(&data[11]),
  653. .z = c2_area,
  654. .area = c2_area,
  655. .finger_id = data[8],
  656. }
  657. },
  658. .finger_count = wd->maxcontacts,
  659. .spurious_flag = 0,
  660. .end_of_frame = (data[0] >> 7) == 0,
  661. .button = data[0] & 0x01,
  662. };
  663. wtp_send_raw_xy_event(hidpp, &raw);
  664. return 1;
  665. }
  666. static int wtp_raw_event(struct hid_device *hdev, u8 *data, int size)
  667. {
  668. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  669. struct wtp_data *wd = hidpp->private_data;
  670. struct hidpp_report *report = (struct hidpp_report *)data;
  671. struct hidpp_touchpad_raw_xy raw;
  672. if (!wd || !wd->input)
  673. return 1;
  674. switch (data[0]) {
  675. case 0x02:
  676. if (size < 2) {
  677. hid_err(hdev, "Received HID report of bad size (%d)",
  678. size);
  679. return 1;
  680. }
  681. if (hidpp->quirks & HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS) {
  682. input_event(wd->input, EV_KEY, BTN_LEFT,
  683. !!(data[1] & 0x01));
  684. input_event(wd->input, EV_KEY, BTN_RIGHT,
  685. !!(data[1] & 0x02));
  686. input_sync(wd->input);
  687. return 0;
  688. } else {
  689. if (size < 21)
  690. return 1;
  691. return wtp_mouse_raw_xy_event(hidpp, &data[7]);
  692. }
  693. case REPORT_ID_HIDPP_LONG:
  694. /* size is already checked in hidpp_raw_event. */
  695. if ((report->fap.feature_index != wd->mt_feature_index) ||
  696. (report->fap.funcindex_clientid != EVENT_TOUCHPAD_RAW_XY))
  697. return 1;
  698. hidpp_touchpad_raw_xy_event(hidpp, data + 4, &raw);
  699. wtp_send_raw_xy_event(hidpp, &raw);
  700. return 0;
  701. }
  702. return 0;
  703. }
  704. static int wtp_get_config(struct hidpp_device *hidpp)
  705. {
  706. struct wtp_data *wd = hidpp->private_data;
  707. struct hidpp_touchpad_raw_info raw_info = {0};
  708. u8 feature_type;
  709. int ret;
  710. ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_TOUCHPAD_RAW_XY,
  711. &wd->mt_feature_index, &feature_type);
  712. if (ret)
  713. /* means that the device is not powered up */
  714. return ret;
  715. ret = hidpp_touchpad_get_raw_info(hidpp, wd->mt_feature_index,
  716. &raw_info);
  717. if (ret)
  718. return ret;
  719. wd->x_size = raw_info.x_size;
  720. wd->y_size = raw_info.y_size;
  721. wd->maxcontacts = raw_info.maxcontacts;
  722. wd->flip_y = raw_info.origin == TOUCHPAD_RAW_XY_ORIGIN_LOWER_LEFT;
  723. wd->resolution = raw_info.res;
  724. if (!wd->resolution)
  725. wd->resolution = WTP_MANUAL_RESOLUTION;
  726. return 0;
  727. }
  728. static int wtp_allocate(struct hid_device *hdev, const struct hid_device_id *id)
  729. {
  730. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  731. struct wtp_data *wd;
  732. wd = devm_kzalloc(&hdev->dev, sizeof(struct wtp_data),
  733. GFP_KERNEL);
  734. if (!wd)
  735. return -ENOMEM;
  736. hidpp->private_data = wd;
  737. return 0;
  738. };
  739. static void wtp_connect(struct hid_device *hdev, bool connected)
  740. {
  741. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  742. struct wtp_data *wd = hidpp->private_data;
  743. int ret;
  744. if (!connected)
  745. return;
  746. if (!wd->x_size) {
  747. ret = wtp_get_config(hidpp);
  748. if (ret) {
  749. hid_err(hdev, "Can not get wtp config: %d\n", ret);
  750. return;
  751. }
  752. }
  753. hidpp_touchpad_set_raw_report_state(hidpp, wd->mt_feature_index,
  754. true, true);
  755. }
  756. /* -------------------------------------------------------------------------- */
  757. /* Generic HID++ devices */
  758. /* -------------------------------------------------------------------------- */
  759. static int hidpp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
  760. struct hid_field *field, struct hid_usage *usage,
  761. unsigned long **bit, int *max)
  762. {
  763. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  764. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
  765. return wtp_input_mapping(hdev, hi, field, usage, bit, max);
  766. return 0;
  767. }
  768. static void hidpp_populate_input(struct hidpp_device *hidpp,
  769. struct input_dev *input, bool origin_is_hid_core)
  770. {
  771. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
  772. wtp_populate_input(hidpp, input, origin_is_hid_core);
  773. }
  774. static void hidpp_input_configured(struct hid_device *hdev,
  775. struct hid_input *hidinput)
  776. {
  777. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  778. struct input_dev *input = hidinput->input;
  779. hidpp_populate_input(hidpp, input, true);
  780. }
  781. static int hidpp_raw_hidpp_event(struct hidpp_device *hidpp, u8 *data,
  782. int size)
  783. {
  784. struct hidpp_report *question = hidpp->send_receive_buf;
  785. struct hidpp_report *answer = hidpp->send_receive_buf;
  786. struct hidpp_report *report = (struct hidpp_report *)data;
  787. /*
  788. * If the mutex is locked then we have a pending answer from a
  789. * previoulsly sent command
  790. */
  791. if (unlikely(mutex_is_locked(&hidpp->send_mutex))) {
  792. /*
  793. * Check for a correct hidpp20 answer or the corresponding
  794. * error
  795. */
  796. if (hidpp_match_answer(question, report) ||
  797. hidpp_match_error(question, report)) {
  798. *answer = *report;
  799. hidpp->answer_available = true;
  800. wake_up(&hidpp->wait);
  801. /*
  802. * This was an answer to a command that this driver sent
  803. * We return 1 to hid-core to avoid forwarding the
  804. * command upstream as it has been treated by the driver
  805. */
  806. return 1;
  807. }
  808. }
  809. if (unlikely(hidpp_report_is_connect_event(report))) {
  810. atomic_set(&hidpp->connected,
  811. !(report->rap.params[0] & (1 << 6)));
  812. if ((hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) &&
  813. (schedule_work(&hidpp->work) == 0))
  814. dbg_hid("%s: connect event already queued\n", __func__);
  815. return 1;
  816. }
  817. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
  818. return wtp_raw_event(hidpp->hid_dev, data, size);
  819. return 0;
  820. }
  821. static int hidpp_raw_event(struct hid_device *hdev, struct hid_report *report,
  822. u8 *data, int size)
  823. {
  824. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  825. switch (data[0]) {
  826. case REPORT_ID_HIDPP_LONG:
  827. if (size != HIDPP_REPORT_LONG_LENGTH) {
  828. hid_err(hdev, "received hid++ report of bad size (%d)",
  829. size);
  830. return 1;
  831. }
  832. return hidpp_raw_hidpp_event(hidpp, data, size);
  833. case REPORT_ID_HIDPP_SHORT:
  834. if (size != HIDPP_REPORT_SHORT_LENGTH) {
  835. hid_err(hdev, "received hid++ report of bad size (%d)",
  836. size);
  837. return 1;
  838. }
  839. return hidpp_raw_hidpp_event(hidpp, data, size);
  840. }
  841. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
  842. return wtp_raw_event(hdev, data, size);
  843. return 0;
  844. }
  845. static void hidpp_overwrite_name(struct hid_device *hdev, bool use_unifying)
  846. {
  847. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  848. char *name;
  849. if (use_unifying)
  850. /*
  851. * the device is connected through an Unifying receiver, and
  852. * might not be already connected.
  853. * Ask the receiver for its name.
  854. */
  855. name = hidpp_get_unifying_name(hidpp);
  856. else
  857. name = hidpp_get_device_name(hidpp);
  858. if (!name)
  859. hid_err(hdev, "unable to retrieve the name of the device");
  860. else
  861. snprintf(hdev->name, sizeof(hdev->name), "%s", name);
  862. kfree(name);
  863. }
  864. static int hidpp_input_open(struct input_dev *dev)
  865. {
  866. struct hid_device *hid = input_get_drvdata(dev);
  867. return hid_hw_open(hid);
  868. }
  869. static void hidpp_input_close(struct input_dev *dev)
  870. {
  871. struct hid_device *hid = input_get_drvdata(dev);
  872. hid_hw_close(hid);
  873. }
  874. static struct input_dev *hidpp_allocate_input(struct hid_device *hdev)
  875. {
  876. struct input_dev *input_dev = devm_input_allocate_device(&hdev->dev);
  877. if (!input_dev)
  878. return NULL;
  879. input_set_drvdata(input_dev, hdev);
  880. input_dev->open = hidpp_input_open;
  881. input_dev->close = hidpp_input_close;
  882. input_dev->name = hdev->name;
  883. input_dev->phys = hdev->phys;
  884. input_dev->uniq = hdev->uniq;
  885. input_dev->id.bustype = hdev->bus;
  886. input_dev->id.vendor = hdev->vendor;
  887. input_dev->id.product = hdev->product;
  888. input_dev->id.version = hdev->version;
  889. input_dev->dev.parent = &hdev->dev;
  890. return input_dev;
  891. }
  892. static void hidpp_connect_event(struct hidpp_device *hidpp)
  893. {
  894. struct hid_device *hdev = hidpp->hid_dev;
  895. int ret = 0;
  896. bool connected = atomic_read(&hidpp->connected);
  897. struct input_dev *input;
  898. char *name, *devm_name;
  899. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)
  900. wtp_connect(hdev, connected);
  901. if (!connected || hidpp->delayed_input)
  902. return;
  903. if (!hidpp->protocol_major) {
  904. ret = !hidpp_is_connected(hidpp);
  905. if (ret) {
  906. hid_err(hdev, "Can not get the protocol version.\n");
  907. return;
  908. }
  909. }
  910. /* the device is already connected, we can ask for its name and
  911. * protocol */
  912. hid_info(hdev, "HID++ %u.%u device connected.\n",
  913. hidpp->protocol_major, hidpp->protocol_minor);
  914. input = hidpp_allocate_input(hdev);
  915. if (!input) {
  916. hid_err(hdev, "cannot allocate new input device: %d\n", ret);
  917. return;
  918. }
  919. name = hidpp_get_device_name(hidpp);
  920. if (!name) {
  921. hid_err(hdev, "unable to retrieve the name of the device");
  922. } else {
  923. devm_name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "%s", name);
  924. if (devm_name)
  925. input->name = devm_name;
  926. kfree(name);
  927. }
  928. hidpp_populate_input(hidpp, input, false);
  929. ret = input_register_device(input);
  930. if (ret)
  931. input_free_device(input);
  932. hidpp->delayed_input = input;
  933. }
  934. static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id)
  935. {
  936. struct hidpp_device *hidpp;
  937. int ret;
  938. bool connected;
  939. unsigned int connect_mask = HID_CONNECT_DEFAULT;
  940. hidpp = devm_kzalloc(&hdev->dev, sizeof(struct hidpp_device),
  941. GFP_KERNEL);
  942. if (!hidpp)
  943. return -ENOMEM;
  944. hidpp->hid_dev = hdev;
  945. hid_set_drvdata(hdev, hidpp);
  946. hidpp->quirks = id->driver_data;
  947. if (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP) {
  948. ret = wtp_allocate(hdev, id);
  949. if (ret)
  950. goto wtp_allocate_fail;
  951. }
  952. INIT_WORK(&hidpp->work, delayed_work_cb);
  953. mutex_init(&hidpp->send_mutex);
  954. init_waitqueue_head(&hidpp->wait);
  955. ret = hid_parse(hdev);
  956. if (ret) {
  957. hid_err(hdev, "%s:parse failed\n", __func__);
  958. goto hid_parse_fail;
  959. }
  960. /* Allow incoming packets */
  961. hid_device_io_start(hdev);
  962. connected = hidpp_is_connected(hidpp);
  963. if (id->group != HID_GROUP_LOGITECH_DJ_DEVICE) {
  964. if (!connected) {
  965. hid_err(hdev, "Device not connected");
  966. hid_device_io_stop(hdev);
  967. goto hid_parse_fail;
  968. }
  969. hid_info(hdev, "HID++ %u.%u device connected.\n",
  970. hidpp->protocol_major, hidpp->protocol_minor);
  971. }
  972. hidpp_overwrite_name(hdev, id->group == HID_GROUP_LOGITECH_DJ_DEVICE);
  973. atomic_set(&hidpp->connected, connected);
  974. if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_WTP)) {
  975. ret = wtp_get_config(hidpp);
  976. if (ret)
  977. goto hid_parse_fail;
  978. }
  979. /* Block incoming packets */
  980. hid_device_io_stop(hdev);
  981. if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT)
  982. connect_mask &= ~HID_CONNECT_HIDINPUT;
  983. /* Re-enable hidinput for multi-input devices */
  984. if (hidpp->quirks & HIDPP_QUIRK_MULTI_INPUT)
  985. connect_mask |= HID_CONNECT_HIDINPUT;
  986. ret = hid_hw_start(hdev, connect_mask);
  987. if (ret) {
  988. hid_err(hdev, "%s:hid_hw_start returned error\n", __func__);
  989. goto hid_hw_start_fail;
  990. }
  991. if (hidpp->quirks & HIDPP_QUIRK_DELAYED_INIT) {
  992. /* Allow incoming packets */
  993. hid_device_io_start(hdev);
  994. hidpp_connect_event(hidpp);
  995. }
  996. return ret;
  997. hid_hw_start_fail:
  998. hid_parse_fail:
  999. cancel_work_sync(&hidpp->work);
  1000. mutex_destroy(&hidpp->send_mutex);
  1001. wtp_allocate_fail:
  1002. hid_set_drvdata(hdev, NULL);
  1003. return ret;
  1004. }
  1005. static void hidpp_remove(struct hid_device *hdev)
  1006. {
  1007. struct hidpp_device *hidpp = hid_get_drvdata(hdev);
  1008. cancel_work_sync(&hidpp->work);
  1009. mutex_destroy(&hidpp->send_mutex);
  1010. hid_hw_stop(hdev);
  1011. }
  1012. static const struct hid_device_id hidpp_devices[] = {
  1013. { /* wireless touchpad */
  1014. HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
  1015. USB_VENDOR_ID_LOGITECH, 0x4011),
  1016. .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT |
  1017. HIDPP_QUIRK_WTP_PHYSICAL_BUTTONS },
  1018. { /* wireless touchpad T650 */
  1019. HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
  1020. USB_VENDOR_ID_LOGITECH, 0x4101),
  1021. .driver_data = HIDPP_QUIRK_CLASS_WTP | HIDPP_QUIRK_DELAYED_INIT },
  1022. { /* wireless touchpad T651 */
  1023. HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_LOGITECH,
  1024. USB_DEVICE_ID_LOGITECH_T651),
  1025. .driver_data = HIDPP_QUIRK_CLASS_WTP },
  1026. { /* Keyboard TK820 */
  1027. HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
  1028. USB_VENDOR_ID_LOGITECH, 0x4102),
  1029. .driver_data = HIDPP_QUIRK_DELAYED_INIT | HIDPP_QUIRK_MULTI_INPUT |
  1030. HIDPP_QUIRK_CLASS_WTP },
  1031. { HID_DEVICE(BUS_USB, HID_GROUP_LOGITECH_DJ_DEVICE,
  1032. USB_VENDOR_ID_LOGITECH, HID_ANY_ID)},
  1033. {}
  1034. };
  1035. MODULE_DEVICE_TABLE(hid, hidpp_devices);
  1036. static struct hid_driver hidpp_driver = {
  1037. .name = "logitech-hidpp-device",
  1038. .id_table = hidpp_devices,
  1039. .probe = hidpp_probe,
  1040. .remove = hidpp_remove,
  1041. .raw_event = hidpp_raw_event,
  1042. .input_configured = hidpp_input_configured,
  1043. .input_mapping = hidpp_input_mapping,
  1044. };
  1045. module_hid_driver(hidpp_driver);