Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 1 | /* |
| 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 Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 12 | * Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu> |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 13 | */ |
| 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 Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 24 | #include <linux/device.h> |
| 25 | #include <linux/hid.h> |
| 26 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 28 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 29 | #include <linux/power_supply.h> |
| 30 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 31 | |
| 32 | #include "hid-ids.h" |
| 33 | |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 34 | #define PAD_DEVICE_ID 0x0F |
| 35 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 36 | struct wacom_data { |
| 37 | __u16 tool; |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 38 | __u16 butstate; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 39 | __u8 features; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 40 | __u32 id; |
| 41 | __u32 serial; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 42 | unsigned char high_speed; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 43 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 44 | int battery_capacity; |
| 45 | struct power_supply battery; |
| 46 | struct power_supply ac; |
| 47 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 48 | }; |
| 49 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 50 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 51 | /*percent of battery capacity, 0 means AC online*/ |
| 52 | static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; |
| 53 | |
| 54 | static enum power_supply_property wacom_battery_props[] = { |
| 55 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 56 | POWER_SUPPLY_PROP_CAPACITY, |
| 57 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static enum power_supply_property wacom_ac_props[] = { |
| 61 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 62 | POWER_SUPPLY_PROP_ONLINE, |
| 63 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static 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 Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 79 | case POWER_SUPPLY_PROP_SCOPE: |
| 80 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 81 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 82 | 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 | |
| 96 | static 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 Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 113 | case POWER_SUPPLY_PROP_SCOPE: |
| 114 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 115 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 116 | default: |
| 117 | ret = -EINVAL; |
| 118 | break; |
| 119 | } |
| 120 | return ret; |
| 121 | } |
| 122 | #endif |
| 123 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 124 | static 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 Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 137 | static void wacom_poke(struct hid_device *hdev, u8 speed) |
| 138 | { |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 139 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 140 | 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 Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 163 | if (ret >= 0) { |
| 164 | wdata->high_speed = speed; |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 165 | return; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 166 | } |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 167 | } |
| 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 Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 173 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 174 | rep_data[0], ret); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 175 | return; |
| 176 | } |
| 177 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 178 | static 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 | |
| 187 | static 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 Kosina | edd2126 | 2010-11-18 16:28:43 +0100 | [diff] [blame] | 204 | static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 205 | wacom_show_speed, wacom_store_speed); |
| 206 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 207 | static int wacom_gr_parse_report(struct hid_device *hdev, |
| 208 | struct wacom_data *wdata, |
| 209 | struct input_dev *input, unsigned char *data) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 210 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 211 | int tool, x, y, rw; |
| 212 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 213 | tool = 0; |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 214 | /* 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 Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 249 | input_abs_get_max(input, ABS_DISTANCE)); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 250 | } 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 Firszt | 0e253fd | 2010-01-09 15:20:03 +0100 | [diff] [blame] | 307 | input_report_key(input, BTN_TOOL_FINGER, 0xf0); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 308 | input_event(input, EV_MSC, MSC_SERIAL, 0xf0); |
| 309 | input_sync(input); |
| 310 | } |
| 311 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 312 | #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 Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 318 | return 1; |
| 319 | } |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 320 | |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 321 | static 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 Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 345 | static 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 Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 349 | __u8 distance; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 350 | |
| 351 | switch (data[1]) { |
| 352 | case 0x80: /* Out of proximity report */ |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 353 | input_report_key(input, BTN_TOUCH, 0); |
| 354 | input_report_abs(input, ABS_PRESSURE, 0); |
Przemo Firszt | 693f45b | 2012-03-09 13:20:51 +0000 | [diff] [blame^] | 355 | input_report_key(input, BTN_STYLUS, 0); |
| 356 | input_report_key(input, BTN_STYLUS2, 0); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 357 | input_report_key(input, wdata->tool, 0); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 358 | input_report_abs(input, ABS_MISC, 0); |
| 359 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
Przemo Firszt | 32db737 | 2012-02-19 20:20:29 +0000 | [diff] [blame] | 360 | wdata->tool = 0; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 361 | input_sync(input); |
| 362 | break; |
| 363 | case 0xC2: /* Tool report */ |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 364 | wdata->id = ((data[2] << 4) | (data[3] >> 4) | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 365 | ((data[7] & 0x0f) << 20) | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 366 | ((data[8] & 0xf0) << 12)); |
| 367 | wdata->serial = ((data[3] & 0x0f) << 28) + |
| 368 | (data[4] << 20) + (data[5] << 12) + |
| 369 | (data[6] << 4) + (data[7] >> 4); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 370 | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 371 | switch (wdata->id) { |
| 372 | case 0x100802: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 373 | wdata->tool = BTN_TOOL_PEN; |
| 374 | break; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 375 | case 0x10080A: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 376 | wdata->tool = BTN_TOOL_RUBBER; |
| 377 | break; |
| 378 | } |
| 379 | break; |
| 380 | default: /* Position/pressure report */ |
| 381 | x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1); |
| 382 | y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01); |
| 383 | pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) |
| 384 | | (data[1] & 0x01); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 385 | distance = (data[9] >> 2) & 0x3f; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 386 | |
| 387 | input_report_key(input, BTN_TOUCH, pressure > 1); |
| 388 | |
| 389 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 390 | input_report_key(input, BTN_STYLUS2, data[1] & 0x04); |
| 391 | input_report_key(input, wdata->tool, 1); |
| 392 | input_report_abs(input, ABS_X, x); |
| 393 | input_report_abs(input, ABS_Y, y); |
| 394 | input_report_abs(input, ABS_PRESSURE, pressure); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 395 | input_report_abs(input, ABS_DISTANCE, distance); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 396 | input_report_abs(input, ABS_MISC, wdata->id); |
| 397 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
| 398 | input_report_key(input, wdata->tool, 1); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 399 | input_sync(input); |
| 400 | break; |
| 401 | } |
| 402 | |
| 403 | return; |
| 404 | } |
| 405 | |
| 406 | static void wacom_i4_parse_report(struct hid_device *hdev, |
| 407 | struct wacom_data *wdata, |
| 408 | struct input_dev *input, unsigned char *data) |
| 409 | { |
| 410 | switch (data[0]) { |
| 411 | case 0x00: /* Empty report */ |
| 412 | break; |
| 413 | case 0x02: /* Pen report */ |
| 414 | wacom_i4_parse_pen_report(wdata, input, data); |
| 415 | break; |
| 416 | case 0x03: /* Features Report */ |
| 417 | wdata->features = data[2]; |
| 418 | break; |
| 419 | case 0x0C: /* Button report */ |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 420 | wacom_i4_parse_button_report(wdata, input, data); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 421 | break; |
| 422 | default: |
| 423 | hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]); |
| 424 | break; |
| 425 | } |
| 426 | } |
| 427 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 428 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 429 | u8 *raw_data, int size) |
| 430 | { |
| 431 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 432 | struct hid_input *hidinput; |
| 433 | struct input_dev *input; |
| 434 | unsigned char *data = (unsigned char *) raw_data; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 435 | int i; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 436 | |
| 437 | if (!(hdev->claimed & HID_CLAIMED_INPUT)) |
| 438 | return 0; |
| 439 | |
| 440 | hidinput = list_entry(hdev->inputs.next, struct hid_input, list); |
| 441 | input = hidinput->input; |
| 442 | |
| 443 | /* Check if this is a tablet report */ |
| 444 | if (data[0] != 0x03) |
| 445 | return 0; |
| 446 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 447 | switch (hdev->product) { |
| 448 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 449 | return wacom_gr_parse_report(hdev, wdata, input, data); |
| 450 | break; |
| 451 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
| 452 | i = 1; |
| 453 | |
| 454 | switch (data[0]) { |
| 455 | case 0x04: |
| 456 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 457 | i += 10; |
| 458 | /* fall through */ |
| 459 | case 0x03: |
| 460 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 461 | i += 10; |
| 462 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 463 | break; |
| 464 | default: |
| 465 | hid_err(hdev, "Unknown report: %d,%d size:%d\n", |
| 466 | data[0], data[1], size); |
| 467 | return 0; |
| 468 | } |
| 469 | } |
| 470 | return 1; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 471 | } |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 472 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 473 | static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 474 | struct hid_field *field, struct hid_usage *usage, unsigned long **bit, |
| 475 | int *max) |
| 476 | { |
| 477 | struct input_dev *input = hi->input; |
| 478 | |
Jiri Kosina | f6f1242 | 2011-10-25 09:58:12 +0200 | [diff] [blame] | 479 | __set_bit(INPUT_PROP_POINTER, input->propbit); |
| 480 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 481 | /* Basics */ |
| 482 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); |
| 483 | |
| 484 | __set_bit(REL_WHEEL, input->relbit); |
| 485 | |
| 486 | __set_bit(BTN_TOOL_PEN, input->keybit); |
| 487 | __set_bit(BTN_TOUCH, input->keybit); |
| 488 | __set_bit(BTN_STYLUS, input->keybit); |
| 489 | __set_bit(BTN_STYLUS2, input->keybit); |
| 490 | __set_bit(BTN_LEFT, input->keybit); |
| 491 | __set_bit(BTN_RIGHT, input->keybit); |
| 492 | __set_bit(BTN_MIDDLE, input->keybit); |
| 493 | |
| 494 | /* Pad */ |
| 495 | input->evbit[0] |= BIT(EV_MSC); |
| 496 | |
| 497 | __set_bit(MSC_SERIAL, input->mscbit); |
| 498 | |
| 499 | __set_bit(BTN_0, input->keybit); |
| 500 | __set_bit(BTN_1, input->keybit); |
| 501 | __set_bit(BTN_TOOL_FINGER, input->keybit); |
| 502 | |
| 503 | /* Distance, rubber and mouse */ |
| 504 | __set_bit(BTN_TOOL_RUBBER, input->keybit); |
| 505 | __set_bit(BTN_TOOL_MOUSE, input->keybit); |
| 506 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 507 | switch (hdev->product) { |
| 508 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 509 | input_set_abs_params(input, ABS_X, 0, 16704, 4, 0); |
| 510 | input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0); |
| 511 | input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0); |
| 512 | input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0); |
| 513 | break; |
| 514 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
Przemo Firszt | 2c653e6 | 2012-02-24 13:47:48 +0000 | [diff] [blame] | 515 | __set_bit(ABS_MISC, input->absbit); |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 516 | __set_bit(BTN_2, input->keybit); |
| 517 | __set_bit(BTN_3, input->keybit); |
| 518 | __set_bit(BTN_4, input->keybit); |
| 519 | __set_bit(BTN_5, input->keybit); |
| 520 | __set_bit(BTN_6, input->keybit); |
| 521 | __set_bit(BTN_7, input->keybit); |
| 522 | __set_bit(BTN_8, input->keybit); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 523 | input_set_abs_params(input, ABS_X, 0, 40640, 4, 0); |
| 524 | input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0); |
| 525 | input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 526 | input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 527 | break; |
| 528 | } |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 533 | static int wacom_probe(struct hid_device *hdev, |
| 534 | const struct hid_device_id *id) |
| 535 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 536 | struct wacom_data *wdata; |
| 537 | int ret; |
| 538 | |
| 539 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); |
| 540 | if (wdata == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 541 | hid_err(hdev, "can't alloc wacom descriptor\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 542 | return -ENOMEM; |
| 543 | } |
| 544 | |
| 545 | hid_set_drvdata(hdev, wdata); |
| 546 | |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 547 | /* Parse the HID report now */ |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 548 | ret = hid_parse(hdev); |
| 549 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 550 | hid_err(hdev, "parse failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 551 | goto err_free; |
| 552 | } |
| 553 | |
| 554 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 555 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 556 | hid_err(hdev, "hw start failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 557 | goto err_free; |
| 558 | } |
| 559 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 560 | ret = device_create_file(&hdev->dev, &dev_attr_speed); |
| 561 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 562 | hid_warn(hdev, |
| 563 | "can't create sysfs speed attribute err: %d\n", ret); |
Jiri Kosina | 342f31e | 2010-02-03 15:52:31 +0100 | [diff] [blame] | 564 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 565 | switch (hdev->product) { |
| 566 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 567 | /* Set Wacom mode 2 with high reporting speed */ |
| 568 | wacom_poke(hdev, 1); |
| 569 | break; |
| 570 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
| 571 | wdata->features = 0; |
| 572 | wacom_set_features(hdev); |
| 573 | break; |
| 574 | } |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 575 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 576 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 577 | wdata->battery.properties = wacom_battery_props; |
| 578 | wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); |
| 579 | wdata->battery.get_property = wacom_battery_get_property; |
| 580 | wdata->battery.name = "wacom_battery"; |
| 581 | wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 582 | wdata->battery.use_for_apm = 0; |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 583 | |
Jeremy Fitzhardinge | 35b4c01 | 2011-12-09 09:35:00 -0800 | [diff] [blame] | 584 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 585 | ret = power_supply_register(&hdev->dev, &wdata->battery); |
| 586 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 587 | hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", |
| 588 | ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 589 | goto err_battery; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Przemo Firszt | d7cb3db | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 592 | power_supply_powers(&wdata->battery, &hdev->dev); |
| 593 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 594 | wdata->ac.properties = wacom_ac_props; |
| 595 | wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); |
| 596 | wdata->ac.get_property = wacom_ac_get_property; |
| 597 | wdata->ac.name = "wacom_ac"; |
| 598 | wdata->ac.type = POWER_SUPPLY_TYPE_MAINS; |
| 599 | wdata->ac.use_for_apm = 0; |
| 600 | |
| 601 | ret = power_supply_register(&hdev->dev, &wdata->ac); |
| 602 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 603 | hid_warn(hdev, |
| 604 | "can't create ac battery attribute, err: %d\n", ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 605 | goto err_ac; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 606 | } |
Przemo Firszt | d7cb3db | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 607 | |
| 608 | power_supply_powers(&wdata->ac, &hdev->dev); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 609 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 610 | return 0; |
Daniel Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 611 | |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 612 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 613 | err_ac: |
| 614 | power_supply_unregister(&wdata->battery); |
| 615 | err_battery: |
| 616 | device_remove_file(&hdev->dev, &dev_attr_speed); |
| 617 | hid_hw_stop(hdev); |
| 618 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 619 | err_free: |
| 620 | kfree(wdata); |
| 621 | return ret; |
| 622 | } |
| 623 | |
| 624 | static void wacom_remove(struct hid_device *hdev) |
| 625 | { |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 626 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 627 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 628 | #endif |
David Herrmann | 9086617 | 2011-09-05 18:45:29 +0200 | [diff] [blame] | 629 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 630 | hid_hw_stop(hdev); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 631 | |
| 632 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 633 | power_supply_unregister(&wdata->battery); |
| 634 | power_supply_unregister(&wdata->ac); |
| 635 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 636 | kfree(hid_get_drvdata(hdev)); |
| 637 | } |
| 638 | |
| 639 | static const struct hid_device_id wacom_devices[] = { |
| 640 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 641 | { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, |
Jiri Kosina | d5e0a06 | 2010-07-20 17:48:48 +0200 | [diff] [blame] | 642 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 643 | { } |
| 644 | }; |
| 645 | MODULE_DEVICE_TABLE(hid, wacom_devices); |
| 646 | |
| 647 | static struct hid_driver wacom_driver = { |
| 648 | .name = "wacom", |
| 649 | .id_table = wacom_devices, |
| 650 | .probe = wacom_probe, |
| 651 | .remove = wacom_remove, |
| 652 | .raw_event = wacom_raw_event, |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 653 | .input_mapped = wacom_input_mapped, |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 654 | }; |
| 655 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 656 | static int __init wacom_init(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 657 | { |
| 658 | int ret; |
| 659 | |
| 660 | ret = hid_register_driver(&wacom_driver); |
| 661 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 662 | pr_err("can't register wacom driver\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 663 | return ret; |
| 664 | } |
| 665 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 666 | static void __exit wacom_exit(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 667 | { |
| 668 | hid_unregister_driver(&wacom_driver); |
| 669 | } |
| 670 | |
| 671 | module_init(wacom_init); |
| 672 | module_exit(wacom_exit); |
| 673 | MODULE_LICENSE("GPL"); |
| 674 | |