Blame view

drivers/hid/hid-wacom.c 15.3 KB
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
1
2
3
4
5
6
7
8
9
10
11
  /*
   *  Bluetooth Wacom Tablet support
   *
   *  Copyright (c) 1999 Andreas Gal
   *  Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
   *  Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
   *  Copyright (c) 2006-2007 Jiri Kosina
   *  Copyright (c) 2007 Paul Walmsley
   *  Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
   *  Copyright (c) 2006 Andrew Zabolotny <zap@homelink.ru>
   *  Copyright (c) 2009 Bastien Nocera <hadess@hadess.net>
78761ff9b   Przemo Firszt   HID: wacom: Initi...
12
   *  Copyright (c) 2011 Przemysław Firszt <przemo@firszt.eu>
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
13
14
15
16
17
18
19
20
   */
  
  /*
   * This program is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License as published by the Free
   * Software Foundation; either version 2 of the License, or (at your option)
   * any later version.
   */
4291ee305   Joe Perches   HID: Add and use ...
21
  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
22
23
24
  #include <linux/device.h>
  #include <linux/hid.h>
  #include <linux/module.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
25
  #include <linux/slab.h>
59d2334ac   Przemo Firszt   HID: expose wacom...
26
27
28
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  #include <linux/power_supply.h>
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
29
30
31
32
33
34
  
  #include "hid-ids.h"
  
  struct wacom_data {
  	__u16 tool;
  	unsigned char butstate;
78761ff9b   Przemo Firszt   HID: wacom: Initi...
35
  	__u8 features;
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
36
  	unsigned char high_speed;
59d2334ac   Przemo Firszt   HID: expose wacom...
37
38
39
40
41
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  	int battery_capacity;
  	struct power_supply battery;
  	struct power_supply ac;
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
42
  };
59d2334ac   Przemo Firszt   HID: expose wacom...
43
44
45
46
47
48
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  /*percent of battery capacity, 0 means AC online*/
  static unsigned short batcap[8] = { 1, 15, 25, 35, 50, 70, 100, 0 };
  
  static enum power_supply_property wacom_battery_props[] = {
  	POWER_SUPPLY_PROP_PRESENT,
73db88137   Jeremy Fitzhardinge   power_supply: add...
49
50
  	POWER_SUPPLY_PROP_CAPACITY,
  	POWER_SUPPLY_PROP_SCOPE,
59d2334ac   Przemo Firszt   HID: expose wacom...
51
52
53
54
  };
  
  static enum power_supply_property wacom_ac_props[] = {
  	POWER_SUPPLY_PROP_PRESENT,
73db88137   Jeremy Fitzhardinge   power_supply: add...
55
56
  	POWER_SUPPLY_PROP_ONLINE,
  	POWER_SUPPLY_PROP_SCOPE,
59d2334ac   Przemo Firszt   HID: expose wacom...
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  };
  
  static int wacom_battery_get_property(struct power_supply *psy,
  				enum power_supply_property psp,
  				union power_supply_propval *val)
  {
  	struct wacom_data *wdata = container_of(psy,
  					struct wacom_data, battery);
  	int power_state = batcap[wdata->battery_capacity];
  	int ret = 0;
  
  	switch (psp) {
  	case POWER_SUPPLY_PROP_PRESENT:
  		val->intval = 1;
  		break;
73db88137   Jeremy Fitzhardinge   power_supply: add...
72
73
74
  	case POWER_SUPPLY_PROP_SCOPE:
  		val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  		break;
59d2334ac   Przemo Firszt   HID: expose wacom...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  	case POWER_SUPPLY_PROP_CAPACITY:
  		/* show 100% battery capacity when charging */
  		if (power_state == 0)
  			val->intval = 100;
  		else
  			val->intval = power_state;
  		break;
  	default:
  		ret = -EINVAL;
  		break;
  	}
  	return ret;
  }
  
  static int wacom_ac_get_property(struct power_supply *psy,
  				enum power_supply_property psp,
  				union power_supply_propval *val)
  {
  	struct wacom_data *wdata = container_of(psy, struct wacom_data, ac);
  	int power_state = batcap[wdata->battery_capacity];
  	int ret = 0;
  
  	switch (psp) {
  	case POWER_SUPPLY_PROP_PRESENT:
  		/* fall through */
  	case POWER_SUPPLY_PROP_ONLINE:
  		if (power_state == 0)
  			val->intval = 1;
  		else
  			val->intval = 0;
  		break;
73db88137   Jeremy Fitzhardinge   power_supply: add...
106
107
108
  	case POWER_SUPPLY_PROP_SCOPE:
  		val->intval = POWER_SUPPLY_SCOPE_DEVICE;
  		break;
59d2334ac   Przemo Firszt   HID: expose wacom...
109
110
111
112
113
114
115
  	default:
  		ret = -EINVAL;
  		break;
  	}
  	return ret;
  }
  #endif
