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