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