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