aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-wacom.c
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-01-17 16:15:55 -0500
commit8dea78da5cee153b8af9c07a2745f6c55057fe12 (patch)
treea8f4d49d63b1ecc92f2fddceba0655b2472c5bd9 /drivers/hid/hid-wacom.c
parent406089d01562f1e2bf9f089fd7637009ebaad589 (diff)
Patched in Tegra support.
Diffstat (limited to 'drivers/hid/hid-wacom.c')
-rw-r--r--drivers/hid/hid-wacom.c748
1 files changed, 122 insertions, 626 deletions
diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c
index 2f60da9ed06..72ca689b647 100644
--- a/drivers/hid/hid-wacom.c
+++ b/drivers/hid/hid-wacom.c
@@ -5,10 +5,10 @@
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz> 5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc 6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina 7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
8 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com> 9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
9 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru> 10 * Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
10 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net> 11 * Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
11 * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
12 */ 12 */
13 13
14/* 14/*
@@ -23,269 +23,57 @@
23#include <linux/device.h> 23#include <linux/device.h>
24#include <linux/hid.h> 24#include <linux/hid.h>
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/leds.h>
27#include <linux/slab.h> 26#include <linux/slab.h>
27#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
28#include <linux/power_supply.h> 28#include <linux/power_supply.h>
29#endif
29 30
30#include "hid-ids.h" 31#include "hid-ids.h"
31 32
32#define PAD_DEVICE_ID 0x0F
33
34#define WAC_CMD_LED_CONTROL 0x20
35#define WAC_CMD_ICON_START_STOP 0x21
36#define WAC_CMD_ICON_TRANSFER 0x26
37
38struct wacom_data { 33struct wacom_data {
39 __u16 tool; 34 __u16 tool;
40 __u16 butstate; 35 unsigned char butstate;
41 __u8 whlstate;
42 __u8 features;
43 __u32 id;
44 __u32 serial;
45 unsigned char high_speed; 36 unsigned char high_speed;
46 __u8 battery_capacity; 37#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
47 __u8 power_raw; 38 int battery_capacity;
48 __u8 ps_connected;
49 struct power_supply battery; 39 struct power_supply battery;
50 struct power_supply ac; 40 struct power_supply ac;
51 __u8 led_selector; 41#endif
52 struct led_classdev *leds[4];
53}; 42};
54 43
55/*percent of battery capacity for Graphire 44#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
56 8th value means AC online and show 100% capacity */ 45/*percent of battery capacity, 0 means AC online*/
57static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 }; 46static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
58/*percent of battery capacity for Intuos4 WL, AC has a separate bit*/
59static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 };
60 47
61static enum power_supply_property wacom_battery_props[] = { 48static enum power_supply_property wacom_battery_props[] = {
62 POWER_SUPPLY_PROP_PRESENT, 49 POWER_SUPPLY_PROP_PRESENT,
63 POWER_SUPPLY_PROP_CAPACITY, 50 POWER_SUPPLY_PROP_CAPACITY
64 POWER_SUPPLY_PROP_SCOPE,
65}; 51};
66 52
67static enum power_supply_property wacom_ac_props[] = { 53static enum power_supply_property wacom_ac_props[] = {
68 POWER_SUPPLY_PROP_PRESENT, 54 POWER_SUPPLY_PROP_PRESENT,
69 POWER_SUPPLY_PROP_ONLINE, 55 POWER_SUPPLY_PROP_ONLINE
70 POWER_SUPPLY_PROP_SCOPE,
71}; 56};
72 57
73static void wacom_scramble(__u8 *image)
74{
75 __u16 mask;
76 __u16 s1;
77 __u16 s2;
78 __u16 r1 ;
79 __u16 r2 ;
80 __u16 r;
81 __u8 buf[256];
82 int i, w, x, y, z;
83
84 for (x = 0; x < 32; x++) {
85 for (y = 0; y < 8; y++)
86 buf[(8 * x) + (7 - y)] = image[(8 * x) + y];
87 }
88
89 /* Change 76543210 into GECA6420 as required by Intuos4 WL
90 * HGFEDCBA HFDB7531
91 */
92 for (x = 0; x < 4; x++) {
93 for (y = 0; y < 4; y++) {
94 for (z = 0; z < 8; z++) {
95 mask = 0x0001;
96 r1 = 0;
97 r2 = 0;
98 i = (x << 6) + (y << 4) + z;
99 s1 = buf[i];
100 s2 = buf[i+8];
101 for (w = 0; w < 8; w++) {
102 r1 |= (s1 & mask);
103 r2 |= (s2 & mask);
104 s1 <<= 1;
105 s2 <<= 1;
106 mask <<= 2;
107 }
108 r = r1 | (r2 << 1);
109 i = (x << 6) + (y << 4) + (z << 1);
110 image[i] = 0xFF & r;
111 image[i+1] = (0xFF00 & r) >> 8;
112 }
113 }
114 }
115}
116
117static void wacom_set_image(struct hid_device *hdev, const char *image,
118 __u8 icon_no)
119{
120 __u8 rep_data[68];
121 __u8 p[256];
122 int ret, i, j;
123
124 for (i = 0; i < 256; i++)
125 p[i] = image[i];
126
127 rep_data[0] = WAC_CMD_ICON_START_STOP;
128 rep_data[1] = 0;
129 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
130 HID_FEATURE_REPORT);
131 if (ret < 0)
132 goto err;
133
134 rep_data[0] = WAC_CMD_ICON_TRANSFER;
135 rep_data[1] = icon_no & 0x07;
136
137 wacom_scramble(p);
138
139 for (i = 0; i < 4; i++) {
140 for (j = 0; j < 64; j++)
141 rep_data[j + 3] = p[(i << 6) + j];
142
143 rep_data[2] = i;
144 ret = hdev->hid_output_raw_report(hdev, rep_data, 67,
145 HID_FEATURE_REPORT);
146 }
147
148 rep_data[0] = WAC_CMD_ICON_START_STOP;
149 rep_data[1] = 0;
150
151 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
152 HID_FEATURE_REPORT);
153
154err:
155 return;
156}
157
158static void wacom_leds_set_brightness(struct led_classdev *led_dev,
159 enum led_brightness value)
160{
161 struct device *dev = led_dev->dev->parent;
162 struct hid_device *hdev;
163 struct wacom_data *wdata;
164 unsigned char *buf;
165 __u8 led = 0;
166 int i;
167
168 hdev = container_of(dev, struct hid_device, dev);
169 wdata = hid_get_drvdata(hdev);
170 for (i = 0; i < 4; ++i) {
171 if (wdata->leds[i] == led_dev)
172 wdata->led_selector = i;
173 }
174
175 led = wdata->led_selector | 0x04;
176 buf = kzalloc(9, GFP_KERNEL);
177 if (buf) {
178 buf[0] = WAC_CMD_LED_CONTROL;
179 buf[1] = led;
180 buf[2] = value >> 2;
181 buf[3] = value;
182 /* use fixed brightness for OLEDs */
183 buf[4] = 0x08;
184 hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT);
185 kfree(buf);
186 }
187
188 return;
189}
190
191static enum led_brightness wacom_leds_get_brightness(struct led_classdev *led_dev)
192{
193 struct wacom_data *wdata;
194 struct device *dev = led_dev->dev->parent;
195 int value = 0;
196 int i;
197
198 wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev));
199
200 for (i = 0; i < 4; ++i) {
201 if (wdata->leds[i] == led_dev) {
202 value = wdata->leds[i]->brightness;
203 break;
204 }
205 }
206
207 return value;
208}
209
210
211static int wacom_initialize_leds(struct hid_device *hdev)
212{
213 struct wacom_data *wdata = hid_get_drvdata(hdev);
214 struct led_classdev *led;
215 struct device *dev = &hdev->dev;
216 size_t namesz = strlen(dev_name(dev)) + 12;
217 char *name;
218 int i, ret;
219
220 wdata->led_selector = 0;
221
222 for (i = 0; i < 4; i++) {
223 led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL);
224 if (!led) {
225 hid_warn(hdev,
226 "can't allocate memory for LED selector\n");
227 ret = -ENOMEM;
228 goto err;
229 }
230
231 name = (void *)&led[1];
232 snprintf(name, namesz, "%s:selector:%d", dev_name(dev), i);
233 led->name = name;
234 led->brightness = 0;
235 led->max_brightness = 127;
236 led->brightness_get = wacom_leds_get_brightness;
237 led->brightness_set = wacom_leds_set_brightness;
238
239 wdata->leds[i] = led;
240
241 ret = led_classdev_register(dev, wdata->leds[i]);
242
243 if (ret) {
244 wdata->leds[i] = NULL;
245 kfree(led);
246 hid_warn(hdev, "can't register LED\n");
247 goto err;
248 }
249 }
250
251err:
252 return ret;
253}
254
255static void wacom_destroy_leds(struct hid_device *hdev)
256{
257 struct wacom_data *wdata = hid_get_drvdata(hdev);
258 struct led_classdev *led;
259 int i;
260
261 for (i = 0; i < 4; ++i) {
262 if (wdata->leds[i]) {
263 led = wdata->leds[i];
264 wdata->leds[i] = NULL;
265 led_classdev_unregister(led);
266 kfree(led);
267 }
268 }
269
270}
271
272static int wacom_battery_get_property(struct power_supply *psy, 58static int wacom_battery_get_property(struct power_supply *psy,
273 enum power_supply_property psp, 59 enum power_supply_property psp,
274 union power_supply_propval *val) 60 union power_supply_propval *val)
275{ 61{
276 struct wacom_data *wdata = container_of(psy, 62 struct wacom_data *wdata = container_of(psy,
277 struct wacom_data, battery); 63 struct wacom_data, battery);
64 int power_state = batcap[wdata->battery_capacity];
278 int ret = 0; 65 int ret = 0;
279 66
280 switch (psp) { 67 switch (psp) {
281 case POWER_SUPPLY_PROP_PRESENT: 68 case POWER_SUPPLY_PROP_PRESENT:
282 val->intval = 1; 69 val->intval = 1;
283 break; 70 break;
284 case POWER_SUPPLY_PROP_SCOPE:
285 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
286 break;
287 case POWER_SUPPLY_PROP_CAPACITY: 71 case POWER_SUPPLY_PROP_CAPACITY:
288 val->intval = wdata->battery_capacity; 72 /* show 100% battery capacity when charging */
73 if (power_state == 0)
74 val->intval = 100;
75 else
76 val->intval = power_state;
289 break; 77 break;
290 default: 78 default:
291 ret = -EINVAL; 79 ret = -EINVAL;
@@ -299,16 +87,17 @@ static int wacom_ac_get_property(struct power_supply *psy,
299 union power_supply_propval *val) 87 union power_supply_propval *val)
300{ 88{
301 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); 89 struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
90 int power_state = batcap[wdata->battery_capacity];
302 int ret = 0; 91 int ret = 0;
303 92
304 switch (psp) { 93 switch (psp) {
305 case POWER_SUPPLY_PROP_PRESENT: 94 case POWER_SUPPLY_PROP_PRESENT:
306 /* fall through */ 95 /* fall through */
307 case POWER_SUPPLY_PROP_ONLINE: 96 case POWER_SUPPLY_PROP_ONLINE:
308 val->intval = wdata->ps_connected; 97 if (power_state == 0)
309 break; 98 val->intval = 1;
310 case POWER_SUPPLY_PROP_SCOPE: 99 else
311 val->intval = POWER_SUPPLY_SCOPE_DEVICE; 100 val->intval = 0;
312 break; 101 break;
313 default: 102 default:
314 ret = -EINVAL; 103 ret = -EINVAL;
@@ -316,16 +105,28 @@ static int wacom_ac_get_property(struct power_supply *psy,
316 } 105 }
317 return ret; 106 return ret;
318} 107}
108#endif
319 109
320static void wacom_set_features(struct hid_device *hdev, u8 speed) 110static void wacom_poke(struct hid_device *hdev, u8 speed)
321{ 111{
322 struct wacom_data *wdata = hid_get_drvdata(hdev); 112 struct wacom_data *wdata = hid_get_drvdata(hdev);
323 int limit, ret; 113 int limit, ret;
324 __u8 rep_data[2]; 114 char rep_data[2];
115
116 rep_data[0] = 0x03 ; rep_data[1] = 0x00;
117 limit = 3;
118 do {
119 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
120 HID_FEATURE_REPORT);
121 } while (ret < 0 && limit-- > 0);
325 122
326 switch (hdev->product) { 123 if (ret >= 0) {
327 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: 124 if (speed == 0)
328 rep_data[0] = 0x03 ; rep_data[1] = 0x00; 125 rep_data[0] = 0x05;
126 else
127 rep_data[0] = 0x06;
128
129 rep_data[1] = 0x00;
329 limit = 3; 130 limit = 3;
330 do { 131 do {
331 ret = hdev->hid_output_raw_report(hdev, rep_data, 2, 132 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
@@ -333,47 +134,17 @@ static void wacom_set_features(struct hid_device *hdev, u8 speed)
333 } while (ret < 0 && limit-- > 0); 134 } while (ret < 0 && limit-- > 0);
334 135
335 if (ret >= 0) { 136 if (ret >= 0) {
336 if (speed == 0)
337 rep_data[0] = 0x05;
338 else
339 rep_data[0] = 0x06;
340
341 rep_data[1] = 0x00;
342 limit = 3;
343 do {
344 ret = hdev->hid_output_raw_report(hdev,
345 rep_data, 2, HID_FEATURE_REPORT);
346 } while (ret < 0 && limit-- > 0);
347
348 if (ret >= 0) {
349 wdata->high_speed = speed;
350 return;
351 }
352 }
353
354 /*
355 * Note that if the raw queries fail, it's not a hard failure
356 * and it is safe to continue
357 */
358 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
359 rep_data[0], ret);
360 break;
361 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
362 if (speed == 1)
363 wdata->features &= ~0x20;
364 else
365 wdata->features |= 0x20;
366
367 rep_data[0] = 0x03;
368 rep_data[1] = wdata->features;
369
370 ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
371 HID_FEATURE_REPORT);
372 if (ret >= 0)
373 wdata->high_speed = speed; 137 wdata->high_speed = speed;
374 break; 138 return;
139 }
375 } 140 }
376 141
142 /*
143 * Note that if the raw queries fail, it's not a hard failure and it
144 * is safe to continue
145 */
146 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
147 rep_data[0], ret);
377 return; 148 return;
378} 149}
379 150
@@ -397,7 +168,7 @@ static ssize_t wacom_store_speed(struct device *dev,
397 return -EINVAL; 168 return -EINVAL;
398 169
399 if (new_speed == 0 || new_speed == 1) { 170 if (new_speed == 0 || new_speed == 1) {
400 wacom_set_features(hdev, new_speed); 171 wacom_poke(hdev, new_speed);
401 return strnlen(buf, PAGE_SIZE); 172 return strnlen(buf, PAGE_SIZE);
402 } else 173 } else
403 return -EINVAL; 174 return -EINVAL;
@@ -406,41 +177,26 @@ static ssize_t wacom_store_speed(struct device *dev,
406static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, 177static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
407 wacom_show_speed, wacom_store_speed); 178 wacom_show_speed, wacom_store_speed);
408 179
409#define WACOM_STORE(OLED_ID) \ 180static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
410static ssize_t wacom_oled##OLED_ID##_store(struct device *dev, \ 181 u8 *raw_data, int size)
411 struct device_attribute *attr, \
412 const char *buf, size_t count) \
413{ \
414 struct hid_device *hdev = container_of(dev, struct hid_device, \
415 dev); \
416 \
417 if (count != 256) \
418 return -EINVAL; \
419 \
420 wacom_set_image(hdev, buf, OLED_ID); \
421 \
422 return count; \
423} \
424 \
425static DEVICE_ATTR(oled##OLED_ID##_img, S_IWUSR | S_IWGRP, NULL, \
426 wacom_oled##OLED_ID##_store)
427
428WACOM_STORE(0);
429WACOM_STORE(1);
430WACOM_STORE(2);
431WACOM_STORE(3);
432WACOM_STORE(4);
433WACOM_STORE(5);
434WACOM_STORE(6);
435WACOM_STORE(7);
436
437static int wacom_gr_parse_report(struct hid_device *hdev,
438 struct wacom_data *wdata,
439 struct input_dev *input, unsigned char *data)
440{ 182{
183 struct wacom_data *wdata = hid_get_drvdata(hdev);
184 struct hid_input *hidinput;
185 struct input_dev *input;
186 unsigned char *data = (unsigned char *) raw_data;
441 int tool, x, y, rw; 187 int tool, x, y, rw;
442 188
189 if (!(hdev->claimed & HID_CLAIMED_INPUT))
190 return 0;
191
443 tool = 0; 192 tool = 0;
193 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
194 input = hidinput->input;
195
196 /* Check if this is a tablet report */
197 if (data[0] != 0x03)
198 return 0;
199
444 /* Get X & Y positions */ 200 /* Get X & Y positions */
445 x = le16_to_cpu(*(__le16 *) &data[2]); 201 x = le16_to_cpu(*(__le16 *) &data[2]);
446 y = le16_to_cpu(*(__le16 *) &data[4]); 202 y = le16_to_cpu(*(__le16 *) &data[4]);
@@ -539,272 +295,20 @@ static int wacom_gr_parse_report(struct hid_device *hdev,
539 input_sync(input); 295 input_sync(input);
540 } 296 }
541 297
542 /* Store current battery capacity and power supply state*/ 298#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
299 /* Store current battery capacity */
543 rw = (data[7] >> 2 & 0x07); 300 rw = (data[7] >> 2 & 0x07);
544 if (rw != wdata->power_raw) { 301 if (rw != wdata->battery_capacity)
545 wdata->power_raw = rw; 302 wdata->battery_capacity = rw;
546 wdata->battery_capacity = batcap_gr[rw]; 303#endif
547 if (rw == 7)
548 wdata->ps_connected = 1;
549 else
550 wdata->ps_connected = 0;
551 }
552 return 1; 304 return 1;
553} 305}
554 306
555static void wacom_i4_parse_button_report(struct wacom_data *wdata,
556 struct input_dev *input, unsigned char *data)
557{
558 __u16 new_butstate;
559 __u8 new_whlstate;
560 __u8 sync = 0;
561
562 new_whlstate = data[1];
563 if (new_whlstate != wdata->whlstate) {
564 wdata->whlstate = new_whlstate;
565 if (new_whlstate & 0x80) {
566 input_report_key(input, BTN_TOUCH, 1);
567 input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f));
568 input_report_key(input, BTN_TOOL_FINGER, 1);
569 } else {
570 input_report_key(input, BTN_TOUCH, 0);
571 input_report_abs(input, ABS_WHEEL, 0);
572 input_report_key(input, BTN_TOOL_FINGER, 0);
573 }
574 sync = 1;
575 }
576
577 new_butstate = (data[3] << 1) | (data[2] & 0x01);
578 if (new_butstate != wdata->butstate) {
579 wdata->butstate = new_butstate;
580 input_report_key(input, BTN_0, new_butstate & 0x001);
581 input_report_key(input, BTN_1, new_butstate & 0x002);
582 input_report_key(input, BTN_2, new_butstate & 0x004);
583 input_report_key(input, BTN_3, new_butstate & 0x008);
584 input_report_key(input, BTN_4, new_butstate & 0x010);
585 input_report_key(input, BTN_5, new_butstate & 0x020);
586 input_report_key(input, BTN_6, new_butstate & 0x040);
587 input_report_key(input, BTN_7, new_butstate & 0x080);
588 input_report_key(input, BTN_8, new_butstate & 0x100);
589 input_report_key(input, BTN_TOOL_FINGER, 1);
590 sync = 1;
591 }
592
593 if (sync) {
594 input_report_abs(input, ABS_MISC, PAD_DEVICE_ID);
595 input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff);
596 input_sync(input);
597 }
598}
599
600static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
601 struct input_dev *input, unsigned char *data)
602{
603 __u16 x, y, pressure;
604 __u8 distance;
605 __u8 tilt_x, tilt_y;
606
607 switch (data[1]) {
608 case 0x80: /* Out of proximity report */
609 input_report_key(input, BTN_TOUCH, 0);
610 input_report_abs(input, ABS_PRESSURE, 0);
611 input_report_key(input, BTN_STYLUS, 0);
612 input_report_key(input, BTN_STYLUS2, 0);
613 input_report_key(input, wdata->tool, 0);
614 input_report_abs(input, ABS_MISC, 0);
615 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
616 wdata->tool = 0;
617 input_sync(input);
618 break;
619 case 0xC2: /* Tool report */
620 wdata->id = ((data[2] << 4) | (data[3] >> 4) |
621 ((data[7] & 0x0f) << 20) |
622 ((data[8] & 0xf0) << 12));
623 wdata->serial = ((data[3] & 0x0f) << 28) +
624 (data[4] << 20) + (data[5] << 12) +
625 (data[6] << 4) + (data[7] >> 4);
626
627 switch (wdata->id) {
628 case 0x100802:
629 wdata->tool = BTN_TOOL_PEN;
630 break;
631 case 0x10080A:
632 wdata->tool = BTN_TOOL_RUBBER;
633 break;
634 }
635 break;
636 default: /* Position/pressure report */
637 x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
638 y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
639 pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
640 | (data[1] & 0x01);
641 distance = (data[9] >> 2) & 0x3f;
642 tilt_x = ((data[7] << 1) & 0x7e) | (data[8] >> 7);
643 tilt_y = data[8] & 0x7f;
644
645 input_report_key(input, BTN_TOUCH, pressure > 1);
646
647 input_report_key(input, BTN_STYLUS, data[1] & 0x02);
648 input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
649 input_report_key(input, wdata->tool, 1);
650 input_report_abs(input, ABS_X, x);
651 input_report_abs(input, ABS_Y, y);
652 input_report_abs(input, ABS_PRESSURE, pressure);
653 input_report_abs(input, ABS_DISTANCE, distance);
654 input_report_abs(input, ABS_TILT_X, tilt_x);
655 input_report_abs(input, ABS_TILT_Y, tilt_y);
656 input_report_abs(input, ABS_MISC, wdata->id);
657 input_event(input, EV_MSC, MSC_SERIAL, wdata->serial);
658 input_report_key(input, wdata->tool, 1);
659 input_sync(input);
660 break;
661 }
662
663 return;
664}
665
666static void wacom_i4_parse_report(struct hid_device *hdev,
667 struct wacom_data *wdata,
668 struct input_dev *input, unsigned char *data)
669{
670 switch (data[0]) {
671 case 0x00: /* Empty report */
672 break;
673 case 0x02: /* Pen report */
674 wacom_i4_parse_pen_report(wdata, input, data);
675 break;
676 case 0x03: /* Features Report */
677 wdata->features = data[2];
678 break;
679 case 0x0C: /* Button report */
680 wacom_i4_parse_button_report(wdata, input, data);
681 break;
682 default:
683 hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]);
684 break;
685 }
686}
687
688static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
689 u8 *raw_data, int size)
690{
691 struct wacom_data *wdata = hid_get_drvdata(hdev);
692 struct hid_input *hidinput;
693 struct input_dev *input;
694 unsigned char *data = (unsigned char *) raw_data;
695 int i;
696 __u8 power_raw;
697
698 if (!(hdev->claimed & HID_CLAIMED_INPUT))
699 return 0;
700
701 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
702 input = hidinput->input;
703
704 switch (hdev->product) {
705 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
706 if (data[0] == 0x03) {
707 return wacom_gr_parse_report(hdev, wdata, input, data);
708 } else {
709 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
710 data[0], data[1], size);
711 return 0;
712 }
713 break;
714 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
715 i = 1;
716
717 switch (data[0]) {
718 case 0x04:
719 wacom_i4_parse_report(hdev, wdata, input, data + i);
720 i += 10;
721 /* fall through */
722 case 0x03:
723 wacom_i4_parse_report(hdev, wdata, input, data + i);
724 i += 10;
725 wacom_i4_parse_report(hdev, wdata, input, data + i);
726 power_raw = data[i+10];
727 if (power_raw != wdata->power_raw) {
728 wdata->power_raw = power_raw;
729 wdata->battery_capacity = batcap_i4[power_raw & 0x07];
730 wdata->ps_connected = power_raw & 0x08;
731 }
732
733 break;
734 default:
735 hid_err(hdev, "Unknown report: %d,%d size:%d\n",
736 data[0], data[1], size);
737 return 0;
738 }
739 }
740 return 1;
741}
742
743static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
744 struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
745 int *max)
746{
747 struct input_dev *input = hi->input;
748
749 __set_bit(INPUT_PROP_POINTER, input->propbit);
750
751 /* Basics */
752 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
753
754 __set_bit(REL_WHEEL, input->relbit);
755
756 __set_bit(BTN_TOOL_PEN, input->keybit);
757 __set_bit(BTN_TOUCH, input->keybit);
758 __set_bit(BTN_STYLUS, input->keybit);
759 __set_bit(BTN_STYLUS2, input->keybit);
760 __set_bit(BTN_LEFT, input->keybit);
761 __set_bit(BTN_RIGHT, input->keybit);
762 __set_bit(BTN_MIDDLE, input->keybit);
763
764 /* Pad */
765 input_set_capability(input, EV_MSC, MSC_SERIAL);
766
767 __set_bit(BTN_0, input->keybit);
768 __set_bit(BTN_1, input->keybit);
769 __set_bit(BTN_TOOL_FINGER, input->keybit);
770
771 /* Distance, rubber and mouse */
772 __set_bit(BTN_TOOL_RUBBER, input->keybit);
773 __set_bit(BTN_TOOL_MOUSE, input->keybit);
774
775 switch (hdev->product) {
776 case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
777 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
778 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
779 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
780 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
781 break;
782 case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
783 __set_bit(ABS_WHEEL, input->absbit);
784 __set_bit(ABS_MISC, input->absbit);
785 __set_bit(BTN_2, input->keybit);
786 __set_bit(BTN_3, input->keybit);
787 __set_bit(BTN_4, input->keybit);
788 __set_bit(BTN_5, input->keybit);
789 __set_bit(BTN_6, input->keybit);
790 __set_bit(BTN_7, input->keybit);
791 __set_bit(BTN_8, input->keybit);
792 input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0);
793 input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
794 input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
795 input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
796 input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0);
797 input_set_abs_params(input, ABS_TILT_X, 0, 127, 0, 0);
798 input_set_abs_params(input, ABS_TILT_Y, 0, 127, 0, 0);
799 break;
800 }
801
802 return 0;
803}
804
805static int wacom_probe(struct hid_device *hdev, 307static int wacom_probe(struct hid_device *hdev,
806 const struct hid_device_id *id) 308 const struct hid_device_id *id)
807{ 309{
310 struct hid_input *hidinput;
311 struct input_dev *input;
808 struct wacom_data *wdata; 312 struct wacom_data *wdata;
809 int ret; 313 int ret;
810 314
@@ -834,35 +338,10 @@ static int wacom_probe(struct hid_device *hdev,
834 hid_warn(hdev, 338 hid_warn(hdev,
835 "can't create sysfs speed attribute err: %d\n", ret); 339 "can't create sysfs speed attribute err: %d\n", ret);
836 340
837#define OLED_INIT(OLED_ID) \ 341 /* Set Wacom mode 2 with high reporting speed */
838 do { \ 342 wacom_poke(hdev, 1);
839 ret = device_create_file(&hdev->dev, \
840 &dev_attr_oled##OLED_ID##_img); \
841 if (ret) \
842 hid_warn(hdev, \
843 "can't create sysfs oled attribute, err: %d\n", ret);\
844 } while (0)
845
846OLED_INIT(0);
847OLED_INIT(1);
848OLED_INIT(2);
849OLED_INIT(3);
850OLED_INIT(4);
851OLED_INIT(5);
852OLED_INIT(6);
853OLED_INIT(7);
854
855 wdata->features = 0;
856 wacom_set_features(hdev, 1);
857
858 if (hdev->product == USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) {
859 sprintf(hdev->name, "%s", "Wacom Intuos4 WL");
860 ret = wacom_initialize_leds(hdev);
861 if (ret)
862 hid_warn(hdev,
863 "can't create led attribute, err: %d\n", ret);
864 }
865 343
344#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
866 wdata->battery.properties = wacom_battery_props; 345 wdata->battery.properties = wacom_battery_props;
867 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); 346 wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
868 wdata->battery.get_property = wacom_battery_get_property; 347 wdata->battery.get_property = wacom_battery_get_property;
@@ -870,16 +349,13 @@ OLED_INIT(7);
870 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; 349 wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
871 wdata->battery.use_for_apm = 0; 350 wdata->battery.use_for_apm = 0;
872 351
873
874 ret = power_supply_register(&hdev->dev, &wdata->battery); 352 ret = power_supply_register(&hdev->dev, &wdata->battery);
875 if (ret) { 353 if (ret) {
876 hid_err(hdev, "can't create sysfs battery attribute, err: %d\n", 354 hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n",
877 ret); 355 ret);
878 goto err_battery; 356 goto err_battery;
879 } 357 }
880 358
881 power_supply_powers(&wdata->battery, &hdev->dev);
882
883 wdata->ac.properties = wacom_ac_props; 359 wdata->ac.properties = wacom_ac_props;
884 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); 360 wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
885 wdata->ac.get_property = wacom_ac_get_property; 361 wdata->ac.get_property = wacom_ac_get_property;
@@ -889,28 +365,56 @@ OLED_INIT(7);
889 365
890 ret = power_supply_register(&hdev->dev, &wdata->ac); 366 ret = power_supply_register(&hdev->dev, &wdata->ac);
891 if (ret) { 367 if (ret) {
892 hid_err(hdev, 368 hid_warn(hdev,
893 "can't create ac battery attribute, err: %d\n", ret); 369 "can't create ac battery attribute, err: %d\n", ret);
894 goto err_ac; 370 goto err_ac;
895 } 371 }
372#endif
373 hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
374 input = hidinput->input;
375
376 __set_bit(INPUT_PROP_POINTER, input->propbit);
377
378 /* Basics */
379 input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
380
381 __set_bit(REL_WHEEL, input->relbit);
382
383 __set_bit(BTN_TOOL_PEN, input->keybit);
384 __set_bit(BTN_TOUCH, input->keybit);
385 __set_bit(BTN_STYLUS, input->keybit);
386 __set_bit(BTN_STYLUS2, input->keybit);
387 __set_bit(BTN_LEFT, input->keybit);
388 __set_bit(BTN_RIGHT, input->keybit);
389 __set_bit(BTN_MIDDLE, input->keybit);
390
391 /* Pad */
392 input->evbit[0] |= BIT(EV_MSC);
393
394 __set_bit(MSC_SERIAL, input->mscbit);
395
396 __set_bit(BTN_0, input->keybit);
397 __set_bit(BTN_1, input->keybit);
398 __set_bit(BTN_TOOL_FINGER, input->keybit);
399
400 /* Distance, rubber and mouse */
401 __set_bit(BTN_TOOL_RUBBER, input->keybit);
402 __set_bit(BTN_TOOL_MOUSE, input->keybit);
403
404 input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
405 input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
406 input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
407 input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
896 408
897 power_supply_powers(&wdata->ac, &hdev->dev);
898 return 0; 409 return 0;
899 410
411#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
900err_ac: 412err_ac:
901 power_supply_unregister(&wdata->battery); 413 power_supply_unregister(&wdata->battery);
902err_battery: 414err_battery:
903 wacom_destroy_leds(hdev);
904 device_remove_file(&hdev->dev, &dev_attr_oled0_img);
905 device_remove_file(&hdev->dev, &dev_attr_oled1_img);
906 device_remove_file(&hdev->dev, &dev_attr_oled2_img);
907 device_remove_file(&hdev->dev, &dev_attr_oled3_img);
908 device_remove_file(&hdev->dev, &dev_attr_oled4_img);
909 device_remove_file(&hdev->dev, &dev_attr_oled5_img);
910 device_remove_file(&hdev->dev, &dev_attr_oled6_img);
911 device_remove_file(&hdev->dev, &dev_attr_oled7_img);
912 device_remove_file(&hdev->dev, &dev_attr_speed); 415 device_remove_file(&hdev->dev, &dev_attr_speed);
913 hid_hw_stop(hdev); 416 hid_hw_stop(hdev);
417#endif
914err_free: 418err_free:
915 kfree(wdata); 419 kfree(wdata);
916 return ret; 420 return ret;
@@ -918,28 +422,21 @@ err_free:
918 422
919static void wacom_remove(struct hid_device *hdev) 423static void wacom_remove(struct hid_device *hdev)
920{ 424{
425#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
921 struct wacom_data *wdata = hid_get_drvdata(hdev); 426 struct wacom_data *wdata = hid_get_drvdata(hdev);
922 427#endif
923 wacom_destroy_leds(hdev);
924 device_remove_file(&hdev->dev, &dev_attr_oled0_img);
925 device_remove_file(&hdev->dev, &dev_attr_oled1_img);
926 device_remove_file(&hdev->dev, &dev_attr_oled2_img);
927 device_remove_file(&hdev->dev, &dev_attr_oled3_img);
928 device_remove_file(&hdev->dev, &dev_attr_oled4_img);
929 device_remove_file(&hdev->dev, &dev_attr_oled5_img);
930 device_remove_file(&hdev->dev, &dev_attr_oled6_img);
931 device_remove_file(&hdev->dev, &dev_attr_oled7_img);
932 device_remove_file(&hdev->dev, &dev_attr_speed); 428 device_remove_file(&hdev->dev, &dev_attr_speed);
933 hid_hw_stop(hdev); 429 hid_hw_stop(hdev);
934 430
431#ifdef CONFIG_HID_WACOM_POWER_SUPPLY
935 power_supply_unregister(&wdata->battery); 432 power_supply_unregister(&wdata->battery);
936 power_supply_unregister(&wdata->ac); 433 power_supply_unregister(&wdata->ac);
434#endif
937 kfree(hid_get_drvdata(hdev)); 435 kfree(hid_get_drvdata(hdev));
938} 436}
939 437
940static const struct hid_device_id wacom_devices[] = { 438static const struct hid_device_id wacom_devices[] = {
941 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, 439 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
942 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
943 440
944 { } 441 { }
945}; 442};
@@ -951,7 +448,6 @@ static struct hid_driver wacom_driver = {
951 .probe = wacom_probe, 448 .probe = wacom_probe,
952 .remove = wacom_remove, 449 .remove = wacom_remove,
953 .raw_event = wacom_raw_event, 450 .raw_event = wacom_raw_event,
954 .input_mapped = wacom_input_mapped,
955}; 451};
956 452
957static int __init wacom_init(void) 453static int __init wacom_init(void)
@@ -971,5 +467,5 @@ static void __exit wacom_exit(void)
971 467
972module_init(wacom_init); 468module_init(wacom_init);
973module_exit(wacom_exit); 469module_exit(wacom_exit);
974MODULE_DESCRIPTION("Driver for Wacom Graphire Bluetooth and Wacom Intuos4 WL");
975MODULE_LICENSE("GPL"); 470MODULE_LICENSE("GPL");
471