blob: f9af474275dbbd09c247d8716d1676dedc3866da [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 Firszt78761ff2011-11-05 11:28:22 +000039 __u8 features;
Przemo Firszt24709002012-02-24 13:52:32 +000040 __u32 id;
41 __u32 serial;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +000042 unsigned char high_speed;
Przemo Firszt59d23342010-03-15 19:16:23 +000043#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
44 int battery_capacity;
45 struct power_supply battery;
46 struct power_supply ac;
47#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +020048};
49
Przemo Firszt59d23342010-03-15 19:16:23 +000050#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
51/*percent of battery capacity, 0 means AC online*/
52static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
53
54static enum power_supply_property wacom_battery_props[] = {
55 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080056 POWER_SUPPLY_PROP_CAPACITY,
57 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000058};
59
60static enum power_supply_property wacom_ac_props[] = {
61 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080062 POWER_SUPPLY_PROP_ONLINE,
63 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000064};
65
66static int wacom_battery_get_property(struct power_supply *psy,
67 enum power_supply_property psp,
68 union power_supply_propval *val)
69{
70 struct wacom_data *wdata = container_of(psy,
71 struct wacom_data, battery);
72 int power_state = batcap[wdata->battery_capacity];
73 int ret = 0;
74
75 switch (psp) {
76 case POWER_SUPPLY_PROP_PRESENT:
77 val->intval = 1;
78 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080079 case POWER_SUPPLY_PROP_SCOPE:
80 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
81 break;
Przemo Firszt59d23342010-03-15 19:16:23 +000082 case POWER_SUPPLY_PROP_CAPACITY:
83 /* show 100% battery capacity when charging */
84 if (power_state == 0)
85 val->intval = 100;
86 else
87 val->intval = power_state;
88 break;
89 default:
90 ret = -EINVAL;
91 break;
92 }
93 return ret;
94}
95
96static int wacom_ac_get_property(struct power_supply *psy,
97 enum power_supply_property psp,
98 union power_supply_propval *val)
99{
100 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
101 int power_state = batcap[wdata->battery_capacity];
102 int ret = 0;
103
104 switch (psp) {
105 case POWER_SUPPLY_PROP_PRESENT:
106 /* fall through */
107 case POWER_SUPPLY_PROP_ONLINE:
108 if (power_state == 0)
109 val->intval = 1;
110 else
111 val->intval = 0;
112 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -0800113 case POWER_SUPPLY_PROP_SCOPE:
114 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
115 break;
Przemo Firszt59d23342010-03-15 19:16:23 +0000116 default:
117 ret = -EINVAL;
118 break;
119 }
120 return ret;
121}
122#endif
123
Przemo Firszt78761ff2011-11-05 11:28:22 +0000124static void wacom_set_features(struct hid_device *hdev)
125{
126 int ret;
127 __u8 rep_data[2];
128
129 /*set high speed, tablet mode*/
130 rep_data[0] = 0x03;
131 rep_data[1] = 0x20;
132 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
133 HID_FEATURE_REPORT);
134 return;
135}
136
Przemo Firszt06c7c312010-03-22 09:55:04 +0100137static void wacom_poke(struct hid_device *hdev, u8 speed)
138{
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000139 struct wacom_data *wdata = hid_get_drvdata(hdev);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100140 int limit, ret;
141 char rep_data[2];
142
143 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
144 limit = 3;
145 do {
146 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
147 HID_FEATURE_REPORT);
148 } while (ret < 0 && limit-- > 0);
149
150 if (ret >= 0) {
151 if (speed == 0)
152 rep_data[0] = 0x05;
153 else
154 rep_data[0] = 0x06;
155
156 rep_data[1] = 0x00;
157 limit = 3;
158 do {
159 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
160 HID_FEATURE_REPORT);
161 } while (ret < 0 && limit-- > 0);
162
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000163 if (ret >= 0) {
164 wdata->high_speed = speed;
Przemo Firszt06c7c312010-03-22 09:55:04 +0100165 return;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000166 }
Przemo Firszt06c7c312010-03-22 09:55:04 +0100167 }
168
169 /*
170 * Note that if the raw queries fail, it's not a hard failure and it
171 * is safe to continue
172 */
Joe Perches4291ee32010-12-09 19:29:03 -0800173 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
174 rep_data[0], ret);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100175 return;
176}
177
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000178static ssize_t wacom_show_speed(struct device *dev,
179 struct device_attribute
180 *attr, char *buf)
181{
182 struct wacom_data *wdata = dev_get_drvdata(dev);
183
184 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
185}
186
187static ssize_t wacom_store_speed(struct device *dev,
188 struct device_attribute *attr,
189 const char *buf, size_t count)
190{
191 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
192 int new_speed;
193
194 if (sscanf(buf, "%1d", &new_speed ) != 1)
195 return -EINVAL;
196
197 if (new_speed == 0 || new_speed == 1) {
198 wacom_poke(hdev, new_speed);
199 return strnlen(buf, PAGE_SIZE);
200 } else
201 return -EINVAL;
202}
203
Jiri Kosinaedd21262010-11-18 16:28:43 +0100204static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000205 wacom_show_speed, wacom_store_speed);
206
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000207static int wacom_gr_parse_report(struct hid_device *hdev,
208 struct wacom_data *wdata,
209 struct input_dev *input, unsigned char *data)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200210{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200211 int tool, x, y, rw;
212
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200213 tool = 0;
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200214 /* Get X & Y positions */
215 x = le16_to_cpu(*(__le16 *) &data[2]);
216 y = le16_to_cpu(*(__le16 *) &data[4]);
217
218 /* Get current tool identifier */
219 if (data[1] & 0x90) { /* If pen is in the in/active area */
220 switch ((data[1] >> 5) & 3) {
221 case 0: /* Pen */
222 tool = BTN_TOOL_PEN;
223 break;
224
225 case 1: /* Rubber */
226 tool = BTN_TOOL_RUBBER;
227 break;
228
229 case 2: /* Mouse with wheel */
230 case 3: /* Mouse without wheel */
231 tool = BTN_TOOL_MOUSE;
232 break;
233 }
234
235 /* Reset tool if out of active tablet area */
236 if (!(data[1] & 0x10))
237 tool = 0;
238 }
239
240 /* If tool changed, notify input subsystem */
241 if (wdata->tool != tool) {
242 if (wdata->tool) {
243 /* Completely reset old tool state */
244 if (wdata->tool == BTN_TOOL_MOUSE) {
245 input_report_key(input, BTN_LEFT, 0);
246 input_report_key(input, BTN_RIGHT, 0);
247 input_report_key(input, BTN_MIDDLE, 0);
248 input_report_abs(input, ABS_DISTANCE,
Daniel Mack987a6c02010-08-02 20:15:17 -0700249 input_abs_get_max(input, ABS_DISTANCE));
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200250 } else {
251 input_report_key(input, BTN_TOUCH, 0);
252 input_report_key(input, BTN_STYLUS, 0);
253 input_report_key(input, BTN_STYLUS2, 0);
254 input_report_abs(input, ABS_PRESSURE, 0);
255 }
256 input_report_key(input, wdata->tool, 0);
257 input_sync(input);
258 }
259 wdata->tool = tool;
260 if (tool)
261 input_report_key(input, tool, 1);
262 }
263
264 if (tool) {
265 input_report_abs(input, ABS_X, x);
266 input_report_abs(input, ABS_Y, y);
267
268 switch ((data[1] >> 5) & 3) {
269 case 2: /* Mouse with wheel */
270 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
271 rw = (data[6] & 0x01) ? -1 :
272 (data[6] & 0x02) ? 1 : 0;
273 input_report_rel(input, REL_WHEEL, rw);
274 /* fall through */
275
276 case 3: /* Mouse without wheel */
277 input_report_key(input, BTN_LEFT, data[1] & 0x01);
278 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
279 /* Compute distance between mouse and tablet */
280 rw = 44 - (data[6] >> 2);
281 if (rw < 0)
282 rw = 0;
283 else if (rw > 31)
284 rw = 31;
285 input_report_abs(input, ABS_DISTANCE, rw);
286 break;
287
288 default:
289 input_report_abs(input, ABS_PRESSURE,
290 data[6] | (((__u16) (data[1] & 0x08)) << 5));
291 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
292 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
293 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
294 break;
295 }
296
297 input_sync(input);
298 }
299
300 /* Report the state of the two buttons at the top of the tablet
301 * as two extra fingerpad keys (buttons 4 & 5). */
302 rw = data[7] & 0x03;
303 if (rw != wdata->butstate) {
304 wdata->butstate = rw;
305 input_report_key(input, BTN_0, rw & 0x02);
306 input_report_key(input, BTN_1, rw & 0x01);
Przemo Firszt0e253fd2010-01-09 15:20:03 +0100307 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200308 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
309 input_sync(input);
310 }
311
Przemo Firszt59d23342010-03-15 19:16:23 +0000312#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
313 /* Store current battery capacity */
314 rw = (data[7] >> 2 & 0x07);
315 if (rw != wdata->battery_capacity)
316 wdata->battery_capacity = rw;
317#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200318 return 1;
319}
Przemo Firszt78761ff2011-11-05 11:28:22 +0000320
Przemo Firszt6245bde2012-02-28 17:19:05 +0000321static void wacom_i4_parse_button_report(struct wacom_data *wdata,
322 struct input_dev *input, unsigned char *data)
323{
324 __u16 new_butstate;
325
326 new_butstate = (data[3] << 1) | (data[2] & 0x01);
327 if (new_butstate != wdata->butstate) {
328 wdata->butstate = new_butstate;
329 input_report_key(input, BTN_0, new_butstate & 0x001);
330 input_report_key(input, BTN_1, new_butstate & 0x002);
331 input_report_key(input, BTN_2, new_butstate & 0x004);
332 input_report_key(input, BTN_3, new_butstate & 0x008);
333 input_report_key(input, BTN_4, new_butstate & 0x010);
334 input_report_key(input, BTN_5, new_butstate & 0x020);
335 input_report_key(input, BTN_6, new_butstate & 0x040);
336 input_report_key(input, BTN_7, new_butstate & 0x080);
337 input_report_key(input, BTN_8, new_butstate & 0x100);
338 input_report_key(input, BTN_TOOL_FINGER, 1);
339 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
340 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
341 input_sync(input);
342 }
343}
344
Przemo Firszt78761ff2011-11-05 11:28:22 +0000345static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
346 struct input_dev *input, unsigned char *data)
347{
348 __u16 x, y, pressure;
Przemo Firszte0829e92012-02-28 17:19:04 +0000349 __u8 distance;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000350
351 switch (data[1]) {
352 case 0x80: /* Out of proximity report */
Przemo Firszt78761ff2011-11-05 11:28:22 +0000353 input_report_key(input, BTN_TOUCH, 0);
354 input_report_abs(input, ABS_PRESSURE, 0);
Przemo Firszt693f45b2012-03-09 13:20:51 +0000355 input_report_key(input, BTN_STYLUS, 0);
356 input_report_key(input, BTN_STYLUS2, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000357 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000358 input_report_abs(input, ABS_MISC, 0);
359 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000360 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000361 input_sync(input);
362 break;
363 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000364 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000365 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000366 ((data[8] & 0xf0) << 12));
367 wdata->serial = ((data[3] & 0x0f) << 28) +
368 (data[4] << 20) + (data[5] << 12) +
369 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000370
Przemo Firszt24709002012-02-24 13:52:32 +0000371 switch (wdata->id) {
372 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000373 wdata->tool = BTN_TOOL_PEN;
374 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000375 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000376 wdata->tool = BTN_TOOL_RUBBER;
377 break;
378 }
379 break;
380 default: /* Position/pressure report */
381 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
382 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
383 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
384 | (data[1] & 0x01);
Przemo Firszte0829e92012-02-28 17:19:04 +0000385 distance = (data[9] >> 2) & 0x3f;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000386
387 input_report_key(input, BTN_TOUCH, pressure > 1);
388
389 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
390 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
391 input_report_key(input, wdata->tool, 1);
392 input_report_abs(input, ABS_X, x);
393 input_report_abs(input, ABS_Y, y);
394 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszte0829e92012-02-28 17:19:04 +0000395 input_report_abs(input, ABS_DISTANCE, distance);
Przemo Firszt24709002012-02-24 13:52:32 +0000396 input_report_abs(input, ABS_MISC, wdata->id);
397 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
398 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000399 input_sync(input);
400 break;
401 }
402
403 return;
404}
405
406static void wacom_i4_parse_report(struct hid_device *hdev,
407 struct wacom_data *wdata,
408 struct input_dev *input, unsigned char *data)
409{
410 switch (data[0]) {
411 case 0x00: /* Empty report */
412 break;
413 case 0x02: /* Pen report */
414 wacom_i4_parse_pen_report(wdata, input, data);
415 break;
416 case 0x03: /* Features Report */
417 wdata->features = data[2];
418 break;
419 case 0x0C: /* Button report */
Przemo Firszt6245bde2012-02-28 17:19:05 +0000420 wacom_i4_parse_button_report(wdata, input, data);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000421 break;
422 default:
423 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
424 break;
425 }
426}
427
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000428static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
429 u8 *raw_data, int size)
430{
431 struct wacom_data *wdata = hid_get_drvdata(hdev);
432 struct hid_input *hidinput;
433 struct input_dev *input;
434 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000435 int i;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000436
437 if (!(hdev->claimed & HID_CLAIMED_INPUT))
438 return 0;
439
440 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
441 input = hidinput->input;
442
443 /* Check if this is a tablet report */
444 if (data[0] != 0x03)
445 return 0;
446
Przemo Firszt78761ff2011-11-05 11:28:22 +0000447 switch (hdev->product) {
448 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
449 return wacom_gr_parse_report(hdev, wdata, input, data);
450 break;
451 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
452 i = 1;
453
454 switch (data[0]) {
455 case 0x04:
456 wacom_i4_parse_report(hdev, wdata, input, data + i);
457 i += 10;
458 /* fall through */
459 case 0x03:
460 wacom_i4_parse_report(hdev, wdata, input, data + i);
461 i += 10;
462 wacom_i4_parse_report(hdev, wdata, input, data + i);
463 break;
464 default:
465 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
466 data[0], data[1], size);
467 return 0;
468 }
469 }
470 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000471}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200472
David Herrmann3797ef62011-10-08 23:20:17 +0200473static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
474 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
475 int *max)
476{
477 struct input_dev *input = hi->input;
478
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200479 __set_bit(INPUT_PROP_POINTER, input->propbit);
480
David Herrmann3797ef62011-10-08 23:20:17 +0200481 /* Basics */
482 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
483
484 __set_bit(REL_WHEEL, input->relbit);
485
486 __set_bit(BTN_TOOL_PEN, input->keybit);
487 __set_bit(BTN_TOUCH, input->keybit);
488 __set_bit(BTN_STYLUS, input->keybit);
489 __set_bit(BTN_STYLUS2, input->keybit);
490 __set_bit(BTN_LEFT, input->keybit);
491 __set_bit(BTN_RIGHT, input->keybit);
492 __set_bit(BTN_MIDDLE, input->keybit);
493
494 /* Pad */
495 input->evbit[0] |= BIT(EV_MSC);
496
497 __set_bit(MSC_SERIAL, input->mscbit);
498
499 __set_bit(BTN_0, input->keybit);
500 __set_bit(BTN_1, input->keybit);
501 __set_bit(BTN_TOOL_FINGER, input->keybit);
502
503 /* Distance, rubber and mouse */
504 __set_bit(BTN_TOOL_RUBBER, input->keybit);
505 __set_bit(BTN_TOOL_MOUSE, input->keybit);
506
Przemo Firszt78761ff2011-11-05 11:28:22 +0000507 switch (hdev->product) {
508 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
509 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
510 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
511 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
512 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
513 break;
514 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt2c653e62012-02-24 13:47:48 +0000515 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt6245bde2012-02-28 17:19:05 +0000516 __set_bit(BTN_2, input->keybit);
517 __set_bit(BTN_3, input->keybit);
518 __set_bit(BTN_4, input->keybit);
519 __set_bit(BTN_5, input->keybit);
520 __set_bit(BTN_6, input->keybit);
521 __set_bit(BTN_7, input->keybit);
522 __set_bit(BTN_8, input->keybit);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000523 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
524 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
525 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
Przemo Firszte0829e92012-02-28 17:19:04 +0000526 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000527 break;
528 }
David Herrmann3797ef62011-10-08 23:20:17 +0200529
530 return 0;
531}
532
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200533static int wacom_probe(struct hid_device *hdev,
534 const struct hid_device_id *id)
535{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200536 struct wacom_data *wdata;
537 int ret;
538
539 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
540 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800541 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200542 return -ENOMEM;
543 }
544
545 hid_set_drvdata(hdev, wdata);
546
Bastien Nocera46a709b2010-01-20 12:00:53 +0000547 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200548 ret = hid_parse(hdev);
549 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800550 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200551 goto err_free;
552 }
553
554 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
555 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800556 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200557 goto err_free;
558 }
559
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000560 ret = device_create_file(&hdev->dev, &dev_attr_speed);
561 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800562 hid_warn(hdev,
563 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100564
Przemo Firszt78761ff2011-11-05 11:28:22 +0000565 switch (hdev->product) {
566 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
567 /* Set Wacom mode 2 with high reporting speed */
568 wacom_poke(hdev, 1);
569 break;
570 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
571 wdata->features = 0;
572 wacom_set_features(hdev);
573 break;
574 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000575
Przemo Firszt59d23342010-03-15 19:16:23 +0000576#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
577 wdata->battery.properties = wacom_battery_props;
578 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
579 wdata->battery.get_property = wacom_battery_get_property;
580 wdata->battery.name = "wacom_battery";
581 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
582 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000583
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800584
Przemo Firszt59d23342010-03-15 19:16:23 +0000585 ret = power_supply_register(&hdev->dev, &wdata->battery);
586 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800587 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
588 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200589 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000590 }
591
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000592 power_supply_powers(&wdata->battery, &hdev->dev);
593
Przemo Firszt59d23342010-03-15 19:16:23 +0000594 wdata->ac.properties = wacom_ac_props;
595 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
596 wdata->ac.get_property = wacom_ac_get_property;
597 wdata->ac.name = "wacom_ac";
598 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
599 wdata->ac.use_for_apm = 0;
600
601 ret = power_supply_register(&hdev->dev, &wdata->ac);
602 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800603 hid_warn(hdev,
604 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200605 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000606 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000607
608 power_supply_powers(&wdata->ac, &hdev->dev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000609#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200610 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700611
David Herrmanndde58cf2011-09-05 18:45:28 +0200612#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
613err_ac:
614 power_supply_unregister(&wdata->battery);
615err_battery:
616 device_remove_file(&hdev->dev, &dev_attr_speed);
617 hid_hw_stop(hdev);
618#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200619err_free:
620 kfree(wdata);
621 return ret;
622}
623
624static void wacom_remove(struct hid_device *hdev)
625{
Przemo Firszt59d23342010-03-15 19:16:23 +0000626#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
627 struct wacom_data *wdata = hid_get_drvdata(hdev);
628#endif
David Herrmann90866172011-09-05 18:45:29 +0200629 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200630 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000631
632#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
633 power_supply_unregister(&wdata->battery);
634 power_supply_unregister(&wdata->ac);
635#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200636 kfree(hid_get_drvdata(hdev));
637}
638
639static const struct hid_device_id wacom_devices[] = {
640 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000641 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200642
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200643 { }
644};
645MODULE_DEVICE_TABLE(hid, wacom_devices);
646
647static struct hid_driver wacom_driver = {
648 .name = "wacom",
649 .id_table = wacom_devices,
650 .probe = wacom_probe,
651 .remove = wacom_remove,
652 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200653 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200654};
655
Peter Huewea24f423b2009-07-02 19:08:38 +0200656static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200657{
658 int ret;
659
660 ret = hid_register_driver(&wacom_driver);
661 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800662 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200663 return ret;
664}
665
Peter Huewea24f423b2009-07-02 19:08:38 +0200666static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200667{
668 hid_unregister_driver(&wacom_driver);
669}
670
671module_init(wacom_init);
672module_exit(wacom_exit);
673MODULE_LICENSE("GPL");
674