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 |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 26 | #define WAC_CMD_DELETE_PAIRING 0x20 |
| 27 | #define WAC_CMD_UNPAIR_ALL 0xFF |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 28 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 29 | #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) |
| 30 | #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 31 | #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP) |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 32 | |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 33 | static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 34 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 35 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 36 | int retval; |
| 37 | |
| 38 | do { |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 39 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 40 | HID_REQ_GET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 41 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 42 | |
| 43 | if (retval < 0) |
| 44 | hid_err(hdev, "wacom_get_report: ran out of retries " |
| 45 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 46 | |
| 47 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 50 | static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 51 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 52 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 53 | int retval; |
| 54 | |
| 55 | do { |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 56 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 57 | HID_REQ_SET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 58 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 59 | |
| 60 | if (retval < 0) |
| 61 | hid_err(hdev, "wacom_set_report: ran out of retries " |
| 62 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 63 | |
| 64 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 67 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 68 | u8 *raw_data, int size) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 69 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 70 | struct wacom *wacom = hid_get_drvdata(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 71 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 72 | if (size > WACOM_PKGLEN_MAX) |
| 73 | return 1; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 74 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 75 | memcpy(wacom->wacom_wac.data, raw_data, size); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 76 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 77 | wacom_wac_irq(&wacom->wacom_wac, size); |
| 78 | |
| 79 | return 0; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 82 | static int wacom_open(struct input_dev *dev) |
| 83 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 84 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 85 | |
Benjamin Tissoires | dff6741 | 2014-12-01 11:52:40 -0500 | [diff] [blame] | 86 | return hid_hw_open(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | static void wacom_close(struct input_dev *dev) |
| 90 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 91 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 92 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 93 | /* |
| 94 | * wacom->hdev should never be null, but surprisingly, I had the case |
| 95 | * once while unplugging the Wacom Wireless Receiver. |
| 96 | */ |
| 97 | if (wacom->hdev) |
| 98 | hid_hw_close(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 101 | /* |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 102 | * 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] | 103 | */ |
| 104 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 105 | unsigned unit, int exponent) |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 106 | { |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 107 | struct hid_field field = { |
| 108 | .logical_maximum = logical_extents, |
| 109 | .physical_maximum = physical_extents, |
| 110 | .unit = unit, |
| 111 | .unit_exponent = exponent, |
| 112 | }; |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 113 | |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 114 | return hidinput_calc_abs_res(&field, ABS_X); |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 115 | } |
| 116 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 117 | static void wacom_feature_mapping(struct hid_device *hdev, |
| 118 | struct hid_field *field, struct hid_usage *usage) |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 119 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 120 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 121 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 122 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 123 | u8 *data; |
| 124 | int ret; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 125 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 126 | switch (usage->hid) { |
| 127 | case HID_DG_CONTACTMAX: |
| 128 | /* leave touch_max as is if predefined */ |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 129 | if (!features->touch_max) { |
| 130 | /* read manually */ |
| 131 | data = kzalloc(2, GFP_KERNEL); |
| 132 | if (!data) |
| 133 | break; |
| 134 | data[0] = field->report->id; |
| 135 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Jason Gerecke | 05e8fd9 | 2015-05-21 10:44:32 -0700 | [diff] [blame] | 136 | data, 2, WAC_CMD_RETRIES); |
| 137 | if (ret == 2) { |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 138 | features->touch_max = data[1]; |
Jason Gerecke | 05e8fd9 | 2015-05-21 10:44:32 -0700 | [diff] [blame] | 139 | } else { |
| 140 | features->touch_max = 16; |
| 141 | hid_warn(hdev, "wacom_feature_mapping: " |
| 142 | "could not get HID_DG_CONTACTMAX, " |
| 143 | "defaulting to %d\n", |
| 144 | features->touch_max); |
| 145 | } |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 146 | kfree(data); |
| 147 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 148 | break; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 149 | case HID_DG_INPUTMODE: |
| 150 | /* Ignore if value index is out of bounds. */ |
| 151 | if (usage->usage_index >= field->report_count) { |
| 152 | dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n"); |
| 153 | break; |
| 154 | } |
| 155 | |
| 156 | hid_data->inputmode = field->report->id; |
| 157 | hid_data->inputmode_index = usage->usage_index; |
| 158 | break; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 159 | |
| 160 | case HID_UP_DIGITIZER: |
| 161 | if (field->report->id == 0x0B && |
| 162 | (field->application == WACOM_G9_DIGITIZER || |
| 163 | field->application == WACOM_G11_DIGITIZER)) { |
| 164 | wacom->wacom_wac.mode_report = field->report->id; |
| 165 | wacom->wacom_wac.mode_value = 0; |
| 166 | } |
| 167 | break; |
| 168 | |
| 169 | case WACOM_G9_PAGE: |
| 170 | case WACOM_G11_PAGE: |
| 171 | if (field->report->id == 0x03 && |
| 172 | (field->application == WACOM_G9_TOUCHSCREEN || |
| 173 | field->application == WACOM_G11_TOUCHSCREEN)) { |
| 174 | wacom->wacom_wac.mode_report = field->report->id; |
| 175 | wacom->wacom_wac.mode_value = 0; |
| 176 | } |
| 177 | break; |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Interface Descriptor of wacom devices can be incomplete and |
| 183 | * inconsistent so wacom_features table is used to store stylus |
| 184 | * device's packet lengths, various maximum values, and tablet |
| 185 | * resolution based on product ID's. |
| 186 | * |
| 187 | * For devices that contain 2 interfaces, wacom_features table is |
| 188 | * inaccurate for the touch interface. Since the Interface Descriptor |
| 189 | * for touch interfaces has pretty complete data, this function exists |
| 190 | * to query tablet for this missing information instead of hard coding in |
| 191 | * an additional table. |
| 192 | * |
| 193 | * A typical Interface Descriptor for a stylus will contain a |
| 194 | * boot mouse application collection that is not of interest and this |
| 195 | * function will ignore it. |
| 196 | * |
| 197 | * It also contains a digitizer application collection that also is not |
| 198 | * of interest since any information it contains would be duplicate |
| 199 | * of what is in wacom_features. Usually it defines a report of an array |
| 200 | * of bytes that could be used as max length of the stylus packet returned. |
| 201 | * If it happens to define a Digitizer-Stylus Physical Collection then |
| 202 | * the X and Y logical values contain valid data but it is ignored. |
| 203 | * |
| 204 | * A typical Interface Descriptor for a touch interface will contain a |
| 205 | * Digitizer-Finger Physical Collection which will define both logical |
| 206 | * X/Y maximum as well as the physical size of tablet. Since touch |
| 207 | * interfaces haven't supported pressure or distance, this is enough |
| 208 | * information to override invalid values in the wacom_features table. |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 209 | * |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 210 | * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful |
| 211 | * data. We deal with them after returning from this function. |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 212 | */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 213 | static void wacom_usage_mapping(struct hid_device *hdev, |
| 214 | struct hid_field *field, struct hid_usage *usage) |
| 215 | { |
| 216 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 217 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | d97a552 | 2015-01-05 16:32:12 -0500 | [diff] [blame] | 218 | bool finger = WACOM_FINGER_FIELD(field); |
| 219 | bool pen = WACOM_PEN_FIELD(field); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * Requiring Stylus Usage will ignore boot mouse |
| 223 | * X/Y values and some cases of invalid Digitizer X/Y |
| 224 | * values commonly reported. |
| 225 | */ |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 226 | if (pen) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 227 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 228 | else if (finger) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 229 | features->device_type |= WACOM_DEVICETYPE_TOUCH; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 230 | else |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 231 | return; |
| 232 | |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 233 | /* |
| 234 | * Bamboo models do not support HID_DG_CONTACTMAX. |
| 235 | * And, Bamboo Pen only descriptor contains touch. |
| 236 | */ |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 237 | if (features->type > BAMBOO_PT) { |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 238 | /* ISDv4 touch devices at least supports one touch point */ |
| 239 | if (finger && !features->touch_max) |
| 240 | features->touch_max = 1; |
| 241 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 242 | |
| 243 | switch (usage->hid) { |
| 244 | case HID_GD_X: |
| 245 | features->x_max = field->logical_maximum; |
| 246 | if (finger) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 247 | features->x_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 248 | if ((features->type != BAMBOO_PT) && |
| 249 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 250 | features->unit = field->unit; |
| 251 | features->unitExpo = field->unit_exponent; |
| 252 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 253 | } |
| 254 | break; |
| 255 | case HID_GD_Y: |
| 256 | features->y_max = field->logical_maximum; |
| 257 | if (finger) { |
| 258 | features->y_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 259 | if ((features->type != BAMBOO_PT) && |
| 260 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 261 | features->unit = field->unit; |
| 262 | features->unitExpo = field->unit_exponent; |
| 263 | } |
| 264 | } |
| 265 | break; |
| 266 | case HID_DG_TIPPRESSURE: |
| 267 | if (pen) |
| 268 | features->pressure_max = field->logical_maximum; |
| 269 | break; |
| 270 | } |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 271 | |
| 272 | if (features->type == HID_GENERIC) |
| 273 | wacom_wac_usage_mapping(hdev, field, usage); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 276 | static void wacom_post_parse_hid(struct hid_device *hdev, |
| 277 | struct wacom_features *features) |
| 278 | { |
| 279 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 280 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 281 | |
| 282 | if (features->type == HID_GENERIC) { |
| 283 | /* Any last-minute generic device setup */ |
| 284 | if (features->touch_max > 1) { |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 285 | input_mt_init_slots(wacom_wac->touch_input, wacom_wac->features.touch_max, |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 286 | INPUT_MT_DIRECT); |
| 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 291 | static void wacom_parse_hid(struct hid_device *hdev, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 292 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 293 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 294 | struct hid_report_enum *rep_enum; |
| 295 | struct hid_report *hreport; |
| 296 | int i, j; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 297 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 298 | /* check features first */ |
| 299 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; |
| 300 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 301 | for (i = 0; i < hreport->maxfield; i++) { |
| 302 | /* Ignore if report count is out of bounds. */ |
| 303 | if (hreport->field[i]->report_count < 1) |
| 304 | continue; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 305 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 306 | for (j = 0; j < hreport->field[i]->maxusage; j++) { |
| 307 | wacom_feature_mapping(hdev, hreport->field[i], |
| 308 | hreport->field[i]->usage + j); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 309 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 313 | /* now check the input usages */ |
| 314 | rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
| 315 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 316 | |
| 317 | if (!hreport->maxfield) |
| 318 | continue; |
| 319 | |
| 320 | for (i = 0; i < hreport->maxfield; i++) |
| 321 | for (j = 0; j < hreport->field[i]->maxusage; j++) |
| 322 | wacom_usage_mapping(hdev, hreport->field[i], |
| 323 | hreport->field[i]->usage + j); |
| 324 | } |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 325 | |
| 326 | wacom_post_parse_hid(hdev, features); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 327 | } |
| 328 | |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 329 | static int wacom_hid_set_device_mode(struct hid_device *hdev) |
| 330 | { |
| 331 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 332 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
| 333 | struct hid_report *r; |
| 334 | struct hid_report_enum *re; |
| 335 | |
| 336 | if (hid_data->inputmode < 0) |
| 337 | return 0; |
| 338 | |
| 339 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 340 | r = re->report_id_hash[hid_data->inputmode]; |
| 341 | if (r) { |
| 342 | r->field[0]->value[hid_data->inputmode_index] = 2; |
| 343 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); |
| 344 | } |
| 345 | return 0; |
| 346 | } |
| 347 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 348 | static int wacom_set_device_mode(struct hid_device *hdev, |
| 349 | struct wacom_wac *wacom_wac) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 350 | { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 351 | u8 *rep_data; |
| 352 | struct hid_report *r; |
| 353 | struct hid_report_enum *re; |
| 354 | int length; |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 355 | int error = -ENOMEM, limit = 0; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 356 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 357 | if (wacom_wac->mode_report < 0) |
| 358 | return 0; |
| 359 | |
| 360 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 361 | r = re->report_id_hash[wacom_wac->mode_report]; |
| 362 | if (!r) |
| 363 | return -EINVAL; |
| 364 | |
| 365 | rep_data = hid_alloc_report_buf(r, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 366 | if (!rep_data) |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 367 | return -ENOMEM; |
| 368 | |
| 369 | length = hid_report_len(r); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 370 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 371 | do { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 372 | rep_data[0] = wacom_wac->mode_report; |
| 373 | rep_data[1] = wacom_wac->mode_value; |
Chris Bagwell | 9937c02 | 2013-01-23 19:37:34 -0800 | [diff] [blame] | 374 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 375 | error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, |
| 376 | length, 1); |
Benjamin Tissoires | 3cb8315 | 2014-07-24 12:47:47 -0700 | [diff] [blame] | 377 | if (error >= 0) |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 378 | error = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 379 | rep_data, length, 1); |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 380 | } while (error >= 0 && |
| 381 | rep_data[1] != wacom_wac->mode_report && |
| 382 | limit++ < WAC_MSG_RETRIES); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 383 | |
| 384 | kfree(rep_data); |
| 385 | |
| 386 | return error < 0 ? error : 0; |
| 387 | } |
| 388 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 389 | static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, |
| 390 | struct wacom_features *features) |
| 391 | { |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 392 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 393 | int ret; |
| 394 | u8 rep_data[2]; |
| 395 | |
| 396 | switch (features->type) { |
| 397 | case GRAPHIRE_BT: |
| 398 | rep_data[0] = 0x03; |
| 399 | rep_data[1] = 0x00; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 400 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 401 | 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 402 | |
| 403 | if (ret >= 0) { |
| 404 | rep_data[0] = speed == 0 ? 0x05 : 0x06; |
| 405 | rep_data[1] = 0x00; |
| 406 | |
| 407 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 408 | rep_data, 2, 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 409 | |
| 410 | if (ret >= 0) { |
| 411 | wacom->wacom_wac.bt_high_speed = speed; |
| 412 | return 0; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | /* |
| 417 | * Note that if the raw queries fail, it's not a hard failure |
| 418 | * and it is safe to continue |
| 419 | */ |
| 420 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 421 | rep_data[0], ret); |
| 422 | break; |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 423 | case INTUOS4WL: |
| 424 | if (speed == 1) |
| 425 | wacom->wacom_wac.bt_features &= ~0x20; |
| 426 | else |
| 427 | wacom->wacom_wac.bt_features |= 0x20; |
| 428 | |
| 429 | rep_data[0] = 0x03; |
| 430 | rep_data[1] = wacom->wacom_wac.bt_features; |
| 431 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 432 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 433 | 1); |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 434 | if (ret >= 0) |
| 435 | wacom->wacom_wac.bt_high_speed = speed; |
| 436 | break; |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 442 | /* |
| 443 | * Switch the tablet into its most-capable mode. Wacom tablets are |
| 444 | * typically configured to power-up in a mode which sends mouse-like |
| 445 | * reports to the OS. To get absolute position, pressure data, etc. |
| 446 | * from the tablet, it is necessary to switch the tablet out of this |
| 447 | * mode and into one which sends the full range of tablet data. |
| 448 | */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 449 | static int wacom_query_tablet_data(struct hid_device *hdev, |
| 450 | struct wacom_features *features) |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 451 | { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 452 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 453 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 454 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 455 | if (hdev->bus == BUS_BLUETOOTH) |
| 456 | return wacom_bt_query_tablet_data(hdev, 1, features); |
| 457 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 458 | if (features->type != HID_GENERIC) { |
| 459 | if (features->device_type & WACOM_DEVICETYPE_TOUCH) { |
| 460 | if (features->type > TABLETPC) { |
| 461 | /* MT Tablet PC touch */ |
| 462 | wacom_wac->mode_report = 3; |
| 463 | wacom_wac->mode_value = 4; |
| 464 | } else if (features->type == WACOM_24HDT) { |
| 465 | wacom_wac->mode_report = 18; |
| 466 | wacom_wac->mode_value = 2; |
| 467 | } else if (features->type == WACOM_27QHDT) { |
| 468 | wacom_wac->mode_report = 131; |
| 469 | wacom_wac->mode_value = 2; |
| 470 | } else if (features->type == BAMBOO_PAD) { |
| 471 | wacom_wac->mode_report = 2; |
| 472 | wacom_wac->mode_value = 2; |
| 473 | } |
| 474 | } else if (features->device_type & WACOM_DEVICETYPE_PEN) { |
| 475 | if (features->type <= BAMBOO_PT) { |
| 476 | wacom_wac->mode_report = 2; |
| 477 | wacom_wac->mode_value = 2; |
| 478 | } |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 482 | wacom_set_device_mode(hdev, wacom_wac); |
| 483 | |
| 484 | if (features->type == HID_GENERIC) |
| 485 | return wacom_hid_set_device_mode(hdev); |
| 486 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 487 | return 0; |
| 488 | } |
| 489 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 490 | static void wacom_retrieve_hid_descriptor(struct hid_device *hdev, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 491 | struct wacom_features *features) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 492 | { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 493 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 494 | struct usb_interface *intf = wacom->intf; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 495 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 496 | /* default features */ |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 497 | features->x_fuzz = 4; |
| 498 | features->y_fuzz = 4; |
| 499 | features->pressure_fuzz = 0; |
Jason Gerecke | bef7e20 | 2016-04-22 14:30:53 -0700 | [diff] [blame] | 500 | features->distance_fuzz = 1; |
| 501 | features->tilt_fuzz = 1; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 502 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 503 | /* |
| 504 | * The wireless device HID is basic and layout conflicts with |
| 505 | * other tablets (monitor and touch interface can look like pen). |
| 506 | * Skip the query for this type and modify defaults based on |
| 507 | * interface number. |
| 508 | */ |
| 509 | if (features->type == WIRELESS) { |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 510 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 511 | features->device_type = WACOM_DEVICETYPE_WL_MONITOR; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 512 | else |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 513 | features->device_type = WACOM_DEVICETYPE_NONE; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 514 | return; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 517 | wacom_parse_hid(hdev, features); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 518 | } |
| 519 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 520 | struct wacom_hdev_data { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 521 | struct list_head list; |
| 522 | struct kref kref; |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 523 | struct hid_device *dev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 524 | struct wacom_shared shared; |
| 525 | }; |
| 526 | |
| 527 | static LIST_HEAD(wacom_udev_list); |
| 528 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 529 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 530 | static bool wacom_are_sibling(struct hid_device *hdev, |
| 531 | struct hid_device *sibling) |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 532 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 533 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 534 | struct wacom_features *features = &wacom->wacom_wac.features; |
| 535 | int vid = features->oVid; |
| 536 | int pid = features->oPid; |
| 537 | int n1,n2; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 538 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 539 | if (vid == 0 && pid == 0) { |
| 540 | vid = hdev->vendor; |
| 541 | pid = hdev->product; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 544 | if (vid != sibling->vendor || pid != sibling->product) |
| 545 | return false; |
| 546 | |
| 547 | /* Compare the physical path. */ |
| 548 | n1 = strrchr(hdev->phys, '.') - hdev->phys; |
| 549 | n2 = strrchr(sibling->phys, '.') - sibling->phys; |
| 550 | if (n1 != n2 || n1 <= 0 || n2 <= 0) |
| 551 | return false; |
| 552 | |
| 553 | return !strncmp(hdev->phys, sibling->phys, n1); |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 556 | 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] | 557 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 558 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 559 | |
| 560 | list_for_each_entry(data, &wacom_udev_list, list) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 561 | if (wacom_are_sibling(hdev, data->dev)) { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 562 | kref_get(&data->kref); |
| 563 | return data; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | return NULL; |
| 568 | } |
| 569 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 570 | static void wacom_release_shared_data(struct kref *kref) |
| 571 | { |
| 572 | struct wacom_hdev_data *data = |
| 573 | container_of(kref, struct wacom_hdev_data, kref); |
| 574 | |
| 575 | mutex_lock(&wacom_udev_list_lock); |
| 576 | list_del(&data->list); |
| 577 | mutex_unlock(&wacom_udev_list_lock); |
| 578 | |
| 579 | kfree(data); |
| 580 | } |
| 581 | |
| 582 | static void wacom_remove_shared_data(void *res) |
| 583 | { |
| 584 | struct wacom *wacom = res; |
| 585 | struct wacom_hdev_data *data; |
| 586 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 587 | |
| 588 | if (wacom_wac->shared) { |
| 589 | data = container_of(wacom_wac->shared, struct wacom_hdev_data, |
| 590 | shared); |
| 591 | |
| 592 | if (wacom_wac->shared->touch == wacom->hdev) |
| 593 | wacom_wac->shared->touch = NULL; |
| 594 | else if (wacom_wac->shared->pen == wacom->hdev) |
| 595 | wacom_wac->shared->pen = NULL; |
| 596 | |
| 597 | kref_put(&data->kref, wacom_release_shared_data); |
| 598 | wacom_wac->shared = NULL; |
| 599 | } |
| 600 | } |
| 601 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 602 | static int wacom_add_shared_data(struct hid_device *hdev) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 603 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 604 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 605 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 606 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 607 | int retval = 0; |
| 608 | |
| 609 | mutex_lock(&wacom_udev_list_lock); |
| 610 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 611 | data = wacom_get_hdev_data(hdev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 612 | if (!data) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 613 | data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 614 | if (!data) { |
| 615 | retval = -ENOMEM; |
| 616 | goto out; |
| 617 | } |
| 618 | |
| 619 | kref_init(&data->kref); |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 620 | data->dev = hdev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 621 | list_add_tail(&data->list, &wacom_udev_list); |
| 622 | } |
| 623 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 624 | wacom_wac->shared = &data->shared; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 625 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 626 | retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom); |
| 627 | if (retval) { |
| 628 | mutex_unlock(&wacom_udev_list_lock); |
| 629 | wacom_remove_shared_data(wacom); |
| 630 | return retval; |
| 631 | } |
| 632 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 633 | if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) |
Benjamin Tissoires | a97ac10 | 2015-02-25 11:43:39 -0500 | [diff] [blame] | 634 | wacom_wac->shared->touch = hdev; |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 635 | else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN) |
Benjamin Tissoires | a97ac10 | 2015-02-25 11:43:39 -0500 | [diff] [blame] | 636 | wacom_wac->shared->pen = hdev; |
| 637 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 638 | out: |
| 639 | mutex_unlock(&wacom_udev_list_lock); |
| 640 | return retval; |
| 641 | } |
| 642 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 643 | static int wacom_led_control(struct wacom *wacom) |
| 644 | { |
| 645 | unsigned char *buf; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 646 | int retval; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 647 | unsigned char report_id = WAC_CMD_LED_CONTROL; |
| 648 | int buf_size = 9; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 649 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 650 | if (!wacom->led.groups) |
| 651 | return -ENOTSUPP; |
| 652 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 653 | if (wacom->wacom_wac.pid) { /* wireless connected */ |
| 654 | report_id = WAC_CMD_WL_LED_CONTROL; |
| 655 | buf_size = 13; |
| 656 | } |
| 657 | buf = kzalloc(buf_size, GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 658 | if (!buf) |
| 659 | return -ENOMEM; |
| 660 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 661 | if (wacom->wacom_wac.features.type >= INTUOS5S && |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 662 | wacom->wacom_wac.features.type <= INTUOSPL) { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 663 | /* |
| 664 | * Touch Ring and crop mark LED luminance may take on |
| 665 | * one of four values: |
| 666 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off |
| 667 | */ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 668 | int ring_led = wacom->led.groups[0].select & 0x03; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 669 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; |
| 670 | int crop_lum = 0; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 671 | unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 672 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 673 | buf[0] = report_id; |
| 674 | if (wacom->wacom_wac.pid) { |
| 675 | wacom_get_report(wacom->hdev, HID_FEATURE_REPORT, |
| 676 | buf, buf_size, WAC_CMD_RETRIES); |
| 677 | buf[0] = report_id; |
| 678 | buf[4] = led_bits; |
| 679 | } else |
| 680 | buf[1] = led_bits; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 681 | } |
| 682 | else { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 683 | int led = wacom->led.groups[0].select | 0x4; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 684 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 685 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || |
| 686 | wacom->wacom_wac.features.type == WACOM_24HD) |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 687 | led |= (wacom->led.groups[1].select << 4) | 0x40; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 688 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 689 | buf[0] = report_id; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 690 | buf[1] = led; |
| 691 | buf[2] = wacom->led.llv; |
| 692 | buf[3] = wacom->led.hlv; |
| 693 | buf[4] = wacom->led.img_lum; |
| 694 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 695 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 696 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 697 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 698 | kfree(buf); |
| 699 | |
| 700 | return retval; |
| 701 | } |
| 702 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 703 | static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id, |
| 704 | const unsigned len, const void *img) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 705 | { |
| 706 | unsigned char *buf; |
| 707 | int i, retval; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 708 | 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] | 709 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 710 | buf = kzalloc(chunk_len + 3 , GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 711 | if (!buf) |
| 712 | return -ENOMEM; |
| 713 | |
| 714 | /* Send 'start' command */ |
| 715 | buf[0] = WAC_CMD_ICON_START; |
| 716 | buf[1] = 1; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 717 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 718 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 719 | if (retval < 0) |
| 720 | goto out; |
| 721 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 722 | buf[0] = xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 723 | buf[1] = button_id & 0x07; |
| 724 | for (i = 0; i < 4; i++) { |
| 725 | buf[2] = i; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 726 | memcpy(buf + 3, img + i * chunk_len, chunk_len); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 727 | |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 728 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 729 | buf, chunk_len + 3, WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 730 | if (retval < 0) |
| 731 | break; |
| 732 | } |
| 733 | |
| 734 | /* Send 'stop' */ |
| 735 | buf[0] = WAC_CMD_ICON_START; |
| 736 | buf[1] = 0; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 737 | wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 738 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 739 | |
| 740 | out: |
| 741 | kfree(buf); |
| 742 | return retval; |
| 743 | } |
| 744 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 745 | 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] | 746 | const char *buf, size_t count) |
| 747 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 748 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 749 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 750 | unsigned int id; |
| 751 | int err; |
| 752 | |
| 753 | err = kstrtouint(buf, 10, &id); |
| 754 | if (err) |
| 755 | return err; |
| 756 | |
| 757 | mutex_lock(&wacom->lock); |
| 758 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 759 | wacom->led.groups[set_id].select = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 760 | err = wacom_led_control(wacom); |
| 761 | |
| 762 | mutex_unlock(&wacom->lock); |
| 763 | |
| 764 | return err < 0 ? err : count; |
| 765 | } |
| 766 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 767 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 768 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 769 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 770 | { \ |
| 771 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 772 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 773 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 774 | struct device_attribute *attr, char *buf) \ |
| 775 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 776 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 777 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 778 | return scnprintf(buf, PAGE_SIZE, "%d\n", \ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 779 | wacom->led.groups[SET_ID].select); \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 780 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 781 | static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 782 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 783 | wacom_led##SET_ID##_select_store) |
| 784 | |
| 785 | DEVICE_LED_SELECT_ATTR(0); |
| 786 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 787 | |
| 788 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 789 | const char *buf, size_t count) |
| 790 | { |
| 791 | unsigned int value; |
| 792 | int err; |
| 793 | |
| 794 | err = kstrtouint(buf, 10, &value); |
| 795 | if (err) |
| 796 | return err; |
| 797 | |
| 798 | mutex_lock(&wacom->lock); |
| 799 | |
| 800 | *dest = value & 0x7f; |
| 801 | err = wacom_led_control(wacom); |
| 802 | |
| 803 | mutex_unlock(&wacom->lock); |
| 804 | |
| 805 | return err < 0 ? err : count; |
| 806 | } |
| 807 | |
| 808 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 809 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 810 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 811 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 812 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 813 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 814 | \ |
| 815 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 816 | buf, count); \ |
| 817 | } \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 818 | static ssize_t wacom_##name##_luminance_show(struct device *dev, \ |
| 819 | struct device_attribute *attr, char *buf) \ |
| 820 | { \ |
| 821 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 822 | return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \ |
| 823 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 824 | static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 825 | wacom_##name##_luminance_show, \ |
| 826 | wacom_##name##_luminance_store) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 827 | |
| 828 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 829 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 830 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 831 | |
| 832 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 833 | const char *buf, size_t count) |
| 834 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 835 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 836 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 837 | int err; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 838 | unsigned len; |
| 839 | u8 xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 840 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 841 | if (hdev->bus == BUS_BLUETOOTH) { |
| 842 | len = 256; |
| 843 | xfer_id = WAC_CMD_ICON_BT_XFER; |
| 844 | } else { |
| 845 | len = 1024; |
| 846 | xfer_id = WAC_CMD_ICON_XFER; |
| 847 | } |
| 848 | |
| 849 | if (count != len) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 850 | return -EINVAL; |
| 851 | |
| 852 | mutex_lock(&wacom->lock); |
| 853 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 854 | err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 855 | |
| 856 | mutex_unlock(&wacom->lock); |
| 857 | |
| 858 | return err < 0 ? err : count; |
| 859 | } |
| 860 | |
| 861 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 862 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 863 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 864 | { \ |
| 865 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 866 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 867 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 868 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 869 | |
| 870 | DEVICE_BTNIMG_ATTR(0); |
| 871 | DEVICE_BTNIMG_ATTR(1); |
| 872 | DEVICE_BTNIMG_ATTR(2); |
| 873 | DEVICE_BTNIMG_ATTR(3); |
| 874 | DEVICE_BTNIMG_ATTR(4); |
| 875 | DEVICE_BTNIMG_ATTR(5); |
| 876 | DEVICE_BTNIMG_ATTR(6); |
| 877 | DEVICE_BTNIMG_ATTR(7); |
| 878 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 879 | static struct attribute *cintiq_led_attrs[] = { |
| 880 | &dev_attr_status_led0_select.attr, |
| 881 | &dev_attr_status_led1_select.attr, |
| 882 | NULL |
| 883 | }; |
| 884 | |
| 885 | static struct attribute_group cintiq_led_attr_group = { |
| 886 | .name = "wacom_led", |
| 887 | .attrs = cintiq_led_attrs, |
| 888 | }; |
| 889 | |
| 890 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 891 | &dev_attr_status0_luminance.attr, |
| 892 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 893 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 894 | &dev_attr_buttons_luminance.attr, |
| 895 | &dev_attr_button0_rawimg.attr, |
| 896 | &dev_attr_button1_rawimg.attr, |
| 897 | &dev_attr_button2_rawimg.attr, |
| 898 | &dev_attr_button3_rawimg.attr, |
| 899 | &dev_attr_button4_rawimg.attr, |
| 900 | &dev_attr_button5_rawimg.attr, |
| 901 | &dev_attr_button6_rawimg.attr, |
| 902 | &dev_attr_button7_rawimg.attr, |
| 903 | NULL |
| 904 | }; |
| 905 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 906 | static struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 907 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 908 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 909 | }; |
| 910 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 911 | static struct attribute *intuos5_led_attrs[] = { |
| 912 | &dev_attr_status0_luminance.attr, |
| 913 | &dev_attr_status_led0_select.attr, |
| 914 | NULL |
| 915 | }; |
| 916 | |
| 917 | static struct attribute_group intuos5_led_attr_group = { |
| 918 | .name = "wacom_led", |
| 919 | .attrs = intuos5_led_attrs, |
| 920 | }; |
| 921 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 922 | struct wacom_sysfs_group_devres { |
| 923 | struct attribute_group *group; |
| 924 | struct kobject *root; |
| 925 | }; |
| 926 | |
| 927 | static void wacom_devm_sysfs_group_release(struct device *dev, void *res) |
| 928 | { |
| 929 | struct wacom_sysfs_group_devres *devres = res; |
| 930 | struct kobject *kobj = devres->root; |
| 931 | |
| 932 | dev_dbg(dev, "%s: dropping reference to %s\n", |
| 933 | __func__, devres->group->name); |
| 934 | sysfs_remove_group(kobj, devres->group); |
| 935 | } |
| 936 | |
| 937 | static int wacom_devm_sysfs_create_group(struct wacom *wacom, |
| 938 | struct attribute_group *group) |
| 939 | { |
| 940 | struct wacom_sysfs_group_devres *devres; |
| 941 | int error; |
| 942 | |
| 943 | devres = devres_alloc(wacom_devm_sysfs_group_release, |
| 944 | sizeof(struct wacom_sysfs_group_devres), |
| 945 | GFP_KERNEL); |
| 946 | if (!devres) |
| 947 | return -ENOMEM; |
| 948 | |
| 949 | devres->group = group; |
| 950 | devres->root = &wacom->hdev->dev.kobj; |
| 951 | |
| 952 | error = sysfs_create_group(devres->root, group); |
| 953 | if (error) |
| 954 | return error; |
| 955 | |
| 956 | devres_add(&wacom->hdev->dev, devres); |
| 957 | |
| 958 | return 0; |
| 959 | } |
| 960 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 961 | static void wacom_led_groups_release(void *data) |
| 962 | { |
| 963 | struct wacom *wacom = data; |
| 964 | |
| 965 | wacom->led.groups = NULL; |
| 966 | } |
| 967 | |
| 968 | static int wacom_led_groups_allocate(struct wacom *wacom, int count) |
| 969 | { |
| 970 | struct wacom_group_leds *groups; |
| 971 | int error; |
| 972 | |
| 973 | groups = devm_kzalloc(&wacom->hdev->dev, |
| 974 | sizeof(struct wacom_group_leds) * count, |
| 975 | GFP_KERNEL); |
| 976 | if (!groups) |
| 977 | return -ENOMEM; |
| 978 | |
| 979 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 980 | wacom_led_groups_release, |
| 981 | wacom); |
| 982 | if (error) |
| 983 | return error; |
| 984 | |
| 985 | wacom->led.groups = groups; |
| 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 990 | static int wacom_initialize_leds(struct wacom *wacom) |
| 991 | { |
| 992 | int error; |
| 993 | |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 994 | if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD)) |
| 995 | return 0; |
| 996 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 997 | /* Initialize default values */ |
| 998 | switch (wacom->wacom_wac.features.type) { |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 999 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1000 | case INTUOS4: |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 1001 | case INTUOS4WL: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1002 | case INTUOS4L: |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 1003 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1004 | wacom->led.hlv = 20; |
| 1005 | wacom->led.img_lum = 10; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1006 | |
| 1007 | error = wacom_led_groups_allocate(wacom, 1); |
| 1008 | if (error) { |
| 1009 | hid_err(wacom->hdev, |
| 1010 | "cannot create leds err: %d\n", error); |
| 1011 | return error; |
| 1012 | } |
| 1013 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1014 | error = wacom_devm_sysfs_create_group(wacom, |
| 1015 | &intuos4_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1016 | break; |
| 1017 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 1018 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1019 | case WACOM_21UX2: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1020 | wacom->led.llv = 0; |
| 1021 | wacom->led.hlv = 0; |
| 1022 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1023 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1024 | error = wacom_led_groups_allocate(wacom, 2); |
| 1025 | if (error) { |
| 1026 | hid_err(wacom->hdev, |
| 1027 | "cannot create leds err: %d\n", error); |
| 1028 | return error; |
| 1029 | } |
| 1030 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1031 | error = wacom_devm_sysfs_create_group(wacom, |
| 1032 | &cintiq_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1033 | break; |
| 1034 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1035 | case INTUOS5S: |
| 1036 | case INTUOS5: |
| 1037 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 1038 | case INTUOSPS: |
| 1039 | case INTUOSPM: |
| 1040 | case INTUOSPL: |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 1041 | wacom->led.llv = 32; |
| 1042 | wacom->led.hlv = 0; |
| 1043 | wacom->led.img_lum = 0; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1044 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1045 | error = wacom_led_groups_allocate(wacom, 1); |
| 1046 | if (error) { |
| 1047 | hid_err(wacom->hdev, |
| 1048 | "cannot create leds err: %d\n", error); |
| 1049 | return error; |
| 1050 | } |
| 1051 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1052 | error = wacom_devm_sysfs_create_group(wacom, |
| 1053 | &intuos5_led_attr_group); |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1054 | break; |
| 1055 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1056 | case REMOTE: |
| 1057 | error = wacom_led_groups_allocate(wacom, 5); |
| 1058 | if (error) { |
| 1059 | hid_err(wacom->hdev, |
| 1060 | "cannot create leds err: %d\n", error); |
| 1061 | return error; |
| 1062 | } |
| 1063 | return 0; |
| 1064 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1065 | default: |
| 1066 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1069 | if (error) { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 1070 | hid_err(wacom->hdev, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1071 | "cannot create sysfs group err: %d\n", error); |
| 1072 | return error; |
| 1073 | } |
| 1074 | wacom_led_control(wacom); |
| 1075 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1076 | return 0; |
| 1077 | } |
| 1078 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1079 | static enum power_supply_property wacom_battery_props[] = { |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1080 | POWER_SUPPLY_PROP_PRESENT, |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1081 | POWER_SUPPLY_PROP_STATUS, |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1082 | POWER_SUPPLY_PROP_SCOPE, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1083 | POWER_SUPPLY_PROP_CAPACITY |
| 1084 | }; |
| 1085 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1086 | static enum power_supply_property wacom_ac_props[] = { |
| 1087 | POWER_SUPPLY_PROP_PRESENT, |
| 1088 | POWER_SUPPLY_PROP_ONLINE, |
| 1089 | POWER_SUPPLY_PROP_SCOPE, |
| 1090 | }; |
| 1091 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1092 | static int wacom_battery_get_property(struct power_supply *psy, |
| 1093 | enum power_supply_property psp, |
| 1094 | union power_supply_propval *val) |
| 1095 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1096 | struct wacom *wacom = power_supply_get_drvdata(psy); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1097 | int ret = 0; |
| 1098 | |
| 1099 | switch (psp) { |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1100 | case POWER_SUPPLY_PROP_PRESENT: |
| 1101 | val->intval = wacom->wacom_wac.bat_connected; |
| 1102 | break; |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1103 | case POWER_SUPPLY_PROP_SCOPE: |
| 1104 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 1105 | break; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1106 | case POWER_SUPPLY_PROP_CAPACITY: |
| 1107 | val->intval = |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1108 | wacom->wacom_wac.battery_capacity; |
| 1109 | break; |
| 1110 | case POWER_SUPPLY_PROP_STATUS: |
| 1111 | if (wacom->wacom_wac.bat_charging) |
| 1112 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
| 1113 | else if (wacom->wacom_wac.battery_capacity == 100 && |
| 1114 | wacom->wacom_wac.ps_connected) |
| 1115 | val->intval = POWER_SUPPLY_STATUS_FULL; |
Jason Gerecke | b0882cb | 2015-03-06 11:47:43 -0800 | [diff] [blame] | 1116 | else if (wacom->wacom_wac.ps_connected) |
| 1117 | val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1118 | else |
| 1119 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1120 | break; |
| 1121 | default: |
| 1122 | ret = -EINVAL; |
| 1123 | break; |
| 1124 | } |
| 1125 | |
| 1126 | return ret; |
| 1127 | } |
| 1128 | |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1129 | static int wacom_ac_get_property(struct power_supply *psy, |
| 1130 | enum power_supply_property psp, |
| 1131 | union power_supply_propval *val) |
| 1132 | { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1133 | struct wacom *wacom = power_supply_get_drvdata(psy); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1134 | int ret = 0; |
| 1135 | |
| 1136 | switch (psp) { |
| 1137 | case POWER_SUPPLY_PROP_PRESENT: |
| 1138 | /* fall through */ |
| 1139 | case POWER_SUPPLY_PROP_ONLINE: |
| 1140 | val->intval = wacom->wacom_wac.ps_connected; |
| 1141 | break; |
| 1142 | case POWER_SUPPLY_PROP_SCOPE: |
| 1143 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 1144 | break; |
| 1145 | default: |
| 1146 | ret = -EINVAL; |
| 1147 | break; |
| 1148 | } |
| 1149 | return ret; |
| 1150 | } |
| 1151 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1152 | static int wacom_initialize_battery(struct wacom *wacom) |
| 1153 | { |
Benjamin Tissoires | d70420b | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1154 | static atomic_t battery_no = ATOMIC_INIT(0); |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1155 | struct device *dev = &wacom->hdev->dev; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1156 | struct power_supply_config psy_cfg = { .drv_data = wacom, }; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1157 | struct power_supply_desc *bat_desc = &wacom->battery_desc; |
Benjamin Tissoires | d70420b | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1158 | unsigned long n; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1159 | int error; |
| 1160 | |
| 1161 | if (!devres_open_group(dev, bat_desc, GFP_KERNEL)) |
| 1162 | return -ENOMEM; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1163 | |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1164 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) { |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1165 | struct power_supply_desc *ac_desc = &wacom->ac_desc; |
Benjamin Tissoires | d70420b | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1166 | n = atomic_inc_return(&battery_no) - 1; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1167 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1168 | bat_desc->properties = wacom_battery_props; |
| 1169 | bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props); |
| 1170 | bat_desc->get_property = wacom_battery_get_property; |
Benjamin Tissoires | d70420b | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1171 | sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1172 | bat_desc->name = wacom->wacom_wac.bat_name; |
| 1173 | bat_desc->type = POWER_SUPPLY_TYPE_BATTERY; |
| 1174 | bat_desc->use_for_apm = 0; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1175 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1176 | ac_desc->properties = wacom_ac_props; |
| 1177 | ac_desc->num_properties = ARRAY_SIZE(wacom_ac_props); |
| 1178 | ac_desc->get_property = wacom_ac_get_property; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1179 | sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1180 | ac_desc->name = wacom->wacom_wac.ac_name; |
| 1181 | ac_desc->type = POWER_SUPPLY_TYPE_MAINS; |
| 1182 | ac_desc->use_for_apm = 0; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1183 | |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1184 | wacom->battery = devm_power_supply_register(dev, |
| 1185 | &wacom->battery_desc, |
| 1186 | &psy_cfg); |
| 1187 | if (IS_ERR(wacom->battery)) { |
| 1188 | error = PTR_ERR(wacom->battery); |
| 1189 | goto err; |
| 1190 | } |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1191 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1192 | power_supply_powers(wacom->battery, &wacom->hdev->dev); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1193 | |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1194 | wacom->ac = devm_power_supply_register(dev, |
| 1195 | &wacom->ac_desc, |
| 1196 | &psy_cfg); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1197 | if (IS_ERR(wacom->ac)) { |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1198 | error = PTR_ERR(wacom->ac); |
| 1199 | goto err; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1202 | power_supply_powers(wacom->ac, &wacom->hdev->dev); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1203 | } |
| 1204 | |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1205 | devres_close_group(dev, bat_desc); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1206 | return 0; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1207 | |
| 1208 | err: |
| 1209 | devres_release_group(dev, bat_desc); |
| 1210 | return error; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | static void wacom_destroy_battery(struct wacom *wacom) |
| 1214 | { |
Linus Torvalds | 8de29a3 | 2015-04-14 08:25:26 -0800 | [diff] [blame] | 1215 | if (wacom->battery) { |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1216 | devres_release_group(&wacom->hdev->dev, &wacom->battery_desc); |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1217 | wacom->battery = NULL; |
Krzysztof Kozlowski | 297d716 | 2015-03-12 08:44:11 +0100 | [diff] [blame] | 1218 | wacom->ac = NULL; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1219 | } |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1220 | } |
| 1221 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1222 | static ssize_t wacom_show_speed(struct device *dev, |
| 1223 | struct device_attribute |
| 1224 | *attr, char *buf) |
| 1225 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1226 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1227 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1228 | |
| 1229 | return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed); |
| 1230 | } |
| 1231 | |
| 1232 | static ssize_t wacom_store_speed(struct device *dev, |
| 1233 | struct device_attribute *attr, |
| 1234 | const char *buf, size_t count) |
| 1235 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1236 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1237 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1238 | u8 new_speed; |
| 1239 | |
| 1240 | if (kstrtou8(buf, 0, &new_speed)) |
| 1241 | return -EINVAL; |
| 1242 | |
| 1243 | if (new_speed != 0 && new_speed != 1) |
| 1244 | return -EINVAL; |
| 1245 | |
| 1246 | wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features); |
| 1247 | |
| 1248 | return count; |
| 1249 | } |
| 1250 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1251 | static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM, |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1252 | wacom_show_speed, wacom_store_speed); |
| 1253 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1254 | |
| 1255 | static ssize_t wacom_show_remote_mode(struct kobject *kobj, |
| 1256 | struct kobj_attribute *kattr, |
| 1257 | char *buf, int index) |
| 1258 | { |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1259 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1260 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1261 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1262 | u8 mode; |
| 1263 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1264 | mode = wacom->led.groups[index].select; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1265 | if (mode >= 0 && mode < 3) |
| 1266 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 1267 | else |
| 1268 | return snprintf(buf, PAGE_SIZE, "%d\n", -1); |
| 1269 | } |
| 1270 | |
| 1271 | #define DEVICE_EKR_ATTR_GROUP(SET_ID) \ |
| 1272 | static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \ |
| 1273 | struct kobj_attribute *kattr, char *buf) \ |
| 1274 | { \ |
| 1275 | return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \ |
| 1276 | } \ |
| 1277 | static struct kobj_attribute remote##SET_ID##_mode_attr = { \ |
| 1278 | .attr = {.name = "remote_mode", \ |
| 1279 | .mode = DEV_ATTR_RO_PERM}, \ |
| 1280 | .show = wacom_show_remote##SET_ID##_mode, \ |
| 1281 | }; \ |
| 1282 | static struct attribute *remote##SET_ID##_serial_attrs[] = { \ |
| 1283 | &remote##SET_ID##_mode_attr.attr, \ |
| 1284 | NULL \ |
| 1285 | }; \ |
| 1286 | static struct attribute_group remote##SET_ID##_serial_group = { \ |
| 1287 | .name = NULL, \ |
| 1288 | .attrs = remote##SET_ID##_serial_attrs, \ |
| 1289 | } |
| 1290 | |
| 1291 | DEVICE_EKR_ATTR_GROUP(0); |
| 1292 | DEVICE_EKR_ATTR_GROUP(1); |
| 1293 | DEVICE_EKR_ATTR_GROUP(2); |
| 1294 | DEVICE_EKR_ATTR_GROUP(3); |
| 1295 | DEVICE_EKR_ATTR_GROUP(4); |
| 1296 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1297 | static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, |
| 1298 | int index) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1299 | { |
| 1300 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1301 | struct wacom_remote *remote = wacom->remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1302 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1303 | remote->serial[index] = serial; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1304 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1305 | remote->remote_group[index].name = devm_kasprintf(&wacom->hdev->dev, |
| 1306 | GFP_KERNEL, |
| 1307 | "%d", serial); |
| 1308 | if (!remote->remote_group[index].name) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1309 | return -ENOMEM; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1310 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1311 | error = sysfs_create_group(remote->remote_dir, |
| 1312 | &remote->remote_group[index]); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1313 | if (error) { |
| 1314 | hid_err(wacom->hdev, |
| 1315 | "cannot create sysfs group err: %d\n", error); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1316 | return error; |
| 1317 | } |
| 1318 | |
| 1319 | return 0; |
| 1320 | } |
| 1321 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1322 | static void wacom_remote_destroy_attr_group(struct wacom *wacom, __u32 serial) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1323 | { |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1324 | struct wacom_remote *remote = wacom->remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1325 | int i; |
| 1326 | |
| 1327 | if (!serial) |
| 1328 | return; |
| 1329 | |
| 1330 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1331 | if (remote->serial[i] == serial) { |
| 1332 | remote->serial[i] = 0; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1333 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1334 | if (remote->remote_group[i].name) { |
| 1335 | sysfs_remove_group(remote->remote_dir, |
| 1336 | &remote->remote_group[i]); |
Benjamin Tissoires | c1f5409 | 2016-07-13 18:05:57 +0200 | [diff] [blame] | 1337 | devm_kfree(&wacom->hdev->dev, |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1338 | (char *)remote->remote_group[i].name); |
| 1339 | remote->remote_group[i].name = NULL; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1340 | } |
| 1341 | } |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) |
| 1346 | { |
| 1347 | const size_t buf_size = 2; |
| 1348 | unsigned char *buf; |
| 1349 | int retval; |
| 1350 | |
| 1351 | buf = kzalloc(buf_size, GFP_KERNEL); |
| 1352 | if (!buf) |
| 1353 | return -ENOMEM; |
| 1354 | |
| 1355 | buf[0] = WAC_CMD_DELETE_PAIRING; |
| 1356 | buf[1] = selector; |
| 1357 | |
| 1358 | retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf, |
| 1359 | buf_size, WAC_CMD_RETRIES); |
| 1360 | kfree(buf); |
| 1361 | |
| 1362 | return retval; |
| 1363 | } |
| 1364 | |
| 1365 | static ssize_t wacom_store_unpair_remote(struct kobject *kobj, |
| 1366 | struct kobj_attribute *attr, |
| 1367 | const char *buf, size_t count) |
| 1368 | { |
| 1369 | unsigned char selector = 0; |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1370 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1371 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1372 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1373 | int err; |
| 1374 | |
| 1375 | if (!strncmp(buf, "*\n", 2)) { |
| 1376 | selector = WAC_CMD_UNPAIR_ALL; |
| 1377 | } else { |
| 1378 | hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n", |
| 1379 | buf); |
| 1380 | return -1; |
| 1381 | } |
| 1382 | |
| 1383 | mutex_lock(&wacom->lock); |
| 1384 | |
| 1385 | err = wacom_cmd_unpair_remote(wacom, selector); |
| 1386 | mutex_unlock(&wacom->lock); |
| 1387 | |
| 1388 | return err < 0 ? err : count; |
| 1389 | } |
| 1390 | |
| 1391 | static struct kobj_attribute unpair_remote_attr = { |
| 1392 | .attr = {.name = "unpair_remote", .mode = 0200}, |
| 1393 | .store = wacom_store_unpair_remote, |
| 1394 | }; |
| 1395 | |
| 1396 | static const struct attribute *remote_unpair_attrs[] = { |
| 1397 | &unpair_remote_attr.attr, |
| 1398 | NULL |
| 1399 | }; |
| 1400 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1401 | static void wacom_remotes_destroy(void *data) |
| 1402 | { |
| 1403 | struct wacom *wacom = data; |
| 1404 | struct wacom_remote *remote = wacom->remote; |
| 1405 | |
| 1406 | if (!remote) |
| 1407 | return; |
| 1408 | |
| 1409 | kobject_put(remote->remote_dir); |
| 1410 | kfifo_free(&remote->remote_fifo); |
| 1411 | wacom->remote = NULL; |
| 1412 | } |
| 1413 | |
| 1414 | static int wacom_initialize_remotes(struct wacom *wacom) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1415 | { |
| 1416 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1417 | struct wacom_remote *remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1418 | int i; |
| 1419 | |
| 1420 | if (wacom->wacom_wac.features.type != REMOTE) |
| 1421 | return 0; |
| 1422 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1423 | remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote), |
| 1424 | GFP_KERNEL); |
| 1425 | if (!remote) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1426 | return -ENOMEM; |
| 1427 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1428 | wacom->remote = remote; |
| 1429 | |
| 1430 | spin_lock_init(&remote->remote_lock); |
| 1431 | |
| 1432 | error = kfifo_alloc(&remote->remote_fifo, |
| 1433 | 5 * sizeof(struct wacom_remote_data), |
| 1434 | GFP_KERNEL); |
| 1435 | if (error) { |
| 1436 | hid_err(wacom->hdev, "failed allocating remote_fifo\n"); |
| 1437 | return -ENOMEM; |
| 1438 | } |
| 1439 | |
| 1440 | remote->remote_group[0] = remote0_serial_group; |
| 1441 | remote->remote_group[1] = remote1_serial_group; |
| 1442 | remote->remote_group[2] = remote2_serial_group; |
| 1443 | remote->remote_group[3] = remote3_serial_group; |
| 1444 | remote->remote_group[4] = remote4_serial_group; |
| 1445 | |
| 1446 | remote->remote_dir = kobject_create_and_add("wacom_remote", |
| 1447 | &wacom->hdev->dev.kobj); |
| 1448 | if (!remote->remote_dir) |
| 1449 | return -ENOMEM; |
| 1450 | |
| 1451 | error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1452 | |
| 1453 | if (error) { |
| 1454 | hid_err(wacom->hdev, |
| 1455 | "cannot create sysfs group err: %d\n", error); |
| 1456 | return error; |
| 1457 | } |
| 1458 | |
| 1459 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1460 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1461 | remote->serial[i] = 0; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1464 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 1465 | wacom_remotes_destroy, wacom); |
| 1466 | if (error) |
| 1467 | return error; |
| 1468 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1469 | return 0; |
| 1470 | } |
| 1471 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1472 | static struct input_dev *wacom_allocate_input(struct wacom *wacom) |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1473 | { |
| 1474 | struct input_dev *input_dev; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1475 | struct hid_device *hdev = wacom->hdev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1476 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1477 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1478 | input_dev = devm_input_allocate_device(&hdev->dev); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1479 | if (!input_dev) |
| 1480 | return NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1481 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 1482 | input_dev->name = wacom_wac->features.name; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1483 | input_dev->phys = hdev->phys; |
| 1484 | input_dev->dev.parent = &hdev->dev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1485 | input_dev->open = wacom_open; |
| 1486 | input_dev->close = wacom_close; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1487 | input_dev->uniq = hdev->uniq; |
| 1488 | input_dev->id.bustype = hdev->bus; |
| 1489 | input_dev->id.vendor = hdev->vendor; |
Benjamin Tissoires | 12969e3 | 2014-09-11 13:14:04 -0400 | [diff] [blame] | 1490 | input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1491 | input_dev->id.version = hdev->version; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1492 | input_set_drvdata(input_dev, wacom); |
| 1493 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1494 | return input_dev; |
| 1495 | } |
| 1496 | |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1497 | static int wacom_allocate_inputs(struct wacom *wacom) |
| 1498 | { |
| 1499 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
| 1500 | |
| 1501 | wacom_wac->pen_input = wacom_allocate_input(wacom); |
| 1502 | wacom_wac->touch_input = wacom_allocate_input(wacom); |
| 1503 | wacom_wac->pad_input = wacom_allocate_input(wacom); |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1504 | if (!wacom_wac->pen_input || |
| 1505 | !wacom_wac->touch_input || |
| 1506 | !wacom_wac->pad_input) |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1507 | return -ENOMEM; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1508 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 1509 | wacom_wac->pen_input->name = wacom_wac->pen_name; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1510 | wacom_wac->touch_input->name = wacom_wac->touch_name; |
| 1511 | wacom_wac->pad_input->name = wacom_wac->pad_name; |
| 1512 | |
| 1513 | return 0; |
| 1514 | } |
| 1515 | |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1516 | static int wacom_register_inputs(struct wacom *wacom) |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1517 | { |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1518 | struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1519 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Jason Gerecke | 2636a3f | 2015-06-15 18:01:44 -0700 | [diff] [blame] | 1520 | int error = 0; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1521 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1522 | pen_input_dev = wacom_wac->pen_input; |
| 1523 | touch_input_dev = wacom_wac->touch_input; |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 1524 | pad_input_dev = wacom_wac->pad_input; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1525 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1526 | if (!pen_input_dev || !touch_input_dev || !pad_input_dev) |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 1527 | return -EINVAL; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1528 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1529 | error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac); |
| 1530 | if (error) { |
| 1531 | /* no pen in use on this interface */ |
| 1532 | input_free_device(pen_input_dev); |
| 1533 | wacom_wac->pen_input = NULL; |
| 1534 | pen_input_dev = NULL; |
| 1535 | } else { |
| 1536 | error = input_register_device(pen_input_dev); |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 1537 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1538 | goto fail; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac); |
| 1542 | if (error) { |
| 1543 | /* no touch in use on this interface */ |
| 1544 | input_free_device(touch_input_dev); |
| 1545 | wacom_wac->touch_input = NULL; |
| 1546 | touch_input_dev = NULL; |
| 1547 | } else { |
| 1548 | error = input_register_device(touch_input_dev); |
| 1549 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1550 | goto fail; |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 1551 | } |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1552 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1553 | error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); |
| 1554 | if (error) { |
| 1555 | /* no pad in use on this interface */ |
| 1556 | input_free_device(pad_input_dev); |
| 1557 | wacom_wac->pad_input = NULL; |
| 1558 | pad_input_dev = NULL; |
| 1559 | } else { |
| 1560 | error = input_register_device(pad_input_dev); |
| 1561 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1562 | goto fail; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1565 | return 0; |
| 1566 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1567 | fail: |
| 1568 | wacom_wac->pad_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1569 | wacom_wac->touch_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1570 | wacom_wac->pen_input = NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1571 | return error; |
| 1572 | } |
| 1573 | |
Jason Gerecke | 0be0171 | 2015-08-05 15:44:53 -0700 | [diff] [blame] | 1574 | /* |
| 1575 | * Not all devices report physical dimensions from HID. |
| 1576 | * Compute the default from hardcoded logical dimension |
| 1577 | * and resolution before driver overwrites them. |
| 1578 | */ |
| 1579 | static void wacom_set_default_phy(struct wacom_features *features) |
| 1580 | { |
| 1581 | if (features->x_resolution) { |
| 1582 | features->x_phy = (features->x_max * 100) / |
| 1583 | features->x_resolution; |
| 1584 | features->y_phy = (features->y_max * 100) / |
| 1585 | features->y_resolution; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | static void wacom_calculate_res(struct wacom_features *features) |
| 1590 | { |
| 1591 | /* set unit to "100th of a mm" for devices not reported by HID */ |
| 1592 | if (!features->unit) { |
| 1593 | features->unit = 0x11; |
| 1594 | features->unitExpo = -3; |
| 1595 | } |
| 1596 | |
| 1597 | features->x_resolution = wacom_calc_hid_res(features->x_max, |
| 1598 | features->x_phy, |
| 1599 | features->unit, |
| 1600 | features->unitExpo); |
| 1601 | features->y_resolution = wacom_calc_hid_res(features->y_max, |
| 1602 | features->y_phy, |
| 1603 | features->unit, |
| 1604 | features->unitExpo); |
| 1605 | } |
| 1606 | |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1607 | void wacom_battery_work(struct work_struct *work) |
| 1608 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 1609 | struct wacom *wacom = container_of(work, struct wacom, battery_work); |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1610 | |
| 1611 | if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Linus Torvalds | 8de29a3 | 2015-04-14 08:25:26 -0800 | [diff] [blame] | 1612 | !wacom->battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1613 | wacom_initialize_battery(wacom); |
| 1614 | } |
| 1615 | else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Linus Torvalds | 8de29a3 | 2015-04-14 08:25:26 -0800 | [diff] [blame] | 1616 | wacom->battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1617 | wacom_destroy_battery(wacom); |
| 1618 | } |
| 1619 | } |
| 1620 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1621 | static size_t wacom_compute_pktlen(struct hid_device *hdev) |
| 1622 | { |
| 1623 | struct hid_report_enum *report_enum; |
| 1624 | struct hid_report *report; |
| 1625 | size_t size = 0; |
| 1626 | |
| 1627 | report_enum = hdev->report_enum + HID_INPUT_REPORT; |
| 1628 | |
| 1629 | list_for_each_entry(report, &report_enum->report_list, list) { |
Mathieu Magnaudet | dabb05c6 | 2014-11-27 16:02:36 +0100 | [diff] [blame] | 1630 | size_t report_size = hid_report_len(report); |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1631 | if (report_size > size) |
| 1632 | size = report_size; |
| 1633 | } |
| 1634 | |
| 1635 | return size; |
| 1636 | } |
| 1637 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1638 | static void wacom_update_name(struct wacom *wacom, const char *suffix) |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1639 | { |
| 1640 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 1641 | struct wacom_features *features = &wacom_wac->features; |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1642 | char name[WACOM_NAME_MAX]; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1643 | |
| 1644 | /* Generic devices name unspecified */ |
| 1645 | if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { |
| 1646 | if (strstr(wacom->hdev->name, "Wacom") || |
| 1647 | strstr(wacom->hdev->name, "wacom") || |
| 1648 | strstr(wacom->hdev->name, "WACOM")) { |
| 1649 | /* name is in HID descriptor, use it */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1650 | strlcpy(name, wacom->hdev->name, sizeof(name)); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1651 | |
| 1652 | /* strip out excess whitespaces */ |
| 1653 | while (1) { |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1654 | char *gap = strstr(name, " "); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1655 | if (gap == NULL) |
| 1656 | break; |
| 1657 | /* shift everything including the terminator */ |
| 1658 | memmove(gap, gap+1, strlen(gap)); |
| 1659 | } |
| 1660 | /* get rid of trailing whitespace */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1661 | if (name[strlen(name)-1] == ' ') |
| 1662 | name[strlen(name)-1] = '\0'; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1663 | } else { |
| 1664 | /* no meaningful name retrieved. use product ID */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1665 | snprintf(name, sizeof(name), |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1666 | "%s %X", features->name, wacom->hdev->product); |
| 1667 | } |
| 1668 | } else { |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 1669 | strlcpy(name, features->name, sizeof(name)); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /* Append the device type to the name */ |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1673 | snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1674 | "%s%s Pen", name, suffix); |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1675 | snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1676 | "%s%s Finger", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1677 | snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1678 | "%s%s Pad", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 1679 | } |
| 1680 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1681 | static void wacom_release_resources(struct wacom *wacom) |
| 1682 | { |
| 1683 | struct hid_device *hdev = wacom->hdev; |
| 1684 | |
| 1685 | if (!wacom->resources) |
| 1686 | return; |
| 1687 | |
| 1688 | devres_release_group(&hdev->dev, wacom); |
| 1689 | |
| 1690 | wacom->resources = false; |
| 1691 | |
| 1692 | wacom->wacom_wac.pen_input = NULL; |
| 1693 | wacom->wacom_wac.touch_input = NULL; |
| 1694 | wacom->wacom_wac.pad_input = NULL; |
| 1695 | } |
| 1696 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1697 | static int wacom_parse_and_register(struct wacom *wacom, bool wireless) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1698 | { |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1699 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 1700 | struct wacom_features *features = &wacom_wac->features; |
| 1701 | struct hid_device *hdev = wacom->hdev; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 1702 | int error; |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 1703 | unsigned int connect_mask = HID_CONNECT_HIDRAW; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1704 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 1705 | features->pktlen = wacom_compute_pktlen(hdev); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1706 | if (features->pktlen > WACOM_PKGLEN_MAX) |
| 1707 | return -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1708 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1709 | if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL)) |
| 1710 | return -ENOMEM; |
| 1711 | |
| 1712 | wacom->resources = true; |
| 1713 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 1714 | error = wacom_allocate_inputs(wacom); |
| 1715 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1716 | goto fail; |
Benjamin Tissoires | 494078b | 2014-09-23 12:08:07 -0400 | [diff] [blame] | 1717 | |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 1718 | /* |
| 1719 | * Bamboo Pad has a generic hid handling for the Pen, and we switch it |
| 1720 | * into debug mode for the touch part. |
| 1721 | * We ignore the other interfaces. |
| 1722 | */ |
| 1723 | if (features->type == BAMBOO_PAD) { |
| 1724 | if (features->pktlen == WACOM_PKGLEN_PENABLED) { |
| 1725 | features->type = HID_GENERIC; |
| 1726 | } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) && |
| 1727 | (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) { |
| 1728 | error = -ENODEV; |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1729 | goto fail; |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 1730 | } |
| 1731 | } |
| 1732 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1733 | /* set the default size in case we do not get them from hid */ |
| 1734 | wacom_set_default_phy(features); |
| 1735 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 1736 | /* Retrieve the physical and logical size for touch devices */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 1737 | wacom_retrieve_hid_descriptor(hdev, features); |
Ping Cheng | 42f4f27 | 2015-04-15 16:53:54 -0700 | [diff] [blame] | 1738 | wacom_setup_device_quirks(wacom); |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 1739 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 1740 | if (features->device_type == WACOM_DEVICETYPE_NONE && |
| 1741 | features->type != WIRELESS) { |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 1742 | error = features->type == HID_GENERIC ? -ENODEV : 0; |
| 1743 | |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 1744 | dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.", |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 1745 | hdev->name, |
| 1746 | error ? "Ignoring" : "Assuming pen"); |
| 1747 | |
| 1748 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1749 | goto fail; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 1750 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 1751 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 1752 | } |
| 1753 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 1754 | wacom_calculate_res(features); |
| 1755 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1756 | wacom_update_name(wacom, wireless ? " (WL)" : ""); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 1757 | |
Ping Cheng | f3586d2 | 2015-03-20 14:57:00 -0700 | [diff] [blame] | 1758 | error = wacom_add_shared_data(hdev); |
| 1759 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1760 | goto fail; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 1761 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 1762 | if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) && |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1763 | (features->quirks & WACOM_QUIRK_BATTERY)) { |
| 1764 | error = wacom_initialize_battery(wacom); |
| 1765 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1766 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1767 | } |
| 1768 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 1769 | error = wacom_register_inputs(wacom); |
| 1770 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1771 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1772 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1773 | if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) { |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 1774 | error = wacom_initialize_leds(wacom); |
| 1775 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1776 | goto fail; |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 1777 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1778 | error = wacom_initialize_remotes(wacom); |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1779 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1780 | goto fail; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1781 | } |
| 1782 | |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 1783 | if (features->type == HID_GENERIC) |
| 1784 | connect_mask |= HID_CONNECT_DRIVER; |
| 1785 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1786 | /* Regular HID work starts now */ |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 1787 | error = hid_hw_start(hdev, connect_mask); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1788 | if (error) { |
| 1789 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1790 | goto fail; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1793 | if (!wireless) { |
| 1794 | /* Note that if query fails it is not a hard failure */ |
| 1795 | wacom_query_tablet_data(hdev, features); |
| 1796 | } |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 1797 | |
| 1798 | /* touch only Bamboo doesn't support pen */ |
| 1799 | if ((features->type == BAMBOO_TOUCH) && |
| 1800 | (features->device_type & WACOM_DEVICETYPE_PEN)) { |
| 1801 | error = -ENODEV; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1802 | goto fail_quirks; |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | /* pen only Bamboo neither support touch nor pad */ |
| 1806 | if ((features->type == BAMBOO_PEN) && |
| 1807 | ((features->device_type & WACOM_DEVICETYPE_TOUCH) || |
| 1808 | (features->device_type & WACOM_DEVICETYPE_PAD))) { |
| 1809 | error = -ENODEV; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1810 | goto fail_quirks; |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 1811 | } |
| 1812 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 1813 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 1814 | error = hid_hw_open(hdev); |
| 1815 | |
Ping Cheng | eda01da | 2015-09-23 13:51:15 -0700 | [diff] [blame] | 1816 | if ((wacom_wac->features.type == INTUOSHT || |
Benjamin Tissoires | 97f9afa | 2016-07-13 18:05:49 +0200 | [diff] [blame] | 1817 | wacom_wac->features.type == INTUOSHT2) && |
Ping Cheng | eda01da | 2015-09-23 13:51:15 -0700 | [diff] [blame] | 1818 | (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH)) { |
Benjamin Tissoires | 97f9afa | 2016-07-13 18:05:49 +0200 | [diff] [blame] | 1819 | wacom_wac->shared->type = wacom_wac->features.type; |
| 1820 | wacom_wac->shared->touch_input = wacom_wac->touch_input; |
Ping Cheng | 961794a | 2013-12-05 12:54:53 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1823 | devres_close_group(&hdev->dev, wacom); |
| 1824 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 1825 | return 0; |
| 1826 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 1827 | fail_quirks: |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1828 | hid_hw_stop(hdev); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 1829 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1830 | wacom_release_resources(wacom); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1831 | return error; |
| 1832 | } |
| 1833 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1834 | static void wacom_wireless_work(struct work_struct *work) |
| 1835 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 1836 | struct wacom *wacom = container_of(work, struct wacom, wireless_work); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1837 | struct usb_device *usbdev = wacom->usbdev; |
| 1838 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 1839 | struct hid_device *hdev1, *hdev2; |
| 1840 | struct wacom *wacom1, *wacom2; |
| 1841 | struct wacom_wac *wacom_wac1, *wacom_wac2; |
| 1842 | int error; |
| 1843 | |
| 1844 | /* |
| 1845 | * Regardless if this is a disconnect or a new tablet, |
| 1846 | * remove any existing input and battery devices. |
| 1847 | */ |
| 1848 | |
| 1849 | wacom_destroy_battery(wacom); |
| 1850 | |
| 1851 | /* Stylus interface */ |
| 1852 | hdev1 = usb_get_intfdata(usbdev->config->interface[1]); |
| 1853 | wacom1 = hid_get_drvdata(hdev1); |
| 1854 | wacom_wac1 = &(wacom1->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1855 | wacom_release_resources(wacom1); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1856 | |
| 1857 | /* Touch interface */ |
| 1858 | hdev2 = usb_get_intfdata(usbdev->config->interface[2]); |
| 1859 | wacom2 = hid_get_drvdata(hdev2); |
| 1860 | wacom_wac2 = &(wacom2->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1861 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1862 | |
| 1863 | if (wacom_wac->pid == 0) { |
| 1864 | hid_info(wacom->hdev, "wireless tablet disconnected\n"); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1865 | } else { |
| 1866 | const struct hid_device_id *id = wacom_ids; |
| 1867 | |
| 1868 | hid_info(wacom->hdev, "wireless tablet connected with PID %x\n", |
| 1869 | wacom_wac->pid); |
| 1870 | |
| 1871 | while (id->bus) { |
| 1872 | if (id->vendor == USB_VENDOR_ID_WACOM && |
| 1873 | id->product == wacom_wac->pid) |
| 1874 | break; |
| 1875 | id++; |
| 1876 | } |
| 1877 | |
| 1878 | if (!id->bus) { |
| 1879 | hid_info(wacom->hdev, "ignoring unknown PID.\n"); |
| 1880 | return; |
| 1881 | } |
| 1882 | |
| 1883 | /* Stylus interface */ |
| 1884 | wacom_wac1->features = |
| 1885 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1886 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1887 | wacom_wac1->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1888 | hid_hw_stop(hdev1); |
| 1889 | error = wacom_parse_and_register(wacom1, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1890 | if (error) |
| 1891 | goto fail; |
| 1892 | |
| 1893 | /* Touch interface */ |
| 1894 | if (wacom_wac1->features.touch_max || |
| 1895 | (wacom_wac1->features.type >= INTUOSHT && |
| 1896 | wacom_wac1->features.type <= BAMBOO_PT)) { |
| 1897 | wacom_wac2->features = |
| 1898 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1899 | wacom_wac2->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 1900 | hid_hw_stop(hdev2); |
| 1901 | error = wacom_parse_and_register(wacom2, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1902 | if (error) |
| 1903 | goto fail; |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | error = wacom_initialize_battery(wacom); |
| 1907 | if (error) |
| 1908 | goto fail; |
| 1909 | } |
| 1910 | |
| 1911 | return; |
| 1912 | |
| 1913 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1914 | wacom_release_resources(wacom1); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 1915 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 1916 | return; |
| 1917 | } |
| 1918 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1919 | static void wacom_remote_work(struct work_struct *work) |
| 1920 | { |
| 1921 | struct wacom *wacom = container_of(work, struct wacom, remote_work); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1922 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1923 | struct wacom_remote_data data; |
| 1924 | unsigned long flags; |
| 1925 | unsigned int count; |
| 1926 | u32 serial; |
| 1927 | int i, k; |
| 1928 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1929 | spin_lock_irqsave(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1930 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1931 | count = kfifo_out(&remote->remote_fifo, &data, sizeof(data)); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1932 | |
| 1933 | if (count != sizeof(data)) { |
| 1934 | hid_err(wacom->hdev, |
| 1935 | "workitem triggered without status available\n"); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1936 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1937 | return; |
| 1938 | } |
| 1939 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1940 | if (!kfifo_is_empty(&remote->remote_fifo)) |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1941 | wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE); |
| 1942 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1943 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1944 | |
| 1945 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
| 1946 | serial = data.remote[i].serial; |
| 1947 | if (data.remote[i].connected) { |
| 1948 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1949 | if (remote->serial[i] == serial) |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1950 | continue; |
| 1951 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1952 | if (remote->serial[i]) { |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1953 | wacom_remote_destroy_attr_group(wacom, |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1954 | remote->serial[i]); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | /* A remote can pair more than once with an EKR, |
| 1958 | * check to make sure this serial isn't already paired. |
| 1959 | */ |
| 1960 | for (k = 0; k < WACOM_MAX_REMOTES; k++) { |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1961 | if (remote->serial[k] == serial) |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1962 | break; |
| 1963 | } |
| 1964 | |
| 1965 | if (k < WACOM_MAX_REMOTES) { |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1966 | remote->serial[i] = serial; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1967 | continue; |
| 1968 | } |
| 1969 | wacom_remote_create_attr_group(wacom, serial, i); |
| 1970 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1971 | } else if (remote->serial[i]) { |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1972 | wacom_remote_destroy_attr_group(wacom, |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1973 | remote->serial[i]); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1974 | } |
| 1975 | } |
| 1976 | } |
| 1977 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1978 | static int wacom_probe(struct hid_device *hdev, |
| 1979 | const struct hid_device_id *id) |
| 1980 | { |
| 1981 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 1982 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1983 | struct wacom *wacom; |
| 1984 | struct wacom_wac *wacom_wac; |
| 1985 | struct wacom_features *features; |
| 1986 | int error; |
| 1987 | |
| 1988 | if (!id->driver_data) |
| 1989 | return -EINVAL; |
| 1990 | |
| 1991 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 1992 | |
| 1993 | /* hid-core sets this quirk for the boot interface */ |
| 1994 | hdev->quirks &= ~HID_QUIRK_NOGET; |
| 1995 | |
Benjamin Tissoires | 19b6433 | 2016-07-13 18:05:58 +0200 | [diff] [blame] | 1996 | wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 1997 | if (!wacom) |
| 1998 | return -ENOMEM; |
| 1999 | |
| 2000 | hid_set_drvdata(hdev, wacom); |
| 2001 | wacom->hdev = hdev; |
| 2002 | |
| 2003 | wacom_wac = &wacom->wacom_wac; |
| 2004 | wacom_wac->features = *((struct wacom_features *)id->driver_data); |
| 2005 | features = &wacom_wac->features; |
| 2006 | |
| 2007 | if (features->check_for_hid_type && features->hid_type != hdev->type) { |
| 2008 | error = -ENODEV; |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 2009 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2010 | } |
| 2011 | |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2012 | wacom_wac->hid_data.inputmode = -1; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 2013 | wacom_wac->mode_report = -1; |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2014 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2015 | wacom->usbdev = dev; |
| 2016 | wacom->intf = intf; |
| 2017 | mutex_init(&wacom->lock); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2018 | INIT_WORK(&wacom->wireless_work, wacom_wireless_work); |
| 2019 | INIT_WORK(&wacom->battery_work, wacom_battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2020 | INIT_WORK(&wacom->remote_work, wacom_remote_work); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2021 | |
| 2022 | /* ask for the report descriptor to be loaded by HID */ |
| 2023 | error = hid_parse(hdev); |
| 2024 | if (error) { |
| 2025 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 2026 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2027 | } |
| 2028 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2029 | error = wacom_parse_and_register(wacom, false); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2030 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 2031 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2032 | |
| 2033 | if (hdev->bus == BUS_BLUETOOTH) { |
| 2034 | error = device_create_file(&hdev->dev, &dev_attr_speed); |
| 2035 | if (error) |
| 2036 | hid_warn(hdev, |
| 2037 | "can't create sysfs speed attribute err: %d\n", |
| 2038 | error); |
| 2039 | } |
| 2040 | |
| 2041 | return 0; |
| 2042 | |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame^] | 2043 | fail: |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2044 | hid_set_drvdata(hdev, NULL); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 2045 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2048 | static void wacom_remove(struct hid_device *hdev) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2049 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2050 | struct wacom *wacom = hid_get_drvdata(hdev); |
Benjamin Tissoires | f620516 | 2016-02-12 17:27:45 +0100 | [diff] [blame] | 2051 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2052 | struct wacom_features *features = &wacom_wac->features; |
| 2053 | |
| 2054 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
| 2055 | hid_hw_close(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2056 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2057 | hid_hw_stop(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2058 | |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2059 | cancel_work_sync(&wacom->wireless_work); |
| 2060 | cancel_work_sync(&wacom->battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2061 | cancel_work_sync(&wacom->remote_work); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2062 | if (hdev->bus == BUS_BLUETOOTH) |
| 2063 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2064 | |
| 2065 | hid_set_drvdata(hdev, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2066 | } |
| 2067 | |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2068 | #ifdef CONFIG_PM |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2069 | static int wacom_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2070 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2071 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 2072 | struct wacom_features *features = &wacom->wacom_wac.features; |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2073 | |
| 2074 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2075 | |
| 2076 | /* switch to wacom mode first */ |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 2077 | wacom_query_tablet_data(hdev, features); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2078 | wacom_led_control(wacom); |
| 2079 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2080 | mutex_unlock(&wacom->lock); |
| 2081 | |
| 2082 | return 0; |
| 2083 | } |
| 2084 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2085 | static int wacom_reset_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2086 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2087 | return wacom_resume(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2088 | } |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2089 | #endif /* CONFIG_PM */ |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2090 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2091 | static struct hid_driver wacom_driver = { |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2092 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 2093 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2094 | .probe = wacom_probe, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2095 | .remove = wacom_remove, |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2096 | .report = wacom_wac_report, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2097 | #ifdef CONFIG_PM |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2098 | .resume = wacom_resume, |
| 2099 | .reset_resume = wacom_reset_resume, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2100 | #endif |
| 2101 | .raw_event = wacom_raw_event, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2102 | }; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2103 | module_hid_driver(wacom_driver); |
Benjamin Tissoires | f2e0a7d | 2014-08-06 14:07:49 -0700 | [diff] [blame] | 2104 | |
| 2105 | MODULE_VERSION(DRIVER_VERSION); |
| 2106 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 2107 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 2108 | MODULE_LICENSE(DRIVER_LICENSE); |