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 |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 19 | #define WAC_CMD_RETRIES 10 |
| 20 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 21 | #define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP) |
| 22 | #define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 23 | #define DEV_ATTR_RO_PERM (S_IRUSR | S_IRGRP) |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 24 | |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 25 | static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 26 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 27 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 28 | int retval; |
| 29 | |
| 30 | do { |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 31 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 32 | HID_REQ_GET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 33 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 34 | |
| 35 | if (retval < 0) |
| 36 | hid_err(hdev, "wacom_get_report: ran out of retries " |
| 37 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 38 | |
| 39 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 42 | static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf, |
| 43 | size_t size, unsigned int retries) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 44 | { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 45 | int retval; |
| 46 | |
| 47 | do { |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 48 | retval = hid_hw_raw_request(hdev, buf[0], buf, size, type, |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 49 | HID_REQ_SET_REPORT); |
Jason Gerecke | aef3156 | 2015-05-21 10:44:31 -0700 | [diff] [blame] | 50 | } while ((retval == -ETIMEDOUT || retval == -EAGAIN) && --retries); |
| 51 | |
| 52 | if (retval < 0) |
| 53 | hid_err(hdev, "wacom_set_report: ran out of retries " |
| 54 | "(last error = %d)\n", retval); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 55 | |
| 56 | return retval; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 59 | static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report, |
| 60 | u8 *raw_data, int size) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 61 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 62 | struct wacom *wacom = hid_get_drvdata(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 63 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 64 | if (size > WACOM_PKGLEN_MAX) |
| 65 | return 1; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 66 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 67 | memcpy(wacom->wacom_wac.data, raw_data, size); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 68 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 69 | wacom_wac_irq(&wacom->wacom_wac, size); |
| 70 | |
| 71 | return 0; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 74 | static int wacom_open(struct input_dev *dev) |
| 75 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 76 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 77 | |
Benjamin Tissoires | dff6741 | 2014-12-01 11:52:40 -0500 | [diff] [blame] | 78 | return hid_hw_open(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static void wacom_close(struct input_dev *dev) |
| 82 | { |
Dmitry Torokhov | 7791bda | 2007-04-12 01:34:39 -0400 | [diff] [blame] | 83 | struct wacom *wacom = input_get_drvdata(dev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 84 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 85 | /* |
| 86 | * wacom->hdev should never be null, but surprisingly, I had the case |
| 87 | * once while unplugging the Wacom Wireless Receiver. |
| 88 | */ |
| 89 | if (wacom->hdev) |
| 90 | hid_hw_close(wacom->hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Chris Bagwell | 16bf288 | 2012-03-25 23:26:20 -0700 | [diff] [blame] | 93 | /* |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 94 | * 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] | 95 | */ |
| 96 | static int wacom_calc_hid_res(int logical_extents, int physical_extents, |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 97 | unsigned unit, int exponent) |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 98 | { |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 99 | struct hid_field field = { |
| 100 | .logical_maximum = logical_extents, |
| 101 | .physical_maximum = physical_extents, |
| 102 | .unit = unit, |
| 103 | .unit_exponent = exponent, |
| 104 | }; |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 105 | |
Benjamin Tissoires | 198fdee | 2014-07-24 13:03:05 -0700 | [diff] [blame] | 106 | return hidinput_calc_abs_res(&field, ABS_X); |
Jason Gerecke | 115d5e1 | 2012-10-03 17:24:32 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 109 | static void wacom_feature_mapping(struct hid_device *hdev, |
| 110 | struct hid_field *field, struct hid_usage *usage) |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 111 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 112 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 113 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 114 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 115 | unsigned int equivalent_usage = wacom_equivalent_usage(usage->hid); |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 116 | u8 *data; |
| 117 | int ret; |
Jason Gerecke | 345857b | 2016-10-19 18:03:50 -0700 | [diff] [blame] | 118 | int n; |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 119 | |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 120 | switch (equivalent_usage) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 121 | case HID_DG_CONTACTMAX: |
| 122 | /* leave touch_max as is if predefined */ |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 123 | if (!features->touch_max) { |
| 124 | /* read manually */ |
| 125 | data = kzalloc(2, GFP_KERNEL); |
| 126 | if (!data) |
| 127 | break; |
| 128 | data[0] = field->report->id; |
| 129 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Jason Gerecke | 05e8fd9 | 2015-05-21 10:44:32 -0700 | [diff] [blame] | 130 | data, 2, WAC_CMD_RETRIES); |
| 131 | if (ret == 2) { |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 132 | features->touch_max = data[1]; |
Jason Gerecke | 05e8fd9 | 2015-05-21 10:44:32 -0700 | [diff] [blame] | 133 | } else { |
| 134 | features->touch_max = 16; |
| 135 | hid_warn(hdev, "wacom_feature_mapping: " |
| 136 | "could not get HID_DG_CONTACTMAX, " |
| 137 | "defaulting to %d\n", |
| 138 | features->touch_max); |
| 139 | } |
Benjamin Tissoires | 8ffffd5 | 2014-09-16 16:56:39 -0400 | [diff] [blame] | 140 | kfree(data); |
| 141 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 142 | break; |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 143 | case HID_DG_INPUTMODE: |
| 144 | /* Ignore if value index is out of bounds. */ |
| 145 | if (usage->usage_index >= field->report_count) { |
| 146 | dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n"); |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | hid_data->inputmode = field->report->id; |
| 151 | hid_data->inputmode_index = usage->usage_index; |
| 152 | break; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 153 | |
| 154 | case HID_UP_DIGITIZER: |
| 155 | if (field->report->id == 0x0B && |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 156 | (field->application == WACOM_HID_G9_PEN || |
| 157 | field->application == WACOM_HID_G11_PEN)) { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 158 | wacom->wacom_wac.mode_report = field->report->id; |
| 159 | wacom->wacom_wac.mode_value = 0; |
| 160 | } |
| 161 | break; |
| 162 | |
Jason Gerecke | c9c0958 | 2016-10-19 18:03:43 -0700 | [diff] [blame] | 163 | case WACOM_HID_WD_DATAMODE: |
| 164 | wacom->wacom_wac.mode_report = field->report->id; |
| 165 | wacom->wacom_wac.mode_value = 2; |
| 166 | break; |
| 167 | |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 168 | case WACOM_HID_UP_G9: |
| 169 | case WACOM_HID_UP_G11: |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 170 | if (field->report->id == 0x03 && |
Jason Gerecke | 8de8228 | 2016-10-19 18:03:37 -0700 | [diff] [blame] | 171 | (field->application == WACOM_HID_G9_TOUCHSCREEN || |
| 172 | field->application == WACOM_HID_G11_TOUCHSCREEN)) { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 173 | wacom->wacom_wac.mode_report = field->report->id; |
| 174 | wacom->wacom_wac.mode_value = 0; |
| 175 | } |
| 176 | break; |
Jason Gerecke | 345857b | 2016-10-19 18:03:50 -0700 | [diff] [blame] | 177 | case WACOM_HID_WD_OFFSETLEFT: |
| 178 | case WACOM_HID_WD_OFFSETTOP: |
| 179 | case WACOM_HID_WD_OFFSETRIGHT: |
| 180 | case WACOM_HID_WD_OFFSETBOTTOM: |
| 181 | /* read manually */ |
| 182 | n = hid_report_len(field->report); |
| 183 | data = hid_alloc_report_buf(field->report, GFP_KERNEL); |
| 184 | if (!data) |
| 185 | break; |
| 186 | data[0] = field->report->id; |
| 187 | ret = wacom_get_report(hdev, HID_FEATURE_REPORT, |
| 188 | data, n, WAC_CMD_RETRIES); |
| 189 | if (ret == n) { |
| 190 | ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, |
| 191 | data, n, 0); |
| 192 | } else { |
| 193 | hid_warn(hdev, "%s: could not retrieve sensor offsets\n", |
| 194 | __func__); |
| 195 | } |
| 196 | kfree(data); |
| 197 | break; |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 201 | /* |
| 202 | * Interface Descriptor of wacom devices can be incomplete and |
| 203 | * inconsistent so wacom_features table is used to store stylus |
| 204 | * device's packet lengths, various maximum values, and tablet |
| 205 | * resolution based on product ID's. |
| 206 | * |
| 207 | * For devices that contain 2 interfaces, wacom_features table is |
| 208 | * inaccurate for the touch interface. Since the Interface Descriptor |
| 209 | * for touch interfaces has pretty complete data, this function exists |
| 210 | * to query tablet for this missing information instead of hard coding in |
| 211 | * an additional table. |
| 212 | * |
| 213 | * A typical Interface Descriptor for a stylus will contain a |
| 214 | * boot mouse application collection that is not of interest and this |
| 215 | * function will ignore it. |
| 216 | * |
| 217 | * It also contains a digitizer application collection that also is not |
| 218 | * of interest since any information it contains would be duplicate |
| 219 | * of what is in wacom_features. Usually it defines a report of an array |
| 220 | * of bytes that could be used as max length of the stylus packet returned. |
| 221 | * If it happens to define a Digitizer-Stylus Physical Collection then |
| 222 | * the X and Y logical values contain valid data but it is ignored. |
| 223 | * |
| 224 | * A typical Interface Descriptor for a touch interface will contain a |
| 225 | * Digitizer-Finger Physical Collection which will define both logical |
| 226 | * X/Y maximum as well as the physical size of tablet. Since touch |
| 227 | * interfaces haven't supported pressure or distance, this is enough |
| 228 | * information to override invalid values in the wacom_features table. |
Chris Bagwell | 4134361 | 2011-10-26 22:32:52 -0700 | [diff] [blame] | 229 | * |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 230 | * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful |
| 231 | * data. We deal with them after returning from this function. |
Chris Bagwell | 428f858 | 2011-10-26 22:26:59 -0700 | [diff] [blame] | 232 | */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 233 | static void wacom_usage_mapping(struct hid_device *hdev, |
| 234 | struct hid_field *field, struct hid_usage *usage) |
| 235 | { |
| 236 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 237 | struct wacom_features *features = &wacom->wacom_wac.features; |
Benjamin Tissoires | d97a552 | 2015-01-05 16:32:12 -0500 | [diff] [blame] | 238 | bool finger = WACOM_FINGER_FIELD(field); |
| 239 | bool pen = WACOM_PEN_FIELD(field); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * Requiring Stylus Usage will ignore boot mouse |
| 243 | * X/Y values and some cases of invalid Digitizer X/Y |
| 244 | * values commonly reported. |
| 245 | */ |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 246 | if (pen) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 247 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 248 | else if (finger) |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 249 | features->device_type |= WACOM_DEVICETYPE_TOUCH; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 250 | else |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 251 | return; |
| 252 | |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 253 | /* |
| 254 | * Bamboo models do not support HID_DG_CONTACTMAX. |
| 255 | * And, Bamboo Pen only descriptor contains touch. |
| 256 | */ |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 257 | if (features->type > BAMBOO_PT) { |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 258 | /* ISDv4 touch devices at least supports one touch point */ |
| 259 | if (finger && !features->touch_max) |
| 260 | features->touch_max = 1; |
| 261 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 262 | |
Jason Gerecke | 6005a13 | 2016-10-19 18:03:40 -0700 | [diff] [blame] | 263 | /* |
| 264 | * ISDv4 devices which predate HID's adoption of the |
| 265 | * HID_DG_BARELSWITCH2 usage use 0x000D0000 in its |
| 266 | * position instead. We can accurately detect if a |
| 267 | * usage with that value should be HID_DG_BARRELSWITCH2 |
| 268 | * based on the surrounding usages, which have remained |
| 269 | * constant across generations. |
| 270 | */ |
| 271 | if (features->type == HID_GENERIC && |
| 272 | usage->hid == 0x000D0000 && |
| 273 | field->application == HID_DG_PEN && |
| 274 | field->physical == HID_DG_STYLUS) { |
| 275 | int i = usage->usage_index; |
| 276 | |
| 277 | if (i-4 >= 0 && i+1 < field->maxusage && |
| 278 | field->usage[i-4].hid == HID_DG_TIPSWITCH && |
| 279 | field->usage[i-3].hid == HID_DG_BARRELSWITCH && |
| 280 | field->usage[i-2].hid == HID_DG_ERASER && |
| 281 | field->usage[i-1].hid == HID_DG_INVERT && |
| 282 | field->usage[i+1].hid == HID_DG_INRANGE) { |
| 283 | usage->hid = HID_DG_BARRELSWITCH2; |
| 284 | } |
| 285 | } |
| 286 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 287 | switch (usage->hid) { |
| 288 | case HID_GD_X: |
| 289 | features->x_max = field->logical_maximum; |
| 290 | if (finger) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 291 | features->x_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 292 | if ((features->type != BAMBOO_PT) && |
| 293 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 294 | features->unit = field->unit; |
| 295 | features->unitExpo = field->unit_exponent; |
| 296 | } |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 297 | } |
| 298 | break; |
| 299 | case HID_GD_Y: |
| 300 | features->y_max = field->logical_maximum; |
| 301 | if (finger) { |
| 302 | features->y_phy = field->physical_maximum; |
Ping Cheng | 3b164a0 | 2015-09-23 09:59:10 -0700 | [diff] [blame] | 303 | if ((features->type != BAMBOO_PT) && |
| 304 | (features->type != BAMBOO_TOUCH)) { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 305 | features->unit = field->unit; |
| 306 | features->unitExpo = field->unit_exponent; |
| 307 | } |
| 308 | } |
| 309 | break; |
| 310 | case HID_DG_TIPPRESSURE: |
| 311 | if (pen) |
| 312 | features->pressure_max = field->logical_maximum; |
| 313 | break; |
| 314 | } |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 315 | |
| 316 | if (features->type == HID_GENERIC) |
| 317 | wacom_wac_usage_mapping(hdev, field, usage); |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 320 | static void wacom_post_parse_hid(struct hid_device *hdev, |
| 321 | struct wacom_features *features) |
| 322 | { |
| 323 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 324 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 325 | |
| 326 | if (features->type == HID_GENERIC) { |
| 327 | /* Any last-minute generic device setup */ |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 328 | if (wacom_wac->has_mode_change) { |
| 329 | if (wacom_wac->is_direct_mode) |
| 330 | features->device_type |= WACOM_DEVICETYPE_DIRECT; |
| 331 | else |
| 332 | features->device_type &= ~WACOM_DEVICETYPE_DIRECT; |
| 333 | } |
| 334 | |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 335 | if (features->touch_max > 1) { |
Aaron Armstrong Skomra | ac2423c | 2017-01-25 12:08:40 -0800 | [diff] [blame] | 336 | if (features->device_type & WACOM_DEVICETYPE_DIRECT) |
| 337 | input_mt_init_slots(wacom_wac->touch_input, |
| 338 | wacom_wac->features.touch_max, |
| 339 | INPUT_MT_DIRECT); |
| 340 | else |
| 341 | input_mt_init_slots(wacom_wac->touch_input, |
| 342 | wacom_wac->features.touch_max, |
| 343 | INPUT_MT_POINTER); |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 344 | } |
| 345 | } |
| 346 | } |
| 347 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 348 | static void wacom_parse_hid(struct hid_device *hdev, |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 349 | struct wacom_features *features) |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 350 | { |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 351 | struct hid_report_enum *rep_enum; |
| 352 | struct hid_report *hreport; |
| 353 | int i, j; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 354 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 355 | /* check features first */ |
| 356 | rep_enum = &hdev->report_enum[HID_FEATURE_REPORT]; |
| 357 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 358 | for (i = 0; i < hreport->maxfield; i++) { |
| 359 | /* Ignore if report count is out of bounds. */ |
| 360 | if (hreport->field[i]->report_count < 1) |
| 361 | continue; |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 362 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 363 | for (j = 0; j < hreport->field[i]->maxusage; j++) { |
| 364 | wacom_feature_mapping(hdev, hreport->field[i], |
| 365 | hreport->field[i]->usage + j); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 366 | } |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 370 | /* now check the input usages */ |
| 371 | rep_enum = &hdev->report_enum[HID_INPUT_REPORT]; |
| 372 | list_for_each_entry(hreport, &rep_enum->report_list, list) { |
| 373 | |
| 374 | if (!hreport->maxfield) |
| 375 | continue; |
| 376 | |
| 377 | for (i = 0; i < hreport->maxfield; i++) |
| 378 | for (j = 0; j < hreport->field[i]->maxusage; j++) |
| 379 | wacom_usage_mapping(hdev, hreport->field[i], |
| 380 | hreport->field[i]->usage + j); |
| 381 | } |
Jason Gerecke | b58ba1b | 2014-12-05 13:37:32 -0800 | [diff] [blame] | 382 | |
| 383 | wacom_post_parse_hid(hdev, features); |
Ping Cheng | 545f4e9 | 2008-11-24 11:44:27 -0500 | [diff] [blame] | 384 | } |
| 385 | |
Benjamin Tissoires | 5ae6e89 | 2014-09-23 12:08:09 -0400 | [diff] [blame] | 386 | static int wacom_hid_set_device_mode(struct hid_device *hdev) |
| 387 | { |
| 388 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 389 | struct hid_data *hid_data = &wacom->wacom_wac.hid_data; |
| 390 | struct hid_report *r; |
| 391 | struct hid_report_enum *re; |
| 392 | |
| 393 | if (hid_data->inputmode < 0) |
| 394 | return 0; |
| 395 | |
| 396 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 397 | r = re->report_id_hash[hid_data->inputmode]; |
| 398 | if (r) { |
| 399 | r->field[0]->value[hid_data->inputmode_index] = 2; |
| 400 | hid_hw_request(hdev, r, HID_REQ_SET_REPORT); |
| 401 | } |
| 402 | return 0; |
| 403 | } |
| 404 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 405 | static int wacom_set_device_mode(struct hid_device *hdev, |
| 406 | struct wacom_wac *wacom_wac) |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 407 | { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 408 | u8 *rep_data; |
| 409 | struct hid_report *r; |
| 410 | struct hid_report_enum *re; |
| 411 | int length; |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 412 | int error = -ENOMEM, limit = 0; |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 413 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 414 | if (wacom_wac->mode_report < 0) |
| 415 | return 0; |
| 416 | |
| 417 | re = &(hdev->report_enum[HID_FEATURE_REPORT]); |
| 418 | r = re->report_id_hash[wacom_wac->mode_report]; |
| 419 | if (!r) |
| 420 | return -EINVAL; |
| 421 | |
| 422 | rep_data = hid_alloc_report_buf(r, GFP_KERNEL); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 423 | if (!rep_data) |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 424 | return -ENOMEM; |
| 425 | |
| 426 | length = hid_report_len(r); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 427 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 428 | do { |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 429 | rep_data[0] = wacom_wac->mode_report; |
| 430 | rep_data[1] = wacom_wac->mode_value; |
Chris Bagwell | 9937c02 | 2013-01-23 19:37:34 -0800 | [diff] [blame] | 431 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 432 | error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, |
| 433 | length, 1); |
Benjamin Tissoires | 3cb8315 | 2014-07-24 12:47:47 -0700 | [diff] [blame] | 434 | if (error >= 0) |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 435 | error = wacom_get_report(hdev, HID_FEATURE_REPORT, |
Ping Cheng | c64d883 | 2014-09-10 12:41:04 -0700 | [diff] [blame] | 436 | rep_data, length, 1); |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 437 | } while (error >= 0 && |
| 438 | rep_data[1] != wacom_wac->mode_report && |
| 439 | limit++ < WAC_MSG_RETRIES); |
Dmitry Torokhov | 3b7307c | 2009-08-20 21:41:04 -0700 | [diff] [blame] | 440 | |
| 441 | kfree(rep_data); |
| 442 | |
| 443 | return error < 0 ? error : 0; |
| 444 | } |
| 445 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 446 | static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed, |
| 447 | struct wacom_features *features) |
| 448 | { |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 449 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 450 | int ret; |
| 451 | u8 rep_data[2]; |
| 452 | |
| 453 | switch (features->type) { |
| 454 | case GRAPHIRE_BT: |
| 455 | rep_data[0] = 0x03; |
| 456 | rep_data[1] = 0x00; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 457 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 458 | 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 459 | |
| 460 | if (ret >= 0) { |
| 461 | rep_data[0] = speed == 0 ? 0x05 : 0x06; |
| 462 | rep_data[1] = 0x00; |
| 463 | |
| 464 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 465 | rep_data, 2, 3); |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 466 | |
| 467 | if (ret >= 0) { |
| 468 | wacom->wacom_wac.bt_high_speed = speed; |
| 469 | return 0; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | /* |
| 474 | * Note that if the raw queries fail, it's not a hard failure |
| 475 | * and it is safe to continue |
| 476 | */ |
| 477 | hid_warn(hdev, "failed to poke device, command %d, err %d\n", |
| 478 | rep_data[0], ret); |
| 479 | break; |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 480 | case INTUOS4WL: |
| 481 | if (speed == 1) |
| 482 | wacom->wacom_wac.bt_features &= ~0x20; |
| 483 | else |
| 484 | wacom->wacom_wac.bt_features |= 0x20; |
| 485 | |
| 486 | rep_data[0] = 0x03; |
| 487 | rep_data[1] = wacom->wacom_wac.bt_features; |
| 488 | |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 489 | ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2, |
| 490 | 1); |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 491 | if (ret >= 0) |
| 492 | wacom->wacom_wac.bt_high_speed = speed; |
| 493 | break; |
Benjamin Tissoires | 387142b | 2014-08-06 13:52:56 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 496 | return 0; |
| 497 | } |
| 498 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 499 | /* |
| 500 | * Switch the tablet into its most-capable mode. Wacom tablets are |
| 501 | * typically configured to power-up in a mode which sends mouse-like |
| 502 | * reports to the OS. To get absolute position, pressure data, etc. |
| 503 | * from the tablet, it is necessary to switch the tablet out of this |
| 504 | * mode and into one which sends the full range of tablet data. |
| 505 | */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 506 | static int _wacom_query_tablet_data(struct wacom *wacom) |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 507 | { |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 508 | struct hid_device *hdev = wacom->hdev; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 509 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 510 | struct wacom_features *features = &wacom_wac->features; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 511 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 512 | if (hdev->bus == BUS_BLUETOOTH) |
| 513 | return wacom_bt_query_tablet_data(hdev, 1, features); |
| 514 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 515 | if (features->type != HID_GENERIC) { |
| 516 | if (features->device_type & WACOM_DEVICETYPE_TOUCH) { |
| 517 | if (features->type > TABLETPC) { |
| 518 | /* MT Tablet PC touch */ |
| 519 | wacom_wac->mode_report = 3; |
| 520 | wacom_wac->mode_value = 4; |
| 521 | } else if (features->type == WACOM_24HDT) { |
| 522 | wacom_wac->mode_report = 18; |
| 523 | wacom_wac->mode_value = 2; |
| 524 | } else if (features->type == WACOM_27QHDT) { |
| 525 | wacom_wac->mode_report = 131; |
| 526 | wacom_wac->mode_value = 2; |
| 527 | } else if (features->type == BAMBOO_PAD) { |
| 528 | wacom_wac->mode_report = 2; |
| 529 | wacom_wac->mode_value = 2; |
| 530 | } |
| 531 | } else if (features->device_type & WACOM_DEVICETYPE_PEN) { |
| 532 | if (features->type <= BAMBOO_PT) { |
| 533 | wacom_wac->mode_report = 2; |
| 534 | wacom_wac->mode_value = 2; |
| 535 | } |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 536 | } |
| 537 | } |
| 538 | |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 539 | wacom_set_device_mode(hdev, wacom_wac); |
| 540 | |
| 541 | if (features->type == HID_GENERIC) |
| 542 | return wacom_hid_set_device_mode(hdev); |
| 543 | |
Jason Gerecke | fe494bc | 2012-10-03 17:25:35 -0700 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 547 | static void wacom_retrieve_hid_descriptor(struct hid_device *hdev, |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 548 | struct wacom_features *features) |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 549 | { |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 550 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 551 | struct usb_interface *intf = wacom->intf; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 552 | |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 553 | /* default features */ |
Henrik Rydberg | fed87e6 | 2010-09-05 12:25:11 -0700 | [diff] [blame] | 554 | features->x_fuzz = 4; |
| 555 | features->y_fuzz = 4; |
| 556 | features->pressure_fuzz = 0; |
Jason Gerecke | bef7e20 | 2016-04-22 14:30:53 -0700 | [diff] [blame] | 557 | features->distance_fuzz = 1; |
| 558 | features->tilt_fuzz = 1; |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 559 | |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 560 | /* |
| 561 | * The wireless device HID is basic and layout conflicts with |
| 562 | * other tablets (monitor and touch interface can look like pen). |
| 563 | * Skip the query for this type and modify defaults based on |
| 564 | * interface number. |
| 565 | */ |
| 566 | if (features->type == WIRELESS) { |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 567 | if (intf->cur_altsetting->desc.bInterfaceNumber == 0) |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 568 | features->device_type = WACOM_DEVICETYPE_WL_MONITOR; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 569 | else |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 570 | features->device_type = WACOM_DEVICETYPE_NONE; |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 571 | return; |
Chris Bagwell | d3825d5 | 2012-03-25 23:26:11 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 574 | wacom_parse_hid(hdev, features); |
Ping Cheng | ec67bbe | 2009-12-15 00:35:24 -0800 | [diff] [blame] | 575 | } |
| 576 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 577 | struct wacom_hdev_data { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 578 | struct list_head list; |
| 579 | struct kref kref; |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 580 | struct hid_device *dev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 581 | struct wacom_shared shared; |
| 582 | }; |
| 583 | |
| 584 | static LIST_HEAD(wacom_udev_list); |
| 585 | static DEFINE_MUTEX(wacom_udev_list_lock); |
| 586 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 587 | static bool compare_device_paths(struct hid_device *hdev_a, |
| 588 | struct hid_device *hdev_b, char separator) |
| 589 | { |
| 590 | int n1 = strrchr(hdev_a->phys, separator) - hdev_a->phys; |
| 591 | int n2 = strrchr(hdev_b->phys, separator) - hdev_b->phys; |
| 592 | |
| 593 | if (n1 != n2 || n1 <= 0 || n2 <= 0) |
| 594 | return false; |
| 595 | |
| 596 | return !strncmp(hdev_a->phys, hdev_b->phys, n1); |
| 597 | } |
| 598 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 599 | static bool wacom_are_sibling(struct hid_device *hdev, |
| 600 | struct hid_device *sibling) |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 601 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 602 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 603 | struct wacom_features *features = &wacom->wacom_wac.features; |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 604 | struct wacom *sibling_wacom = hid_get_drvdata(sibling); |
| 605 | struct wacom_features *sibling_features = &sibling_wacom->wacom_wac.features; |
| 606 | __u32 oVid = features->oVid ? features->oVid : hdev->vendor; |
| 607 | __u32 oPid = features->oPid ? features->oPid : hdev->product; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 608 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 609 | /* The defined oVid/oPid must match that of the sibling */ |
| 610 | if (features->oVid != HID_ANY_ID && sibling->vendor != oVid) |
| 611 | return false; |
| 612 | if (features->oPid != HID_ANY_ID && sibling->product != oPid) |
| 613 | return false; |
| 614 | |
| 615 | /* |
| 616 | * Devices with the same VID/PID must share the same physical |
| 617 | * device path, while those with different VID/PID must share |
| 618 | * the same physical parent device path. |
| 619 | */ |
| 620 | if (hdev->vendor == sibling->vendor && hdev->product == sibling->product) { |
| 621 | if (!compare_device_paths(hdev, sibling, '/')) |
| 622 | return false; |
| 623 | } else { |
| 624 | if (!compare_device_paths(hdev, sibling, '.')) |
| 625 | return false; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 628 | /* Skip the remaining heuristics unless you are a HID_GENERIC device */ |
| 629 | if (features->type != HID_GENERIC) |
| 630 | return true; |
| 631 | |
| 632 | /* |
| 633 | * Direct-input devices may not be siblings of indirect-input |
| 634 | * devices. |
| 635 | */ |
| 636 | if ((features->device_type & WACOM_DEVICETYPE_DIRECT) && |
| 637 | !(sibling_features->device_type & WACOM_DEVICETYPE_DIRECT)) |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 638 | return false; |
| 639 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 640 | /* |
| 641 | * Indirect-input devices may not be siblings of direct-input |
| 642 | * devices. |
| 643 | */ |
| 644 | if (!(features->device_type & WACOM_DEVICETYPE_DIRECT) && |
| 645 | (sibling_features->device_type & WACOM_DEVICETYPE_DIRECT)) |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 646 | return false; |
| 647 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 648 | /* Pen devices may only be siblings of touch devices */ |
| 649 | if ((features->device_type & WACOM_DEVICETYPE_PEN) && |
| 650 | !(sibling_features->device_type & WACOM_DEVICETYPE_TOUCH)) |
| 651 | return false; |
| 652 | |
| 653 | /* Touch devices may only be siblings of pen devices */ |
| 654 | if ((features->device_type & WACOM_DEVICETYPE_TOUCH) && |
| 655 | !(sibling_features->device_type & WACOM_DEVICETYPE_PEN)) |
| 656 | return false; |
| 657 | |
| 658 | /* |
| 659 | * No reason could be found for these two devices to NOT be |
| 660 | * siblings, so there's a good chance they ARE siblings |
| 661 | */ |
| 662 | return true; |
Jason Gerecke | aea2bf6 | 2012-10-21 00:38:03 -0700 | [diff] [blame] | 663 | } |
| 664 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 665 | 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] | 666 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 667 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 668 | |
Jason Gerecke | 41372d5 | 2016-08-08 12:06:30 -0700 | [diff] [blame] | 669 | /* Try to find an already-probed interface from the same device */ |
| 670 | list_for_each_entry(data, &wacom_udev_list, list) { |
| 671 | if (compare_device_paths(hdev, data->dev, '/')) |
| 672 | return data; |
| 673 | } |
| 674 | |
| 675 | /* Fallback to finding devices that appear to be "siblings" */ |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 676 | list_for_each_entry(data, &wacom_udev_list, list) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 677 | if (wacom_are_sibling(hdev, data->dev)) { |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 678 | kref_get(&data->kref); |
| 679 | return data; |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | return NULL; |
| 684 | } |
| 685 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 686 | static void wacom_release_shared_data(struct kref *kref) |
| 687 | { |
| 688 | struct wacom_hdev_data *data = |
| 689 | container_of(kref, struct wacom_hdev_data, kref); |
| 690 | |
| 691 | mutex_lock(&wacom_udev_list_lock); |
| 692 | list_del(&data->list); |
| 693 | mutex_unlock(&wacom_udev_list_lock); |
| 694 | |
| 695 | kfree(data); |
| 696 | } |
| 697 | |
| 698 | static void wacom_remove_shared_data(void *res) |
| 699 | { |
| 700 | struct wacom *wacom = res; |
| 701 | struct wacom_hdev_data *data; |
| 702 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 703 | |
| 704 | if (wacom_wac->shared) { |
| 705 | data = container_of(wacom_wac->shared, struct wacom_hdev_data, |
| 706 | shared); |
| 707 | |
| 708 | if (wacom_wac->shared->touch == wacom->hdev) |
| 709 | wacom_wac->shared->touch = NULL; |
| 710 | else if (wacom_wac->shared->pen == wacom->hdev) |
| 711 | wacom_wac->shared->pen = NULL; |
| 712 | |
| 713 | kref_put(&data->kref, wacom_release_shared_data); |
| 714 | wacom_wac->shared = NULL; |
| 715 | } |
| 716 | } |
| 717 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 718 | static int wacom_add_shared_data(struct hid_device *hdev) |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 719 | { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 720 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 721 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 722 | struct wacom_hdev_data *data; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 723 | int retval = 0; |
| 724 | |
| 725 | mutex_lock(&wacom_udev_list_lock); |
| 726 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 727 | data = wacom_get_hdev_data(hdev); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 728 | if (!data) { |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 729 | data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 730 | if (!data) { |
| 731 | retval = -ENOMEM; |
| 732 | goto out; |
| 733 | } |
| 734 | |
| 735 | kref_init(&data->kref); |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 736 | data->dev = hdev; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 737 | list_add_tail(&data->list, &wacom_udev_list); |
| 738 | } |
| 739 | |
Benjamin Tissoires | 4451e08 | 2014-07-24 13:01:05 -0700 | [diff] [blame] | 740 | wacom_wac->shared = &data->shared; |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 741 | |
Benjamin Tissoires | 1c817c8 | 2016-07-13 18:05:59 +0200 | [diff] [blame] | 742 | retval = devm_add_action(&hdev->dev, wacom_remove_shared_data, wacom); |
| 743 | if (retval) { |
| 744 | mutex_unlock(&wacom_udev_list_lock); |
| 745 | wacom_remove_shared_data(wacom); |
| 746 | return retval; |
| 747 | } |
| 748 | |
Jason Gerecke | a9ce785 | 2017-01-17 15:38:58 -0800 | [diff] [blame] | 749 | if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) |
| 750 | wacom_wac->shared->touch = hdev; |
| 751 | else if (wacom_wac->features.device_type & WACOM_DEVICETYPE_PEN) |
| 752 | wacom_wac->shared->pen = hdev; |
| 753 | |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 754 | out: |
| 755 | mutex_unlock(&wacom_udev_list_lock); |
| 756 | return retval; |
| 757 | } |
| 758 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 759 | static int wacom_led_control(struct wacom *wacom) |
| 760 | { |
| 761 | unsigned char *buf; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 762 | int retval; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 763 | unsigned char report_id = WAC_CMD_LED_CONTROL; |
| 764 | int buf_size = 9; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 765 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 766 | if (!wacom->led.groups) |
| 767 | return -ENOTSUPP; |
| 768 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 769 | if (wacom->wacom_wac.pid) { /* wireless connected */ |
| 770 | report_id = WAC_CMD_WL_LED_CONTROL; |
| 771 | buf_size = 13; |
| 772 | } |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 773 | else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { |
| 774 | report_id = WAC_CMD_WL_INTUOSP2; |
| 775 | buf_size = 51; |
| 776 | } |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 777 | buf = kzalloc(buf_size, GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 778 | if (!buf) |
| 779 | return -ENOMEM; |
| 780 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 781 | if (wacom->wacom_wac.features.type == HID_GENERIC) { |
| 782 | buf[0] = WAC_CMD_LED_CONTROL_GENERIC; |
| 783 | buf[1] = wacom->led.llv; |
| 784 | buf[2] = wacom->led.groups[0].select & 0x03; |
| 785 | |
| 786 | } else if ((wacom->wacom_wac.features.type >= INTUOS5S && |
| 787 | wacom->wacom_wac.features.type <= INTUOSPL)) { |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 788 | /* |
| 789 | * Touch Ring and crop mark LED luminance may take on |
| 790 | * one of four values: |
| 791 | * 0 = Low; 1 = Medium; 2 = High; 3 = Off |
| 792 | */ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 793 | int ring_led = wacom->led.groups[0].select & 0x03; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 794 | int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03; |
| 795 | int crop_lum = 0; |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 796 | unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 797 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 798 | buf[0] = report_id; |
| 799 | if (wacom->wacom_wac.pid) { |
| 800 | wacom_get_report(wacom->hdev, HID_FEATURE_REPORT, |
| 801 | buf, buf_size, WAC_CMD_RETRIES); |
| 802 | buf[0] = report_id; |
| 803 | buf[4] = led_bits; |
| 804 | } else |
| 805 | buf[1] = led_bits; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 806 | } |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 807 | else if (wacom->wacom_wac.features.type == INTUOSP2_BT) { |
| 808 | buf[0] = report_id; |
| 809 | buf[4] = 100; // Power Connection LED (ORANGE) |
| 810 | buf[5] = 100; // BT Connection LED (BLUE) |
| 811 | buf[6] = 100; // Paper Mode (RED?) |
| 812 | buf[7] = 100; // Paper Mode (GREEN?) |
| 813 | buf[8] = 100; // Paper Mode (BLUE?) |
| 814 | buf[9] = wacom->led.llv; |
| 815 | buf[10] = wacom->led.groups[0].select & 0x03; |
| 816 | } |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 817 | else { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 818 | int led = wacom->led.groups[0].select | 0x4; |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 819 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 820 | if (wacom->wacom_wac.features.type == WACOM_21UX2 || |
| 821 | wacom->wacom_wac.features.type == WACOM_24HD) |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 822 | led |= (wacom->led.groups[1].select << 4) | 0x40; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 823 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 824 | buf[0] = report_id; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 825 | buf[1] = led; |
| 826 | buf[2] = wacom->led.llv; |
| 827 | buf[3] = wacom->led.hlv; |
| 828 | buf[4] = wacom->led.img_lum; |
| 829 | } |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 830 | |
Ping Cheng | 912ca21 | 2014-09-10 12:41:31 -0700 | [diff] [blame] | 831 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 832 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 833 | kfree(buf); |
| 834 | |
| 835 | return retval; |
| 836 | } |
| 837 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 838 | static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id, |
| 839 | const unsigned len, const void *img) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 840 | { |
| 841 | unsigned char *buf; |
| 842 | int i, retval; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 843 | 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] | 844 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 845 | buf = kzalloc(chunk_len + 3 , GFP_KERNEL); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 846 | if (!buf) |
| 847 | return -ENOMEM; |
| 848 | |
| 849 | /* Send 'start' command */ |
| 850 | buf[0] = WAC_CMD_ICON_START; |
| 851 | buf[1] = 1; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 852 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 853 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 854 | if (retval < 0) |
| 855 | goto out; |
| 856 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 857 | buf[0] = xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 858 | buf[1] = button_id & 0x07; |
| 859 | for (i = 0; i < 4; i++) { |
| 860 | buf[2] = i; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 861 | memcpy(buf + 3, img + i * chunk_len, chunk_len); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 862 | |
Benjamin Tissoires | 27b20a9 | 2014-07-24 12:56:22 -0700 | [diff] [blame] | 863 | retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 864 | buf, chunk_len + 3, WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 865 | if (retval < 0) |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | /* Send 'stop' */ |
| 870 | buf[0] = WAC_CMD_ICON_START; |
| 871 | buf[1] = 0; |
Przemo Firszt | 296b737 | 2014-08-06 14:00:38 -0700 | [diff] [blame] | 872 | wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2, |
| 873 | WAC_CMD_RETRIES); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 874 | |
| 875 | out: |
| 876 | kfree(buf); |
| 877 | return retval; |
| 878 | } |
| 879 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 880 | 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] | 881 | const char *buf, size_t count) |
| 882 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 883 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 884 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 885 | unsigned int id; |
| 886 | int err; |
| 887 | |
| 888 | err = kstrtouint(buf, 10, &id); |
| 889 | if (err) |
| 890 | return err; |
| 891 | |
| 892 | mutex_lock(&wacom->lock); |
| 893 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 894 | wacom->led.groups[set_id].select = id & 0x3; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 895 | err = wacom_led_control(wacom); |
| 896 | |
| 897 | mutex_unlock(&wacom->lock); |
| 898 | |
| 899 | return err < 0 ? err : count; |
| 900 | } |
| 901 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 902 | #define DEVICE_LED_SELECT_ATTR(SET_ID) \ |
| 903 | static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \ |
| 904 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 905 | { \ |
| 906 | return wacom_led_select_store(dev, SET_ID, buf, count); \ |
| 907 | } \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 908 | static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \ |
| 909 | struct device_attribute *attr, char *buf) \ |
| 910 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 911 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 912 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 913 | return scnprintf(buf, PAGE_SIZE, "%d\n", \ |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 914 | wacom->led.groups[SET_ID].select); \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 915 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 916 | static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 04c59ab | 2011-10-04 23:51:49 -0700 | [diff] [blame] | 917 | wacom_led##SET_ID##_select_show, \ |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 918 | wacom_led##SET_ID##_select_store) |
| 919 | |
| 920 | DEVICE_LED_SELECT_ATTR(0); |
| 921 | DEVICE_LED_SELECT_ATTR(1); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 922 | |
| 923 | static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest, |
| 924 | const char *buf, size_t count) |
| 925 | { |
| 926 | unsigned int value; |
| 927 | int err; |
| 928 | |
| 929 | err = kstrtouint(buf, 10, &value); |
| 930 | if (err) |
| 931 | return err; |
| 932 | |
| 933 | mutex_lock(&wacom->lock); |
| 934 | |
| 935 | *dest = value & 0x7f; |
| 936 | err = wacom_led_control(wacom); |
| 937 | |
| 938 | mutex_unlock(&wacom->lock); |
| 939 | |
| 940 | return err < 0 ? err : count; |
| 941 | } |
| 942 | |
| 943 | #define DEVICE_LUMINANCE_ATTR(name, field) \ |
| 944 | static ssize_t wacom_##name##_luminance_store(struct device *dev, \ |
| 945 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 946 | { \ |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 947 | struct hid_device *hdev = to_hid_device(dev);\ |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 948 | struct wacom *wacom = hid_get_drvdata(hdev); \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 949 | \ |
| 950 | return wacom_luminance_store(wacom, &wacom->led.field, \ |
| 951 | buf, count); \ |
| 952 | } \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 953 | static ssize_t wacom_##name##_luminance_show(struct device *dev, \ |
| 954 | struct device_attribute *attr, char *buf) \ |
| 955 | { \ |
| 956 | struct wacom *wacom = dev_get_drvdata(dev); \ |
| 957 | return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \ |
| 958 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 959 | static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \ |
Ping Cheng | 37449ad | 2014-09-10 12:40:30 -0700 | [diff] [blame] | 960 | wacom_##name##_luminance_show, \ |
| 961 | wacom_##name##_luminance_store) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 962 | |
| 963 | DEVICE_LUMINANCE_ATTR(status0, llv); |
| 964 | DEVICE_LUMINANCE_ATTR(status1, hlv); |
| 965 | DEVICE_LUMINANCE_ATTR(buttons, img_lum); |
| 966 | |
| 967 | static ssize_t wacom_button_image_store(struct device *dev, int button_id, |
| 968 | const char *buf, size_t count) |
| 969 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 970 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 971 | struct wacom *wacom = hid_get_drvdata(hdev); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 972 | int err; |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 973 | unsigned len; |
| 974 | u8 xfer_id; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 975 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 976 | if (hdev->bus == BUS_BLUETOOTH) { |
| 977 | len = 256; |
| 978 | xfer_id = WAC_CMD_ICON_BT_XFER; |
| 979 | } else { |
| 980 | len = 1024; |
| 981 | xfer_id = WAC_CMD_ICON_XFER; |
| 982 | } |
| 983 | |
| 984 | if (count != len) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 985 | return -EINVAL; |
| 986 | |
| 987 | mutex_lock(&wacom->lock); |
| 988 | |
Benjamin Tissoires | 849e2f0 | 2014-08-06 13:58:25 -0700 | [diff] [blame] | 989 | err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf); |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 990 | |
| 991 | mutex_unlock(&wacom->lock); |
| 992 | |
| 993 | return err < 0 ? err : count; |
| 994 | } |
| 995 | |
| 996 | #define DEVICE_BTNIMG_ATTR(BUTTON_ID) \ |
| 997 | static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \ |
| 998 | struct device_attribute *attr, const char *buf, size_t count) \ |
| 999 | { \ |
| 1000 | return wacom_button_image_store(dev, BUTTON_ID, buf, count); \ |
| 1001 | } \ |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1002 | static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \ |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1003 | NULL, wacom_btnimg##BUTTON_ID##_store) |
| 1004 | |
| 1005 | DEVICE_BTNIMG_ATTR(0); |
| 1006 | DEVICE_BTNIMG_ATTR(1); |
| 1007 | DEVICE_BTNIMG_ATTR(2); |
| 1008 | DEVICE_BTNIMG_ATTR(3); |
| 1009 | DEVICE_BTNIMG_ATTR(4); |
| 1010 | DEVICE_BTNIMG_ATTR(5); |
| 1011 | DEVICE_BTNIMG_ATTR(6); |
| 1012 | DEVICE_BTNIMG_ATTR(7); |
| 1013 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1014 | static struct attribute *cintiq_led_attrs[] = { |
| 1015 | &dev_attr_status_led0_select.attr, |
| 1016 | &dev_attr_status_led1_select.attr, |
| 1017 | NULL |
| 1018 | }; |
| 1019 | |
| 1020 | static struct attribute_group cintiq_led_attr_group = { |
| 1021 | .name = "wacom_led", |
| 1022 | .attrs = cintiq_led_attrs, |
| 1023 | }; |
| 1024 | |
| 1025 | static struct attribute *intuos4_led_attrs[] = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1026 | &dev_attr_status0_luminance.attr, |
| 1027 | &dev_attr_status1_luminance.attr, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1028 | &dev_attr_status_led0_select.attr, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1029 | &dev_attr_buttons_luminance.attr, |
| 1030 | &dev_attr_button0_rawimg.attr, |
| 1031 | &dev_attr_button1_rawimg.attr, |
| 1032 | &dev_attr_button2_rawimg.attr, |
| 1033 | &dev_attr_button3_rawimg.attr, |
| 1034 | &dev_attr_button4_rawimg.attr, |
| 1035 | &dev_attr_button5_rawimg.attr, |
| 1036 | &dev_attr_button6_rawimg.attr, |
| 1037 | &dev_attr_button7_rawimg.attr, |
| 1038 | NULL |
| 1039 | }; |
| 1040 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1041 | static struct attribute_group intuos4_led_attr_group = { |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1042 | .name = "wacom_led", |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1043 | .attrs = intuos4_led_attrs, |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1044 | }; |
| 1045 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1046 | static struct attribute *intuos5_led_attrs[] = { |
| 1047 | &dev_attr_status0_luminance.attr, |
| 1048 | &dev_attr_status_led0_select.attr, |
| 1049 | NULL |
| 1050 | }; |
| 1051 | |
| 1052 | static struct attribute_group intuos5_led_attr_group = { |
| 1053 | .name = "wacom_led", |
| 1054 | .attrs = intuos5_led_attrs, |
| 1055 | }; |
| 1056 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1057 | static struct attribute *generic_led_attrs[] = { |
| 1058 | &dev_attr_status0_luminance.attr, |
| 1059 | &dev_attr_status_led0_select.attr, |
| 1060 | NULL |
| 1061 | }; |
| 1062 | |
| 1063 | static struct attribute_group generic_led_attr_group = { |
| 1064 | .name = "wacom_led", |
| 1065 | .attrs = generic_led_attrs, |
| 1066 | }; |
| 1067 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1068 | struct wacom_sysfs_group_devres { |
| 1069 | struct attribute_group *group; |
| 1070 | struct kobject *root; |
| 1071 | }; |
| 1072 | |
| 1073 | static void wacom_devm_sysfs_group_release(struct device *dev, void *res) |
| 1074 | { |
| 1075 | struct wacom_sysfs_group_devres *devres = res; |
| 1076 | struct kobject *kobj = devres->root; |
| 1077 | |
| 1078 | dev_dbg(dev, "%s: dropping reference to %s\n", |
| 1079 | __func__, devres->group->name); |
| 1080 | sysfs_remove_group(kobj, devres->group); |
| 1081 | } |
| 1082 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1083 | static int __wacom_devm_sysfs_create_group(struct wacom *wacom, |
| 1084 | struct kobject *root, |
| 1085 | struct attribute_group *group) |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1086 | { |
| 1087 | struct wacom_sysfs_group_devres *devres; |
| 1088 | int error; |
| 1089 | |
| 1090 | devres = devres_alloc(wacom_devm_sysfs_group_release, |
| 1091 | sizeof(struct wacom_sysfs_group_devres), |
| 1092 | GFP_KERNEL); |
| 1093 | if (!devres) |
| 1094 | return -ENOMEM; |
| 1095 | |
| 1096 | devres->group = group; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1097 | devres->root = root; |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1098 | |
| 1099 | error = sysfs_create_group(devres->root, group); |
| 1100 | if (error) |
| 1101 | return error; |
| 1102 | |
| 1103 | devres_add(&wacom->hdev->dev, devres); |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1108 | static int wacom_devm_sysfs_create_group(struct wacom *wacom, |
| 1109 | struct attribute_group *group) |
| 1110 | { |
| 1111 | return __wacom_devm_sysfs_create_group(wacom, &wacom->hdev->dev.kobj, |
| 1112 | group); |
| 1113 | } |
| 1114 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1115 | enum led_brightness wacom_leds_brightness_get(struct wacom_led *led) |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1116 | { |
| 1117 | struct wacom *wacom = led->wacom; |
| 1118 | |
| 1119 | if (wacom->led.max_hlv) |
| 1120 | return led->hlv * LED_FULL / wacom->led.max_hlv; |
| 1121 | |
| 1122 | if (wacom->led.max_llv) |
| 1123 | return led->llv * LED_FULL / wacom->led.max_llv; |
| 1124 | |
| 1125 | /* device doesn't support brightness tuning */ |
| 1126 | return LED_FULL; |
| 1127 | } |
| 1128 | |
| 1129 | static enum led_brightness __wacom_led_brightness_get(struct led_classdev *cdev) |
| 1130 | { |
| 1131 | struct wacom_led *led = container_of(cdev, struct wacom_led, cdev); |
| 1132 | struct wacom *wacom = led->wacom; |
| 1133 | |
| 1134 | if (wacom->led.groups[led->group].select != led->id) |
| 1135 | return LED_OFF; |
| 1136 | |
| 1137 | return wacom_leds_brightness_get(led); |
| 1138 | } |
| 1139 | |
| 1140 | static int wacom_led_brightness_set(struct led_classdev *cdev, |
| 1141 | enum led_brightness brightness) |
| 1142 | { |
| 1143 | struct wacom_led *led = container_of(cdev, struct wacom_led, cdev); |
| 1144 | struct wacom *wacom = led->wacom; |
| 1145 | int error; |
| 1146 | |
| 1147 | mutex_lock(&wacom->lock); |
| 1148 | |
| 1149 | if (!wacom->led.groups || (brightness == LED_OFF && |
| 1150 | wacom->led.groups[led->group].select != led->id)) { |
| 1151 | error = 0; |
| 1152 | goto out; |
| 1153 | } |
| 1154 | |
| 1155 | led->llv = wacom->led.llv = wacom->led.max_llv * brightness / LED_FULL; |
| 1156 | led->hlv = wacom->led.hlv = wacom->led.max_hlv * brightness / LED_FULL; |
| 1157 | |
| 1158 | wacom->led.groups[led->group].select = led->id; |
| 1159 | |
| 1160 | error = wacom_led_control(wacom); |
| 1161 | |
| 1162 | out: |
| 1163 | mutex_unlock(&wacom->lock); |
| 1164 | |
| 1165 | return error; |
| 1166 | } |
| 1167 | |
| 1168 | static void wacom_led_readonly_brightness_set(struct led_classdev *cdev, |
| 1169 | enum led_brightness brightness) |
| 1170 | { |
| 1171 | } |
| 1172 | |
| 1173 | static int wacom_led_register_one(struct device *dev, struct wacom *wacom, |
| 1174 | struct wacom_led *led, unsigned int group, |
| 1175 | unsigned int id, bool read_only) |
| 1176 | { |
| 1177 | int error; |
| 1178 | char *name; |
| 1179 | |
| 1180 | name = devm_kasprintf(dev, GFP_KERNEL, |
| 1181 | "%s::wacom-%d.%d", |
| 1182 | dev_name(dev), |
| 1183 | group, |
| 1184 | id); |
| 1185 | if (!name) |
| 1186 | return -ENOMEM; |
| 1187 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1188 | if (!read_only) { |
| 1189 | led->trigger.name = name; |
| 1190 | error = devm_led_trigger_register(dev, &led->trigger); |
| 1191 | if (error) { |
| 1192 | hid_err(wacom->hdev, |
| 1193 | "failed to register LED trigger %s: %d\n", |
| 1194 | led->cdev.name, error); |
| 1195 | return error; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1199 | led->group = group; |
| 1200 | led->id = id; |
| 1201 | led->wacom = wacom; |
| 1202 | led->llv = wacom->led.llv; |
| 1203 | led->hlv = wacom->led.hlv; |
| 1204 | led->cdev.name = name; |
| 1205 | led->cdev.max_brightness = LED_FULL; |
| 1206 | led->cdev.flags = LED_HW_PLUGGABLE; |
| 1207 | led->cdev.brightness_get = __wacom_led_brightness_get; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1208 | if (!read_only) { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1209 | led->cdev.brightness_set_blocking = wacom_led_brightness_set; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1210 | led->cdev.default_trigger = led->cdev.name; |
| 1211 | } else { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1212 | led->cdev.brightness_set = wacom_led_readonly_brightness_set; |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1213 | } |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1214 | |
| 1215 | error = devm_led_classdev_register(dev, &led->cdev); |
| 1216 | if (error) { |
| 1217 | hid_err(wacom->hdev, |
| 1218 | "failed to register LED %s: %d\n", |
| 1219 | led->cdev.name, error); |
| 1220 | led->cdev.name = NULL; |
| 1221 | return error; |
| 1222 | } |
| 1223 | |
| 1224 | return 0; |
| 1225 | } |
| 1226 | |
Benjamin Tissoires | 589e506 | 2016-07-13 18:06:11 +0200 | [diff] [blame] | 1227 | static void wacom_led_groups_release_one(void *data) |
| 1228 | { |
| 1229 | struct wacom_group_leds *group = data; |
| 1230 | |
| 1231 | devres_release_group(group->dev, group); |
| 1232 | } |
| 1233 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1234 | static int wacom_led_groups_alloc_and_register_one(struct device *dev, |
| 1235 | struct wacom *wacom, |
| 1236 | int group_id, int count, |
| 1237 | bool read_only) |
| 1238 | { |
| 1239 | struct wacom_led *leds; |
| 1240 | int i, error; |
| 1241 | |
| 1242 | if (group_id >= wacom->led.count || count <= 0) |
| 1243 | return -EINVAL; |
| 1244 | |
| 1245 | if (!devres_open_group(dev, &wacom->led.groups[group_id], GFP_KERNEL)) |
| 1246 | return -ENOMEM; |
| 1247 | |
| 1248 | leds = devm_kzalloc(dev, sizeof(struct wacom_led) * count, GFP_KERNEL); |
| 1249 | if (!leds) { |
| 1250 | error = -ENOMEM; |
| 1251 | goto err; |
| 1252 | } |
| 1253 | |
| 1254 | wacom->led.groups[group_id].leds = leds; |
| 1255 | wacom->led.groups[group_id].count = count; |
| 1256 | |
| 1257 | for (i = 0; i < count; i++) { |
| 1258 | error = wacom_led_register_one(dev, wacom, &leds[i], |
| 1259 | group_id, i, read_only); |
| 1260 | if (error) |
| 1261 | goto err; |
| 1262 | } |
| 1263 | |
Benjamin Tissoires | 589e506 | 2016-07-13 18:06:11 +0200 | [diff] [blame] | 1264 | wacom->led.groups[group_id].dev = dev; |
| 1265 | |
| 1266 | devres_close_group(dev, &wacom->led.groups[group_id]); |
| 1267 | |
| 1268 | /* |
| 1269 | * There is a bug (?) in devm_led_classdev_register() in which its |
| 1270 | * increments the refcount of the parent. If the parent is an input |
| 1271 | * device, that means the ref count never reaches 0 when |
| 1272 | * devm_input_device_release() gets called. |
| 1273 | * This means that the LEDs are still there after disconnect. |
| 1274 | * Manually force the release of the group so that the leds are released |
| 1275 | * once we are done using them. |
| 1276 | */ |
| 1277 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 1278 | wacom_led_groups_release_one, |
| 1279 | &wacom->led.groups[group_id]); |
| 1280 | if (error) |
| 1281 | return error; |
| 1282 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1283 | return 0; |
| 1284 | |
| 1285 | err: |
| 1286 | devres_release_group(dev, &wacom->led.groups[group_id]); |
| 1287 | return error; |
| 1288 | } |
| 1289 | |
Benjamin Tissoires | 34736aa | 2016-07-13 18:06:12 +0200 | [diff] [blame] | 1290 | struct wacom_led *wacom_led_find(struct wacom *wacom, unsigned int group_id, |
| 1291 | unsigned int id) |
| 1292 | { |
| 1293 | struct wacom_group_leds *group; |
| 1294 | |
| 1295 | if (group_id >= wacom->led.count) |
| 1296 | return NULL; |
| 1297 | |
| 1298 | group = &wacom->led.groups[group_id]; |
| 1299 | |
| 1300 | if (!group->leds) |
| 1301 | return NULL; |
| 1302 | |
| 1303 | id %= group->count; |
| 1304 | |
| 1305 | return &group->leds[id]; |
| 1306 | } |
| 1307 | |
| 1308 | /** |
| 1309 | * wacom_led_next: gives the next available led with a wacom trigger. |
| 1310 | * |
| 1311 | * returns the next available struct wacom_led which has its default trigger |
| 1312 | * or the current one if none is available. |
| 1313 | */ |
| 1314 | struct wacom_led *wacom_led_next(struct wacom *wacom, struct wacom_led *cur) |
| 1315 | { |
| 1316 | struct wacom_led *next_led; |
| 1317 | int group, next; |
| 1318 | |
| 1319 | if (!wacom || !cur) |
| 1320 | return NULL; |
| 1321 | |
| 1322 | group = cur->group; |
| 1323 | next = cur->id; |
| 1324 | |
| 1325 | do { |
| 1326 | next_led = wacom_led_find(wacom, group, ++next); |
| 1327 | if (!next_led || next_led == cur) |
| 1328 | return next_led; |
| 1329 | } while (next_led->cdev.trigger != &next_led->trigger); |
| 1330 | |
| 1331 | return next_led; |
| 1332 | } |
| 1333 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1334 | static void wacom_led_groups_release(void *data) |
| 1335 | { |
| 1336 | struct wacom *wacom = data; |
| 1337 | |
| 1338 | wacom->led.groups = NULL; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1339 | wacom->led.count = 0; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | static int wacom_led_groups_allocate(struct wacom *wacom, int count) |
| 1343 | { |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1344 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1345 | struct wacom_group_leds *groups; |
| 1346 | int error; |
| 1347 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1348 | groups = devm_kzalloc(dev, sizeof(struct wacom_group_leds) * count, |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1349 | GFP_KERNEL); |
| 1350 | if (!groups) |
| 1351 | return -ENOMEM; |
| 1352 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1353 | error = devm_add_action_or_reset(dev, wacom_led_groups_release, wacom); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1354 | if (error) |
| 1355 | return error; |
| 1356 | |
| 1357 | wacom->led.groups = groups; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1358 | wacom->led.count = count; |
| 1359 | |
| 1360 | return 0; |
| 1361 | } |
| 1362 | |
| 1363 | static int wacom_leds_alloc_and_register(struct wacom *wacom, int group_count, |
| 1364 | int led_per_group, bool read_only) |
| 1365 | { |
| 1366 | struct device *dev; |
| 1367 | int i, error; |
| 1368 | |
| 1369 | if (!wacom->wacom_wac.pad_input) |
| 1370 | return -EINVAL; |
| 1371 | |
| 1372 | dev = &wacom->wacom_wac.pad_input->dev; |
| 1373 | |
| 1374 | error = wacom_led_groups_allocate(wacom, group_count); |
| 1375 | if (error) |
| 1376 | return error; |
| 1377 | |
| 1378 | for (i = 0; i < group_count; i++) { |
| 1379 | error = wacom_led_groups_alloc_and_register_one(dev, wacom, i, |
| 1380 | led_per_group, |
| 1381 | read_only); |
| 1382 | if (error) |
| 1383 | return error; |
| 1384 | } |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1389 | int wacom_initialize_leds(struct wacom *wacom) |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1390 | { |
| 1391 | int error; |
| 1392 | |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 1393 | if (!(wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD)) |
| 1394 | return 0; |
| 1395 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1396 | /* Initialize default values */ |
| 1397 | switch (wacom->wacom_wac.features.type) { |
Aaron Armstrong Skomra | 10c55ca | 2017-01-25 12:08:42 -0800 | [diff] [blame] | 1398 | case HID_GENERIC: |
| 1399 | if (!wacom->generic_has_leds) |
| 1400 | return 0; |
| 1401 | wacom->led.llv = 100; |
| 1402 | wacom->led.max_llv = 100; |
| 1403 | |
| 1404 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
| 1405 | if (error) { |
| 1406 | hid_err(wacom->hdev, |
| 1407 | "cannot create leds err: %d\n", error); |
| 1408 | return error; |
| 1409 | } |
| 1410 | |
| 1411 | error = wacom_devm_sysfs_create_group(wacom, |
| 1412 | &generic_led_attr_group); |
| 1413 | break; |
| 1414 | |
Jason Gerecke | a19fc98 | 2012-06-12 00:27:53 -0700 | [diff] [blame] | 1415 | case INTUOS4S: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1416 | case INTUOS4: |
Benjamin Tissoires | 81af7e6 | 2014-08-06 13:55:56 -0700 | [diff] [blame] | 1417 | case INTUOS4WL: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1418 | case INTUOS4L: |
Ping Cheng | f4fa9a6 | 2011-10-04 23:49:42 -0700 | [diff] [blame] | 1419 | wacom->led.llv = 10; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1420 | wacom->led.hlv = 20; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1421 | wacom->led.max_llv = 127; |
| 1422 | wacom->led.max_hlv = 127; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1423 | wacom->led.img_lum = 10; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1424 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1425 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1426 | if (error) { |
| 1427 | hid_err(wacom->hdev, |
| 1428 | "cannot create leds err: %d\n", error); |
| 1429 | return error; |
| 1430 | } |
| 1431 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1432 | error = wacom_devm_sysfs_create_group(wacom, |
| 1433 | &intuos4_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1434 | break; |
| 1435 | |
Jason Gerecke | 246835f | 2011-12-12 00:12:04 -0800 | [diff] [blame] | 1436 | case WACOM_24HD: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1437 | case WACOM_21UX2: |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1438 | wacom->led.llv = 0; |
| 1439 | wacom->led.hlv = 0; |
| 1440 | wacom->led.img_lum = 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1441 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1442 | error = wacom_leds_alloc_and_register(wacom, 2, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1443 | if (error) { |
| 1444 | hid_err(wacom->hdev, |
| 1445 | "cannot create leds err: %d\n", error); |
| 1446 | return error; |
| 1447 | } |
| 1448 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1449 | error = wacom_devm_sysfs_create_group(wacom, |
| 1450 | &cintiq_led_attr_group); |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1451 | break; |
| 1452 | |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1453 | case INTUOS5S: |
| 1454 | case INTUOS5: |
| 1455 | case INTUOS5L: |
Ping Cheng | 9a35c41 | 2013-09-20 09:51:56 -0700 | [diff] [blame] | 1456 | case INTUOSPS: |
| 1457 | case INTUOSPM: |
| 1458 | case INTUOSPL: |
Jason Gerecke | 862cf55 | 2015-06-15 18:01:43 -0700 | [diff] [blame] | 1459 | wacom->led.llv = 32; |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1460 | wacom->led.max_llv = 96; |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1461 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1462 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1463 | if (error) { |
| 1464 | hid_err(wacom->hdev, |
| 1465 | "cannot create leds err: %d\n", error); |
| 1466 | return error; |
| 1467 | } |
| 1468 | |
Benjamin Tissoires | 2df68a8 | 2016-07-13 18:05:56 +0200 | [diff] [blame] | 1469 | error = wacom_devm_sysfs_create_group(wacom, |
| 1470 | &intuos5_led_attr_group); |
Jason Gerecke | 9b5b95d | 2012-04-03 15:50:37 -0700 | [diff] [blame] | 1471 | break; |
| 1472 | |
Jason Gerecke | 4922cd2 | 2017-01-25 12:08:37 -0800 | [diff] [blame] | 1473 | case INTUOSP2_BT: |
| 1474 | wacom->led.llv = 50; |
| 1475 | wacom->led.max_llv = 100; |
| 1476 | error = wacom_leds_alloc_and_register(wacom, 1, 4, false); |
| 1477 | if (error) { |
| 1478 | hid_err(wacom->hdev, |
| 1479 | "cannot create leds err: %d\n", error); |
| 1480 | return error; |
| 1481 | } |
| 1482 | return 0; |
| 1483 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1484 | case REMOTE: |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 1485 | wacom->led.llv = 255; |
| 1486 | wacom->led.max_llv = 255; |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1487 | error = wacom_led_groups_allocate(wacom, 5); |
| 1488 | if (error) { |
| 1489 | hid_err(wacom->hdev, |
| 1490 | "cannot create leds err: %d\n", error); |
| 1491 | return error; |
| 1492 | } |
| 1493 | return 0; |
| 1494 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1495 | default: |
| 1496 | return 0; |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1497 | } |
| 1498 | |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1499 | if (error) { |
Benjamin Tissoires | c31a408 | 2014-07-24 12:59:45 -0700 | [diff] [blame] | 1500 | hid_err(wacom->hdev, |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1501 | "cannot create sysfs group err: %d\n", error); |
| 1502 | return error; |
| 1503 | } |
Ping Cheng | 09e7d94 | 2011-10-04 23:51:14 -0700 | [diff] [blame] | 1504 | |
Eduard Hasenleithner | 5d7e7d4 | 2011-09-07 14:08:54 -0700 | [diff] [blame] | 1505 | return 0; |
| 1506 | } |
| 1507 | |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 1508 | static void wacom_init_work(struct work_struct *work) |
| 1509 | { |
| 1510 | struct wacom *wacom = container_of(work, struct wacom, init_work.work); |
| 1511 | |
| 1512 | _wacom_query_tablet_data(wacom); |
| 1513 | wacom_led_control(wacom); |
| 1514 | } |
| 1515 | |
| 1516 | static void wacom_query_tablet_data(struct wacom *wacom) |
| 1517 | { |
| 1518 | schedule_delayed_work(&wacom->init_work, msecs_to_jiffies(1000)); |
| 1519 | } |
| 1520 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1521 | static enum power_supply_property wacom_battery_props[] = { |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1522 | POWER_SUPPLY_PROP_MODEL_NAME, |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1523 | POWER_SUPPLY_PROP_PRESENT, |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1524 | POWER_SUPPLY_PROP_STATUS, |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1525 | POWER_SUPPLY_PROP_SCOPE, |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1526 | POWER_SUPPLY_PROP_CAPACITY |
| 1527 | }; |
| 1528 | |
| 1529 | static int wacom_battery_get_property(struct power_supply *psy, |
| 1530 | enum power_supply_property psp, |
| 1531 | union power_supply_propval *val) |
| 1532 | { |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1533 | struct wacom_battery *battery = power_supply_get_drvdata(psy); |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1534 | int ret = 0; |
| 1535 | |
| 1536 | switch (psp) { |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1537 | case POWER_SUPPLY_PROP_MODEL_NAME: |
| 1538 | val->strval = battery->wacom->wacom_wac.name; |
| 1539 | break; |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1540 | case POWER_SUPPLY_PROP_PRESENT: |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1541 | val->intval = battery->bat_connected; |
Jason Gerecke | 71fa641 | 2015-03-11 10:25:41 -0700 | [diff] [blame] | 1542 | break; |
Bastien Nocera | 6e2a6e8 | 2013-10-15 23:33:00 -0700 | [diff] [blame] | 1543 | case POWER_SUPPLY_PROP_SCOPE: |
| 1544 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 1545 | break; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1546 | case POWER_SUPPLY_PROP_CAPACITY: |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1547 | val->intval = battery->battery_capacity; |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1548 | break; |
| 1549 | case POWER_SUPPLY_PROP_STATUS: |
Jason Gerecke | 16e4598 | 2017-04-28 09:25:33 -0700 | [diff] [blame] | 1550 | if (battery->bat_status != WACOM_POWER_SUPPLY_STATUS_AUTO) |
| 1551 | val->intval = battery->bat_status; |
| 1552 | else if (battery->bat_charging) |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1553 | val->intval = POWER_SUPPLY_STATUS_CHARGING; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1554 | else if (battery->battery_capacity == 100 && |
| 1555 | battery->ps_connected) |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1556 | val->intval = POWER_SUPPLY_STATUS_FULL; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1557 | else if (battery->ps_connected) |
Jason Gerecke | b0882cb | 2015-03-06 11:47:43 -0800 | [diff] [blame] | 1558 | val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING; |
Benjamin Tissoires | ac8d101 | 2014-07-25 17:29:48 -0700 | [diff] [blame] | 1559 | else |
| 1560 | val->intval = POWER_SUPPLY_STATUS_DISCHARGING; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1561 | break; |
| 1562 | default: |
| 1563 | ret = -EINVAL; |
| 1564 | break; |
| 1565 | } |
| 1566 | |
| 1567 | return ret; |
| 1568 | } |
| 1569 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1570 | static int __wacom_initialize_battery(struct wacom *wacom, |
| 1571 | struct wacom_battery *battery) |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1572 | { |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1573 | static atomic_t battery_no = ATOMIC_INIT(0); |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1574 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1575 | struct power_supply_config psy_cfg = { .drv_data = battery, }; |
Benjamin Tissoires | 136ae5e | 2016-07-13 18:06:16 +0200 | [diff] [blame] | 1576 | struct power_supply *ps_bat; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1577 | struct power_supply_desc *bat_desc = &battery->bat_desc; |
Benjamin Tissoires | d70420b9 | 2014-07-25 17:31:51 -0700 | [diff] [blame] | 1578 | unsigned long n; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1579 | int error; |
| 1580 | |
| 1581 | if (!devres_open_group(dev, bat_desc, GFP_KERNEL)) |
| 1582 | return -ENOMEM; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1583 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 1584 | battery->wacom = wacom; |
| 1585 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1586 | n = atomic_inc_return(&battery_no) - 1; |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1587 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1588 | bat_desc->properties = wacom_battery_props; |
| 1589 | bat_desc->num_properties = ARRAY_SIZE(wacom_battery_props); |
| 1590 | bat_desc->get_property = wacom_battery_get_property; |
| 1591 | sprintf(battery->bat_name, "wacom_battery_%ld", n); |
| 1592 | bat_desc->name = battery->bat_name; |
Benjamin Tissoires | 9698329 | 2016-07-13 18:06:15 +0200 | [diff] [blame] | 1593 | bat_desc->type = POWER_SUPPLY_TYPE_USB; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1594 | bat_desc->use_for_apm = 0; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1595 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1596 | ps_bat = devm_power_supply_register(dev, bat_desc, &psy_cfg); |
| 1597 | if (IS_ERR(ps_bat)) { |
| 1598 | error = PTR_ERR(ps_bat); |
| 1599 | goto err; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1600 | } |
| 1601 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1602 | power_supply_powers(ps_bat, &wacom->hdev->dev); |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1603 | |
| 1604 | battery->battery = ps_bat; |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1605 | |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1606 | devres_close_group(dev, bat_desc); |
Benjamin Tissoires | 7dbd229 | 2014-07-25 17:32:41 -0700 | [diff] [blame] | 1607 | return 0; |
Benjamin Tissoires | b189da9 | 2016-07-13 18:05:53 +0200 | [diff] [blame] | 1608 | |
| 1609 | err: |
| 1610 | devres_release_group(dev, bat_desc); |
| 1611 | return error; |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1614 | static int wacom_initialize_battery(struct wacom *wacom) |
| 1615 | { |
| 1616 | if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) |
| 1617 | return __wacom_initialize_battery(wacom, &wacom->battery); |
| 1618 | |
| 1619 | return 0; |
| 1620 | } |
| 1621 | |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1622 | static void wacom_destroy_battery(struct wacom *wacom) |
| 1623 | { |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1624 | if (wacom->battery.battery) { |
| 1625 | devres_release_group(&wacom->hdev->dev, |
| 1626 | &wacom->battery.bat_desc); |
| 1627 | wacom->battery.battery = NULL; |
Chris Bagwell | b7af2bb | 2012-06-12 00:25:23 -0700 | [diff] [blame] | 1628 | } |
Chris Bagwell | a1d552c | 2012-03-25 23:26:30 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1631 | static ssize_t wacom_show_speed(struct device *dev, |
| 1632 | struct device_attribute |
| 1633 | *attr, char *buf) |
| 1634 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1635 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1636 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1637 | |
| 1638 | return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed); |
| 1639 | } |
| 1640 | |
| 1641 | static ssize_t wacom_store_speed(struct device *dev, |
| 1642 | struct device_attribute *attr, |
| 1643 | const char *buf, size_t count) |
| 1644 | { |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1645 | struct hid_device *hdev = to_hid_device(dev); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1646 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1647 | u8 new_speed; |
| 1648 | |
| 1649 | if (kstrtou8(buf, 0, &new_speed)) |
| 1650 | return -EINVAL; |
| 1651 | |
| 1652 | if (new_speed != 0 && new_speed != 1) |
| 1653 | return -EINVAL; |
| 1654 | |
| 1655 | wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features); |
| 1656 | |
| 1657 | return count; |
| 1658 | } |
| 1659 | |
Ping Cheng | e0984bc | 2014-09-10 12:40:05 -0700 | [diff] [blame] | 1660 | static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM, |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 1661 | wacom_show_speed, wacom_store_speed); |
| 1662 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1663 | |
| 1664 | static ssize_t wacom_show_remote_mode(struct kobject *kobj, |
| 1665 | struct kobj_attribute *kattr, |
| 1666 | char *buf, int index) |
| 1667 | { |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1668 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1669 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1670 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1671 | u8 mode; |
| 1672 | |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1673 | mode = wacom->led.groups[index].select; |
Christos Gkekas | bc35f73 | 2017-07-08 20:25:48 +0100 | [diff] [blame^] | 1674 | return sprintf(buf, "%d\n", mode < 3 ? mode : -1); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
| 1677 | #define DEVICE_EKR_ATTR_GROUP(SET_ID) \ |
| 1678 | static ssize_t wacom_show_remote##SET_ID##_mode(struct kobject *kobj, \ |
| 1679 | struct kobj_attribute *kattr, char *buf) \ |
| 1680 | { \ |
| 1681 | return wacom_show_remote_mode(kobj, kattr, buf, SET_ID); \ |
| 1682 | } \ |
| 1683 | static struct kobj_attribute remote##SET_ID##_mode_attr = { \ |
| 1684 | .attr = {.name = "remote_mode", \ |
| 1685 | .mode = DEV_ATTR_RO_PERM}, \ |
| 1686 | .show = wacom_show_remote##SET_ID##_mode, \ |
| 1687 | }; \ |
| 1688 | static struct attribute *remote##SET_ID##_serial_attrs[] = { \ |
| 1689 | &remote##SET_ID##_mode_attr.attr, \ |
| 1690 | NULL \ |
| 1691 | }; \ |
| 1692 | static struct attribute_group remote##SET_ID##_serial_group = { \ |
| 1693 | .name = NULL, \ |
| 1694 | .attrs = remote##SET_ID##_serial_attrs, \ |
| 1695 | } |
| 1696 | |
| 1697 | DEVICE_EKR_ATTR_GROUP(0); |
| 1698 | DEVICE_EKR_ATTR_GROUP(1); |
| 1699 | DEVICE_EKR_ATTR_GROUP(2); |
| 1700 | DEVICE_EKR_ATTR_GROUP(3); |
| 1701 | DEVICE_EKR_ATTR_GROUP(4); |
| 1702 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 1703 | static int wacom_remote_create_attr_group(struct wacom *wacom, __u32 serial, |
| 1704 | int index) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1705 | { |
| 1706 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1707 | struct wacom_remote *remote = wacom->remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1708 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1709 | remote->remotes[index].group.name = devm_kasprintf(&wacom->hdev->dev, |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1710 | GFP_KERNEL, |
| 1711 | "%d", serial); |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1712 | if (!remote->remotes[index].group.name) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1713 | return -ENOMEM; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1714 | |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 1715 | error = __wacom_devm_sysfs_create_group(wacom, remote->remote_dir, |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1716 | &remote->remotes[index].group); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1717 | if (error) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1718 | remote->remotes[index].group.name = NULL; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1719 | hid_err(wacom->hdev, |
| 1720 | "cannot create sysfs group err: %d\n", error); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1721 | return error; |
| 1722 | } |
| 1723 | |
| 1724 | return 0; |
| 1725 | } |
| 1726 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1727 | static int wacom_cmd_unpair_remote(struct wacom *wacom, unsigned char selector) |
| 1728 | { |
| 1729 | const size_t buf_size = 2; |
| 1730 | unsigned char *buf; |
| 1731 | int retval; |
| 1732 | |
| 1733 | buf = kzalloc(buf_size, GFP_KERNEL); |
| 1734 | if (!buf) |
| 1735 | return -ENOMEM; |
| 1736 | |
| 1737 | buf[0] = WAC_CMD_DELETE_PAIRING; |
| 1738 | buf[1] = selector; |
| 1739 | |
| 1740 | retval = wacom_set_report(wacom->hdev, HID_OUTPUT_REPORT, buf, |
| 1741 | buf_size, WAC_CMD_RETRIES); |
| 1742 | kfree(buf); |
| 1743 | |
| 1744 | return retval; |
| 1745 | } |
| 1746 | |
| 1747 | static ssize_t wacom_store_unpair_remote(struct kobject *kobj, |
| 1748 | struct kobj_attribute *attr, |
| 1749 | const char *buf, size_t count) |
| 1750 | { |
| 1751 | unsigned char selector = 0; |
Geliang Tang | 2cf8383 | 2015-12-27 17:25:24 +0800 | [diff] [blame] | 1752 | struct device *dev = kobj_to_dev(kobj->parent); |
Geliang Tang | ee79a8f | 2015-12-27 17:25:21 +0800 | [diff] [blame] | 1753 | struct hid_device *hdev = to_hid_device(dev); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1754 | struct wacom *wacom = hid_get_drvdata(hdev); |
| 1755 | int err; |
| 1756 | |
| 1757 | if (!strncmp(buf, "*\n", 2)) { |
| 1758 | selector = WAC_CMD_UNPAIR_ALL; |
| 1759 | } else { |
| 1760 | hid_info(wacom->hdev, "remote: unrecognized unpair code: %s\n", |
| 1761 | buf); |
| 1762 | return -1; |
| 1763 | } |
| 1764 | |
| 1765 | mutex_lock(&wacom->lock); |
| 1766 | |
| 1767 | err = wacom_cmd_unpair_remote(wacom, selector); |
| 1768 | mutex_unlock(&wacom->lock); |
| 1769 | |
| 1770 | return err < 0 ? err : count; |
| 1771 | } |
| 1772 | |
| 1773 | static struct kobj_attribute unpair_remote_attr = { |
| 1774 | .attr = {.name = "unpair_remote", .mode = 0200}, |
| 1775 | .store = wacom_store_unpair_remote, |
| 1776 | }; |
| 1777 | |
| 1778 | static const struct attribute *remote_unpair_attrs[] = { |
| 1779 | &unpair_remote_attr.attr, |
| 1780 | NULL |
| 1781 | }; |
| 1782 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1783 | static void wacom_remotes_destroy(void *data) |
| 1784 | { |
| 1785 | struct wacom *wacom = data; |
| 1786 | struct wacom_remote *remote = wacom->remote; |
| 1787 | |
| 1788 | if (!remote) |
| 1789 | return; |
| 1790 | |
| 1791 | kobject_put(remote->remote_dir); |
| 1792 | kfifo_free(&remote->remote_fifo); |
| 1793 | wacom->remote = NULL; |
| 1794 | } |
| 1795 | |
| 1796 | static int wacom_initialize_remotes(struct wacom *wacom) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1797 | { |
| 1798 | int error = 0; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1799 | struct wacom_remote *remote; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1800 | int i; |
| 1801 | |
| 1802 | if (wacom->wacom_wac.features.type != REMOTE) |
| 1803 | return 0; |
| 1804 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1805 | remote = devm_kzalloc(&wacom->hdev->dev, sizeof(*wacom->remote), |
| 1806 | GFP_KERNEL); |
| 1807 | if (!remote) |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1808 | return -ENOMEM; |
| 1809 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1810 | wacom->remote = remote; |
| 1811 | |
| 1812 | spin_lock_init(&remote->remote_lock); |
| 1813 | |
| 1814 | error = kfifo_alloc(&remote->remote_fifo, |
| 1815 | 5 * sizeof(struct wacom_remote_data), |
| 1816 | GFP_KERNEL); |
| 1817 | if (error) { |
| 1818 | hid_err(wacom->hdev, "failed allocating remote_fifo\n"); |
| 1819 | return -ENOMEM; |
| 1820 | } |
| 1821 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1822 | remote->remotes[0].group = remote0_serial_group; |
| 1823 | remote->remotes[1].group = remote1_serial_group; |
| 1824 | remote->remotes[2].group = remote2_serial_group; |
| 1825 | remote->remotes[3].group = remote3_serial_group; |
| 1826 | remote->remotes[4].group = remote4_serial_group; |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1827 | |
| 1828 | remote->remote_dir = kobject_create_and_add("wacom_remote", |
| 1829 | &wacom->hdev->dev.kobj); |
| 1830 | if (!remote->remote_dir) |
| 1831 | return -ENOMEM; |
| 1832 | |
| 1833 | error = sysfs_create_files(remote->remote_dir, remote_unpair_attrs); |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1834 | |
| 1835 | if (error) { |
| 1836 | hid_err(wacom->hdev, |
| 1837 | "cannot create sysfs group err: %d\n", error); |
| 1838 | return error; |
| 1839 | } |
| 1840 | |
| 1841 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | a50aac7 | 2016-07-13 18:06:00 +0200 | [diff] [blame] | 1842 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 1843 | remote->remotes[i].serial = 0; |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 1846 | error = devm_add_action_or_reset(&wacom->hdev->dev, |
| 1847 | wacom_remotes_destroy, wacom); |
| 1848 | if (error) |
| 1849 | return error; |
| 1850 | |
Aaron Skomra | 72b236d | 2015-08-20 16:05:17 -0700 | [diff] [blame] | 1851 | return 0; |
| 1852 | } |
| 1853 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1854 | static struct input_dev *wacom_allocate_input(struct wacom *wacom) |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1855 | { |
| 1856 | struct input_dev *input_dev; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1857 | struct hid_device *hdev = wacom->hdev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1858 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1859 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1860 | input_dev = devm_input_allocate_device(&hdev->dev); |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1861 | if (!input_dev) |
| 1862 | return NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1863 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 1864 | input_dev->name = wacom_wac->features.name; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1865 | input_dev->phys = hdev->phys; |
| 1866 | input_dev->dev.parent = &hdev->dev; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1867 | input_dev->open = wacom_open; |
| 1868 | input_dev->close = wacom_close; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1869 | input_dev->uniq = hdev->uniq; |
| 1870 | input_dev->id.bustype = hdev->bus; |
| 1871 | input_dev->id.vendor = hdev->vendor; |
Benjamin Tissoires | 12969e3 | 2014-09-11 13:14:04 -0400 | [diff] [blame] | 1872 | input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product; |
Benjamin Tissoires | b6c79f2 | 2014-07-24 13:00:03 -0700 | [diff] [blame] | 1873 | input_dev->id.version = hdev->version; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1874 | input_set_drvdata(input_dev, wacom); |
| 1875 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1876 | return input_dev; |
| 1877 | } |
| 1878 | |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1879 | static int wacom_allocate_inputs(struct wacom *wacom) |
| 1880 | { |
| 1881 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
| 1882 | |
| 1883 | wacom_wac->pen_input = wacom_allocate_input(wacom); |
| 1884 | wacom_wac->touch_input = wacom_allocate_input(wacom); |
| 1885 | wacom_wac->pad_input = wacom_allocate_input(wacom); |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1886 | if (!wacom_wac->pen_input || |
| 1887 | !wacom_wac->touch_input || |
| 1888 | !wacom_wac->pad_input) |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1889 | return -ENOMEM; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1890 | |
Jason Gerecke | 2bdd163 | 2015-07-13 18:03:45 -0700 | [diff] [blame] | 1891 | wacom_wac->pen_input->name = wacom_wac->pen_name; |
Jason Gerecke | d9f2d20 | 2015-07-13 18:03:44 -0700 | [diff] [blame] | 1892 | wacom_wac->touch_input->name = wacom_wac->touch_name; |
| 1893 | wacom_wac->pad_input->name = wacom_wac->pad_name; |
| 1894 | |
| 1895 | return 0; |
| 1896 | } |
| 1897 | |
Benjamin Tissoires | 008f4d9 | 2014-07-24 12:51:26 -0700 | [diff] [blame] | 1898 | static int wacom_register_inputs(struct wacom *wacom) |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1899 | { |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1900 | struct input_dev *pen_input_dev, *touch_input_dev, *pad_input_dev; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1901 | struct wacom_wac *wacom_wac = &(wacom->wacom_wac); |
Jason Gerecke | 2636a3f | 2015-06-15 18:01:44 -0700 | [diff] [blame] | 1902 | int error = 0; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1903 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1904 | pen_input_dev = wacom_wac->pen_input; |
| 1905 | touch_input_dev = wacom_wac->touch_input; |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 1906 | pad_input_dev = wacom_wac->pad_input; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1907 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1908 | if (!pen_input_dev || !touch_input_dev || !pad_input_dev) |
Benjamin Tissoires | 2546dac | 2014-09-23 12:08:06 -0400 | [diff] [blame] | 1909 | return -EINVAL; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1910 | |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1911 | error = wacom_setup_pen_input_capabilities(pen_input_dev, wacom_wac); |
| 1912 | if (error) { |
| 1913 | /* no pen in use on this interface */ |
| 1914 | input_free_device(pen_input_dev); |
| 1915 | wacom_wac->pen_input = NULL; |
| 1916 | pen_input_dev = NULL; |
| 1917 | } else { |
| 1918 | error = input_register_device(pen_input_dev); |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 1919 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1920 | goto fail; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1921 | } |
| 1922 | |
| 1923 | error = wacom_setup_touch_input_capabilities(touch_input_dev, wacom_wac); |
| 1924 | if (error) { |
| 1925 | /* no touch in use on this interface */ |
| 1926 | input_free_device(touch_input_dev); |
| 1927 | wacom_wac->touch_input = NULL; |
| 1928 | touch_input_dev = NULL; |
| 1929 | } else { |
| 1930 | error = input_register_device(touch_input_dev); |
| 1931 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1932 | goto fail; |
Ping Cheng | 30ebc1a | 2014-11-18 13:29:16 -0800 | [diff] [blame] | 1933 | } |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1934 | |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1935 | error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac); |
| 1936 | if (error) { |
| 1937 | /* no pad in use on this interface */ |
| 1938 | input_free_device(pad_input_dev); |
| 1939 | wacom_wac->pad_input = NULL; |
| 1940 | pad_input_dev = NULL; |
| 1941 | } else { |
| 1942 | error = input_register_device(pad_input_dev); |
| 1943 | if (error) |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1944 | goto fail; |
Benjamin Tissoires | d2d13f1 | 2014-07-24 12:48:28 -0700 | [diff] [blame] | 1945 | } |
| 1946 | |
Ping Cheng | 1963518 | 2012-04-29 21:09:18 -0700 | [diff] [blame] | 1947 | return 0; |
| 1948 | |
Benjamin Tissoires | 3dad188 | 2016-07-13 18:05:54 +0200 | [diff] [blame] | 1949 | fail: |
| 1950 | wacom_wac->pad_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1951 | wacom_wac->touch_input = NULL; |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 1952 | wacom_wac->pen_input = NULL; |
Chris Bagwell | 3aac0ef | 2012-03-25 23:25:45 -0700 | [diff] [blame] | 1953 | return error; |
| 1954 | } |
| 1955 | |
Jason Gerecke | 0be0171 | 2015-08-05 15:44:53 -0700 | [diff] [blame] | 1956 | /* |
| 1957 | * Not all devices report physical dimensions from HID. |
| 1958 | * Compute the default from hardcoded logical dimension |
| 1959 | * and resolution before driver overwrites them. |
| 1960 | */ |
| 1961 | static void wacom_set_default_phy(struct wacom_features *features) |
| 1962 | { |
| 1963 | if (features->x_resolution) { |
| 1964 | features->x_phy = (features->x_max * 100) / |
| 1965 | features->x_resolution; |
| 1966 | features->y_phy = (features->y_max * 100) / |
| 1967 | features->y_resolution; |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | static void wacom_calculate_res(struct wacom_features *features) |
| 1972 | { |
| 1973 | /* set unit to "100th of a mm" for devices not reported by HID */ |
| 1974 | if (!features->unit) { |
| 1975 | features->unit = 0x11; |
| 1976 | features->unitExpo = -3; |
| 1977 | } |
| 1978 | |
| 1979 | features->x_resolution = wacom_calc_hid_res(features->x_max, |
| 1980 | features->x_phy, |
| 1981 | features->unit, |
| 1982 | features->unitExpo); |
| 1983 | features->y_resolution = wacom_calc_hid_res(features->y_max, |
| 1984 | features->y_phy, |
| 1985 | features->unit, |
| 1986 | features->unitExpo); |
| 1987 | } |
| 1988 | |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1989 | void wacom_battery_work(struct work_struct *work) |
| 1990 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 1991 | struct wacom *wacom = container_of(work, struct wacom, battery_work); |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1992 | |
| 1993 | if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1994 | !wacom->battery.battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1995 | wacom_initialize_battery(wacom); |
| 1996 | } |
| 1997 | else if (!(wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) && |
Benjamin Tissoires | 59d69bc | 2016-07-13 18:06:08 +0200 | [diff] [blame] | 1998 | wacom->battery.battery) { |
Jason Gerecke | fce9957 | 2015-03-06 11:47:40 -0800 | [diff] [blame] | 1999 | wacom_destroy_battery(wacom); |
| 2000 | } |
| 2001 | } |
| 2002 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2003 | static size_t wacom_compute_pktlen(struct hid_device *hdev) |
| 2004 | { |
| 2005 | struct hid_report_enum *report_enum; |
| 2006 | struct hid_report *report; |
| 2007 | size_t size = 0; |
| 2008 | |
| 2009 | report_enum = hdev->report_enum + HID_INPUT_REPORT; |
| 2010 | |
| 2011 | list_for_each_entry(report, &report_enum->report_list, list) { |
Mathieu Magnaudet | dabb05c6 | 2014-11-27 16:02:36 +0100 | [diff] [blame] | 2012 | size_t report_size = hid_report_len(report); |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2013 | if (report_size > size) |
| 2014 | size = report_size; |
| 2015 | } |
| 2016 | |
| 2017 | return size; |
| 2018 | } |
| 2019 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2020 | static void wacom_update_name(struct wacom *wacom, const char *suffix) |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2021 | { |
| 2022 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2023 | struct wacom_features *features = &wacom_wac->features; |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2024 | char name[WACOM_NAME_MAX]; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2025 | |
| 2026 | /* Generic devices name unspecified */ |
| 2027 | if ((features->type == HID_GENERIC) && !strcmp("Wacom HID", features->name)) { |
| 2028 | if (strstr(wacom->hdev->name, "Wacom") || |
| 2029 | strstr(wacom->hdev->name, "wacom") || |
| 2030 | strstr(wacom->hdev->name, "WACOM")) { |
| 2031 | /* name is in HID descriptor, use it */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2032 | strlcpy(name, wacom->hdev->name, sizeof(name)); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2033 | |
| 2034 | /* strip out excess whitespaces */ |
| 2035 | while (1) { |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2036 | char *gap = strstr(name, " "); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2037 | if (gap == NULL) |
| 2038 | break; |
| 2039 | /* shift everything including the terminator */ |
| 2040 | memmove(gap, gap+1, strlen(gap)); |
| 2041 | } |
Jason Gerecke | f2209d4 | 2016-10-19 18:03:41 -0700 | [diff] [blame] | 2042 | |
| 2043 | /* strip off excessive prefixing */ |
| 2044 | if (strstr(name, "Wacom Co.,Ltd. Wacom ") == name) { |
| 2045 | int n = strlen(name); |
| 2046 | int x = strlen("Wacom Co.,Ltd. "); |
| 2047 | memmove(name, name+x, n-x+1); |
| 2048 | } |
| 2049 | if (strstr(name, "Wacom Co., Ltd. Wacom ") == name) { |
| 2050 | int n = strlen(name); |
| 2051 | int x = strlen("Wacom Co., Ltd. "); |
| 2052 | memmove(name, name+x, n-x+1); |
| 2053 | } |
| 2054 | |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2055 | /* get rid of trailing whitespace */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2056 | if (name[strlen(name)-1] == ' ') |
| 2057 | name[strlen(name)-1] = '\0'; |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2058 | } else { |
| 2059 | /* no meaningful name retrieved. use product ID */ |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2060 | snprintf(name, sizeof(name), |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2061 | "%s %X", features->name, wacom->hdev->product); |
| 2062 | } |
| 2063 | } else { |
Jason Gerecke | 44b5250 | 2015-06-15 18:01:41 -0700 | [diff] [blame] | 2064 | strlcpy(name, features->name, sizeof(name)); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2065 | } |
| 2066 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 2067 | snprintf(wacom_wac->name, sizeof(wacom_wac->name), "%s%s", |
| 2068 | name, suffix); |
| 2069 | |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2070 | /* Append the device type to the name */ |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2071 | snprintf(wacom_wac->pen_name, sizeof(wacom_wac->pen_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2072 | "%s%s Pen", name, suffix); |
Jason Gerecke | 2a6cdbd | 2015-06-15 18:01:45 -0700 | [diff] [blame] | 2073 | snprintf(wacom_wac->touch_name, sizeof(wacom_wac->touch_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2074 | "%s%s Finger", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2075 | snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name), |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2076 | "%s%s Pad", name, suffix); |
Ping Cheng | c24eab4 | 2015-04-24 15:32:51 -0700 | [diff] [blame] | 2077 | } |
| 2078 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2079 | static void wacom_release_resources(struct wacom *wacom) |
| 2080 | { |
| 2081 | struct hid_device *hdev = wacom->hdev; |
| 2082 | |
| 2083 | if (!wacom->resources) |
| 2084 | return; |
| 2085 | |
| 2086 | devres_release_group(&hdev->dev, wacom); |
| 2087 | |
| 2088 | wacom->resources = false; |
| 2089 | |
| 2090 | wacom->wacom_wac.pen_input = NULL; |
| 2091 | wacom->wacom_wac.touch_input = NULL; |
| 2092 | wacom->wacom_wac.pad_input = NULL; |
| 2093 | } |
| 2094 | |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2095 | static void wacom_set_shared_values(struct wacom_wac *wacom_wac) |
| 2096 | { |
| 2097 | if (wacom_wac->features.device_type & WACOM_DEVICETYPE_TOUCH) { |
| 2098 | wacom_wac->shared->type = wacom_wac->features.type; |
| 2099 | wacom_wac->shared->touch_input = wacom_wac->touch_input; |
| 2100 | } |
| 2101 | |
Ping Cheng | d793ff8 | 2017-02-14 21:27:45 -0800 | [diff] [blame] | 2102 | if (wacom_wac->has_mute_touch_switch) { |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2103 | wacom_wac->shared->has_mute_touch_switch = true; |
Ping Cheng | d793ff8 | 2017-02-14 21:27:45 -0800 | [diff] [blame] | 2104 | wacom_wac->shared->is_touch_on = true; |
| 2105 | } |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2106 | |
| 2107 | if (wacom_wac->shared->has_mute_touch_switch && |
| 2108 | wacom_wac->shared->touch_input) { |
| 2109 | set_bit(EV_SW, wacom_wac->shared->touch_input->evbit); |
| 2110 | input_set_capability(wacom_wac->shared->touch_input, EV_SW, |
| 2111 | SW_MUTE_DEVICE); |
| 2112 | } |
| 2113 | } |
| 2114 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2115 | static int wacom_parse_and_register(struct wacom *wacom, bool wireless) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2116 | { |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2117 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2118 | struct wacom_features *features = &wacom_wac->features; |
| 2119 | struct hid_device *hdev = wacom->hdev; |
Jason Childs | e33da8a | 2010-02-17 22:38:31 -0800 | [diff] [blame] | 2120 | int error; |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2121 | unsigned int connect_mask = HID_CONNECT_HIDRAW; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2122 | |
Benjamin Tissoires | 01c846f | 2014-07-24 12:59:11 -0700 | [diff] [blame] | 2123 | features->pktlen = wacom_compute_pktlen(hdev); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2124 | if (features->pktlen > WACOM_PKGLEN_MAX) |
| 2125 | return -EINVAL; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2126 | |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2127 | if (!devres_open_group(&hdev->dev, wacom, GFP_KERNEL)) |
| 2128 | return -ENOMEM; |
| 2129 | |
| 2130 | wacom->resources = true; |
| 2131 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 2132 | error = wacom_allocate_inputs(wacom); |
| 2133 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2134 | goto fail; |
Benjamin Tissoires | 494078b | 2014-09-23 12:08:07 -0400 | [diff] [blame] | 2135 | |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 2136 | /* |
| 2137 | * Bamboo Pad has a generic hid handling for the Pen, and we switch it |
| 2138 | * into debug mode for the touch part. |
| 2139 | * We ignore the other interfaces. |
| 2140 | */ |
| 2141 | if (features->type == BAMBOO_PAD) { |
| 2142 | if (features->pktlen == WACOM_PKGLEN_PENABLED) { |
| 2143 | features->type = HID_GENERIC; |
| 2144 | } else if ((features->pktlen != WACOM_PKGLEN_BPAD_TOUCH) && |
| 2145 | (features->pktlen != WACOM_PKGLEN_BPAD_TOUCH_USB)) { |
| 2146 | error = -ENODEV; |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2147 | goto fail; |
Benjamin Tissoires | 8c97a76 | 2015-02-26 11:28:50 -0500 | [diff] [blame] | 2148 | } |
| 2149 | } |
| 2150 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 2151 | /* set the default size in case we do not get them from hid */ |
| 2152 | wacom_set_default_phy(features); |
| 2153 | |
Ping Cheng | f393ee2 | 2012-04-29 21:09:17 -0700 | [diff] [blame] | 2154 | /* Retrieve the physical and logical size for touch devices */ |
Benjamin Tissoires | c669fb2 | 2014-07-24 13:02:14 -0700 | [diff] [blame] | 2155 | wacom_retrieve_hid_descriptor(hdev, features); |
Ping Cheng | 42f4f27 | 2015-04-15 16:53:54 -0700 | [diff] [blame] | 2156 | wacom_setup_device_quirks(wacom); |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2157 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 2158 | if (features->device_type == WACOM_DEVICETYPE_NONE && |
| 2159 | features->type != WIRELESS) { |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 2160 | error = features->type == HID_GENERIC ? -ENODEV : 0; |
| 2161 | |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2162 | dev_warn(&hdev->dev, "Unknown device_type for '%s'. %s.", |
Jason Gerecke | 8e116d3 | 2015-04-30 17:51:55 -0700 | [diff] [blame] | 2163 | hdev->name, |
| 2164 | error ? "Ignoring" : "Assuming pen"); |
| 2165 | |
| 2166 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2167 | goto fail; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2168 | |
Jason Gerecke | aa86b18 | 2015-06-15 18:01:42 -0700 | [diff] [blame] | 2169 | features->device_type |= WACOM_DEVICETYPE_PEN; |
Jason Gerecke | 042628a | 2015-04-30 17:51:54 -0700 | [diff] [blame] | 2170 | } |
| 2171 | |
Ping Cheng | 401d7d1 | 2013-07-28 00:38:54 -0700 | [diff] [blame] | 2172 | wacom_calculate_res(features); |
| 2173 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2174 | wacom_update_name(wacom, wireless ? " (WL)" : ""); |
Ping Cheng | 4492eff | 2010-03-19 22:18:15 -0700 | [diff] [blame] | 2175 | |
Aaron Armstrong Skomra | 8b40735 | 2017-03-29 10:35:39 -0700 | [diff] [blame] | 2176 | /* pen only Bamboo neither support touch nor pad */ |
| 2177 | if ((features->type == BAMBOO_PEN) && |
| 2178 | ((features->device_type & WACOM_DEVICETYPE_TOUCH) || |
| 2179 | (features->device_type & WACOM_DEVICETYPE_PAD))) { |
| 2180 | error = -ENODEV; |
| 2181 | goto fail; |
| 2182 | } |
| 2183 | |
Jason Gerecke | a9ce785 | 2017-01-17 15:38:58 -0800 | [diff] [blame] | 2184 | error = wacom_add_shared_data(hdev); |
| 2185 | if (error) |
| 2186 | goto fail; |
Ping Cheng | 49b764a | 2010-02-20 00:53:49 -0800 | [diff] [blame] | 2187 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 2188 | if (!(features->device_type & WACOM_DEVICETYPE_WL_MONITOR) && |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2189 | (features->quirks & WACOM_QUIRK_BATTERY)) { |
| 2190 | error = wacom_initialize_battery(wacom); |
| 2191 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2192 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2193 | } |
| 2194 | |
Jason Gerecke | 3f14a63 | 2015-08-03 10:17:05 -0700 | [diff] [blame] | 2195 | error = wacom_register_inputs(wacom); |
| 2196 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2197 | goto fail; |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2198 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2199 | if (wacom->wacom_wac.features.device_type & WACOM_DEVICETYPE_PAD) { |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 2200 | error = wacom_initialize_leds(wacom); |
| 2201 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2202 | goto fail; |
Benjamin Tissoires | 85d2c77 | 2016-07-13 18:05:51 +0200 | [diff] [blame] | 2203 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2204 | error = wacom_initialize_remotes(wacom); |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2205 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2206 | goto fail; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2207 | } |
| 2208 | |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2209 | if (features->type == HID_GENERIC) |
| 2210 | connect_mask |= HID_CONNECT_DRIVER; |
| 2211 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2212 | /* Regular HID work starts now */ |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2213 | error = hid_hw_start(hdev, connect_mask); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2214 | if (error) { |
| 2215 | hid_err(hdev, "hw start failed\n"); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2216 | goto fail; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2219 | if (!wireless) { |
| 2220 | /* Note that if query fails it is not a hard failure */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2221 | wacom_query_tablet_data(wacom); |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2222 | } |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2223 | |
| 2224 | /* touch only Bamboo doesn't support pen */ |
| 2225 | if ((features->type == BAMBOO_TOUCH) && |
| 2226 | (features->device_type & WACOM_DEVICETYPE_PEN)) { |
Aaron Armstrong Skomra | 4d20c33 | 2017-03-29 11:41:28 -0700 | [diff] [blame] | 2227 | cancel_delayed_work_sync(&wacom->init_work); |
| 2228 | _wacom_query_tablet_data(wacom); |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2229 | error = -ENODEV; |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2230 | goto fail_quirks; |
Jason Gerecke | 86e88f0 | 2015-11-03 16:57:58 -0800 | [diff] [blame] | 2231 | } |
| 2232 | |
Jason Gerecke | ccad85c | 2015-08-03 10:17:04 -0700 | [diff] [blame] | 2233 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2234 | error = hid_hw_open(hdev); |
| 2235 | |
Aaron Armstrong Skomra | d2ec58a | 2017-01-25 12:08:41 -0800 | [diff] [blame] | 2236 | wacom_set_shared_values(wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2237 | devres_close_group(&hdev->dev, wacom); |
| 2238 | |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2239 | return 0; |
| 2240 | |
Benjamin Tissoires | b62f646 | 2016-07-13 18:05:50 +0200 | [diff] [blame] | 2241 | fail_quirks: |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2242 | hid_hw_stop(hdev); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2243 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2244 | wacom_release_resources(wacom); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2245 | return error; |
| 2246 | } |
| 2247 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2248 | static void wacom_wireless_work(struct work_struct *work) |
| 2249 | { |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2250 | struct wacom *wacom = container_of(work, struct wacom, wireless_work); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2251 | struct usb_device *usbdev = wacom->usbdev; |
| 2252 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2253 | struct hid_device *hdev1, *hdev2; |
| 2254 | struct wacom *wacom1, *wacom2; |
| 2255 | struct wacom_wac *wacom_wac1, *wacom_wac2; |
| 2256 | int error; |
| 2257 | |
| 2258 | /* |
| 2259 | * Regardless if this is a disconnect or a new tablet, |
| 2260 | * remove any existing input and battery devices. |
| 2261 | */ |
| 2262 | |
| 2263 | wacom_destroy_battery(wacom); |
| 2264 | |
| 2265 | /* Stylus interface */ |
| 2266 | hdev1 = usb_get_intfdata(usbdev->config->interface[1]); |
| 2267 | wacom1 = hid_get_drvdata(hdev1); |
| 2268 | wacom_wac1 = &(wacom1->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2269 | wacom_release_resources(wacom1); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2270 | |
| 2271 | /* Touch interface */ |
| 2272 | hdev2 = usb_get_intfdata(usbdev->config->interface[2]); |
| 2273 | wacom2 = hid_get_drvdata(hdev2); |
| 2274 | wacom_wac2 = &(wacom2->wacom_wac); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2275 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2276 | |
| 2277 | if (wacom_wac->pid == 0) { |
| 2278 | hid_info(wacom->hdev, "wireless tablet disconnected\n"); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2279 | } else { |
| 2280 | const struct hid_device_id *id = wacom_ids; |
| 2281 | |
| 2282 | hid_info(wacom->hdev, "wireless tablet connected with PID %x\n", |
| 2283 | wacom_wac->pid); |
| 2284 | |
| 2285 | while (id->bus) { |
| 2286 | if (id->vendor == USB_VENDOR_ID_WACOM && |
| 2287 | id->product == wacom_wac->pid) |
| 2288 | break; |
| 2289 | id++; |
| 2290 | } |
| 2291 | |
| 2292 | if (!id->bus) { |
| 2293 | hid_info(wacom->hdev, "ignoring unknown PID.\n"); |
| 2294 | return; |
| 2295 | } |
| 2296 | |
| 2297 | /* Stylus interface */ |
| 2298 | wacom_wac1->features = |
| 2299 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2300 | |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2301 | wacom_wac1->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2302 | hid_hw_stop(hdev1); |
| 2303 | error = wacom_parse_and_register(wacom1, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2304 | if (error) |
| 2305 | goto fail; |
| 2306 | |
| 2307 | /* Touch interface */ |
| 2308 | if (wacom_wac1->features.touch_max || |
| 2309 | (wacom_wac1->features.type >= INTUOSHT && |
| 2310 | wacom_wac1->features.type <= BAMBOO_PT)) { |
| 2311 | wacom_wac2->features = |
| 2312 | *((struct wacom_features *)id->driver_data); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2313 | wacom_wac2->pid = wacom_wac->pid; |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2314 | hid_hw_stop(hdev2); |
| 2315 | error = wacom_parse_and_register(wacom2, true); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2316 | if (error) |
| 2317 | goto fail; |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2318 | } |
| 2319 | |
Benjamin Tissoires | 9956953 | 2016-07-13 18:06:17 +0200 | [diff] [blame] | 2320 | strlcpy(wacom_wac->name, wacom_wac1->name, |
| 2321 | sizeof(wacom_wac->name)); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2322 | error = wacom_initialize_battery(wacom); |
| 2323 | if (error) |
| 2324 | goto fail; |
| 2325 | } |
| 2326 | |
| 2327 | return; |
| 2328 | |
| 2329 | fail: |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2330 | wacom_release_resources(wacom1); |
Benjamin Tissoires | 84dfbd7 | 2016-07-13 18:05:55 +0200 | [diff] [blame] | 2331 | wacom_release_resources(wacom2); |
Benjamin Tissoires | a2f091a | 2016-02-12 17:27:42 +0100 | [diff] [blame] | 2332 | return; |
| 2333 | } |
| 2334 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2335 | static void wacom_remote_destroy_one(struct wacom *wacom, unsigned int index) |
| 2336 | { |
| 2337 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2338 | u32 serial = remote->remotes[index].serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2339 | int i; |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2340 | unsigned long flags; |
| 2341 | |
| 2342 | spin_lock_irqsave(&remote->remote_lock, flags); |
| 2343 | remote->remotes[index].registered = false; |
| 2344 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2345 | |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2346 | if (remote->remotes[index].battery.battery) |
| 2347 | devres_release_group(&wacom->hdev->dev, |
| 2348 | &remote->remotes[index].battery.bat_desc); |
| 2349 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2350 | if (remote->remotes[index].group.name) |
| 2351 | devres_release_group(&wacom->hdev->dev, |
| 2352 | &remote->remotes[index]); |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2353 | |
| 2354 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2355 | if (remote->remotes[i].serial == serial) { |
| 2356 | remote->remotes[i].serial = 0; |
| 2357 | remote->remotes[i].group.name = NULL; |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2358 | remote->remotes[i].registered = false; |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2359 | remote->remotes[i].battery.battery = NULL; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2360 | wacom->led.groups[i].select = WACOM_STATUS_UNKNOWN; |
| 2361 | } |
| 2362 | } |
| 2363 | } |
| 2364 | |
| 2365 | static int wacom_remote_create_one(struct wacom *wacom, u32 serial, |
| 2366 | unsigned int index) |
| 2367 | { |
| 2368 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2369 | struct device *dev = &wacom->hdev->dev; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2370 | int error, k; |
| 2371 | |
| 2372 | /* A remote can pair more than once with an EKR, |
| 2373 | * check to make sure this serial isn't already paired. |
| 2374 | */ |
| 2375 | for (k = 0; k < WACOM_MAX_REMOTES; k++) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2376 | if (remote->remotes[k].serial == serial) |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2377 | break; |
| 2378 | } |
| 2379 | |
| 2380 | if (k < WACOM_MAX_REMOTES) { |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2381 | remote->remotes[index].serial = serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2382 | return 0; |
| 2383 | } |
| 2384 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2385 | if (!devres_open_group(dev, &remote->remotes[index], GFP_KERNEL)) |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2386 | return -ENOMEM; |
| 2387 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2388 | error = wacom_remote_create_attr_group(wacom, serial, index); |
| 2389 | if (error) |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2390 | goto fail; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2391 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2392 | remote->remotes[index].input = wacom_allocate_input(wacom); |
| 2393 | if (!remote->remotes[index].input) { |
| 2394 | error = -ENOMEM; |
| 2395 | goto fail; |
| 2396 | } |
| 2397 | remote->remotes[index].input->uniq = remote->remotes[index].group.name; |
| 2398 | remote->remotes[index].input->name = wacom->wacom_wac.pad_name; |
| 2399 | |
| 2400 | if (!remote->remotes[index].input->name) { |
| 2401 | error = -EINVAL; |
| 2402 | goto fail; |
| 2403 | } |
| 2404 | |
| 2405 | error = wacom_setup_pad_input_capabilities(remote->remotes[index].input, |
| 2406 | &wacom->wacom_wac); |
| 2407 | if (error) |
| 2408 | goto fail; |
| 2409 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2410 | remote->remotes[index].serial = serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2411 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2412 | error = input_register_device(remote->remotes[index].input); |
| 2413 | if (error) |
| 2414 | goto fail; |
| 2415 | |
Benjamin Tissoires | 97f5541 | 2016-07-13 18:06:10 +0200 | [diff] [blame] | 2416 | error = wacom_led_groups_alloc_and_register_one( |
| 2417 | &remote->remotes[index].input->dev, |
| 2418 | wacom, index, 3, true); |
| 2419 | if (error) |
| 2420 | goto fail; |
| 2421 | |
Benjamin Tissoires | 7c35dc3 | 2016-07-13 18:06:07 +0200 | [diff] [blame] | 2422 | remote->remotes[index].registered = true; |
| 2423 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2424 | devres_close_group(dev, &remote->remotes[index]); |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2425 | return 0; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2426 | |
| 2427 | fail: |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2428 | devres_release_group(dev, &remote->remotes[index]); |
| 2429 | remote->remotes[index].serial = 0; |
Benjamin Tissoires | f9036bd | 2016-07-13 18:06:05 +0200 | [diff] [blame] | 2430 | return error; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2431 | } |
| 2432 | |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2433 | static int wacom_remote_attach_battery(struct wacom *wacom, int index) |
| 2434 | { |
| 2435 | struct wacom_remote *remote = wacom->remote; |
| 2436 | int error; |
| 2437 | |
| 2438 | if (!remote->remotes[index].registered) |
| 2439 | return 0; |
| 2440 | |
| 2441 | if (remote->remotes[index].battery.battery) |
| 2442 | return 0; |
| 2443 | |
| 2444 | if (wacom->led.groups[index].select == WACOM_STATUS_UNKNOWN) |
| 2445 | return 0; |
| 2446 | |
| 2447 | error = __wacom_initialize_battery(wacom, |
| 2448 | &wacom->remote->remotes[index].battery); |
| 2449 | if (error) |
| 2450 | return error; |
| 2451 | |
| 2452 | return 0; |
| 2453 | } |
| 2454 | |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2455 | static void wacom_remote_work(struct work_struct *work) |
| 2456 | { |
| 2457 | struct wacom *wacom = container_of(work, struct wacom, remote_work); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2458 | struct wacom_remote *remote = wacom->remote; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2459 | struct wacom_remote_data data; |
| 2460 | unsigned long flags; |
| 2461 | unsigned int count; |
| 2462 | u32 serial; |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2463 | int i; |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2464 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2465 | spin_lock_irqsave(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2466 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2467 | count = kfifo_out(&remote->remote_fifo, &data, sizeof(data)); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2468 | |
| 2469 | if (count != sizeof(data)) { |
| 2470 | hid_err(wacom->hdev, |
| 2471 | "workitem triggered without status available\n"); |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2472 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2473 | return; |
| 2474 | } |
| 2475 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2476 | if (!kfifo_is_empty(&remote->remote_fifo)) |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2477 | wacom_schedule_work(&wacom->wacom_wac, WACOM_WORKER_REMOTE); |
| 2478 | |
Benjamin Tissoires | 83e6b40 | 2016-07-13 18:06:02 +0200 | [diff] [blame] | 2479 | spin_unlock_irqrestore(&remote->remote_lock, flags); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2480 | |
| 2481 | for (i = 0; i < WACOM_MAX_REMOTES; i++) { |
| 2482 | serial = data.remote[i].serial; |
| 2483 | if (data.remote[i].connected) { |
| 2484 | |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2485 | if (remote->remotes[i].serial == serial) { |
| 2486 | wacom_remote_attach_battery(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2487 | continue; |
Benjamin Tissoires | 9f1015d4 | 2016-07-13 18:06:09 +0200 | [diff] [blame] | 2488 | } |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2489 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2490 | if (remote->remotes[i].serial) |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2491 | wacom_remote_destroy_one(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2492 | |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2493 | wacom_remote_create_one(wacom, serial, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2494 | |
Benjamin Tissoires | e7749f6 | 2016-07-13 18:06:06 +0200 | [diff] [blame] | 2495 | } else if (remote->remotes[i].serial) { |
Benjamin Tissoires | 04bfa27 | 2016-07-13 18:06:04 +0200 | [diff] [blame] | 2496 | wacom_remote_destroy_one(wacom, i); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2497 | } |
| 2498 | } |
| 2499 | } |
| 2500 | |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2501 | static void wacom_mode_change_work(struct work_struct *work) |
| 2502 | { |
| 2503 | struct wacom *wacom = container_of(work, struct wacom, mode_change_work); |
| 2504 | struct wacom_shared *shared = wacom->wacom_wac.shared; |
| 2505 | struct wacom *wacom1 = NULL; |
| 2506 | struct wacom *wacom2 = NULL; |
| 2507 | bool is_direct = wacom->wacom_wac.is_direct_mode; |
| 2508 | int error = 0; |
| 2509 | |
| 2510 | if (shared->pen) { |
| 2511 | wacom1 = hid_get_drvdata(shared->pen); |
| 2512 | wacom_release_resources(wacom1); |
| 2513 | hid_hw_stop(wacom1->hdev); |
| 2514 | wacom1->wacom_wac.has_mode_change = true; |
| 2515 | wacom1->wacom_wac.is_direct_mode = is_direct; |
| 2516 | } |
| 2517 | |
| 2518 | if (shared->touch) { |
| 2519 | wacom2 = hid_get_drvdata(shared->touch); |
| 2520 | wacom_release_resources(wacom2); |
| 2521 | hid_hw_stop(wacom2->hdev); |
| 2522 | wacom2->wacom_wac.has_mode_change = true; |
| 2523 | wacom2->wacom_wac.is_direct_mode = is_direct; |
| 2524 | } |
| 2525 | |
| 2526 | if (wacom1) { |
| 2527 | error = wacom_parse_and_register(wacom1, false); |
| 2528 | if (error) |
| 2529 | return; |
| 2530 | } |
| 2531 | |
| 2532 | if (wacom2) { |
| 2533 | error = wacom_parse_and_register(wacom2, false); |
| 2534 | if (error) |
| 2535 | return; |
| 2536 | } |
| 2537 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2538 | return; |
| 2539 | } |
| 2540 | |
| 2541 | static int wacom_probe(struct hid_device *hdev, |
| 2542 | const struct hid_device_id *id) |
| 2543 | { |
| 2544 | struct usb_interface *intf = to_usb_interface(hdev->dev.parent); |
| 2545 | struct usb_device *dev = interface_to_usbdev(intf); |
| 2546 | struct wacom *wacom; |
| 2547 | struct wacom_wac *wacom_wac; |
| 2548 | struct wacom_features *features; |
| 2549 | int error; |
| 2550 | |
| 2551 | if (!id->driver_data) |
| 2552 | return -EINVAL; |
| 2553 | |
| 2554 | hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS; |
| 2555 | |
| 2556 | /* hid-core sets this quirk for the boot interface */ |
| 2557 | hdev->quirks &= ~HID_QUIRK_NOGET; |
| 2558 | |
Benjamin Tissoires | 19b6433 | 2016-07-13 18:05:58 +0200 | [diff] [blame] | 2559 | wacom = devm_kzalloc(&hdev->dev, sizeof(struct wacom), GFP_KERNEL); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2560 | if (!wacom) |
| 2561 | return -ENOMEM; |
| 2562 | |
| 2563 | hid_set_drvdata(hdev, wacom); |
| 2564 | wacom->hdev = hdev; |
| 2565 | |
| 2566 | wacom_wac = &wacom->wacom_wac; |
| 2567 | wacom_wac->features = *((struct wacom_features *)id->driver_data); |
| 2568 | features = &wacom_wac->features; |
| 2569 | |
| 2570 | if (features->check_for_hid_type && features->hid_type != hdev->type) { |
| 2571 | error = -ENODEV; |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2572 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2575 | wacom_wac->hid_data.inputmode = -1; |
Jason Gerecke | 326ea2a | 2016-04-04 11:26:52 -0700 | [diff] [blame] | 2576 | wacom_wac->mode_report = -1; |
Jason Gerecke | c6fa1ae | 2016-04-04 11:26:51 -0700 | [diff] [blame] | 2577 | |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2578 | wacom->usbdev = dev; |
| 2579 | wacom->intf = intf; |
| 2580 | mutex_init(&wacom->lock); |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2581 | INIT_DELAYED_WORK(&wacom->init_work, wacom_init_work); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2582 | INIT_WORK(&wacom->wireless_work, wacom_wireless_work); |
| 2583 | INIT_WORK(&wacom->battery_work, wacom_battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2584 | INIT_WORK(&wacom->remote_work, wacom_remote_work); |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2585 | INIT_WORK(&wacom->mode_change_work, wacom_mode_change_work); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2586 | |
| 2587 | /* ask for the report descriptor to be loaded by HID */ |
| 2588 | error = hid_parse(hdev); |
| 2589 | if (error) { |
| 2590 | hid_err(hdev, "parse failed\n"); |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2591 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2592 | } |
| 2593 | |
Benjamin Tissoires | fd5f92b | 2016-02-12 17:27:43 +0100 | [diff] [blame] | 2594 | error = wacom_parse_and_register(wacom, false); |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2595 | if (error) |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2596 | goto fail; |
Benjamin Tissoires | c58ac3a | 2016-02-12 17:27:41 +0100 | [diff] [blame] | 2597 | |
| 2598 | if (hdev->bus == BUS_BLUETOOTH) { |
| 2599 | error = device_create_file(&hdev->dev, &dev_attr_speed); |
| 2600 | if (error) |
| 2601 | hid_warn(hdev, |
| 2602 | "can't create sysfs speed attribute err: %d\n", |
| 2603 | error); |
| 2604 | } |
| 2605 | |
| 2606 | return 0; |
| 2607 | |
Benjamin Tissoires | 3888b0d | 2016-07-13 18:06:03 +0200 | [diff] [blame] | 2608 | fail: |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2609 | hid_set_drvdata(hdev, NULL); |
Dmitry Torokhov | 5014186 | 2007-04-12 01:33:39 -0400 | [diff] [blame] | 2610 | return error; |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2611 | } |
| 2612 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2613 | static void wacom_remove(struct hid_device *hdev) |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2614 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2615 | struct wacom *wacom = hid_get_drvdata(hdev); |
Benjamin Tissoires | f620516 | 2016-02-12 17:27:45 +0100 | [diff] [blame] | 2616 | struct wacom_wac *wacom_wac = &wacom->wacom_wac; |
| 2617 | struct wacom_features *features = &wacom_wac->features; |
| 2618 | |
| 2619 | if (features->device_type & WACOM_DEVICETYPE_WL_MONITOR) |
| 2620 | hid_hw_close(hdev); |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2621 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2622 | hid_hw_stop(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2623 | |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2624 | cancel_delayed_work_sync(&wacom->init_work); |
Benjamin Tissoires | d17d1f1 | 2016-07-13 18:05:52 +0200 | [diff] [blame] | 2625 | cancel_work_sync(&wacom->wireless_work); |
| 2626 | cancel_work_sync(&wacom->battery_work); |
Benjamin Tissoires | e6f2813 | 2016-07-13 18:06:01 +0200 | [diff] [blame] | 2627 | cancel_work_sync(&wacom->remote_work); |
Benjamin Tissoires | 4082da8 | 2017-02-14 21:27:18 -0800 | [diff] [blame] | 2628 | cancel_work_sync(&wacom->mode_change_work); |
Benjamin Tissoires | f81a129 | 2014-08-06 13:48:01 -0700 | [diff] [blame] | 2629 | if (hdev->bus == BUS_BLUETOOTH) |
| 2630 | device_remove_file(&hdev->dev, &dev_attr_speed); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2631 | |
Benjamin Tissoires | c0265a94 | 2017-01-20 16:20:12 +0100 | [diff] [blame] | 2632 | /* make sure we don't trigger the LEDs */ |
| 2633 | wacom_led_groups_release(wacom); |
Aaron Armstrong Skomra | b6b1f19 | 2017-03-06 10:54:58 -0800 | [diff] [blame] | 2634 | |
| 2635 | if (wacom->wacom_wac.features.type != REMOTE) |
| 2636 | wacom_release_resources(wacom); |
Benjamin Tissoires | 5b779fc | 2017-01-20 16:20:11 +0100 | [diff] [blame] | 2637 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2638 | hid_set_drvdata(hdev, NULL); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2639 | } |
| 2640 | |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2641 | #ifdef CONFIG_PM |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2642 | static int wacom_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2643 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2644 | struct wacom *wacom = hid_get_drvdata(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2645 | |
| 2646 | mutex_lock(&wacom->lock); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2647 | |
| 2648 | /* switch to wacom mode first */ |
Benjamin Tissoires | a544c61 | 2017-01-20 16:20:13 +0100 | [diff] [blame] | 2649 | _wacom_query_tablet_data(wacom); |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2650 | wacom_led_control(wacom); |
| 2651 | |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2652 | mutex_unlock(&wacom->lock); |
| 2653 | |
| 2654 | return 0; |
| 2655 | } |
| 2656 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2657 | static int wacom_reset_resume(struct hid_device *hdev) |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2658 | { |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2659 | return wacom_resume(hdev); |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2660 | } |
Geert Uytterhoeven | 41a7458 | 2014-08-11 11:03:19 -0700 | [diff] [blame] | 2661 | #endif /* CONFIG_PM */ |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2662 | |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2663 | static struct hid_driver wacom_driver = { |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2664 | .name = "wacom", |
Bastian Blank | b036f6f | 2010-02-10 23:06:23 -0800 | [diff] [blame] | 2665 | .id_table = wacom_ids, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2666 | .probe = wacom_probe, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2667 | .remove = wacom_remove, |
Benjamin Tissoires | 7704ac9 | 2014-09-23 12:08:08 -0400 | [diff] [blame] | 2668 | .report = wacom_wac_report, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2669 | #ifdef CONFIG_PM |
Oliver Neukum | e722409 | 2008-04-15 01:31:57 -0400 | [diff] [blame] | 2670 | .resume = wacom_resume, |
| 2671 | .reset_resume = wacom_reset_resume, |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2672 | #endif |
| 2673 | .raw_event = wacom_raw_event, |
Ping Cheng | 3bea733 | 2006-07-13 18:01:36 -0700 | [diff] [blame] | 2674 | }; |
Benjamin Tissoires | 29b4739 | 2014-07-24 12:52:23 -0700 | [diff] [blame] | 2675 | module_hid_driver(wacom_driver); |
Benjamin Tissoires | f2e0a7d | 2014-08-06 14:07:49 -0700 | [diff] [blame] | 2676 | |
| 2677 | MODULE_VERSION(DRIVER_VERSION); |
| 2678 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 2679 | MODULE_DESCRIPTION(DRIVER_DESC); |
Grant Grundler | 7021b60 | 2017-01-05 11:07:04 -0800 | [diff] [blame] | 2680 | MODULE_LICENSE("GPL"); |