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