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