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