2 * ati_remote2 - ATI/Philips USB RF remote driver
4 * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
5 * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation.
12 #include <linux/usb/input.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
16 #define DRIVER_DESC "ATI/Philips USB RF remote driver"
18 MODULE_DESCRIPTION(DRIVER_DESC
);
19 MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
20 MODULE_LICENSE("GPL");
23 * ATI Remote Wonder II Channel Configuration
25 * The remote control can be assigned one of sixteen "channels" in order to facilitate
26 * the use of multiple remote controls within range of each other.
27 * A remote's "channel" may be altered by pressing and holding the "PC" button for
28 * approximately 3 seconds, after which the button will slowly flash the count of the
29 * currently configured "channel", using the numeric keypad enter a number between 1 and
30 * 16 and then press the "PC" button again, the button will slowly flash the count of the
31 * newly configured "channel".
35 ATI_REMOTE2_MAX_CHANNEL_MASK
= 0xFFFF,
36 ATI_REMOTE2_MAX_MODE_MASK
= 0x1F,
39 static int ati_remote2_set_mask(const char *val
,
40 const struct kernel_param
*kp
,
49 ret
= kstrtouint(val
, 0, &mask
);
56 *(unsigned int *)kp
->arg
= mask
;
61 static int ati_remote2_set_channel_mask(const char *val
,
62 const struct kernel_param
*kp
)
64 pr_debug("%s()\n", __func__
);
66 return ati_remote2_set_mask(val
, kp
, ATI_REMOTE2_MAX_CHANNEL_MASK
);
69 static int ati_remote2_get_channel_mask(char *buffer
,
70 const struct kernel_param
*kp
)
72 pr_debug("%s()\n", __func__
);
74 return sprintf(buffer
, "0x%04x", *(unsigned int *)kp
->arg
);
77 static int ati_remote2_set_mode_mask(const char *val
,
78 const struct kernel_param
*kp
)
80 pr_debug("%s()\n", __func__
);
82 return ati_remote2_set_mask(val
, kp
, ATI_REMOTE2_MAX_MODE_MASK
);
85 static int ati_remote2_get_mode_mask(char *buffer
,
86 const struct kernel_param
*kp
)
88 pr_debug("%s()\n", __func__
);
90 return sprintf(buffer
, "0x%02x", *(unsigned int *)kp
->arg
);
93 static unsigned int channel_mask
= ATI_REMOTE2_MAX_CHANNEL_MASK
;
94 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
95 static const struct kernel_param_ops param_ops_channel_mask
= {
96 .set
= ati_remote2_set_channel_mask
,
97 .get
= ati_remote2_get_channel_mask
,
99 module_param(channel_mask
, channel_mask
, 0644);
100 MODULE_PARM_DESC(channel_mask
, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
102 static unsigned int mode_mask
= ATI_REMOTE2_MAX_MODE_MASK
;
103 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
104 static const struct kernel_param_ops param_ops_mode_mask
= {
105 .set
= ati_remote2_set_mode_mask
,
106 .get
= ati_remote2_get_mode_mask
,
108 module_param(mode_mask
, mode_mask
, 0644);
109 MODULE_PARM_DESC(mode_mask
, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
111 static const struct usb_device_id ati_remote2_id_table
[] = {
112 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
115 MODULE_DEVICE_TABLE(usb
, ati_remote2_id_table
);
117 static DEFINE_MUTEX(ati_remote2_mutex
);
120 ATI_REMOTE2_OPENED
= 0x1,
121 ATI_REMOTE2_SUSPENDED
= 0x2,
133 static const struct {
136 } ati_remote2_key_table
[] = {
149 { 0x10, KEY_VOLUMEUP
},
150 { 0x11, KEY_VOLUMEDOWN
},
151 { 0x20, KEY_CHANNELUP
},
152 { 0x21, KEY_CHANNELDOWN
},
153 { 0x28, KEY_FORWARD
},
154 { 0x29, KEY_REWIND
},
158 { 0x37, KEY_RECORD
},
161 { 0x3f, KEY_PROG1
}, /* AUX1-AUX4 and PC */
175 { 0x8e, KEY_VENDOR
},
176 { 0x96, KEY_COFFEE
},
179 { 0xbe, KEY_QUESTION
},
186 struct input_dev
*idev
;
187 struct usb_device
*udev
;
189 struct usb_interface
*intf
[2];
190 struct usb_endpoint_descriptor
*ep
[2];
193 dma_addr_t buf_dma
[2];
195 unsigned long jiffies
;
201 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
202 u16 keycode
[ATI_REMOTE2_MODES
][ARRAY_SIZE(ati_remote2_key_table
)];
206 unsigned int channel_mask
;
207 unsigned int mode_mask
;
210 static int ati_remote2_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
);
211 static void ati_remote2_disconnect(struct usb_interface
*interface
);
212 static int ati_remote2_suspend(struct usb_interface
*interface
, pm_message_t message
);
213 static int ati_remote2_resume(struct usb_interface
*interface
);
214 static int ati_remote2_reset_resume(struct usb_interface
*interface
);
215 static int ati_remote2_pre_reset(struct usb_interface
*interface
);
216 static int ati_remote2_post_reset(struct usb_interface
*interface
);
218 static struct usb_driver ati_remote2_driver
= {
219 .name
= "ati_remote2",
220 .probe
= ati_remote2_probe
,
221 .disconnect
= ati_remote2_disconnect
,
222 .id_table
= ati_remote2_id_table
,
223 .suspend
= ati_remote2_suspend
,
224 .resume
= ati_remote2_resume
,
225 .reset_resume
= ati_remote2_reset_resume
,
226 .pre_reset
= ati_remote2_pre_reset
,
227 .post_reset
= ati_remote2_post_reset
,
228 .supports_autosuspend
= 1,
231 static int ati_remote2_submit_urbs(struct ati_remote2
*ar2
)
235 r
= usb_submit_urb(ar2
->urb
[0], GFP_KERNEL
);
237 dev_err(&ar2
->intf
[0]->dev
,
238 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
241 r
= usb_submit_urb(ar2
->urb
[1], GFP_KERNEL
);
243 usb_kill_urb(ar2
->urb
[0]);
244 dev_err(&ar2
->intf
[1]->dev
,
245 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
252 static void ati_remote2_kill_urbs(struct ati_remote2
*ar2
)
254 usb_kill_urb(ar2
->urb
[1]);
255 usb_kill_urb(ar2
->urb
[0]);
258 static int ati_remote2_open(struct input_dev
*idev
)
260 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
263 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
265 r
= usb_autopm_get_interface(ar2
->intf
[0]);
267 dev_err(&ar2
->intf
[0]->dev
,
268 "%s(): usb_autopm_get_interface() = %d\n", __func__
, r
);
272 mutex_lock(&ati_remote2_mutex
);
274 if (!(ar2
->flags
& ATI_REMOTE2_SUSPENDED
)) {
275 r
= ati_remote2_submit_urbs(ar2
);
280 ar2
->flags
|= ATI_REMOTE2_OPENED
;
282 mutex_unlock(&ati_remote2_mutex
);
284 usb_autopm_put_interface(ar2
->intf
[0]);
289 mutex_unlock(&ati_remote2_mutex
);
290 usb_autopm_put_interface(ar2
->intf
[0]);
295 static void ati_remote2_close(struct input_dev
*idev
)
297 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
299 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
301 mutex_lock(&ati_remote2_mutex
);
303 if (!(ar2
->flags
& ATI_REMOTE2_SUSPENDED
))
304 ati_remote2_kill_urbs(ar2
);
306 ar2
->flags
&= ~ATI_REMOTE2_OPENED
;
308 mutex_unlock(&ati_remote2_mutex
);
311 static void ati_remote2_input_mouse(struct ati_remote2
*ar2
)
313 struct input_dev
*idev
= ar2
->idev
;
314 u8
*data
= ar2
->buf
[0];
317 channel
= data
[0] >> 4;
319 if (!((1 << channel
) & ar2
->channel_mask
))
322 mode
= data
[0] & 0x0F;
324 if (mode
> ATI_REMOTE2_PC
) {
325 dev_err(&ar2
->intf
[0]->dev
,
326 "Unknown mode byte (%02x %02x %02x %02x)\n",
327 data
[3], data
[2], data
[1], data
[0]);
331 if (!((1 << mode
) & ar2
->mode_mask
))
334 input_event(idev
, EV_REL
, REL_X
, (s8
) data
[1]);
335 input_event(idev
, EV_REL
, REL_Y
, (s8
) data
[2]);
339 static int ati_remote2_lookup(unsigned int hw_code
)
343 for (i
= 0; i
< ARRAY_SIZE(ati_remote2_key_table
); i
++)
344 if (ati_remote2_key_table
[i
].hw_code
== hw_code
)
350 static void ati_remote2_input_key(struct ati_remote2
*ar2
)
352 struct input_dev
*idev
= ar2
->idev
;
353 u8
*data
= ar2
->buf
[1];
354 int channel
, mode
, hw_code
, index
;
356 channel
= data
[0] >> 4;
358 if (!((1 << channel
) & ar2
->channel_mask
))
361 mode
= data
[0] & 0x0F;
363 if (mode
> ATI_REMOTE2_PC
) {
364 dev_err(&ar2
->intf
[1]->dev
,
365 "Unknown mode byte (%02x %02x %02x %02x)\n",
366 data
[3], data
[2], data
[1], data
[0]);
371 if (hw_code
== 0x3f) {
373 * For some incomprehensible reason the mouse pad generates
374 * events which look identical to the events from the last
375 * pressed mode key. Naturally we don't want to generate key
376 * events for the mouse pad so we filter out any subsequent
377 * events from the same mode key.
379 if (ar2
->mode
== mode
)
386 if (!((1 << mode
) & ar2
->mode_mask
))
389 index
= ati_remote2_lookup(hw_code
);
391 dev_err(&ar2
->intf
[1]->dev
,
392 "Unknown code byte (%02x %02x %02x %02x)\n",
393 data
[3], data
[2], data
[1], data
[0]);
398 case 0: /* release */
401 ar2
->jiffies
= jiffies
+ msecs_to_jiffies(idev
->rep
[REP_DELAY
]);
405 /* No repeat for mouse buttons. */
406 if (ar2
->keycode
[mode
][index
] == BTN_LEFT
||
407 ar2
->keycode
[mode
][index
] == BTN_RIGHT
)
410 if (!time_after_eq(jiffies
, ar2
->jiffies
))
413 ar2
->jiffies
= jiffies
+ msecs_to_jiffies(idev
->rep
[REP_PERIOD
]);
416 dev_err(&ar2
->intf
[1]->dev
,
417 "Unknown state byte (%02x %02x %02x %02x)\n",
418 data
[3], data
[2], data
[1], data
[0]);
422 input_event(idev
, EV_KEY
, ar2
->keycode
[mode
][index
], data
[1]);
426 static void ati_remote2_complete_mouse(struct urb
*urb
)
428 struct ati_remote2
*ar2
= urb
->context
;
431 switch (urb
->status
) {
433 usb_mark_last_busy(ar2
->udev
);
434 ati_remote2_input_mouse(ar2
);
440 dev_dbg(&ar2
->intf
[0]->dev
,
441 "%s(): urb status = %d\n", __func__
, urb
->status
);
444 usb_mark_last_busy(ar2
->udev
);
445 dev_err(&ar2
->intf
[0]->dev
,
446 "%s(): urb status = %d\n", __func__
, urb
->status
);
449 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
451 dev_err(&ar2
->intf
[0]->dev
,
452 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
455 static void ati_remote2_complete_key(struct urb
*urb
)
457 struct ati_remote2
*ar2
= urb
->context
;
460 switch (urb
->status
) {
462 usb_mark_last_busy(ar2
->udev
);
463 ati_remote2_input_key(ar2
);
469 dev_dbg(&ar2
->intf
[1]->dev
,
470 "%s(): urb status = %d\n", __func__
, urb
->status
);
473 usb_mark_last_busy(ar2
->udev
);
474 dev_err(&ar2
->intf
[1]->dev
,
475 "%s(): urb status = %d\n", __func__
, urb
->status
);
478 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
480 dev_err(&ar2
->intf
[1]->dev
,
481 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
484 static int ati_remote2_getkeycode(struct input_dev
*idev
,
485 struct input_keymap_entry
*ke
)
487 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
491 unsigned int scancode
;
493 if (ke
->flags
& INPUT_KEYMAP_BY_INDEX
) {
495 if (index
>= ATI_REMOTE2_MODES
*
496 ARRAY_SIZE(ati_remote2_key_table
))
499 mode
= ke
->index
/ ARRAY_SIZE(ati_remote2_key_table
);
500 offset
= ke
->index
% ARRAY_SIZE(ati_remote2_key_table
);
501 scancode
= (mode
<< 8) + ati_remote2_key_table
[offset
].hw_code
;
503 if (input_scancode_to_scalar(ke
, &scancode
))
506 mode
= scancode
>> 8;
507 if (mode
> ATI_REMOTE2_PC
)
510 offset
= ati_remote2_lookup(scancode
& 0xff);
514 index
= mode
* ARRAY_SIZE(ati_remote2_key_table
) + offset
;
517 ke
->keycode
= ar2
->keycode
[mode
][offset
];
518 ke
->len
= sizeof(scancode
);
519 memcpy(&ke
->scancode
, &scancode
, sizeof(scancode
));
525 static int ati_remote2_setkeycode(struct input_dev
*idev
,
526 const struct input_keymap_entry
*ke
,
527 unsigned int *old_keycode
)
529 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
533 unsigned int scancode
;
535 if (ke
->flags
& INPUT_KEYMAP_BY_INDEX
) {
536 if (ke
->index
>= ATI_REMOTE2_MODES
*
537 ARRAY_SIZE(ati_remote2_key_table
))
540 mode
= ke
->index
/ ARRAY_SIZE(ati_remote2_key_table
);
541 offset
= ke
->index
% ARRAY_SIZE(ati_remote2_key_table
);
543 if (input_scancode_to_scalar(ke
, &scancode
))
546 mode
= scancode
>> 8;
547 if (mode
> ATI_REMOTE2_PC
)
550 offset
= ati_remote2_lookup(scancode
& 0xff);
555 *old_keycode
= ar2
->keycode
[mode
][offset
];
556 ar2
->keycode
[mode
][offset
] = ke
->keycode
;
557 __set_bit(ke
->keycode
, idev
->keybit
);
559 for (mode
= 0; mode
< ATI_REMOTE2_MODES
; mode
++) {
560 for (index
= 0; index
< ARRAY_SIZE(ati_remote2_key_table
); index
++) {
561 if (ar2
->keycode
[mode
][index
] == *old_keycode
)
566 __clear_bit(*old_keycode
, idev
->keybit
);
571 static int ati_remote2_input_init(struct ati_remote2
*ar2
)
573 struct input_dev
*idev
;
574 int index
, mode
, retval
;
576 idev
= input_allocate_device();
581 input_set_drvdata(idev
, ar2
);
583 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
) | BIT_MASK(EV_REL
);
584 idev
->keybit
[BIT_WORD(BTN_MOUSE
)] = BIT_MASK(BTN_LEFT
) |
586 idev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
588 for (mode
= 0; mode
< ATI_REMOTE2_MODES
; mode
++) {
589 for (index
= 0; index
< ARRAY_SIZE(ati_remote2_key_table
); index
++) {
590 ar2
->keycode
[mode
][index
] = ati_remote2_key_table
[index
].keycode
;
591 __set_bit(ar2
->keycode
[mode
][index
], idev
->keybit
);
595 /* AUX1-AUX4 and PC generate the same scancode. */
596 index
= ati_remote2_lookup(0x3f);
597 ar2
->keycode
[ATI_REMOTE2_AUX1
][index
] = KEY_PROG1
;
598 ar2
->keycode
[ATI_REMOTE2_AUX2
][index
] = KEY_PROG2
;
599 ar2
->keycode
[ATI_REMOTE2_AUX3
][index
] = KEY_PROG3
;
600 ar2
->keycode
[ATI_REMOTE2_AUX4
][index
] = KEY_PROG4
;
601 ar2
->keycode
[ATI_REMOTE2_PC
][index
] = KEY_PC
;
602 __set_bit(KEY_PROG1
, idev
->keybit
);
603 __set_bit(KEY_PROG2
, idev
->keybit
);
604 __set_bit(KEY_PROG3
, idev
->keybit
);
605 __set_bit(KEY_PROG4
, idev
->keybit
);
606 __set_bit(KEY_PC
, idev
->keybit
);
608 idev
->rep
[REP_DELAY
] = 250;
609 idev
->rep
[REP_PERIOD
] = 33;
611 idev
->open
= ati_remote2_open
;
612 idev
->close
= ati_remote2_close
;
614 idev
->getkeycode
= ati_remote2_getkeycode
;
615 idev
->setkeycode
= ati_remote2_setkeycode
;
617 idev
->name
= ar2
->name
;
618 idev
->phys
= ar2
->phys
;
620 usb_to_input_id(ar2
->udev
, &idev
->id
);
621 idev
->dev
.parent
= &ar2
->udev
->dev
;
623 retval
= input_register_device(idev
);
625 input_free_device(idev
);
630 static int ati_remote2_urb_init(struct ati_remote2
*ar2
)
632 struct usb_device
*udev
= ar2
->udev
;
635 for (i
= 0; i
< 2; i
++) {
636 ar2
->buf
[i
] = usb_alloc_coherent(udev
, 4, GFP_KERNEL
, &ar2
->buf_dma
[i
]);
640 ar2
->urb
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
644 pipe
= usb_rcvintpipe(udev
, ar2
->ep
[i
]->bEndpointAddress
);
645 maxp
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
646 maxp
= maxp
> 4 ? 4 : maxp
;
648 usb_fill_int_urb(ar2
->urb
[i
], udev
, pipe
, ar2
->buf
[i
], maxp
,
649 i
? ati_remote2_complete_key
: ati_remote2_complete_mouse
,
650 ar2
, ar2
->ep
[i
]->bInterval
);
651 ar2
->urb
[i
]->transfer_dma
= ar2
->buf_dma
[i
];
652 ar2
->urb
[i
]->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
658 static void ati_remote2_urb_cleanup(struct ati_remote2
*ar2
)
662 for (i
= 0; i
< 2; i
++) {
663 usb_free_urb(ar2
->urb
[i
]);
664 usb_free_coherent(ar2
->udev
, 4, ar2
->buf
[i
], ar2
->buf_dma
[i
]);
668 static int ati_remote2_setup(struct ati_remote2
*ar2
, unsigned int ch_mask
)
673 * Configure receiver to only accept input from remote "channel"
674 * channel == 0 -> Accept input from any remote channel
675 * channel == 1 -> Only accept input from remote channel 1
676 * channel == 2 -> Only accept input from remote channel 2
678 * channel == 16 -> Only accept input from remote channel 16
682 for (i
= 0; i
< 16; i
++) {
683 if ((1 << i
) & ch_mask
) {
684 if (!(~(1 << i
) & ch_mask
))
690 r
= usb_control_msg(ar2
->udev
, usb_sndctrlpipe(ar2
->udev
, 0),
692 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_INTERFACE
,
693 channel
, 0x0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
695 dev_err(&ar2
->udev
->dev
, "%s - failed to set channel due to error: %d\n",
703 static ssize_t
ati_remote2_show_channel_mask(struct device
*dev
,
704 struct device_attribute
*attr
,
707 struct usb_device
*udev
= to_usb_device(dev
);
708 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
709 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
711 return sprintf(buf
, "0x%04x\n", ar2
->channel_mask
);
714 static ssize_t
ati_remote2_store_channel_mask(struct device
*dev
,
715 struct device_attribute
*attr
,
716 const char *buf
, size_t count
)
718 struct usb_device
*udev
= to_usb_device(dev
);
719 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
720 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
724 r
= kstrtouint(buf
, 0, &mask
);
728 if (mask
& ~ATI_REMOTE2_MAX_CHANNEL_MASK
)
731 r
= usb_autopm_get_interface(ar2
->intf
[0]);
733 dev_err(&ar2
->intf
[0]->dev
,
734 "%s(): usb_autopm_get_interface() = %d\n", __func__
, r
);
738 mutex_lock(&ati_remote2_mutex
);
740 if (mask
!= ar2
->channel_mask
) {
741 r
= ati_remote2_setup(ar2
, mask
);
743 ar2
->channel_mask
= mask
;
746 mutex_unlock(&ati_remote2_mutex
);
748 usb_autopm_put_interface(ar2
->intf
[0]);
750 return r
? r
: count
;
753 static ssize_t
ati_remote2_show_mode_mask(struct device
*dev
,
754 struct device_attribute
*attr
,
757 struct usb_device
*udev
= to_usb_device(dev
);
758 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
759 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
761 return sprintf(buf
, "0x%02x\n", ar2
->mode_mask
);
764 static ssize_t
ati_remote2_store_mode_mask(struct device
*dev
,
765 struct device_attribute
*attr
,
766 const char *buf
, size_t count
)
768 struct usb_device
*udev
= to_usb_device(dev
);
769 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
770 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
774 err
= kstrtouint(buf
, 0, &mask
);
778 if (mask
& ~ATI_REMOTE2_MAX_MODE_MASK
)
781 ar2
->mode_mask
= mask
;
786 static DEVICE_ATTR(channel_mask
, 0644, ati_remote2_show_channel_mask
,
787 ati_remote2_store_channel_mask
);
789 static DEVICE_ATTR(mode_mask
, 0644, ati_remote2_show_mode_mask
,
790 ati_remote2_store_mode_mask
);
792 static struct attribute
*ati_remote2_attrs
[] = {
793 &dev_attr_channel_mask
.attr
,
794 &dev_attr_mode_mask
.attr
,
798 static struct attribute_group ati_remote2_attr_group
= {
799 .attrs
= ati_remote2_attrs
,
802 static int ati_remote2_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
804 struct usb_device
*udev
= interface_to_usbdev(interface
);
805 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
806 struct ati_remote2
*ar2
;
809 if (alt
->desc
.bInterfaceNumber
)
812 ar2
= kzalloc(sizeof (struct ati_remote2
), GFP_KERNEL
);
818 /* Sanity check, first interface must have an endpoint */
819 if (alt
->desc
.bNumEndpoints
< 1 || !alt
->endpoint
) {
820 dev_err(&interface
->dev
,
821 "%s(): interface 0 must have an endpoint\n", __func__
);
825 ar2
->intf
[0] = interface
;
826 ar2
->ep
[0] = &alt
->endpoint
[0].desc
;
828 /* Sanity check, the device must have two interfaces */
829 ar2
->intf
[1] = usb_ifnum_to_if(udev
, 1);
830 if ((udev
->actconfig
->desc
.bNumInterfaces
< 2) || !ar2
->intf
[1]) {
831 dev_err(&interface
->dev
, "%s(): need 2 interfaces, found %d\n",
832 __func__
, udev
->actconfig
->desc
.bNumInterfaces
);
837 r
= usb_driver_claim_interface(&ati_remote2_driver
, ar2
->intf
[1], ar2
);
841 /* Sanity check, second interface must have an endpoint */
842 alt
= ar2
->intf
[1]->cur_altsetting
;
843 if (alt
->desc
.bNumEndpoints
< 1 || !alt
->endpoint
) {
844 dev_err(&interface
->dev
,
845 "%s(): interface 1 must have an endpoint\n", __func__
);
849 ar2
->ep
[1] = &alt
->endpoint
[0].desc
;
851 r
= ati_remote2_urb_init(ar2
);
855 ar2
->channel_mask
= channel_mask
;
856 ar2
->mode_mask
= mode_mask
;
858 r
= ati_remote2_setup(ar2
, ar2
->channel_mask
);
862 usb_make_path(udev
, ar2
->phys
, sizeof(ar2
->phys
));
863 strlcat(ar2
->phys
, "/input0", sizeof(ar2
->phys
));
865 strlcat(ar2
->name
, "ATI Remote Wonder II", sizeof(ar2
->name
));
867 r
= sysfs_create_group(&udev
->dev
.kobj
, &ati_remote2_attr_group
);
871 r
= ati_remote2_input_init(ar2
);
875 usb_set_intfdata(interface
, ar2
);
877 interface
->needs_remote_wakeup
= 1;
882 sysfs_remove_group(&udev
->dev
.kobj
, &ati_remote2_attr_group
);
884 ati_remote2_urb_cleanup(ar2
);
886 usb_driver_release_interface(&ati_remote2_driver
, ar2
->intf
[1]);
893 static void ati_remote2_disconnect(struct usb_interface
*interface
)
895 struct ati_remote2
*ar2
;
896 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
898 if (alt
->desc
.bInterfaceNumber
)
901 ar2
= usb_get_intfdata(interface
);
902 usb_set_intfdata(interface
, NULL
);
904 input_unregister_device(ar2
->idev
);
906 sysfs_remove_group(&ar2
->udev
->dev
.kobj
, &ati_remote2_attr_group
);
908 ati_remote2_urb_cleanup(ar2
);
910 usb_driver_release_interface(&ati_remote2_driver
, ar2
->intf
[1]);
915 static int ati_remote2_suspend(struct usb_interface
*interface
,
916 pm_message_t message
)
918 struct ati_remote2
*ar2
;
919 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
921 if (alt
->desc
.bInterfaceNumber
)
924 ar2
= usb_get_intfdata(interface
);
926 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
928 mutex_lock(&ati_remote2_mutex
);
930 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
931 ati_remote2_kill_urbs(ar2
);
933 ar2
->flags
|= ATI_REMOTE2_SUSPENDED
;
935 mutex_unlock(&ati_remote2_mutex
);
940 static int ati_remote2_resume(struct usb_interface
*interface
)
942 struct ati_remote2
*ar2
;
943 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
946 if (alt
->desc
.bInterfaceNumber
)
949 ar2
= usb_get_intfdata(interface
);
951 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
953 mutex_lock(&ati_remote2_mutex
);
955 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
956 r
= ati_remote2_submit_urbs(ar2
);
959 ar2
->flags
&= ~ATI_REMOTE2_SUSPENDED
;
961 mutex_unlock(&ati_remote2_mutex
);
966 static int ati_remote2_reset_resume(struct usb_interface
*interface
)
968 struct ati_remote2
*ar2
;
969 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
972 if (alt
->desc
.bInterfaceNumber
)
975 ar2
= usb_get_intfdata(interface
);
977 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
979 mutex_lock(&ati_remote2_mutex
);
981 r
= ati_remote2_setup(ar2
, ar2
->channel_mask
);
985 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
986 r
= ati_remote2_submit_urbs(ar2
);
989 ar2
->flags
&= ~ATI_REMOTE2_SUSPENDED
;
992 mutex_unlock(&ati_remote2_mutex
);
997 static int ati_remote2_pre_reset(struct usb_interface
*interface
)
999 struct ati_remote2
*ar2
;
1000 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
1002 if (alt
->desc
.bInterfaceNumber
)
1005 ar2
= usb_get_intfdata(interface
);
1007 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
1009 mutex_lock(&ati_remote2_mutex
);
1011 if (ar2
->flags
== ATI_REMOTE2_OPENED
)
1012 ati_remote2_kill_urbs(ar2
);
1017 static int ati_remote2_post_reset(struct usb_interface
*interface
)
1019 struct ati_remote2
*ar2
;
1020 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
1023 if (alt
->desc
.bInterfaceNumber
)
1026 ar2
= usb_get_intfdata(interface
);
1028 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
1030 if (ar2
->flags
== ATI_REMOTE2_OPENED
)
1031 r
= ati_remote2_submit_urbs(ar2
);
1033 mutex_unlock(&ati_remote2_mutex
);
1038 module_usb_driver(ati_remote2_driver
);