HID: wacom: Refactor battery/ac reporting for Graphire
[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;
e31e3832
PF
42 __u8 battery_capacity;
43 __u8 power_raw;
44 __u8 ps_connected;
59d2334a
PF
45 struct power_supply battery;
46 struct power_supply ac;
ca2dcd40
BN
47};
48
e31e3832
PF
49/*percent of battery capacity for Graphire
50 8th value means AC online and show 100% capacity */
51static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
59d2334a
PF
52
53static enum power_supply_property wacom_battery_props[] = {
54 POWER_SUPPLY_PROP_PRESENT,
73db8813
JF
55 POWER_SUPPLY_PROP_CAPACITY,
56 POWER_SUPPLY_PROP_SCOPE,
59d2334a
PF
57};
58
59static enum power_supply_property wacom_ac_props[] = {
60 POWER_SUPPLY_PROP_PRESENT,
73db8813
JF
61 POWER_SUPPLY_PROP_ONLINE,
62 POWER_SUPPLY_PROP_SCOPE,
59d2334a
PF
63};
64
65static int wacom_battery_get_property(struct power_supply *psy,
66 enum power_supply_property psp,
67 union power_supply_propval *val)
68{
69 struct wacom_data *wdata = container_of(psy,
70 struct wacom_data, battery);
59d2334a
PF
71 int ret = 0;
72
73 switch (psp) {
74 case POWER_SUPPLY_PROP_PRESENT:
75 val->intval = 1;
76 break;
73db8813
JF
77 case POWER_SUPPLY_PROP_SCOPE:
78 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
79 break;
59d2334a 80 case POWER_SUPPLY_PROP_CAPACITY:
e31e3832 81 val->intval = wdata->battery_capacity;
59d2334a
PF
82 break;
83 default:
84 ret = -EINVAL;
85 break;
86 }
87 return ret;
88}
89
90static int wacom_ac_get_property(struct power_supply *psy,
91 enum power_supply_property psp,
92 union power_supply_propval *val)
93{
94 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
59d2334a
PF
95 int ret = 0;
96
97 switch (psp) {
98 case POWER_SUPPLY_PROP_PRESENT:
99 /* fall through */
100 case POWER_SUPPLY_PROP_ONLINE:
e31e3832 101 val->intval = wdata->ps_connected;
59d2334a 102 break;
73db8813
JF
103 case POWER_SUPPLY_PROP_SCOPE:
104 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
105 break;
59d2334a
PF
106 default:
107 ret = -EINVAL;
108 break;
109 }
110 return ret;
111}
59d2334a 112
78761ff9
PF
113static void wacom_set_features(struct hid_device *hdev)
114{
115 int ret;
116 __u8 rep_data[2];
117
118 /*set high speed, tablet mode*/
119 rep_data[0] = 0x03;
120 rep_data[1] = 0x20;
121 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
122 HID_FEATURE_REPORT);
123 return;
124}
125
06c7c313
PF
126static void wacom_poke(struct hid_device *hdev, u8 speed)
127{
20a3ce7e 128 struct wacom_data *wdata = hid_get_drvdata(hdev);
06c7c313
PF
129 int limit, ret;
130 char rep_data[2];
131
132 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
133 limit = 3;
134 do {
135 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
136 HID_FEATURE_REPORT);
137 } while (ret < 0 && limit-- > 0);
138
139 if (ret >= 0) {
140 if (speed == 0)
141 rep_data[0] = 0x05;
142 else
143 rep_data[0] = 0x06;
144
145 rep_data[1] = 0x00;
146 limit = 3;
147 do {
148 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
149 HID_FEATURE_REPORT);
150 } while (ret < 0 && limit-- > 0);
151
20a3ce7e
PF
152 if (ret >= 0) {
153 wdata->high_speed = speed;
06c7c313 154 return;
20a3ce7e 155 }
06c7c313
PF
156 }
157
158 /*
159 * Note that if the raw queries fail, it's not a hard failure and it
160 * is safe to continue
161 */
4291ee30
JP
162 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
163 rep_data[0], ret);
06c7c313
PF
164 return;
165}
166
20a3ce7e
PF
167static ssize_t wacom_show_speed(struct device *dev,
168 struct device_attribute
169 *attr, char *buf)
170{
171 struct wacom_data *wdata = dev_get_drvdata(dev);
172
173 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
174}
175
176static ssize_t wacom_store_speed(struct device *dev,
177 struct device_attribute *attr,
178 const char *buf, size_t count)
179{
180 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
181 int new_speed;
182
183 if (sscanf(buf, "%1d", &new_speed ) != 1)
184 return -EINVAL;
185
186 if (new_speed == 0 || new_speed == 1) {
187 wacom_poke(hdev, new_speed);
188 return strnlen(buf, PAGE_SIZE);
189 } else
190 return -EINVAL;
191}
192
edd2126a 193static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
20a3ce7e
PF
194 wacom_show_speed, wacom_store_speed);
195
f6b7efc1
PF
196static int wacom_gr_parse_report(struct hid_device *hdev,
197 struct wacom_data *wdata,
198 struct input_dev *input, unsigned char *data)
ca2dcd40 199{
ca2dcd40
BN
200 int tool, x, y, rw;
201
ca2dcd40 202 tool = 0;
ca2dcd40
BN
203 /* Get X & Y positions */
204 x = le16_to_cpu(*(__le16 *) &data[2]);
205 y = le16_to_cpu(*(__le16 *) &data[4]);
206
207 /* Get current tool identifier */
208 if (data[1] & 0x90) { /* If pen is in the in/active area */
209 switch ((data[1] >> 5) & 3) {
210 case 0: /* Pen */
211 tool = BTN_TOOL_PEN;
212 break;
213
214 case 1: /* Rubber */
215 tool = BTN_TOOL_RUBBER;
216 break;
217
218 case 2: /* Mouse with wheel */
219 case 3: /* Mouse without wheel */
220 tool = BTN_TOOL_MOUSE;
221 break;
222 }
223
224 /* Reset tool if out of active tablet area */
225 if (!(data[1] & 0x10))
226 tool = 0;
227 }
228
229 /* If tool changed, notify input subsystem */
230 if (wdata->tool != tool) {
231 if (wdata->tool) {
232 /* Completely reset old tool state */
233 if (wdata->tool == BTN_TOOL_MOUSE) {
234 input_report_key(input, BTN_LEFT, 0);
235 input_report_key(input, BTN_RIGHT, 0);
236 input_report_key(input, BTN_MIDDLE, 0);
237 input_report_abs(input, ABS_DISTANCE,
987a6c02 238 input_abs_get_max(input, ABS_DISTANCE));
ca2dcd40
BN
239 } else {
240 input_report_key(input, BTN_TOUCH, 0);
241 input_report_key(input, BTN_STYLUS, 0);
242 input_report_key(input, BTN_STYLUS2, 0);
243 input_report_abs(input, ABS_PRESSURE, 0);
244 }
245 input_report_key(input, wdata->tool, 0);
246 input_sync(input);
247 }
248 wdata->tool = tool;
249 if (tool)
250 input_report_key(input, tool, 1);
251 }
252
253 if (tool) {
254 input_report_abs(input, ABS_X, x);
255 input_report_abs(input, ABS_Y, y);
256
257 switch ((data[1] >> 5) & 3) {
258 case 2: /* Mouse with wheel */
259 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
260 rw = (data[6] & 0x01) ? -1 :
261 (data[6] & 0x02) ? 1 : 0;
262 input_report_rel(input, REL_WHEEL, rw);
263 /* fall through */
264
265 case 3: /* Mouse without wheel */
266 input_report_key(input, BTN_LEFT, data[1] & 0x01);
267 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
268 /* Compute distance between mouse and tablet */
269 rw = 44 - (data[6] >> 2);
270 if (rw < 0)
271 rw = 0;
272 else if (rw > 31)
273 rw = 31;
274 input_report_abs(input, ABS_DISTANCE, rw);
275 break;
276
277 default:
278 input_report_abs(input, ABS_PRESSURE,
279 data[6] | (((__u16) (data[1] & 0x08)) << 5));
280 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
281 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
282 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
283 break;
284 }
285
286 input_sync(input);
287 }
288
289 /* Report the state of the two buttons at the top of the tablet
290 * as two extra fingerpad keys (buttons 4 & 5). */
291 rw = data[7] & 0x03;
292 if (rw != wdata->butstate) {
293 wdata->butstate = rw;
294 input_report_key(input, BTN_0, rw & 0x02);
295 input_report_key(input, BTN_1, rw & 0x01);
0e253fdb 296 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
ca2dcd40
BN
297 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
298 input_sync(input);
299 }
300
e31e3832 301 /* Store current battery capacity and power supply state*/
59d2334a 302 rw = (data[7] >> 2 & 0x07);
e31e3832
PF
303 if (rw != wdata->power_raw) {
304 wdata->power_raw = rw;
305 wdata->battery_capacity = batcap_gr[rw];
306 if (rw == 7)
307 wdata->ps_connected = 1;
308 else
309 wdata->ps_connected = 0;
310 }
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.529014 seconds and 5 git commands to generate.