blob: a3476f9a5103614ea02f5813731e4fd0108b549a [file] [log] [blame]
Bastien Noceraca2dcd42009-05-11 17:18:12 +02001/*
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>
Przemo Firszt78761ff2011-11-05 11:28:22 +000012 * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
Bastien Noceraca2dcd42009-05-11 17:18:12 +020013 */
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
Joe Perches4291ee32010-12-09 19:29:03 -080022#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23
Bastien Noceraca2dcd42009-05-11 17:18:12 +020024#include <linux/device.h>
25#include <linux/hid.h>
26#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Przemo Firszt59d23342010-03-15 19:16:23 +000028#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
29#include <linux/power_supply.h>
30#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +020031
32#include "hid-ids.h"
33
34struct wacom_data {
35 __u16 tool;
36 unsigned char butstate;
Przemo Firszt78761ff2011-11-05 11:28:22 +000037 __u8 features;
Przemo Firszt24709002012-02-24 13:52:32 +000038 __u32 id;
39 __u32 serial;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +000040 unsigned char high_speed;
Przemo Firszt59d23342010-03-15 19:16:23 +000041#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
42 int battery_capacity;
43 struct power_supply battery;
44 struct power_supply ac;
45#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +020046};
47
Przemo Firszt59d23342010-03-15 19:16:23 +000048#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
49/*percent of battery capacity, 0 means AC online*/
50static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
51
52static enum power_supply_property wacom_battery_props[] = {
53 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080054 POWER_SUPPLY_PROP_CAPACITY,
55 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000056};
57
58static enum power_supply_property wacom_ac_props[] = {
59 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080060 POWER_SUPPLY_PROP_ONLINE,
61 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000062};
63
64static int wacom_battery_get_property(struct power_supply *psy,
65 enum power_supply_property psp,
66 union power_supply_propval *val)
67{
68 struct wacom_data *wdata = container_of(psy,
69 struct wacom_data, battery);
70 int power_state = batcap[wdata->battery_capacity];
71 int ret = 0;
72
73 switch (psp) {
74 case POWER_SUPPLY_PROP_PRESENT:
75 val->intval = 1;
76 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080077 case POWER_SUPPLY_PROP_SCOPE:
78 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
79 break;
Przemo Firszt59d23342010-03-15 19:16:23 +000080 case POWER_SUPPLY_PROP_CAPACITY:
81 /* show 100% battery capacity when charging */
82 if (power_state == 0)
83 val->intval = 100;
84 else
85 val->intval = power_state;
86 break;
87 default:
88 ret = -EINVAL;
89 break;
90 }
91 return ret;
92}
93
94static int wacom_ac_get_property(struct power_supply *psy,
95 enum power_supply_property psp,
96 union power_supply_propval *val)
97{
98 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
99 int power_state = batcap[wdata->battery_capacity];
100 int ret = 0;
101
102 switch (psp) {
103 case POWER_SUPPLY_PROP_PRESENT:
104 /* fall through */
105 case POWER_SUPPLY_PROP_ONLINE:
106 if (power_state == 0)
107 val->intval = 1;
108 else
109 val->intval = 0;
110 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -0800111 case POWER_SUPPLY_PROP_SCOPE:
112 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
113 break;
Przemo Firszt59d23342010-03-15 19:16:23 +0000114 default:
115 ret = -EINVAL;
116 break;
117 }
118 return ret;
119}
120#endif
121
Przemo Firszt78761ff2011-11-05 11:28:22 +0000122static void wacom_set_features(struct hid_device *hdev)
123{
124 int ret;
125 __u8 rep_data[2];
126
127 /*set high speed, tablet mode*/
128 rep_data[0] = 0x03;
129 rep_data[1] = 0x20;
130 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
131 HID_FEATURE_REPORT);
132 return;
133}
134
Przemo Firszt06c7c312010-03-22 09:55:04 +0100135static void wacom_poke(struct hid_device *hdev, u8 speed)
136{
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000137 struct wacom_data *wdata = hid_get_drvdata(hdev);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100138 int limit, ret;
139 char rep_data[2];
140
141 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
142 limit = 3;
143 do {
144 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
145 HID_FEATURE_REPORT);
146 } while (ret < 0 && limit-- > 0);
147
148 if (ret >= 0) {
149 if (speed == 0)
150 rep_data[0] = 0x05;
151 else
152 rep_data[0] = 0x06;
153
154 rep_data[1] = 0x00;
155 limit = 3;
156 do {
157 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
158 HID_FEATURE_REPORT);
159 } while (ret < 0 && limit-- > 0);
160
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000161 if (ret >= 0) {
162 wdata->high_speed = speed;
Przemo Firszt06c7c312010-03-22 09:55:04 +0100163 return;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000164 }
Przemo Firszt06c7c312010-03-22 09:55:04 +0100165 }
166
167 /*
168 * Note that if the raw queries fail, it's not a hard failure and it
169 * is safe to continue
170 */
Joe Perches4291ee32010-12-09 19:29:03 -0800171 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
172 rep_data[0], ret);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100173 return;
174}
175
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000176static ssize_t wacom_show_speed(struct device *dev,
177 struct device_attribute
178 *attr, char *buf)
179{
180 struct wacom_data *wdata = dev_get_drvdata(dev);
181
182 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
183}
184
185static ssize_t wacom_store_speed(struct device *dev,
186 struct device_attribute *attr,
187 const char *buf, size_t count)
188{
189 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
190 int new_speed;
191
192 if (sscanf(buf, "%1d", &new_speed ) != 1)
193 return -EINVAL;
194
195 if (new_speed == 0 || new_speed == 1) {
196 wacom_poke(hdev, new_speed);
197 return strnlen(buf, PAGE_SIZE);
198 } else
199 return -EINVAL;
200}
201
Jiri Kosinaedd21262010-11-18 16:28:43 +0100202static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000203 wacom_show_speed, wacom_store_speed);
204
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000205static int wacom_gr_parse_report(struct hid_device *hdev,
206 struct wacom_data *wdata,
207 struct input_dev *input, unsigned char *data)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200208{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200209 int tool, x, y, rw;
210
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200211 tool = 0;
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200212 /* Get X & Y positions */
213 x = le16_to_cpu(*(__le16 *) &data[2]);
214 y = le16_to_cpu(*(__le16 *) &data[4]);
215
216 /* Get current tool identifier */
217 if (data[1] & 0x90) { /* If pen is in the in/active area */
218 switch ((data[1] >> 5) & 3) {
219 case 0: /* Pen */
220 tool = BTN_TOOL_PEN;
221 break;
222
223 case 1: /* Rubber */
224 tool = BTN_TOOL_RUBBER;
225 break;
226
227 case 2: /* Mouse with wheel */
228 case 3: /* Mouse without wheel */
229 tool = BTN_TOOL_MOUSE;
230 break;
231 }
232
233 /* Reset tool if out of active tablet area */
234 if (!(data[1] & 0x10))
235 tool = 0;
236 }
237
238 /* If tool changed, notify input subsystem */
239 if (wdata->tool != tool) {
240 if (wdata->tool) {
241 /* Completely reset old tool state */
242 if (wdata->tool == BTN_TOOL_MOUSE) {
243 input_report_key(input, BTN_LEFT, 0);
244 input_report_key(input, BTN_RIGHT, 0);
245 input_report_key(input, BTN_MIDDLE, 0);
246 input_report_abs(input, ABS_DISTANCE,
Daniel Mack987a6c02010-08-02 20:15:17 -0700247 input_abs_get_max(input, ABS_DISTANCE));
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200248 } else {
249 input_report_key(input, BTN_TOUCH, 0);
250 input_report_key(input, BTN_STYLUS, 0);
251 input_report_key(input, BTN_STYLUS2, 0);
252 input_report_abs(input, ABS_PRESSURE, 0);
253 }
254 input_report_key(input, wdata->tool, 0);
255 input_sync(input);
256 }
257 wdata->tool = tool;
258 if (tool)
259 input_report_key(input, tool, 1);
260 }
261
262 if (tool) {
263 input_report_abs(input, ABS_X, x);
264 input_report_abs(input, ABS_Y, y);
265
266 switch ((data[1] >> 5) & 3) {
267 case 2: /* Mouse with wheel */
268 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
269 rw = (data[6] & 0x01) ? -1 :
270 (data[6] & 0x02) ? 1 : 0;
271 input_report_rel(input, REL_WHEEL, rw);
272 /* fall through */
273
274 case 3: /* Mouse without wheel */
275 input_report_key(input, BTN_LEFT, data[1] & 0x01);
276 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
277 /* Compute distance between mouse and tablet */
278 rw = 44 - (data[6] >> 2);
279 if (rw < 0)
280 rw = 0;
281 else if (rw > 31)
282 rw = 31;
283 input_report_abs(input, ABS_DISTANCE, rw);
284 break;
285
286 default:
287 input_report_abs(input, ABS_PRESSURE,
288 data[6] | (((__u16) (data[1] & 0x08)) << 5));
289 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
290 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
291 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
292 break;
293 }
294
295 input_sync(input);
296 }
297
298 /* Report the state of the two buttons at the top of the tablet
299 * as two extra fingerpad keys (buttons 4 & 5). */
300 rw = data[7] & 0x03;
301 if (rw != wdata->butstate) {
302 wdata->butstate = rw;
303 input_report_key(input, BTN_0, rw & 0x02);
304 input_report_key(input, BTN_1, rw & 0x01);
Przemo Firszt0e253fd2010-01-09 15:20:03 +0100305 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200306 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
307 input_sync(input);
308 }
309
Przemo Firszt59d23342010-03-15 19:16:23 +0000310#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
311 /* Store current battery capacity */
312 rw = (data[7] >> 2 & 0x07);
313 if (rw != wdata->battery_capacity)
314 wdata->battery_capacity = rw;
315#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200316 return 1;
317}
Przemo Firszt78761ff2011-11-05 11:28:22 +0000318
319static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
320 struct input_dev *input, unsigned char *data)
321{
322 __u16 x, y, pressure;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000323
324 switch (data[1]) {
325 case 0x80: /* Out of proximity report */
Przemo Firszt78761ff2011-11-05 11:28:22 +0000326 input_report_key(input, BTN_TOUCH, 0);
327 input_report_abs(input, ABS_PRESSURE, 0);
328 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000329 input_report_abs(input, ABS_MISC, 0);
330 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000331 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000332 input_sync(input);
333 break;
334 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000335 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000336 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000337 ((data[8] & 0xf0) << 12));
338 wdata->serial = ((data[3] & 0x0f) << 28) +
339 (data[4] << 20) + (data[5] << 12) +
340 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000341
Przemo Firszt24709002012-02-24 13:52:32 +0000342 switch (wdata->id) {
343 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000344 wdata->tool = BTN_TOOL_PEN;
345 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000346 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000347 wdata->tool = BTN_TOOL_RUBBER;
348 break;
349 }
350 break;
351 default: /* Position/pressure report */
352 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
353 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
354 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
355 | (data[1] & 0x01);
356
357 input_report_key(input, BTN_TOUCH, pressure > 1);
358
359 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
360 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
361 input_report_key(input, wdata->tool, 1);
362 input_report_abs(input, ABS_X, x);
363 input_report_abs(input, ABS_Y, y);
364 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszt24709002012-02-24 13:52:32 +0000365 input_report_abs(input, ABS_MISC, wdata->id);
366 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
367 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000368 input_sync(input);
369 break;
370 }
371
372 return;
373}
374
375static void wacom_i4_parse_report(struct hid_device *hdev,
376 struct wacom_data *wdata,
377 struct input_dev *input, unsigned char *data)
378{
379 switch (data[0]) {
380 case 0x00: /* Empty report */
381 break;
382 case 0x02: /* Pen report */
383 wacom_i4_parse_pen_report(wdata, input, data);
384 break;
385 case 0x03: /* Features Report */
386 wdata->features = data[2];
387 break;
388 case 0x0C: /* Button report */
389 break;
390 default:
391 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
392 break;
393 }
394}
395
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000396static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
397 u8 *raw_data, int size)
398{
399 struct wacom_data *wdata = hid_get_drvdata(hdev);
400 struct hid_input *hidinput;
401 struct input_dev *input;
402 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000403 int i;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000404
405 if (!(hdev->claimed & HID_CLAIMED_INPUT))
406 return 0;
407
408 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
409 input = hidinput->input;
410
411 /* Check if this is a tablet report */
412 if (data[0] != 0x03)
413 return 0;
414
Przemo Firszt78761ff2011-11-05 11:28:22 +0000415 switch (hdev->product) {
416 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
417 return wacom_gr_parse_report(hdev, wdata, input, data);
418 break;
419 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
420 i = 1;
421
422 switch (data[0]) {
423 case 0x04:
424 wacom_i4_parse_report(hdev, wdata, input, data + i);
425 i += 10;
426 /* fall through */
427 case 0x03:
428 wacom_i4_parse_report(hdev, wdata, input, data + i);
429 i += 10;
430 wacom_i4_parse_report(hdev, wdata, input, data + i);
431 break;
432 default:
433 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
434 data[0], data[1], size);
435 return 0;
436 }
437 }
438 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000439}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200440
David Herrmann3797ef62011-10-08 23:20:17 +0200441static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
442 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
443 int *max)
444{
445 struct input_dev *input = hi->input;
446
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200447 __set_bit(INPUT_PROP_POINTER, input->propbit);
448
David Herrmann3797ef62011-10-08 23:20:17 +0200449 /* Basics */
450 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
451
452 __set_bit(REL_WHEEL, input->relbit);
453
454 __set_bit(BTN_TOOL_PEN, input->keybit);
455 __set_bit(BTN_TOUCH, input->keybit);
456 __set_bit(BTN_STYLUS, input->keybit);
457 __set_bit(BTN_STYLUS2, input->keybit);
458 __set_bit(BTN_LEFT, input->keybit);
459 __set_bit(BTN_RIGHT, input->keybit);
460 __set_bit(BTN_MIDDLE, input->keybit);
461
462 /* Pad */
463 input->evbit[0] |= BIT(EV_MSC);
464
465 __set_bit(MSC_SERIAL, input->mscbit);
466
467 __set_bit(BTN_0, input->keybit);
468 __set_bit(BTN_1, input->keybit);
469 __set_bit(BTN_TOOL_FINGER, input->keybit);
470
471 /* Distance, rubber and mouse */
472 __set_bit(BTN_TOOL_RUBBER, input->keybit);
473 __set_bit(BTN_TOOL_MOUSE, input->keybit);
474
Przemo Firszt78761ff2011-11-05 11:28:22 +0000475 switch (hdev->product) {
476 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
477 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
478 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
479 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
480 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
481 break;
482 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt2c653e62012-02-24 13:47:48 +0000483 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000484 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
485 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
486 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
487 break;
488 }
David Herrmann3797ef62011-10-08 23:20:17 +0200489
490 return 0;
491}
492
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200493static int wacom_probe(struct hid_device *hdev,
494 const struct hid_device_id *id)
495{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200496 struct wacom_data *wdata;
497 int ret;
498
499 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
500 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800501 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200502 return -ENOMEM;
503 }
504
505 hid_set_drvdata(hdev, wdata);
506
Bastien Nocera46a709b2010-01-20 12:00:53 +0000507 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200508 ret = hid_parse(hdev);
509 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800510 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200511 goto err_free;
512 }
513
514 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
515 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800516 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200517 goto err_free;
518 }
519
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000520 ret = device_create_file(&hdev->dev, &dev_attr_speed);
521 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800522 hid_warn(hdev,
523 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100524
Przemo Firszt78761ff2011-11-05 11:28:22 +0000525 switch (hdev->product) {
526 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
527 /* Set Wacom mode 2 with high reporting speed */
528 wacom_poke(hdev, 1);
529 break;
530 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
531 wdata->features = 0;
532 wacom_set_features(hdev);
533 break;
534 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000535
Przemo Firszt59d23342010-03-15 19:16:23 +0000536#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
537 wdata->battery.properties = wacom_battery_props;
538 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
539 wdata->battery.get_property = wacom_battery_get_property;
540 wdata->battery.name = "wacom_battery";
541 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
542 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000543
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800544
Przemo Firszt59d23342010-03-15 19:16:23 +0000545 ret = power_supply_register(&hdev->dev, &wdata->battery);
546 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800547 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
548 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200549 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000550 }
551
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000552 power_supply_powers(&wdata->battery, &hdev->dev);
553
Przemo Firszt59d23342010-03-15 19:16:23 +0000554 wdata->ac.properties = wacom_ac_props;
555 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
556 wdata->ac.get_property = wacom_ac_get_property;
557 wdata->ac.name = "wacom_ac";
558 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
559 wdata->ac.use_for_apm = 0;
560
561 ret = power_supply_register(&hdev->dev, &wdata->ac);
562 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800563 hid_warn(hdev,
564 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200565 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000566 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000567
568 power_supply_powers(&wdata->ac, &hdev->dev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000569#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200570 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700571
David Herrmanndde58cf2011-09-05 18:45:28 +0200572#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
573err_ac:
574 power_supply_unregister(&wdata->battery);
575err_battery:
576 device_remove_file(&hdev->dev, &dev_attr_speed);
577 hid_hw_stop(hdev);
578#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200579err_free:
580 kfree(wdata);
581 return ret;
582}
583
584static void wacom_remove(struct hid_device *hdev)
585{
Przemo Firszt59d23342010-03-15 19:16:23 +0000586#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
587 struct wacom_data *wdata = hid_get_drvdata(hdev);
588#endif
David Herrmann90866172011-09-05 18:45:29 +0200589 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200590 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000591
592#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
593 power_supply_unregister(&wdata->battery);
594 power_supply_unregister(&wdata->ac);
595#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200596 kfree(hid_get_drvdata(hdev));
597}
598
599static const struct hid_device_id wacom_devices[] = {
600 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000601 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200602
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200603 { }
604};
605MODULE_DEVICE_TABLE(hid, wacom_devices);
606
607static struct hid_driver wacom_driver = {
608 .name = "wacom",
609 .id_table = wacom_devices,
610 .probe = wacom_probe,
611 .remove = wacom_remove,
612 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200613 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200614};
615
Peter Huewea24f423b2009-07-02 19:08:38 +0200616static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200617{
618 int ret;
619
620 ret = hid_register_driver(&wacom_driver);
621 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800622 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200623 return ret;
624}
625
Peter Huewea24f423b2009-07-02 19:08:38 +0200626static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200627{
628 hid_unregister_driver(&wacom_driver);
629}
630
631module_init(wacom_init);
632module_exit(wacom_exit);
633MODULE_LICENSE("GPL");
634