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