blob: 872aa0be2e70595ad3ec5aed970371bddd567ca0 [file] [log] [blame]
Ping Cheng3bea7332006-07-13 18:01:36 -07001/*
Dmitry Torokhov4104d132007-05-07 16:16:29 -04002 * drivers/input/tablet/wacom_sys.c
Ping Cheng3bea7332006-07-13 18:01:36 -07003 *
Ping Cheng232f5692009-12-15 00:35:24 -08004 * USB Wacom tablet support - system specific code
Ping Cheng3bea7332006-07-13 18:01:36 -07005 */
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 Cheng3bea7332006-07-13 18:01:36 -070014#include "wacom_wac.h"
Dmitry Torokhov51269fe2010-03-19 22:18:15 -070015#include "wacom.h"
Jason Gereckeb58ba1b2014-12-05 13:37:32 -080016#include <linux/input/mt.h>
Ping Cheng3bea7332006-07-13 18:01:36 -070017
Ping Chenga417ea42011-08-16 00:17:56 -070018#define WAC_MSG_RETRIES 5
Ping Cheng3bea7332006-07-13 18:01:36 -070019
Ping Cheng912ca212014-09-10 12:41:31 -070020#define WAC_CMD_WL_LED_CONTROL 0x03
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070021#define WAC_CMD_LED_CONTROL 0x20
22#define WAC_CMD_ICON_START 0x21
23#define WAC_CMD_ICON_XFER 0x23
Benjamin Tissoires849e2f02014-08-06 13:58:25 -070024#define WAC_CMD_ICON_BT_XFER 0x26
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070025#define WAC_CMD_RETRIES 10
26
Ping Chenge0984bc2014-09-10 12:40:05 -070027#define DEV_ATTR_RW_PERM (S_IRUGO | S_IWUSR | S_IWGRP)
28#define DEV_ATTR_WO_PERM (S_IWUSR | S_IWGRP)
29
Ping Chengc64d8832014-09-10 12:41:04 -070030static int wacom_get_report(struct hid_device *hdev, u8 type, u8 *buf,
31 size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070032{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070033 int retval;
34
35 do {
Ping Chengc64d8832014-09-10 12:41:04 -070036 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
Benjamin Tissoires27b20a92014-07-24 12:56:22 -070037 HID_REQ_GET_REPORT);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070038 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
39
40 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070041}
42
Przemo Firszt296b7372014-08-06 14:00:38 -070043static int wacom_set_report(struct hid_device *hdev, u8 type, u8 *buf,
44 size_t size, unsigned int retries)
Ping Cheng3bea7332006-07-13 18:01:36 -070045{
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070046 int retval;
47
48 do {
Przemo Firszt296b7372014-08-06 14:00:38 -070049 retval = hid_hw_raw_request(hdev, buf[0], buf, size, type,
Benjamin Tissoires27b20a92014-07-24 12:56:22 -070050 HID_REQ_SET_REPORT);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -070051 } while ((retval == -ETIMEDOUT || retval == -EPIPE) && --retries);
52
53 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070054}
55
Benjamin Tissoires29b47392014-07-24 12:52:23 -070056static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
57 u8 *raw_data, int size)
Ping Cheng3bea7332006-07-13 18:01:36 -070058{
Benjamin Tissoires29b47392014-07-24 12:52:23 -070059 struct wacom *wacom = hid_get_drvdata(hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -070060
Benjamin Tissoires29b47392014-07-24 12:52:23 -070061 if (size > WACOM_PKGLEN_MAX)
62 return 1;
Ping Cheng3bea7332006-07-13 18:01:36 -070063
Benjamin Tissoires29b47392014-07-24 12:52:23 -070064 memcpy(wacom->wacom_wac.data, raw_data, size);
Ping Cheng3bea7332006-07-13 18:01:36 -070065
Benjamin Tissoires29b47392014-07-24 12:52:23 -070066 wacom_wac_irq(&wacom->wacom_wac, size);
67
68 return 0;
Ping Cheng3bea7332006-07-13 18:01:36 -070069}
70
Ping Cheng3bea7332006-07-13 18:01:36 -070071static int wacom_open(struct input_dev *dev)
72{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -040073 struct wacom *wacom = input_get_drvdata(dev);
Benjamin Tissoires29b47392014-07-24 12:52:23 -070074 int retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070075
Oliver Neukume7224092008-04-15 01:31:57 -040076 mutex_lock(&wacom->lock);
Benjamin Tissoires29b47392014-07-24 12:52:23 -070077 retval = hid_hw_open(wacom->hdev);
Oliver Neukume7224092008-04-15 01:31:57 -040078 mutex_unlock(&wacom->lock);
Benjamin Tissoires29b47392014-07-24 12:52:23 -070079
Dmitry Torokhovf6cd3782010-10-04 21:46:11 -070080 return retval;
Ping Cheng3bea7332006-07-13 18:01:36 -070081}
82
83static void wacom_close(struct input_dev *dev)
84{
Dmitry Torokhov7791bda2007-04-12 01:34:39 -040085 struct wacom *wacom = input_get_drvdata(dev);
Ping Cheng3bea7332006-07-13 18:01:36 -070086
Oliver Neukume7224092008-04-15 01:31:57 -040087 mutex_lock(&wacom->lock);
Benjamin Tissoires29b47392014-07-24 12:52:23 -070088 hid_hw_close(wacom->hdev);
Oliver Neukume7224092008-04-15 01:31:57 -040089 mutex_unlock(&wacom->lock);
Ping Cheng3bea7332006-07-13 18:01:36 -070090}
91
Chris Bagwell16bf2882012-03-25 23:26:20 -070092/*
Benjamin Tissoires198fdee2014-07-24 13:03:05 -070093 * Calculate the resolution of the X or Y axis using hidinput_calc_abs_res.
Jason Gerecke115d5e12012-10-03 17:24:32 -070094 */
95static int wacom_calc_hid_res(int logical_extents, int physical_extents,
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -070096 unsigned unit, int exponent)
Jason Gerecke115d5e12012-10-03 17:24:32 -070097{
Benjamin Tissoires198fdee2014-07-24 13:03:05 -070098 struct hid_field field = {
99 .logical_maximum = logical_extents,
100 .physical_maximum = physical_extents,
101 .unit = unit,
102 .unit_exponent = exponent,
103 };
Jason Gerecke115d5e12012-10-03 17:24:32 -0700104
Benjamin Tissoires198fdee2014-07-24 13:03:05 -0700105 return hidinput_calc_abs_res(&field, ABS_X);
Jason Gerecke115d5e12012-10-03 17:24:32 -0700106}
107
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700108static void wacom_feature_mapping(struct hid_device *hdev,
109 struct hid_field *field, struct hid_usage *usage)
Chris Bagwell41343612011-10-26 22:32:52 -0700110{
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700111 struct wacom *wacom = hid_get_drvdata(hdev);
112 struct wacom_features *features = &wacom->wacom_wac.features;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400113 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400114 u8 *data;
115 int ret;
Chris Bagwell41343612011-10-26 22:32:52 -0700116
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700117 switch (usage->hid) {
118 case HID_DG_CONTACTMAX:
119 /* leave touch_max as is if predefined */
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -0400120 if (!features->touch_max) {
121 /* read manually */
122 data = kzalloc(2, GFP_KERNEL);
123 if (!data)
124 break;
125 data[0] = field->report->id;
126 ret = wacom_get_report(hdev, HID_FEATURE_REPORT,
127 data, 2, 0);
128 if (ret == 2)
129 features->touch_max = data[1];
130 kfree(data);
131 }
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700132 break;
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400133 case HID_DG_INPUTMODE:
134 /* Ignore if value index is out of bounds. */
135 if (usage->usage_index >= field->report_count) {
136 dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
137 break;
138 }
139
140 hid_data->inputmode = field->report->id;
141 hid_data->inputmode_index = usage->usage_index;
142 break;
Ping Chengf393ee22012-04-29 21:09:17 -0700143 }
144}
145
Chris Bagwell428f8582011-10-26 22:26:59 -0700146/*
147 * Interface Descriptor of wacom devices can be incomplete and
148 * inconsistent so wacom_features table is used to store stylus
149 * device's packet lengths, various maximum values, and tablet
150 * resolution based on product ID's.
151 *
152 * For devices that contain 2 interfaces, wacom_features table is
153 * inaccurate for the touch interface. Since the Interface Descriptor
154 * for touch interfaces has pretty complete data, this function exists
155 * to query tablet for this missing information instead of hard coding in
156 * an additional table.
157 *
158 * A typical Interface Descriptor for a stylus will contain a
159 * boot mouse application collection that is not of interest and this
160 * function will ignore it.
161 *
162 * It also contains a digitizer application collection that also is not
163 * of interest since any information it contains would be duplicate
164 * of what is in wacom_features. Usually it defines a report of an array
165 * of bytes that could be used as max length of the stylus packet returned.
166 * If it happens to define a Digitizer-Stylus Physical Collection then
167 * the X and Y logical values contain valid data but it is ignored.
168 *
169 * A typical Interface Descriptor for a touch interface will contain a
170 * Digitizer-Finger Physical Collection which will define both logical
171 * X/Y maximum as well as the physical size of tablet. Since touch
172 * interfaces haven't supported pressure or distance, this is enough
173 * information to override invalid values in the wacom_features table.
Chris Bagwell41343612011-10-26 22:32:52 -0700174 *
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700175 * Intuos5 touch interface and 3rd gen Bamboo Touch do not contain useful
176 * data. We deal with them after returning from this function.
Chris Bagwell428f8582011-10-26 22:26:59 -0700177 */
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700178static void wacom_usage_mapping(struct hid_device *hdev,
179 struct hid_field *field, struct hid_usage *usage)
180{
181 struct wacom *wacom = hid_get_drvdata(hdev);
182 struct wacom_features *features = &wacom->wacom_wac.features;
183 bool finger = (field->logical == HID_DG_FINGER) ||
184 (field->physical == HID_DG_FINGER);
185 bool pen = (field->logical == HID_DG_STYLUS) ||
186 (field->physical == HID_DG_STYLUS);
187
188 /*
189 * Requiring Stylus Usage will ignore boot mouse
190 * X/Y values and some cases of invalid Digitizer X/Y
191 * values commonly reported.
192 */
193 if (!pen && !finger)
194 return;
195
Ping Cheng30ebc1a2014-11-18 13:29:16 -0800196 /*
197 * Bamboo models do not support HID_DG_CONTACTMAX.
198 * And, Bamboo Pen only descriptor contains touch.
199 */
200 if (features->type != BAMBOO_PT) {
201 /* ISDv4 touch devices at least supports one touch point */
202 if (finger && !features->touch_max)
203 features->touch_max = 1;
204 }
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700205
206 switch (usage->hid) {
207 case HID_GD_X:
208 features->x_max = field->logical_maximum;
209 if (finger) {
210 features->device_type = BTN_TOOL_FINGER;
211 features->x_phy = field->physical_maximum;
212 if (features->type != BAMBOO_PT) {
213 features->unit = field->unit;
214 features->unitExpo = field->unit_exponent;
215 }
216 } else {
217 features->device_type = BTN_TOOL_PEN;
218 }
219 break;
220 case HID_GD_Y:
221 features->y_max = field->logical_maximum;
222 if (finger) {
223 features->y_phy = field->physical_maximum;
224 if (features->type != BAMBOO_PT) {
225 features->unit = field->unit;
226 features->unitExpo = field->unit_exponent;
227 }
228 }
229 break;
230 case HID_DG_TIPPRESSURE:
231 if (pen)
232 features->pressure_max = field->logical_maximum;
233 break;
234 }
Benjamin Tissoires7704ac92014-09-23 12:08:08 -0400235
236 if (features->type == HID_GENERIC)
237 wacom_wac_usage_mapping(hdev, field, usage);
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700238}
239
Jason Gereckeb58ba1b2014-12-05 13:37:32 -0800240static void wacom_post_parse_hid(struct hid_device *hdev,
241 struct wacom_features *features)
242{
243 struct wacom *wacom = hid_get_drvdata(hdev);
244 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
245
246 if (features->type == HID_GENERIC) {
247 /* Any last-minute generic device setup */
248 if (features->touch_max > 1) {
249 input_mt_init_slots(wacom_wac->input, wacom_wac->features.touch_max,
250 INPUT_MT_DIRECT);
251 }
252 }
253}
254
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700255static void wacom_parse_hid(struct hid_device *hdev,
Ping Chengec67bbe2009-12-15 00:35:24 -0800256 struct wacom_features *features)
Ping Cheng545f4e92008-11-24 11:44:27 -0500257{
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700258 struct hid_report_enum *rep_enum;
259 struct hid_report *hreport;
260 int i, j;
Ping Cheng545f4e92008-11-24 11:44:27 -0500261
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700262 /* check features first */
263 rep_enum = &hdev->report_enum[HID_FEATURE_REPORT];
264 list_for_each_entry(hreport, &rep_enum->report_list, list) {
265 for (i = 0; i < hreport->maxfield; i++) {
266 /* Ignore if report count is out of bounds. */
267 if (hreport->field[i]->report_count < 1)
268 continue;
Ping Cheng545f4e92008-11-24 11:44:27 -0500269
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700270 for (j = 0; j < hreport->field[i]->maxusage; j++) {
271 wacom_feature_mapping(hdev, hreport->field[i],
272 hreport->field[i]->usage + j);
Ping Cheng545f4e92008-11-24 11:44:27 -0500273 }
Ping Cheng545f4e92008-11-24 11:44:27 -0500274 }
275 }
276
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700277 /* now check the input usages */
278 rep_enum = &hdev->report_enum[HID_INPUT_REPORT];
279 list_for_each_entry(hreport, &rep_enum->report_list, list) {
280
281 if (!hreport->maxfield)
282 continue;
283
284 for (i = 0; i < hreport->maxfield; i++)
285 for (j = 0; j < hreport->field[i]->maxusage; j++)
286 wacom_usage_mapping(hdev, hreport->field[i],
287 hreport->field[i]->usage + j);
288 }
Jason Gereckeb58ba1b2014-12-05 13:37:32 -0800289
290 wacom_post_parse_hid(hdev, features);
Ping Cheng545f4e92008-11-24 11:44:27 -0500291}
292
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400293static int wacom_hid_set_device_mode(struct hid_device *hdev)
294{
295 struct wacom *wacom = hid_get_drvdata(hdev);
296 struct hid_data *hid_data = &wacom->wacom_wac.hid_data;
297 struct hid_report *r;
298 struct hid_report_enum *re;
299
300 if (hid_data->inputmode < 0)
301 return 0;
302
303 re = &(hdev->report_enum[HID_FEATURE_REPORT]);
304 r = re->report_id_hash[hid_data->inputmode];
305 if (r) {
306 r->field[0]->value[hid_data->inputmode_index] = 2;
307 hid_hw_request(hdev, r, HID_REQ_SET_REPORT);
308 }
309 return 0;
310}
311
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700312static int wacom_set_device_mode(struct hid_device *hdev, int report_id,
313 int length, int mode)
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700314{
315 unsigned char *rep_data;
Jason Gereckefe494bc2012-10-03 17:25:35 -0700316 int error = -ENOMEM, limit = 0;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700317
Jason Gereckefe494bc2012-10-03 17:25:35 -0700318 rep_data = kzalloc(length, GFP_KERNEL);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700319 if (!rep_data)
Ping Chengec67bbe2009-12-15 00:35:24 -0800320 return error;
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700321
Jason Gereckefe494bc2012-10-03 17:25:35 -0700322 do {
Chris Bagwell9937c022013-01-23 19:37:34 -0800323 rep_data[0] = report_id;
324 rep_data[1] = mode;
325
Przemo Firszt296b7372014-08-06 14:00:38 -0700326 error = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data,
327 length, 1);
Benjamin Tissoires3cb83152014-07-24 12:47:47 -0700328 if (error >= 0)
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700329 error = wacom_get_report(hdev, HID_FEATURE_REPORT,
Ping Chengc64d8832014-09-10 12:41:04 -0700330 rep_data, length, 1);
Jason Gereckefe494bc2012-10-03 17:25:35 -0700331 } while ((error < 0 || rep_data[1] != mode) && limit++ < WAC_MSG_RETRIES);
Dmitry Torokhov3b7307c2009-08-20 21:41:04 -0700332
333 kfree(rep_data);
334
335 return error < 0 ? error : 0;
336}
337
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700338static int wacom_bt_query_tablet_data(struct hid_device *hdev, u8 speed,
339 struct wacom_features *features)
340{
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700341 struct wacom *wacom = hid_get_drvdata(hdev);
342 int ret;
343 u8 rep_data[2];
344
345 switch (features->type) {
346 case GRAPHIRE_BT:
347 rep_data[0] = 0x03;
348 rep_data[1] = 0x00;
Przemo Firszt296b7372014-08-06 14:00:38 -0700349 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
350 3);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700351
352 if (ret >= 0) {
353 rep_data[0] = speed == 0 ? 0x05 : 0x06;
354 rep_data[1] = 0x00;
355
356 ret = wacom_set_report(hdev, HID_FEATURE_REPORT,
Przemo Firszt296b7372014-08-06 14:00:38 -0700357 rep_data, 2, 3);
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700358
359 if (ret >= 0) {
360 wacom->wacom_wac.bt_high_speed = speed;
361 return 0;
362 }
363 }
364
365 /*
366 * Note that if the raw queries fail, it's not a hard failure
367 * and it is safe to continue
368 */
369 hid_warn(hdev, "failed to poke device, command %d, err %d\n",
370 rep_data[0], ret);
371 break;
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700372 case INTUOS4WL:
373 if (speed == 1)
374 wacom->wacom_wac.bt_features &= ~0x20;
375 else
376 wacom->wacom_wac.bt_features |= 0x20;
377
378 rep_data[0] = 0x03;
379 rep_data[1] = wacom->wacom_wac.bt_features;
380
Przemo Firszt296b7372014-08-06 14:00:38 -0700381 ret = wacom_set_report(hdev, HID_FEATURE_REPORT, rep_data, 2,
382 1);
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700383 if (ret >= 0)
384 wacom->wacom_wac.bt_high_speed = speed;
385 break;
Benjamin Tissoires387142b2014-08-06 13:52:56 -0700386 }
387
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700388 return 0;
389}
390
Jason Gereckefe494bc2012-10-03 17:25:35 -0700391/*
392 * Switch the tablet into its most-capable mode. Wacom tablets are
393 * typically configured to power-up in a mode which sends mouse-like
394 * reports to the OS. To get absolute position, pressure data, etc.
395 * from the tablet, it is necessary to switch the tablet out of this
396 * mode and into one which sends the full range of tablet data.
397 */
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700398static int wacom_query_tablet_data(struct hid_device *hdev,
399 struct wacom_features *features)
Jason Gereckefe494bc2012-10-03 17:25:35 -0700400{
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -0700401 if (hdev->bus == BUS_BLUETOOTH)
402 return wacom_bt_query_tablet_data(hdev, 1, features);
403
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -0400404 if (features->type == HID_GENERIC)
405 return wacom_hid_set_device_mode(hdev);
406
Jason Gereckefe494bc2012-10-03 17:25:35 -0700407 if (features->device_type == BTN_TOOL_FINGER) {
408 if (features->type > TABLETPC) {
409 /* MT Tablet PC touch */
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700410 return wacom_set_device_mode(hdev, 3, 4, 4);
Jason Gereckefe494bc2012-10-03 17:25:35 -0700411 }
Jason Gerecke36d3c512013-09-20 09:47:35 -0700412 else if (features->type == WACOM_24HDT || features->type == CINTIQ_HYBRID) {
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700413 return wacom_set_device_mode(hdev, 18, 3, 2);
Jason Gereckeb1e42792012-10-21 00:38:04 -0700414 }
Jason Gereckefe494bc2012-10-03 17:25:35 -0700415 } else if (features->device_type == BTN_TOOL_PEN) {
416 if (features->type <= BAMBOO_PT && features->type != WIRELESS) {
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700417 return wacom_set_device_mode(hdev, 2, 2, 2);
Jason Gereckefe494bc2012-10-03 17:25:35 -0700418 }
419 }
420
421 return 0;
422}
423
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700424static void wacom_retrieve_hid_descriptor(struct hid_device *hdev,
Ping Cheng19635182012-04-29 21:09:18 -0700425 struct wacom_features *features)
Ping Chengec67bbe2009-12-15 00:35:24 -0800426{
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700427 struct wacom *wacom = hid_get_drvdata(hdev);
428 struct usb_interface *intf = wacom->intf;
Ping Chengec67bbe2009-12-15 00:35:24 -0800429
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700430 /* default features */
Ping Chengec67bbe2009-12-15 00:35:24 -0800431 features->device_type = BTN_TOOL_PEN;
Henrik Rydbergfed87e62010-09-05 12:25:11 -0700432 features->x_fuzz = 4;
433 features->y_fuzz = 4;
434 features->pressure_fuzz = 0;
435 features->distance_fuzz = 0;
Ping Chengec67bbe2009-12-15 00:35:24 -0800436
Chris Bagwelld3825d52012-03-25 23:26:11 -0700437 /*
438 * The wireless device HID is basic and layout conflicts with
439 * other tablets (monitor and touch interface can look like pen).
440 * Skip the query for this type and modify defaults based on
441 * interface number.
442 */
443 if (features->type == WIRELESS) {
444 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
445 features->device_type = 0;
446 } else if (intf->cur_altsetting->desc.bInterfaceNumber == 2) {
Ping Chengadad0042012-06-28 16:48:17 -0700447 features->device_type = BTN_TOOL_FINGER;
Chris Bagwelld3825d52012-03-25 23:26:11 -0700448 features->pktlen = WACOM_PKGLEN_BBTOUCH3;
449 }
450 }
451
Ping Cheng19635182012-04-29 21:09:18 -0700452 /* only devices that support touch need to retrieve the info */
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700453 if (features->type < BAMBOO_PT)
454 return;
Ping Chengec67bbe2009-12-15 00:35:24 -0800455
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -0700456 wacom_parse_hid(hdev, features);
Ping Chengec67bbe2009-12-15 00:35:24 -0800457}
458
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700459struct wacom_hdev_data {
Ping Cheng4492eff2010-03-19 22:18:15 -0700460 struct list_head list;
461 struct kref kref;
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700462 struct hid_device *dev;
Ping Cheng4492eff2010-03-19 22:18:15 -0700463 struct wacom_shared shared;
464};
465
466static LIST_HEAD(wacom_udev_list);
467static DEFINE_MUTEX(wacom_udev_list_lock);
468
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700469static bool wacom_are_sibling(struct hid_device *hdev,
470 struct hid_device *sibling)
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700471{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700472 struct wacom *wacom = hid_get_drvdata(hdev);
473 struct wacom_features *features = &wacom->wacom_wac.features;
474 int vid = features->oVid;
475 int pid = features->oPid;
476 int n1,n2;
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700477
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700478 if (vid == 0 && pid == 0) {
479 vid = hdev->vendor;
480 pid = hdev->product;
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700481 }
482
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700483 if (vid != sibling->vendor || pid != sibling->product)
484 return false;
485
486 /* Compare the physical path. */
487 n1 = strrchr(hdev->phys, '.') - hdev->phys;
488 n2 = strrchr(sibling->phys, '.') - sibling->phys;
489 if (n1 != n2 || n1 <= 0 || n2 <= 0)
490 return false;
491
492 return !strncmp(hdev->phys, sibling->phys, n1);
Jason Gereckeaea2bf62012-10-21 00:38:03 -0700493}
494
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700495static struct wacom_hdev_data *wacom_get_hdev_data(struct hid_device *hdev)
Ping Cheng4492eff2010-03-19 22:18:15 -0700496{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700497 struct wacom_hdev_data *data;
Ping Cheng4492eff2010-03-19 22:18:15 -0700498
499 list_for_each_entry(data, &wacom_udev_list, list) {
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700500 if (wacom_are_sibling(hdev, data->dev)) {
Ping Cheng4492eff2010-03-19 22:18:15 -0700501 kref_get(&data->kref);
502 return data;
503 }
504 }
505
506 return NULL;
507}
508
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700509static int wacom_add_shared_data(struct hid_device *hdev)
Ping Cheng4492eff2010-03-19 22:18:15 -0700510{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700511 struct wacom *wacom = hid_get_drvdata(hdev);
512 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
513 struct wacom_hdev_data *data;
Ping Cheng4492eff2010-03-19 22:18:15 -0700514 int retval = 0;
515
516 mutex_lock(&wacom_udev_list_lock);
517
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700518 data = wacom_get_hdev_data(hdev);
Ping Cheng4492eff2010-03-19 22:18:15 -0700519 if (!data) {
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700520 data = kzalloc(sizeof(struct wacom_hdev_data), GFP_KERNEL);
Ping Cheng4492eff2010-03-19 22:18:15 -0700521 if (!data) {
522 retval = -ENOMEM;
523 goto out;
524 }
525
526 kref_init(&data->kref);
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700527 data->dev = hdev;
Ping Cheng4492eff2010-03-19 22:18:15 -0700528 list_add_tail(&data->list, &wacom_udev_list);
529 }
530
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700531 wacom_wac->shared = &data->shared;
Ping Cheng4492eff2010-03-19 22:18:15 -0700532
533out:
534 mutex_unlock(&wacom_udev_list_lock);
535 return retval;
536}
537
538static void wacom_release_shared_data(struct kref *kref)
539{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700540 struct wacom_hdev_data *data =
541 container_of(kref, struct wacom_hdev_data, kref);
Ping Cheng4492eff2010-03-19 22:18:15 -0700542
543 mutex_lock(&wacom_udev_list_lock);
544 list_del(&data->list);
545 mutex_unlock(&wacom_udev_list_lock);
546
547 kfree(data);
548}
549
550static void wacom_remove_shared_data(struct wacom_wac *wacom)
551{
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700552 struct wacom_hdev_data *data;
Ping Cheng4492eff2010-03-19 22:18:15 -0700553
554 if (wacom->shared) {
Benjamin Tissoires4451e082014-07-24 13:01:05 -0700555 data = container_of(wacom->shared, struct wacom_hdev_data, shared);
Ping Cheng4492eff2010-03-19 22:18:15 -0700556 kref_put(&data->kref, wacom_release_shared_data);
557 wacom->shared = NULL;
558 }
559}
560
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700561static int wacom_led_control(struct wacom *wacom)
562{
563 unsigned char *buf;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700564 int retval;
Ping Cheng912ca212014-09-10 12:41:31 -0700565 unsigned char report_id = WAC_CMD_LED_CONTROL;
566 int buf_size = 9;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700567
Ping Cheng912ca212014-09-10 12:41:31 -0700568 if (wacom->wacom_wac.pid) { /* wireless connected */
569 report_id = WAC_CMD_WL_LED_CONTROL;
570 buf_size = 13;
571 }
572 buf = kzalloc(buf_size, GFP_KERNEL);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700573 if (!buf)
574 return -ENOMEM;
575
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700576 if (wacom->wacom_wac.features.type >= INTUOS5S &&
Ping Cheng9a35c412013-09-20 09:51:56 -0700577 wacom->wacom_wac.features.type <= INTUOSPL) {
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700578 /*
579 * Touch Ring and crop mark LED luminance may take on
580 * one of four values:
581 * 0 = Low; 1 = Medium; 2 = High; 3 = Off
582 */
583 int ring_led = wacom->led.select[0] & 0x03;
584 int ring_lum = (((wacom->led.llv & 0x60) >> 5) - 1) & 0x03;
585 int crop_lum = 0;
Ping Cheng912ca212014-09-10 12:41:31 -0700586 unsigned char led_bits = (crop_lum << 4) | (ring_lum << 2) | (ring_led);
Ping Cheng09e7d942011-10-04 23:51:14 -0700587
Ping Cheng912ca212014-09-10 12:41:31 -0700588 buf[0] = report_id;
589 if (wacom->wacom_wac.pid) {
590 wacom_get_report(wacom->hdev, HID_FEATURE_REPORT,
591 buf, buf_size, WAC_CMD_RETRIES);
592 buf[0] = report_id;
593 buf[4] = led_bits;
594 } else
595 buf[1] = led_bits;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700596 }
597 else {
598 int led = wacom->led.select[0] | 0x4;
Ping Cheng09e7d942011-10-04 23:51:14 -0700599
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700600 if (wacom->wacom_wac.features.type == WACOM_21UX2 ||
601 wacom->wacom_wac.features.type == WACOM_24HD)
602 led |= (wacom->led.select[1] << 4) | 0x40;
603
Ping Cheng912ca212014-09-10 12:41:31 -0700604 buf[0] = report_id;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700605 buf[1] = led;
606 buf[2] = wacom->led.llv;
607 buf[3] = wacom->led.hlv;
608 buf[4] = wacom->led.img_lum;
609 }
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700610
Ping Cheng912ca212014-09-10 12:41:31 -0700611 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, buf_size,
Przemo Firszt296b7372014-08-06 14:00:38 -0700612 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700613 kfree(buf);
614
615 return retval;
616}
617
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700618static int wacom_led_putimage(struct wacom *wacom, int button_id, u8 xfer_id,
619 const unsigned len, const void *img)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700620{
621 unsigned char *buf;
622 int i, retval;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700623 const unsigned chunk_len = len / 4; /* 4 chunks are needed to be sent */
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700624
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700625 buf = kzalloc(chunk_len + 3 , GFP_KERNEL);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700626 if (!buf)
627 return -ENOMEM;
628
629 /* Send 'start' command */
630 buf[0] = WAC_CMD_ICON_START;
631 buf[1] = 1;
Przemo Firszt296b7372014-08-06 14:00:38 -0700632 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
633 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700634 if (retval < 0)
635 goto out;
636
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700637 buf[0] = xfer_id;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700638 buf[1] = button_id & 0x07;
639 for (i = 0; i < 4; i++) {
640 buf[2] = i;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700641 memcpy(buf + 3, img + i * chunk_len, chunk_len);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700642
Benjamin Tissoires27b20a92014-07-24 12:56:22 -0700643 retval = wacom_set_report(wacom->hdev, HID_FEATURE_REPORT,
Przemo Firszt296b7372014-08-06 14:00:38 -0700644 buf, chunk_len + 3, WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700645 if (retval < 0)
646 break;
647 }
648
649 /* Send 'stop' */
650 buf[0] = WAC_CMD_ICON_START;
651 buf[1] = 0;
Przemo Firszt296b7372014-08-06 14:00:38 -0700652 wacom_set_report(wacom->hdev, HID_FEATURE_REPORT, buf, 2,
653 WAC_CMD_RETRIES);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700654
655out:
656 kfree(buf);
657 return retval;
658}
659
Ping Cheng09e7d942011-10-04 23:51:14 -0700660static ssize_t wacom_led_select_store(struct device *dev, int set_id,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700661 const char *buf, size_t count)
662{
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700663 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700664 struct wacom *wacom = hid_get_drvdata(hdev);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700665 unsigned int id;
666 int err;
667
668 err = kstrtouint(buf, 10, &id);
669 if (err)
670 return err;
671
672 mutex_lock(&wacom->lock);
673
Ping Cheng09e7d942011-10-04 23:51:14 -0700674 wacom->led.select[set_id] = id & 0x3;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700675 err = wacom_led_control(wacom);
676
677 mutex_unlock(&wacom->lock);
678
679 return err < 0 ? err : count;
680}
681
Ping Cheng09e7d942011-10-04 23:51:14 -0700682#define DEVICE_LED_SELECT_ATTR(SET_ID) \
683static ssize_t wacom_led##SET_ID##_select_store(struct device *dev, \
684 struct device_attribute *attr, const char *buf, size_t count) \
685{ \
686 return wacom_led_select_store(dev, SET_ID, buf, count); \
687} \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700688static ssize_t wacom_led##SET_ID##_select_show(struct device *dev, \
689 struct device_attribute *attr, char *buf) \
690{ \
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700691 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700692 struct wacom *wacom = hid_get_drvdata(hdev); \
Ping Cheng37449ad2014-09-10 12:40:30 -0700693 return scnprintf(buf, PAGE_SIZE, "%d\n", \
694 wacom->led.select[SET_ID]); \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700695} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700696static DEVICE_ATTR(status_led##SET_ID##_select, DEV_ATTR_RW_PERM, \
Ping Cheng04c59ab2011-10-04 23:51:49 -0700697 wacom_led##SET_ID##_select_show, \
Ping Cheng09e7d942011-10-04 23:51:14 -0700698 wacom_led##SET_ID##_select_store)
699
700DEVICE_LED_SELECT_ATTR(0);
701DEVICE_LED_SELECT_ATTR(1);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700702
703static ssize_t wacom_luminance_store(struct wacom *wacom, u8 *dest,
704 const char *buf, size_t count)
705{
706 unsigned int value;
707 int err;
708
709 err = kstrtouint(buf, 10, &value);
710 if (err)
711 return err;
712
713 mutex_lock(&wacom->lock);
714
715 *dest = value & 0x7f;
716 err = wacom_led_control(wacom);
717
718 mutex_unlock(&wacom->lock);
719
720 return err < 0 ? err : count;
721}
722
723#define DEVICE_LUMINANCE_ATTR(name, field) \
724static ssize_t wacom_##name##_luminance_store(struct device *dev, \
725 struct device_attribute *attr, const char *buf, size_t count) \
726{ \
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700727 struct hid_device *hdev = container_of(dev, struct hid_device, dev);\
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700728 struct wacom *wacom = hid_get_drvdata(hdev); \
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700729 \
730 return wacom_luminance_store(wacom, &wacom->led.field, \
731 buf, count); \
732} \
Ping Cheng37449ad2014-09-10 12:40:30 -0700733static ssize_t wacom_##name##_luminance_show(struct device *dev, \
734 struct device_attribute *attr, char *buf) \
735{ \
736 struct wacom *wacom = dev_get_drvdata(dev); \
737 return scnprintf(buf, PAGE_SIZE, "%d\n", wacom->led.field); \
738} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700739static DEVICE_ATTR(name##_luminance, DEV_ATTR_RW_PERM, \
Ping Cheng37449ad2014-09-10 12:40:30 -0700740 wacom_##name##_luminance_show, \
741 wacom_##name##_luminance_store)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700742
743DEVICE_LUMINANCE_ATTR(status0, llv);
744DEVICE_LUMINANCE_ATTR(status1, hlv);
745DEVICE_LUMINANCE_ATTR(buttons, img_lum);
746
747static ssize_t wacom_button_image_store(struct device *dev, int button_id,
748 const char *buf, size_t count)
749{
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700750 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
Benjamin Tissoires29b47392014-07-24 12:52:23 -0700751 struct wacom *wacom = hid_get_drvdata(hdev);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700752 int err;
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700753 unsigned len;
754 u8 xfer_id;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700755
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700756 if (hdev->bus == BUS_BLUETOOTH) {
757 len = 256;
758 xfer_id = WAC_CMD_ICON_BT_XFER;
759 } else {
760 len = 1024;
761 xfer_id = WAC_CMD_ICON_XFER;
762 }
763
764 if (count != len)
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700765 return -EINVAL;
766
767 mutex_lock(&wacom->lock);
768
Benjamin Tissoires849e2f02014-08-06 13:58:25 -0700769 err = wacom_led_putimage(wacom, button_id, xfer_id, len, buf);
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700770
771 mutex_unlock(&wacom->lock);
772
773 return err < 0 ? err : count;
774}
775
776#define DEVICE_BTNIMG_ATTR(BUTTON_ID) \
777static ssize_t wacom_btnimg##BUTTON_ID##_store(struct device *dev, \
778 struct device_attribute *attr, const char *buf, size_t count) \
779{ \
780 return wacom_button_image_store(dev, BUTTON_ID, buf, count); \
781} \
Ping Chenge0984bc2014-09-10 12:40:05 -0700782static DEVICE_ATTR(button##BUTTON_ID##_rawimg, DEV_ATTR_WO_PERM, \
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700783 NULL, wacom_btnimg##BUTTON_ID##_store)
784
785DEVICE_BTNIMG_ATTR(0);
786DEVICE_BTNIMG_ATTR(1);
787DEVICE_BTNIMG_ATTR(2);
788DEVICE_BTNIMG_ATTR(3);
789DEVICE_BTNIMG_ATTR(4);
790DEVICE_BTNIMG_ATTR(5);
791DEVICE_BTNIMG_ATTR(6);
792DEVICE_BTNIMG_ATTR(7);
793
Ping Cheng09e7d942011-10-04 23:51:14 -0700794static struct attribute *cintiq_led_attrs[] = {
795 &dev_attr_status_led0_select.attr,
796 &dev_attr_status_led1_select.attr,
797 NULL
798};
799
800static struct attribute_group cintiq_led_attr_group = {
801 .name = "wacom_led",
802 .attrs = cintiq_led_attrs,
803};
804
805static struct attribute *intuos4_led_attrs[] = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700806 &dev_attr_status0_luminance.attr,
807 &dev_attr_status1_luminance.attr,
Ping Cheng09e7d942011-10-04 23:51:14 -0700808 &dev_attr_status_led0_select.attr,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700809 &dev_attr_buttons_luminance.attr,
810 &dev_attr_button0_rawimg.attr,
811 &dev_attr_button1_rawimg.attr,
812 &dev_attr_button2_rawimg.attr,
813 &dev_attr_button3_rawimg.attr,
814 &dev_attr_button4_rawimg.attr,
815 &dev_attr_button5_rawimg.attr,
816 &dev_attr_button6_rawimg.attr,
817 &dev_attr_button7_rawimg.attr,
818 NULL
819};
820
Ping Cheng09e7d942011-10-04 23:51:14 -0700821static struct attribute_group intuos4_led_attr_group = {
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700822 .name = "wacom_led",
Ping Cheng09e7d942011-10-04 23:51:14 -0700823 .attrs = intuos4_led_attrs,
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700824};
825
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700826static struct attribute *intuos5_led_attrs[] = {
827 &dev_attr_status0_luminance.attr,
828 &dev_attr_status_led0_select.attr,
829 NULL
830};
831
832static struct attribute_group intuos5_led_attr_group = {
833 .name = "wacom_led",
834 .attrs = intuos5_led_attrs,
835};
836
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700837static int wacom_initialize_leds(struct wacom *wacom)
838{
839 int error;
840
Ping Cheng09e7d942011-10-04 23:51:14 -0700841 /* Initialize default values */
842 switch (wacom->wacom_wac.features.type) {
Jason Gereckea19fc982012-06-12 00:27:53 -0700843 case INTUOS4S:
Ping Cheng09e7d942011-10-04 23:51:14 -0700844 case INTUOS4:
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700845 case INTUOS4WL:
Ping Cheng09e7d942011-10-04 23:51:14 -0700846 case INTUOS4L:
847 wacom->led.select[0] = 0;
848 wacom->led.select[1] = 0;
Ping Chengf4fa9a62011-10-04 23:49:42 -0700849 wacom->led.llv = 10;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700850 wacom->led.hlv = 20;
851 wacom->led.img_lum = 10;
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700852 error = sysfs_create_group(&wacom->hdev->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700853 &intuos4_led_attr_group);
854 break;
855
Jason Gerecke246835f2011-12-12 00:12:04 -0800856 case WACOM_24HD:
Ping Cheng09e7d942011-10-04 23:51:14 -0700857 case WACOM_21UX2:
858 wacom->led.select[0] = 0;
859 wacom->led.select[1] = 0;
860 wacom->led.llv = 0;
861 wacom->led.hlv = 0;
862 wacom->led.img_lum = 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700863
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700864 error = sysfs_create_group(&wacom->hdev->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700865 &cintiq_led_attr_group);
866 break;
867
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700868 case INTUOS5S:
869 case INTUOS5:
870 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -0700871 case INTUOSPS:
872 case INTUOSPM:
873 case INTUOSPL:
Ping Chengc2b0c272013-09-20 09:50:14 -0700874 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN) {
875 wacom->led.select[0] = 0;
876 wacom->led.select[1] = 0;
877 wacom->led.llv = 32;
878 wacom->led.hlv = 0;
879 wacom->led.img_lum = 0;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700880
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700881 error = sysfs_create_group(&wacom->hdev->dev.kobj,
Ping Chengc2b0c272013-09-20 09:50:14 -0700882 &intuos5_led_attr_group);
883 } else
884 return 0;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700885 break;
886
Ping Cheng09e7d942011-10-04 23:51:14 -0700887 default:
888 return 0;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700889 }
890
Ping Cheng09e7d942011-10-04 23:51:14 -0700891 if (error) {
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700892 hid_err(wacom->hdev,
Ping Cheng09e7d942011-10-04 23:51:14 -0700893 "cannot create sysfs group err: %d\n", error);
894 return error;
895 }
896 wacom_led_control(wacom);
Benjamin Tissoiresc757cba2014-07-24 13:16:17 -0700897 wacom->led_initialized = true;
Ping Cheng09e7d942011-10-04 23:51:14 -0700898
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700899 return 0;
900}
901
902static void wacom_destroy_leds(struct wacom *wacom)
903{
Benjamin Tissoiresc757cba2014-07-24 13:16:17 -0700904 if (!wacom->led_initialized)
905 return;
906
907 wacom->led_initialized = false;
908
Ping Cheng09e7d942011-10-04 23:51:14 -0700909 switch (wacom->wacom_wac.features.type) {
Jason Gereckea19fc982012-06-12 00:27:53 -0700910 case INTUOS4S:
Ping Cheng09e7d942011-10-04 23:51:14 -0700911 case INTUOS4:
Benjamin Tissoires81af7e62014-08-06 13:55:56 -0700912 case INTUOS4WL:
Ping Cheng09e7d942011-10-04 23:51:14 -0700913 case INTUOS4L:
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700914 sysfs_remove_group(&wacom->hdev->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700915 &intuos4_led_attr_group);
916 break;
917
Jason Gerecke246835f2011-12-12 00:12:04 -0800918 case WACOM_24HD:
Ping Cheng09e7d942011-10-04 23:51:14 -0700919 case WACOM_21UX2:
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700920 sysfs_remove_group(&wacom->hdev->dev.kobj,
Ping Cheng09e7d942011-10-04 23:51:14 -0700921 &cintiq_led_attr_group);
922 break;
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700923
924 case INTUOS5S:
925 case INTUOS5:
926 case INTUOS5L:
Ping Cheng9a35c412013-09-20 09:51:56 -0700927 case INTUOSPS:
928 case INTUOSPM:
929 case INTUOSPL:
Ping Chengc2b0c272013-09-20 09:50:14 -0700930 if (wacom->wacom_wac.features.device_type == BTN_TOOL_PEN)
Benjamin Tissoiresc31a4082014-07-24 12:59:45 -0700931 sysfs_remove_group(&wacom->hdev->dev.kobj,
Ping Chengc2b0c272013-09-20 09:50:14 -0700932 &intuos5_led_attr_group);
Jason Gerecke9b5b95d2012-04-03 15:50:37 -0700933 break;
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -0700934 }
935}
936
Chris Bagwella1d552c2012-03-25 23:26:30 -0700937static enum power_supply_property wacom_battery_props[] = {
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -0700938 POWER_SUPPLY_PROP_STATUS,
Bastien Nocera6e2a6e82013-10-15 23:33:00 -0700939 POWER_SUPPLY_PROP_SCOPE,
Chris Bagwella1d552c2012-03-25 23:26:30 -0700940 POWER_SUPPLY_PROP_CAPACITY
941};
942
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -0700943static enum power_supply_property wacom_ac_props[] = {
944 POWER_SUPPLY_PROP_PRESENT,
945 POWER_SUPPLY_PROP_ONLINE,
946 POWER_SUPPLY_PROP_SCOPE,
947};
948
Chris Bagwella1d552c2012-03-25 23:26:30 -0700949static int wacom_battery_get_property(struct power_supply *psy,
950 enum power_supply_property psp,
951 union power_supply_propval *val)
952{
953 struct wacom *wacom = container_of(psy, struct wacom, battery);
954 int ret = 0;
955
956 switch (psp) {
Bastien Nocera6e2a6e82013-10-15 23:33:00 -0700957 case POWER_SUPPLY_PROP_SCOPE:
958 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
959 break;
Chris Bagwella1d552c2012-03-25 23:26:30 -0700960 case POWER_SUPPLY_PROP_CAPACITY:
961 val->intval =
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -0700962 wacom->wacom_wac.battery_capacity;
963 break;
964 case POWER_SUPPLY_PROP_STATUS:
965 if (wacom->wacom_wac.bat_charging)
966 val->intval = POWER_SUPPLY_STATUS_CHARGING;
967 else if (wacom->wacom_wac.battery_capacity == 100 &&
968 wacom->wacom_wac.ps_connected)
969 val->intval = POWER_SUPPLY_STATUS_FULL;
970 else
971 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
Chris Bagwella1d552c2012-03-25 23:26:30 -0700972 break;
973 default:
974 ret = -EINVAL;
975 break;
976 }
977
978 return ret;
979}
980
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -0700981static int wacom_ac_get_property(struct power_supply *psy,
982 enum power_supply_property psp,
983 union power_supply_propval *val)
984{
985 struct wacom *wacom = container_of(psy, struct wacom, ac);
986 int ret = 0;
987
988 switch (psp) {
989 case POWER_SUPPLY_PROP_PRESENT:
990 /* fall through */
991 case POWER_SUPPLY_PROP_ONLINE:
992 val->intval = wacom->wacom_wac.ps_connected;
993 break;
994 case POWER_SUPPLY_PROP_SCOPE:
995 val->intval = POWER_SUPPLY_SCOPE_DEVICE;
996 break;
997 default:
998 ret = -EINVAL;
999 break;
1000 }
1001 return ret;
1002}
1003
Chris Bagwella1d552c2012-03-25 23:26:30 -07001004static int wacom_initialize_battery(struct wacom *wacom)
1005{
Benjamin Tissoiresd70420b2014-07-25 17:31:51 -07001006 static atomic_t battery_no = ATOMIC_INIT(0);
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001007 int error;
Benjamin Tissoiresd70420b2014-07-25 17:31:51 -07001008 unsigned long n;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001009
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001010 if (wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) {
Benjamin Tissoiresd70420b2014-07-25 17:31:51 -07001011 n = atomic_inc_return(&battery_no) - 1;
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001012
Chris Bagwella1d552c2012-03-25 23:26:30 -07001013 wacom->battery.properties = wacom_battery_props;
1014 wacom->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
1015 wacom->battery.get_property = wacom_battery_get_property;
Benjamin Tissoiresd70420b2014-07-25 17:31:51 -07001016 sprintf(wacom->wacom_wac.bat_name, "wacom_battery_%ld", n);
1017 wacom->battery.name = wacom->wacom_wac.bat_name;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001018 wacom->battery.type = POWER_SUPPLY_TYPE_BATTERY;
1019 wacom->battery.use_for_apm = 0;
1020
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001021 wacom->ac.properties = wacom_ac_props;
1022 wacom->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
1023 wacom->ac.get_property = wacom_ac_get_property;
1024 sprintf(wacom->wacom_wac.ac_name, "wacom_ac_%ld", n);
1025 wacom->ac.name = wacom->wacom_wac.ac_name;
1026 wacom->ac.type = POWER_SUPPLY_TYPE_MAINS;
1027 wacom->ac.use_for_apm = 0;
1028
Benjamin Tissoiresdd3181a2014-07-24 13:01:40 -07001029 error = power_supply_register(&wacom->hdev->dev,
Chris Bagwella1d552c2012-03-25 23:26:30 -07001030 &wacom->battery);
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001031 if (error)
1032 return error;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001033
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001034 power_supply_powers(&wacom->battery, &wacom->hdev->dev);
1035
1036 error = power_supply_register(&wacom->hdev->dev, &wacom->ac);
1037 if (error) {
1038 power_supply_unregister(&wacom->battery);
1039 return error;
1040 }
1041
1042 power_supply_powers(&wacom->ac, &wacom->hdev->dev);
Chris Bagwella1d552c2012-03-25 23:26:30 -07001043 }
1044
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001045 return 0;
Chris Bagwella1d552c2012-03-25 23:26:30 -07001046}
1047
1048static void wacom_destroy_battery(struct wacom *wacom)
1049{
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001050 if ((wacom->wacom_wac.features.quirks & WACOM_QUIRK_BATTERY) &&
1051 wacom->battery.dev) {
Chris Bagwella1d552c2012-03-25 23:26:30 -07001052 power_supply_unregister(&wacom->battery);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001053 wacom->battery.dev = NULL;
Benjamin Tissoires7dbd2292014-07-25 17:32:41 -07001054 power_supply_unregister(&wacom->ac);
1055 wacom->ac.dev = NULL;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001056 }
Chris Bagwella1d552c2012-03-25 23:26:30 -07001057}
1058
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001059static ssize_t wacom_show_speed(struct device *dev,
1060 struct device_attribute
1061 *attr, char *buf)
1062{
1063 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1064 struct wacom *wacom = hid_get_drvdata(hdev);
1065
1066 return snprintf(buf, PAGE_SIZE, "%i\n", wacom->wacom_wac.bt_high_speed);
1067}
1068
1069static ssize_t wacom_store_speed(struct device *dev,
1070 struct device_attribute *attr,
1071 const char *buf, size_t count)
1072{
1073 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1074 struct wacom *wacom = hid_get_drvdata(hdev);
1075 u8 new_speed;
1076
1077 if (kstrtou8(buf, 0, &new_speed))
1078 return -EINVAL;
1079
1080 if (new_speed != 0 && new_speed != 1)
1081 return -EINVAL;
1082
1083 wacom_bt_query_tablet_data(hdev, new_speed, &wacom->wacom_wac.features);
1084
1085 return count;
1086}
1087
Ping Chenge0984bc2014-09-10 12:40:05 -07001088static DEVICE_ATTR(speed, DEV_ATTR_RW_PERM,
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001089 wacom_show_speed, wacom_store_speed);
1090
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001091static struct input_dev *wacom_allocate_input(struct wacom *wacom)
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001092{
1093 struct input_dev *input_dev;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001094 struct hid_device *hdev = wacom->hdev;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001095 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001096
1097 input_dev = input_allocate_device();
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001098 if (!input_dev)
1099 return NULL;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001100
1101 input_dev->name = wacom_wac->name;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001102 input_dev->phys = hdev->phys;
1103 input_dev->dev.parent = &hdev->dev;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001104 input_dev->open = wacom_open;
1105 input_dev->close = wacom_close;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001106 input_dev->uniq = hdev->uniq;
1107 input_dev->id.bustype = hdev->bus;
1108 input_dev->id.vendor = hdev->vendor;
Benjamin Tissoires12969e32014-09-11 13:14:04 -04001109 input_dev->id.product = wacom_wac->pid ? wacom_wac->pid : hdev->product;
Benjamin Tissoiresb6c79f22014-07-24 13:00:03 -07001110 input_dev->id.version = hdev->version;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001111 input_set_drvdata(input_dev, wacom);
1112
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001113 return input_dev;
1114}
1115
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001116static void wacom_free_inputs(struct wacom *wacom)
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001117{
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001118 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1119
1120 if (wacom_wac->input)
1121 input_free_device(wacom_wac->input);
1122 if (wacom_wac->pad_input)
1123 input_free_device(wacom_wac->pad_input);
1124 wacom_wac->input = NULL;
1125 wacom_wac->pad_input = NULL;
1126}
1127
1128static int wacom_allocate_inputs(struct wacom *wacom)
1129{
1130 struct input_dev *input_dev, *pad_input_dev;
1131 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1132
1133 input_dev = wacom_allocate_input(wacom);
1134 pad_input_dev = wacom_allocate_input(wacom);
1135 if (!input_dev || !pad_input_dev) {
1136 wacom_free_inputs(wacom);
1137 return -ENOMEM;
1138 }
1139
1140 wacom_wac->input = input_dev;
1141 wacom_wac->pad_input = pad_input_dev;
1142 wacom_wac->pad_input->name = wacom_wac->pad_name;
1143
1144 return 0;
1145}
1146
1147static void wacom_clean_inputs(struct wacom *wacom)
1148{
1149 if (wacom->wacom_wac.input) {
1150 if (wacom->wacom_wac.input_registered)
1151 input_unregister_device(wacom->wacom_wac.input);
1152 else
1153 input_free_device(wacom->wacom_wac.input);
1154 }
1155 if (wacom->wacom_wac.pad_input) {
Ping Cheng954df6a2014-11-20 16:31:12 -08001156 if (wacom->wacom_wac.pad_registered)
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001157 input_unregister_device(wacom->wacom_wac.pad_input);
1158 else
1159 input_free_device(wacom->wacom_wac.pad_input);
1160 }
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001161 wacom->wacom_wac.input = NULL;
1162 wacom->wacom_wac.pad_input = NULL;
Ping Cheng912ca212014-09-10 12:41:31 -07001163 wacom_destroy_leds(wacom);
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001164}
1165
1166static int wacom_register_inputs(struct wacom *wacom)
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001167{
1168 struct input_dev *input_dev, *pad_input_dev;
1169 struct wacom_wac *wacom_wac = &(wacom->wacom_wac);
1170 int error;
1171
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001172 input_dev = wacom_wac->input;
1173 pad_input_dev = wacom_wac->pad_input;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001174
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001175 if (!input_dev || !pad_input_dev)
1176 return -EINVAL;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001177
Ping Cheng30ebc1a2014-11-18 13:29:16 -08001178 error = wacom_setup_pentouch_input_capabilities(input_dev, wacom_wac);
1179 if (!error) {
1180 error = input_register_device(input_dev);
1181 if (error)
1182 return error;
Ping Cheng954df6a2014-11-20 16:31:12 -08001183 wacom_wac->input_registered = true;
Ping Cheng30ebc1a2014-11-18 13:29:16 -08001184 }
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001185
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001186 error = wacom_setup_pad_input_capabilities(pad_input_dev, wacom_wac);
1187 if (error) {
1188 /* no pad in use on this interface */
1189 input_free_device(pad_input_dev);
1190 wacom_wac->pad_input = NULL;
1191 pad_input_dev = NULL;
1192 } else {
1193 error = input_register_device(pad_input_dev);
1194 if (error)
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001195 goto fail_register_pad_input;
Ping Cheng954df6a2014-11-20 16:31:12 -08001196 wacom_wac->pad_registered = true;
Ping Cheng912ca212014-09-10 12:41:31 -07001197
1198 error = wacom_initialize_leds(wacom);
1199 if (error)
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001200 goto fail_leds;
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001201 }
1202
Ping Cheng19635182012-04-29 21:09:18 -07001203 return 0;
1204
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001205fail_leds:
Ping Cheng912ca212014-09-10 12:41:31 -07001206 input_unregister_device(pad_input_dev);
1207 pad_input_dev = NULL;
Ping Cheng954df6a2014-11-20 16:31:12 -08001208 wacom_wac->pad_registered = false;
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001209fail_register_pad_input:
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001210 input_unregister_device(input_dev);
Ping Cheng19635182012-04-29 21:09:18 -07001211 wacom_wac->input = NULL;
Ping Cheng954df6a2014-11-20 16:31:12 -08001212 wacom_wac->input_registered = false;
Chris Bagwell3aac0ef2012-03-25 23:25:45 -07001213 return error;
1214}
1215
Chris Bagwell16bf2882012-03-25 23:26:20 -07001216static void wacom_wireless_work(struct work_struct *work)
1217{
1218 struct wacom *wacom = container_of(work, struct wacom, work);
1219 struct usb_device *usbdev = wacom->usbdev;
1220 struct wacom_wac *wacom_wac = &wacom->wacom_wac;
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001221 struct hid_device *hdev1, *hdev2;
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001222 struct wacom *wacom1, *wacom2;
1223 struct wacom_wac *wacom_wac1, *wacom_wac2;
1224 int error;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001225
1226 /*
1227 * Regardless if this is a disconnect or a new tablet,
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001228 * remove any existing input and battery devices.
Chris Bagwell16bf2882012-03-25 23:26:20 -07001229 */
1230
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001231 wacom_destroy_battery(wacom);
1232
Chris Bagwell16bf2882012-03-25 23:26:20 -07001233 /* Stylus interface */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001234 hdev1 = usb_get_intfdata(usbdev->config->interface[1]);
1235 wacom1 = hid_get_drvdata(hdev1);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001236 wacom_wac1 = &(wacom1->wacom_wac);
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001237 wacom_clean_inputs(wacom1);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001238
1239 /* Touch interface */
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001240 hdev2 = usb_get_intfdata(usbdev->config->interface[2]);
1241 wacom2 = hid_get_drvdata(hdev2);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001242 wacom_wac2 = &(wacom2->wacom_wac);
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001243 wacom_clean_inputs(wacom2);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001244
1245 if (wacom_wac->pid == 0) {
Benjamin Tissoirese2114ce2014-07-24 13:01:56 -07001246 hid_info(wacom->hdev, "wireless tablet disconnected\n");
Benjamin Tissoiresac8d1012014-07-25 17:29:48 -07001247 wacom_wac1->shared->type = 0;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001248 } else {
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001249 const struct hid_device_id *id = wacom_ids;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001250
Benjamin Tissoirese2114ce2014-07-24 13:01:56 -07001251 hid_info(wacom->hdev, "wireless tablet connected with PID %x\n",
Dmitry Torokhoveb71d1b2012-05-02 00:13:38 -07001252 wacom_wac->pid);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001253
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001254 while (id->bus) {
1255 if (id->vendor == USB_VENDOR_ID_WACOM &&
1256 id->product == wacom_wac->pid)
Chris Bagwell16bf2882012-03-25 23:26:20 -07001257 break;
1258 id++;
1259 }
1260
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001261 if (!id->bus) {
Benjamin Tissoirese2114ce2014-07-24 13:01:56 -07001262 hid_info(wacom->hdev, "ignoring unknown PID.\n");
Chris Bagwell16bf2882012-03-25 23:26:20 -07001263 return;
1264 }
1265
1266 /* Stylus interface */
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001267 wacom_wac1->features =
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001268 *((struct wacom_features *)id->driver_data);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001269 wacom_wac1->features.device_type = BTN_TOOL_PEN;
Ping Cheng57bcfce2013-10-15 23:44:00 -07001270 snprintf(wacom_wac1->name, WACOM_NAME_MAX, "%s (WL) Pen",
1271 wacom_wac1->features.name);
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001272 snprintf(wacom_wac1->pad_name, WACOM_NAME_MAX, "%s (WL) Pad",
1273 wacom_wac1->features.name);
Ping Cheng961794a2013-12-05 12:54:53 -08001274 wacom_wac1->shared->touch_max = wacom_wac1->features.touch_max;
1275 wacom_wac1->shared->type = wacom_wac1->features.type;
Ping Cheng912ca212014-09-10 12:41:31 -07001276 wacom_wac1->pid = wacom_wac->pid;
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001277 error = wacom_allocate_inputs(wacom1) ||
1278 wacom_register_inputs(wacom1);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001279 if (error)
Ping Cheng57bcfce2013-10-15 23:44:00 -07001280 goto fail;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001281
1282 /* Touch interface */
Ping Chengb5fd2a32013-11-25 18:44:55 -08001283 if (wacom_wac1->features.touch_max ||
1284 wacom_wac1->features.type == INTUOSHT) {
Ping Cheng57bcfce2013-10-15 23:44:00 -07001285 wacom_wac2->features =
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001286 *((struct wacom_features *)id->driver_data);
Ping Cheng57bcfce2013-10-15 23:44:00 -07001287 wacom_wac2->features.pktlen = WACOM_PKGLEN_BBTOUCH3;
1288 wacom_wac2->features.device_type = BTN_TOOL_FINGER;
1289 wacom_wac2->features.x_max = wacom_wac2->features.y_max = 4096;
1290 if (wacom_wac2->features.touch_max)
1291 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1292 "%s (WL) Finger",wacom_wac2->features.name);
1293 else
1294 snprintf(wacom_wac2->name, WACOM_NAME_MAX,
1295 "%s (WL) Pad",wacom_wac2->features.name);
Benjamin Tissoires008f4d92014-07-24 12:51:26 -07001296 snprintf(wacom_wac2->pad_name, WACOM_NAME_MAX,
1297 "%s (WL) Pad", wacom_wac2->features.name);
Ping Cheng912ca212014-09-10 12:41:31 -07001298 wacom_wac2->pid = wacom_wac->pid;
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001299 error = wacom_allocate_inputs(wacom2) ||
1300 wacom_register_inputs(wacom2);
Ping Cheng57bcfce2013-10-15 23:44:00 -07001301 if (error)
1302 goto fail;
Ping Cheng961794a2013-12-05 12:54:53 -08001303
1304 if (wacom_wac1->features.type == INTUOSHT &&
1305 wacom_wac1->features.touch_max)
1306 wacom_wac->shared->touch_input = wacom_wac2->input;
Ping Cheng57bcfce2013-10-15 23:44:00 -07001307 }
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001308
1309 error = wacom_initialize_battery(wacom);
1310 if (error)
Ping Cheng57bcfce2013-10-15 23:44:00 -07001311 goto fail;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001312 }
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001313
1314 return;
1315
Ping Cheng57bcfce2013-10-15 23:44:00 -07001316fail:
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001317 wacom_clean_inputs(wacom1);
1318 wacom_clean_inputs(wacom2);
Chris Bagwellb7af2bb2012-06-12 00:25:23 -07001319 return;
Chris Bagwell16bf2882012-03-25 23:26:20 -07001320}
1321
Ping Cheng401d7d12013-07-28 00:38:54 -07001322/*
1323 * Not all devices report physical dimensions from HID.
1324 * Compute the default from hardcoded logical dimension
1325 * and resolution before driver overwrites them.
1326 */
1327static void wacom_set_default_phy(struct wacom_features *features)
1328{
1329 if (features->x_resolution) {
1330 features->x_phy = (features->x_max * 100) /
1331 features->x_resolution;
1332 features->y_phy = (features->y_max * 100) /
1333 features->y_resolution;
1334 }
1335}
1336
1337static void wacom_calculate_res(struct wacom_features *features)
1338{
1339 features->x_resolution = wacom_calc_hid_res(features->x_max,
1340 features->x_phy,
1341 features->unit,
1342 features->unitExpo);
1343 features->y_resolution = wacom_calc_hid_res(features->y_max,
1344 features->y_phy,
1345 features->unit,
1346 features->unitExpo);
1347}
1348
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07001349static int wacom_hid_report_len(struct hid_report *report)
1350{
1351 /* equivalent to DIV_ROUND_UP(report->size, 8) + !!(report->id > 0) */
1352 return ((report->size - 1) >> 3) + 1 + (report->id > 0);
1353}
1354
1355static size_t wacom_compute_pktlen(struct hid_device *hdev)
1356{
1357 struct hid_report_enum *report_enum;
1358 struct hid_report *report;
1359 size_t size = 0;
1360
1361 report_enum = hdev->report_enum + HID_INPUT_REPORT;
1362
1363 list_for_each_entry(report, &report_enum->report_list, list) {
1364 size_t report_size = wacom_hid_report_len(report);
1365 if (report_size > size)
1366 size = report_size;
1367 }
1368
1369 return size;
1370}
1371
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001372static int wacom_probe(struct hid_device *hdev,
1373 const struct hid_device_id *id)
Ping Cheng3bea7332006-07-13 18:01:36 -07001374{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001375 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
Ping Cheng3bea7332006-07-13 18:01:36 -07001376 struct usb_device *dev = interface_to_usbdev(intf);
Ping Cheng3bea7332006-07-13 18:01:36 -07001377 struct wacom *wacom;
1378 struct wacom_wac *wacom_wac;
Jason Childse33da8a2010-02-17 22:38:31 -08001379 struct wacom_features *features;
Jason Childse33da8a2010-02-17 22:38:31 -08001380 int error;
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001381 unsigned int connect_mask = HID_CONNECT_HIDRAW;
Ping Cheng3bea7332006-07-13 18:01:36 -07001382
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001383 if (!id->driver_data)
Bastian Blankb036f6f2010-02-10 23:06:23 -08001384 return -EINVAL;
1385
Benjamin Tissoires8ffffd52014-09-16 16:56:39 -04001386 hdev->quirks |= HID_QUIRK_NO_INIT_REPORTS;
1387
Ping Cheng3bea7332006-07-13 18:01:36 -07001388 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
Dan Carpenterf1823942012-03-29 22:38:11 -07001389 if (!wacom)
1390 return -ENOMEM;
Ping Cheng3bea7332006-07-13 18:01:36 -07001391
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001392 hid_set_drvdata(hdev, wacom);
1393 wacom->hdev = hdev;
1394
Benjamin Tissoiresba9a3542014-07-24 12:58:45 -07001395 /* ask for the report descriptor to be loaded by HID */
1396 error = hid_parse(hdev);
1397 if (error) {
1398 hid_err(hdev, "parse failed\n");
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001399 goto fail_parse;
Benjamin Tissoiresba9a3542014-07-24 12:58:45 -07001400 }
1401
Dmitry Torokhov51269fe2010-03-19 22:18:15 -07001402 wacom_wac = &wacom->wacom_wac;
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001403 wacom_wac->features = *((struct wacom_features *)id->driver_data);
Jason Childse33da8a2010-02-17 22:38:31 -08001404 features = &wacom_wac->features;
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07001405 features->pktlen = wacom_compute_pktlen(hdev);
Jason Childse33da8a2010-02-17 22:38:31 -08001406 if (features->pktlen > WACOM_PKGLEN_MAX) {
1407 error = -EINVAL;
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001408 goto fail_pktlen;
Jason Childse33da8a2010-02-17 22:38:31 -08001409 }
1410
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001411 if (features->check_for_hid_type && features->hid_type != hdev->type) {
1412 error = -ENODEV;
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001413 goto fail_type;
Jason Childse33da8a2010-02-17 22:38:31 -08001414 }
Ping Cheng3bea7332006-07-13 18:01:36 -07001415
Ping Cheng3bea7332006-07-13 18:01:36 -07001416 wacom->usbdev = dev;
Oliver Neukume7224092008-04-15 01:31:57 -04001417 wacom->intf = intf;
1418 mutex_init(&wacom->lock);
Chris Bagwell16bf2882012-03-25 23:26:20 -07001419 INIT_WORK(&wacom->work, wacom_wireless_work);
Ping Cheng3bea7332006-07-13 18:01:36 -07001420
Benjamin Tissoires494078b2014-09-23 12:08:07 -04001421 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
1422 error = wacom_allocate_inputs(wacom);
1423 if (error)
1424 goto fail_allocate_inputs;
1425 }
1426
Ping Cheng401d7d12013-07-28 00:38:54 -07001427 /* set the default size in case we do not get them from hid */
1428 wacom_set_default_phy(features);
1429
Ping Chengf393ee22012-04-29 21:09:17 -07001430 /* Retrieve the physical and logical size for touch devices */
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -07001431 wacom_retrieve_hid_descriptor(hdev, features);
Ping Cheng545f4e92008-11-24 11:44:27 -05001432
Jason Gereckeae584ca2012-04-03 15:50:40 -07001433 /*
1434 * Intuos5 has no useful data about its touch interface in its
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07001435 * HID descriptor. If this is the touch interface (PacketSize
Jason Gereckeae584ca2012-04-03 15:50:40 -07001436 * of WACOM_PKGLEN_BBTOUCH3), override the table values.
1437 */
Ping Chengb5fd2a32013-11-25 18:44:55 -08001438 if (features->type >= INTUOS5S && features->type <= INTUOSHT) {
Benjamin Tissoires01c846f2014-07-24 12:59:11 -07001439 if (features->pktlen == WACOM_PKGLEN_BBTOUCH3) {
Jason Gereckeae584ca2012-04-03 15:50:40 -07001440 features->device_type = BTN_TOOL_FINGER;
Jason Gereckeae584ca2012-04-03 15:50:40 -07001441
Jason Gereckeae584ca2012-04-03 15:50:40 -07001442 features->x_max = 4096;
1443 features->y_max = 4096;
1444 } else {
1445 features->device_type = BTN_TOOL_PEN;
1446 }
1447 }
1448
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -07001449 /*
1450 * Same thing for Bamboo 3rd gen.
1451 */
1452 if ((features->type == BAMBOO_PT) &&
1453 (features->pktlen == WACOM_PKGLEN_BBTOUCH3) &&
1454 (features->device_type == BTN_TOOL_PEN)) {
1455 features->device_type = BTN_TOOL_FINGER;
1456
1457 features->x_max = 4096;
1458 features->y_max = 4096;
1459 }
1460
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001461 if (hdev->bus == BUS_BLUETOOTH)
1462 features->quirks |= WACOM_QUIRK_BATTERY;
1463
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07001464 wacom_setup_device_quirks(features);
1465
Ping Cheng401d7d12013-07-28 00:38:54 -07001466 /* set unit to "100th of a mm" for devices not reported by HID */
1467 if (!features->unit) {
1468 features->unit = 0x11;
Benjamin Tissoiresc669fb22014-07-24 13:02:14 -07001469 features->unitExpo = -3;
Ping Cheng401d7d12013-07-28 00:38:54 -07001470 }
1471 wacom_calculate_res(features);
1472
Ping Cheng49b764a2010-02-20 00:53:49 -08001473 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
Benjamin Tissoiresd2d13f12014-07-24 12:48:28 -07001474 snprintf(wacom_wac->pad_name, sizeof(wacom_wac->pad_name),
1475 "%s Pad", features->name);
Ping Cheng49b764a2010-02-20 00:53:49 -08001476
Henrik Rydbergbc73dd32010-09-05 12:26:16 -07001477 if (features->quirks & WACOM_QUIRK_MULTI_INPUT) {
Ping Cheng49b764a2010-02-20 00:53:49 -08001478 /* Append the device type to the name */
Ping Cheng57bcfce2013-10-15 23:44:00 -07001479 if (features->device_type != BTN_TOOL_FINGER)
1480 strlcat(wacom_wac->name, " Pen", WACOM_NAME_MAX);
1481 else if (features->touch_max)
1482 strlcat(wacom_wac->name, " Finger", WACOM_NAME_MAX);
1483 else
1484 strlcat(wacom_wac->name, " Pad", WACOM_NAME_MAX);
Ping Cheng4492eff2010-03-19 22:18:15 -07001485
Benjamin Tissoires4451e082014-07-24 13:01:05 -07001486 error = wacom_add_shared_data(hdev);
Ping Cheng4492eff2010-03-19 22:18:15 -07001487 if (error)
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001488 goto fail_shared_data;
Ping Cheng49b764a2010-02-20 00:53:49 -08001489 }
1490
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001491 if (!(features->quirks & WACOM_QUIRK_MONITOR) &&
1492 (features->quirks & WACOM_QUIRK_BATTERY)) {
1493 error = wacom_initialize_battery(wacom);
1494 if (error)
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001495 goto fail_battery;
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001496 }
1497
Chris Bagwelld3825d52012-03-25 23:26:11 -07001498 if (!(features->quirks & WACOM_QUIRK_NO_INPUT)) {
Benjamin Tissoires494078b2014-09-23 12:08:07 -04001499 error = wacom_register_inputs(wacom);
Chris Bagwelld3825d52012-03-25 23:26:11 -07001500 if (error)
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001501 goto fail_register_inputs;
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001502 }
1503
1504 if (hdev->bus == BUS_BLUETOOTH) {
1505 error = device_create_file(&hdev->dev, &dev_attr_speed);
1506 if (error)
1507 hid_warn(hdev,
1508 "can't create sysfs speed attribute err: %d\n",
1509 error);
Chris Bagwelld3825d52012-03-25 23:26:11 -07001510 }
Eduard Hasenleithner5d7e7d42011-09-07 14:08:54 -07001511
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001512 if (features->type == HID_GENERIC)
1513 connect_mask |= HID_CONNECT_DRIVER;
1514
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001515 /* Regular HID work starts now */
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001516 error = hid_hw_start(hdev, connect_mask);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001517 if (error) {
1518 hid_err(hdev, "hw start failed\n");
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001519 goto fail_hw_start;
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001520 }
1521
Benjamin Tissoires5ae6e892014-09-23 12:08:09 -04001522 /* Note that if query fails it is not a hard failure */
1523 wacom_query_tablet_data(hdev, features);
1524
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001525 if (features->quirks & WACOM_QUIRK_MONITOR)
1526 error = hid_hw_open(hdev);
1527
Ping Cheng961794a2013-12-05 12:54:53 -08001528 if (wacom_wac->features.type == INTUOSHT && wacom_wac->features.touch_max) {
1529 if (wacom_wac->features.device_type == BTN_TOOL_FINGER)
1530 wacom_wac->shared->touch_input = wacom_wac->input;
1531 }
1532
Ping Cheng3bea7332006-07-13 18:01:36 -07001533 return 0;
1534
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001535fail_hw_start:
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001536 if (hdev->bus == BUS_BLUETOOTH)
1537 device_remove_file(&hdev->dev, &dev_attr_speed);
1538fail_register_inputs:
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001539 wacom_clean_inputs(wacom);
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001540 wacom_destroy_battery(wacom);
1541fail_battery:
1542 wacom_remove_shared_data(wacom_wac);
1543fail_shared_data:
Benjamin Tissoires494078b2014-09-23 12:08:07 -04001544 wacom_clean_inputs(wacom);
1545fail_allocate_inputs:
Benjamin Tissoires7fefeec2014-09-23 12:08:05 -04001546fail_type:
1547fail_pktlen:
1548fail_parse:
1549 kfree(wacom);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001550 hid_set_drvdata(hdev, NULL);
Dmitry Torokhov50141862007-04-12 01:33:39 -04001551 return error;
Ping Cheng3bea7332006-07-13 18:01:36 -07001552}
1553
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001554static void wacom_remove(struct hid_device *hdev)
Ping Cheng3bea7332006-07-13 18:01:36 -07001555{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001556 struct wacom *wacom = hid_get_drvdata(hdev);
Ping Cheng3bea7332006-07-13 18:01:36 -07001557
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001558 hid_hw_stop(hdev);
Oliver Neukume7224092008-04-15 01:31:57 -04001559
Chris Bagwell16bf2882012-03-25 23:26:20 -07001560 cancel_work_sync(&wacom->work);
Benjamin Tissoires2546dac2014-09-23 12:08:06 -04001561 wacom_clean_inputs(wacom);
Benjamin Tissoiresf81a1292014-08-06 13:48:01 -07001562 if (hdev->bus == BUS_BLUETOOTH)
1563 device_remove_file(&hdev->dev, &dev_attr_speed);
Chris Bagwella1d552c2012-03-25 23:26:30 -07001564 wacom_destroy_battery(wacom);
Dmitry Torokhov51269fe2010-03-19 22:18:15 -07001565 wacom_remove_shared_data(&wacom->wacom_wac);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001566
1567 hid_set_drvdata(hdev, NULL);
Oliver Neukume7224092008-04-15 01:31:57 -04001568 kfree(wacom);
1569}
1570
Geert Uytterhoeven41a74582014-08-11 11:03:19 -07001571#ifdef CONFIG_PM
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001572static int wacom_resume(struct hid_device *hdev)
Oliver Neukume7224092008-04-15 01:31:57 -04001573{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001574 struct wacom *wacom = hid_get_drvdata(hdev);
1575 struct wacom_features *features = &wacom->wacom_wac.features;
Oliver Neukume7224092008-04-15 01:31:57 -04001576
1577 mutex_lock(&wacom->lock);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001578
1579 /* switch to wacom mode first */
Benjamin Tissoires27b20a92014-07-24 12:56:22 -07001580 wacom_query_tablet_data(hdev, features);
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001581 wacom_led_control(wacom);
1582
Oliver Neukume7224092008-04-15 01:31:57 -04001583 mutex_unlock(&wacom->lock);
1584
1585 return 0;
1586}
1587
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001588static int wacom_reset_resume(struct hid_device *hdev)
Oliver Neukume7224092008-04-15 01:31:57 -04001589{
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001590 return wacom_resume(hdev);
Oliver Neukume7224092008-04-15 01:31:57 -04001591}
Geert Uytterhoeven41a74582014-08-11 11:03:19 -07001592#endif /* CONFIG_PM */
Oliver Neukume7224092008-04-15 01:31:57 -04001593
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001594static struct hid_driver wacom_driver = {
Ping Cheng3bea7332006-07-13 18:01:36 -07001595 .name = "wacom",
Bastian Blankb036f6f2010-02-10 23:06:23 -08001596 .id_table = wacom_ids,
Ping Cheng3bea7332006-07-13 18:01:36 -07001597 .probe = wacom_probe,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001598 .remove = wacom_remove,
Benjamin Tissoires7704ac92014-09-23 12:08:08 -04001599 .event = wacom_wac_event,
1600 .report = wacom_wac_report,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001601#ifdef CONFIG_PM
Oliver Neukume7224092008-04-15 01:31:57 -04001602 .resume = wacom_resume,
1603 .reset_resume = wacom_reset_resume,
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001604#endif
1605 .raw_event = wacom_raw_event,
Ping Cheng3bea7332006-07-13 18:01:36 -07001606};
Benjamin Tissoires29b47392014-07-24 12:52:23 -07001607module_hid_driver(wacom_driver);
Benjamin Tissoiresf2e0a7d2014-08-06 14:07:49 -07001608
1609MODULE_VERSION(DRIVER_VERSION);
1610MODULE_AUTHOR(DRIVER_AUTHOR);
1611MODULE_DESCRIPTION(DRIVER_DESC);
1612MODULE_LICENSE(DRIVER_LICENSE);