blob: 694545d5bfeab0ed2ce7fd8c5c5602bfd8aa36c3 [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
Przemo Firszt6245bde2012-02-28 17:19:05 +000034#define PAD_DEVICE_ID 0x0F
35
Bastien Noceraca2dcd42009-05-11 17:18:12 +020036struct wacom_data {
37 __u16 tool;
Przemo Firszt6245bde2012-02-28 17:19:05 +000038 __u16 butstate;
Przemo Firszt7e503a32012-03-14 19:55:04 +000039 __u8 whlstate;
Przemo Firszt78761ff2011-11-05 11:28:22 +000040 __u8 features;
Przemo Firszt24709002012-02-24 13:52:32 +000041 __u32 id;
42 __u32 serial;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +000043 unsigned char high_speed;
Przemo Firszt59d23342010-03-15 19:16:23 +000044#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
45 int battery_capacity;
46 struct power_supply battery;
47 struct power_supply ac;
48#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +020049};
50
Przemo Firszt59d23342010-03-15 19:16:23 +000051#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
52/*percent of battery capacity, 0 means AC online*/
53static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
54
55static enum power_supply_property wacom_battery_props[] = {
56 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080057 POWER_SUPPLY_PROP_CAPACITY,
58 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000059};
60
61static enum power_supply_property wacom_ac_props[] = {
62 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080063 POWER_SUPPLY_PROP_ONLINE,
64 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000065};
66
67static int wacom_battery_get_property(struct power_supply *psy,
68 enum power_supply_property psp,
69 union power_supply_propval *val)
70{
71 struct wacom_data *wdata = container_of(psy,
72 struct wacom_data, battery);
73 int power_state = batcap[wdata->battery_capacity];
74 int ret = 0;
75
76 switch (psp) {
77 case POWER_SUPPLY_PROP_PRESENT:
78 val->intval = 1;
79 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080080 case POWER_SUPPLY_PROP_SCOPE:
81 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
82 break;
Przemo Firszt59d23342010-03-15 19:16:23 +000083 case POWER_SUPPLY_PROP_CAPACITY:
84 /* show 100% battery capacity when charging */
85 if (power_state == 0)
86 val->intval = 100;
87 else
88 val->intval = power_state;
89 break;
90 default:
91 ret = -EINVAL;
92 break;
93 }
94 return ret;
95}
96
97static int wacom_ac_get_property(struct power_supply *psy,
98 enum power_supply_property psp,
99 union power_supply_propval *val)
100{
101 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
102 int power_state = batcap[wdata->battery_capacity];
103 int ret = 0;
104
105 switch (psp) {
106 case POWER_SUPPLY_PROP_PRESENT:
107 /* fall through */
108 case POWER_SUPPLY_PROP_ONLINE:
109 if (power_state == 0)
110 val->intval = 1;
111 else
112 val->intval = 0;
113 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -0800114 case POWER_SUPPLY_PROP_SCOPE:
115 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
116 break;
Przemo Firszt59d23342010-03-15 19:16:23 +0000117 default:
118 ret = -EINVAL;
119 break;
120 }
121 return ret;
122}
123#endif
124
Przemo Firszt78761ff2011-11-05 11:28:22 +0000125static void wacom_set_features(struct hid_device *hdev)
126{
127 int ret;
128 __u8 rep_data[2];
129
130 /*set high speed, tablet mode*/
131 rep_data[0] = 0x03;
132 rep_data[1] = 0x20;
133 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
134 HID_FEATURE_REPORT);
135 return;
136}
137
Przemo Firszt06c7c312010-03-22 09:55:04 +0100138static void wacom_poke(struct hid_device *hdev, u8 speed)
139{
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000140 struct wacom_data *wdata = hid_get_drvdata(hdev);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100141 int limit, ret;
142 char rep_data[2];
143
144 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
145 limit = 3;
146 do {
147 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
148 HID_FEATURE_REPORT);
149 } while (ret < 0 && limit-- > 0);
150
151 if (ret >= 0) {
152 if (speed == 0)
153 rep_data[0] = 0x05;
154 else
155 rep_data[0] = 0x06;
156
157 rep_data[1] = 0x00;
158 limit = 3;
159 do {
160 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
161 HID_FEATURE_REPORT);
162 } while (ret < 0 && limit-- > 0);
163
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000164 if (ret >= 0) {
165 wdata->high_speed = speed;
Przemo Firszt06c7c312010-03-22 09:55:04 +0100166 return;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000167 }
Przemo Firszt06c7c312010-03-22 09:55:04 +0100168 }
169
170 /*
171 * Note that if the raw queries fail, it's not a hard failure and it
172 * is safe to continue
173 */
Joe Perches4291ee32010-12-09 19:29:03 -0800174 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
175 rep_data[0], ret);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100176 return;
177}
178
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000179static ssize_t wacom_show_speed(struct device *dev,
180 struct device_attribute
181 *attr, char *buf)
182{
183 struct wacom_data *wdata = dev_get_drvdata(dev);
184
185 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
186}
187
188static ssize_t wacom_store_speed(struct device *dev,
189 struct device_attribute *attr,
190 const char *buf, size_t count)
191{
192 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
193 int new_speed;
194
195 if (sscanf(buf, "%1d", &new_speed ) != 1)
196 return -EINVAL;
197
198 if (new_speed == 0 || new_speed == 1) {
199 wacom_poke(hdev, new_speed);
200 return strnlen(buf, PAGE_SIZE);
201 } else
202 return -EINVAL;
203}
204
Jiri Kosinaedd21262010-11-18 16:28:43 +0100205static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000206 wacom_show_speed, wacom_store_speed);
207
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000208static int wacom_gr_parse_report(struct hid_device *hdev,
209 struct wacom_data *wdata,
210 struct input_dev *input, unsigned char *data)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200211{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200212 int tool, x, y, rw;
213
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200214 tool = 0;
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200215 /* Get X & Y positions */
216 x = le16_to_cpu(*(__le16 *) &data[2]);
217 y = le16_to_cpu(*(__le16 *) &data[4]);
218
219 /* Get current tool identifier */
220 if (data[1] & 0x90) { /* If pen is in the in/active area */
221 switch ((data[1] >> 5) & 3) {
222 case 0: /* Pen */
223 tool = BTN_TOOL_PEN;
224 break;
225
226 case 1: /* Rubber */
227 tool = BTN_TOOL_RUBBER;
228 break;
229
230 case 2: /* Mouse with wheel */
231 case 3: /* Mouse without wheel */
232 tool = BTN_TOOL_MOUSE;
233 break;
234 }
235
236 /* Reset tool if out of active tablet area */
237 if (!(data[1] & 0x10))
238 tool = 0;
239 }
240
241 /* If tool changed, notify input subsystem */
242 if (wdata->tool != tool) {
243 if (wdata->tool) {
244 /* Completely reset old tool state */
245 if (wdata->tool == BTN_TOOL_MOUSE) {
246 input_report_key(input, BTN_LEFT, 0);
247 input_report_key(input, BTN_RIGHT, 0);
248 input_report_key(input, BTN_MIDDLE, 0);
249 input_report_abs(input, ABS_DISTANCE,
Daniel Mack987a6c02010-08-02 20:15:17 -0700250 input_abs_get_max(input, ABS_DISTANCE));
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200251 } else {
252 input_report_key(input, BTN_TOUCH, 0);
253 input_report_key(input, BTN_STYLUS, 0);
254 input_report_key(input, BTN_STYLUS2, 0);
255 input_report_abs(input, ABS_PRESSURE, 0);
256 }
257 input_report_key(input, wdata->tool, 0);
258 input_sync(input);
259 }
260 wdata->tool = tool;
261 if (tool)
262 input_report_key(input, tool, 1);
263 }
264
265 if (tool) {
266 input_report_abs(input, ABS_X, x);
267 input_report_abs(input, ABS_Y, y);
268
269 switch ((data[1] >> 5) & 3) {
270 case 2: /* Mouse with wheel */
271 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
272 rw = (data[6] & 0x01) ? -1 :
273 (data[6] & 0x02) ? 1 : 0;
274 input_report_rel(input, REL_WHEEL, rw);
275 /* fall through */
276
277 case 3: /* Mouse without wheel */
278 input_report_key(input, BTN_LEFT, data[1] & 0x01);
279 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
280 /* Compute distance between mouse and tablet */
281 rw = 44 - (data[6] >> 2);
282 if (rw < 0)
283 rw = 0;
284 else if (rw > 31)
285 rw = 31;
286 input_report_abs(input, ABS_DISTANCE, rw);
287 break;
288
289 default:
290 input_report_abs(input, ABS_PRESSURE,
291 data[6] | (((__u16) (data[1] & 0x08)) << 5));
292 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
293 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
294 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
295 break;
296 }
297
298 input_sync(input);
299 }
300
301 /* Report the state of the two buttons at the top of the tablet
302 * as two extra fingerpad keys (buttons 4 & 5). */
303 rw = data[7] & 0x03;
304 if (rw != wdata->butstate) {
305 wdata->butstate = rw;
306 input_report_key(input, BTN_0, rw & 0x02);
307 input_report_key(input, BTN_1, rw & 0x01);
Przemo Firszt0e253fd2010-01-09 15:20:03 +0100308 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200309 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
310 input_sync(input);
311 }
312
Przemo Firszt59d23342010-03-15 19:16:23 +0000313#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
314 /* Store current battery capacity */
315 rw = (data[7] >> 2 & 0x07);
316 if (rw != wdata->battery_capacity)
317 wdata->battery_capacity = rw;
318#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200319 return 1;
320}
Przemo Firszt78761ff2011-11-05 11:28:22 +0000321
Przemo Firszt6245bde2012-02-28 17:19:05 +0000322static void wacom_i4_parse_button_report(struct wacom_data *wdata,
323 struct input_dev *input, unsigned char *data)
324{
325 __u16 new_butstate;
Przemo Firszt7e503a32012-03-14 19:55:04 +0000326 __u8 new_whlstate;
327 __u8 sync = 0;
328
329 new_whlstate = data[1];
330 if (new_whlstate != wdata->whlstate) {
331 wdata->whlstate = new_whlstate;
332 if (new_whlstate & 0x80) {
333 input_report_key(input, BTN_TOUCH, 1);
334 input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
335 input_report_key(input, BTN_TOOL_FINGER, 1);
336 } else {
337 input_report_key(input, BTN_TOUCH, 0);
338 input_report_abs(input, ABS_WHEEL, 0);
339 input_report_key(input, BTN_TOOL_FINGER, 0);
340 }
341 sync = 1;
342 }
Przemo Firszt6245bde2012-02-28 17:19:05 +0000343
344 new_butstate = (data[3] << 1) | (data[2] & 0x01);
345 if (new_butstate != wdata->butstate) {
346 wdata->butstate = new_butstate;
347 input_report_key(input, BTN_0, new_butstate & 0x001);
348 input_report_key(input, BTN_1, new_butstate & 0x002);
349 input_report_key(input, BTN_2, new_butstate & 0x004);
350 input_report_key(input, BTN_3, new_butstate & 0x008);
351 input_report_key(input, BTN_4, new_butstate & 0x010);
352 input_report_key(input, BTN_5, new_butstate & 0x020);
353 input_report_key(input, BTN_6, new_butstate & 0x040);
354 input_report_key(input, BTN_7, new_butstate & 0x080);
355 input_report_key(input, BTN_8, new_butstate & 0x100);
356 input_report_key(input, BTN_TOOL_FINGER, 1);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000357 sync = 1;
358 }
359
360 if (sync) {
Przemo Firszt6245bde2012-02-28 17:19:05 +0000361 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
362 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
363 input_sync(input);
364 }
365}
366
Przemo Firszt78761ff2011-11-05 11:28:22 +0000367static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
368 struct input_dev *input, unsigned char *data)
369{
370 __u16 x, y, pressure;
Przemo Firszte0829e92012-02-28 17:19:04 +0000371 __u8 distance;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000372
373 switch (data[1]) {
374 case 0x80: /* Out of proximity report */
Przemo Firszt78761ff2011-11-05 11:28:22 +0000375 input_report_key(input, BTN_TOUCH, 0);
376 input_report_abs(input, ABS_PRESSURE, 0);
Przemo Firszt693f45b2012-03-09 13:20:51 +0000377 input_report_key(input, BTN_STYLUS, 0);
378 input_report_key(input, BTN_STYLUS2, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000379 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000380 input_report_abs(input, ABS_MISC, 0);
381 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000382 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000383 input_sync(input);
384 break;
385 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000386 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000387 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000388 ((data[8] & 0xf0) << 12));
389 wdata->serial = ((data[3] & 0x0f) << 28) +
390 (data[4] << 20) + (data[5] << 12) +
391 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000392
Przemo Firszt24709002012-02-24 13:52:32 +0000393 switch (wdata->id) {
394 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000395 wdata->tool = BTN_TOOL_PEN;
396 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000397 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000398 wdata->tool = BTN_TOOL_RUBBER;
399 break;
400 }
401 break;
402 default: /* Position/pressure report */
403 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
404 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
405 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
406 | (data[1] & 0x01);
Przemo Firszte0829e92012-02-28 17:19:04 +0000407 distance = (data[9] >> 2) & 0x3f;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000408
409 input_report_key(input, BTN_TOUCH, pressure > 1);
410
411 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
412 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
413 input_report_key(input, wdata->tool, 1);
414 input_report_abs(input, ABS_X, x);
415 input_report_abs(input, ABS_Y, y);
416 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszte0829e92012-02-28 17:19:04 +0000417 input_report_abs(input, ABS_DISTANCE, distance);
Przemo Firszt24709002012-02-24 13:52:32 +0000418 input_report_abs(input, ABS_MISC, wdata->id);
419 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
420 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000421 input_sync(input);
422 break;
423 }
424
425 return;
426}
427
428static void wacom_i4_parse_report(struct hid_device *hdev,
429 struct wacom_data *wdata,
430 struct input_dev *input, unsigned char *data)
431{
432 switch (data[0]) {
433 case 0x00: /* Empty report */
434 break;
435 case 0x02: /* Pen report */
436 wacom_i4_parse_pen_report(wdata, input, data);
437 break;
438 case 0x03: /* Features Report */
439 wdata->features = data[2];
440 break;
441 case 0x0C: /* Button report */
Przemo Firszt6245bde2012-02-28 17:19:05 +0000442 wacom_i4_parse_button_report(wdata, input, data);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000443 break;
444 default:
445 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
446 break;
447 }
448}
449
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000450static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
451 u8 *raw_data, int size)
452{
453 struct wacom_data *wdata = hid_get_drvdata(hdev);
454 struct hid_input *hidinput;
455 struct input_dev *input;
456 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000457 int i;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000458
459 if (!(hdev->claimed & HID_CLAIMED_INPUT))
460 return 0;
461
462 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
463 input = hidinput->input;
464
465 /* Check if this is a tablet report */
466 if (data[0] != 0x03)
467 return 0;
468
Przemo Firszt78761ff2011-11-05 11:28:22 +0000469 switch (hdev->product) {
470 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
471 return wacom_gr_parse_report(hdev, wdata, input, data);
472 break;
473 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
474 i = 1;
475
476 switch (data[0]) {
477 case 0x04:
478 wacom_i4_parse_report(hdev, wdata, input, data + i);
479 i += 10;
480 /* fall through */
481 case 0x03:
482 wacom_i4_parse_report(hdev, wdata, input, data + i);
483 i += 10;
484 wacom_i4_parse_report(hdev, wdata, input, data + i);
485 break;
486 default:
487 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
488 data[0], data[1], size);
489 return 0;
490 }
491 }
492 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000493}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200494
David Herrmann3797ef62011-10-08 23:20:17 +0200495static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
496 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
497 int *max)
498{
499 struct input_dev *input = hi->input;
500
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200501 __set_bit(INPUT_PROP_POINTER, input->propbit);
502
David Herrmann3797ef62011-10-08 23:20:17 +0200503 /* Basics */
504 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
505
506 __set_bit(REL_WHEEL, input->relbit);
507
508 __set_bit(BTN_TOOL_PEN, input->keybit);
509 __set_bit(BTN_TOUCH, input->keybit);
510 __set_bit(BTN_STYLUS, input->keybit);
511 __set_bit(BTN_STYLUS2, input->keybit);
512 __set_bit(BTN_LEFT, input->keybit);
513 __set_bit(BTN_RIGHT, input->keybit);
514 __set_bit(BTN_MIDDLE, input->keybit);
515
516 /* Pad */
Przemo Firszt9a911da2012-03-14 19:55:03 +0000517 input_set_capability(input, EV_MSC, MSC_SERIAL);
David Herrmann3797ef62011-10-08 23:20:17 +0200518
519 __set_bit(BTN_0, input->keybit);
520 __set_bit(BTN_1, input->keybit);
521 __set_bit(BTN_TOOL_FINGER, input->keybit);
522
523 /* Distance, rubber and mouse */
524 __set_bit(BTN_TOOL_RUBBER, input->keybit);
525 __set_bit(BTN_TOOL_MOUSE, input->keybit);
526
Przemo Firszt78761ff2011-11-05 11:28:22 +0000527 switch (hdev->product) {
528 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
529 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
530 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
531 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
532 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
533 break;
534 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt7e503a32012-03-14 19:55:04 +0000535 __set_bit(ABS_WHEEL, input->absbit);
Przemo Firszt2c653e62012-02-24 13:47:48 +0000536 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt6245bde2012-02-28 17:19:05 +0000537 __set_bit(BTN_2, input->keybit);
538 __set_bit(BTN_3, input->keybit);
539 __set_bit(BTN_4, input->keybit);
540 __set_bit(BTN_5, input->keybit);
541 __set_bit(BTN_6, input->keybit);
542 __set_bit(BTN_7, input->keybit);
543 __set_bit(BTN_8, input->keybit);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000544 input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000545 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
546 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
547 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
Przemo Firszte0829e92012-02-28 17:19:04 +0000548 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000549 break;
550 }
David Herrmann3797ef62011-10-08 23:20:17 +0200551
552 return 0;
553}
554
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200555static int wacom_probe(struct hid_device *hdev,
556 const struct hid_device_id *id)
557{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200558 struct wacom_data *wdata;
559 int ret;
560
561 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
562 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800563 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200564 return -ENOMEM;
565 }
566
567 hid_set_drvdata(hdev, wdata);
568
Bastien Nocera46a709b2010-01-20 12:00:53 +0000569 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200570 ret = hid_parse(hdev);
571 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800572 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200573 goto err_free;
574 }
575
576 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
577 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800578 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200579 goto err_free;
580 }
581
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000582 ret = device_create_file(&hdev->dev, &dev_attr_speed);
583 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800584 hid_warn(hdev,
585 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100586
Przemo Firszt78761ff2011-11-05 11:28:22 +0000587 switch (hdev->product) {
588 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
589 /* Set Wacom mode 2 with high reporting speed */
590 wacom_poke(hdev, 1);
591 break;
592 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
593 wdata->features = 0;
594 wacom_set_features(hdev);
595 break;
596 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000597
Przemo Firszt59d23342010-03-15 19:16:23 +0000598#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
599 wdata->battery.properties = wacom_battery_props;
600 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
601 wdata->battery.get_property = wacom_battery_get_property;
602 wdata->battery.name = "wacom_battery";
603 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
604 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000605
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800606
Przemo Firszt59d23342010-03-15 19:16:23 +0000607 ret = power_supply_register(&hdev->dev, &wdata->battery);
608 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800609 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
610 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200611 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000612 }
613
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000614 power_supply_powers(&wdata->battery, &hdev->dev);
615
Przemo Firszt59d23342010-03-15 19:16:23 +0000616 wdata->ac.properties = wacom_ac_props;
617 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
618 wdata->ac.get_property = wacom_ac_get_property;
619 wdata->ac.name = "wacom_ac";
620 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
621 wdata->ac.use_for_apm = 0;
622
623 ret = power_supply_register(&hdev->dev, &wdata->ac);
624 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800625 hid_warn(hdev,
626 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200627 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000628 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000629
630 power_supply_powers(&wdata->ac, &hdev->dev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000631#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200632 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700633
David Herrmanndde58cf2011-09-05 18:45:28 +0200634#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
635err_ac:
636 power_supply_unregister(&wdata->battery);
637err_battery:
638 device_remove_file(&hdev->dev, &dev_attr_speed);
639 hid_hw_stop(hdev);
640#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200641err_free:
642 kfree(wdata);
643 return ret;
644}
645
646static void wacom_remove(struct hid_device *hdev)
647{
Przemo Firszt59d23342010-03-15 19:16:23 +0000648#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
649 struct wacom_data *wdata = hid_get_drvdata(hdev);
650#endif
David Herrmann90866172011-09-05 18:45:29 +0200651 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200652 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000653
654#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
655 power_supply_unregister(&wdata->battery);
656 power_supply_unregister(&wdata->ac);
657#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200658 kfree(hid_get_drvdata(hdev));
659}
660
661static const struct hid_device_id wacom_devices[] = {
662 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000663 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200664
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200665 { }
666};
667MODULE_DEVICE_TABLE(hid, wacom_devices);
668
669static struct hid_driver wacom_driver = {
670 .name = "wacom",
671 .id_table = wacom_devices,
672 .probe = wacom_probe,
673 .remove = wacom_remove,
674 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200675 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200676};
677
Peter Huewea24f423b2009-07-02 19:08:38 +0200678static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200679{
680 int ret;
681
682 ret = hid_register_driver(&wacom_driver);
683 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800684 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200685 return ret;
686}
687
Peter Huewea24f423b2009-07-02 19:08:38 +0200688static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200689{
690 hid_unregister_driver(&wacom_driver);
691}
692
693module_init(wacom_init);
694module_exit(wacom_exit);
695MODULE_LICENSE("GPL");
696