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