Blame view

drivers/input/misc/ati_remote2.c 23.6 KB
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
1
2
3
  /*
   * ati_remote2 - ATI/Philips USB RF remote driver
   *
1971b9d56   Ville Syrjala   Input: ati_remote...
4
5
   * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
   * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
6
7
8
9
10
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2
   * as published by the Free Software Foundation.
   */
ae0dadcf0   David Brownell   [PATCH] USB: move...
11
  #include <linux/usb/input.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
12
  #include <linux/slab.h>
d2d8442d0   Paul Gortmaker   drivers/input: Ad...
13
  #include <linux/module.h>
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
14
15
  
  #define DRIVER_DESC    "ATI/Philips USB RF remote driver"
1971b9d56   Ville Syrjala   Input: ati_remote...
16
  #define DRIVER_VERSION "0.3"
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
17
18
19
20
21
  
  MODULE_DESCRIPTION(DRIVER_DESC);
  MODULE_VERSION(DRIVER_VERSION);
  MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
  MODULE_LICENSE("GPL");
a1421d3c7   Peter Stokes   Input: add logica...
22
23
24
25
26
27
28
29
  /*
   * ATI Remote Wonder II Channel Configuration
   *
   * The remote control can by assigned one of sixteen "channels" in order to facilitate
   * the use of multiple remote controls within range of each other.
   * A remote's "channel" may be altered by pressing and holding the "PC" button for
   * approximately 3 seconds, after which the button will slowly flash the count of the
   * currently configured "channel", using the numeric keypad enter a number between 1 and
1971b9d56   Ville Syrjala   Input: ati_remote...
30
   * 16 and then press the "PC" button again, the button will slowly flash the count of the
a1421d3c7   Peter Stokes   Input: add logica...
31
32
   * newly configured "channel".
   */
d329e33c7   Ville Syrjala   Input: ati_remote...
33
34
35
36
  enum {
  	ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
  	ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
  };
8a49cfa9d   Ville Syrjala   Input: ati_remote...
37
  static int ati_remote2_set_mask(const char *val,
9bbb9e5a3   Rusty Russell   param: use ops in...
38
39
  				const struct kernel_param *kp,
  				unsigned int max)
8a49cfa9d   Ville Syrjala   Input: ati_remote...
40
  {
76496e7a0   JJ Ding   Input: convert ob...
41
  	unsigned int mask;
8a49cfa9d   Ville Syrjala   Input: ati_remote...
42
43
44
45
  	int ret;
  
  	if (!val)
  		return -EINVAL;
76496e7a0   JJ Ding   Input: convert ob...
46
  	ret = kstrtouint(val, 0, &mask);
8a49cfa9d   Ville Syrjala   Input: ati_remote...
47
48
49
50
51
52
53
54
55
56
57
58
  	if (ret)
  		return ret;
  
  	if (mask & ~max)
  		return -EINVAL;
  
  	*(unsigned int *)kp->arg = mask;
  
  	return 0;
  }
  
  static int ati_remote2_set_channel_mask(const char *val,
9bbb9e5a3   Rusty Russell   param: use ops in...
59
  					const struct kernel_param *kp)