78761ff9b   Przemo Firszt   HID: wacom: Initi...
116
117
118
119
120
121
122
123
124
125
126
127
  static void wacom_set_features(struct hid_device *hdev)
  {
  	int ret;
  	__u8 rep_data[2];
  
  	/*set high speed, tablet mode*/
  	rep_data[0] = 0x03;
  	rep_data[1] = 0x20;
  	ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  				HID_FEATURE_REPORT);
  	return;
  }
06c7c313b   Przemo Firszt   HID: separate mod...
128
129
  static void wacom_poke(struct hid_device *hdev, u8 speed)
  {
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
130
  	struct wacom_data *wdata = hid_get_drvdata(hdev);
06c7c313b   Przemo Firszt   HID: separate mod...
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  	int limit, ret;
  	char rep_data[2];
  
  	rep_data[0] = 0x03 ; rep_data[1] = 0x00;
  	limit = 3;
  	do {
  		ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  				HID_FEATURE_REPORT);
  	} while (ret < 0 && limit-- > 0);
  
  	if (ret >= 0) {
  		if (speed == 0)
  			rep_data[0] = 0x05;
  		else
  			rep_data[0] = 0x06;
  
  		rep_data[1] = 0x00;
  		limit = 3;
  		do {
  			ret = hdev->hid_output_raw_report(hdev, rep_data, 2,
  					HID_FEATURE_REPORT);
  		} while (ret < 0 && limit-- > 0);
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
153
154
  		if (ret >= 0) {
  			wdata->high_speed = speed;
06c7c313b   Przemo Firszt   HID: separate mod...
155
  			return;
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
156
  		}
06c7c313b   Przemo Firszt   HID: separate mod...
157
158
159
160
161
162
  	}
  
  	/*
  	 * Note that if the raw queries fail, it's not a hard failure and it
  	 * is safe to continue
  	 */
4291ee305   Joe Perches   HID: Add and use ...
163
164
165
  	hid_warn(hdev, "failed to poke device, command %d, err %d
  ",
  		 rep_data[0], ret);
