blob: fb0fe165a89dd32b361702f01fe91e1693cf4737 [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 Firszt4202f1d2012-03-22 18:54:08 +000052/*percent of battery capacity for Intuos4 WL, AC has a separate bit*/
53static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
Przemo Firszt59d23342010-03-15 19:16:23 +000054
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);
Przemo Firszt59d23342010-03-15 19:16:23 +000073 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:
Przemo Firszte31e3832012-03-22 18:54:07 +000083 val->intval = wdata->battery_capacity;
Przemo Firszt59d23342010-03-15 19:16:23 +000084 break;
85 default:
86 ret = -EINVAL;
87 break;
88 }
89 return ret;
90}
91
92static int wacom_ac_get_property(struct power_supply *psy,
93 enum power_supply_property psp,
94 union power_supply_propval *val)
95{
96 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
Przemo Firszt59d23342010-03-15 19:16:23 +000097 int ret = 0;
98
99 switch (psp) {
100 case POWER_SUPPLY_PROP_PRESENT:
101 /* fall through */
102 case POWER_SUPPLY_PROP_ONLINE:
Przemo Firszte31e3832012-03-22 18:54:07 +0000103 val->intval = wdata->ps_connected;
Przemo Firszt59d23342010-03-15 19:16:23 +0000104 break;
Jeremy Fitzhardinge73db8812011-12-07 11:29:46 -0800105 case POWER_SUPPLY_PROP_SCOPE:
106 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
107 break;
Przemo Firszt59d23342010-03-15 19:16:23 +0000108 default:
109 ret = -EINVAL;
110 break;
111 }
112 return ret;
113}
Przemo Firszt59d23342010-03-15 19:16:23 +0000114
Przemo Firszt78761ff2011-11-05 11:28:22 +0000115static void wacom_set_features(struct hid_device *hdev)
116{
117 int ret;
118 __u8 rep_data[2];
119
120 /*set high speed, tablet mode*/
121 rep_data[0] = 0x03;
122 rep_data[1] = 0x20;
123 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
124 HID_FEATURE_REPORT);
125 return;
126}
127
Przemo Firszt06c7c312010-03-22 09:55:04 +0100128static void wacom_poke(struct hid_device *hdev, u8 speed)
129{
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000130 struct wacom_data *wdata = hid_get_drvdata(hdev);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100131 int limit, ret;
132 char rep_data[2];
133
134 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
135 limit = 3;
136 do {
137 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
138 HID_FEATURE_REPORT);
139 } while (ret < 0 && limit-- > 0);
140
141 if (ret >= 0) {
142 if (speed == 0)
143 rep_data[0] = 0x05;
144 else
145 rep_data[0] = 0x06;
146
147 rep_data[1] = 0x00;
148 limit = 3;
149 do {
150 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
151 HID_FEATURE_REPORT);
152 } while (ret < 0 && limit-- > 0);
153
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000154 if (ret >= 0) {
155 wdata->high_speed = speed;
Przemo Firszt06c7c312010-03-22 09:55:04 +0100156 return;
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000157 }
Przemo Firszt06c7c312010-03-22 09:55:04 +0100158 }
159
160 /*
161 * Note that if the raw queries fail, it's not a hard failure and it
162 * is safe to continue
163 */
Joe Perches4291ee32010-12-09 19:29:03 -0800164 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
165 rep_data[0], ret);
Przemo Firszt06c7c312010-03-22 09:55:04 +0100166 return;
167}
168
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000169static ssize_t wacom_show_speed(struct device *dev,
170 struct device_attribute
171 *attr, char *buf)
172{
173 struct wacom_data *wdata = dev_get_drvdata(dev);
174
175 return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed);
176}
177
178static ssize_t wacom_store_speed(struct device *dev,
179 struct device_attribute *attr,
180 const char *buf, size_t count)
181{
182 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
183 int new_speed;
184
185 if (sscanf(buf, "%1d", &new_speed ) != 1)
186 return -EINVAL;
187
188 if (new_speed == 0 || new_speed == 1) {
189 wacom_poke(hdev, new_speed);
190 return strnlen(buf, PAGE_SIZE);
191 } else
192 return -EINVAL;
193}
194
Jiri Kosinaedd21262010-11-18 16:28:43 +0100195static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000196 wacom_show_speed, wacom_store_speed);
197
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000198static int wacom_gr_parse_report(struct hid_device *hdev,
199 struct wacom_data *wdata,
200 struct input_dev *input, unsigned char *data)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200201{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200202 int tool, x, y, rw;
203
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200204 tool = 0;
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200205 /* Get X & Y positions */
206 x = le16_to_cpu(*(__le16 *) &data[2]);
207 y = le16_to_cpu(*(__le16 *) &data[4]);
208
209 /* Get current tool identifier */
210 if (data[1] & 0x90) { /* If pen is in the in/active area */
211 switch ((data[1] >> 5) & 3) {
212 case 0: /* Pen */
213 tool = BTN_TOOL_PEN;
214 break;
215
216 case 1: /* Rubber */
217 tool = BTN_TOOL_RUBBER;
218 break;
219
220 case 2: /* Mouse with wheel */
221 case 3: /* Mouse without wheel */
222 tool = BTN_TOOL_MOUSE;
223 break;
224 }
225
226 /* Reset tool if out of active tablet area */
227 if (!(data[1] & 0x10))
228 tool = 0;
229 }
230
231 /* If tool changed, notify input subsystem */
232 if (wdata->tool != tool) {
233 if (wdata->tool) {
234 /* Completely reset old tool state */
235 if (wdata->tool == BTN_TOOL_MOUSE) {
236 input_report_key(input, BTN_LEFT, 0);
237 input_report_key(input, BTN_RIGHT, 0);
238 input_report_key(input, BTN_MIDDLE, 0);
239 input_report_abs(input, ABS_DISTANCE,
Daniel Mack987a6c02010-08-02 20:15:17 -0700240 input_abs_get_max(input, ABS_DISTANCE));
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200241 } else {
242 input_report_key(input, BTN_TOUCH, 0);
243 input_report_key(input, BTN_STYLUS, 0);
244 input_report_key(input, BTN_STYLUS2, 0);
245 input_report_abs(input, ABS_PRESSURE, 0);
246 }
247 input_report_key(input, wdata->tool, 0);
248 input_sync(input);
249 }
250 wdata->tool = tool;
251 if (tool)
252 input_report_key(input, tool, 1);
253 }
254
255 if (tool) {
256 input_report_abs(input, ABS_X, x);
257 input_report_abs(input, ABS_Y, y);
258
259 switch ((data[1] >> 5) & 3) {
260 case 2: /* Mouse with wheel */
261 input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
262 rw = (data[6] & 0x01) ? -1 :
263 (data[6] & 0x02) ? 1 : 0;
264 input_report_rel(input, REL_WHEEL, rw);
265 /* fall through */
266
267 case 3: /* Mouse without wheel */
268 input_report_key(input, BTN_LEFT, data[1] & 0x01);
269 input_report_key(input, BTN_RIGHT, data[1] & 0x02);
270 /* Compute distance between mouse and tablet */
271 rw = 44 - (data[6] >> 2);
272 if (rw < 0)
273 rw = 0;
274 else if (rw > 31)
275 rw = 31;
276 input_report_abs(input, ABS_DISTANCE, rw);
277 break;
278
279 default:
280 input_report_abs(input, ABS_PRESSURE,
281 data[6] | (((__u16) (data[1] & 0x08)) << 5));
282 input_report_key(input, BTN_TOUCH, data[1] & 0x01);
283 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
284 input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
285 break;
286 }
287
288 input_sync(input);
289 }
290
291 /* Report the state of the two buttons at the top of the tablet
292 * as two extra fingerpad keys (buttons 4 & 5). */
293 rw = data[7] & 0x03;
294 if (rw != wdata->butstate) {
295 wdata->butstate = rw;
296 input_report_key(input, BTN_0, rw & 0x02);
297 input_report_key(input, BTN_1, rw & 0x01);
Przemo Firszt0e253fd2010-01-09 15:20:03 +0100298 input_report_key(input, BTN_TOOL_FINGER, 0xf0);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200299 input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
300 input_sync(input);
301 }
302
Przemo Firszte31e3832012-03-22 18:54:07 +0000303 /* Store current battery capacity and power supply state*/
Przemo Firszt59d23342010-03-15 19:16:23 +0000304 rw = (data[7] >> 2 & 0x07);
Przemo Firszte31e3832012-03-22 18:54:07 +0000305 if (rw != wdata->power_raw) {
306 wdata->power_raw = rw;
307 wdata->battery_capacity = batcap_gr[rw];
308 if (rw == 7)
309 wdata->ps_connected = 1;
310 else
311 wdata->ps_connected = 0;
312 }
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200313 return 1;
314}
Przemo Firszt78761ff2011-11-05 11:28:22 +0000315
Przemo Firszt6245bde2012-02-28 17:19:05 +0000316static void wacom_i4_parse_button_report(struct wacom_data *wdata,
317 struct input_dev *input, unsigned char *data)
318{
319 __u16 new_butstate;
Przemo Firszt7e503a32012-03-14 19:55:04 +0000320 __u8 new_whlstate;
321 __u8 sync = 0;
322
323 new_whlstate = data[1];
324 if (new_whlstate != wdata->whlstate) {
325 wdata->whlstate = new_whlstate;
326 if (new_whlstate & 0x80) {
327 input_report_key(input, BTN_TOUCH, 1);
328 input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
329 input_report_key(input, BTN_TOOL_FINGER, 1);
330 } else {
331 input_report_key(input, BTN_TOUCH, 0);
332 input_report_abs(input, ABS_WHEEL, 0);
333 input_report_key(input, BTN_TOOL_FINGER, 0);
334 }
335 sync = 1;
336 }
Przemo Firszt6245bde2012-02-28 17:19:05 +0000337
338 new_butstate = (data[3] << 1) | (data[2] & 0x01);
339 if (new_butstate != wdata->butstate) {
340 wdata->butstate = new_butstate;
341 input_report_key(input, BTN_0, new_butstate & 0x001);
342 input_report_key(input, BTN_1, new_butstate & 0x002);
343 input_report_key(input, BTN_2, new_butstate & 0x004);
344 input_report_key(input, BTN_3, new_butstate & 0x008);
345 input_report_key(input, BTN_4, new_butstate & 0x010);
346 input_report_key(input, BTN_5, new_butstate & 0x020);
347 input_report_key(input, BTN_6, new_butstate & 0x040);
348 input_report_key(input, BTN_7, new_butstate & 0x080);
349 input_report_key(input, BTN_8, new_butstate & 0x100);
350 input_report_key(input, BTN_TOOL_FINGER, 1);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000351 sync = 1;
352 }
353
354 if (sync) {
Przemo Firszt6245bde2012-02-28 17:19:05 +0000355 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
356 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
357 input_sync(input);
358 }
359}
360
Przemo Firszt78761ff2011-11-05 11:28:22 +0000361static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
362 struct input_dev *input, unsigned char *data)
363{
364 __u16 x, y, pressure;
Przemo Firszte0829e92012-02-28 17:19:04 +0000365 __u8 distance;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000366
367 switch (data[1]) {
368 case 0x80: /* Out of proximity report */
Przemo Firszt78761ff2011-11-05 11:28:22 +0000369 input_report_key(input, BTN_TOUCH, 0);
370 input_report_abs(input, ABS_PRESSURE, 0);
Przemo Firszt693f45b2012-03-09 13:20:51 +0000371 input_report_key(input, BTN_STYLUS, 0);
372 input_report_key(input, BTN_STYLUS2, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000373 input_report_key(input, wdata->tool, 0);
Przemo Firszt24709002012-02-24 13:52:32 +0000374 input_report_abs(input, ABS_MISC, 0);
375 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
Przemo Firszt32db7372012-02-19 20:20:29 +0000376 wdata->tool = 0;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000377 input_sync(input);
378 break;
379 case 0xC2: /* Tool report */
Przemo Firszt24709002012-02-24 13:52:32 +0000380 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
Przemo Firszt78761ff2011-11-05 11:28:22 +0000381 ((data[7] & 0x0f) << 20) |
Przemo Firszt24709002012-02-24 13:52:32 +0000382 ((data[8] & 0xf0) << 12));
383 wdata->serial = ((data[3] & 0x0f) << 28) +
384 (data[4] << 20) + (data[5] << 12) +
385 (data[6] << 4) + (data[7] >> 4);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000386
Przemo Firszt24709002012-02-24 13:52:32 +0000387 switch (wdata->id) {
388 case 0x100802:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000389 wdata->tool = BTN_TOOL_PEN;
390 break;
Przemo Firszt24709002012-02-24 13:52:32 +0000391 case 0x10080A:
Przemo Firszt78761ff2011-11-05 11:28:22 +0000392 wdata->tool = BTN_TOOL_RUBBER;
393 break;
394 }
395 break;
396 default: /* Position/pressure report */
397 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
398 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
399 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
400 | (data[1] & 0x01);
Przemo Firszte0829e92012-02-28 17:19:04 +0000401 distance = (data[9] >> 2) & 0x3f;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000402
403 input_report_key(input, BTN_TOUCH, pressure > 1);
404
405 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
406 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
407 input_report_key(input, wdata->tool, 1);
408 input_report_abs(input, ABS_X, x);
409 input_report_abs(input, ABS_Y, y);
410 input_report_abs(input, ABS_PRESSURE, pressure);
Przemo Firszte0829e92012-02-28 17:19:04 +0000411 input_report_abs(input, ABS_DISTANCE, distance);
Przemo Firszt24709002012-02-24 13:52:32 +0000412 input_report_abs(input, ABS_MISC, wdata->id);
413 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
414 input_report_key(input, wdata->tool, 1);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000415 input_sync(input);
416 break;
417 }
418
419 return;
420}
421
422static void wacom_i4_parse_report(struct hid_device *hdev,
423 struct wacom_data *wdata,
424 struct input_dev *input, unsigned char *data)
425{
426 switch (data[0]) {
427 case 0x00: /* Empty report */
428 break;
429 case 0x02: /* Pen report */
430 wacom_i4_parse_pen_report(wdata, input, data);
431 break;
432 case 0x03: /* Features Report */
433 wdata->features = data[2];
434 break;
435 case 0x0C: /* Button report */
Przemo Firszt6245bde2012-02-28 17:19:05 +0000436 wacom_i4_parse_button_report(wdata, input, data);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000437 break;
438 default:
439 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
440 break;
441 }
442}
443
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000444static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
445 u8 *raw_data, int size)
446{
447 struct wacom_data *wdata = hid_get_drvdata(hdev);
448 struct hid_input *hidinput;
449 struct input_dev *input;
450 unsigned char *data = (unsigned char *) raw_data;
Przemo Firszt78761ff2011-11-05 11:28:22 +0000451 int i;
Przemo Firszt4202f1d2012-03-22 18:54:08 +0000452 __u8 power_raw;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000453
454 if (!(hdev->claimed & HID_CLAIMED_INPUT))
455 return 0;
456
457 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
458 input = hidinput->input;
459
460 /* Check if this is a tablet report */
461 if (data[0] != 0x03)
462 return 0;
463
Przemo Firszt78761ff2011-11-05 11:28:22 +0000464 switch (hdev->product) {
465 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
466 return wacom_gr_parse_report(hdev, wdata, input, data);
467 break;
468 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
469 i = 1;
470
471 switch (data[0]) {
472 case 0x04:
473 wacom_i4_parse_report(hdev, wdata, input, data + i);
474 i += 10;
475 /* fall through */
476 case 0x03:
477 wacom_i4_parse_report(hdev, wdata, input, data + i);
478 i += 10;
479 wacom_i4_parse_report(hdev, wdata, input, data + i);
Przemo Firszt4202f1d2012-03-22 18:54:08 +0000480 power_raw = data[i+10];
481 if (power_raw != wdata->power_raw) {
482 wdata->power_raw = power_raw;
483 wdata->battery_capacity = batcap_i4[power_raw & 0x07];
484 wdata->ps_connected = power_raw & 0x08;
485 }
486
Przemo Firszt78761ff2011-11-05 11:28:22 +0000487 break;
488 default:
489 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
490 data[0], data[1], size);
491 return 0;
492 }
493 }
494 return 1;
Przemo Firsztf6b7efc2011-11-05 11:28:21 +0000495}
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200496
David Herrmann3797ef62011-10-08 23:20:17 +0200497static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
498 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
499 int *max)
500{
501 struct input_dev *input = hi->input;
502
Jiri Kosinaf6f12422011-10-25 09:58:12 +0200503 __set_bit(INPUT_PROP_POINTER, input->propbit);
504
David Herrmann3797ef62011-10-08 23:20:17 +0200505 /* Basics */
506 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
507
508 __set_bit(REL_WHEEL, input->relbit);
509
510 __set_bit(BTN_TOOL_PEN, input->keybit);
511 __set_bit(BTN_TOUCH, input->keybit);
512 __set_bit(BTN_STYLUS, input->keybit);
513 __set_bit(BTN_STYLUS2, input->keybit);
514 __set_bit(BTN_LEFT, input->keybit);
515 __set_bit(BTN_RIGHT, input->keybit);
516 __set_bit(BTN_MIDDLE, input->keybit);
517
518 /* Pad */
Przemo Firszt9a911da2012-03-14 19:55:03 +0000519 input_set_capability(input, EV_MSC, MSC_SERIAL);
David Herrmann3797ef62011-10-08 23:20:17 +0200520
521 __set_bit(BTN_0, input->keybit);
522 __set_bit(BTN_1, input->keybit);
523 __set_bit(BTN_TOOL_FINGER, input->keybit);
524
525 /* Distance, rubber and mouse */
526 __set_bit(BTN_TOOL_RUBBER, input->keybit);
527 __set_bit(BTN_TOOL_MOUSE, input->keybit);
528
Przemo Firszt78761ff2011-11-05 11:28:22 +0000529 switch (hdev->product) {
530 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
531 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
532 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
533 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
534 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
535 break;
536 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszt7e503a32012-03-14 19:55:04 +0000537 __set_bit(ABS_WHEEL, input->absbit);
Przemo Firszt2c653e62012-02-24 13:47:48 +0000538 __set_bit(ABS_MISC, input->absbit);
Przemo Firszt6245bde2012-02-28 17:19:05 +0000539 __set_bit(BTN_2, input->keybit);
540 __set_bit(BTN_3, input->keybit);
541 __set_bit(BTN_4, input->keybit);
542 __set_bit(BTN_5, input->keybit);
543 __set_bit(BTN_6, input->keybit);
544 __set_bit(BTN_7, input->keybit);
545 __set_bit(BTN_8, input->keybit);
Przemo Firszt7e503a32012-03-14 19:55:04 +0000546 input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000547 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
548 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
549 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
Przemo Firszte0829e92012-02-28 17:19:04 +0000550 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
Przemo Firszt78761ff2011-11-05 11:28:22 +0000551 break;
552 }
David Herrmann3797ef62011-10-08 23:20:17 +0200553
554 return 0;
555}
556
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200557static int wacom_probe(struct hid_device *hdev,
558 const struct hid_device_id *id)
559{
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200560 struct wacom_data *wdata;
561 int ret;
562
563 wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
564 if (wdata == NULL) {
Joe Perches4291ee32010-12-09 19:29:03 -0800565 hid_err(hdev, "can't alloc wacom descriptor\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200566 return -ENOMEM;
567 }
568
569 hid_set_drvdata(hdev, wdata);
570
Bastien Nocera46a709b2010-01-20 12:00:53 +0000571 /* Parse the HID report now */
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200572 ret = hid_parse(hdev);
573 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800574 hid_err(hdev, "parse failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200575 goto err_free;
576 }
577
578 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
579 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800580 hid_err(hdev, "hw start failed\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200581 goto err_free;
582 }
583
Przemo Firszt20a3ce7e2010-03-18 14:34:34 +0000584 ret = device_create_file(&hdev->dev, &dev_attr_speed);
585 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800586 hid_warn(hdev,
587 "can't create sysfs speed attribute err: %d\n", ret);
Jiri Kosina342f31e2010-02-03 15:52:31 +0100588
Przemo Firszt78761ff2011-11-05 11:28:22 +0000589 switch (hdev->product) {
590 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
591 /* Set Wacom mode 2 with high reporting speed */
592 wacom_poke(hdev, 1);
593 break;
594 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
Przemo Firszta72c5dd2012-02-17 17:47:10 +0000595 sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
Przemo Firszt78761ff2011-11-05 11:28:22 +0000596 wdata->features = 0;
597 wacom_set_features(hdev);
598 break;
599 }
Bastien Nocera46a709b2010-01-20 12:00:53 +0000600
Przemo Firszt59d23342010-03-15 19:16:23 +0000601 wdata->battery.properties = wacom_battery_props;
602 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
603 wdata->battery.get_property = wacom_battery_get_property;
604 wdata->battery.name = "wacom_battery";
605 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
606 wdata->battery.use_for_apm = 0;
Bastien Nocera46a709b2010-01-20 12:00:53 +0000607
Jeremy Fitzhardinge35b4c012011-12-09 09:35:00 -0800608
Przemo Firszt59d23342010-03-15 19:16:23 +0000609 ret = power_supply_register(&hdev->dev, &wdata->battery);
610 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800611 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
612 ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200613 goto err_battery;
Przemo Firszt59d23342010-03-15 19:16:23 +0000614 }
615
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000616 power_supply_powers(&wdata->battery, &hdev->dev);
617
Przemo Firszt59d23342010-03-15 19:16:23 +0000618 wdata->ac.properties = wacom_ac_props;
619 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
620 wdata->ac.get_property = wacom_ac_get_property;
621 wdata->ac.name = "wacom_ac";
622 wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
623 wdata->ac.use_for_apm = 0;
624
625 ret = power_supply_register(&hdev->dev, &wdata->ac);
626 if (ret) {
Joe Perches4291ee32010-12-09 19:29:03 -0800627 hid_warn(hdev,
628 "can't create ac battery attribute, err: %d\n", ret);
David Herrmanndde58cf2011-09-05 18:45:28 +0200629 goto err_ac;
Przemo Firszt59d23342010-03-15 19:16:23 +0000630 }
Przemo Firsztd7cb3db2012-02-05 22:35:24 +0000631
632 power_supply_powers(&wdata->ac, &hdev->dev);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200633 return 0;
Daniel Mack987a6c02010-08-02 20:15:17 -0700634
David Herrmanndde58cf2011-09-05 18:45:28 +0200635err_ac:
636 power_supply_unregister(&wdata->battery);
637err_battery:
638 device_remove_file(&hdev->dev, &dev_attr_speed);
639 hid_hw_stop(hdev);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200640err_free:
641 kfree(wdata);
642 return ret;
643}
644
645static void wacom_remove(struct hid_device *hdev)
646{
Przemo Firszt59d23342010-03-15 19:16:23 +0000647 struct wacom_data *wdata = hid_get_drvdata(hdev);
David Herrmann90866172011-09-05 18:45:29 +0200648 device_remove_file(&hdev->dev, &dev_attr_speed);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200649 hid_hw_stop(hdev);
Przemo Firszt59d23342010-03-15 19:16:23 +0000650
Przemo Firszt59d23342010-03-15 19:16:23 +0000651 power_supply_unregister(&wdata->battery);
652 power_supply_unregister(&wdata->ac);
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200653 kfree(hid_get_drvdata(hdev));
654}
655
656static const struct hid_device_id wacom_devices[] = {
657 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
Przemo Firszt78761ff2011-11-05 11:28:22 +0000658 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
Jiri Kosinad5e0a062010-07-20 17:48:48 +0200659
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200660 { }
661};
662MODULE_DEVICE_TABLE(hid, wacom_devices);
663
664static struct hid_driver wacom_driver = {
665 .name = "wacom",
666 .id_table = wacom_devices,
667 .probe = wacom_probe,
668 .remove = wacom_remove,
669 .raw_event = wacom_raw_event,
David Herrmann3797ef62011-10-08 23:20:17 +0200670 .input_mapped = wacom_input_mapped,
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200671};
672
Peter Huewea24f423b2009-07-02 19:08:38 +0200673static int __init wacom_init(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200674{
675 int ret;
676
677 ret = hid_register_driver(&wacom_driver);
678 if (ret)
Joe Perches4291ee32010-12-09 19:29:03 -0800679 pr_err("can't register wacom driver\n");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200680 return ret;
681}
682
Peter Huewea24f423b2009-07-02 19:08:38 +0200683static void __exit wacom_exit(void)
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200684{
685 hid_unregister_driver(&wacom_driver);
686}
687
688module_init(wacom_init);
689module_exit(wacom_exit);
Przemo Firszt1fa2f722012-03-28 22:13:37 +0100690MODULE_DESCRIPTION("Driver for Wacom Graphire Bluetooth and Wacom Intuos4 WL");
Bastien Noceraca2dcd42009-05-11 17:18:12 +0200691MODULE_LICENSE("GPL");