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