blob: edf6cba6037a1626d00a4a0ce189d22fa948afdd [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#include <linux/power_supply.h>
Bastien Noceraca2dcd42009-05-11 17:18:12 +020029
30#include "hid-ids.h"
31
Przemo Firszt6245bde2012-02-28 17:19:05 +000032#define PAD_DEVICE_ID 0x0F
33
Bastien Noceraca2dcd42009-05-11 17:18:12 +020034struct wacom_data {
35 __u16 tool;
Przemo Firszt6245bde2012-02-28 17:19:05 +000036 __u16 butstate;
Przemo Firszt7e503a32012-03-14 19:55:04 +000037 __u8 whlstate;
Przemo Firszt78761ff2011-11-05 11:28:22 +000038 __u8 features;
Przemo Firszt24709002012-02-24 13:52:32 +000039 __u32 id;
40 __u32 serial;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +000041 unsigned char high_speed;
Przemo Firszte31e3832012-03-22 18:54:07 +000042 __u8 battery_capacity;
43 __u8 power_raw;
44 __u8 ps_connected;
Przemo Firszt59d23342010-03-15 19:16:23 +000045 struct power_supply battery;
46 struct power_supply ac;
Bastien Noceraca2dcd42009-05-11 17:18:12 +020047};
48
Przemo Firszte31e3832012-03-22 18:54:07 +000049/*percent of battery capacity for Graphire
50 8th value means AC online and show 100% capacity */
51static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 };
Przemo Firszt59d23342010-03-15 19:16:23 +000052
53static enum power_supply_property wacom_battery_props[] = {
54 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080055 POWER_SUPPLY_PROP_CAPACITY,
56 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000057};
58
59static enum power_supply_property wacom_ac_props[] = {
60 POWER_SUPPLY_PROP_PRESENT,
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -080061 POWER_SUPPLY_PROP_ONLINE,
62 POWER_SUPPLY_PROP_SCOPE,
Przemo Firszt59d23342010-03-15 19:16:23 +000063};
64
65static int wacom_battery_get_property(struct power_supply *psy,
66 enum power_supply_property psp,
67 union power_supply_propval *val)
68{
69 struct wacom_data *wdata = container_of(psy,
70 struct wacom_data, battery);
Przemo Firszt59d23342010-03-15 19:16:23 +000071 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:
Przemo Firszte31e3832012-03-22 18:54:07 +000081 val->intval = wdata->battery_capacity;
Przemo Firszt59d23342010-03-15 19:16:23 +000082 break;
83 default:
84 ret = -EINVAL;
85 break;
86 }
87 return ret;
88}
89
90static int wacom_ac_get_property(struct power_supply *psy,
91 enum power_supply_property psp,
92 union power_supply_propval *val)
93{
94 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
Przemo Firszt59d23342010-03-15 19:16:23 +000095 int ret = 0;
96
97 switch (psp) {
98 case POWER_SUPPLY_PROP_PRESENT:
99 /* fall through */
100 case POWER_SUPPLY_PROP_ONLINE:
Przemo Firszte31e3832012-03-22 18:54:07 +0000101 val->intval = wdata->ps_connected;
Przemo Firszt59d23342010-03-15 19:16:23 +0000102 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -0800103 case POWER_SUPPLY_PROP_SCOPE:
104 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
105 break;
Przemo Firszt59d23342010-03-15 19:16:23 +0000106 default:
107 ret = -EINVAL;
108 break;
109 }
110 return ret;
111}
Przemo Firszt59d23342010-03-15 19:16:23 +0000112
Przemo Firszt78761ff2011-11-05 11:28:22 +0000113static void wacom_set_features(struct hid_device *hdev)
114{
115 int ret;
116 __u8 rep_data[2];
117
118 /*set high speed, tablet mode*/
119 rep_data[0] = 0x03;
120 rep_data[1] = 0x20;
121 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
122 HID_FEATURE_REPORT);
123 return;
124}
125
Przemo Firszt06c7c312010-03-22 09:55:04 +0100126static void wacom_poke(struct hid_device *hdev, u8 speed)
127{
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000128 struct wacom_data *wdata = hid_get_drvdata(hdev);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100129 int limit, ret;
130 char rep_data[2];
131
132 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
133 limit = 3;
134 do {
135 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
136 HID_FEATURE_REPORT);
137 } while (ret < 0 && limit-- > 0);
138
139 if (ret >= 0) {
140 if (speed == 0)
141 rep_data[0] = 0x05;
142 else
143 rep_data[0] = 0x06;
144
145 rep_data[1] = 0x00;
146 limit = 3;
147 do {
148 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
149 HID_FEATURE_REPORT);
150 } while (ret < 0 && limit-- > 0);
151
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000152 if (ret >= 0) {
153 wdata->high_speed = speed;
Przemo Firszt06c7c312010-03-22 09:55:04 +0100154 return;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000155 }
Przemo Firszt06c7c312010-03-22 09:55:04 +0100156 }
157
158 /*
159 * Note that if the raw queries fail, it's not a hard failure and it
160 * is safe to continue
161 */
Joe Perches4291ee32010-12-09 19:29:03 -0800162 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
163 rep_data[0], ret);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100164 return;
165}
166
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000167static ssize_t wacom_show_speed(struct device *dev,
168 struct device_attribute
169 *attr, char *buf)
170{
171 struct wacom_data *wdata = dev_get_drvdata(dev);
172
173 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
174}
175
176static ssize_t wacom_store_speed(struct device *dev,
177 struct device_attribute *attr,
178 const char *buf, size_t count)
179{
180 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
181 int new_speed;
182
183 if (sscanf(buf, "%1d", &new_speed ) != 1)
184 return -EINVAL;
185
186 if (new_speed == 0 || new_speed == 1) {
187 wacom_poke(hdev, new_speed);
188 return strnlen(buf, PAGE_SIZE);
189 } else
190 return -EINVAL;
191}
192
Jiri Kosinaedd21262010-11-18 16:28:43 +0100193static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000194 wacom_show_speed, wacom_store_speed);
195
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000196static int wacom_gr_parse_report(struct hid_device *hdev,
197 struct wacom_data *wdata,
198 struct input_dev *input, unsigned char *data)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200199{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200200 int tool, x, y, rw;
201
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200202 tool = 0;
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200203 /* Get X & Y positions */
204 x = le16_to_cpu(*(__le16 *) &data[2]);
205 y = le16_to_cpu(*(__le16 *) &data[4]);
206
207 /* Get current tool identifier */
208 if (data[1] & 0x90) { /* If pen is in the in/active area */
209 switch ((data[1] >> 5) & 3) {
210 case 0: /* Pen */
211 tool = BTN_TOOL_PEN;
212 break;
213
214 case 1: /* Rubber */
215 tool = BTN_TOOL_RUBBER;
216 break;
217
218 case 2: /* Mouse with wheel */
219 case 3: /* Mouse without wheel */
220 tool = BTN_TOOL_MOUSE;
221 break;
222 }
223
224 /* Reset tool if out of active tablet area */
225 if (!(data[1] & 0x10))
226 tool = 0;
227 }
228
229 /* If tool changed, notify input subsystem */
230 if (wdata->tool != tool) {
231 if (wdata->tool) {
232 /* Completely reset old tool state */
233 if (wdata->tool == BTN_TOOL_MOUSE) {
234 input_report_key(input, BTN_LEFT, 0);
235 input_report_key(input, BTN_RIGHT, 0);
236 input_report_key(input, BTN_MIDDLE, 0);
237 input_report_abs(input, ABS_DISTANCE,
Daniel Mack987a6c02010-08-02 20:15:17 -0700238 input_abs_get_max(input, ABS_DISTANCE));
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200239 } else {
240 input_report_key(input, BTN_TOUCH, 0);
241 input_report_key(input, BTN_STYLUS, 0);
242 input_report_key(input, BTN_STYLUS2, 0);
243 input_report_abs(input, ABS_PRESSURE, 0);
244 }
245 input_report_key(input, wdata->tool, 0);
246 input_sync(input);
247 }
248 wdata->tool = tool;
249 if (tool)
250 input_report_key(input, tool, 1);
251 }
252
253 if (tool) {
254 input_report_abs(input, ABS_X, x);
255 input_report_abs(input, ABS_Y, y);
256
257 switch ((data[1] >> 5) & 3) {
258 case 2: /* Mouse with wheel */
259 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
260 rw = (data[6] & 0x01) ? -1 :
261 (data[6] & 0x02) ? 1 : 0;
262 input_report_rel(input, REL_WHEEL, rw);
263 /* fall through */
264
265 case 3: /* Mouse without wheel */
266 input_report_key(input, BTN_LEFT, data[1] & 0x01);
267 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
268 /* Compute distance between mouse and tablet */
269 rw = 44 - (data[6] >> 2);
270 if (rw < 0)
271 rw = 0;
272 else if (rw > 31)
273 rw = 31;
274 input_report_abs(input, ABS_DISTANCE, rw);
275 break;
276
277 default:
278 input_report_abs(input, ABS_PRESSURE,
279 data[6] | (((__u16) (data[1] & 0x08)) << 5));
280 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
281 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
282 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
283 break;
284 }
285
286 input_sync(input);
287 }
288
289 /* Report the state of the two buttons at the top of the tablet
290 * as two extra fingerpad keys (buttons 4 & 5). */
291 rw = data[7] & 0x03;
292 if (rw != wdata->butstate) {
293 wdata->butstate = rw;
294 input_report_key(input, BTN_0, rw & 0x02);
295 input_report_key(input, BTN_1, rw & 0x01);
Przemo Firszt0e253fd2010-01-09 15:20:03 +0100296 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200297 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
298 input_sync(input);
299 }
300
Przemo Firszte31e3832012-03-22 18:54:07 +0000301 /* Store current battery capacity and power supply state*/
Przemo Firszt59d23342010-03-15 19:16:23 +0000302 rw = (data[7] >> 2 & 0x07);
Przemo Firszte31e3832012-03-22 18:54:07 +0000303 if (rw != wdata->power_raw) {
304 wdata->power_raw = rw;
305 wdata->battery_capacity = batcap_gr[rw];
306 if (rw == 7)
307 wdata->ps_connected = 1;
308 else
309 wdata->ps_connected = 0;
310 }
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200311 return 1;
312}
Przemo Firszt78761ff2011-11-05 11:28:22 +0000313
Przemo Firszt6245bde2012-02-28 17:19:05 +0000314static void wacom_i4_parse_button_report(struct wacom_data *wdata,
315 struct input_dev *input, unsigned char *data)
316{
317 __u16 new_butstate;
Przemo Firszt7e503a32012-03-14 19:55:04 +0000318 __u8 new_whlstate;
319 __u8 sync = 0;
320
321 new_whlstate = data[1];
322 if (new_whlstate != wdata->whlstate) {
323 wdata->whlstate = new_whlstate;
324 if (new_whlstate & 0x80) {
325 input_report_key(input, BTN_TOUCH, 1);
326 input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
327 input_report_key(input, BTN_TOOL_FINGER, 1);
328 } else {
329 input_report_key(input, BTN_TOUCH, 0);
330 input_report_abs(input, ABS_WHEEL, 0);
331 input_report_key(input, BTN_TOOL_FINGER, 0);
332 }
333 sync = 1;
334 }
Przemo Firszt6245bde2012-02-28 17:19:05 +0000335
336 new_butstate = (data[3] << 1) | (data[2] & 0x01);
337 if (new_butstate != wdata->butstate) {
338 wdata->butstate = new_butstate;
339 input_report_key(input, BTN_0, new_butstate & 0x001);
340 input_report_key(input, BTN_1, new_butstate & 0x002);
341 input_report_key(input, BTN_2, new_butstate & 0x004);
342 input_report_key(input, BTN_3, new_butstate & 0x008);
343 input_report_key(input, BTN_4, new_butstate & 0x010);
344 input_report_key(input, BTN_5, new_butstate & 0x020);
345 input_report_key(input, BTN_6, new_butstate & 0x040);
346 input_report_key(input, BTN_7, new_butstate & 0x080);
347 input_report_key(input, BTN_8, new_butstate & 0x100);
348 input_report_key(input, BTN_TOOL_FINGER, 1);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000349 sync = 1;
350 }
351
352 if (sync) {
Przemo Firszt6245bde2012-02-28 17:19:05 +0000353 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
354 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
355 input_sync(input);
356 }
357}
358
Przemo Firszt78761ff2011-11-05 11:28:22 +0000359static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
360 struct input_dev *input, unsigned char *data)
361{
362 __u16 x, y, pressure;
Przemo Firszte0829e92012-02-28 17:19:04 +0000363 __u8 distance;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000364
365 switch (data[1]) {
366 case 0x80: /* Out of proximity report */
Przemo Firszt78761ff2011-11-05 11:28:22 +0000367 input_report_key(input, BTN_TOUCH, 0);
368 input_report_abs(input, ABS_PRESSURE, 0);
Przemo Firszt693f45b2012-03-09 13:20:51 +0000369 input_report_key(input, BTN_STYLUS, 0);
370 input_report_key(input, BTN_STYLUS2, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000371 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000372 input_report_abs(input, ABS_MISC, 0);
373 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000374 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000375 input_sync(input);
376 break;
377 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000378 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000379 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000380 ((data[8] & 0xf0) << 12));
381 wdata->serial = ((data[3] & 0x0f) << 28) +
382 (data[4] << 20) + (data[5] << 12) +
383 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000384
Przemo Firszt24709002012-02-24 13:52:32 +0000385 switch (wdata->id) {
386 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000387 wdata->tool = BTN_TOOL_PEN;
388 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000389 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000390 wdata->tool = BTN_TOOL_RUBBER;
391 break;
392 }
393 break;
394 default: /* Position/pressure report */
395 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
396 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
397 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
398 | (data[1] & 0x01);
Przemo Firszte0829e92012-02-28 17:19:04 +0000399 distance = (data[9] >> 2) & 0x3f;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000400
401 input_report_key(input, BTN_TOUCH, pressure > 1);
402
403 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
404 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
405 input_report_key(input, wdata->tool, 1);
406 input_report_abs(input, ABS_X, x);
407 input_report_abs(input, ABS_Y, y);
408 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszte0829e92012-02-28 17:19:04 +0000409 input_report_abs(input, ABS_DISTANCE, distance);
Przemo Firszt24709002012-02-24 13:52:32 +0000410 input_report_abs(input, ABS_MISC, wdata->id);
411 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
412 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000413 input_sync(input);
414 break;
415 }
416
417 return;
418}
419
420static void wacom_i4_parse_report(struct hid_device *hdev,
421 struct wacom_data *wdata,
422 struct input_dev *input, unsigned char *data)
423{
424 switch (data[0]) {
425 case 0x00: /* Empty report */
426 break;
427 case 0x02: /* Pen report */
428 wacom_i4_parse_pen_report(wdata, input, data);
429 break;
430 case 0x03: /* Features Report */
431 wdata->features = data[2];
432 break;
433 case 0x0C: /* Button report */
Przemo Firszt6245bde2012-02-28 17:19:05 +0000434 wacom_i4_parse_button_report(wdata, input, data);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000435 break;
436 default:
437 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
438 break;
439 }
440}
441
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000442static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
443 u8 *raw_data, int size)
444{
445 struct wacom_data *wdata = hid_get_drvdata(hdev);
446 struct hid_input *hidinput;
447 struct input_dev *input;
448 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000449 int i;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000450
451 if (!(hdev->claimed & HID_CLAIMED_INPUT))
452 return 0;
453
454 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
455 input = hidinput->input;
456
457 /* Check if this is a tablet report */
458 if (data[0] != 0x03)
459 return 0;
460
Przemo Firszt78761ff2011-11-05 11:28:22 +0000461 switch (hdev->product) {
462 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
463 return wacom_gr_parse_report(hdev, wdata, input, data);
464 break;
465 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
466 i = 1;
467
468 switch (data[0]) {
469 case 0x04:
470 wacom_i4_parse_report(hdev, wdata, input, data + i);
471 i += 10;
472 /* fall through */
473 case 0x03:
474 wacom_i4_parse_report(hdev, wdata, input, data + i);
475 i += 10;
476 wacom_i4_parse_report(hdev, wdata, input, data + i);
477 break;
478 default:
479 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
480 data[0], data[1], size);
481 return 0;
482 }
483 }
484 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000485}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200486
David Herrmann3797ef62011-10-08 23:20:17 +0200487static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
488 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
489 int *max)
490{
491 struct input_dev *input = hi->input;
492
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200493 __set_bit(INPUT_PROP_POINTER, input->propbit);
494
David Herrmann3797ef62011-10-08 23:20:17 +0200495 /* Basics */
496 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
497
498 __set_bit(REL_WHEEL, input->relbit);
499
500 __set_bit(BTN_TOOL_PEN, input->keybit);
501 __set_bit(BTN_TOUCH, input->keybit);
502 __set_bit(BTN_STYLUS, input->keybit);
503 __set_bit(BTN_STYLUS2, input->keybit);
504 __set_bit(BTN_LEFT, input->keybit);
505 __set_bit(BTN_RIGHT, input->keybit);
506 __set_bit(BTN_MIDDLE, input->keybit);
507
508 /* Pad */
Przemo Firszt9a911da2012-03-14 19:55:03 +0000509 input_set_capability(input, EV_MSC, MSC_SERIAL);
David Herrmann3797ef62011-10-08 23:20:17 +0200510
511 __set_bit(BTN_0, input->keybit);
512 __set_bit(BTN_1, input->keybit);
513 __set_bit(BTN_TOOL_FINGER, input->keybit);
514
515 /* Distance, rubber and mouse */
516 __set_bit(BTN_TOOL_RUBBER, input->keybit);
517 __set_bit(BTN_TOOL_MOUSE, input->keybit);
518
Przemo Firszt78761ff2011-11-05 11:28:22 +0000519 switch (hdev->product) {
520 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
521 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
522 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
523 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
524 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
525 break;
526 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt7e503a32012-03-14 19:55:04 +0000527 __set_bit(ABS_WHEEL, input->absbit);
Przemo Firszt2c653e62012-02-24 13:47:48 +0000528 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt6245bde2012-02-28 17:19:05 +0000529 __set_bit(BTN_2, input->keybit);
530 __set_bit(BTN_3, input->keybit);
531 __set_bit(BTN_4, input->keybit);
532 __set_bit(BTN_5, input->keybit);
533 __set_bit(BTN_6, input->keybit);
534 __set_bit(BTN_7, input->keybit);
535 __set_bit(BTN_8, input->keybit);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000536 input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000537 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
538 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
539 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
Przemo Firszte0829e92012-02-28 17:19:04 +0000540 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000541 break;
542 }
David Herrmann3797ef62011-10-08 23:20:17 +0200543
544 return 0;
545}
546
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200547static int wacom_probe(struct hid_device *hdev,
548 const struct hid_device_id *id)
549{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200550 struct wacom_data *wdata;
551 int ret;
552
553 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
554 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800555 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200556 return -ENOMEM;
557 }
558
559 hid_set_drvdata(hdev, wdata);
560
Bastien Nocera46a709b2010-01-20 12:00:53 +0000561 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200562 ret = hid_parse(hdev);
563 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800564 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200565 goto err_free;
566 }
567
568 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
569 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800570 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200571 goto err_free;
572 }
573
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000574 ret = device_create_file(&hdev->dev, &dev_attr_speed);
575 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800576 hid_warn(hdev,
577 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100578
Przemo Firszt78761ff2011-11-05 11:28:22 +0000579 switch (hdev->product) {
580 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
581 /* Set Wacom mode 2 with high reporting speed */
582 wacom_poke(hdev, 1);
583 break;
584 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszta72c5dd2012-02-17 17:47:10 +0000585 sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
Przemo Firszt78761ff2011-11-05 11:28:22 +0000586 wdata->features = 0;
587 wacom_set_features(hdev);
588 break;
589 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000590
Przemo Firszt59d23342010-03-15 19:16:23 +0000591 wdata->battery.properties = wacom_battery_props;
592 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
593 wdata->battery.get_property = wacom_battery_get_property;
594 wdata->battery.name = "wacom_battery";
595 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
596 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000597
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800598
Przemo Firszt59d23342010-03-15 19:16:23 +0000599 ret = power_supply_register(&hdev->dev, &wdata->battery);
600 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800601 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
602 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200603 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000604 }
605
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000606 power_supply_powers(&wdata->battery, &hdev->dev);
607
Przemo Firszt59d23342010-03-15 19:16:23 +0000608 wdata->ac.properties = wacom_ac_props;
609 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
610 wdata->ac.get_property = wacom_ac_get_property;
611 wdata->ac.name = "wacom_ac";
612 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
613 wdata->ac.use_for_apm = 0;
614
615 ret = power_supply_register(&hdev->dev, &wdata->ac);
616 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800617 hid_warn(hdev,
618 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200619 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000620 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000621
622 power_supply_powers(&wdata->ac, &hdev->dev);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200623 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700624
David Herrmanndde58cf2011-09-05 18:45:28 +0200625err_ac:
626 power_supply_unregister(&wdata->battery);
627err_battery:
628 device_remove_file(&hdev->dev, &dev_attr_speed);
629 hid_hw_stop(hdev);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200630err_free:
631 kfree(wdata);
632 return ret;
633}
634
635static void wacom_remove(struct hid_device *hdev)
636{
Przemo Firszt59d23342010-03-15 19:16:23 +0000637 struct wacom_data *wdata = hid_get_drvdata(hdev);
David Herrmann90866172011-09-05 18:45:29 +0200638 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200639 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000640
Przemo Firszt59d23342010-03-15 19:16:23 +0000641 power_supply_unregister(&wdata->battery);
642 power_supply_unregister(&wdata->ac);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200643 kfree(hid_get_drvdata(hdev));
644}
645
646static const struct hid_device_id wacom_devices[] = {
647 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000648 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200649
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200650 { }
651};
652MODULE_DEVICE_TABLE(hid, wacom_devices);
653
654static struct hid_driver wacom_driver = {
655 .name = "wacom",
656 .id_table = wacom_devices,
657 .probe = wacom_probe,
658 .remove = wacom_remove,
659 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200660 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200661};
662
Peter Huewea24f423b2009-07-02 19:08:38 +0200663static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200664{
665 int ret;
666
667 ret = hid_register_driver(&wacom_driver);
668 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800669 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200670 return ret;
671}
672
Peter Huewea24f423b2009-07-02 19:08:38 +0200673static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200674{
675 hid_unregister_driver(&wacom_driver);
676}
677
678module_init(wacom_init);
679module_exit(wacom_exit);
680MODULE_LICENSE("GPL");
681