hid-wacom.c 17 KB

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