hid-wacom.c 17 KB

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