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