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