06c7c313b   Przemo Firszt   HID: separate mod...
166
167
  	return;
  }
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
  static ssize_t wacom_show_speed(struct device *dev,
  				struct device_attribute
  				*attr, char *buf)
  {
  	struct wacom_data *wdata = dev_get_drvdata(dev);
  
  	return snprintf(buf, PAGE_SIZE, "%i
  ", wdata->high_speed);
  }
  
  static ssize_t wacom_store_speed(struct device *dev,
  				struct device_attribute *attr,
  				const char *buf, size_t count)
  {
  	struct hid_device *hdev = container_of(dev, struct hid_device, dev);
  	int new_speed;
  
  	if (sscanf(buf, "%1d", &new_speed ) != 1)
  		return -EINVAL;
  
  	if (new_speed == 0 || new_speed == 1) {
  		wacom_poke(hdev, new_speed);
  		return strnlen(buf, PAGE_SIZE);
  	} else
  		return -EINVAL;
  }
edd2126aa   Jiri Kosina   HID: wacom: make ...
194
  static DEVICE_ATTR(speed, S_IRUGO | S_IWUSR | S_IWGRP,
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
195
  		wacom_show_speed, wacom_store_speed);
f6b7efc16   Przemo Firszt   HID: wacom: Move ...
196
197
198
  static int wacom_gr_parse_report(struct hid_device *hdev,
  			struct wacom_data *wdata,
  			struct input_dev *input, unsigned char *data)
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
199
  {
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
200
  	int tool, x, y, rw;
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
201
  	tool = 0;
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
  	/* Get X & Y positions */
  	x = le16_to_cpu(*(__le16 *) &data[2]);
  	y = le16_to_cpu(*(__le16 *) &data[4]);
  
  	/* Get current tool identifier */
  	if (data[1] & 0x90) { /* If pen is in the in/active area */
  		switch ((data[1] >> 5) & 3) {
  		case 0:	/* Pen */
  			tool = BTN_TOOL_PEN;
  			break;
  
  		case 1: /* Rubber */
  			tool = BTN_TOOL_RUBBER;
  			break;
  
  		case 2: /* Mouse with wheel */
  		case 3: /* Mouse without wheel */
  			tool = BTN_TOOL_MOUSE;
  			break;
  		}
  
  		/* Reset tool if out of active tablet area */
  		if (!(data[1] & 0x10))
  			tool = 0;
  	}
  
  	/* If tool changed, notify input subsystem */
  	if (wdata->tool != tool) {
  		if (wdata->tool) {
  			/* Completely reset old tool state */
  			if (wdata->tool == BTN_TOOL_MOUSE) {
  				input_report_key(input, BTN_LEFT, 0);
  				input_report_key(input, BTN_RIGHT, 0);
  				input_report_key(input, BTN_MIDDLE, 0);
  				input_report_abs(input, ABS_DISTANCE,
987a6c029   Daniel Mack   Input: switch to ...
237
  					input_abs_get_max(input, ABS_DISTANCE));
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
  			} else {
  				input_report_key(input, BTN_TOUCH, 0);
  				input_report_key(input, BTN_STYLUS, 0);
  				input_report_key(input, BTN_STYLUS2, 0);
  				input_report_abs(input, ABS_PRESSURE, 0);
  			}
  			input_report_key(input, wdata->tool, 0);
  			input_sync(input);
  		}
  		wdata->tool = tool;
  		if (tool)
  			input_report_key(input, tool, 1);
  	}
  
  	if (tool) {
  		input_report_abs(input, ABS_X, x);
  		input_report_abs(input, ABS_Y, y);
  
  		switch ((data[1] >> 5) & 3) {
  		case 2: /* Mouse with wheel */
  			input_report_key(input, BTN_MIDDLE, data[1] & 0x04);
  			rw = (data[6] & 0x01) ? -1 :
  				(data[6] & 0x02) ? 1 : 0;
  			input_report_rel(input, REL_WHEEL, rw);
  			/* fall through */
  
  		case 3: /* Mouse without wheel */
  			input_report_key(input, BTN_LEFT, data[1] & 0x01);
  			input_report_key(input, BTN_RIGHT, data[1] & 0x02);
  			/* Compute distance between mouse and tablet */
  			rw = 44 - (data[6] >> 2);
  			if (rw < 0)
  				rw = 0;
  			else if (rw > 31)
  				rw = 31;
  			input_report_abs(input, ABS_DISTANCE, rw);
  			break;
  
  		default:
  			input_report_abs(input, ABS_PRESSURE,
  					data[6] | (((__u16) (data[1] & 0x08)) << 5));
  			input_report_key(input, BTN_TOUCH, data[1] & 0x01);
  			input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  			input_report_key(input, BTN_STYLUS2, (tool == BTN_TOOL_PEN) && data[1] & 0x04);
  			break;
  		}
  
  		input_sync(input);
  	}
  
  	/* Report the state of the two buttons at the top of the tablet
  	 * as two extra fingerpad keys (buttons 4 & 5). */
  	rw = data[7] & 0x03;
  	if (rw != wdata->butstate) {
  		wdata->butstate = rw;
  		input_report_key(input, BTN_0, rw & 0x02);
  		input_report_key(input, BTN_1, rw & 0x01);
0e253fdb3   Przemo Firszt   HID: wacom: Add B...
295
  		input_report_key(input, BTN_TOOL_FINGER, 0xf0);
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
296
297
298
  		input_event(input, EV_MSC, MSC_SERIAL, 0xf0);
  		input_sync(input);
  	}
59d2334ac   Przemo Firszt   HID: expose wacom...
299
300
301
302
303
304
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  	/* Store current battery capacity */
  	rw = (data[7] >> 2 & 0x07);
  	if (rw != wdata->battery_capacity)
  		wdata->battery_capacity = rw;
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
305
306
  	return 1;
  }
78761ff9b   Przemo Firszt   HID: wacom: Initi...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
  
  static void wacom_i4_parse_pen_report(struct wacom_data *wdata,
  			struct input_dev *input, unsigned char *data)
  {
  	__u16 x, y, pressure;
  	__u32 id;
  
  	switch (data[1]) {
  	case 0x80: /* Out of proximity report */
  		wdata->tool = 0;
  		input_report_key(input, BTN_TOUCH, 0);
  		input_report_abs(input, ABS_PRESSURE, 0);
  		input_report_key(input, wdata->tool, 0);
  		input_sync(input);
  		break;
  	case 0xC2: /* Tool report */
  		id = ((data[2] << 4) | (data[3] >> 4) |
  			((data[7] & 0x0f) << 20) |
  			((data[8] & 0xf0) << 12)) & 0xfffff;
  
  		switch (id) {
  		case 0x802:
  			wdata->tool = BTN_TOOL_PEN;
  			break;
  		case 0x80A:
  			wdata->tool = BTN_TOOL_RUBBER;
  			break;
  		}
  		break;
  	default: /* Position/pressure report */
  		x = data[2] << 9 | data[3] << 1 | ((data[9] & 0x02) >> 1);
  		y = data[4] << 9 | data[5] << 1 | (data[9] & 0x01);
  		pressure = (data[6] << 3) | ((data[7] & 0xC0) >> 5)
  			| (data[1] & 0x01);
  
  		input_report_key(input, BTN_TOUCH, pressure > 1);
  
  		input_report_key(input, BTN_STYLUS, data[1] & 0x02);
  		input_report_key(input, BTN_STYLUS2, data[1] & 0x04);
  		input_report_key(input, wdata->tool, 1);
  		input_report_abs(input, ABS_X, x);
  		input_report_abs(input, ABS_Y, y);
  		input_report_abs(input, ABS_PRESSURE, pressure);
  		input_sync(input);
  		break;
  	}
  
  	return;
  }
  
  static void wacom_i4_parse_report(struct hid_device *hdev,
  			struct wacom_data *wdata,
  			struct input_dev *input, unsigned char *data)
  {
  	switch (data[0]) {
  	case 0x00: /* Empty report */
  		break;
  	case 0x02: /* Pen report */
  		wacom_i4_parse_pen_report(wdata, input, data);
  		break;
  	case 0x03: /* Features Report */
  		wdata->features = data[2];
  		break;
  	case 0x0C: /* Button report */
  		break;
  	default:
  		hid_err(hdev, "Unknown report: %d,%d
  ", data[0], data[1]);
  		break;
  	}
  }
f6b7efc16   Przemo Firszt   HID: wacom: Move ...
378
379
380
381
382
383
384
  static int wacom_raw_event(struct hid_device *hdev, struct hid_report *report,
  		u8 *raw_data, int size)
  {
  	struct wacom_data *wdata = hid_get_drvdata(hdev);
  	struct hid_input *hidinput;
  	struct input_dev *input;
  	unsigned char *data = (unsigned char *) raw_data;
78761ff9b   Przemo Firszt   HID: wacom: Initi...
385
  	int i;
f6b7efc16   Przemo Firszt   HID: wacom: Move ...
386
387
388
389
390
391
392
393
394
395
  
  	if (!(hdev->claimed & HID_CLAIMED_INPUT))
  		return 0;
  
  	hidinput = list_entry(hdev->inputs.next, struct hid_input, list);
  	input = hidinput->input;
  
  	/* Check if this is a tablet report */
  	if (data[0] != 0x03)
  		return 0;
78761ff9b   Przemo Firszt   HID: wacom: Initi...
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
  	switch (hdev->product) {
  	case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  		return wacom_gr_parse_report(hdev, wdata, input, data);
  		break;
  	case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  		i = 1;
  
  		switch (data[0]) {
  		case 0x04:
  			wacom_i4_parse_report(hdev, wdata, input, data + i);
  			i += 10;
  			/* fall through */
  		case 0x03:
  			wacom_i4_parse_report(hdev, wdata, input, data + i);
  			i += 10;
  			wacom_i4_parse_report(hdev, wdata, input, data + i);
  			break;
  		default:
  			hid_err(hdev, "Unknown report: %d,%d size:%d
  ",
  					data[0], data[1], size);
  			return 0;
  		}
  	}
  	return 1;
f6b7efc16   Przemo Firszt   HID: wacom: Move ...
421
  }
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
422

3797ef6b6   David Herrmann   HID: wacom: Set i...
423
424
425
426
427
  static int wacom_input_mapped(struct hid_device *hdev, struct hid_input *hi,
  	struct hid_field *field, struct hid_usage *usage, unsigned long **bit,
  								int *max)
  {
  	struct input_dev *input = hi->input;
f6f124278   Jiri Kosina   Merge branch 'ups...
428
  	__set_bit(INPUT_PROP_POINTER, input->propbit);
3797ef6b6   David Herrmann   HID: wacom: Set i...
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
  	/* Basics */
  	input->evbit[0] |= BIT(EV_KEY) | BIT(EV_ABS) | BIT(EV_REL);
  
  	__set_bit(REL_WHEEL, input->relbit);
  
  	__set_bit(BTN_TOOL_PEN, input->keybit);
  	__set_bit(BTN_TOUCH, input->keybit);
  	__set_bit(BTN_STYLUS, input->keybit);
  	__set_bit(BTN_STYLUS2, input->keybit);
  	__set_bit(BTN_LEFT, input->keybit);
  	__set_bit(BTN_RIGHT, input->keybit);
  	__set_bit(BTN_MIDDLE, input->keybit);
  
  	/* Pad */
  	input->evbit[0] |= BIT(EV_MSC);
  
  	__set_bit(MSC_SERIAL, input->mscbit);
  
  	__set_bit(BTN_0, input->keybit);
  	__set_bit(BTN_1, input->keybit);
  	__set_bit(BTN_TOOL_FINGER, input->keybit);
  
  	/* Distance, rubber and mouse */
  	__set_bit(BTN_TOOL_RUBBER, input->keybit);
  	__set_bit(BTN_TOOL_MOUSE, input->keybit);
78761ff9b   Przemo Firszt   HID: wacom: Initi...
454
455
456
457
458
459
460
461
462
463
464
465
466
  	switch (hdev->product) {
  	case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  		input_set_abs_params(input, ABS_X, 0, 16704, 4, 0);
  		input_set_abs_params(input, ABS_Y, 0, 12064, 4, 0);
  		input_set_abs_params(input, ABS_PRESSURE, 0, 511, 0, 0);
  		input_set_abs_params(input, ABS_DISTANCE, 0, 32, 0, 0);
  		break;
  	case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  		input_set_abs_params(input, ABS_X, 0, 40640, 4, 0);
  		input_set_abs_params(input, ABS_Y, 0, 25400, 4, 0);
  		input_set_abs_params(input, ABS_PRESSURE, 0, 2047, 0, 0);
  		break;
  	}
3797ef6b6   David Herrmann   HID: wacom: Set i...
467
468
469
  
  	return 0;
  }
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
470
471
472
  static int wacom_probe(struct hid_device *hdev,
  		const struct hid_device_id *id)
  {
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
473
474
475
476
477
  	struct wacom_data *wdata;
  	int ret;
  
  	wdata = kzalloc(sizeof(*wdata), GFP_KERNEL);
  	if (wdata == NULL) {
4291ee305   Joe Perches   HID: Add and use ...
478
479
  		hid_err(hdev, "can't alloc wacom descriptor
  ");
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
480
481
482
483
  		return -ENOMEM;
  	}
  
  	hid_set_drvdata(hdev, wdata);
46a709b90   Bastien Nocera   HID: Implement Wa...
484
  	/* Parse the HID report now */
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
485
486
  	ret = hid_parse(hdev);
  	if (ret) {
4291ee305   Joe Perches   HID: Add and use ...
487
488
  		hid_err(hdev, "parse failed
  ");
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
489
490
491
492
493
  		goto err_free;
  	}
  
  	ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
  	if (ret) {
4291ee305   Joe Perches   HID: Add and use ...
494
495
  		hid_err(hdev, "hw start failed
  ");
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
496
497
  		goto err_free;
  	}
20a3ce7e4   Przemo Firszt   HID: add sysfs sp...
498
499
  	ret = device_create_file(&hdev->dev, &dev_attr_speed);
  	if (ret)
4291ee305   Joe Perches   HID: Add and use ...
500
501
502
  		hid_warn(hdev,
  			 "can't create sysfs speed attribute err: %d
  ", ret);
342f31e84   Jiri Kosina   HID: make Wacom m...
503

78761ff9b   Przemo Firszt   HID: wacom: Initi...
504
505
506
507
508
509
510
511
512
513
  	switch (hdev->product) {
  	case USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH:
  		/* Set Wacom mode 2 with high reporting speed */
  		wacom_poke(hdev, 1);
  		break;
  	case USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH:
  		wdata->features = 0;
  		wacom_set_features(hdev);
  		break;
  	}
46a709b90   Bastien Nocera   HID: Implement Wa...
514

59d2334ac   Przemo Firszt   HID: expose wacom...
515
516
517
518
519
520
521
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  	wdata->battery.properties = wacom_battery_props;
  	wdata->battery.num_properties = ARRAY_SIZE(wacom_battery_props);
  	wdata->battery.get_property = wacom_battery_get_property;
  	wdata->battery.name = "wacom_battery";
  	wdata->battery.type = POWER_SUPPLY_TYPE_BATTERY;
  	wdata->battery.use_for_apm = 0;
46a709b90   Bastien Nocera   HID: Implement Wa...
522

35b4c01e2   Jeremy Fitzhardinge   power_supply: add...
523
  	power_supply_powers(&wdata->battery, &hdev->dev);
59d2334ac   Przemo Firszt   HID: expose wacom...
524
525
  	ret = power_supply_register(&hdev->dev, &wdata->battery);
  	if (ret) {
4291ee305   Joe Perches   HID: Add and use ...
526
527
528
  		hid_warn(hdev, "can't create sysfs battery attribute, err: %d
  ",
  			 ret);
dde58cfcc   David Herrmann   HID: wacom: Fix e...
529
  		goto err_battery;
59d2334ac   Przemo Firszt   HID: expose wacom...
530
531
532
533
534
535
536
537
  	}
  
  	wdata->ac.properties = wacom_ac_props;
  	wdata->ac.num_properties = ARRAY_SIZE(wacom_ac_props);
  	wdata->ac.get_property = wacom_ac_get_property;
  	wdata->ac.name = "wacom_ac";
  	wdata->ac.type = POWER_SUPPLY_TYPE_MAINS;
  	wdata->ac.use_for_apm = 0;
35b4c01e2   Jeremy Fitzhardinge   power_supply: add...
538
  	power_supply_powers(&wdata->battery, &hdev->dev);
59d2334ac   Przemo Firszt   HID: expose wacom...
539
540
  	ret = power_supply_register(&hdev->dev, &wdata->ac);
  	if (ret) {
4291ee305   Joe Perches   HID: Add and use ...
541
542
543
  		hid_warn(hdev,
  			 "can't create ac battery attribute, err: %d
  ", ret);
dde58cfcc   David Herrmann   HID: wacom: Fix e...
544
  		goto err_ac;
59d2334ac   Przemo Firszt   HID: expose wacom...
545
  	}
59d2334ac   Przemo Firszt   HID: expose wacom...
546
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
547
  	return 0;
987a6c029   Daniel Mack   Input: switch to ...
548

dde58cfcc   David Herrmann   HID: wacom: Fix e...
549
550
551
552
553
554
555
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  err_ac:
  	power_supply_unregister(&wdata->battery);
  err_battery:
  	device_remove_file(&hdev->dev, &dev_attr_speed);
  	hid_hw_stop(hdev);
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
556
557
558
559
560
561
562
  err_free:
  	kfree(wdata);
  	return ret;
  }
  
  static void wacom_remove(struct hid_device *hdev)
  {
59d2334ac   Przemo Firszt   HID: expose wacom...
563
564
565
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  	struct wacom_data *wdata = hid_get_drvdata(hdev);
  #endif
9086617ea   David Herrmann   HID: wacom: Unreg...
566
  	device_remove_file(&hdev->dev, &dev_attr_speed);
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
567
  	hid_hw_stop(hdev);
59d2334ac   Przemo Firszt   HID: expose wacom...
568
569
570
571
572
  
  #ifdef CONFIG_HID_WACOM_POWER_SUPPLY
  	power_supply_unregister(&wdata->battery);
  	power_supply_unregister(&wdata->ac);
  #endif
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
573
574
575
576
577
  	kfree(hid_get_drvdata(hdev));
  }
  
  static const struct hid_device_id wacom_devices[] = {
  	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) },
78761ff9b   Przemo Firszt   HID: wacom: Initi...
578
  	{ HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) },
d5e0a06f1   Jiri Kosina   Revert "HID: add ...
579

ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
580
581
582
583
584
585
586
587
588
589
  	{ }
  };
  MODULE_DEVICE_TABLE(hid, wacom_devices);
  
  static struct hid_driver wacom_driver = {
  	.name = "wacom",
  	.id_table = wacom_devices,
  	.probe = wacom_probe,
  	.remove = wacom_remove,
  	.raw_event = wacom_raw_event,
3797ef6b6   David Herrmann   HID: wacom: Set i...
590
  	.input_mapped = wacom_input_mapped,
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
591
  };
a24f423bd   Peter Huewe   HID: adding __ini...
592
  static int __init wacom_init(void)
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
593
594
595
596
597
  {
  	int ret;
  
  	ret = hid_register_driver(&wacom_driver);
  	if (ret)
4291ee305   Joe Perches   HID: Add and use ...
598
599
  		pr_err("can't register wacom driver
  ");
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
600
601
  	return ret;
  }
a24f423bd   Peter Huewe   HID: adding __ini...
602
  static void __exit wacom_exit(void)
ca2dcd40f   Bastien Nocera   HID: Wacom Graphi...
603
604
605
606
607
608
609
  {
  	hid_unregister_driver(&wacom_driver);
  }
  
  module_init(wacom_init);
  module_exit(wacom_exit);
  MODULE_LICENSE("GPL");