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