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