hid-logitech-hidpp.c 34 KB

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