8a49cfa9d   Ville Syrjala   Input: ati_remote...
60
61
62
63
64
65
  {
  	pr_debug("%s()
  ", __func__);
  
  	return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
  }
9bbb9e5a3   Rusty Russell   param: use ops in...
66
67
  static int ati_remote2_get_channel_mask(char *buffer,
  					const struct kernel_param *kp)
8a49cfa9d   Ville Syrjala   Input: ati_remote...
68
69
70
71
72
73
  {
  	pr_debug("%s()
  ", __func__);
  
  	return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
  }
9bbb9e5a3   Rusty Russell   param: use ops in...
74
75
  static int ati_remote2_set_mode_mask(const char *val,
  				     const struct kernel_param *kp)
8a49cfa9d   Ville Syrjala   Input: ati_remote...
76
77
78
79
80
81
  {
  	pr_debug("%s()
  ", __func__);
  
  	return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
  }
9bbb9e5a3   Rusty Russell   param: use ops in...
82
83
  static int ati_remote2_get_mode_mask(char *buffer,
  				     const struct kernel_param *kp)
8a49cfa9d   Ville Syrjala   Input: ati_remote...
84
85
86
87
88
89
  {
  	pr_debug("%s()
  ", __func__);
  
  	return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
  }
d329e33c7   Ville Syrjala   Input: ati_remote...
90
  static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
8a49cfa9d   Ville Syrjala   Input: ati_remote...
91
  #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
9bbb9e5a3   Rusty Russell   param: use ops in...
92
93
94
95
  static struct kernel_param_ops param_ops_channel_mask = {
  	.set = ati_remote2_set_channel_mask,
  	.get = ati_remote2_get_channel_mask,
  };
8a49cfa9d   Ville Syrjala   Input: ati_remote...
96
  module_param(channel_mask, channel_mask, 0644);
a1421d3c7   Peter Stokes   Input: add logica...
97
  MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
d329e33c7   Ville Syrjala   Input: ati_remote...
98
  static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
8a49cfa9d   Ville Syrjala   Input: ati_remote...
99
  #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
9bbb9e5a3   Rusty Russell   param: use ops in...
100
101
102
103
  static struct kernel_param_ops param_ops_mode_mask = {
  	.set = ati_remote2_set_mode_mask,
  	.get = ati_remote2_get_mode_mask,
  };
8a49cfa9d   Ville Syrjala   Input: ati_remote...
104
  module_param(mode_mask, mode_mask, 0644);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
105
106
107
108
109
110
111
  MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
  
  static struct usb_device_id ati_remote2_id_table[] = {
  	{ USB_DEVICE(0x0471, 0x0602) },	/* ATI Remote Wonder II */
  	{ }
  };
  MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
d6505ab9c   Ville Syrjala   Input: ati_remote...
112
113
114
115
116
117
  static DEFINE_MUTEX(ati_remote2_mutex);
  
  enum {
  	ATI_REMOTE2_OPENED = 0x1,
  	ATI_REMOTE2_SUSPENDED = 0x2,
  };
1971b9d56   Ville Syrjala   Input: ati_remote...
118
119
120
121
122
123
124
125
126
127
128
129
  enum {
  	ATI_REMOTE2_AUX1,
  	ATI_REMOTE2_AUX2,
  	ATI_REMOTE2_AUX3,
  	ATI_REMOTE2_AUX4,
  	ATI_REMOTE2_PC,
  	ATI_REMOTE2_MODES,
  };
  
  static const struct {
  	u8  hw_code;
  	u16 keycode;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
  } ati_remote2_key_table[] = {
  	{ 0x00, KEY_0 },
  	{ 0x01, KEY_1 },
  	{ 0x02, KEY_2 },
  	{ 0x03, KEY_3 },
  	{ 0x04, KEY_4 },
  	{ 0x05, KEY_5 },
  	{ 0x06, KEY_6 },
  	{ 0x07, KEY_7 },
  	{ 0x08, KEY_8 },
  	{ 0x09, KEY_9 },
  	{ 0x0c, KEY_POWER },
  	{ 0x0d, KEY_MUTE },
  	{ 0x10, KEY_VOLUMEUP },
  	{ 0x11, KEY_VOLUMEDOWN },
  	{ 0x20, KEY_CHANNELUP },
  	{ 0x21, KEY_CHANNELDOWN },
  	{ 0x28, KEY_FORWARD },
  	{ 0x29, KEY_REWIND },
  	{ 0x2c, KEY_PLAY },
  	{ 0x30, KEY_PAUSE },
  	{ 0x31, KEY_STOP },
  	{ 0x37, KEY_RECORD },
  	{ 0x38, KEY_DVD },
  	{ 0x39, KEY_TV },
1971b9d56   Ville Syrjala   Input: ati_remote...
155
  	{ 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
  	{ 0x54, KEY_MENU },
  	{ 0x58, KEY_UP },
  	{ 0x59, KEY_DOWN },
  	{ 0x5a, KEY_LEFT },
  	{ 0x5b, KEY_RIGHT },
  	{ 0x5c, KEY_OK },
  	{ 0x78, KEY_A },
  	{ 0x79, KEY_B },
  	{ 0x7a, KEY_C },
  	{ 0x7b, KEY_D },
  	{ 0x7c, KEY_E },
  	{ 0x7d, KEY_F },
  	{ 0x82, KEY_ENTER },
  	{ 0x8e, KEY_VENDOR },
  	{ 0x96, KEY_COFFEE },
  	{ 0xa9, BTN_LEFT },
  	{ 0xaa, BTN_RIGHT },
  	{ 0xbe, KEY_QUESTION },
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
174
  	{ 0xd0, KEY_EDIT },
1971b9d56   Ville Syrjala   Input: ati_remote...
175
  	{ 0xd5, KEY_FRONT },
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
176
  	{ 0xf9, KEY_INFO },
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
  };
  
  struct ati_remote2 {
  	struct input_dev *idev;
  	struct usb_device *udev;
  
  	struct usb_interface *intf[2];
  	struct usb_endpoint_descriptor *ep[2];
  	struct urb *urb[2];
  	void *buf[2];
  	dma_addr_t buf_dma[2];
  
  	unsigned long jiffies;
  	int mode;
  
  	char name[64];
  	char phys[64];
1971b9d56   Ville Syrjala   Input: ati_remote...
194
195
196
  
  	/* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
  	u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
d6505ab9c   Ville Syrjala   Input: ati_remote...
197
198
  
  	unsigned int flags;
d329e33c7   Ville Syrjala   Input: ati_remote...
199
200
201
  
  	unsigned int channel_mask;
  	unsigned int mode_mask;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
202
203
204
205
  };
  
  static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
  static void ati_remote2_disconnect(struct usb_interface *interface);
d6505ab9c   Ville Syrjala   Input: ati_remote...
206
207
  static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
  static int ati_remote2_resume(struct usb_interface *interface);
169bc1efa   Ville Syrjala   Input: ati_remote...
208
209
210
  static int ati_remote2_reset_resume(struct usb_interface *interface);
  static int ati_remote2_pre_reset(struct usb_interface *interface);
  static int ati_remote2_post_reset(struct usb_interface *interface);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
211
212
213
214
215
216
  
  static struct usb_driver ati_remote2_driver = {
  	.name       = "ati_remote2",
  	.probe      = ati_remote2_probe,
  	.disconnect = ati_remote2_disconnect,
  	.id_table   = ati_remote2_id_table,
d6505ab9c   Ville Syrjala   Input: ati_remote...
217
218
  	.suspend    = ati_remote2_suspend,
  	.resume     = ati_remote2_resume,
169bc1efa   Ville Syrjala   Input: ati_remote...
219
220
221
  	.reset_resume = ati_remote2_reset_resume,
  	.pre_reset  = ati_remote2_pre_reset,
  	.post_reset = ati_remote2_post_reset,
d6505ab9c   Ville Syrjala   Input: ati_remote...
222
  	.supports_autosuspend = 1,
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
223
  };
d6505ab9c   Ville Syrjala   Input: ati_remote...
224
  static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
225
  {
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
226
227
228
229
230
  	int r;
  
  	r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
  	if (r) {
  		dev_err(&ar2->intf[0]->dev,
d6505ab9c   Ville Syrjala   Input: ati_remote...
231
232
  			"%s(): usb_submit_urb() = %d
  ", __func__, r);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
233
234
235
236
237
238
  		return r;
  	}
  	r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
  	if (r) {
  		usb_kill_urb(ar2->urb[0]);
  		dev_err(&ar2->intf[1]->dev,
d6505ab9c   Ville Syrjala   Input: ati_remote...
239
240
  			"%s(): usb_submit_urb() = %d
  ", __func__, r);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
241
242
243
244
245
  		return r;
  	}
  
  	return 0;
  }
d6505ab9c   Ville Syrjala   Input: ati_remote...
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
  static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
  {
  	usb_kill_urb(ar2->urb[1]);
  	usb_kill_urb(ar2->urb[0]);
  }
  
  static int ati_remote2_open(struct input_dev *idev)
  {
  	struct ati_remote2 *ar2 = input_get_drvdata(idev);
  	int r;
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	r = usb_autopm_get_interface(ar2->intf[0]);
  	if (r) {
  		dev_err(&ar2->intf[0]->dev,
  			"%s(): usb_autopm_get_interface() = %d
  ", __func__, r);
  		goto fail1;
  	}
  
  	mutex_lock(&ati_remote2_mutex);
  
  	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
  		r = ati_remote2_submit_urbs(ar2);
  		if (r)
  			goto fail2;
  	}
  
  	ar2->flags |= ATI_REMOTE2_OPENED;
  
  	mutex_unlock(&ati_remote2_mutex);
  
  	usb_autopm_put_interface(ar2->intf[0]);
  
  	return 0;
  
   fail2:
  	mutex_unlock(&ati_remote2_mutex);
  	usb_autopm_put_interface(ar2->intf[0]);
   fail1:
  	return r;
  }
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
290
291
  static void ati_remote2_close(struct input_dev *idev)
  {
7791bdae7   Dmitry Torokhov   Input: drivers/us...
292
  	struct ati_remote2 *ar2 = input_get_drvdata(idev);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
293

d6505ab9c   Ville Syrjala   Input: ati_remote...
294
295
296
297
298
299
300
301
302
303
304
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	mutex_lock(&ati_remote2_mutex);
  
  	if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
  		ati_remote2_kill_urbs(ar2);
  
  	ar2->flags &= ~ATI_REMOTE2_OPENED;
  
  	mutex_unlock(&ati_remote2_mutex);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
305
  }
7d12e780e   David Howells   IRQ: Maintain reg...
306
  static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
307
308
309
  {
  	struct input_dev *idev = ar2->idev;
  	u8 *data = ar2->buf[0];
a1421d3c7   Peter Stokes   Input: add logica...
310
311
312
  	int channel, mode;
  
  	channel = data[0] >> 4;
d329e33c7   Ville Syrjala   Input: ati_remote...
313
  	if (!((1 << channel) & ar2->channel_mask))
a1421d3c7   Peter Stokes   Input: add logica...
314
  		return;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
315

a1421d3c7   Peter Stokes   Input: add logica...
316
  	mode = data[0] & 0x0F;
1971b9d56   Ville Syrjala   Input: ati_remote...
317
  	if (mode > ATI_REMOTE2_PC) {
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
318
319
320
321
322
323
  		dev_err(&ar2->intf[0]->dev,
  			"Unknown mode byte (%02x %02x %02x %02x)
  ",
  			data[3], data[2], data[1], data[0]);
  		return;
  	}
d329e33c7   Ville Syrjala   Input: ati_remote...
324
  	if (!((1 << mode) & ar2->mode_mask))
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
325
  		return;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
326
327
328
329
330
331
332
333
  	input_event(idev, EV_REL, REL_X, (s8) data[1]);
  	input_event(idev, EV_REL, REL_Y, (s8) data[2]);
  	input_sync(idev);
  }
  
  static int ati_remote2_lookup(unsigned int hw_code)
  {
  	int i;
1971b9d56   Ville Syrjala   Input: ati_remote...
334
  	for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
335
336
337
338
339
  		if (ati_remote2_key_table[i].hw_code == hw_code)
  			return i;
  
  	return -1;
  }
7d12e780e   David Howells   IRQ: Maintain reg...
340
  static void ati_remote2_input_key(struct ati_remote2 *ar2)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
341
342
343
  {
  	struct input_dev *idev = ar2->idev;
  	u8 *data = ar2->buf[1];
a1421d3c7   Peter Stokes   Input: add logica...
344
345
346
  	int channel, mode, hw_code, index;
  
  	channel = data[0] >> 4;
d329e33c7   Ville Syrjala   Input: ati_remote...
347
  	if (!((1 << channel) & ar2->channel_mask))
a1421d3c7   Peter Stokes   Input: add logica...
348
  		return;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
349

a1421d3c7   Peter Stokes   Input: add logica...
350
  	mode = data[0] & 0x0F;
1971b9d56   Ville Syrjala   Input: ati_remote...
351
  	if (mode > ATI_REMOTE2_PC) {
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
352
353
354
355
356
357
358
359
  		dev_err(&ar2->intf[1]->dev,
  			"Unknown mode byte (%02x %02x %02x %02x)
  ",
  			data[3], data[2], data[1], data[0]);
  		return;
  	}
  
  	hw_code = data[2];
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
360
361
362
363
364
365
366
367
  	if (hw_code == 0x3f) {
  		/*
  		 * For some incomprehensible reason the mouse pad generates
  		 * events which look identical to the events from the last
  		 * pressed mode key. Naturally we don't want to generate key
  		 * events for the mouse pad so we filter out any subsequent
  		 * events from the same mode key.
  		 */
a1421d3c7   Peter Stokes   Input: add logica...
368
  		if (ar2->mode == mode)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
369
370
371
  			return;
  
  		if (data[1] == 0)
a1421d3c7   Peter Stokes   Input: add logica...
372
  			ar2->mode = mode;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
373
  	}
d329e33c7   Ville Syrjala   Input: ati_remote...
374
  	if (!((1 << mode) & ar2->mode_mask))
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
  		return;
  
  	index = ati_remote2_lookup(hw_code);
  	if (index < 0) {
  		dev_err(&ar2->intf[1]->dev,
  			"Unknown code byte (%02x %02x %02x %02x)
  ",
  			data[3], data[2], data[1], data[0]);
  		return;
  	}
  
  	switch (data[1]) {
  	case 0:	/* release */
  		break;
  	case 1:	/* press */
  		ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
  		break;
  	case 2:	/* repeat */
  
  		/* No repeat for mouse buttons. */
1971b9d56   Ville Syrjala   Input: ati_remote...
395
396
  		if (ar2->keycode[mode][index] == BTN_LEFT ||
  		    ar2->keycode[mode][index] == BTN_RIGHT)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
397
398
399
400
401
402
403
404
405
406
407
408
409
410
  			return;
  
  		if (!time_after_eq(jiffies, ar2->jiffies))
  			return;
  
  		ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
  		break;
  	default:
  		dev_err(&ar2->intf[1]->dev,
  			"Unknown state byte (%02x %02x %02x %02x)
  ",
  			data[3], data[2], data[1], data[0]);
  		return;
  	}
1971b9d56   Ville Syrjala   Input: ati_remote...
411
  	input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
412
413
  	input_sync(idev);
  }
7d12e780e   David Howells   IRQ: Maintain reg...
414
  static void ati_remote2_complete_mouse(struct urb *urb)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
415
416
417
418
419
420
  {
  	struct ati_remote2 *ar2 = urb->context;
  	int r;
  
  	switch (urb->status) {
  	case 0:
d6505ab9c   Ville Syrjala   Input: ati_remote...
421
  		usb_mark_last_busy(ar2->udev);
7d12e780e   David Howells   IRQ: Maintain reg...
422
  		ati_remote2_input_mouse(ar2);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
423
424
425
426
427
428
  		break;
  	case -ENOENT:
  	case -EILSEQ:
  	case -ECONNRESET:
  	case -ESHUTDOWN:
  		dev_dbg(&ar2->intf[0]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
429
430
  			"%s(): urb status = %d
  ", __func__, urb->status);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
431
432
  		return;
  	default:
d6505ab9c   Ville Syrjala   Input: ati_remote...
433
  		usb_mark_last_busy(ar2->udev);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
434
  		dev_err(&ar2->intf[0]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
435
436
  			"%s(): urb status = %d
  ", __func__, urb->status);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
437
438
439
440
441
  	}
  
  	r = usb_submit_urb(urb, GFP_ATOMIC);
  	if (r)
  		dev_err(&ar2->intf[0]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
442
443
  			"%s(): usb_submit_urb() = %d
  ", __func__, r);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
444
  }
7d12e780e   David Howells   IRQ: Maintain reg...
445
  static void ati_remote2_complete_key(struct urb *urb)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
446
447
448
449
450
451
  {
  	struct ati_remote2 *ar2 = urb->context;
  	int r;
  
  	switch (urb->status) {
  	case 0:
d6505ab9c   Ville Syrjala   Input: ati_remote...
452
  		usb_mark_last_busy(ar2->udev);
7d12e780e   David Howells   IRQ: Maintain reg...
453
  		ati_remote2_input_key(ar2);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
454
455
456
457
458
459
  		break;
  	case -ENOENT:
  	case -EILSEQ:
  	case -ECONNRESET:
  	case -ESHUTDOWN:
  		dev_dbg(&ar2->intf[1]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
460
461
  			"%s(): urb status = %d
  ", __func__, urb->status);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
462
463
  		return;
  	default:
d6505ab9c   Ville Syrjala   Input: ati_remote...
464
  		usb_mark_last_busy(ar2->udev);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
465
  		dev_err(&ar2->intf[1]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
466
467
  			"%s(): urb status = %d
  ", __func__, urb->status);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
468
469
470
471
472
  	}
  
  	r = usb_submit_urb(urb, GFP_ATOMIC);
  	if (r)
  		dev_err(&ar2->intf[1]->dev,
ea3e6c592   Harvey Harrison   Input: replace re...
473
474
  			"%s(): usb_submit_urb() = %d
  ", __func__, r);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
475
  }
1971b9d56   Ville Syrjala   Input: ati_remote...
476
  static int ati_remote2_getkeycode(struct input_dev *idev,
1f7930c55   Dmitry Torokhov   Input: ati_remote...
477
  				  struct input_keymap_entry *ke)
1971b9d56   Ville Syrjala   Input: ati_remote...
478
479
  {
  	struct ati_remote2 *ar2 = input_get_drvdata(idev);
58b939959   Dmitry Torokhov   Input: scancode i...
480
  	unsigned int mode;
1f7930c55   Dmitry Torokhov   Input: ati_remote...
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
  	int offset;
  	unsigned int index;
  	unsigned int scancode;
  
  	if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
  		index = ke->index;
  		if (index >= ATI_REMOTE2_MODES *
  				ARRAY_SIZE(ati_remote2_key_table))
  			return -EINVAL;
  
  		mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
  		offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
  		scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
  	} else {
  		if (input_scancode_to_scalar(ke, &scancode))
  			return -EINVAL;
  
  		mode = scancode >> 8;
  		if (mode > ATI_REMOTE2_PC)
  			return -EINVAL;
  
  		offset = ati_remote2_lookup(scancode & 0xff);
  		if (offset < 0)
  			return -EINVAL;
  
  		index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
  	}
1971b9d56   Ville Syrjala   Input: ati_remote...
508

1f7930c55   Dmitry Torokhov   Input: ati_remote...
509
510
511
512
  	ke->keycode = ar2->keycode[mode][offset];
  	ke->len = sizeof(scancode);
  	memcpy(&ke->scancode, &scancode, sizeof(scancode));
  	ke->index = index;
1971b9d56   Ville Syrjala   Input: ati_remote...
513

1971b9d56   Ville Syrjala   Input: ati_remote...
514
515
  	return 0;
  }
58b939959   Dmitry Torokhov   Input: scancode i...
516
  static int ati_remote2_setkeycode(struct input_dev *idev,
1f7930c55   Dmitry Torokhov   Input: ati_remote...
517
518
  				  const struct input_keymap_entry *ke,
  				  unsigned int *old_keycode)
1971b9d56   Ville Syrjala   Input: ati_remote...
519
520
  {
  	struct ati_remote2 *ar2 = input_get_drvdata(idev);
1f7930c55   Dmitry Torokhov   Input: ati_remote...
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
  	unsigned int mode;
  	int offset;
  	unsigned int index;
  	unsigned int scancode;
  
  	if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
  		if (ke->index >= ATI_REMOTE2_MODES *
  				ARRAY_SIZE(ati_remote2_key_table))
  			return -EINVAL;
  
  		mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
  		offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
  	} else {
  		if (input_scancode_to_scalar(ke, &scancode))
  			return -EINVAL;
  
  		mode = scancode >> 8;
  		if (mode > ATI_REMOTE2_PC)
  			return -EINVAL;
  
  		offset = ati_remote2_lookup(scancode & 0xff);
  		if (offset < 0)
  			return -EINVAL;
  	}
1971b9d56   Ville Syrjala   Input: ati_remote...
545

1f7930c55   Dmitry Torokhov   Input: ati_remote...
546
547
548
  	*old_keycode = ar2->keycode[mode][offset];
  	ar2->keycode[mode][offset] = ke->keycode;
  	__set_bit(ke->keycode, idev->keybit);
1971b9d56   Ville Syrjala   Input: ati_remote...
549
550
551
  
  	for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
  		for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
1f7930c55   Dmitry Torokhov   Input: ati_remote...
552
  			if (ar2->keycode[mode][index] == *old_keycode)
1971b9d56   Ville Syrjala   Input: ati_remote...
553
554
555
  				return 0;
  		}
  	}
1f7930c55   Dmitry Torokhov   Input: ati_remote...
556
  	__clear_bit(*old_keycode, idev->keybit);
1971b9d56   Ville Syrjala   Input: ati_remote...
557
558
559
  
  	return 0;
  }
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
560
561
562
  static int ati_remote2_input_init(struct ati_remote2 *ar2)
  {
  	struct input_dev *idev;
1971b9d56   Ville Syrjala   Input: ati_remote...
563
  	int index, mode, retval;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
564
565
566
567
568
569
  
  	idev = input_allocate_device();
  	if (!idev)
  		return -ENOMEM;
  
  	ar2->idev = idev;
7791bdae7   Dmitry Torokhov   Input: drivers/us...
570
  	input_set_drvdata(idev, ar2);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
571

7b19ada2e   Jiri Slaby   get rid of input ...
572
573
574
575
  	idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
  	idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
  		BIT_MASK(BTN_RIGHT);
  	idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
1971b9d56   Ville Syrjala   Input: ati_remote...
576
577
578
579
  
  	for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
  		for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
  			ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
225c9886b   Ville Syrjala   Input: ati_remote...
580
  			__set_bit(ar2->keycode[mode][index], idev->keybit);
1971b9d56   Ville Syrjala   Input: ati_remote...
581
582
583
584
585
586
587
588
589
590
  		}
  	}
  
  	/* AUX1-AUX4 and PC generate the same scancode. */
  	index = ati_remote2_lookup(0x3f);
  	ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
  	ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
  	ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
  	ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
  	ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
225c9886b   Ville Syrjala   Input: ati_remote...
591
592
593
594
595
  	__set_bit(KEY_PROG1, idev->keybit);
  	__set_bit(KEY_PROG2, idev->keybit);
  	__set_bit(KEY_PROG3, idev->keybit);
  	__set_bit(KEY_PROG4, idev->keybit);
  	__set_bit(KEY_PC, idev->keybit);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
596
597
598
599
600
601
  
  	idev->rep[REP_DELAY]  = 250;
  	idev->rep[REP_PERIOD] = 33;
  
  	idev->open = ati_remote2_open;
  	idev->close = ati_remote2_close;
aebd636bd   Dmitry Torokhov   Input: switch com...
602
603
  	idev->getkeycode = ati_remote2_getkeycode;
  	idev->setkeycode = ati_remote2_setkeycode;
1971b9d56   Ville Syrjala   Input: ati_remote...
604

735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
605
606
607
608
  	idev->name = ar2->name;
  	idev->phys = ar2->phys;
  
  	usb_to_input_id(ar2->udev, &idev->id);
c0f82d570   Dmitry Torokhov   Input: USB device...
609
  	idev->dev.parent = &ar2->udev->dev;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
610

5014186de   Dmitry Torokhov   Input: USB device...
611
612
  	retval = input_register_device(idev);
  	if (retval)
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
613
  		input_free_device(idev);
5014186de   Dmitry Torokhov   Input: USB device...
614
  	return retval;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
615
616
617
618
619
620
621
622
  }
  
  static int ati_remote2_urb_init(struct ati_remote2 *ar2)
  {
  	struct usb_device *udev = ar2->udev;
  	int i, pipe, maxp;
  
  	for (i = 0; i < 2; i++) {
997ea58eb   Daniel Mack   USB: rename usb_b...
623
  		ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
  		if (!ar2->buf[i])
  			return -ENOMEM;
  
  		ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
  		if (!ar2->urb[i])
  			return -ENOMEM;
  
  		pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
  		maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
  		maxp = maxp > 4 ? 4 : maxp;
  
  		usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
  				 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
  				 ar2, ar2->ep[i]->bInterval);
  		ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
  		ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  	}
  
  	return 0;
  }
  
  static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
  {
  	int i;
  
  	for (i = 0; i < 2; i++) {
2381526a7   Mariusz Kozlowski   usb: ati_remote2 ...
650
  		usb_free_urb(ar2->urb[i]);
997ea58eb   Daniel Mack   USB: rename usb_b...
651
  		usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
652
653
  	}
  }
d329e33c7   Ville Syrjala   Input: ati_remote...
654
  static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
a1421d3c7   Peter Stokes   Input: add logica...
655
656
657
658
659
660
661
662
663
664
665
666
667
668
  {
  	int r, i, channel;
  
  	/*
  	 * Configure receiver to only accept input from remote "channel"
  	 *  channel == 0  -> Accept input from any remote channel
  	 *  channel == 1  -> Only accept input from remote channel 1
  	 *  channel == 2  -> Only accept input from remote channel 2
  	 *  ...
  	 *  channel == 16 -> Only accept input from remote channel 16
  	 */
  
  	channel = 0;
  	for (i = 0; i < 16; i++) {
d329e33c7   Ville Syrjala   Input: ati_remote...
669
670
  		if ((1 << i) & ch_mask) {
  			if (!(~(1 << i) & ch_mask))
a1421d3c7   Peter Stokes   Input: add logica...
671
672
673
674
675
676
677
678
679
680
681
682
  				channel = i + 1;
  			break;
  		}
  	}
  
  	r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
  			    0x20,
  			    USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
  			    channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
  	if (r) {
  		dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d
  ",
ea3e6c592   Harvey Harrison   Input: replace re...
683
  			__func__, r);
a1421d3c7   Peter Stokes   Input: add logica...
684
685
686
687
688
  		return r;
  	}
  
  	return 0;
  }
d329e33c7   Ville Syrjala   Input: ati_remote...
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
  static ssize_t ati_remote2_show_channel_mask(struct device *dev,
  					     struct device_attribute *attr,
  					     char *buf)
  {
  	struct usb_device *udev = to_usb_device(dev);
  	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
  	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
  
  	return sprintf(buf, "0x%04x
  ", ar2->channel_mask);
  }
  
  static ssize_t ati_remote2_store_channel_mask(struct device *dev,
  					      struct device_attribute *attr,
  					      const char *buf, size_t count)
  {
  	struct usb_device *udev = to_usb_device(dev);
  	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
  	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
76496e7a0   JJ Ding   Input: convert ob...
708
  	unsigned int mask;
d329e33c7   Ville Syrjala   Input: ati_remote...
709
  	int r;
76496e7a0   JJ Ding   Input: convert ob...
710
711
712
  	r = kstrtouint(buf, 0, &mask);
  	if (r)
  		return r;
d329e33c7   Ville Syrjala   Input: ati_remote...
713
714
715
716
717
718
719
720
721
722
723
724
725
  
  	if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
  		return -EINVAL;
  
  	r = usb_autopm_get_interface(ar2->intf[0]);
  	if (r) {
  		dev_err(&ar2->intf[0]->dev,
  			"%s(): usb_autopm_get_interface() = %d
  ", __func__, r);
  		return r;
  	}
  
  	mutex_lock(&ati_remote2_mutex);
7388754e0   Ville Syrjala   Input: ati_remote...
726
727
728
729
730
  	if (mask != ar2->channel_mask) {
  		r = ati_remote2_setup(ar2, mask);
  		if (!r)
  			ar2->channel_mask = mask;
  	}
d329e33c7   Ville Syrjala   Input: ati_remote...
731
732
733
734
  
  	mutex_unlock(&ati_remote2_mutex);
  
  	usb_autopm_put_interface(ar2->intf[0]);
7388754e0   Ville Syrjala   Input: ati_remote...
735
  	return r ? r : count;
d329e33c7   Ville Syrjala   Input: ati_remote...
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
  }
  
  static ssize_t ati_remote2_show_mode_mask(struct device *dev,
  					  struct device_attribute *attr,
  					  char *buf)
  {
  	struct usb_device *udev = to_usb_device(dev);
  	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
  	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
  
  	return sprintf(buf, "0x%02x
  ", ar2->mode_mask);
  }
  
  static ssize_t ati_remote2_store_mode_mask(struct device *dev,
  					   struct device_attribute *attr,
  					   const char *buf, size_t count)
  {
  	struct usb_device *udev = to_usb_device(dev);
  	struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
  	struct ati_remote2 *ar2 = usb_get_intfdata(intf);
76496e7a0   JJ Ding   Input: convert ob...
757
758
  	unsigned int mask;
  	int err;
d329e33c7   Ville Syrjala   Input: ati_remote...
759

76496e7a0   JJ Ding   Input: convert ob...
760
761
762
  	err = kstrtouint(buf, 0, &mask);
  	if (err)
  		return err;
d329e33c7   Ville Syrjala   Input: ati_remote...
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
  
  	if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
  		return -EINVAL;
  
  	ar2->mode_mask = mask;
  
  	return count;
  }
  
  static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
  		   ati_remote2_store_channel_mask);
  
  static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
  		   ati_remote2_store_mode_mask);
  
  static struct attribute *ati_remote2_attrs[] = {
  	&dev_attr_channel_mask.attr,
  	&dev_attr_mode_mask.attr,
  	NULL,
  };
  
  static struct attribute_group ati_remote2_attr_group = {
  	.attrs = ati_remote2_attrs,
  };
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
  static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
  {
  	struct usb_device *udev = interface_to_usbdev(interface);
  	struct usb_host_interface *alt = interface->cur_altsetting;
  	struct ati_remote2 *ar2;
  	int r;
  
  	if (alt->desc.bInterfaceNumber)
  		return -ENODEV;
  
  	ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
  	if (!ar2)
  		return -ENOMEM;
  
  	ar2->udev = udev;
  
  	ar2->intf[0] = interface;
  	ar2->ep[0] = &alt->endpoint[0].desc;
  
  	ar2->intf[1] = usb_ifnum_to_if(udev, 1);
  	r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
  	if (r)
  		goto fail1;
  	alt = ar2->intf[1]->cur_altsetting;
  	ar2->ep[1] = &alt->endpoint[0].desc;
  
  	r = ati_remote2_urb_init(ar2);
  	if (r)
  		goto fail2;
8a49cfa9d   Ville Syrjala   Input: ati_remote...
816
817
  	ar2->channel_mask = channel_mask;
  	ar2->mode_mask = mode_mask;
d329e33c7   Ville Syrjala   Input: ati_remote...
818
819
  
  	r = ati_remote2_setup(ar2, ar2->channel_mask);
a1421d3c7   Peter Stokes   Input: add logica...
820
821
  	if (r)
  		goto fail2;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
822
823
824
825
  	usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
  	strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
  
  	strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
d329e33c7   Ville Syrjala   Input: ati_remote...
826
  	r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
827
828
  	if (r)
  		goto fail2;
d329e33c7   Ville Syrjala   Input: ati_remote...
829
830
831
  	r = ati_remote2_input_init(ar2);
  	if (r)
  		goto fail3;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
832
  	usb_set_intfdata(interface, ar2);
d6505ab9c   Ville Syrjala   Input: ati_remote...
833
  	interface->needs_remote_wakeup = 1;
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
834
  	return 0;
d329e33c7   Ville Syrjala   Input: ati_remote...
835
836
   fail3:
  	sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
837
838
   fail2:
  	ati_remote2_urb_cleanup(ar2);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
  	usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
   fail1:
  	kfree(ar2);
  
  	return r;
  }
  
  static void ati_remote2_disconnect(struct usb_interface *interface)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  
  	if (alt->desc.bInterfaceNumber)
  		return;
  
  	ar2 = usb_get_intfdata(interface);
  	usb_set_intfdata(interface, NULL);
  
  	input_unregister_device(ar2->idev);
d329e33c7   Ville Syrjala   Input: ati_remote...
858
  	sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
735b0cbb5   Ville Syrjälä   [PATCH] USB: add ...
859
860
861
862
863
864
  	ati_remote2_urb_cleanup(ar2);
  
  	usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
  
  	kfree(ar2);
  }
d6505ab9c   Ville Syrjala   Input: ati_remote...
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
  static int ati_remote2_suspend(struct usb_interface *interface,
  			       pm_message_t message)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  
  	if (alt->desc.bInterfaceNumber)
  		return 0;
  
  	ar2 = usb_get_intfdata(interface);
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	mutex_lock(&ati_remote2_mutex);
  
  	if (ar2->flags & ATI_REMOTE2_OPENED)
  		ati_remote2_kill_urbs(ar2);
  
  	ar2->flags |= ATI_REMOTE2_SUSPENDED;
  
  	mutex_unlock(&ati_remote2_mutex);
  
  	return 0;
  }
  
  static int ati_remote2_resume(struct usb_interface *interface)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  	int r = 0;
  
  	if (alt->desc.bInterfaceNumber)
  		return 0;
  
  	ar2 = usb_get_intfdata(interface);
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	mutex_lock(&ati_remote2_mutex);
  
  	if (ar2->flags & ATI_REMOTE2_OPENED)
  		r = ati_remote2_submit_urbs(ar2);
  
  	if (!r)
  		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
  
  	mutex_unlock(&ati_remote2_mutex);
  
  	return r;
  }
