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 | |
| 34 | struct wacom_data { |
| 35 | __u16 tool; |
| 36 | unsigned char butstate; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 37 | __u8 features; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 38 | __u32 id; |
| 39 | __u32 serial; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 40 | unsigned char high_speed; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 41 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 42 | int battery_capacity; |
| 43 | struct power_supply battery; |
| 44 | struct power_supply ac; |
| 45 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 46 | }; |
| 47 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 48 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 49 | /*percent of battery capacity, 0 means AC online*/ |
| 50 | static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 }; |
| 51 | |
| 52 | static enum power_supply_property wacom_battery_props[] = { |
| 53 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 54 | POWER_SUPPLY_PROP_CAPACITY, |
| 55 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | static enum power_supply_property wacom_ac_props[] = { |
| 59 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 60 | POWER_SUPPLY_PROP_ONLINE, |
| 61 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | static int wacom_battery_get_property(struct power_supply *psy, |
| 65 | enum power_supply_property psp, |
| 66 | union power_supply_propval *val) |
| 67 | { |
| 68 | struct wacom_data *wdata = container_of(psy, |
| 69 | struct wacom_data, battery); |
| 70 | int power_state = batcap[wdata->battery_capacity]; |
| 71 | int ret = 0; |
| 72 | |
| 73 | switch (psp) { |
| 74 | case POWER_SUPPLY_PROP_PRESENT: |
| 75 | val->intval = 1; |
| 76 | break; |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 77 | case POWER_SUPPLY_PROP_SCOPE: |
| 78 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 79 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 80 | case POWER_SUPPLY_PROP_CAPACITY: |
| 81 | /* show 100% battery capacity when charging */ |
| 82 | if (power_state == 0) |
| 83 | val->intval = 100; |
| 84 | else |
| 85 | val->intval = power_state; |
| 86 | break; |
| 87 | default: |
| 88 | ret = -EINVAL; |
| 89 | break; |
| 90 | } |
| 91 | return ret; |
| 92 | } |
| 93 | |
| 94 | static int wacom_ac_get_property(struct power_supply *psy, |
| 95 | enum power_supply_property psp, |
| 96 | union power_supply_propval *val) |
| 97 | { |
| 98 | struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); |
| 99 | int power_state = batcap[wdata->battery_capacity]; |
| 100 | int ret = 0; |
| 101 | |
| 102 | switch (psp) { |
| 103 | case POWER_SUPPLY_PROP_PRESENT: |
| 104 | /* fall through */ |
| 105 | case POWER_SUPPLY_PROP_ONLINE: |
| 106 | if (power_state == 0) |
| 107 | val->intval = 1; |
| 108 | else |
| 109 | val->intval = 0; |
| 110 | break; |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 111 | case POWER_SUPPLY_PROP_SCOPE: |
| 112 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 113 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 114 | default: |
| 115 | ret = -EINVAL; |
| 116 | break; |
| 117 | } |
| 118 | return ret; |
| 119 | } |
| 120 | #endif |
| 121 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 122 | static void wacom_set_features(struct hid_device *hdev) |
| 123 | { |
| 124 | int ret; |
| 125 | __u8 rep_data[2]; |
| 126 | |
| 127 | /*set high speed, tablet mode*/ |
| 128 | rep_data[0] = 0x03; |
| 129 | rep_data[1] = 0x20; |
| 130 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 131 | HID_FEATURE_REPORT); |
| 132 | return; |
| 133 | } |
| 134 | |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 135 | static void wacom_poke(struct hid_device *hdev, u8 speed) |
| 136 | { |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 137 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 138 | int limit, ret; |
| 139 | char rep_data[2]; |
| 140 | |
| 141 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; |
| 142 | limit = 3; |
| 143 | do { |
| 144 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 145 | HID_FEATURE_REPORT); |
| 146 | } while (ret < 0 && limit-- > 0); |
| 147 | |
| 148 | if (ret >= 0) { |
| 149 | if (speed == 0) |
| 150 | rep_data[0] = 0x05; |
| 151 | else |
| 152 | rep_data[0] = 0x06; |
| 153 | |
| 154 | rep_data[1] = 0x00; |
| 155 | limit = 3; |
| 156 | do { |
| 157 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 158 | HID_FEATURE_REPORT); |
| 159 | } while (ret < 0 && limit-- > 0); |
| 160 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 161 | if (ret >= 0) { |
| 162 | wdata->high_speed = speed; |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 163 | return; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 164 | } |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* |
| 168 | * Note that if the raw queries fail, it's not a hard failure and it |
| 169 | * is safe to continue |
| 170 | */ |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 171 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 172 | rep_data[0], ret); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 173 | return; |
| 174 | } |
| 175 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 176 | static ssize_t wacom_show_speed(struct device *dev, |
| 177 | struct device_attribute |
| 178 | *attr, char *buf) |
| 179 | { |
| 180 | struct wacom_data *wdata = dev_get_drvdata(dev); |
| 181 | |
| 182 | return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed); |
| 183 | } |
| 184 | |
| 185 | static ssize_t wacom_store_speed(struct device *dev, |
| 186 | struct device_attribute *attr, |
| 187 | const char *buf, size_t count) |
| 188 | { |
| 189 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 190 | int new_speed; |
| 191 | |
| 192 | if (sscanf(buf, "%1d", &new_speed ) != 1) |
| 193 | return -EINVAL; |
| 194 | |
| 195 | if (new_speed == 0 || new_speed == 1) { |
| 196 | wacom_poke(hdev, new_speed); |
| 197 | return strnlen(buf, PAGE_SIZE); |
| 198 | } else |
| 199 | return -EINVAL; |
| 200 | } |
| 201 | |
Jiri Kosina | edd2126 | 2010-11-18 16:28:43 +0100 | [diff] [blame] | 202 | static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 203 | wacom_show_speed, wacom_store_speed); |
| 204 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 205 | static int wacom_gr_parse_report(struct hid_device *hdev, |
| 206 | struct wacom_data *wdata, |
| 207 | struct input_dev *input, unsigned char *data) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 208 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 209 | int tool, x, y, rw; |
| 210 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 211 | tool = 0; |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 212 | /* Get X & Y positions */ |
| 213 | x = le16_to_cpu(*(__le16 *) &data[2]); |
| 214 | y = le16_to_cpu(*(__le16 *) &data[4]); |
| 215 | |
| 216 | /* Get current tool identifier */ |
| 217 | if (data[1] & 0x90) { /* If pen is in the in/active area */ |
| 218 | switch ((data[1] >> 5) & 3) { |
| 219 | case 0: /* Pen */ |
| 220 | tool = BTN_TOOL_PEN; |
| 221 | break; |
| 222 | |
| 223 | case 1: /* Rubber */ |
| 224 | tool = BTN_TOOL_RUBBER; |
| 225 | break; |
| 226 | |
| 227 | case 2: /* Mouse with wheel */ |
| 228 | case 3: /* Mouse without wheel */ |
| 229 | tool = BTN_TOOL_MOUSE; |
| 230 | break; |
| 231 | } |
| 232 | |
| 233 | /* Reset tool if out of active tablet area */ |
| 234 | if (!(data[1] & 0x10)) |
| 235 | tool = 0; |
| 236 | } |
| 237 | |
| 238 | /* If tool changed, notify input subsystem */ |
| 239 | if (wdata->tool != tool) { |
| 240 | if (wdata->tool) { |
| 241 | /* Completely reset old tool state */ |
| 242 | if (wdata->tool == BTN_TOOL_MOUSE) { |
| 243 | input_report_key(input, BTN_LEFT, 0); |
| 244 | input_report_key(input, BTN_RIGHT, 0); |
| 245 | input_report_key(input, BTN_MIDDLE, 0); |
| 246 | input_report_abs(input, ABS_DISTANCE, |
Daniel Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 247 | input_abs_get_max(input, ABS_DISTANCE)); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 248 | } else { |
| 249 | input_report_key(input, BTN_TOUCH, 0); |
| 250 | input_report_key(input, BTN_STYLUS, 0); |
| 251 | input_report_key(input, BTN_STYLUS2, 0); |
| 252 | input_report_abs(input, ABS_PRESSURE, 0); |
| 253 | } |
| 254 | input_report_key(input, wdata->tool, 0); |
| 255 | input_sync(input); |
| 256 | } |
| 257 | wdata->tool = tool; |
| 258 | if (tool) |
| 259 | input_report_key(input, tool, 1); |
| 260 | } |
| 261 | |
| 262 | if (tool) { |
| 263 | input_report_abs(input, ABS_X, x); |
| 264 | input_report_abs(input, ABS_Y, y); |
| 265 | |
| 266 | switch ((data[1] >> 5) & 3) { |
| 267 | case 2: /* Mouse with wheel */ |
| 268 | input_report_key(input, BTN_MIDDLE, data[1] & 0x04); |
| 269 | rw = (data[6] & 0x01) ? -1 : |
| 270 | (data[6] & 0x02) ? 1 : 0; |
| 271 | input_report_rel(input, REL_WHEEL, rw); |
| 272 | /* fall through */ |
| 273 | |
| 274 | case 3: /* Mouse without wheel */ |
| 275 | input_report_key(input, BTN_LEFT, data[1] & 0x01); |
| 276 | input_report_key(input, BTN_RIGHT, data[1] & 0x02); |
| 277 | /* Compute distance between mouse and tablet */ |
| 278 | rw = 44 - (data[6] >> 2); |
| 279 | if (rw < 0) |
| 280 | rw = 0; |
| 281 | else if (rw > 31) |
| 282 | rw = 31; |
| 283 | input_report_abs(input, ABS_DISTANCE, rw); |
| 284 | break; |
| 285 | |
| 286 | default: |
| 287 | input_report_abs(input, ABS_PRESSURE, |
| 288 | data[6] | (((__u16) (data[1] & 0x08)) << 5)); |
| 289 | input_report_key(input, BTN_TOUCH, data[1] & 0x01); |
| 290 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 291 | input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04); |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | input_sync(input); |
| 296 | } |
| 297 | |
| 298 | /* Report the state of the two buttons at the top of the tablet |
| 299 | * as two extra fingerpad keys (buttons 4 & 5). */ |
| 300 | rw = data[7] & 0x03; |
| 301 | if (rw != wdata->butstate) { |
| 302 | wdata->butstate = rw; |
| 303 | input_report_key(input, BTN_0, rw & 0x02); |
| 304 | input_report_key(input, BTN_1, rw & 0x01); |
Przemo Firszt | 0e253fd | 2010-01-09 15:20:03 +0100 | [diff] [blame] | 305 | input_report_key(input, BTN_TOOL_FINGER, 0xf0); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 306 | input_event(input, EV_MSC, MSC_SERIAL, 0xf0); |
| 307 | input_sync(input); |
| 308 | } |
| 309 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 310 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 311 | /* Store current battery capacity */ |
| 312 | rw = (data[7] >> 2 & 0x07); |
| 313 | if (rw != wdata->battery_capacity) |
| 314 | wdata->battery_capacity = rw; |
| 315 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 316 | return 1; |
| 317 | } |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 318 | |
| 319 | static void wacom_i4_parse_pen_report(struct wacom_data *wdata, |
| 320 | struct input_dev *input, unsigned char *data) |
| 321 | { |
| 322 | __u16 x, y, pressure; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 323 | |
| 324 | switch (data[1]) { |
| 325 | case 0x80: /* Out of proximity report */ |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 326 | input_report_key(input, BTN_TOUCH, 0); |
| 327 | input_report_abs(input, ABS_PRESSURE, 0); |
| 328 | input_report_key(input, wdata->tool, 0); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 329 | input_report_abs(input, ABS_MISC, 0); |
| 330 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
Przemo Firszt | 32db737 | 2012-02-19 20:20:29 +0000 | [diff] [blame] | 331 | wdata->tool = 0; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 332 | input_sync(input); |
| 333 | break; |
| 334 | case 0xC2: /* Tool report */ |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 335 | wdata->id = ((data[2] << 4) | (data[3] >> 4) | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 336 | ((data[7] & 0x0f) << 20) | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 337 | ((data[8] & 0xf0) << 12)); |
| 338 | wdata->serial = ((data[3] & 0x0f) << 28) + |
| 339 | (data[4] << 20) + (data[5] << 12) + |
| 340 | (data[6] << 4) + (data[7] >> 4); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 341 | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 342 | switch (wdata->id) { |
| 343 | case 0x100802: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 344 | wdata->tool = BTN_TOOL_PEN; |
| 345 | break; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 346 | case 0x10080A: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 347 | wdata->tool = BTN_TOOL_RUBBER; |
| 348 | break; |
| 349 | } |
| 350 | break; |
| 351 | default: /* Position/pressure report */ |
| 352 | x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1); |
| 353 | y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01); |
| 354 | pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) |
| 355 | | (data[1] & 0x01); |
| 356 | |
| 357 | input_report_key(input, BTN_TOUCH, pressure > 1); |
| 358 | |
| 359 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 360 | input_report_key(input, BTN_STYLUS2, data[1] & 0x04); |
| 361 | input_report_key(input, wdata->tool, 1); |
| 362 | input_report_abs(input, ABS_X, x); |
| 363 | input_report_abs(input, ABS_Y, y); |
| 364 | input_report_abs(input, ABS_PRESSURE, pressure); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame^] | 365 | input_report_abs(input, ABS_MISC, wdata->id); |
| 366 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
| 367 | input_report_key(input, wdata->tool, 1); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 368 | input_sync(input); |
| 369 | break; |
| 370 | } |
| 371 | |
| 372 | return; |
| 373 | } |
| 374 | |
| 375 | static void wacom_i4_parse_report(struct hid_device *hdev, |
| 376 | struct wacom_data *wdata, |
| 377 | struct input_dev *input, unsigned char *data) |
| 378 | { |
| 379 | switch (data[0]) { |
| 380 | case 0x00: /* Empty report */ |
| 381 | break; |
| 382 | case 0x02: /* Pen report */ |
| 383 | wacom_i4_parse_pen_report(wdata, input, data); |
| 384 | break; |
| 385 | case 0x03: /* Features Report */ |
| 386 | wdata->features = data[2]; |
| 387 | break; |
| 388 | case 0x0C: /* Button report */ |
| 389 | break; |
| 390 | default: |
| 391 | hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]); |
| 392 | break; |
| 393 | } |
| 394 | } |
| 395 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 396 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 397 | u8 *raw_data, int size) |
| 398 | { |
| 399 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 400 | struct hid_input *hidinput; |
| 401 | struct input_dev *input; |
| 402 | unsigned char *data = (unsigned char *) raw_data; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 403 | int i; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 404 | |
| 405 | if (!(hdev->claimed & HID_CLAIMED_INPUT)) |
| 406 | return 0; |
| 407 | |
| 408 | hidinput = list_entry(hdev->inputs.next, struct hid_input, list); |
| 409 | input = hidinput->input; |
| 410 | |
| 411 | /* Check if this is a tablet report */ |
| 412 | if (data[0] != 0x03) |
| 413 | return 0; |
| 414 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 415 | switch (hdev->product) { |
| 416 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 417 | return wacom_gr_parse_report(hdev, wdata, input, data); |
| 418 | break; |
| 419 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
| 420 | i = 1; |
| 421 | |
| 422 | switch (data[0]) { |
| 423 | case 0x04: |
| 424 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 425 | i += 10; |
| 426 | /* fall through */ |
| 427 | case 0x03: |
| 428 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 429 | i += 10; |
| 430 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 431 | break; |
| 432 | default: |
| 433 | hid_err(hdev, "Unknown report: %d,%d size:%d\n", |
| 434 | data[0], data[1], size); |
| 435 | return 0; |
| 436 | } |
| 437 | } |
| 438 | return 1; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 439 | } |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 440 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 441 | static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 442 | struct hid_field *field, struct hid_usage *usage, unsigned long **bit, |
| 443 | int *max) |
| 444 | { |
| 445 | struct input_dev *input = hi->input; |
| 446 | |
Jiri Kosina | f6f1242 | 2011-10-25 09:58:12 +0200 | [diff] [blame] | 447 | __set_bit(INPUT_PROP_POINTER, input->propbit); |
| 448 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 449 | /* Basics */ |
| 450 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); |
| 451 | |
| 452 | __set_bit(REL_WHEEL, input->relbit); |
| 453 | |
| 454 | __set_bit(BTN_TOOL_PEN, input->keybit); |
| 455 | __set_bit(BTN_TOUCH, input->keybit); |
| 456 | __set_bit(BTN_STYLUS, input->keybit); |
| 457 | __set_bit(BTN_STYLUS2, input->keybit); |
| 458 | __set_bit(BTN_LEFT, input->keybit); |
| 459 | __set_bit(BTN_RIGHT, input->keybit); |
| 460 | __set_bit(BTN_MIDDLE, input->keybit); |
| 461 | |
| 462 | /* Pad */ |
| 463 | input->evbit[0] |= BIT(EV_MSC); |
| 464 | |
| 465 | __set_bit(MSC_SERIAL, input->mscbit); |
| 466 | |
| 467 | __set_bit(BTN_0, input->keybit); |
| 468 | __set_bit(BTN_1, input->keybit); |
| 469 | __set_bit(BTN_TOOL_FINGER, input->keybit); |
| 470 | |
| 471 | /* Distance, rubber and mouse */ |
| 472 | __set_bit(BTN_TOOL_RUBBER, input->keybit); |
| 473 | __set_bit(BTN_TOOL_MOUSE, input->keybit); |
| 474 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 475 | switch (hdev->product) { |
| 476 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 477 | input_set_abs_params(input, ABS_X, 0, 16704, 4, 0); |
| 478 | input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0); |
| 479 | input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0); |
| 480 | input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0); |
| 481 | break; |
| 482 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
Przemo Firszt | 2c653e6 | 2012-02-24 13:47:48 +0000 | [diff] [blame] | 483 | __set_bit(ABS_MISC, input->absbit); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 484 | input_set_abs_params(input, ABS_X, 0, 40640, 4, 0); |
| 485 | input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0); |
| 486 | input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0); |
| 487 | break; |
| 488 | } |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 489 | |
| 490 | return 0; |
| 491 | } |
| 492 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 493 | static int wacom_probe(struct hid_device *hdev, |
| 494 | const struct hid_device_id *id) |
| 495 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 496 | struct wacom_data *wdata; |
| 497 | int ret; |
| 498 | |
| 499 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); |
| 500 | if (wdata == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 501 | hid_err(hdev, "can't alloc wacom descriptor\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 502 | return -ENOMEM; |
| 503 | } |
| 504 | |
| 505 | hid_set_drvdata(hdev, wdata); |
| 506 | |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 507 | /* Parse the HID report now */ |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 508 | ret = hid_parse(hdev); |
| 509 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 510 | hid_err(hdev, "parse failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 511 | goto err_free; |
| 512 | } |
| 513 | |
| 514 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 515 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 516 | hid_err(hdev, "hw start failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 517 | goto err_free; |
| 518 | } |
| 519 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 520 | ret = device_create_file(&hdev->dev, &dev_attr_speed); |
| 521 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 522 | hid_warn(hdev, |
| 523 | "can't create sysfs speed attribute err: %d\n", ret); |
Jiri Kosina | 342f31e | 2010-02-03 15:52:31 +0100 | [diff] [blame] | 524 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 525 | switch (hdev->product) { |
| 526 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 527 | /* Set Wacom mode 2 with high reporting speed */ |
| 528 | wacom_poke(hdev, 1); |
| 529 | break; |
| 530 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
| 531 | wdata->features = 0; |
| 532 | wacom_set_features(hdev); |
| 533 | break; |
| 534 | } |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 535 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 536 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 537 | wdata->battery.properties = wacom_battery_props; |
| 538 | wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); |
| 539 | wdata->battery.get_property = wacom_battery_get_property; |
| 540 | wdata->battery.name = "wacom_battery"; |
| 541 | wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 542 | wdata->battery.use_for_apm = 0; |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 543 | |
Jeremy Fitzhardinge | 35b4c01 | 2011-12-09 09:35:00 -0800 | [diff] [blame] | 544 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 545 | ret = power_supply_register(&hdev->dev, &wdata->battery); |
| 546 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 547 | hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", |
| 548 | ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 549 | goto err_battery; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Przemo Firszt | d7cb3db | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 552 | power_supply_powers(&wdata->battery, &hdev->dev); |
| 553 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 554 | wdata->ac.properties = wacom_ac_props; |
| 555 | wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); |
| 556 | wdata->ac.get_property = wacom_ac_get_property; |
| 557 | wdata->ac.name = "wacom_ac"; |
| 558 | wdata->ac.type = POWER_SUPPLY_TYPE_MAINS; |
| 559 | wdata->ac.use_for_apm = 0; |
| 560 | |
| 561 | ret = power_supply_register(&hdev->dev, &wdata->ac); |
| 562 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 563 | hid_warn(hdev, |
| 564 | "can't create ac battery attribute, err: %d\n", ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 565 | goto err_ac; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 566 | } |
Przemo Firszt | d7cb3db | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 567 | |
| 568 | power_supply_powers(&wdata->ac, &hdev->dev); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 569 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 570 | return 0; |
Daniel Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 571 | |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 572 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 573 | err_ac: |
| 574 | power_supply_unregister(&wdata->battery); |
| 575 | err_battery: |
| 576 | device_remove_file(&hdev->dev, &dev_attr_speed); |
| 577 | hid_hw_stop(hdev); |
| 578 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 579 | err_free: |
| 580 | kfree(wdata); |
| 581 | return ret; |
| 582 | } |
| 583 | |
| 584 | static void wacom_remove(struct hid_device *hdev) |
| 585 | { |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 586 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 587 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 588 | #endif |
David Herrmann | 9086617 | 2011-09-05 18:45:29 +0200 | [diff] [blame] | 589 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 590 | hid_hw_stop(hdev); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 591 | |
| 592 | #ifdef CONFIG_HID_WACOM_POWER_SUPPLY |
| 593 | power_supply_unregister(&wdata->battery); |
| 594 | power_supply_unregister(&wdata->ac); |
| 595 | #endif |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 596 | kfree(hid_get_drvdata(hdev)); |
| 597 | } |
| 598 | |
| 599 | static const struct hid_device_id wacom_devices[] = { |
| 600 | { 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] | 601 | { 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] | 602 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 603 | { } |
| 604 | }; |
| 605 | MODULE_DEVICE_TABLE(hid, wacom_devices); |
| 606 | |
| 607 | static struct hid_driver wacom_driver = { |
| 608 | .name = "wacom", |
| 609 | .id_table = wacom_devices, |
| 610 | .probe = wacom_probe, |
| 611 | .remove = wacom_remove, |
| 612 | .raw_event = wacom_raw_event, |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 613 | .input_mapped = wacom_input_mapped, |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 614 | }; |
| 615 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 616 | static int __init wacom_init(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 617 | { |
| 618 | int ret; |
| 619 | |
| 620 | ret = hid_register_driver(&wacom_driver); |
| 621 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 622 | pr_err("can't register wacom driver\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 623 | return ret; |
| 624 | } |
| 625 | |
Peter Huewe | a24f423b | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 626 | static void __exit wacom_exit(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 627 | { |
| 628 | hid_unregister_driver(&wacom_driver); |
| 629 | } |
| 630 | |
| 631 | module_init(wacom_init); |
| 632 | module_exit(wacom_exit); |
| 633 | MODULE_LICENSE("GPL"); |
| 634 | |