Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1 | /* |
Dmitry Torokhov | 4104d13 | 2007-05-07 16:16:29 -0400 | [diff] [blame] | 2 | * drivers/input/tablet/wacom_sys.c |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 3 | * |
Ping Cheng | 232f569 | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 4 | * USB Wacom tablet support - system specific code |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | */ |
| 13 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 14 | #include "wacom_wac.h" |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 15 | #include "wacom.h" |
Benjamin Tissoires | f54bc61 | 2014-07-24 12:52:00 -0700 | [diff] [blame] | 16 | #include <linux/hid.h> |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 17 | |
Ping Cheng | a417ea4 | 2011-08-16 00:17:56 -0700 | [diff] [blame] | 18 | #define WAC_MSG_RETRIES 5 |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 19 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 20 | #define WAC_CMD_WL_LED_CONTROL 0x03 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 21 | #define WAC_CMD_LED_CONTROL 0x20 |
| 22 | #define WAC_CMD_ICON_START 0x21 |
| 23 | #define WAC_CMD_ICON_XFER 0x23 |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 24 | #define WAC_CMD_ICON_BT_XFER 0x26 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 25 | #define WAC_CMD_RETRIES 10 |
| 26 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 27 | #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) |
| 28 | #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) |
| 29 | |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 30 | static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 31 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 32 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 33 | int retval; |
| 34 | |
| 35 | do { |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 36 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 37 | HID_REQ_GET_REPORT); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 38 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 39 | |
| 40 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 43 | static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 44 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 45 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 46 | int retval; |
| 47 | |
| 48 | do { |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 49 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 50 | HID_REQ_SET_REPORT); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 51 | } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries); |
| 52 | |
| 53 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 56 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 57 | u8 *raw_data, int size) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 58 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 59 | struct wacom *wacom = hid_get_drvdata(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 60 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 61 | if (size > WACOM_PKGLEN_MAX) |
| 62 | return 1; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 63 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 64 | memcpy(wacom->wacom_wac.data, raw_data, size); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 65 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 66 | wacom_wac_irq(&wacom->wacom_wac, size); |
| 67 | |
| 68 | return 0; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 71 | static int wacom_open(struct input_dev *dev) |
| 72 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 73 | struct wacom *wacom = input_get_drvdata(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 74 | int retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 75 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 76 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 77 | retval = hid_hw_open(wacom->hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 78 | mutex_unlock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 79 | |
Dmitry Torokhov | f6cd378 | 2010-10-04 21:46:11 -0700 | [diff] [blame] | 80 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | static void wacom_close(struct input_dev *dev) |
| 84 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 85 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 86 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 87 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 88 | hid_hw_close(wacom->hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 89 | mutex_unlock(&wacom->lock); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 92 | /* |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 93 | * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res. |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 94 | */ |
| 95 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 96 | unsigned unit, int exponent) |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 97 | { |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 98 | struct hid_field field = { |
| 99 | .logical_maximum = logical_extents, |
| 100 | .physical_maximum = physical_extents, |
| 101 | .unit = unit, |
| 102 | .unit_exponent = exponent, |
| 103 | }; |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 104 | |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 105 | return hidinput_calc_abs_res(&field, ABS_X); |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 108 | static void wacom_feature_mapping(struct hid_device *hdev, |
| 109 | struct hid_field *field, struct hid_usage *usage) |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 110 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 111 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 112 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 113 | u8 *data; |
| 114 | int ret; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 115 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 116 | switch (usage->hid) { |
| 117 | case HID_DG_CONTACTMAX: |
| 118 | /* leave touch_max as is if predefined */ |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 119 | if (!features->touch_max) { |
| 120 | /* read manually */ |
| 121 | data = kzalloc(2, GFP_KERNEL); |
| 122 | if (!data) |
| 123 | break; |
| 124 | data[0] = field->report->id; |
| 125 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
| 126 | data, 2, 0); |
| 127 | if (ret == 2) |
| 128 | features->touch_max = data[1]; |
| 129 | kfree(data); |
| 130 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 131 | break; |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 132 | } |
| 133 | } |
| 134 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 135 | /* |
| 136 | * Interface Descriptor of wacom devices can be incomplete and |
| 137 | * inconsistent so wacom_features table is used to store stylus |
| 138 | * device's packet lengths, various maximum values, and tablet |
| 139 | * resolution based on product ID's. |
| 140 | * |
| 141 | * For devices that contain 2 interfaces, wacom_features table is |
| 142 | * inaccurate for the touch interface. Since the Interface Descriptor |
| 143 | * for touch interfaces has pretty complete data, this function exists |
| 144 | * to query tablet for this missing information instead of hard coding in |
| 145 | * an additional table. |
| 146 | * |
| 147 | * A typical Interface Descriptor for a stylus will contain a |
| 148 | * boot mouse application collection that is not of interest and this |
| 149 | * function will ignore it. |
| 150 | * |
| 151 | * It also contains a digitizer application collection that also is not |
| 152 | * of interest since any information it contains would be duplicate |
| 153 | * of what is in wacom_features. Usually it defines a report of an array |
| 154 | * of bytes that could be used as max length of the stylus packet returned. |
| 155 | * If it happens to define a Digitizer-Stylus Physical Collection then |
| 156 | * the X and Y logical values contain valid data but it is ignored. |
| 157 | * |
| 158 | * A typical Interface Descriptor for a touch interface will contain a |
| 159 | * Digitizer-Finger Physical Collection which will define both logical |
| 160 | * X/Y maximum as well as the physical size of tablet. Since touch |
| 161 | * interfaces haven't supported pressure or distance, this is enough |
| 162 | * information to override invalid values in the wacom_features table. |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 163 | * |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 164 | * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful |
| 165 | * data. We deal with them after returning from this function. |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 166 | */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 167 | static void wacom_usage_mapping(struct hid_device *hdev, |
| 168 | struct hid_field *field, struct hid_usage *usage) |
| 169 | { |
| 170 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 171 | struct wacom_features *features = &wacom->wacom_wac.features; |
| 172 | bool finger = (field->logical == HID_DG_FINGER) || |
| 173 | (field->physical == HID_DG_FINGER); |
| 174 | bool pen = (field->logical == HID_DG_STYLUS) || |
| 175 | (field->physical == HID_DG_STYLUS); |
| 176 | |
| 177 | /* |
| 178 | * Requiring Stylus Usage will ignore boot mouse |
| 179 | * X/Y values and some cases of invalid Digitizer X/Y |
| 180 | * values commonly reported. |
| 181 | */ |
| 182 | if (!pen && !finger) |
| 183 | return; |
| 184 | |
| 185 | if (finger && !features->touch_max) |
| 186 | /* touch device at least supports one touch point */ |
| 187 | features->touch_max = 1; |
| 188 | |
| 189 | switch (usage->hid) { |
| 190 | case HID_GD_X: |
| 191 | features->x_max = field->logical_maximum; |
| 192 | if (finger) { |
| 193 | features->device_type = BTN_TOOL_FINGER; |
| 194 | features->x_phy = field->physical_maximum; |
| 195 | if (features->type != BAMBOO_PT) { |
| 196 | features->unit = field->unit; |
| 197 | features->unitExpo = field->unit_exponent; |
| 198 | } |
| 199 | } else { |
| 200 | features->device_type = BTN_TOOL_PEN; |
| 201 | } |
| 202 | break; |
| 203 | case HID_GD_Y: |
| 204 | features->y_max = field->logical_maximum; |
| 205 | if (finger) { |
| 206 | features->y_phy = field->physical_maximum; |
| 207 | if (features->type != BAMBOO_PT) { |
| 208 | features->unit = field->unit; |
| 209 | features->unitExpo = field->unit_exponent; |
| 210 | } |
| 211 | } |
| 212 | break; |
| 213 | case HID_DG_TIPPRESSURE: |
| 214 | if (pen) |
| 215 | features->pressure_max = field->logical_maximum; |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | static void wacom_parse_hid(struct hid_device *hdev, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 221 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 222 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 223 | struct hid_report_enum *rep_enum; |
| 224 | struct hid_report *hreport; |
| 225 | int i, j; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 226 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 227 | /* check features first */ |
| 228 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; |
| 229 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 230 | for (i = 0; i < hreport->maxfield; i++) { |
| 231 | /* Ignore if report count is out of bounds. */ |
| 232 | if (hreport->field[i]->report_count < 1) |
| 233 | continue; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 234 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 235 | for (j = 0; j < hreport->field[i]->maxusage; j++) { |
| 236 | wacom_feature_mapping(hdev, hreport->field[i], |
| 237 | hreport->field[i]->usage + j); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 238 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 242 | /* now check the input usages */ |
| 243 | rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
| 244 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 245 | |
| 246 | if (!hreport->maxfield) |
| 247 | continue; |
| 248 | |
| 249 | for (i = 0; i < hreport->maxfield; i++) |
| 250 | for (j = 0; j < hreport->field[i]->maxusage; j++) |
| 251 | wacom_usage_mapping(hdev, hreport->field[i], |
| 252 | hreport->field[i]->usage + j); |
| 253 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 254 | } |
| 255 | |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 256 | static int wacom_set_device_mode(struct hid_device *hdev, int report_id, |
| 257 | int length, int mode) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 258 | { |
| 259 | unsigned char *rep_data; |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 260 | int error = -ENOMEM, limit = 0; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 261 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 262 | rep_data = kzalloc(length, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 263 | if (!rep_data) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 264 | return error; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 265 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 266 | do { |
Chris Bagwell | 9937c02 | 2013-01-23 19:37:34 -0800 | [diff] [blame] | 267 | rep_data[0] = report_id; |
| 268 | rep_data[1] = mode; |
| 269 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 270 | error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, |
| 271 | length, 1); |
Benjamin Tissoires | 3cb8315 | 2014-07-24 12:47:47 -0700 | [diff] [blame] | 272 | if (error >= 0) |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 273 | error = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 274 | rep_data, length, 1); |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 275 | } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 276 | |
| 277 | kfree(rep_data); |
| 278 | |
| 279 | return error < 0 ? error : 0; |
| 280 | } |
| 281 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 282 | static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, |
| 283 | struct wacom_features *features) |
| 284 | { |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 285 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 286 | int ret; |
| 287 | u8 rep_data[2]; |
| 288 | |
| 289 | switch (features->type) { |
| 290 | case GRAPHIRE_BT: |
| 291 | rep_data[0] = 0x03; |
| 292 | rep_data[1] = 0x00; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 293 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 294 | 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 295 | |
| 296 | if (ret >= 0) { |
| 297 | rep_data[0] = speed == 0 ? 0x05 : 0x06; |
| 298 | rep_data[1] = 0x00; |
| 299 | |
| 300 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 301 | rep_data, 2, 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 302 | |
| 303 | if (ret >= 0) { |
| 304 | wacom->wacom_wac.bt_high_speed = speed; |
| 305 | return 0; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * Note that if the raw queries fail, it's not a hard failure |
| 311 | * and it is safe to continue |
| 312 | */ |
| 313 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 314 | rep_data[0], ret); |
| 315 | break; |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 316 | case INTUOS4WL: |
| 317 | if (speed == 1) |
| 318 | wacom->wacom_wac.bt_features &= ~0x20; |
| 319 | else |
| 320 | wacom->wacom_wac.bt_features |= 0x20; |
| 321 | |
| 322 | rep_data[0] = 0x03; |
| 323 | rep_data[1] = wacom->wacom_wac.bt_features; |
| 324 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 325 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 326 | 1); |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 327 | if (ret >= 0) |
| 328 | wacom->wacom_wac.bt_high_speed = speed; |
| 329 | break; |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 332 | return 0; |
| 333 | } |
| 334 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 335 | /* |
| 336 | * Switch the tablet into its most-capable mode. Wacom tablets are |
| 337 | * typically configured to power-up in a mode which sends mouse-like |
| 338 | * reports to the OS. To get absolute position, pressure data, etc. |
| 339 | * from the tablet, it is necessary to switch the tablet out of this |
| 340 | * mode and into one which sends the full range of tablet data. |
| 341 | */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 342 | static int wacom_query_tablet_data(struct hid_device *hdev, |
| 343 | struct wacom_features *features) |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 344 | { |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 345 | if (hdev->bus == BUS_BLUETOOTH) |
| 346 | return wacom_bt_query_tablet_data(hdev, 1, features); |
| 347 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 348 | if (features->device_type == BTN_TOOL_FINGER) { |
| 349 | if (features->type > TABLETPC) { |
| 350 | /* MT Tablet PC touch */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 351 | return wacom_set_device_mode(hdev, 3, 4, 4); |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 352 | } |
Jason Gerecke | 36d3c51 | 2013-09-20 09:47:35 -0700 | [diff] [blame] | 353 | else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 354 | return wacom_set_device_mode(hdev, 18, 3, 2); |
Jason Gerecke | b1e4279 | 2012-10-21 00:38:04 -0700 | [diff] [blame] | 355 | } |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 356 | } else if (features->device_type == BTN_TOOL_PEN) { |
| 357 | if (features->type <= BAMBOO_PT && features->type != WIRELESS) { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 358 | return wacom_set_device_mode(hdev, 2, 2, 2); |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 359 | } |
| 360 | } |
| 361 | |
| 362 | return 0; |
| 363 | } |
| 364 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 365 | static void wacom_retrieve_hid_descriptor(struct hid_device *hdev, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 366 | struct wacom_features *features) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 367 | { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 368 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 369 | struct usb_interface *intf = wacom->intf; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 370 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 371 | /* default features */ |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 372 | features->device_type = BTN_TOOL_PEN; |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 373 | features->x_fuzz = 4; |
| 374 | features->y_fuzz = 4; |
| 375 | features->pressure_fuzz = 0; |
| 376 | features->distance_fuzz = 0; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 377 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 378 | /* |
| 379 | * The wireless device HID is basic and layout conflicts with |
| 380 | * other tablets (monitor and touch interface can look like pen). |
| 381 | * Skip the query for this type and modify defaults based on |
| 382 | * interface number. |
| 383 | */ |
| 384 | if (features->type == WIRELESS) { |
| 385 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) { |
| 386 | features->device_type = 0; |
| 387 | } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) { |
Ping Cheng | adad004 | 2012-06-28 16:48:17 -0700 | [diff] [blame] | 388 | features->device_type = BTN_TOOL_FINGER; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 389 | features->pktlen = WACOM_PKGLEN_BBTOUCH3; |
| 390 | } |
| 391 | } |
| 392 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 393 | /* only devices that support touch need to retrieve the info */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 394 | if (features->type < BAMBOO_PT) |
| 395 | return; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 396 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 397 | wacom_parse_hid(hdev, features); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 398 | } |
| 399 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 400 | struct wacom_hdev_data { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 401 | struct list_head list; |
| 402 | struct kref kref; |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 403 | struct hid_device *dev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 404 | struct wacom_shared shared; |
| 405 | }; |
| 406 | |
| 407 | static LIST_HEAD(wacom_udev_list); |
| 408 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 409 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 410 | static bool wacom_are_sibling(struct hid_device *hdev, |
| 411 | struct hid_device *sibling) |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 412 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 413 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 414 | struct wacom_features *features = &wacom->wacom_wac.features; |
| 415 | int vid = features->oVid; |
| 416 | int pid = features->oPid; |
| 417 | int n1,n2; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 418 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 419 | if (vid == 0 && pid == 0) { |
| 420 | vid = hdev->vendor; |
| 421 | pid = hdev->product; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 422 | } |
| 423 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 424 | if (vid != sibling->vendor || pid != sibling->product) |
| 425 | return false; |
| 426 | |
| 427 | /* Compare the physical path. */ |
| 428 | n1 = strrchr(hdev->phys, '.') - hdev->phys; |
| 429 | n2 = strrchr(sibling->phys, '.') - sibling->phys; |
| 430 | if (n1 != n2 || n1 <= 0 || n2 <= 0) |
| 431 | return false; |
| 432 | |
| 433 | return !strncmp(hdev->phys, sibling->phys, n1); |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 436 | static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 437 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 438 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 439 | |
| 440 | list_for_each_entry(data, &wacom_udev_list, list) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 441 | if (wacom_are_sibling(hdev, data->dev)) { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 442 | kref_get(&data->kref); |
| 443 | return data; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | return NULL; |
| 448 | } |
| 449 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 450 | static int wacom_add_shared_data(struct hid_device *hdev) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 451 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 452 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 453 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 454 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 455 | int retval = 0; |
| 456 | |
| 457 | mutex_lock(&wacom_udev_list_lock); |
| 458 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 459 | data = wacom_get_hdev_data(hdev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 460 | if (!data) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 461 | data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 462 | if (!data) { |
| 463 | retval = -ENOMEM; |
| 464 | goto out; |
| 465 | } |
| 466 | |
| 467 | kref_init(&data->kref); |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 468 | data->dev = hdev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 469 | list_add_tail(&data->list, &wacom_udev_list); |
| 470 | } |
| 471 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 472 | wacom_wac->shared = &data->shared; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 473 | |
| 474 | out: |
| 475 | mutex_unlock(&wacom_udev_list_lock); |
| 476 | return retval; |
| 477 | } |
| 478 | |
| 479 | static void wacom_release_shared_data(struct kref *kref) |
| 480 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 481 | struct wacom_hdev_data *data = |
| 482 | container_of(kref, struct wacom_hdev_data, kref); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 483 | |
| 484 | mutex_lock(&wacom_udev_list_lock); |
| 485 | list_del(&data->list); |
| 486 | mutex_unlock(&wacom_udev_list_lock); |
| 487 | |
| 488 | kfree(data); |
| 489 | } |
| 490 | |
| 491 | static void wacom_remove_shared_data(struct wacom_wac *wacom) |
| 492 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 493 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 494 | |
| 495 | if (wacom->shared) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 496 | data = container_of(wacom->shared, struct wacom_hdev_data, shared); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 497 | kref_put(&data->kref, wacom_release_shared_data); |
| 498 | wacom->shared = NULL; |
| 499 | } |
| 500 | } |
| 501 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 502 | static int wacom_led_control(struct wacom *wacom) |
| 503 | { |
| 504 | unsigned char *buf; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 505 | int retval; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 506 | unsigned char report_id = WAC_CMD_LED_CONTROL; |
| 507 | int buf_size = 9; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 508 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 509 | if (wacom->wacom_wac.pid) { /* wireless connected */ |
| 510 | report_id = WAC_CMD_WL_LED_CONTROL; |
| 511 | buf_size = 13; |
| 512 | } |
| 513 | buf = kzalloc(buf_size, GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 514 | if (!buf) |
| 515 | return -ENOMEM; |
| 516 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 517 | if (wacom->wacom_wac.features.type >= INTUOS5S && |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 518 | wacom->wacom_wac.features.type <= INTUOSPL) { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 519 | /* |
| 520 | * Touch Ring and crop mark LED luminance may take on |
| 521 | * one of four values: |
| 522 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off |
| 523 | */ |
| 524 | int ring_led = wacom->led.select[0] & 0x03; |
| 525 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; |
| 526 | int crop_lum = 0; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 527 | unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 528 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 529 | buf[0] = report_id; |
| 530 | if (wacom->wacom_wac.pid) { |
| 531 | wacom_get_report(wacom->hdev, HID_FEATURE_REPORT, |
| 532 | buf, buf_size, WAC_CMD_RETRIES); |
| 533 | buf[0] = report_id; |
| 534 | buf[4] = led_bits; |
| 535 | } else |
| 536 | buf[1] = led_bits; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 537 | } |
| 538 | else { |
| 539 | int led = wacom->led.select[0] | 0x4; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 540 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 541 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || |
| 542 | wacom->wacom_wac.features.type == WACOM_24HD) |
| 543 | led |= (wacom->led.select[1] << 4) | 0x40; |
| 544 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 545 | buf[0] = report_id; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 546 | buf[1] = led; |
| 547 | buf[2] = wacom->led.llv; |
| 548 | buf[3] = wacom->led.hlv; |
| 549 | buf[4] = wacom->led.img_lum; |
| 550 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 551 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 552 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 553 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 554 | kfree(buf); |
| 555 | |
| 556 | return retval; |
| 557 | } |
| 558 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 559 | static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id, |
| 560 | const unsigned len, const void *img) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 561 | { |
| 562 | unsigned char *buf; |
| 563 | int i, retval; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 564 | const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 565 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 566 | buf = kzalloc(chunk_len + 3 , GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 567 | if (!buf) |
| 568 | return -ENOMEM; |
| 569 | |
| 570 | /* Send 'start' command */ |
| 571 | buf[0] = WAC_CMD_ICON_START; |
| 572 | buf[1] = 1; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 573 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 574 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 575 | if (retval < 0) |
| 576 | goto out; |
| 577 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 578 | buf[0] = xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 579 | buf[1] = button_id & 0x07; |
| 580 | for (i = 0; i < 4; i++) { |
| 581 | buf[2] = i; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 582 | memcpy(buf + 3, img + i * chunk_len, chunk_len); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 583 | |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 584 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 585 | buf, chunk_len + 3, WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 586 | if (retval < 0) |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | /* Send 'stop' */ |
| 591 | buf[0] = WAC_CMD_ICON_START; |
| 592 | buf[1] = 0; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 593 | wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 594 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 595 | |
| 596 | out: |
| 597 | kfree(buf); |
| 598 | return retval; |
| 599 | } |
| 600 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 601 | static ssize_t wacom_led_select_store(struct device *dev, int set_id, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 602 | const char *buf, size_t count) |
| 603 | { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 604 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 605 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 606 | unsigned int id; |
| 607 | int err; |
| 608 | |
| 609 | err = kstrtouint(buf, 10, &id); |
| 610 | if (err) |
| 611 | return err; |
| 612 | |
| 613 | mutex_lock(&wacom->lock); |
| 614 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 615 | wacom->led.select[set_id] = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 616 | err = wacom_led_control(wacom); |
| 617 | |
| 618 | mutex_unlock(&wacom->lock); |
| 619 | |
| 620 | return err < 0 ? err : count; |
| 621 | } |
| 622 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 623 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 624 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 625 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 626 | { \ |
| 627 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 628 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 629 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 630 | struct device_attribute *attr, char *buf) \ |
| 631 | { \ |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 632 | struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 633 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 634 | return scnprintf(buf, PAGE_SIZE, "%d\n", \ |
| 635 | wacom->led.select[SET_ID]); \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 636 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 637 | static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 638 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 639 | wacom_led##SET_ID##_select_store) |
| 640 | |
| 641 | DEVICE_LED_SELECT_ATTR(0); |
| 642 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 643 | |
| 644 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 645 | const char *buf, size_t count) |
| 646 | { |
| 647 | unsigned int value; |
| 648 | int err; |
| 649 | |
| 650 | err = kstrtouint(buf, 10, &value); |
| 651 | if (err) |
| 652 | return err; |
| 653 | |
| 654 | mutex_lock(&wacom->lock); |
| 655 | |
| 656 | *dest = value & 0x7f; |
| 657 | err = wacom_led_control(wacom); |
| 658 | |
| 659 | mutex_unlock(&wacom->lock); |
| 660 | |
| 661 | return err < 0 ? err : count; |
| 662 | } |
| 663 | |
| 664 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 665 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 666 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 667 | { \ |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 668 | struct hid_device *hdev = container_of(dev, struct hid_device, dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 669 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 670 | \ |
| 671 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 672 | buf, count); \ |
| 673 | } \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 674 | static ssize_t wacom_##name##_luminance_show(struct device *dev, \ |
| 675 | struct device_attribute *attr, char *buf) \ |
| 676 | { \ |
| 677 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 678 | return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \ |
| 679 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 680 | static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 681 | wacom_##name##_luminance_show, \ |
| 682 | wacom_##name##_luminance_store) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 683 | |
| 684 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 685 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 686 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 687 | |
| 688 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 689 | const char *buf, size_t count) |
| 690 | { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 691 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 692 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 693 | int err; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 694 | unsigned len; |
| 695 | u8 xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 696 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 697 | if (hdev->bus == BUS_BLUETOOTH) { |
| 698 | len = 256; |
| 699 | xfer_id = WAC_CMD_ICON_BT_XFER; |
| 700 | } else { |
| 701 | len = 1024; |
| 702 | xfer_id = WAC_CMD_ICON_XFER; |
| 703 | } |
| 704 | |
| 705 | if (count != len) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | |
| 708 | mutex_lock(&wacom->lock); |
| 709 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 710 | err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 711 | |
| 712 | mutex_unlock(&wacom->lock); |
| 713 | |
| 714 | return err < 0 ? err : count; |
| 715 | } |
| 716 | |
| 717 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 718 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 719 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 720 | { \ |
| 721 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 722 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 723 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 724 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 725 | |
| 726 | DEVICE_BTNIMG_ATTR(0); |
| 727 | DEVICE_BTNIMG_ATTR(1); |
| 728 | DEVICE_BTNIMG_ATTR(2); |
| 729 | DEVICE_BTNIMG_ATTR(3); |
| 730 | DEVICE_BTNIMG_ATTR(4); |
| 731 | DEVICE_BTNIMG_ATTR(5); |
| 732 | DEVICE_BTNIMG_ATTR(6); |
| 733 | DEVICE_BTNIMG_ATTR(7); |
| 734 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 735 | static struct attribute *cintiq_led_attrs[] = { |
| 736 | &dev_attr_status_led0_select.attr, |
| 737 | &dev_attr_status_led1_select.attr, |
| 738 | NULL |
| 739 | }; |
| 740 | |
| 741 | static struct attribute_group cintiq_led_attr_group = { |
| 742 | .name = "wacom_led", |
| 743 | .attrs = cintiq_led_attrs, |
| 744 | }; |
| 745 | |
| 746 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 747 | &dev_attr_status0_luminance.attr, |
| 748 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 749 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 750 | &dev_attr_buttons_luminance.attr, |
| 751 | &dev_attr_button0_rawimg.attr, |
| 752 | &dev_attr_button1_rawimg.attr, |
| 753 | &dev_attr_button2_rawimg.attr, |
| 754 | &dev_attr_button3_rawimg.attr, |
| 755 | &dev_attr_button4_rawimg.attr, |
| 756 | &dev_attr_button5_rawimg.attr, |
| 757 | &dev_attr_button6_rawimg.attr, |
| 758 | &dev_attr_button7_rawimg.attr, |
| 759 | NULL |
| 760 | }; |
| 761 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 762 | static struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 763 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 764 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 765 | }; |
| 766 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 767 | static struct attribute *intuos5_led_attrs[] = { |
| 768 | &dev_attr_status0_luminance.attr, |
| 769 | &dev_attr_status_led0_select.attr, |
| 770 | NULL |
| 771 | }; |
| 772 | |
| 773 | static struct attribute_group intuos5_led_attr_group = { |
| 774 | .name = "wacom_led", |
| 775 | .attrs = intuos5_led_attrs, |
| 776 | }; |
| 777 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 778 | static int wacom_initialize_leds(struct wacom *wacom) |
| 779 | { |
| 780 | int error; |
| 781 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 782 | /* Initialize default values */ |
| 783 | switch (wacom->wacom_wac.features.type) { |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 784 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 785 | case INTUOS4: |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 786 | case INTUOS4WL: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 787 | case INTUOS4L: |
| 788 | wacom->led.select[0] = 0; |
| 789 | wacom->led.select[1] = 0; |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 790 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 791 | wacom->led.hlv = 20; |
| 792 | wacom->led.img_lum = 10; |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 793 | error = sysfs_create_group(&wacom->hdev->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 794 | &intuos4_led_attr_group); |
| 795 | break; |
| 796 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 797 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 798 | case WACOM_21UX2: |
| 799 | wacom->led.select[0] = 0; |
| 800 | wacom->led.select[1] = 0; |
| 801 | wacom->led.llv = 0; |
| 802 | wacom->led.hlv = 0; |
| 803 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 804 | |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 805 | error = sysfs_create_group(&wacom->hdev->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 806 | &cintiq_led_attr_group); |
| 807 | break; |
| 808 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 809 | case INTUOS5S: |
| 810 | case INTUOS5: |
| 811 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 812 | case INTUOSPS: |
| 813 | case INTUOSPM: |
| 814 | case INTUOSPL: |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 815 | if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) { |
| 816 | wacom->led.select[0] = 0; |
| 817 | wacom->led.select[1] = 0; |
| 818 | wacom->led.llv = 32; |
| 819 | wacom->led.hlv = 0; |
| 820 | wacom->led.img_lum = 0; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 821 | |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 822 | error = sysfs_create_group(&wacom->hdev->dev.kobj, |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 823 | &intuos5_led_attr_group); |
| 824 | } else |
| 825 | return 0; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 826 | break; |
| 827 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 828 | default: |
| 829 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 830 | } |
| 831 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 832 | if (error) { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 833 | hid_err(wacom->hdev, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 834 | "cannot create sysfs group err: %d\n", error); |
| 835 | return error; |
| 836 | } |
| 837 | wacom_led_control(wacom); |
Benjamin Tissoires | c757cba | 2014-07-24 13:16:17 -0700 | [diff] [blame] | 838 | wacom->led_initialized = true; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 839 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 840 | return 0; |
| 841 | } |
| 842 | |
| 843 | static void wacom_destroy_leds(struct wacom *wacom) |
| 844 | { |
Benjamin Tissoires | c757cba | 2014-07-24 13:16:17 -0700 | [diff] [blame] | 845 | if (!wacom->led_initialized) |
| 846 | return; |
| 847 | |
| 848 | wacom->led_initialized = false; |
| 849 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 850 | switch (wacom->wacom_wac.features.type) { |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 851 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 852 | case INTUOS4: |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 853 | case INTUOS4WL: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 854 | case INTUOS4L: |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 855 | sysfs_remove_group(&wacom->hdev->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 856 | &intuos4_led_attr_group); |
| 857 | break; |
| 858 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 859 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 860 | case WACOM_21UX2: |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 861 | sysfs_remove_group(&wacom->hdev->dev.kobj, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 862 | &cintiq_led_attr_group); |
| 863 | break; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 864 | |
| 865 | case INTUOS5S: |
| 866 | case INTUOS5: |
| 867 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 868 | case INTUOSPS: |
| 869 | case INTUOSPM: |
| 870 | case INTUOSPL: |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 871 | if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 872 | sysfs_remove_group(&wacom->hdev->dev.kobj, |
Ping Cheng | c2b0c27 | 2013-09-20 09:50:14 -0700 | [diff] [blame] | 873 | &intuos5_led_attr_group); |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 874 | break; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 875 | } |
| 876 | } |
| 877 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 878 | static enum power_supply_property wacom_battery_props[] = { |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 879 | POWER_SUPPLY_PROP_STATUS, |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 880 | POWER_SUPPLY_PROP_SCOPE, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 881 | POWER_SUPPLY_PROP_CAPACITY |
| 882 | }; |
| 883 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 884 | static enum power_supply_property wacom_ac_props[] = { |
| 885 | POWER_SUPPLY_PROP_PRESENT, |
| 886 | POWER_SUPPLY_PROP_ONLINE, |
| 887 | POWER_SUPPLY_PROP_SCOPE, |
| 888 | }; |
| 889 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 890 | static int wacom_battery_get_property(struct power_supply *psy, |
| 891 | enum power_supply_property psp, |
| 892 | union power_supply_propval *val) |
| 893 | { |
| 894 | struct wacom *wacom = container_of(psy, struct wacom, battery); |
| 895 | int ret = 0; |
| 896 | |
| 897 | switch (psp) { |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 898 | case POWER_SUPPLY_PROP_SCOPE: |
| 899 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 900 | break; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 901 | case POWER_SUPPLY_PROP_CAPACITY: |
| 902 | val->intval = |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 903 | wacom->wacom_wac.battery_capacity; |
| 904 | break; |
| 905 | case POWER_SUPPLY_PROP_STATUS: |
| 906 | if (wacom->wacom_wac.bat_charging) |
| 907 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
| 908 | else if (wacom->wacom_wac.battery_capacity == 100 && |
| 909 | wacom->wacom_wac.ps_connected) |
| 910 | val->intval = POWER_SUPPLY_STATUS_FULL; |
| 911 | else |
| 912 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 913 | break; |
| 914 | default: |
| 915 | ret = -EINVAL; |
| 916 | break; |
| 917 | } |
| 918 | |
| 919 | return ret; |
| 920 | } |
| 921 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 922 | static int wacom_ac_get_property(struct power_supply *psy, |
| 923 | enum power_supply_property psp, |
| 924 | union power_supply_propval *val) |
| 925 | { |
| 926 | struct wacom *wacom = container_of(psy, struct wacom, ac); |
| 927 | int ret = 0; |
| 928 | |
| 929 | switch (psp) { |
| 930 | case POWER_SUPPLY_PROP_PRESENT: |
| 931 | /* fall through */ |
| 932 | case POWER_SUPPLY_PROP_ONLINE: |
| 933 | val->intval = wacom->wacom_wac.ps_connected; |
| 934 | break; |
| 935 | case POWER_SUPPLY_PROP_SCOPE: |
| 936 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 937 | break; |
| 938 | default: |
| 939 | ret = -EINVAL; |
| 940 | break; |
| 941 | } |
| 942 | return ret; |
| 943 | } |
| 944 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 945 | static int wacom_initialize_battery(struct wacom *wacom) |
| 946 | { |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 947 | static atomic_t battery_no = ATOMIC_INIT(0); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 948 | int error; |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 949 | unsigned long n; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 950 | |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 951 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) { |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 952 | n = atomic_inc_return(&battery_no) - 1; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 953 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 954 | wacom->battery.properties = wacom_battery_props; |
| 955 | wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props); |
| 956 | wacom->battery.get_property = wacom_battery_get_property; |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 957 | sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n); |
| 958 | wacom->battery.name = wacom->wacom_wac.bat_name; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 959 | wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY; |
| 960 | wacom->battery.use_for_apm = 0; |
| 961 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 962 | wacom->ac.properties = wacom_ac_props; |
| 963 | wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props); |
| 964 | wacom->ac.get_property = wacom_ac_get_property; |
| 965 | sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n); |
| 966 | wacom->ac.name = wacom->wacom_wac.ac_name; |
| 967 | wacom->ac.type = POWER_SUPPLY_TYPE_MAINS; |
| 968 | wacom->ac.use_for_apm = 0; |
| 969 | |
Benjamin Tissoires | dd3181a | 2014-07-24 13:01:40 -0700 | [diff] [blame] | 970 | error = power_supply_register(&wacom->hdev->dev, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 971 | &wacom->battery); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 972 | if (error) |
| 973 | return error; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 974 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 975 | power_supply_powers(&wacom->battery, &wacom->hdev->dev); |
| 976 | |
| 977 | error = power_supply_register(&wacom->hdev->dev, &wacom->ac); |
| 978 | if (error) { |
| 979 | power_supply_unregister(&wacom->battery); |
| 980 | return error; |
| 981 | } |
| 982 | |
| 983 | power_supply_powers(&wacom->ac, &wacom->hdev->dev); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 984 | } |
| 985 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 986 | return 0; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | static void wacom_destroy_battery(struct wacom *wacom) |
| 990 | { |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 991 | if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
| 992 | wacom->battery.dev) { |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 993 | power_supply_unregister(&wacom->battery); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 994 | wacom->battery.dev = NULL; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 995 | power_supply_unregister(&wacom->ac); |
| 996 | wacom->ac.dev = NULL; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 997 | } |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 998 | } |
| 999 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1000 | static ssize_t wacom_show_speed(struct device *dev, |
| 1001 | struct device_attribute |
| 1002 | *attr, char *buf) |
| 1003 | { |
| 1004 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1005 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1006 | |
| 1007 | return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed); |
| 1008 | } |
| 1009 | |
| 1010 | static ssize_t wacom_store_speed(struct device *dev, |
| 1011 | struct device_attribute *attr, |
| 1012 | const char *buf, size_t count) |
| 1013 | { |
| 1014 | struct hid_device *hdev = container_of(dev, struct hid_device, dev); |
| 1015 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1016 | u8 new_speed; |
| 1017 | |
| 1018 | if (kstrtou8(buf, 0, &new_speed)) |
| 1019 | return -EINVAL; |
| 1020 | |
| 1021 | if (new_speed != 0 && new_speed != 1) |
| 1022 | return -EINVAL; |
| 1023 | |
| 1024 | wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features); |
| 1025 | |
| 1026 | return count; |
| 1027 | } |
| 1028 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1029 | static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM, |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1030 | wacom_show_speed, wacom_store_speed); |
| 1031 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1032 | static struct input_dev *wacom_allocate_input(struct wacom *wacom) |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1033 | { |
| 1034 | struct input_dev *input_dev; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1035 | struct hid_device *hdev = wacom->hdev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1036 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1037 | |
| 1038 | input_dev = input_allocate_device(); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1039 | if (!input_dev) |
| 1040 | return NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1041 | |
| 1042 | input_dev->name = wacom_wac->name; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1043 | input_dev->phys = hdev->phys; |
| 1044 | input_dev->dev.parent = &hdev->dev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1045 | input_dev->open = wacom_open; |
| 1046 | input_dev->close = wacom_close; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1047 | input_dev->uniq = hdev->uniq; |
| 1048 | input_dev->id.bustype = hdev->bus; |
| 1049 | input_dev->id.vendor = hdev->vendor; |
Benjamin Tissoires | 12969e3 | 2014-09-11 13:14:04 -0400 | [diff] [blame] | 1050 | input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1051 | input_dev->id.version = hdev->version; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1052 | input_set_drvdata(input_dev, wacom); |
| 1053 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1054 | return input_dev; |
| 1055 | } |
| 1056 | |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1057 | static void wacom_unregister_inputs(struct wacom *wacom) |
| 1058 | { |
| 1059 | if (wacom->wacom_wac.input) |
| 1060 | input_unregister_device(wacom->wacom_wac.input); |
| 1061 | if (wacom->wacom_wac.pad_input) |
| 1062 | input_unregister_device(wacom->wacom_wac.pad_input); |
| 1063 | wacom->wacom_wac.input = NULL; |
| 1064 | wacom->wacom_wac.pad_input = NULL; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 1065 | wacom_destroy_leds(wacom); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | static int wacom_register_inputs(struct wacom *wacom) |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1069 | { |
| 1070 | struct input_dev *input_dev, *pad_input_dev; |
| 1071 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
| 1072 | int error; |
| 1073 | |
| 1074 | input_dev = wacom_allocate_input(wacom); |
| 1075 | pad_input_dev = wacom_allocate_input(wacom); |
| 1076 | if (!input_dev || !pad_input_dev) { |
| 1077 | error = -ENOMEM; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1078 | goto fail_allocate_input; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1081 | wacom_wac->input = input_dev; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1082 | wacom_wac->pad_input = pad_input_dev; |
| 1083 | wacom_wac->pad_input->name = wacom_wac->pad_name; |
| 1084 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1085 | error = wacom_setup_input_capabilities(input_dev, wacom_wac); |
| 1086 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1087 | goto fail_input_cap; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1088 | |
| 1089 | error = input_register_device(input_dev); |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1090 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1091 | goto fail_register_input; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1092 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1093 | error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); |
| 1094 | if (error) { |
| 1095 | /* no pad in use on this interface */ |
| 1096 | input_free_device(pad_input_dev); |
| 1097 | wacom_wac->pad_input = NULL; |
| 1098 | pad_input_dev = NULL; |
| 1099 | } else { |
| 1100 | error = input_register_device(pad_input_dev); |
| 1101 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1102 | goto fail_register_pad_input; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 1103 | |
| 1104 | error = wacom_initialize_leds(wacom); |
| 1105 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1106 | goto fail_leds; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1109 | return 0; |
| 1110 | |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1111 | fail_leds: |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 1112 | input_unregister_device(pad_input_dev); |
| 1113 | pad_input_dev = NULL; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1114 | fail_register_pad_input: |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1115 | input_unregister_device(input_dev); |
| 1116 | input_dev = NULL; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1117 | fail_register_input: |
| 1118 | fail_input_cap: |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1119 | wacom_wac->input = NULL; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1120 | wacom_wac->pad_input = NULL; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1121 | fail_allocate_input: |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1122 | if (input_dev) |
| 1123 | input_free_device(input_dev); |
| 1124 | if (pad_input_dev) |
| 1125 | input_free_device(pad_input_dev); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1126 | return error; |
| 1127 | } |
| 1128 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1129 | static void wacom_wireless_work(struct work_struct *work) |
| 1130 | { |
| 1131 | struct wacom *wacom = container_of(work, struct wacom, work); |
| 1132 | struct usb_device *usbdev = wacom->usbdev; |
| 1133 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1134 | struct hid_device *hdev1, *hdev2; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1135 | struct wacom *wacom1, *wacom2; |
| 1136 | struct wacom_wac *wacom_wac1, *wacom_wac2; |
| 1137 | int error; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1138 | |
| 1139 | /* |
| 1140 | * Regardless if this is a disconnect or a new tablet, |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1141 | * remove any existing input and battery devices. |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1142 | */ |
| 1143 | |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1144 | wacom_destroy_battery(wacom); |
| 1145 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1146 | /* Stylus interface */ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1147 | hdev1 = usb_get_intfdata(usbdev->config->interface[1]); |
| 1148 | wacom1 = hid_get_drvdata(hdev1); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1149 | wacom_wac1 = &(wacom1->wacom_wac); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1150 | wacom_unregister_inputs(wacom1); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1151 | |
| 1152 | /* Touch interface */ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1153 | hdev2 = usb_get_intfdata(usbdev->config->interface[2]); |
| 1154 | wacom2 = hid_get_drvdata(hdev2); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1155 | wacom_wac2 = &(wacom2->wacom_wac); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1156 | wacom_unregister_inputs(wacom2); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1157 | |
| 1158 | if (wacom_wac->pid == 0) { |
Benjamin Tissoires | e2114ce | 2014-07-24 13:01:56 -0700 | [diff] [blame] | 1159 | hid_info(wacom->hdev, "wireless tablet disconnected\n"); |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1160 | wacom_wac1->shared->type = 0; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1161 | } else { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1162 | const struct hid_device_id *id = wacom_ids; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1163 | |
Benjamin Tissoires | e2114ce | 2014-07-24 13:01:56 -0700 | [diff] [blame] | 1164 | hid_info(wacom->hdev, "wireless tablet connected with PID %x\n", |
Dmitry Torokhov | eb71d1b | 2012-05-02 00:13:38 -0700 | [diff] [blame] | 1165 | wacom_wac->pid); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1166 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1167 | while (id->bus) { |
| 1168 | if (id->vendor == USB_VENDOR_ID_WACOM && |
| 1169 | id->product == wacom_wac->pid) |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1170 | break; |
| 1171 | id++; |
| 1172 | } |
| 1173 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1174 | if (!id->bus) { |
Benjamin Tissoires | e2114ce | 2014-07-24 13:01:56 -0700 | [diff] [blame] | 1175 | hid_info(wacom->hdev, "ignoring unknown PID.\n"); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | /* Stylus interface */ |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1180 | wacom_wac1->features = |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1181 | *((struct wacom_features *)id->driver_data); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1182 | wacom_wac1->features.device_type = BTN_TOOL_PEN; |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1183 | snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen", |
| 1184 | wacom_wac1->features.name); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1185 | snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad", |
| 1186 | wacom_wac1->features.name); |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1187 | wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max; |
| 1188 | wacom_wac1->shared->type = wacom_wac1->features.type; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 1189 | wacom_wac1->pid = wacom_wac->pid; |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1190 | error = wacom_register_inputs(wacom1); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1191 | if (error) |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1192 | goto fail; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1193 | |
| 1194 | /* Touch interface */ |
Ping Cheng | b5fd2a3 | 2013-11-25 18:44:55 -0800 | [diff] [blame] | 1195 | if (wacom_wac1->features.touch_max || |
| 1196 | wacom_wac1->features.type == INTUOSHT) { |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1197 | wacom_wac2->features = |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1198 | *((struct wacom_features *)id->driver_data); |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1199 | wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3; |
| 1200 | wacom_wac2->features.device_type = BTN_TOOL_FINGER; |
| 1201 | wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096; |
| 1202 | if (wacom_wac2->features.touch_max) |
| 1203 | snprintf(wacom_wac2->name, WACOM_NAME_MAX, |
| 1204 | "%s (WL) Finger",wacom_wac2->features.name); |
| 1205 | else |
| 1206 | snprintf(wacom_wac2->name, WACOM_NAME_MAX, |
| 1207 | "%s (WL) Pad",wacom_wac2->features.name); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1208 | snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX, |
| 1209 | "%s (WL) Pad", wacom_wac2->features.name); |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 1210 | wacom_wac2->pid = wacom_wac->pid; |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1211 | error = wacom_register_inputs(wacom2); |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1212 | if (error) |
| 1213 | goto fail; |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1214 | |
| 1215 | if (wacom_wac1->features.type == INTUOSHT && |
| 1216 | wacom_wac1->features.touch_max) |
| 1217 | wacom_wac->shared->touch_input = wacom_wac2->input; |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1218 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1219 | |
| 1220 | error = wacom_initialize_battery(wacom); |
| 1221 | if (error) |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1222 | goto fail; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1223 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1224 | |
| 1225 | return; |
| 1226 | |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1227 | fail: |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1228 | wacom_unregister_inputs(wacom1); |
| 1229 | wacom_unregister_inputs(wacom2); |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1230 | return; |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1233 | /* |
| 1234 | * Not all devices report physical dimensions from HID. |
| 1235 | * Compute the default from hardcoded logical dimension |
| 1236 | * and resolution before driver overwrites them. |
| 1237 | */ |
| 1238 | static void wacom_set_default_phy(struct wacom_features *features) |
| 1239 | { |
| 1240 | if (features->x_resolution) { |
| 1241 | features->x_phy = (features->x_max * 100) / |
| 1242 | features->x_resolution; |
| 1243 | features->y_phy = (features->y_max * 100) / |
| 1244 | features->y_resolution; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | static void wacom_calculate_res(struct wacom_features *features) |
| 1249 | { |
| 1250 | features->x_resolution = wacom_calc_hid_res(features->x_max, |
| 1251 | features->x_phy, |
| 1252 | features->unit, |
| 1253 | features->unitExpo); |
| 1254 | features->y_resolution = wacom_calc_hid_res(features->y_max, |
| 1255 | features->y_phy, |
| 1256 | features->unit, |
| 1257 | features->unitExpo); |
| 1258 | } |
| 1259 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1260 | static int wacom_hid_report_len(struct hid_report *report) |
| 1261 | { |
| 1262 | /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */ |
| 1263 | return ((report->size - 1) >> 3) + 1 + (report->id > 0); |
| 1264 | } |
| 1265 | |
| 1266 | static size_t wacom_compute_pktlen(struct hid_device *hdev) |
| 1267 | { |
| 1268 | struct hid_report_enum *report_enum; |
| 1269 | struct hid_report *report; |
| 1270 | size_t size = 0; |
| 1271 | |
| 1272 | report_enum = hdev->report_enum + HID_INPUT_REPORT; |
| 1273 | |
| 1274 | list_for_each_entry(report, &report_enum->report_list, list) { |
| 1275 | size_t report_size = wacom_hid_report_len(report); |
| 1276 | if (report_size > size) |
| 1277 | size = report_size; |
| 1278 | } |
| 1279 | |
| 1280 | return size; |
| 1281 | } |
| 1282 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1283 | static int wacom_probe(struct hid_device *hdev, |
| 1284 | const struct hid_device_id *id) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1285 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1286 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1287 | struct usb_device *dev = interface_to_usbdev(intf); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1288 | struct wacom *wacom; |
| 1289 | struct wacom_wac *wacom_wac; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1290 | struct wacom_features *features; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1291 | int error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1292 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1293 | if (!id->driver_data) |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 1294 | return -EINVAL; |
| 1295 | |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 1296 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 1297 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1298 | wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); |
Dan Carpenter | f182394 | 2012-03-29 22:38:11 -0700 | [diff] [blame] | 1299 | if (!wacom) |
| 1300 | return -ENOMEM; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1301 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1302 | hid_set_drvdata(hdev, wacom); |
| 1303 | wacom->hdev = hdev; |
| 1304 | |
Benjamin Tissoires | ba9a354 | 2014-07-24 12:58:45 -0700 | [diff] [blame] | 1305 | /* ask for the report descriptor to be loaded by HID */ |
| 1306 | error = hid_parse(hdev); |
| 1307 | if (error) { |
| 1308 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1309 | goto fail_parse; |
Benjamin Tissoires | ba9a354 | 2014-07-24 12:58:45 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1312 | wacom_wac = &wacom->wacom_wac; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1313 | wacom_wac->features = *((struct wacom_features *)id->driver_data); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1314 | features = &wacom_wac->features; |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1315 | features->pktlen = wacom_compute_pktlen(hdev); |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1316 | if (features->pktlen > WACOM_PKGLEN_MAX) { |
| 1317 | error = -EINVAL; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1318 | goto fail_pktlen; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1321 | if (features->check_for_hid_type && features->hid_type != hdev->type) { |
| 1322 | error = -ENODEV; |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1323 | goto fail_type; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1324 | } |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1325 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1326 | wacom->usbdev = dev; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1327 | wacom->intf = intf; |
| 1328 | mutex_init(&wacom->lock); |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1329 | INIT_WORK(&wacom->work, wacom_wireless_work); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1330 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1331 | /* set the default size in case we do not get them from hid */ |
| 1332 | wacom_set_default_phy(features); |
| 1333 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 1334 | /* Retrieve the physical and logical size for touch devices */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 1335 | wacom_retrieve_hid_descriptor(hdev, features); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 1336 | |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1337 | /* |
| 1338 | * Intuos5 has no useful data about its touch interface in its |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1339 | * HID descriptor. If this is the touch interface (PacketSize |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1340 | * of WACOM_PKGLEN_BBTOUCH3), override the table values. |
| 1341 | */ |
Ping Cheng | b5fd2a3 | 2013-11-25 18:44:55 -0800 | [diff] [blame] | 1342 | if (features->type >= INTUOS5S && features->type <= INTUOSHT) { |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1343 | if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) { |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1344 | features->device_type = BTN_TOOL_FINGER; |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1345 | |
Jason Gerecke | ae584ca | 2012-04-03 15:50:40 -0700 | [diff] [blame] | 1346 | features->x_max = 4096; |
| 1347 | features->y_max = 4096; |
| 1348 | } else { |
| 1349 | features->device_type = BTN_TOOL_PEN; |
| 1350 | } |
| 1351 | } |
| 1352 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 1353 | /* |
| 1354 | * Same thing for Bamboo 3rd gen. |
| 1355 | */ |
| 1356 | if ((features->type == BAMBOO_PT) && |
| 1357 | (features->pktlen == WACOM_PKGLEN_BBTOUCH3) && |
| 1358 | (features->device_type == BTN_TOOL_PEN)) { |
| 1359 | features->device_type = BTN_TOOL_FINGER; |
| 1360 | |
| 1361 | features->x_max = 4096; |
| 1362 | features->y_max = 4096; |
| 1363 | } |
| 1364 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1365 | if (hdev->bus == BUS_BLUETOOTH) |
| 1366 | features->quirks |= WACOM_QUIRK_BATTERY; |
| 1367 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 1368 | wacom_setup_device_quirks(features); |
| 1369 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1370 | /* set unit to "100th of a mm" for devices not reported by HID */ |
| 1371 | if (!features->unit) { |
| 1372 | features->unit = 0x11; |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 1373 | features->unitExpo = -3; |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1374 | } |
| 1375 | wacom_calculate_res(features); |
| 1376 | |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1377 | strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name)); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1378 | snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), |
| 1379 | "%s Pad", features->name); |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1380 | |
Henrik Rydberg | bc73dd3 | 2010-09-05 12:26:16 -0700 | [diff] [blame] | 1381 | if (features->quirks & WACOM_QUIRK_MULTI_INPUT) { |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1382 | /* Append the device type to the name */ |
Ping Cheng | 57bcfce | 2013-10-15 23:44:00 -0700 | [diff] [blame] | 1383 | if (features->device_type != BTN_TOOL_FINGER) |
| 1384 | strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX); |
| 1385 | else if (features->touch_max) |
| 1386 | strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX); |
| 1387 | else |
| 1388 | strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1389 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 1390 | error = wacom_add_shared_data(hdev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1391 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1392 | goto fail_shared_data; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1395 | if (!(features->quirks & WACOM_QUIRK_MONITOR) && |
| 1396 | (features->quirks & WACOM_QUIRK_BATTERY)) { |
| 1397 | error = wacom_initialize_battery(wacom); |
| 1398 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1399 | goto fail_battery; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1400 | } |
| 1401 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1402 | if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) { |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1403 | error = wacom_register_inputs(wacom); |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1404 | if (error) |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1405 | goto fail_register_inputs; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | if (hdev->bus == BUS_BLUETOOTH) { |
| 1409 | error = device_create_file(&hdev->dev, &dev_attr_speed); |
| 1410 | if (error) |
| 1411 | hid_warn(hdev, |
| 1412 | "can't create sysfs speed attribute err: %d\n", |
| 1413 | error); |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 1414 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1415 | |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 1416 | /* Note that if query fails it is not a hard failure */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 1417 | wacom_query_tablet_data(hdev, features); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1418 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1419 | /* Regular HID work starts now */ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1420 | error = hid_hw_start(hdev, HID_CONNECT_HIDRAW); |
| 1421 | if (error) { |
| 1422 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1423 | goto fail_hw_start; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | if (features->quirks & WACOM_QUIRK_MONITOR) |
| 1427 | error = hid_hw_open(hdev); |
| 1428 | |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1429 | if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) { |
| 1430 | if (wacom_wac->features.device_type == BTN_TOOL_FINGER) |
| 1431 | wacom_wac->shared->touch_input = wacom_wac->input; |
| 1432 | } |
| 1433 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1434 | return 0; |
| 1435 | |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1436 | fail_hw_start: |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1437 | wacom_unregister_inputs(wacom); |
Benjamin Tissoires | 7fefeec | 2014-09-23 12:08:05 -0400 | [diff] [blame^] | 1438 | if (hdev->bus == BUS_BLUETOOTH) |
| 1439 | device_remove_file(&hdev->dev, &dev_attr_speed); |
| 1440 | fail_register_inputs: |
| 1441 | wacom_unregister_inputs(wacom); |
| 1442 | wacom_destroy_battery(wacom); |
| 1443 | fail_battery: |
| 1444 | wacom_remove_shared_data(wacom_wac); |
| 1445 | fail_shared_data: |
| 1446 | fail_type: |
| 1447 | fail_pktlen: |
| 1448 | fail_parse: |
| 1449 | kfree(wacom); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1450 | hid_set_drvdata(hdev, NULL); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 1451 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1454 | static void wacom_remove(struct hid_device *hdev) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1455 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1456 | struct wacom *wacom = hid_get_drvdata(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1457 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1458 | hid_hw_stop(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1459 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 1460 | cancel_work_sync(&wacom->work); |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1461 | wacom_unregister_inputs(wacom); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1462 | if (hdev->bus == BUS_BLUETOOTH) |
| 1463 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1464 | wacom_destroy_battery(wacom); |
Dmitry Torokhov | 51269fe | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1465 | wacom_remove_shared_data(&wacom->wacom_wac); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1466 | |
| 1467 | hid_set_drvdata(hdev, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1468 | kfree(wacom); |
| 1469 | } |
| 1470 | |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 1471 | #ifdef CONFIG_PM |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1472 | static int wacom_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1473 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1474 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1475 | struct wacom_features *features = &wacom->wacom_wac.features; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1476 | |
| 1477 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1478 | |
| 1479 | /* switch to wacom mode first */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 1480 | wacom_query_tablet_data(hdev, features); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1481 | wacom_led_control(wacom); |
| 1482 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1483 | mutex_unlock(&wacom->lock); |
| 1484 | |
| 1485 | return 0; |
| 1486 | } |
| 1487 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1488 | static int wacom_reset_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1489 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1490 | return wacom_resume(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1491 | } |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 1492 | #endif /* CONFIG_PM */ |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1493 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1494 | static struct hid_driver wacom_driver = { |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1495 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 1496 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1497 | .probe = wacom_probe, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1498 | .remove = wacom_remove, |
| 1499 | #ifdef CONFIG_PM |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 1500 | .resume = wacom_resume, |
| 1501 | .reset_resume = wacom_reset_resume, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1502 | #endif |
| 1503 | .raw_event = wacom_raw_event, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1504 | }; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1505 | module_hid_driver(wacom_driver); |
Benjamin Tissoires | f2e0a7d | 2014-08-06 14:07:49 -0700 | [diff] [blame] | 1506 | |
| 1507 | MODULE_VERSION(DRIVER_VERSION); |
| 1508 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1509 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1510 | MODULE_LICENSE(DRIVER_LICENSE); |