169bc1efa   Ville Syrjala   Input: ati_remote...
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
  static int ati_remote2_reset_resume(struct usb_interface *interface)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  	int r = 0;
  
  	if (alt->desc.bInterfaceNumber)
  		return 0;
  
  	ar2 = usb_get_intfdata(interface);
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	mutex_lock(&ati_remote2_mutex);
d329e33c7   Ville Syrjala   Input: ati_remote...
932
  	r = ati_remote2_setup(ar2, ar2->channel_mask);
169bc1efa   Ville Syrjala   Input: ati_remote...
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
  	if (r)
  		goto out;
  
  	if (ar2->flags & ATI_REMOTE2_OPENED)
  		r = ati_remote2_submit_urbs(ar2);
  
  	if (!r)
  		ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
  
   out:
  	mutex_unlock(&ati_remote2_mutex);
  
  	return r;
  }
  
  static int ati_remote2_pre_reset(struct usb_interface *interface)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  
  	if (alt->desc.bInterfaceNumber)
  		return 0;
  
  	ar2 = usb_get_intfdata(interface);
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	mutex_lock(&ati_remote2_mutex);
  
  	if (ar2->flags == ATI_REMOTE2_OPENED)
  		ati_remote2_kill_urbs(ar2);
  
  	return 0;
  }
  
  static int ati_remote2_post_reset(struct usb_interface *interface)
  {
  	struct ati_remote2 *ar2;
  	struct usb_host_interface *alt = interface->cur_altsetting;
  	int r = 0;
  
  	if (alt->desc.bInterfaceNumber)
  		return 0;
  
  	ar2 = usb_get_intfdata(interface);
  
  	dev_dbg(&ar2->intf[0]->dev, "%s()
  ", __func__);
  
  	if (ar2->flags == ATI_REMOTE2_OPENED)
  		r = ati_remote2_submit_urbs(ar2);
  
  	mutex_unlock(&ati_remote2_mutex);
  
  	return r;
  }
08642e7c5   Greg Kroah-Hartman   USB: convert driv...
990
  module_usb_driver(ati_remote2_driver);