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