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