wacom_sys.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * drivers/input/tablet/wacom_sys.c
  3. *
  4. * USB Wacom tablet support - system specific code
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include "wacom.h"
  13. #include "wacom_wac.h"
  14. /* defines to get HID report descriptor */
  15. #define HID_DEVICET_HID (USB_TYPE_CLASS | 0x01)
  16. #define HID_DEVICET_REPORT (USB_TYPE_CLASS | 0x02)
  17. #define HID_USAGE_UNDEFINED 0x00
  18. #define HID_USAGE_PAGE 0x05
  19. #define HID_USAGE_PAGE_DIGITIZER 0x0d
  20. #define HID_USAGE_PAGE_DESKTOP 0x01
  21. #define HID_USAGE 0x09
  22. #define HID_USAGE_X 0x30
  23. #define HID_USAGE_Y 0x31
  24. #define HID_USAGE_X_TILT 0x3d
  25. #define HID_USAGE_Y_TILT 0x3e
  26. #define HID_USAGE_FINGER 0x22
  27. #define HID_USAGE_STYLUS 0x20
  28. #define HID_COLLECTION 0xc0
  29. enum {
  30. WCM_UNDEFINED = 0,
  31. WCM_DESKTOP,
  32. WCM_DIGITIZER,
  33. };
  34. struct hid_descriptor {
  35. struct usb_descriptor_header header;
  36. __le16 bcdHID;
  37. u8 bCountryCode;
  38. u8 bNumDescriptors;
  39. u8 bDescriptorType;
  40. __le16 wDescriptorLength;
  41. } __attribute__ ((packed));
  42. /* defines to get/set USB message */
  43. #define USB_REQ_GET_REPORT 0x01
  44. #define USB_REQ_SET_REPORT 0x09
  45. #define WAC_HID_FEATURE_REPORT 0x03
  46. static int usb_get_report(struct usb_interface *intf, unsigned char type,
  47. unsigned char id, void *buf, int size)
  48. {
  49. return usb_control_msg(interface_to_usbdev(intf),
  50. usb_rcvctrlpipe(interface_to_usbdev(intf), 0),
  51. USB_REQ_GET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  52. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  53. buf, size, 100);
  54. }
  55. static int usb_set_report(struct usb_interface *intf, unsigned char type,
  56. unsigned char id, void *buf, int size)
  57. {
  58. return usb_control_msg(interface_to_usbdev(intf),
  59. usb_sndctrlpipe(interface_to_usbdev(intf), 0),
  60. USB_REQ_SET_REPORT, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
  61. (type << 8) + id, intf->altsetting[0].desc.bInterfaceNumber,
  62. buf, size, 1000);
  63. }
  64. static struct input_dev * get_input_dev(struct wacom_combo *wcombo)
  65. {
  66. return wcombo->wacom->dev;
  67. }
  68. static void wacom_sys_irq(struct urb *urb)
  69. {
  70. struct wacom *wacom = urb->context;
  71. struct wacom_combo wcombo;
  72. int retval;
  73. switch (urb->status) {
  74. case 0:
  75. /* success */
  76. break;
  77. case -ECONNRESET:
  78. case -ENOENT:
  79. case -ESHUTDOWN:
  80. /* this urb is terminated, clean up */
  81. dbg("%s - urb shutting down with status: %d", __func__, urb->status);
  82. return;
  83. default:
  84. dbg("%s - nonzero urb status received: %d", __func__, urb->status);
  85. goto exit;
  86. }
  87. wcombo.wacom = wacom;
  88. wcombo.urb = urb;
  89. if (wacom_wac_irq(wacom->wacom_wac, (void *)&wcombo))
  90. input_sync(get_input_dev(&wcombo));
  91. exit:
  92. usb_mark_last_busy(wacom->usbdev);
  93. retval = usb_submit_urb (urb, GFP_ATOMIC);
  94. if (retval)
  95. err ("%s - usb_submit_urb failed with result %d",
  96. __func__, retval);
  97. }
  98. void wacom_report_key(void *wcombo, unsigned int key_type, int key_data)
  99. {
  100. input_report_key(get_input_dev((struct wacom_combo *)wcombo), key_type, key_data);
  101. }
  102. void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data)
  103. {
  104. input_report_abs(get_input_dev((struct wacom_combo *)wcombo), abs_type, abs_data);
  105. }
  106. void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data)
  107. {
  108. input_report_rel(get_input_dev((struct wacom_combo *)wcombo), rel_type, rel_data);
  109. }
  110. void wacom_input_event(void *wcombo, unsigned int type, unsigned int code, int value)
  111. {
  112. input_event(get_input_dev((struct wacom_combo *)wcombo), type, code, value);
  113. }
  114. __u16 wacom_be16_to_cpu(unsigned char *data)
  115. {
  116. __u16 value;
  117. value = be16_to_cpu(*(__be16 *) data);
  118. return value;
  119. }
  120. __u16 wacom_le16_to_cpu(unsigned char *data)
  121. {
  122. __u16 value;
  123. value = le16_to_cpu(*(__le16 *) data);
  124. return value;
  125. }
  126. void wacom_input_sync(void *wcombo)
  127. {
  128. input_sync(get_input_dev((struct wacom_combo *)wcombo));
  129. }
  130. static int wacom_open(struct input_dev *dev)
  131. {
  132. struct wacom *wacom = input_get_drvdata(dev);
  133. mutex_lock(&wacom->lock);
  134. wacom->irq->dev = wacom->usbdev;
  135. if (usb_autopm_get_interface(wacom->intf) < 0) {
  136. mutex_unlock(&wacom->lock);
  137. return -EIO;
  138. }
  139. if (usb_submit_urb(wacom->irq, GFP_KERNEL)) {
  140. usb_autopm_put_interface(wacom->intf);
  141. mutex_unlock(&wacom->lock);
  142. return -EIO;
  143. }
  144. wacom->open = 1;
  145. wacom->intf->needs_remote_wakeup = 1;
  146. mutex_unlock(&wacom->lock);
  147. return 0;
  148. }
  149. static void wacom_close(struct input_dev *dev)
  150. {
  151. struct wacom *wacom = input_get_drvdata(dev);
  152. mutex_lock(&wacom->lock);
  153. usb_kill_urb(wacom->irq);
  154. wacom->open = 0;
  155. wacom->intf->needs_remote_wakeup = 0;
  156. mutex_unlock(&wacom->lock);
  157. }
  158. void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  159. {
  160. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_1) |
  161. BIT_MASK(BTN_5);
  162. input_set_abs_params(input_dev, ABS_WHEEL, 0, 71, 0, 0);
  163. }
  164. void input_dev_g4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  165. {
  166. input_dev->evbit[0] |= BIT_MASK(EV_MSC);
  167. input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
  168. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  169. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
  170. BIT_MASK(BTN_4);
  171. }
  172. void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  173. {
  174. input_dev->evbit[0] |= BIT_MASK(EV_REL);
  175. input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
  176. input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
  177. BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);
  178. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
  179. BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) |
  180. BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2);
  181. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
  182. }
  183. void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  184. {
  185. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  186. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) |
  187. BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3);
  188. input_set_abs_params(input_dev, ABS_RX, 0, 4096, 0, 0);
  189. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  190. }
  191. void input_dev_i3(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  192. {
  193. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) |
  194. BIT_MASK(BTN_5) | BIT_MASK(BTN_6) | BIT_MASK(BTN_7);
  195. input_set_abs_params(input_dev, ABS_RY, 0, 4096, 0, 0);
  196. }
  197. void input_dev_i4s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  198. {
  199. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_FINGER);
  200. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_0) | BIT_MASK(BTN_1) | BIT_MASK(BTN_2) | BIT_MASK(BTN_3);
  201. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_4) | BIT_MASK(BTN_5) | BIT_MASK(BTN_6);
  202. input_set_abs_params(input_dev, ABS_Z, -900, 899, 0, 0);
  203. }
  204. void input_dev_i4(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  205. {
  206. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_7) | BIT_MASK(BTN_8);
  207. }
  208. void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  209. {
  210. input_dev->keybit[BIT_WORD(BTN_MISC)] |= BIT_MASK(BTN_8) | BIT_MASK(BTN_9);
  211. }
  212. void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  213. {
  214. input_dev->evbit[0] |= BIT_MASK(EV_MSC) | BIT_MASK(EV_REL);
  215. input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
  216. input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);
  217. input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_LEFT) |
  218. BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE) |
  219. BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
  220. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
  221. BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) |
  222. BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) |
  223. BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) |
  224. BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2);
  225. input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0);
  226. input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
  227. input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
  228. input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
  229. input_set_abs_params(input_dev, ABS_RZ, -900, 899, 0, 0);
  230. input_set_abs_params(input_dev, ABS_THROTTLE, -1023, 1023, 0, 0);
  231. }
  232. void input_dev_pl(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  233. {
  234. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_PEN) |
  235. BIT_MASK(BTN_STYLUS) | BIT_MASK(BTN_STYLUS2);
  236. }
  237. void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  238. {
  239. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER);
  240. }
  241. void input_dev_tpc(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  242. {
  243. if (wacom_wac->features->device_type == BTN_TOOL_DOUBLETAP ||
  244. wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) {
  245. input_set_abs_params(input_dev, ABS_RX, 0, wacom_wac->features->x_phy, 0, 0);
  246. input_set_abs_params(input_dev, ABS_RY, 0, wacom_wac->features->y_phy, 0, 0);
  247. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP);
  248. }
  249. }
  250. void input_dev_tpc2fg(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
  251. {
  252. if (wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) {
  253. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_TRIPLETAP);
  254. input_dev->evbit[0] |= BIT_MASK(EV_MSC);
  255. input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
  256. }
  257. }
  258. static int wacom_parse_hid(struct usb_interface *intf, struct hid_descriptor *hid_desc,
  259. struct wacom_features *features)
  260. {
  261. struct usb_device *dev = interface_to_usbdev(intf);
  262. char limit = 0;
  263. /* result has to be defined as int for some devices */
  264. int result = 0;
  265. int i = 0, usage = WCM_UNDEFINED, finger = 0, pen = 0;
  266. unsigned char *report;
  267. report = kzalloc(hid_desc->wDescriptorLength, GFP_KERNEL);
  268. if (!report)
  269. return -ENOMEM;
  270. /* retrive report descriptors */
  271. do {
  272. result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  273. USB_REQ_GET_DESCRIPTOR,
  274. USB_RECIP_INTERFACE | USB_DIR_IN,
  275. HID_DEVICET_REPORT << 8,
  276. intf->altsetting[0].desc.bInterfaceNumber, /* interface */
  277. report,
  278. hid_desc->wDescriptorLength,
  279. 5000); /* 5 secs */
  280. } while (result < 0 && limit++ < 5);
  281. /* No need to parse the Descriptor. It isn't an error though */
  282. if (result < 0)
  283. goto out;
  284. for (i = 0; i < hid_desc->wDescriptorLength; i++) {
  285. switch (report[i]) {
  286. case HID_USAGE_PAGE:
  287. switch (report[i + 1]) {
  288. case HID_USAGE_PAGE_DIGITIZER:
  289. usage = WCM_DIGITIZER;
  290. i++;
  291. break;
  292. case HID_USAGE_PAGE_DESKTOP:
  293. usage = WCM_DESKTOP;
  294. i++;
  295. break;
  296. }
  297. break;
  298. case HID_USAGE:
  299. switch (report[i + 1]) {
  300. case HID_USAGE_X:
  301. if (usage == WCM_DESKTOP) {
  302. if (finger) {
  303. features->device_type = BTN_TOOL_DOUBLETAP;
  304. if (features->type == TABLETPC2FG) {
  305. /* need to reset back */
  306. features->pktlen = WACOM_PKGLEN_TPC2FG;
  307. features->device_type = BTN_TOOL_TRIPLETAP;
  308. }
  309. features->x_max =
  310. wacom_le16_to_cpu(&report[i + 3]);
  311. features->x_phy =
  312. wacom_le16_to_cpu(&report[i + 6]);
  313. features->unit = report[i + 9];
  314. features->unitExpo = report[i + 11];
  315. i += 12;
  316. } else if (pen) {
  317. /* penabled only accepts exact bytes of data */
  318. if (features->type == TABLETPC2FG)
  319. features->pktlen = WACOM_PKGLEN_PENABLED;
  320. features->device_type = BTN_TOOL_PEN;
  321. features->x_max =
  322. wacom_le16_to_cpu(&report[i + 3]);
  323. i += 4;
  324. }
  325. } else if (usage == WCM_DIGITIZER) {
  326. /* max pressure isn't reported
  327. features->pressure_max = (unsigned short)
  328. (report[i+4] << 8 | report[i + 3]);
  329. */
  330. features->pressure_max = 255;
  331. i += 4;
  332. }
  333. break;
  334. case HID_USAGE_Y:
  335. if (usage == WCM_DESKTOP) {
  336. if (finger) {
  337. features->device_type = BTN_TOOL_DOUBLETAP;
  338. if (features->type == TABLETPC2FG) {
  339. /* need to reset back */
  340. features->pktlen = WACOM_PKGLEN_TPC2FG;
  341. features->device_type = BTN_TOOL_TRIPLETAP;
  342. features->y_max =
  343. wacom_le16_to_cpu(&report[i + 3]);
  344. features->y_phy =
  345. wacom_le16_to_cpu(&report[i + 6]);
  346. i += 7;
  347. } else {
  348. features->y_max =
  349. features->x_max;
  350. features->y_phy =
  351. wacom_le16_to_cpu(&report[i + 3]);
  352. i += 4;
  353. }
  354. } else if (pen) {
  355. /* penabled only accepts exact bytes of data */
  356. if (features->type == TABLETPC2FG)
  357. features->pktlen = WACOM_PKGLEN_PENABLED;
  358. features->device_type = BTN_TOOL_PEN;
  359. features->y_max =
  360. wacom_le16_to_cpu(&report[i + 3]);
  361. i += 4;
  362. }
  363. }
  364. break;
  365. case HID_USAGE_FINGER:
  366. finger = 1;
  367. i++;
  368. break;
  369. case HID_USAGE_STYLUS:
  370. pen = 1;
  371. i++;
  372. break;
  373. case HID_USAGE_UNDEFINED:
  374. if (usage == WCM_DESKTOP && finger) /* capacity */
  375. features->pressure_max =
  376. wacom_le16_to_cpu(&report[i + 3]);
  377. i += 4;
  378. break;
  379. }
  380. break;
  381. case HID_COLLECTION:
  382. /* reset UsagePage and Finger */
  383. finger = usage = 0;
  384. break;
  385. }
  386. }
  387. out:
  388. result = 0;
  389. kfree(report);
  390. return result;
  391. }
  392. static int wacom_query_tablet_data(struct usb_interface *intf, struct wacom_features *features)
  393. {
  394. unsigned char *rep_data;
  395. int limit = 0, report_id = 2;
  396. int error = -ENOMEM;
  397. rep_data = kmalloc(2, GFP_KERNEL);
  398. if (!rep_data)
  399. return error;
  400. /* ask to report tablet data if it is 2FGT or not a Tablet PC */
  401. if (features->device_type == BTN_TOOL_TRIPLETAP) {
  402. do {
  403. rep_data[0] = 3;
  404. rep_data[1] = 4;
  405. report_id = 3;
  406. error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
  407. report_id, rep_data, 2);
  408. if (error >= 0)
  409. error = usb_get_report(intf,
  410. WAC_HID_FEATURE_REPORT, report_id,
  411. rep_data, 3);
  412. } while ((error < 0 || rep_data[1] != 4) && limit++ < 5);
  413. } else if (features->type != TABLETPC && features->type != TABLETPC2FG) {
  414. do {
  415. rep_data[0] = 2;
  416. rep_data[1] = 2;
  417. error = usb_set_report(intf, WAC_HID_FEATURE_REPORT,
  418. report_id, rep_data, 2);
  419. if (error >= 0)
  420. error = usb_get_report(intf,
  421. WAC_HID_FEATURE_REPORT, report_id,
  422. rep_data, 2);
  423. } while ((error < 0 || rep_data[1] != 2) && limit++ < 5);
  424. }
  425. kfree(rep_data);
  426. return error < 0 ? error : 0;
  427. }
  428. static int wacom_retrieve_hid_descriptor(struct usb_interface *intf,
  429. struct wacom_features *features)
  430. {
  431. int error = 0;
  432. struct usb_host_interface *interface = intf->cur_altsetting;
  433. struct hid_descriptor *hid_desc;
  434. /* default device to penabled */
  435. features->device_type = BTN_TOOL_PEN;
  436. /* only Tablet PCs need to retrieve the info */
  437. if ((features->type != TABLETPC) && (features->type != TABLETPC2FG))
  438. goto out;
  439. if (usb_get_extra_descriptor(interface, HID_DEVICET_HID, &hid_desc)) {
  440. if (usb_get_extra_descriptor(&interface->endpoint[0],
  441. HID_DEVICET_REPORT, &hid_desc)) {
  442. printk("wacom: can not retrieve extra class descriptor\n");
  443. error = 1;
  444. goto out;
  445. }
  446. }
  447. error = wacom_parse_hid(intf, hid_desc, features);
  448. if (error)
  449. goto out;
  450. /* touch device found but size is not defined. use default */
  451. if (features->device_type == BTN_TOOL_DOUBLETAP && !features->x_max) {
  452. features->x_max = 1023;
  453. features->y_max = 1023;
  454. }
  455. out:
  456. return error;
  457. }
  458. static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *id)
  459. {
  460. struct usb_device *dev = interface_to_usbdev(intf);
  461. struct usb_endpoint_descriptor *endpoint;
  462. struct wacom *wacom;
  463. struct wacom_wac *wacom_wac;
  464. struct wacom_features *features;
  465. struct input_dev *input_dev;
  466. int error = -ENOMEM;
  467. wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
  468. wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
  469. input_dev = input_allocate_device();
  470. if (!wacom || !input_dev || !wacom_wac)
  471. goto fail1;
  472. wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX, GFP_KERNEL, &wacom->data_dma);
  473. if (!wacom_wac->data)
  474. goto fail1;
  475. wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
  476. if (!wacom->irq)
  477. goto fail2;
  478. wacom->usbdev = dev;
  479. wacom->dev = input_dev;
  480. wacom->intf = intf;
  481. mutex_init(&wacom->lock);
  482. usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
  483. strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
  484. wacom_wac->features = features = get_wacom_feature(id);
  485. BUG_ON(features->pktlen > WACOM_PKGLEN_MAX);
  486. input_dev->name = wacom_wac->features->name;
  487. wacom->wacom_wac = wacom_wac;
  488. usb_to_input_id(dev, &input_dev->id);
  489. input_dev->dev.parent = &intf->dev;
  490. input_set_drvdata(input_dev, wacom);
  491. input_dev->open = wacom_open;
  492. input_dev->close = wacom_close;
  493. endpoint = &intf->cur_altsetting->endpoint[0].desc;
  494. /* Retrieve the physical and logical size for OEM devices */
  495. error = wacom_retrieve_hid_descriptor(intf, features);
  496. if (error)
  497. goto fail2;
  498. input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
  499. input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH);
  500. input_set_abs_params(input_dev, ABS_X, 0, features->x_max, 4, 0);
  501. input_set_abs_params(input_dev, ABS_Y, 0, features->y_max, 4, 0);
  502. input_set_abs_params(input_dev, ABS_PRESSURE, 0, features->pressure_max, 0, 0);
  503. input_dev->absbit[BIT_WORD(ABS_MISC)] |= BIT_MASK(ABS_MISC);
  504. wacom_init_input_dev(input_dev, wacom_wac);
  505. usb_fill_int_urb(wacom->irq, dev,
  506. usb_rcvintpipe(dev, endpoint->bEndpointAddress),
  507. wacom_wac->data, features->pktlen,
  508. wacom_sys_irq, wacom, endpoint->bInterval);
  509. wacom->irq->transfer_dma = wacom->data_dma;
  510. wacom->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  511. error = input_register_device(wacom->dev);
  512. if (error)
  513. goto fail3;
  514. /* Note that if query fails it is not a hard failure */
  515. wacom_query_tablet_data(intf, features);
  516. usb_set_intfdata(intf, wacom);
  517. return 0;
  518. fail3: usb_free_urb(wacom->irq);
  519. fail2: usb_buffer_free(dev, WACOM_PKGLEN_MAX, wacom_wac->data, wacom->data_dma);
  520. fail1: input_free_device(input_dev);
  521. kfree(wacom);
  522. kfree(wacom_wac);
  523. return error;
  524. }
  525. static void wacom_disconnect(struct usb_interface *intf)
  526. {
  527. struct wacom *wacom = usb_get_intfdata(intf);
  528. usb_set_intfdata(intf, NULL);
  529. usb_kill_urb(wacom->irq);
  530. input_unregister_device(wacom->dev);
  531. usb_free_urb(wacom->irq);
  532. usb_buffer_free(interface_to_usbdev(intf), WACOM_PKGLEN_MAX,
  533. wacom->wacom_wac->data, wacom->data_dma);
  534. kfree(wacom->wacom_wac);
  535. kfree(wacom);
  536. }
  537. static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
  538. {
  539. struct wacom *wacom = usb_get_intfdata(intf);
  540. mutex_lock(&wacom->lock);
  541. usb_kill_urb(wacom->irq);
  542. mutex_unlock(&wacom->lock);
  543. return 0;
  544. }
  545. static int wacom_resume(struct usb_interface *intf)
  546. {
  547. struct wacom *wacom = usb_get_intfdata(intf);
  548. struct wacom_features *features = wacom->wacom_wac->features;
  549. int rv;
  550. mutex_lock(&wacom->lock);
  551. if (wacom->open) {
  552. rv = usb_submit_urb(wacom->irq, GFP_NOIO);
  553. /* switch to wacom mode if needed */
  554. if (!wacom_retrieve_hid_descriptor(intf, features))
  555. wacom_query_tablet_data(intf, features);
  556. } else
  557. rv = 0;
  558. mutex_unlock(&wacom->lock);
  559. return rv;
  560. }
  561. static int wacom_reset_resume(struct usb_interface *intf)
  562. {
  563. return wacom_resume(intf);
  564. }
  565. static struct usb_driver wacom_driver = {
  566. .name = "wacom",
  567. .probe = wacom_probe,
  568. .disconnect = wacom_disconnect,
  569. .suspend = wacom_suspend,
  570. .resume = wacom_resume,
  571. .reset_resume = wacom_reset_resume,
  572. .supports_autosuspend = 1,
  573. };
  574. static int __init wacom_init(void)
  575. {
  576. int result;
  577. wacom_driver.id_table = get_device_table();
  578. result = usb_register(&wacom_driver);
  579. if (result == 0)
  580. printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
  581. DRIVER_DESC "\n");
  582. return result;
  583. }
  584. static void __exit wacom_exit(void)
  585. {
  586. usb_deregister(&wacom_driver);
  587. }
  588. module_init(wacom_init);
  589. module_exit(wacom_exit);