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>
14 #define DRIVER_DESC "ATI/Philips USB RF remote driver"
15 #define DRIVER_VERSION "0.3"
17 MODULE_DESCRIPTION(DRIVER_DESC
);
18 MODULE_VERSION(DRIVER_VERSION
);
19 MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
20 MODULE_LICENSE("GPL");
23 * ATI Remote Wonder II Channel Configuration
25 * The remote control can by 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 struct kernel_param
*kp
, unsigned int max
)
48 ret
= strict_strtoul(val
, 0, &mask
);
55 *(unsigned int *)kp
->arg
= mask
;
60 static int ati_remote2_set_channel_mask(const char *val
,
61 struct kernel_param
*kp
)
63 pr_debug("%s()\n", __func__
);
65 return ati_remote2_set_mask(val
, kp
, ATI_REMOTE2_MAX_CHANNEL_MASK
);
68 static int ati_remote2_get_channel_mask(char *buffer
, struct kernel_param
*kp
)
70 pr_debug("%s()\n", __func__
);
72 return sprintf(buffer
, "0x%04x", *(unsigned int *)kp
->arg
);
75 static int ati_remote2_set_mode_mask(const char *val
, struct kernel_param
*kp
)
77 pr_debug("%s()\n", __func__
);
79 return ati_remote2_set_mask(val
, kp
, ATI_REMOTE2_MAX_MODE_MASK
);
82 static int ati_remote2_get_mode_mask(char *buffer
, struct kernel_param
*kp
)
84 pr_debug("%s()\n", __func__
);
86 return sprintf(buffer
, "0x%02x", *(unsigned int *)kp
->arg
);
89 static unsigned int channel_mask
= ATI_REMOTE2_MAX_CHANNEL_MASK
;
90 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
91 #define param_set_channel_mask ati_remote2_set_channel_mask
92 #define param_get_channel_mask ati_remote2_get_channel_mask
93 module_param(channel_mask
, channel_mask
, 0644);
94 MODULE_PARM_DESC(channel_mask
, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
96 static unsigned int mode_mask
= ATI_REMOTE2_MAX_MODE_MASK
;
97 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
98 #define param_set_mode_mask ati_remote2_set_mode_mask
99 #define param_get_mode_mask ati_remote2_get_mode_mask
100 module_param(mode_mask
, mode_mask
, 0644);
101 MODULE_PARM_DESC(mode_mask
, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
103 static struct usb_device_id ati_remote2_id_table
[] = {
104 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
107 MODULE_DEVICE_TABLE(usb
, ati_remote2_id_table
);
109 static DEFINE_MUTEX(ati_remote2_mutex
);
112 ATI_REMOTE2_OPENED
= 0x1,
113 ATI_REMOTE2_SUSPENDED
= 0x2,
125 static const struct {
128 } ati_remote2_key_table
[] = {
141 { 0x10, KEY_VOLUMEUP
},
142 { 0x11, KEY_VOLUMEDOWN
},
143 { 0x20, KEY_CHANNELUP
},
144 { 0x21, KEY_CHANNELDOWN
},
145 { 0x28, KEY_FORWARD
},
146 { 0x29, KEY_REWIND
},
150 { 0x37, KEY_RECORD
},
153 { 0x3f, KEY_PROG1
}, /* AUX1-AUX4 and PC */
167 { 0x8e, KEY_VENDOR
},
168 { 0x96, KEY_COFFEE
},
171 { 0xbe, KEY_QUESTION
},
178 struct input_dev
*idev
;
179 struct usb_device
*udev
;
181 struct usb_interface
*intf
[2];
182 struct usb_endpoint_descriptor
*ep
[2];
185 dma_addr_t buf_dma
[2];
187 unsigned long jiffies
;
193 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
194 u16 keycode
[ATI_REMOTE2_MODES
][ARRAY_SIZE(ati_remote2_key_table
)];
198 unsigned int channel_mask
;
199 unsigned int mode_mask
;
202 static int ati_remote2_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
);
203 static void ati_remote2_disconnect(struct usb_interface
*interface
);
204 static int ati_remote2_suspend(struct usb_interface
*interface
, pm_message_t message
);
205 static int ati_remote2_resume(struct usb_interface
*interface
);
206 static int ati_remote2_reset_resume(struct usb_interface
*interface
);
207 static int ati_remote2_pre_reset(struct usb_interface
*interface
);
208 static int ati_remote2_post_reset(struct usb_interface
*interface
);
210 static struct usb_driver ati_remote2_driver
= {
211 .name
= "ati_remote2",
212 .probe
= ati_remote2_probe
,
213 .disconnect
= ati_remote2_disconnect
,
214 .id_table
= ati_remote2_id_table
,
215 .suspend
= ati_remote2_suspend
,
216 .resume
= ati_remote2_resume
,
217 .reset_resume
= ati_remote2_reset_resume
,
218 .pre_reset
= ati_remote2_pre_reset
,
219 .post_reset
= ati_remote2_post_reset
,
220 .supports_autosuspend
= 1,
223 static int ati_remote2_submit_urbs(struct ati_remote2
*ar2
)
227 r
= usb_submit_urb(ar2
->urb
[0], GFP_KERNEL
);
229 dev_err(&ar2
->intf
[0]->dev
,
230 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
233 r
= usb_submit_urb(ar2
->urb
[1], GFP_KERNEL
);
235 usb_kill_urb(ar2
->urb
[0]);
236 dev_err(&ar2
->intf
[1]->dev
,
237 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
244 static void ati_remote2_kill_urbs(struct ati_remote2
*ar2
)
246 usb_kill_urb(ar2
->urb
[1]);
247 usb_kill_urb(ar2
->urb
[0]);
250 static int ati_remote2_open(struct input_dev
*idev
)
252 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
255 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
257 r
= usb_autopm_get_interface(ar2
->intf
[0]);
259 dev_err(&ar2
->intf
[0]->dev
,
260 "%s(): usb_autopm_get_interface() = %d\n", __func__
, r
);
264 mutex_lock(&ati_remote2_mutex
);
266 if (!(ar2
->flags
& ATI_REMOTE2_SUSPENDED
)) {
267 r
= ati_remote2_submit_urbs(ar2
);
272 ar2
->flags
|= ATI_REMOTE2_OPENED
;
274 mutex_unlock(&ati_remote2_mutex
);
276 usb_autopm_put_interface(ar2
->intf
[0]);
281 mutex_unlock(&ati_remote2_mutex
);
282 usb_autopm_put_interface(ar2
->intf
[0]);
287 static void ati_remote2_close(struct input_dev
*idev
)
289 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
291 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
293 mutex_lock(&ati_remote2_mutex
);
295 if (!(ar2
->flags
& ATI_REMOTE2_SUSPENDED
))
296 ati_remote2_kill_urbs(ar2
);
298 ar2
->flags
&= ~ATI_REMOTE2_OPENED
;
300 mutex_unlock(&ati_remote2_mutex
);
303 static void ati_remote2_input_mouse(struct ati_remote2
*ar2
)
305 struct input_dev
*idev
= ar2
->idev
;
306 u8
*data
= ar2
->buf
[0];
309 channel
= data
[0] >> 4;
311 if (!((1 << channel
) & ar2
->channel_mask
))
314 mode
= data
[0] & 0x0F;
316 if (mode
> ATI_REMOTE2_PC
) {
317 dev_err(&ar2
->intf
[0]->dev
,
318 "Unknown mode byte (%02x %02x %02x %02x)\n",
319 data
[3], data
[2], data
[1], data
[0]);
323 if (!((1 << mode
) & ar2
->mode_mask
))
326 input_event(idev
, EV_REL
, REL_X
, (s8
) data
[1]);
327 input_event(idev
, EV_REL
, REL_Y
, (s8
) data
[2]);
331 static int ati_remote2_lookup(unsigned int hw_code
)
335 for (i
= 0; i
< ARRAY_SIZE(ati_remote2_key_table
); i
++)
336 if (ati_remote2_key_table
[i
].hw_code
== hw_code
)
342 static void ati_remote2_input_key(struct ati_remote2
*ar2
)
344 struct input_dev
*idev
= ar2
->idev
;
345 u8
*data
= ar2
->buf
[1];
346 int channel
, mode
, hw_code
, index
;
348 channel
= data
[0] >> 4;
350 if (!((1 << channel
) & ar2
->channel_mask
))
353 mode
= data
[0] & 0x0F;
355 if (mode
> ATI_REMOTE2_PC
) {
356 dev_err(&ar2
->intf
[1]->dev
,
357 "Unknown mode byte (%02x %02x %02x %02x)\n",
358 data
[3], data
[2], data
[1], data
[0]);
363 if (hw_code
== 0x3f) {
365 * For some incomprehensible reason the mouse pad generates
366 * events which look identical to the events from the last
367 * pressed mode key. Naturally we don't want to generate key
368 * events for the mouse pad so we filter out any subsequent
369 * events from the same mode key.
371 if (ar2
->mode
== mode
)
378 if (!((1 << mode
) & ar2
->mode_mask
))
381 index
= ati_remote2_lookup(hw_code
);
383 dev_err(&ar2
->intf
[1]->dev
,
384 "Unknown code byte (%02x %02x %02x %02x)\n",
385 data
[3], data
[2], data
[1], data
[0]);
390 case 0: /* release */
393 ar2
->jiffies
= jiffies
+ msecs_to_jiffies(idev
->rep
[REP_DELAY
]);
397 /* No repeat for mouse buttons. */
398 if (ar2
->keycode
[mode
][index
] == BTN_LEFT
||
399 ar2
->keycode
[mode
][index
] == BTN_RIGHT
)
402 if (!time_after_eq(jiffies
, ar2
->jiffies
))
405 ar2
->jiffies
= jiffies
+ msecs_to_jiffies(idev
->rep
[REP_PERIOD
]);
408 dev_err(&ar2
->intf
[1]->dev
,
409 "Unknown state byte (%02x %02x %02x %02x)\n",
410 data
[3], data
[2], data
[1], data
[0]);
414 input_event(idev
, EV_KEY
, ar2
->keycode
[mode
][index
], data
[1]);
418 static void ati_remote2_complete_mouse(struct urb
*urb
)
420 struct ati_remote2
*ar2
= urb
->context
;
423 switch (urb
->status
) {
425 usb_mark_last_busy(ar2
->udev
);
426 ati_remote2_input_mouse(ar2
);
432 dev_dbg(&ar2
->intf
[0]->dev
,
433 "%s(): urb status = %d\n", __func__
, urb
->status
);
436 usb_mark_last_busy(ar2
->udev
);
437 dev_err(&ar2
->intf
[0]->dev
,
438 "%s(): urb status = %d\n", __func__
, urb
->status
);
441 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
443 dev_err(&ar2
->intf
[0]->dev
,
444 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
447 static void ati_remote2_complete_key(struct urb
*urb
)
449 struct ati_remote2
*ar2
= urb
->context
;
452 switch (urb
->status
) {
454 usb_mark_last_busy(ar2
->udev
);
455 ati_remote2_input_key(ar2
);
461 dev_dbg(&ar2
->intf
[1]->dev
,
462 "%s(): urb status = %d\n", __func__
, urb
->status
);
465 usb_mark_last_busy(ar2
->udev
);
466 dev_err(&ar2
->intf
[1]->dev
,
467 "%s(): urb status = %d\n", __func__
, urb
->status
);
470 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
472 dev_err(&ar2
->intf
[1]->dev
,
473 "%s(): usb_submit_urb() = %d\n", __func__
, r
);
476 static int ati_remote2_getkeycode(struct input_dev
*idev
,
477 int scancode
, int *keycode
)
479 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
482 mode
= scancode
>> 8;
483 if (mode
> ATI_REMOTE2_PC
|| !((1 << mode
) & ar2
->mode_mask
))
486 index
= ati_remote2_lookup(scancode
& 0xFF);
490 *keycode
= ar2
->keycode
[mode
][index
];
494 static int ati_remote2_setkeycode(struct input_dev
*idev
, int scancode
, int keycode
)
496 struct ati_remote2
*ar2
= input_get_drvdata(idev
);
497 int index
, mode
, old_keycode
;
499 mode
= scancode
>> 8;
500 if (mode
> ATI_REMOTE2_PC
|| !((1 << mode
) & ar2
->mode_mask
))
503 index
= ati_remote2_lookup(scancode
& 0xFF);
507 if (keycode
< KEY_RESERVED
|| keycode
> KEY_MAX
)
510 old_keycode
= ar2
->keycode
[mode
][index
];
511 ar2
->keycode
[mode
][index
] = keycode
;
512 set_bit(keycode
, idev
->keybit
);
514 for (mode
= 0; mode
< ATI_REMOTE2_MODES
; mode
++) {
515 for (index
= 0; index
< ARRAY_SIZE(ati_remote2_key_table
); index
++) {
516 if (ar2
->keycode
[mode
][index
] == old_keycode
)
521 clear_bit(old_keycode
, idev
->keybit
);
526 static int ati_remote2_input_init(struct ati_remote2
*ar2
)
528 struct input_dev
*idev
;
529 int index
, mode
, retval
;
531 idev
= input_allocate_device();
536 input_set_drvdata(idev
, ar2
);
538 idev
->evbit
[0] = BIT_MASK(EV_KEY
) | BIT_MASK(EV_REP
) | BIT_MASK(EV_REL
);
539 idev
->keybit
[BIT_WORD(BTN_MOUSE
)] = BIT_MASK(BTN_LEFT
) |
541 idev
->relbit
[0] = BIT_MASK(REL_X
) | BIT_MASK(REL_Y
);
543 for (mode
= 0; mode
< ATI_REMOTE2_MODES
; mode
++) {
544 for (index
= 0; index
< ARRAY_SIZE(ati_remote2_key_table
); index
++) {
545 ar2
->keycode
[mode
][index
] = ati_remote2_key_table
[index
].keycode
;
546 set_bit(ar2
->keycode
[mode
][index
], idev
->keybit
);
550 /* AUX1-AUX4 and PC generate the same scancode. */
551 index
= ati_remote2_lookup(0x3f);
552 ar2
->keycode
[ATI_REMOTE2_AUX1
][index
] = KEY_PROG1
;
553 ar2
->keycode
[ATI_REMOTE2_AUX2
][index
] = KEY_PROG2
;
554 ar2
->keycode
[ATI_REMOTE2_AUX3
][index
] = KEY_PROG3
;
555 ar2
->keycode
[ATI_REMOTE2_AUX4
][index
] = KEY_PROG4
;
556 ar2
->keycode
[ATI_REMOTE2_PC
][index
] = KEY_PC
;
557 set_bit(KEY_PROG1
, idev
->keybit
);
558 set_bit(KEY_PROG2
, idev
->keybit
);
559 set_bit(KEY_PROG3
, idev
->keybit
);
560 set_bit(KEY_PROG4
, idev
->keybit
);
561 set_bit(KEY_PC
, idev
->keybit
);
563 idev
->rep
[REP_DELAY
] = 250;
564 idev
->rep
[REP_PERIOD
] = 33;
566 idev
->open
= ati_remote2_open
;
567 idev
->close
= ati_remote2_close
;
569 idev
->getkeycode
= ati_remote2_getkeycode
;
570 idev
->setkeycode
= ati_remote2_setkeycode
;
572 idev
->name
= ar2
->name
;
573 idev
->phys
= ar2
->phys
;
575 usb_to_input_id(ar2
->udev
, &idev
->id
);
576 idev
->dev
.parent
= &ar2
->udev
->dev
;
578 retval
= input_register_device(idev
);
580 input_free_device(idev
);
585 static int ati_remote2_urb_init(struct ati_remote2
*ar2
)
587 struct usb_device
*udev
= ar2
->udev
;
590 for (i
= 0; i
< 2; i
++) {
591 ar2
->buf
[i
] = usb_buffer_alloc(udev
, 4, GFP_KERNEL
, &ar2
->buf_dma
[i
]);
595 ar2
->urb
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
599 pipe
= usb_rcvintpipe(udev
, ar2
->ep
[i
]->bEndpointAddress
);
600 maxp
= usb_maxpacket(udev
, pipe
, usb_pipeout(pipe
));
601 maxp
= maxp
> 4 ? 4 : maxp
;
603 usb_fill_int_urb(ar2
->urb
[i
], udev
, pipe
, ar2
->buf
[i
], maxp
,
604 i
? ati_remote2_complete_key
: ati_remote2_complete_mouse
,
605 ar2
, ar2
->ep
[i
]->bInterval
);
606 ar2
->urb
[i
]->transfer_dma
= ar2
->buf_dma
[i
];
607 ar2
->urb
[i
]->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
613 static void ati_remote2_urb_cleanup(struct ati_remote2
*ar2
)
617 for (i
= 0; i
< 2; i
++) {
618 usb_free_urb(ar2
->urb
[i
]);
619 usb_buffer_free(ar2
->udev
, 4, ar2
->buf
[i
], ar2
->buf_dma
[i
]);
623 static int ati_remote2_setup(struct ati_remote2
*ar2
, unsigned int ch_mask
)
628 * Configure receiver to only accept input from remote "channel"
629 * channel == 0 -> Accept input from any remote channel
630 * channel == 1 -> Only accept input from remote channel 1
631 * channel == 2 -> Only accept input from remote channel 2
633 * channel == 16 -> Only accept input from remote channel 16
637 for (i
= 0; i
< 16; i
++) {
638 if ((1 << i
) & ch_mask
) {
639 if (!(~(1 << i
) & ch_mask
))
645 r
= usb_control_msg(ar2
->udev
, usb_sndctrlpipe(ar2
->udev
, 0),
647 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_INTERFACE
,
648 channel
, 0x0, NULL
, 0, USB_CTRL_SET_TIMEOUT
);
650 dev_err(&ar2
->udev
->dev
, "%s - failed to set channel due to error: %d\n",
658 static ssize_t
ati_remote2_show_channel_mask(struct device
*dev
,
659 struct device_attribute
*attr
,
662 struct usb_device
*udev
= to_usb_device(dev
);
663 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
664 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
666 return sprintf(buf
, "0x%04x\n", ar2
->channel_mask
);
669 static ssize_t
ati_remote2_store_channel_mask(struct device
*dev
,
670 struct device_attribute
*attr
,
671 const char *buf
, size_t count
)
673 struct usb_device
*udev
= to_usb_device(dev
);
674 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
675 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
679 if (strict_strtoul(buf
, 0, &mask
))
682 if (mask
& ~ATI_REMOTE2_MAX_CHANNEL_MASK
)
685 r
= usb_autopm_get_interface(ar2
->intf
[0]);
687 dev_err(&ar2
->intf
[0]->dev
,
688 "%s(): usb_autopm_get_interface() = %d\n", __func__
, r
);
692 mutex_lock(&ati_remote2_mutex
);
694 if (mask
!= ar2
->channel_mask
&& !ati_remote2_setup(ar2
, mask
))
695 ar2
->channel_mask
= mask
;
697 mutex_unlock(&ati_remote2_mutex
);
699 usb_autopm_put_interface(ar2
->intf
[0]);
704 static ssize_t
ati_remote2_show_mode_mask(struct device
*dev
,
705 struct device_attribute
*attr
,
708 struct usb_device
*udev
= to_usb_device(dev
);
709 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
710 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
712 return sprintf(buf
, "0x%02x\n", ar2
->mode_mask
);
715 static ssize_t
ati_remote2_store_mode_mask(struct device
*dev
,
716 struct device_attribute
*attr
,
717 const char *buf
, size_t count
)
719 struct usb_device
*udev
= to_usb_device(dev
);
720 struct usb_interface
*intf
= usb_ifnum_to_if(udev
, 0);
721 struct ati_remote2
*ar2
= usb_get_intfdata(intf
);
724 if (strict_strtoul(buf
, 0, &mask
))
727 if (mask
& ~ATI_REMOTE2_MAX_MODE_MASK
)
730 ar2
->mode_mask
= mask
;
735 static DEVICE_ATTR(channel_mask
, 0644, ati_remote2_show_channel_mask
,
736 ati_remote2_store_channel_mask
);
738 static DEVICE_ATTR(mode_mask
, 0644, ati_remote2_show_mode_mask
,
739 ati_remote2_store_mode_mask
);
741 static struct attribute
*ati_remote2_attrs
[] = {
742 &dev_attr_channel_mask
.attr
,
743 &dev_attr_mode_mask
.attr
,
747 static struct attribute_group ati_remote2_attr_group
= {
748 .attrs
= ati_remote2_attrs
,
751 static int ati_remote2_probe(struct usb_interface
*interface
, const struct usb_device_id
*id
)
753 struct usb_device
*udev
= interface_to_usbdev(interface
);
754 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
755 struct ati_remote2
*ar2
;
758 if (alt
->desc
.bInterfaceNumber
)
761 ar2
= kzalloc(sizeof (struct ati_remote2
), GFP_KERNEL
);
767 ar2
->intf
[0] = interface
;
768 ar2
->ep
[0] = &alt
->endpoint
[0].desc
;
770 ar2
->intf
[1] = usb_ifnum_to_if(udev
, 1);
771 r
= usb_driver_claim_interface(&ati_remote2_driver
, ar2
->intf
[1], ar2
);
774 alt
= ar2
->intf
[1]->cur_altsetting
;
775 ar2
->ep
[1] = &alt
->endpoint
[0].desc
;
777 r
= ati_remote2_urb_init(ar2
);
781 ar2
->channel_mask
= channel_mask
;
782 ar2
->mode_mask
= mode_mask
;
784 r
= ati_remote2_setup(ar2
, ar2
->channel_mask
);
788 usb_make_path(udev
, ar2
->phys
, sizeof(ar2
->phys
));
789 strlcat(ar2
->phys
, "/input0", sizeof(ar2
->phys
));
791 strlcat(ar2
->name
, "ATI Remote Wonder II", sizeof(ar2
->name
));
793 r
= sysfs_create_group(&udev
->dev
.kobj
, &ati_remote2_attr_group
);
797 r
= ati_remote2_input_init(ar2
);
801 usb_set_intfdata(interface
, ar2
);
803 interface
->needs_remote_wakeup
= 1;
808 sysfs_remove_group(&udev
->dev
.kobj
, &ati_remote2_attr_group
);
810 ati_remote2_urb_cleanup(ar2
);
811 usb_driver_release_interface(&ati_remote2_driver
, ar2
->intf
[1]);
818 static void ati_remote2_disconnect(struct usb_interface
*interface
)
820 struct ati_remote2
*ar2
;
821 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
823 if (alt
->desc
.bInterfaceNumber
)
826 ar2
= usb_get_intfdata(interface
);
827 usb_set_intfdata(interface
, NULL
);
829 input_unregister_device(ar2
->idev
);
831 sysfs_remove_group(&ar2
->udev
->dev
.kobj
, &ati_remote2_attr_group
);
833 ati_remote2_urb_cleanup(ar2
);
835 usb_driver_release_interface(&ati_remote2_driver
, ar2
->intf
[1]);
840 static int ati_remote2_suspend(struct usb_interface
*interface
,
841 pm_message_t message
)
843 struct ati_remote2
*ar2
;
844 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
846 if (alt
->desc
.bInterfaceNumber
)
849 ar2
= usb_get_intfdata(interface
);
851 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
853 mutex_lock(&ati_remote2_mutex
);
855 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
856 ati_remote2_kill_urbs(ar2
);
858 ar2
->flags
|= ATI_REMOTE2_SUSPENDED
;
860 mutex_unlock(&ati_remote2_mutex
);
865 static int ati_remote2_resume(struct usb_interface
*interface
)
867 struct ati_remote2
*ar2
;
868 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
871 if (alt
->desc
.bInterfaceNumber
)
874 ar2
= usb_get_intfdata(interface
);
876 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
878 mutex_lock(&ati_remote2_mutex
);
880 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
881 r
= ati_remote2_submit_urbs(ar2
);
884 ar2
->flags
&= ~ATI_REMOTE2_SUSPENDED
;
886 mutex_unlock(&ati_remote2_mutex
);
891 static int ati_remote2_reset_resume(struct usb_interface
*interface
)
893 struct ati_remote2
*ar2
;
894 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
897 if (alt
->desc
.bInterfaceNumber
)
900 ar2
= usb_get_intfdata(interface
);
902 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
904 mutex_lock(&ati_remote2_mutex
);
906 r
= ati_remote2_setup(ar2
, ar2
->channel_mask
);
910 if (ar2
->flags
& ATI_REMOTE2_OPENED
)
911 r
= ati_remote2_submit_urbs(ar2
);
914 ar2
->flags
&= ~ATI_REMOTE2_SUSPENDED
;
917 mutex_unlock(&ati_remote2_mutex
);
922 static int ati_remote2_pre_reset(struct usb_interface
*interface
)
924 struct ati_remote2
*ar2
;
925 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
927 if (alt
->desc
.bInterfaceNumber
)
930 ar2
= usb_get_intfdata(interface
);
932 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
934 mutex_lock(&ati_remote2_mutex
);
936 if (ar2
->flags
== ATI_REMOTE2_OPENED
)
937 ati_remote2_kill_urbs(ar2
);
942 static int ati_remote2_post_reset(struct usb_interface
*interface
)
944 struct ati_remote2
*ar2
;
945 struct usb_host_interface
*alt
= interface
->cur_altsetting
;
948 if (alt
->desc
.bInterfaceNumber
)
951 ar2
= usb_get_intfdata(interface
);
953 dev_dbg(&ar2
->intf
[0]->dev
, "%s()\n", __func__
);
955 if (ar2
->flags
== ATI_REMOTE2_OPENED
)
956 r
= ati_remote2_submit_urbs(ar2
);
958 mutex_unlock(&ati_remote2_mutex
);
963 static int __init
ati_remote2_init(void)
967 r
= usb_register(&ati_remote2_driver
);
969 printk(KERN_ERR
"ati_remote2: usb_register() = %d\n", r
);
971 printk(KERN_INFO
"ati_remote2: " DRIVER_DESC
" " DRIVER_VERSION
"\n");
976 static void __exit
ati_remote2_exit(void)
978 usb_deregister(&ati_remote2_driver
);
981 module_init(ati_remote2_init
);
982 module_exit(ati_remote2_exit
);