blob: 58aedbc80f02cd899b97b0c6a583508be9ac7587 [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);
355 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000356 input_report_abs(input, ABS_MISC, 0);
357 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000358 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000359 input_sync(input);
360 break;
361 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000362 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000363 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000364 ((data[8] & 0xf0) << 12));
365 wdata->serial = ((data[3] & 0x0f) << 28) +
366 (data[4] << 20) + (data[5] << 12) +
367 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000368
Przemo Firszt24709002012-02-24 13:52:32 +0000369 switch (wdata->id) {
370 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000371 wdata->tool = BTN_TOOL_PEN;
372 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000373 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000374 wdata->tool = BTN_TOOL_RUBBER;
375 break;
376 }
377 break;
378 default: /* Position/pressure report */
379 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
380 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
381 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
382 | (data[1] & 0x01);
Przemo Firszte0829e92012-02-28 17:19:04 +0000383 distance = (data[9] >> 2) & 0x3f;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000384
385 input_report_key(input, BTN_TOUCH, pressure > 1);
386
387 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
388 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
389 input_report_key(input, wdata->tool, 1);
390 input_report_abs(input, ABS_X, x);
391 input_report_abs(input, ABS_Y, y);
392 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszte0829e92012-02-28 17:19:04 +0000393 input_report_abs(input, ABS_DISTANCE, distance);
Przemo Firszt24709002012-02-24 13:52:32 +0000394 input_report_abs(input, ABS_MISC, wdata->id);
395 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
396 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000397 input_sync(input);
398 break;
399 }
400
401 return;
402}
403
404static void wacom_i4_parse_report(struct hid_device *hdev,
405 struct wacom_data *wdata,
406 struct input_dev *input, unsigned char *data)
407{
408 switch (data[0]) {
409 case 0x00: /* Empty report */
410 break;
411 case 0x02: /* Pen report */
412 wacom_i4_parse_pen_report(wdata, input, data);
413 break;
414 case 0x03: /* Features Report */
415 wdata->features = data[2];
416 break;
417 case 0x0C: /* Button report */
Przemo Firszt6245bde2012-02-28 17:19:05 +0000418 wacom_i4_parse_button_report(wdata, input, data);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000419 break;
420 default:
421 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
422 break;
423 }
424}
425
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000426static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
427 u8 *raw_data, int size)
428{
429 struct wacom_data *wdata = hid_get_drvdata(hdev);
430 struct hid_input *hidinput;
431 struct input_dev *input;
432 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000433 int i;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000434
435 if (!(hdev->claimed & HID_CLAIMED_INPUT))
436 return 0;
437
438 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
439 input = hidinput->input;
440
441 /* Check if this is a tablet report */
442 if (data[0] != 0x03)
443 return 0;
444
Przemo Firszt78761ff2011-11-05 11:28:22 +0000445 switch (hdev->product) {
446 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
447 return wacom_gr_parse_report(hdev, wdata, input, data);
448 break;
449 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
450 i = 1;
451
452 switch (data[0]) {
453 case 0x04:
454 wacom_i4_parse_report(hdev, wdata, input, data + i);
455 i += 10;
456 /* fall through */
457 case 0x03:
458 wacom_i4_parse_report(hdev, wdata, input, data + i);
459 i += 10;
460 wacom_i4_parse_report(hdev, wdata, input, data + i);
461 break;
462 default:
463 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
464 data[0], data[1], size);
465 return 0;
466 }
467 }
468 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000469}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200470
David Herrmann3797ef62011-10-08 23:20:17 +0200471static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
472 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
473 int *max)
474{
475 struct input_dev *input = hi->input;
476
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200477 __set_bit(INPUT_PROP_POINTER, input->propbit);
478
David Herrmann3797ef62011-10-08 23:20:17 +0200479 /* Basics */
480 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
481
482 __set_bit(REL_WHEEL, input->relbit);
483
484 __set_bit(BTN_TOOL_PEN, input->keybit);
485 __set_bit(BTN_TOUCH, input->keybit);
486 __set_bit(BTN_STYLUS, input->keybit);
487 __set_bit(BTN_STYLUS2, input->keybit);
488 __set_bit(BTN_LEFT, input->keybit);
489 __set_bit(BTN_RIGHT, input->keybit);
490 __set_bit(BTN_MIDDLE, input->keybit);
491
492 /* Pad */
493 input->evbit[0] |= BIT(EV_MSC);
494
495 __set_bit(MSC_SERIAL, input->mscbit);
496
497 __set_bit(BTN_0, input->keybit);
498 __set_bit(BTN_1, input->keybit);
499 __set_bit(BTN_TOOL_FINGER, input->keybit);
500
501 /* Distance, rubber and mouse */
502 __set_bit(BTN_TOOL_RUBBER, input->keybit);
503 __set_bit(BTN_TOOL_MOUSE, input->keybit);
504
Przemo Firszt78761ff2011-11-05 11:28:22 +0000505 switch (hdev->product) {
506 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
507 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
508 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
509 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
510 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
511 break;
512 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt2c653e62012-02-24 13:47:48 +0000513 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt6245bde2012-02-28 17:19:05 +0000514 __set_bit(BTN_2, input->keybit);
515 __set_bit(BTN_3, input->keybit);
516 __set_bit(BTN_4, input->keybit);
517 __set_bit(BTN_5, input->keybit);
518 __set_bit(BTN_6, input->keybit);
519 __set_bit(BTN_7, input->keybit);
520 __set_bit(BTN_8, input->keybit);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000521 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
522 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
523 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
Przemo Firszte0829e92012-02-28 17:19:04 +0000524 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000525 break;
526 }
David Herrmann3797ef62011-10-08 23:20:17 +0200527
528 return 0;
529}
530
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200531static int wacom_probe(struct hid_device *hdev,
532 const struct hid_device_id *id)
533{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200534 struct wacom_data *wdata;
535 int ret;
536
537 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
538 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800539 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200540 return -ENOMEM;
541 }
542
543 hid_set_drvdata(hdev, wdata);
544
Bastien Nocera46a709b2010-01-20 12:00:53 +0000545 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200546 ret = hid_parse(hdev);
547 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800548 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200549 goto err_free;
550 }
551
552 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
553 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800554 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200555 goto err_free;
556 }
557
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000558 ret = device_create_file(&hdev->dev, &dev_attr_speed);
559 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800560 hid_warn(hdev,
561 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100562
Przemo Firszt78761ff2011-11-05 11:28:22 +0000563 switch (hdev->product) {
564 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
565 /* Set Wacom mode 2 with high reporting speed */
566 wacom_poke(hdev, 1);
567 break;
568 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
569 wdata->features = 0;
570 wacom_set_features(hdev);
571 break;
572 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000573
Przemo Firszt59d23342010-03-15 19:16:23 +0000574#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
575 wdata->battery.properties = wacom_battery_props;
576 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
577 wdata->battery.get_property = wacom_battery_get_property;
578 wdata->battery.name = "wacom_battery";
579 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
580 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000581
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800582
Przemo Firszt59d23342010-03-15 19:16:23 +0000583 ret = power_supply_register(&hdev->dev, &wdata->battery);
584 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800585 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
586 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200587 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000588 }
589
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000590 power_supply_powers(&wdata->battery, &hdev->dev);
591
Przemo Firszt59d23342010-03-15 19:16:23 +0000592 wdata->ac.properties = wacom_ac_props;
593 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
594 wdata->ac.get_property = wacom_ac_get_property;
595 wdata->ac.name = "wacom_ac";
596 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
597 wdata->ac.use_for_apm = 0;
598
599 ret = power_supply_register(&hdev->dev, &wdata->ac);
600 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800601 hid_warn(hdev,
602 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200603 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000604 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000605
606 power_supply_powers(&wdata->ac, &hdev->dev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000607#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200608 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700609
David Herrmanndde58cf2011-09-05 18:45:28 +0200610#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
611err_ac:
612 power_supply_unregister(&wdata->battery);
613err_battery:
614 device_remove_file(&hdev->dev, &dev_attr_speed);
615 hid_hw_stop(hdev);
616#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200617err_free:
618 kfree(wdata);
619 return ret;
620}
621
622static void wacom_remove(struct hid_device *hdev)
623{
Przemo Firszt59d23342010-03-15 19:16:23 +0000624#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
625 struct wacom_data *wdata = hid_get_drvdata(hdev);
626#endif
David Herrmann90866172011-09-05 18:45:29 +0200627 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200628 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000629
630#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
631 power_supply_unregister(&wdata->battery);
632 power_supply_unregister(&wdata->ac);
633#endif
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200634 kfree(hid_get_drvdata(hdev));
635}
636
637static const struct hid_device_id wacom_devices[] = {
638 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000639 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200640
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200641 { }
642};
643MODULE_DEVICE_TABLE(hid, wacom_devices);
644
645static struct hid_driver wacom_driver = {
646 .name = "wacom",
647 .id_table = wacom_devices,
648 .probe = wacom_probe,
649 .remove = wacom_remove,
650 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200651 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200652};
653
Peter Huewea24f423b2009-07-02 19:08:38 +0200654static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200655{
656 int ret;
657
658 ret = hid_register_driver(&wacom_driver);
659 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800660 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200661 return ret;
662}
663
Peter Huewea24f423b2009-07-02 19:08:38 +0200664static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200665{
666 hid_unregister_driver(&wacom_driver);
667}
668
669module_init(wacom_init);
670module_exit(wacom_exit);
671MODULE_LICENSE("GPL");
672