hid-logitech-hidpp.c 33 KB

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