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