hid-wacom.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. * Bluetooth Wacom Tablet support
  3. *
  4. * Copyright (c) 1999 Andreas Gal
  5. * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
  6. * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
  7. * Copyright (c) 2006-2007 Jiri Kosina
  8. * Copyright (c) 2007 Paul Walmsley
  9. * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
  10. * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
  11. * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
  12. * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
  13. */
  14. /*
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the Free
  17. * Software Foundation; either version 2 of the License, or (at your option)
  18. * any later version.
  19. */
  20. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  21. #include <linux/device.h>
  22. #include <linux/hid.h>
  23. #include <linux/module.h>
  24. #include <linux/slab.h>
  25. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  26. #include <linux/power_supply.h>
  27. #endif
  28. #include "hid-ids.h"
  29. #define PAD_DEVICE_ID 0x0F
  30. struct wacom_data {
  31. __u16 tool;
  32. __u16 butstate;
  33. __u8 whlstate;
  34. __u8 features;
  35. __u32 id;
  36. __u32 serial;
  37. unsigned char high_speed;
  38. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  39. int battery_capacity;
  40. struct power_supply battery;
  41. struct power_supply ac;
  42. #endif
  43. };
  44. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  45. /*percent of battery capacity, 0 means AC online*/
  46. static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
  47. static enum power_supply_property wacom_battery_props[] = {
  48. POWER_SUPPLY_PROP_PRESENT,
  49. POWER_SUPPLY_PROP_CAPACITY,
  50. POWER_SUPPLY_PROP_SCOPE,
  51. };
  52. static enum power_supply_property wacom_ac_props[] = {
  53. POWER_SUPPLY_PROP_PRESENT,
  54. POWER_SUPPLY_PROP_ONLINE,
  55. POWER_SUPPLY_PROP_SCOPE,
  56. };
  57. static int wacom_battery_get_property(struct power_supply *psy,
  58. enum power_supply_property psp,
  59. union power_supply_propval *val)
  60. {
  61. struct wacom_data *wdata = container_of(psy,
  62. struct wacom_data, battery);
  63. int power_state = batcap[wdata->battery_capacity];
  64. int ret = 0;
  65. switch (psp) {
  66. case POWER_SUPPLY_PROP_PRESENT:
  67. val->intval = 1;
  68. break;
  69. case POWER_SUPPLY_PROP_SCOPE:
  70. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  71. break;
  72. case POWER_SUPPLY_PROP_CAPACITY:
  73. /* show 100% battery capacity when charging */
  74. if (power_state == 0)
  75. val->intval = 100;
  76. else
  77. val->intval = power_state;
  78. break;
  79. default:
  80. ret = -EINVAL;
  81. break;
  82. }
  83. return ret;
  84. }
  85. static int wacom_ac_get_property(struct power_supply *psy,
  86. enum power_supply_property psp,
  87. union power_supply_propval *val)
  88. {
  89. struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
  90. int power_state = batcap[wdata->battery_capacity];
  91. int ret = 0;
  92. switch (psp) {
  93. case POWER_SUPPLY_PROP_PRESENT:
  94. /* fall through */
  95. case POWER_SUPPLY_PROP_ONLINE:
  96. if (power_state == 0)
  97. val->intval = 1;
  98. else
  99. val->intval = 0;
  100. break;
  101. case POWER_SUPPLY_PROP_SCOPE:
  102. val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  103. break;
  104. default:
  105. ret = -EINVAL;
  106. break;
  107. }
  108. return ret;
  109. }
  110. #endif
  111. static void wacom_set_features(struct hid_device *hdev)
  112. {
  113. int ret;
  114. __u8 rep_data[2];
  115. /*set high speed, tablet mode*/
  116. rep_data[0] = 0x03;
  117. rep_data[1] = 0x20;
  118. ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  119. HID_FEATURE_REPORT);
  120. return;
  121. }
  122. static void wacom_poke(struct hid_device *hdev, u8 speed)
  123. {
  124. struct wacom_data *wdata = hid_get_drvdata(hdev);
  125. int limit, ret;
  126. char rep_data[2];
  127. rep_data[0] = 0x03 ; rep_data[1] = 0x00;
  128. limit = 3;
  129. do {
  130. ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  131. HID_FEATURE_REPORT);
  132. } while (ret < 0 && limit-- > 0);
  133. if (ret >= 0) {
  134. if (speed == 0)
  135. rep_data[0] = 0x05;
  136. else
  137. rep_data[0] = 0x06;
  138. rep_data[1] = 0x00;
  139. limit = 3;
  140. do {
  141. ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  142. HID_FEATURE_REPORT);
  143. } while (ret < 0 && limit-- > 0);
  144. if (ret >= 0) {
  145. wdata->high_speed = speed;
  146. return;
  147. }
  148. }
  149. /*
  150. * Note that if the raw queries fail, it's not a hard failure and it
  151. * is safe to continue
  152. */
  153. hid_warn(hdev, "failed to poke device, command %d, err %d\n",
  154. rep_data[0], ret);
  155. return;
  156. }
  157. static ssize_t wacom_show_speed(struct device *dev,
  158. struct device_attribute
  159. *attr, char *buf)
  160. {
  161. struct wacom_data *wdata = dev_get_drvdata(dev);
  162. return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
  163. }
  164. static ssize_t wacom_store_speed(struct device *dev,
  165. struct device_attribute *attr,
  166. const char *buf, size_t count)
  167. {
  168. struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  169. int new_speed;
  170. if (sscanf(buf, "%1d", &new_speed ) != 1)
  171. return -EINVAL;
  172. if (new_speed == 0 || new_speed == 1) {
  173. wacom_poke(hdev, new_speed);
  174. return strnlen(buf, PAGE_SIZE);
  175. } else
  176. return -EINVAL;
  177. }
  178. static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
  179. wacom_show_speed, wacom_store_speed);
  180. static int wacom_gr_parse_report(struct hid_device *hdev,
  181. struct wacom_data *wdata,
  182. struct input_dev *input, unsigned char *data)
  183. {
  184. int tool, x, y, rw;
  185. tool = 0;
  186. /* Get X & Y positions */
  187. x = le16_to_cpu(*(__le16 *) &data[2]);
  188. y = le16_to_cpu(*(__le16 *) &data[4]);
  189. /* Get current tool identifier */
  190. if (data[1] & 0x90) { /* If pen is in the in/active area */
  191. switch ((data[1] >> 5) & 3) {
  192. case 0: /* Pen */
  193. tool = BTN_TOOL_PEN;
  194. break;
  195. case 1: /* Rubber */
  196. tool = BTN_TOOL_RUBBER;
  197. break;
  198. case 2: /* Mouse with wheel */
  199. case 3: /* Mouse without wheel */
  200. tool = BTN_TOOL_MOUSE;
  201. break;
  202. }
  203. /* Reset tool if out of active tablet area */
  204. if (!(data[1] & 0x10))
  205. tool = 0;
  206. }
  207. /* If tool changed, notify input subsystem */
  208. if (wdata->tool != tool) {
  209. if (wdata->tool) {
  210. /* Completely reset old tool state */
  211. if (wdata->tool == BTN_TOOL_MOUSE) {
  212. input_report_key(input, BTN_LEFT, 0);
  213. input_report_key(input, BTN_RIGHT, 0);
  214. input_report_key(input, BTN_MIDDLE, 0);
  215. input_report_abs(input, ABS_DISTANCE,
  216. input_abs_get_max(input, ABS_DISTANCE));
  217. } else {
  218. input_report_key(input, BTN_TOUCH, 0);
  219. input_report_key(input, BTN_STYLUS, 0);
  220. input_report_key(input, BTN_STYLUS2, 0);
  221. input_report_abs(input, ABS_PRESSURE, 0);
  222. }
  223. input_report_key(input, wdata->tool, 0);
  224. input_sync(input);
  225. }
  226. wdata->tool = tool;
  227. if (tool)
  228. input_report_key(input, tool, 1);
  229. }
  230. if (tool) {
  231. input_report_abs(input, ABS_X, x);
  232. input_report_abs(input, ABS_Y, y);
  233. switch ((data[1] >> 5) & 3) {
  234. case 2: /* Mouse with wheel */
  235. input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
  236. rw = (data[6] & 0x01) ? -1 :
  237. (data[6] & 0x02) ? 1 : 0;
  238. input_report_rel(input, REL_WHEEL, rw);
  239. /* fall through */
  240. case 3: /* Mouse without wheel */
  241. input_report_key(input, BTN_LEFT, data[1] & 0x01);
  242. input_report_key(input, BTN_RIGHT, data[1] & 0x02);
  243. /* Compute distance between mouse and tablet */
  244. rw = 44 - (data[6] >> 2);
  245. if (rw < 0)
  246. rw = 0;
  247. else if (rw > 31)
  248. rw = 31;
  249. input_report_abs(input, ABS_DISTANCE, rw);
  250. break;
  251. default:
  252. input_report_abs(input, ABS_PRESSURE,
  253. data[6] | (((__u16) (data[1] & 0x08)) << 5));
  254. input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  255. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  256. input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
  257. break;
  258. }
  259. input_sync(input);
  260. }
  261. /* Report the state of the two buttons at the top of the tablet
  262. * as two extra fingerpad keys (buttons 4 & 5). */
  263. rw = data[7] & 0x03;
  264. if (rw != wdata->butstate) {
  265. wdata->butstate = rw;
  266. input_report_key(input, BTN_0, rw & 0x02);
  267. input_report_key(input, BTN_1, rw & 0x01);
  268. input_report_key(input, BTN_TOOL_FINGER, 0xf0);
  269. input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
  270. input_sync(input);
  271. }
  272. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  273. /* Store current battery capacity */
  274. rw = (data[7] >> 2 & 0x07);
  275. if (rw != wdata->battery_capacity)
  276. wdata->battery_capacity = rw;
  277. #endif
  278. return 1;
  279. }
  280. static void wacom_i4_parse_button_report(struct wacom_data *wdata,
  281. struct input_dev *input, unsigned char *data)
  282. {
  283. __u16 new_butstate;
  284. __u8 new_whlstate;
  285. __u8 sync = 0;
  286. new_whlstate = data[1];
  287. if (new_whlstate != wdata->whlstate) {
  288. wdata->whlstate = new_whlstate;
  289. if (new_whlstate & 0x80) {
  290. input_report_key(input, BTN_TOUCH, 1);
  291. input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
  292. input_report_key(input, BTN_TOOL_FINGER, 1);
  293. } else {
  294. input_report_key(input, BTN_TOUCH, 0);
  295. input_report_abs(input, ABS_WHEEL, 0);
  296. input_report_key(input, BTN_TOOL_FINGER, 0);
  297. }
  298. sync = 1;
  299. }
  300. new_butstate = (data[3] << 1) | (data[2] & 0x01);
  301. if (new_butstate != wdata->butstate) {
  302. wdata->butstate = new_butstate;
  303. input_report_key(input, BTN_0, new_butstate & 0x001);
  304. input_report_key(input, BTN_1, new_butstate & 0x002);
  305. input_report_key(input, BTN_2, new_butstate & 0x004);
  306. input_report_key(input, BTN_3, new_butstate & 0x008);
  307. input_report_key(input, BTN_4, new_butstate & 0x010);
  308. input_report_key(input, BTN_5, new_butstate & 0x020);
  309. input_report_key(input, BTN_6, new_butstate & 0x040);
  310. input_report_key(input, BTN_7, new_butstate & 0x080);
  311. input_report_key(input, BTN_8, new_butstate & 0x100);
  312. input_report_key(input, BTN_TOOL_FINGER, 1);
  313. sync = 1;
  314. }
  315. if (sync) {
  316. input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
  317. input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
  318. input_sync(input);
  319. }
  320. }
  321. static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
  322. struct input_dev *input, unsigned char *data)
  323. {
  324. __u16 x, y, pressure;
  325. __u8 distance;
  326. switch (data[1]) {
  327. case 0x80: /* Out of proximity report */
  328. input_report_key(input, BTN_TOUCH, 0);
  329. input_report_abs(input, ABS_PRESSURE, 0);
  330. input_report_key(input, BTN_STYLUS, 0);
  331. input_report_key(input, BTN_STYLUS2, 0);
  332. input_report_key(input, wdata->tool, 0);
  333. input_report_abs(input, ABS_MISC, 0);
  334. input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
  335. wdata->tool = 0;
  336. input_sync(input);
  337. break;
  338. case 0xC2: /* Tool report */
  339. wdata->id = ((data[2] << 4) | (data[3] >> 4) |
  340. ((data[7] & 0x0f) << 20) |
  341. ((data[8] & 0xf0) << 12));
  342. wdata->serial = ((data[3] & 0x0f) << 28) +
  343. (data[4] << 20) + (data[5] << 12) +
  344. (data[6] << 4) + (data[7] >> 4);
  345. switch (wdata->id) {
  346. case 0x100802:
  347. wdata->tool = BTN_TOOL_PEN;
  348. break;
  349. case 0x10080A:
  350. wdata->tool = BTN_TOOL_RUBBER;
  351. break;
  352. }
  353. break;
  354. default: /* Position/pressure report */
  355. x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
  356. y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
  357. pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
  358. | (data[1] & 0x01);
  359. distance = (data[9] >> 2) & 0x3f;
  360. input_report_key(input, BTN_TOUCH, pressure > 1);
  361. input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  362. input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
  363. input_report_key(input, wdata->tool, 1);
  364. input_report_abs(input, ABS_X, x);
  365. input_report_abs(input, ABS_Y, y);
  366. input_report_abs(input, ABS_PRESSURE, pressure);
  367. input_report_abs(input, ABS_DISTANCE, distance);
  368. input_report_abs(input, ABS_MISC, wdata->id);
  369. input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
  370. input_report_key(input, wdata->tool, 1);
  371. input_sync(input);
  372. break;
  373. }
  374. return;
  375. }
  376. static void wacom_i4_parse_report(struct hid_device *hdev,
  377. struct wacom_data *wdata,
  378. struct input_dev *input, unsigned char *data)
  379. {
  380. switch (data[0]) {
  381. case 0x00: /* Empty report */
  382. break;
  383. case 0x02: /* Pen report */
  384. wacom_i4_parse_pen_report(wdata, input, data);
  385. break;
  386. case 0x03: /* Features Report */
  387. wdata->features = data[2];
  388. break;
  389. case 0x0C: /* Button report */
  390. wacom_i4_parse_button_report(wdata, input, data);
  391. break;
  392. default:
  393. hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
  394. break;
  395. }
  396. }
  397. static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
  398. u8 *raw_data, int size)
  399. {
  400. struct wacom_data *wdata = hid_get_drvdata(hdev);
  401. struct hid_input *hidinput;
  402. struct input_dev *input;
  403. unsigned char *data = (unsigned char *) raw_data;
  404. int i;
  405. if (!(hdev->claimed & HID_CLAIMED_INPUT))
  406. return 0;
  407. hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
  408. input = hidinput->input;
  409. /* Check if this is a tablet report */
  410. if (data[0] != 0x03)
  411. return 0;
  412. switch (hdev->product) {
  413. case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  414. return wacom_gr_parse_report(hdev, wdata, input, data);
  415. break;
  416. case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  417. i = 1;
  418. switch (data[0]) {
  419. case 0x04:
  420. wacom_i4_parse_report(hdev, wdata, input, data + i);
  421. i += 10;
  422. /* fall through */
  423. case 0x03:
  424. wacom_i4_parse_report(hdev, wdata, input, data + i);
  425. i += 10;
  426. wacom_i4_parse_report(hdev, wdata, input, data + i);
  427. break;
  428. default:
  429. hid_err(hdev, "Unknown report: %d,%d size:%d\n",
  430. data[0], data[1], size);
  431. return 0;
  432. }
  433. }
  434. return 1;
  435. }
  436. static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  437. struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
  438. int *max)
  439. {
  440. struct input_dev *input = hi->input;
  441. __set_bit(INPUT_PROP_POINTER, input->propbit);
  442. /* Basics */
  443. input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
  444. __set_bit(REL_WHEEL, input->relbit);
  445. __set_bit(BTN_TOOL_PEN, input->keybit);
  446. __set_bit(BTN_TOUCH, input->keybit);
  447. __set_bit(BTN_STYLUS, input->keybit);
  448. __set_bit(BTN_STYLUS2, input->keybit);
  449. __set_bit(BTN_LEFT, input->keybit);
  450. __set_bit(BTN_RIGHT, input->keybit);
  451. __set_bit(BTN_MIDDLE, input->keybit);
  452. /* Pad */
  453. input_set_capability(input, EV_MSC, MSC_SERIAL);
  454. __set_bit(BTN_0, input->keybit);
  455. __set_bit(BTN_1, input->keybit);
  456. __set_bit(BTN_TOOL_FINGER, input->keybit);
  457. /* Distance, rubber and mouse */
  458. __set_bit(BTN_TOOL_RUBBER, input->keybit);
  459. __set_bit(BTN_TOOL_MOUSE, input->keybit);
  460. switch (hdev->product) {
  461. case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  462. input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
  463. input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
  464. input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
  465. input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
  466. break;
  467. case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  468. __set_bit(ABS_WHEEL, input->absbit);
  469. __set_bit(ABS_MISC, input->absbit);
  470. __set_bit(BTN_2, input->keybit);
  471. __set_bit(BTN_3, input->keybit);
  472. __set_bit(BTN_4, input->keybit);
  473. __set_bit(BTN_5, input->keybit);
  474. __set_bit(BTN_6, input->keybit);
  475. __set_bit(BTN_7, input->keybit);
  476. __set_bit(BTN_8, input->keybit);
  477. input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
  478. input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
  479. input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
  480. input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
  481. input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
  482. break;
  483. }
  484. return 0;
  485. }
  486. static int wacom_probe(struct hid_device *hdev,
  487. const struct hid_device_id *id)
  488. {
  489. struct wacom_data *wdata;
  490. int ret;
  491. wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
  492. if (wdata == NULL) {
  493. hid_err(hdev, "can't alloc wacom descriptor\n");
  494. return -ENOMEM;
  495. }
  496. hid_set_drvdata(hdev, wdata);
  497. /* Parse the HID report now */
  498. ret = hid_parse(hdev);
  499. if (ret) {
  500. hid_err(hdev, "parse failed\n");
  501. goto err_free;
  502. }
  503. ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  504. if (ret) {
  505. hid_err(hdev, "hw start failed\n");
  506. goto err_free;
  507. }
  508. ret = device_create_file(&hdev->dev, &dev_attr_speed);
  509. if (ret)
  510. hid_warn(hdev,
  511. "can't create sysfs speed attribute err: %d\n", ret);
  512. switch (hdev->product) {
  513. case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  514. /* Set Wacom mode 2 with high reporting speed */
  515. wacom_poke(hdev, 1);
  516. break;
  517. case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  518. sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
  519. wdata->features = 0;
  520. wacom_set_features(hdev);
  521. break;
  522. }
  523. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  524. wdata->battery.properties = wacom_battery_props;
  525. wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
  526. wdata->battery.get_property = wacom_battery_get_property;
  527. wdata->battery.name = "wacom_battery";
  528. wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
  529. wdata->battery.use_for_apm = 0;
  530. ret = power_supply_register(&hdev->dev, &wdata->battery);
  531. if (ret) {
  532. hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
  533. ret);
  534. goto err_battery;
  535. }
  536. power_supply_powers(&wdata->battery, &hdev->dev);
  537. wdata->ac.properties = wacom_ac_props;
  538. wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
  539. wdata->ac.get_property = wacom_ac_get_property;
  540. wdata->ac.name = "wacom_ac";
  541. wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
  542. wdata->ac.use_for_apm = 0;
  543. ret = power_supply_register(&hdev->dev, &wdata->ac);
  544. if (ret) {
  545. hid_warn(hdev,
  546. "can't create ac battery attribute, err: %d\n", ret);
  547. goto err_ac;
  548. }
  549. power_supply_powers(&wdata->ac, &hdev->dev);
  550. #endif
  551. return 0;
  552. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  553. err_ac:
  554. power_supply_unregister(&wdata->battery);
  555. err_battery:
  556. device_remove_file(&hdev->dev, &dev_attr_speed);
  557. hid_hw_stop(hdev);
  558. #endif
  559. err_free:
  560. kfree(wdata);
  561. return ret;
  562. }
  563. static void wacom_remove(struct hid_device *hdev)
  564. {
  565. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  566. struct wacom_data *wdata = hid_get_drvdata(hdev);
  567. #endif
  568. device_remove_file(&hdev->dev, &dev_attr_speed);
  569. hid_hw_stop(hdev);
  570. #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  571. power_supply_unregister(&wdata->battery);
  572. power_supply_unregister(&wdata->ac);
  573. #endif
  574. kfree(hid_get_drvdata(hdev));
  575. }
  576. static const struct hid_device_id wacom_devices[] = {
  577. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
  578. { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
  579. { }
  580. };
  581. MODULE_DEVICE_TABLE(hid, wacom_devices);
  582. static struct hid_driver wacom_driver = {
  583. .name = "wacom",
  584. .id_table = wacom_devices,
  585. .probe = wacom_probe,
  586. .remove = wacom_remove,
  587. .raw_event = wacom_raw_event,
  588. .input_mapped = wacom_input_mapped,
  589. };
  590. static int __init wacom_init(void)
  591. {
  592. int ret;
  593. ret = hid_register_driver(&wacom_driver);
  594. if (ret)
  595. pr_err("can't register wacom driver\n");
  596. return ret;
  597. }
  598. static void __exit wacom_exit(void)
  599. {
  600. hid_unregister_driver(&wacom_driver);
  601. }
  602. module_init(wacom_init);
  603. module_exit(wacom_exit);
  604. MODULE_LICENSE("GPL");