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> |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 27 | #include <linux/leds.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 29 | #include <linux/power_supply.h> |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 30 | |
| 31 | #include "hid-ids.h" |
| 32 | |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 33 | #define PAD_DEVICE_ID 0x0F |
| 34 | |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 35 | #define WAC_CMD_LED_CONTROL 0x20 |
| 36 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 37 | struct wacom_data { |
| 38 | __u16 tool; |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 39 | __u16 butstate; |
Przemo Firszt | 7e503a3 | 2012-03-14 19:55:04 +0000 | [diff] [blame] | 40 | __u8 whlstate; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 41 | __u8 features; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 42 | __u32 id; |
| 43 | __u32 serial; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 44 | unsigned char high_speed; |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 45 | __u8 battery_capacity; |
| 46 | __u8 power_raw; |
| 47 | __u8 ps_connected; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 48 | struct power_supply battery; |
| 49 | struct power_supply ac; |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 50 | __u8 led_selector; |
| 51 | struct led_classdev *leds[4]; |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 52 | }; |
| 53 | |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 54 | /*percent of battery capacity for Graphire |
| 55 | 8th value means AC online and show 100% capacity */ |
| 56 | static unsigned short batcap_gr[8] = { 1, 15, 25, 35, 50, 70, 100, 100 }; |
Przemo Firszt | 4202f1d | 2012-03-22 18:54:08 +0000 | [diff] [blame] | 57 | /*percent of battery capacity for Intuos4 WL, AC has a separate bit*/ |
| 58 | static unsigned short batcap_i4[8] = { 1, 15, 30, 45, 60, 70, 85, 100 }; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 59 | |
| 60 | static enum power_supply_property wacom_battery_props[] = { |
| 61 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 62 | POWER_SUPPLY_PROP_CAPACITY, |
| 63 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | static enum power_supply_property wacom_ac_props[] = { |
| 67 | POWER_SUPPLY_PROP_PRESENT, |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 68 | POWER_SUPPLY_PROP_ONLINE, |
| 69 | POWER_SUPPLY_PROP_SCOPE, |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 72 | static void wacom_leds_set_brightness(struct led_classdev *led_dev, |
| 73 | enum led_brightness value) |
| 74 | { |
| 75 | struct device *dev = led_dev->dev->parent; |
| 76 | struct hid_device *hdev; |
| 77 | struct wacom_data *wdata; |
| 78 | unsigned char *buf; |
| 79 | __u8 led = 0; |
| 80 | int i; |
| 81 | |
| 82 | hdev = container_of(dev, struct hid_device, dev); |
| 83 | wdata = hid_get_drvdata(hdev); |
| 84 | for (i = 0; i < 4; ++i) { |
| 85 | if (wdata->leds[i] == led_dev) |
| 86 | wdata->led_selector = i; |
| 87 | } |
| 88 | |
| 89 | led = wdata->led_selector | 0x04; |
| 90 | buf = kzalloc(9, GFP_KERNEL); |
| 91 | if (buf) { |
| 92 | buf[0] = WAC_CMD_LED_CONTROL; |
| 93 | buf[1] = led; |
| 94 | buf[2] = value; |
| 95 | hdev->hid_output_raw_report(hdev, buf, 9, HID_FEATURE_REPORT); |
| 96 | kfree(buf); |
| 97 | } |
| 98 | |
| 99 | return; |
| 100 | } |
| 101 | |
| 102 | static enum led_brightness wacom_leds_get_brightness(struct led_classdev *led_dev) |
| 103 | { |
| 104 | struct wacom_data *wdata; |
| 105 | struct device *dev = led_dev->dev->parent; |
| 106 | int value = 0; |
| 107 | int i; |
| 108 | |
| 109 | wdata = hid_get_drvdata(container_of(dev, struct hid_device, dev)); |
| 110 | |
| 111 | for (i = 0; i < 4; ++i) { |
| 112 | if (wdata->leds[i] == led_dev) { |
| 113 | value = wdata->leds[i]->brightness; |
| 114 | break; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | return value; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | static int wacom_initialize_leds(struct hid_device *hdev) |
| 123 | { |
| 124 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 125 | struct led_classdev *led; |
| 126 | struct device *dev = &hdev->dev; |
| 127 | size_t namesz = strlen(dev_name(dev)) + 12; |
| 128 | char *name; |
| 129 | int i, ret; |
| 130 | |
| 131 | wdata->led_selector = 0; |
| 132 | |
| 133 | for (i = 0; i < 4; i++) { |
| 134 | led = kzalloc(sizeof(struct led_classdev) + namesz, GFP_KERNEL); |
| 135 | if (!led) { |
| 136 | hid_warn(hdev, |
| 137 | "can't allocate memory for LED selector\n"); |
| 138 | ret = -ENOMEM; |
| 139 | goto err; |
| 140 | } |
| 141 | |
| 142 | name = (void *)&led[1]; |
| 143 | snprintf(name, namesz, "%s:selector:%d", dev_name(dev), i); |
| 144 | led->name = name; |
| 145 | led->brightness = 0; |
| 146 | led->max_brightness = 127; |
| 147 | led->brightness_get = wacom_leds_get_brightness; |
| 148 | led->brightness_set = wacom_leds_set_brightness; |
| 149 | |
| 150 | wdata->leds[i] = led; |
| 151 | |
| 152 | ret = led_classdev_register(dev, wdata->leds[i]); |
| 153 | |
| 154 | if (ret) { |
| 155 | wdata->leds[i] = NULL; |
| 156 | kfree(led); |
| 157 | hid_warn(hdev, "can't register LED\n"); |
| 158 | goto err; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | err: |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | static void wacom_destroy_leds(struct hid_device *hdev) |
| 167 | { |
| 168 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 169 | struct led_classdev *led; |
| 170 | int i; |
| 171 | |
| 172 | for (i = 0; i < 4; ++i) { |
| 173 | if (wdata->leds[i]) { |
| 174 | led = wdata->leds[i]; |
| 175 | wdata->leds[i] = NULL; |
| 176 | led_classdev_unregister(led); |
| 177 | kfree(led); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | } |
| 182 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 183 | static int wacom_battery_get_property(struct power_supply *psy, |
| 184 | enum power_supply_property psp, |
| 185 | union power_supply_propval *val) |
| 186 | { |
| 187 | struct wacom_data *wdata = container_of(psy, |
| 188 | struct wacom_data, battery); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 189 | int ret = 0; |
| 190 | |
| 191 | switch (psp) { |
| 192 | case POWER_SUPPLY_PROP_PRESENT: |
| 193 | val->intval = 1; |
| 194 | break; |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 195 | case POWER_SUPPLY_PROP_SCOPE: |
| 196 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 197 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 198 | case POWER_SUPPLY_PROP_CAPACITY: |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 199 | val->intval = wdata->battery_capacity; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 200 | break; |
| 201 | default: |
| 202 | ret = -EINVAL; |
| 203 | break; |
| 204 | } |
| 205 | return ret; |
| 206 | } |
| 207 | |
| 208 | static int wacom_ac_get_property(struct power_supply *psy, |
| 209 | enum power_supply_property psp, |
| 210 | union power_supply_propval *val) |
| 211 | { |
| 212 | struct wacom_data *wdata = container_of(psy, struct wacom_data, ac); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 213 | int ret = 0; |
| 214 | |
| 215 | switch (psp) { |
| 216 | case POWER_SUPPLY_PROP_PRESENT: |
| 217 | /* fall through */ |
| 218 | case POWER_SUPPLY_PROP_ONLINE: |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 219 | val->intval = wdata->ps_connected; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 220 | break; |
Jeremy Fitzhardinge | 73db881 | 2011-12-07 11:29:46 -0800 | [diff] [blame] | 221 | case POWER_SUPPLY_PROP_SCOPE: |
| 222 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 223 | break; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 224 | default: |
| 225 | ret = -EINVAL; |
| 226 | break; |
| 227 | } |
| 228 | return ret; |
| 229 | } |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 230 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 231 | static void wacom_set_features(struct hid_device *hdev) |
| 232 | { |
| 233 | int ret; |
| 234 | __u8 rep_data[2]; |
| 235 | |
| 236 | /*set high speed, tablet mode*/ |
| 237 | rep_data[0] = 0x03; |
| 238 | rep_data[1] = 0x20; |
| 239 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 240 | HID_FEATURE_REPORT); |
| 241 | return; |
| 242 | } |
| 243 | |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 244 | static void wacom_poke(struct hid_device *hdev, u8 speed) |
| 245 | { |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 246 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 247 | int limit, ret; |
| 248 | char rep_data[2]; |
| 249 | |
| 250 | rep_data[0] = 0x03 ; rep_data[1] = 0x00; |
| 251 | limit = 3; |
| 252 | do { |
| 253 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 254 | HID_FEATURE_REPORT); |
| 255 | } while (ret < 0 && limit-- > 0); |
| 256 | |
| 257 | if (ret >= 0) { |
| 258 | if (speed == 0) |
| 259 | rep_data[0] = 0x05; |
| 260 | else |
| 261 | rep_data[0] = 0x06; |
| 262 | |
| 263 | rep_data[1] = 0x00; |
| 264 | limit = 3; |
| 265 | do { |
| 266 | ret = hdev->hid_output_raw_report(hdev, rep_data, 2, |
| 267 | HID_FEATURE_REPORT); |
| 268 | } while (ret < 0 && limit-- > 0); |
| 269 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 270 | if (ret >= 0) { |
| 271 | wdata->high_speed = speed; |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 272 | return; |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 273 | } |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* |
| 277 | * Note that if the raw queries fail, it's not a hard failure and it |
| 278 | * is safe to continue |
| 279 | */ |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 280 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 281 | rep_data[0], ret); |
Przemo Firszt | 06c7c31 | 2010-03-22 09:55:04 +0100 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 285 | static ssize_t wacom_show_speed(struct device *dev, |
| 286 | struct device_attribute |
| 287 | *attr, char *buf) |
| 288 | { |
| 289 | struct wacom_data *wdata = dev_get_drvdata(dev); |
| 290 | |
| 291 | return snprintf(buf, PAGE_SIZE, "%i\n", wdata->high_speed); |
| 292 | } |
| 293 | |
| 294 | static ssize_t wacom_store_speed(struct device *dev, |
| 295 | struct device_attribute *attr, |
| 296 | const char *buf, size_t count) |
| 297 | { |
| 298 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 299 | int new_speed; |
| 300 | |
| 301 | if (sscanf(buf, "%1d", &new_speed ) != 1) |
| 302 | return -EINVAL; |
| 303 | |
| 304 | if (new_speed == 0 || new_speed == 1) { |
| 305 | wacom_poke(hdev, new_speed); |
| 306 | return strnlen(buf, PAGE_SIZE); |
| 307 | } else |
| 308 | return -EINVAL; |
| 309 | } |
| 310 | |
Jiri Kosina | edd2126 | 2010-11-18 16:28:43 +0100 | [diff] [blame] | 311 | static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP, |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 312 | wacom_show_speed, wacom_store_speed); |
| 313 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 314 | static int wacom_gr_parse_report(struct hid_device *hdev, |
| 315 | struct wacom_data *wdata, |
| 316 | struct input_dev *input, unsigned char *data) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 317 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 318 | int tool, x, y, rw; |
| 319 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 320 | tool = 0; |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 321 | /* Get X & Y positions */ |
| 322 | x = le16_to_cpu(*(__le16 *) &data[2]); |
| 323 | y = le16_to_cpu(*(__le16 *) &data[4]); |
| 324 | |
| 325 | /* Get current tool identifier */ |
| 326 | if (data[1] & 0x90) { /* If pen is in the in/active area */ |
| 327 | switch ((data[1] >> 5) & 3) { |
| 328 | case 0: /* Pen */ |
| 329 | tool = BTN_TOOL_PEN; |
| 330 | break; |
| 331 | |
| 332 | case 1: /* Rubber */ |
| 333 | tool = BTN_TOOL_RUBBER; |
| 334 | break; |
| 335 | |
| 336 | case 2: /* Mouse with wheel */ |
| 337 | case 3: /* Mouse without wheel */ |
| 338 | tool = BTN_TOOL_MOUSE; |
| 339 | break; |
| 340 | } |
| 341 | |
| 342 | /* Reset tool if out of active tablet area */ |
| 343 | if (!(data[1] & 0x10)) |
| 344 | tool = 0; |
| 345 | } |
| 346 | |
| 347 | /* If tool changed, notify input subsystem */ |
| 348 | if (wdata->tool != tool) { |
| 349 | if (wdata->tool) { |
| 350 | /* Completely reset old tool state */ |
| 351 | if (wdata->tool == BTN_TOOL_MOUSE) { |
| 352 | input_report_key(input, BTN_LEFT, 0); |
| 353 | input_report_key(input, BTN_RIGHT, 0); |
| 354 | input_report_key(input, BTN_MIDDLE, 0); |
| 355 | input_report_abs(input, ABS_DISTANCE, |
Daniel Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 356 | input_abs_get_max(input, ABS_DISTANCE)); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 357 | } else { |
| 358 | input_report_key(input, BTN_TOUCH, 0); |
| 359 | input_report_key(input, BTN_STYLUS, 0); |
| 360 | input_report_key(input, BTN_STYLUS2, 0); |
| 361 | input_report_abs(input, ABS_PRESSURE, 0); |
| 362 | } |
| 363 | input_report_key(input, wdata->tool, 0); |
| 364 | input_sync(input); |
| 365 | } |
| 366 | wdata->tool = tool; |
| 367 | if (tool) |
| 368 | input_report_key(input, tool, 1); |
| 369 | } |
| 370 | |
| 371 | if (tool) { |
| 372 | input_report_abs(input, ABS_X, x); |
| 373 | input_report_abs(input, ABS_Y, y); |
| 374 | |
| 375 | switch ((data[1] >> 5) & 3) { |
| 376 | case 2: /* Mouse with wheel */ |
| 377 | input_report_key(input, BTN_MIDDLE, data[1] & 0x04); |
| 378 | rw = (data[6] & 0x01) ? -1 : |
| 379 | (data[6] & 0x02) ? 1 : 0; |
| 380 | input_report_rel(input, REL_WHEEL, rw); |
| 381 | /* fall through */ |
| 382 | |
| 383 | case 3: /* Mouse without wheel */ |
| 384 | input_report_key(input, BTN_LEFT, data[1] & 0x01); |
| 385 | input_report_key(input, BTN_RIGHT, data[1] & 0x02); |
| 386 | /* Compute distance between mouse and tablet */ |
| 387 | rw = 44 - (data[6] >> 2); |
| 388 | if (rw < 0) |
| 389 | rw = 0; |
| 390 | else if (rw > 31) |
| 391 | rw = 31; |
| 392 | input_report_abs(input, ABS_DISTANCE, rw); |
| 393 | break; |
| 394 | |
| 395 | default: |
| 396 | input_report_abs(input, ABS_PRESSURE, |
| 397 | data[6] | (((__u16) (data[1] & 0x08)) << 5)); |
| 398 | input_report_key(input, BTN_TOUCH, data[1] & 0x01); |
| 399 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 400 | input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04); |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | input_sync(input); |
| 405 | } |
| 406 | |
| 407 | /* Report the state of the two buttons at the top of the tablet |
| 408 | * as two extra fingerpad keys (buttons 4 & 5). */ |
| 409 | rw = data[7] & 0x03; |
| 410 | if (rw != wdata->butstate) { |
| 411 | wdata->butstate = rw; |
| 412 | input_report_key(input, BTN_0, rw & 0x02); |
| 413 | input_report_key(input, BTN_1, rw & 0x01); |
Przemo Firszt | 0e253fd | 2010-01-09 15:20:03 +0100 | [diff] [blame] | 414 | input_report_key(input, BTN_TOOL_FINGER, 0xf0); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 415 | input_event(input, EV_MSC, MSC_SERIAL, 0xf0); |
| 416 | input_sync(input); |
| 417 | } |
| 418 | |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 419 | /* Store current battery capacity and power supply state*/ |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 420 | rw = (data[7] >> 2 & 0x07); |
Przemo Firszt | e31e383 | 2012-03-22 18:54:07 +0000 | [diff] [blame] | 421 | if (rw != wdata->power_raw) { |
| 422 | wdata->power_raw = rw; |
| 423 | wdata->battery_capacity = batcap_gr[rw]; |
| 424 | if (rw == 7) |
| 425 | wdata->ps_connected = 1; |
| 426 | else |
| 427 | wdata->ps_connected = 0; |
| 428 | } |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 429 | return 1; |
| 430 | } |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 431 | |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 432 | static void wacom_i4_parse_button_report(struct wacom_data *wdata, |
| 433 | struct input_dev *input, unsigned char *data) |
| 434 | { |
| 435 | __u16 new_butstate; |
Przemo Firszt | 7e503a3 | 2012-03-14 19:55:04 +0000 | [diff] [blame] | 436 | __u8 new_whlstate; |
| 437 | __u8 sync = 0; |
| 438 | |
| 439 | new_whlstate = data[1]; |
| 440 | if (new_whlstate != wdata->whlstate) { |
| 441 | wdata->whlstate = new_whlstate; |
| 442 | if (new_whlstate & 0x80) { |
| 443 | input_report_key(input, BTN_TOUCH, 1); |
| 444 | input_report_abs(input, ABS_WHEEL, (new_whlstate & 0x7f)); |
| 445 | input_report_key(input, BTN_TOOL_FINGER, 1); |
| 446 | } else { |
| 447 | input_report_key(input, BTN_TOUCH, 0); |
| 448 | input_report_abs(input, ABS_WHEEL, 0); |
| 449 | input_report_key(input, BTN_TOOL_FINGER, 0); |
| 450 | } |
| 451 | sync = 1; |
| 452 | } |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 453 | |
| 454 | new_butstate = (data[3] << 1) | (data[2] & 0x01); |
| 455 | if (new_butstate != wdata->butstate) { |
| 456 | wdata->butstate = new_butstate; |
| 457 | input_report_key(input, BTN_0, new_butstate & 0x001); |
| 458 | input_report_key(input, BTN_1, new_butstate & 0x002); |
| 459 | input_report_key(input, BTN_2, new_butstate & 0x004); |
| 460 | input_report_key(input, BTN_3, new_butstate & 0x008); |
| 461 | input_report_key(input, BTN_4, new_butstate & 0x010); |
| 462 | input_report_key(input, BTN_5, new_butstate & 0x020); |
| 463 | input_report_key(input, BTN_6, new_butstate & 0x040); |
| 464 | input_report_key(input, BTN_7, new_butstate & 0x080); |
| 465 | input_report_key(input, BTN_8, new_butstate & 0x100); |
| 466 | input_report_key(input, BTN_TOOL_FINGER, 1); |
Przemo Firszt | 7e503a3 | 2012-03-14 19:55:04 +0000 | [diff] [blame] | 467 | sync = 1; |
| 468 | } |
| 469 | |
| 470 | if (sync) { |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 471 | input_report_abs(input, ABS_MISC, PAD_DEVICE_ID); |
| 472 | input_event(input, EV_MSC, MSC_SERIAL, 0xffffffff); |
| 473 | input_sync(input); |
| 474 | } |
| 475 | } |
| 476 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 477 | static void wacom_i4_parse_pen_report(struct wacom_data *wdata, |
| 478 | struct input_dev *input, unsigned char *data) |
| 479 | { |
| 480 | __u16 x, y, pressure; |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 481 | __u8 distance; |
Przemo Firszt | c653dab | 2012-05-04 18:00:10 +0100 | [diff] [blame] | 482 | __u8 tilt_x, tilt_y; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 483 | |
| 484 | switch (data[1]) { |
| 485 | case 0x80: /* Out of proximity report */ |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 486 | input_report_key(input, BTN_TOUCH, 0); |
| 487 | input_report_abs(input, ABS_PRESSURE, 0); |
Przemo Firszt | 693f45b | 2012-03-09 13:20:51 +0000 | [diff] [blame] | 488 | input_report_key(input, BTN_STYLUS, 0); |
| 489 | input_report_key(input, BTN_STYLUS2, 0); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 490 | input_report_key(input, wdata->tool, 0); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 491 | input_report_abs(input, ABS_MISC, 0); |
| 492 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
Przemo Firszt | 32db737 | 2012-02-19 20:20:29 +0000 | [diff] [blame] | 493 | wdata->tool = 0; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 494 | input_sync(input); |
| 495 | break; |
| 496 | case 0xC2: /* Tool report */ |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 497 | wdata->id = ((data[2] << 4) | (data[3] >> 4) | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 498 | ((data[7] & 0x0f) << 20) | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 499 | ((data[8] & 0xf0) << 12)); |
| 500 | wdata->serial = ((data[3] & 0x0f) << 28) + |
| 501 | (data[4] << 20) + (data[5] << 12) + |
| 502 | (data[6] << 4) + (data[7] >> 4); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 503 | |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 504 | switch (wdata->id) { |
| 505 | case 0x100802: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 506 | wdata->tool = BTN_TOOL_PEN; |
| 507 | break; |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 508 | case 0x10080A: |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 509 | wdata->tool = BTN_TOOL_RUBBER; |
| 510 | break; |
| 511 | } |
| 512 | break; |
| 513 | default: /* Position/pressure report */ |
| 514 | x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1); |
| 515 | y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01); |
| 516 | pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5) |
| 517 | | (data[1] & 0x01); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 518 | distance = (data[9] >> 2) & 0x3f; |
Przemo Firszt | c653dab | 2012-05-04 18:00:10 +0100 | [diff] [blame] | 519 | tilt_x = ((data[7] << 1) & 0x7e) | (data[8] >> 7); |
| 520 | tilt_y = data[8] & 0x7f; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 521 | |
| 522 | input_report_key(input, BTN_TOUCH, pressure > 1); |
| 523 | |
| 524 | input_report_key(input, BTN_STYLUS, data[1] & 0x02); |
| 525 | input_report_key(input, BTN_STYLUS2, data[1] & 0x04); |
| 526 | input_report_key(input, wdata->tool, 1); |
| 527 | input_report_abs(input, ABS_X, x); |
| 528 | input_report_abs(input, ABS_Y, y); |
| 529 | input_report_abs(input, ABS_PRESSURE, pressure); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 530 | input_report_abs(input, ABS_DISTANCE, distance); |
Przemo Firszt | c653dab | 2012-05-04 18:00:10 +0100 | [diff] [blame] | 531 | input_report_abs(input, ABS_TILT_X, tilt_x); |
| 532 | input_report_abs(input, ABS_TILT_Y, tilt_y); |
Przemo Firszt | 2470900 | 2012-02-24 13:52:32 +0000 | [diff] [blame] | 533 | input_report_abs(input, ABS_MISC, wdata->id); |
| 534 | input_event(input, EV_MSC, MSC_SERIAL, wdata->serial); |
| 535 | input_report_key(input, wdata->tool, 1); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 536 | input_sync(input); |
| 537 | break; |
| 538 | } |
| 539 | |
| 540 | return; |
| 541 | } |
| 542 | |
| 543 | static void wacom_i4_parse_report(struct hid_device *hdev, |
| 544 | struct wacom_data *wdata, |
| 545 | struct input_dev *input, unsigned char *data) |
| 546 | { |
| 547 | switch (data[0]) { |
| 548 | case 0x00: /* Empty report */ |
| 549 | break; |
| 550 | case 0x02: /* Pen report */ |
| 551 | wacom_i4_parse_pen_report(wdata, input, data); |
| 552 | break; |
| 553 | case 0x03: /* Features Report */ |
| 554 | wdata->features = data[2]; |
| 555 | break; |
| 556 | case 0x0C: /* Button report */ |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 557 | wacom_i4_parse_button_report(wdata, input, data); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 558 | break; |
| 559 | default: |
| 560 | hid_err(hdev, "Unknown report: %d,%d\n", data[0], data[1]); |
| 561 | break; |
| 562 | } |
| 563 | } |
| 564 | |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 565 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 566 | u8 *raw_data, int size) |
| 567 | { |
| 568 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
| 569 | struct hid_input *hidinput; |
| 570 | struct input_dev *input; |
| 571 | unsigned char *data = (unsigned char *) raw_data; |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 572 | int i; |
Przemo Firszt | 4202f1d | 2012-03-22 18:54:08 +0000 | [diff] [blame] | 573 | __u8 power_raw; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 574 | |
| 575 | if (!(hdev->claimed & HID_CLAIMED_INPUT)) |
| 576 | return 0; |
| 577 | |
| 578 | hidinput = list_entry(hdev->inputs.next, struct hid_input, list); |
| 579 | input = hidinput->input; |
| 580 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 581 | switch (hdev->product) { |
| 582 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
Przemo Firszt | 163a6ae | 2012-05-15 19:32:25 +0100 | [diff] [blame^] | 583 | if (data[0] == 0x03) { |
| 584 | return wacom_gr_parse_report(hdev, wdata, input, data); |
| 585 | } else { |
| 586 | hid_err(hdev, "Unknown report: %d,%d size:%d\n", |
| 587 | data[0], data[1], size); |
| 588 | return 0; |
| 589 | } |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 590 | break; |
| 591 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
| 592 | i = 1; |
| 593 | |
| 594 | switch (data[0]) { |
| 595 | case 0x04: |
| 596 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 597 | i += 10; |
| 598 | /* fall through */ |
| 599 | case 0x03: |
| 600 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
| 601 | i += 10; |
| 602 | wacom_i4_parse_report(hdev, wdata, input, data + i); |
Przemo Firszt | 4202f1d | 2012-03-22 18:54:08 +0000 | [diff] [blame] | 603 | power_raw = data[i+10]; |
| 604 | if (power_raw != wdata->power_raw) { |
| 605 | wdata->power_raw = power_raw; |
| 606 | wdata->battery_capacity = batcap_i4[power_raw & 0x07]; |
| 607 | wdata->ps_connected = power_raw & 0x08; |
| 608 | } |
| 609 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 610 | break; |
| 611 | default: |
| 612 | hid_err(hdev, "Unknown report: %d,%d size:%d\n", |
| 613 | data[0], data[1], size); |
| 614 | return 0; |
| 615 | } |
| 616 | } |
| 617 | return 1; |
Przemo Firszt | f6b7efc | 2011-11-05 11:28:21 +0000 | [diff] [blame] | 618 | } |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 619 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 620 | static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi, |
| 621 | struct hid_field *field, struct hid_usage *usage, unsigned long **bit, |
| 622 | int *max) |
| 623 | { |
| 624 | struct input_dev *input = hi->input; |
| 625 | |
Jiri Kosina | f6f1242 | 2011-10-25 09:58:12 +0200 | [diff] [blame] | 626 | __set_bit(INPUT_PROP_POINTER, input->propbit); |
| 627 | |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 628 | /* Basics */ |
| 629 | input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL); |
| 630 | |
| 631 | __set_bit(REL_WHEEL, input->relbit); |
| 632 | |
| 633 | __set_bit(BTN_TOOL_PEN, input->keybit); |
| 634 | __set_bit(BTN_TOUCH, input->keybit); |
| 635 | __set_bit(BTN_STYLUS, input->keybit); |
| 636 | __set_bit(BTN_STYLUS2, input->keybit); |
| 637 | __set_bit(BTN_LEFT, input->keybit); |
| 638 | __set_bit(BTN_RIGHT, input->keybit); |
| 639 | __set_bit(BTN_MIDDLE, input->keybit); |
| 640 | |
| 641 | /* Pad */ |
Przemo Firszt | 9a911da | 2012-03-14 19:55:03 +0000 | [diff] [blame] | 642 | input_set_capability(input, EV_MSC, MSC_SERIAL); |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 643 | |
| 644 | __set_bit(BTN_0, input->keybit); |
| 645 | __set_bit(BTN_1, input->keybit); |
| 646 | __set_bit(BTN_TOOL_FINGER, input->keybit); |
| 647 | |
| 648 | /* Distance, rubber and mouse */ |
| 649 | __set_bit(BTN_TOOL_RUBBER, input->keybit); |
| 650 | __set_bit(BTN_TOOL_MOUSE, input->keybit); |
| 651 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 652 | switch (hdev->product) { |
| 653 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 654 | input_set_abs_params(input, ABS_X, 0, 16704, 4, 0); |
| 655 | input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0); |
| 656 | input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0); |
| 657 | input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0); |
| 658 | break; |
| 659 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
Przemo Firszt | 7e503a3 | 2012-03-14 19:55:04 +0000 | [diff] [blame] | 660 | __set_bit(ABS_WHEEL, input->absbit); |
Przemo Firszt | 2c653e6 | 2012-02-24 13:47:48 +0000 | [diff] [blame] | 661 | __set_bit(ABS_MISC, input->absbit); |
Przemo Firszt | 6245bde | 2012-02-28 17:19:05 +0000 | [diff] [blame] | 662 | __set_bit(BTN_2, input->keybit); |
| 663 | __set_bit(BTN_3, input->keybit); |
| 664 | __set_bit(BTN_4, input->keybit); |
| 665 | __set_bit(BTN_5, input->keybit); |
| 666 | __set_bit(BTN_6, input->keybit); |
| 667 | __set_bit(BTN_7, input->keybit); |
| 668 | __set_bit(BTN_8, input->keybit); |
Przemo Firszt | 7e503a3 | 2012-03-14 19:55:04 +0000 | [diff] [blame] | 669 | input_set_abs_params(input, ABS_WHEEL, 0, 71, 0, 0); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 670 | input_set_abs_params(input, ABS_X, 0, 40640, 4, 0); |
| 671 | input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0); |
| 672 | input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0); |
Przemo Firszt | e0829e9 | 2012-02-28 17:19:04 +0000 | [diff] [blame] | 673 | input_set_abs_params(input, ABS_DISTANCE, 0, 63, 0, 0); |
Przemo Firszt | c653dab | 2012-05-04 18:00:10 +0100 | [diff] [blame] | 674 | input_set_abs_params(input, ABS_TILT_X, 0, 127, 0, 0); |
| 675 | input_set_abs_params(input, ABS_TILT_Y, 0, 127, 0, 0); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 676 | break; |
| 677 | } |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 682 | static int wacom_probe(struct hid_device *hdev, |
| 683 | const struct hid_device_id *id) |
| 684 | { |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 685 | struct wacom_data *wdata; |
| 686 | int ret; |
| 687 | |
| 688 | wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); |
| 689 | if (wdata == NULL) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 690 | hid_err(hdev, "can't alloc wacom descriptor\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 691 | return -ENOMEM; |
| 692 | } |
| 693 | |
| 694 | hid_set_drvdata(hdev, wdata); |
| 695 | |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 696 | /* Parse the HID report now */ |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 697 | ret = hid_parse(hdev); |
| 698 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 699 | hid_err(hdev, "parse failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 700 | goto err_free; |
| 701 | } |
| 702 | |
| 703 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); |
| 704 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 705 | hid_err(hdev, "hw start failed\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 706 | goto err_free; |
| 707 | } |
| 708 | |
Przemo Firszt | 20a3ce7e | 2010-03-18 14:34:34 +0000 | [diff] [blame] | 709 | ret = device_create_file(&hdev->dev, &dev_attr_speed); |
| 710 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 711 | hid_warn(hdev, |
| 712 | "can't create sysfs speed attribute err: %d\n", ret); |
Jiri Kosina | 342f31e | 2010-02-03 15:52:31 +0100 | [diff] [blame] | 713 | |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 714 | switch (hdev->product) { |
| 715 | case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH: |
| 716 | /* Set Wacom mode 2 with high reporting speed */ |
| 717 | wacom_poke(hdev, 1); |
| 718 | break; |
| 719 | case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH: |
Przemo Firszt | a72c5dd | 2012-02-17 17:47:10 +0000 | [diff] [blame] | 720 | sprintf(hdev->name, "%s", "Wacom Intuos4 WL"); |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 721 | wdata->features = 0; |
| 722 | wacom_set_features(hdev); |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 723 | ret = wacom_initialize_leds(hdev); |
| 724 | if (ret) { |
| 725 | hid_warn(hdev, |
| 726 | "can't create led attribute, err: %d\n", ret); |
| 727 | goto destroy_leds; |
| 728 | } |
Przemo Firszt | 78761ff | 2011-11-05 11:28:22 +0000 | [diff] [blame] | 729 | break; |
| 730 | } |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 731 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 732 | wdata->battery.properties = wacom_battery_props; |
| 733 | wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props); |
| 734 | wdata->battery.get_property = wacom_battery_get_property; |
| 735 | wdata->battery.name = "wacom_battery"; |
| 736 | wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 737 | wdata->battery.use_for_apm = 0; |
Bastien Nocera | 46a709b | 2010-01-20 12:00:53 +0000 | [diff] [blame] | 738 | |
Jeremy Fitzhardinge | 35b4c01 | 2011-12-09 09:35:00 -0800 | [diff] [blame] | 739 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 740 | ret = power_supply_register(&hdev->dev, &wdata->battery); |
| 741 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 742 | hid_warn(hdev, "can't create sysfs battery attribute, err: %d\n", |
| 743 | ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 744 | goto err_battery; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 745 | } |
| 746 | |
Przemo Firszt | d7cb3dbd10 | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 747 | power_supply_powers(&wdata->battery, &hdev->dev); |
| 748 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 749 | wdata->ac.properties = wacom_ac_props; |
| 750 | wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props); |
| 751 | wdata->ac.get_property = wacom_ac_get_property; |
| 752 | wdata->ac.name = "wacom_ac"; |
| 753 | wdata->ac.type = POWER_SUPPLY_TYPE_MAINS; |
| 754 | wdata->ac.use_for_apm = 0; |
| 755 | |
| 756 | ret = power_supply_register(&hdev->dev, &wdata->ac); |
| 757 | if (ret) { |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 758 | hid_warn(hdev, |
| 759 | "can't create ac battery attribute, err: %d\n", ret); |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 760 | goto err_ac; |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 761 | } |
Przemo Firszt | d7cb3dbd10 | 2012-02-05 22:35:24 +0000 | [diff] [blame] | 762 | |
| 763 | power_supply_powers(&wdata->ac, &hdev->dev); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 764 | return 0; |
Daniel Mack | 987a6c0 | 2010-08-02 20:15:17 -0700 | [diff] [blame] | 765 | |
David Herrmann | dde58cf | 2011-09-05 18:45:28 +0200 | [diff] [blame] | 766 | err_ac: |
| 767 | power_supply_unregister(&wdata->battery); |
| 768 | err_battery: |
| 769 | device_remove_file(&hdev->dev, &dev_attr_speed); |
| 770 | hid_hw_stop(hdev); |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 771 | destroy_leds: |
| 772 | wacom_destroy_leds(hdev); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 773 | err_free: |
| 774 | kfree(wdata); |
| 775 | return ret; |
| 776 | } |
| 777 | |
| 778 | static void wacom_remove(struct hid_device *hdev) |
| 779 | { |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 780 | struct wacom_data *wdata = hid_get_drvdata(hdev); |
Przemo Firszt | d13f545 | 2012-05-10 19:23:52 +0100 | [diff] [blame] | 781 | |
| 782 | wacom_destroy_leds(hdev); |
David Herrmann | 9086617 | 2011-09-05 18:45:29 +0200 | [diff] [blame] | 783 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 784 | hid_hw_stop(hdev); |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 785 | |
Przemo Firszt | 59d2334 | 2010-03-15 19:16:23 +0000 | [diff] [blame] | 786 | power_supply_unregister(&wdata->battery); |
| 787 | power_supply_unregister(&wdata->ac); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 788 | kfree(hid_get_drvdata(hdev)); |
| 789 | } |
| 790 | |
| 791 | static const struct hid_device_id wacom_devices[] = { |
| 792 | { 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] | 793 | { 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] | 794 | |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 795 | { } |
| 796 | }; |
| 797 | MODULE_DEVICE_TABLE(hid, wacom_devices); |
| 798 | |
| 799 | static struct hid_driver wacom_driver = { |
| 800 | .name = "wacom", |
| 801 | .id_table = wacom_devices, |
| 802 | .probe = wacom_probe, |
| 803 | .remove = wacom_remove, |
| 804 | .raw_event = wacom_raw_event, |
David Herrmann | 3797ef6 | 2011-10-08 23:20:17 +0200 | [diff] [blame] | 805 | .input_mapped = wacom_input_mapped, |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 806 | }; |
| 807 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 808 | static int __init wacom_init(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 809 | { |
| 810 | int ret; |
| 811 | |
| 812 | ret = hid_register_driver(&wacom_driver); |
| 813 | if (ret) |
Joe Perches | 4291ee3 | 2010-12-09 19:29:03 -0800 | [diff] [blame] | 814 | pr_err("can't register wacom driver\n"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 815 | return ret; |
| 816 | } |
| 817 | |
Peter Huewe | a24f423 | 2009-07-02 19:08:38 +0200 | [diff] [blame] | 818 | static void __exit wacom_exit(void) |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 819 | { |
| 820 | hid_unregister_driver(&wacom_driver); |
| 821 | } |
| 822 | |
| 823 | module_init(wacom_init); |
| 824 | module_exit(wacom_exit); |
Przemo Firszt | 1fa2f72 | 2012-03-28 22:13:37 +0100 | [diff] [blame] | 825 | MODULE_DESCRIPTION("Driver for Wacom Graphire Bluetooth and Wacom Intuos4 WL"); |
Bastien Nocera | ca2dcd4 | 2009-05-11 17:18:12 +0200 | [diff] [blame] | 826 | MODULE_LICENSE("GPL"); |