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