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"
17 #define DRIVER_VERSION "0.3"
19 MODULE_DESCRIPTION(DRIVER_DESC);
20 MODULE_VERSION(DRIVER_VERSION);
21 MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
22 MODULE_LICENSE("GPL");
25 * ATI Remote Wonder II Channel Configuration
27 * The remote control can by assigned one of sixteen "channels" in order to facilitate
28 * the use of multiple remote controls within range of each other.
29 * A remote's "channel" may be altered by pressing and holding the "PC" button for
30 * approximately 3 seconds, after which the button will slowly flash the count of the
31 * currently configured "channel", using the numeric keypad enter a number between 1 and
32 * 16 and then press the "PC" button again, the button will slowly flash the count of the
33 * newly configured "channel".
37 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
38 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
41 static int ati_remote2_set_mask(const char *val,
42 const struct kernel_param *kp,
51 ret = kstrtouint(val, 0, &mask);
58 *(unsigned int *)kp->arg = mask;
63 static int ati_remote2_set_channel_mask(const char *val,
64 const struct kernel_param *kp)
66 pr_debug("%s()\n", __func__);
68 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
71 static int ati_remote2_get_channel_mask(char *buffer,
72 const struct kernel_param *kp)
74 pr_debug("%s()\n", __func__);
76 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
79 static int ati_remote2_set_mode_mask(const char *val,
80 const struct kernel_param *kp)
82 pr_debug("%s()\n", __func__);
84 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
87 static int ati_remote2_get_mode_mask(char *buffer,
88 const struct kernel_param *kp)
90 pr_debug("%s()\n", __func__);
92 return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
95 static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
96 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
97 static struct kernel_param_ops param_ops_channel_mask = {
98 .set = ati_remote2_set_channel_mask,
99 .get = ati_remote2_get_channel_mask,
101 module_param(channel_mask, channel_mask, 0644);
102 MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
104 static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
105 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
106 static struct kernel_param_ops param_ops_mode_mask = {
107 .set = ati_remote2_set_mode_mask,
108 .get = ati_remote2_get_mode_mask,
110 module_param(mode_mask, mode_mask, 0644);
111 MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
113 static struct usb_device_id ati_remote2_id_table[] = {
114 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
117 MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
119 static DEFINE_MUTEX(ati_remote2_mutex);
122 ATI_REMOTE2_OPENED = 0x1,
123 ATI_REMOTE2_SUSPENDED = 0x2,
135 static const struct {
138 } ati_remote2_key_table[] = {
151 { 0x10, KEY_VOLUMEUP },
152 { 0x11, KEY_VOLUMEDOWN },
153 { 0x20, KEY_CHANNELUP },
154 { 0x21, KEY_CHANNELDOWN },
155 { 0x28, KEY_FORWARD },
156 { 0x29, KEY_REWIND },
160 { 0x37, KEY_RECORD },
163 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
177 { 0x8e, KEY_VENDOR },
178 { 0x96, KEY_COFFEE },
181 { 0xbe, KEY_QUESTION },
188 struct input_dev *idev;
189 struct usb_device *udev;
191 struct usb_interface *intf[2];
192 struct usb_endpoint_descriptor *ep[2];
195 dma_addr_t buf_dma[2];
197 unsigned long jiffies;
203 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
204 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
208 unsigned int channel_mask;
209 unsigned int mode_mask;
212 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
213 static void ati_remote2_disconnect(struct usb_interface *interface);
214 static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
215 static int ati_remote2_resume(struct usb_interface *interface);
216 static int ati_remote2_reset_resume(struct usb_interface *interface);
217 static int ati_remote2_pre_reset(struct usb_interface *interface);
218 static int ati_remote2_post_reset(struct usb_interface *interface);
220 static struct usb_driver ati_remote2_driver = {
221 .name = "ati_remote2",
222 .probe = ati_remote2_probe,
223 .disconnect = ati_remote2_disconnect,
224 .id_table = ati_remote2_id_table,
225 .suspend = ati_remote2_suspend,
226 .resume = ati_remote2_resume,
227 .reset_resume = ati_remote2_reset_resume,
228 .pre_reset = ati_remote2_pre_reset,
229 .post_reset = ati_remote2_post_reset,
230 .supports_autosuspend = 1,
233 static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
237 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
239 dev_err(&ar2->intf[0]->dev,
240 "%s(): usb_submit_urb() = %d\n", __func__, r);
243 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
245 usb_kill_urb(ar2->urb[0]);
246 dev_err(&ar2->intf[1]->dev,
247 "%s(): usb_submit_urb() = %d\n", __func__, r);
254 static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
256 usb_kill_urb(ar2->urb[1]);
257 usb_kill_urb(ar2->urb[0]);
260 static int ati_remote2_open(struct input_dev *idev)
262 struct ati_remote2 *ar2 = input_get_drvdata(idev);
265 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
267 r = usb_autopm_get_interface(ar2->intf[0]);
269 dev_err(&ar2->intf[0]->dev,
270 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
274 mutex_lock(&ati_remote2_mutex);
276 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
277 r = ati_remote2_submit_urbs(ar2);
282 ar2->flags |= ATI_REMOTE2_OPENED;
284 mutex_unlock(&ati_remote2_mutex);
286 usb_autopm_put_interface(ar2->intf[0]);
291 mutex_unlock(&ati_remote2_mutex);
292 usb_autopm_put_interface(ar2->intf[0]);
297 static void ati_remote2_close(struct input_dev *idev)
299 struct ati_remote2 *ar2 = input_get_drvdata(idev);
301 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
303 mutex_lock(&ati_remote2_mutex);
305 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
306 ati_remote2_kill_urbs(ar2);
308 ar2->flags &= ~ATI_REMOTE2_OPENED;
310 mutex_unlock(&ati_remote2_mutex);
313 static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
315 struct input_dev *idev = ar2->idev;
316 u8 *data = ar2->buf[0];
319 channel = data[0] >> 4;
321 if (!((1 << channel) & ar2->channel_mask))
324 mode = data[0] & 0x0F;
326 if (mode > ATI_REMOTE2_PC) {
327 dev_err(&ar2->intf[0]->dev,
328 "Unknown mode byte (%02x %02x %02x %02x)\n",
329 data[3], data[2], data[1], data[0]);
333 if (!((1 << mode) & ar2->mode_mask))
336 input_event(idev, EV_REL, REL_X, (s8) data[1]);
337 input_event(idev, EV_REL, REL_Y, (s8) data[2]);
341 static int ati_remote2_lookup(unsigned int hw_code)
345 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
346 if (ati_remote2_key_table[i].hw_code == hw_code)
352 static void ati_remote2_input_key(struct ati_remote2 *ar2)
354 struct input_dev *idev = ar2->idev;
355 u8 *data = ar2->buf[1];
356 int channel, mode, hw_code, index;
358 channel = data[0] >> 4;
360 if (!((1 << channel) & ar2->channel_mask))
363 mode = data[0] & 0x0F;
365 if (mode > ATI_REMOTE2_PC) {
366 dev_err(&ar2->intf[1]->dev,
367 "Unknown mode byte (%02x %02x %02x %02x)\n",
368 data[3], data[2], data[1], data[0]);
373 if (hw_code == 0x3f) {
375 * For some incomprehensible reason the mouse pad generates
376 * events which look identical to the events from the last
377 * pressed mode key. Naturally we don't want to generate key
378 * events for the mouse pad so we filter out any subsequent
379 * events from the same mode key.
381 if (ar2->mode == mode)
388 if (!((1 << mode) & ar2->mode_mask))
391 index = ati_remote2_lookup(hw_code);
393 dev_err(&ar2->intf[1]->dev,
394 "Unknown code byte (%02x %02x %02x %02x)\n",
395 data[3], data[2], data[1], data[0]);
400 case 0: /* release */
403 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
407 /* No repeat for mouse buttons. */
408 if (ar2->keycode[mode][index] == BTN_LEFT ||
409 ar2->keycode[mode][index] == BTN_RIGHT)
412 if (!time_after_eq(jiffies, ar2->jiffies))
415 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
418 dev_err(&ar2->intf[1]->dev,
419 "Unknown state byte (%02x %02x %02x %02x)\n",
420 data[3], data[2], data[1], data[0]);
424 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
428 static void ati_remote2_complete_mouse(struct urb *urb)
430 struct ati_remote2 *ar2 = urb->context;
433 switch (urb->status) {
435 usb_mark_last_busy(ar2->udev);
436 ati_remote2_input_mouse(ar2);
442 dev_dbg(&ar2->intf[0]->dev,
443 "%s(): urb status = %d\n", __func__, urb->status);
446 usb_mark_last_busy(ar2->udev);
447 dev_err(&ar2->intf[0]->dev,
448 "%s(): urb status = %d\n", __func__, urb->status);
451 r = usb_submit_urb(urb, GFP_ATOMIC);
453 dev_err(&ar2->intf[0]->dev,
454 "%s(): usb_submit_urb() = %d\n", __func__, r);
457 static void ati_remote2_complete_key(struct urb *urb)
459 struct ati_remote2 *ar2 = urb->context;
462 switch (urb->status) {
464 usb_mark_last_busy(ar2->udev);
465 ati_remote2_input_key(ar2);
471 dev_dbg(&ar2->intf[1]->dev,
472 "%s(): urb status = %d\n", __func__, urb->status);
475 usb_mark_last_busy(ar2->udev);
476 dev_err(&ar2->intf[1]->dev,
477 "%s(): urb status = %d\n", __func__, urb->status);
480 r = usb_submit_urb(urb, GFP_ATOMIC);
482 dev_err(&ar2->intf[1]->dev,
483 "%s(): usb_submit_urb() = %d\n", __func__, r);
486 static int ati_remote2_getkeycode(struct input_dev *idev,
487 struct input_keymap_entry *ke)
489 struct ati_remote2 *ar2 = input_get_drvdata(idev);
493 unsigned int scancode;
495 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
497 if (index >= ATI_REMOTE2_MODES *
498 ARRAY_SIZE(ati_remote2_key_table))
501 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
502 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
503 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
505 if (input_scancode_to_scalar(ke, &scancode))
508 mode = scancode >> 8;
509 if (mode > ATI_REMOTE2_PC)
512 offset = ati_remote2_lookup(scancode & 0xff);
516 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
519 ke->keycode = ar2->keycode[mode][offset];
520 ke->len = sizeof(scancode);
521 memcpy(&ke->scancode, &scancode, sizeof(scancode));
527 static int ati_remote2_setkeycode(struct input_dev *idev,
528 const struct input_keymap_entry *ke,
529 unsigned int *old_keycode)
531 struct ati_remote2 *ar2 = input_get_drvdata(idev);
535 unsigned int scancode;
537 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
538 if (ke->index >= ATI_REMOTE2_MODES *
539 ARRAY_SIZE(ati_remote2_key_table))
542 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
543 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
545 if (input_scancode_to_scalar(ke, &scancode))
548 mode = scancode >> 8;
549 if (mode > ATI_REMOTE2_PC)
552 offset = ati_remote2_lookup(scancode & 0xff);
557 *old_keycode = ar2->keycode[mode][offset];
558 ar2->keycode[mode][offset] = ke->keycode;
559 __set_bit(ke->keycode, idev->keybit);
561 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
562 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
563 if (ar2->keycode[mode][index] == *old_keycode)
568 __clear_bit(*old_keycode, idev->keybit);
573 static int ati_remote2_input_init(struct ati_remote2 *ar2)
575 struct input_dev *idev;
576 int index, mode, retval;
578 idev = input_allocate_device();
583 input_set_drvdata(idev, ar2);
585 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
586 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
588 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
590 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
591 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
592 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
593 __set_bit(ar2->keycode[mode][index], idev->keybit);
597 /* AUX1-AUX4 and PC generate the same scancode. */
598 index = ati_remote2_lookup(0x3f);
599 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
600 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
601 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
602 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
603 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
604 __set_bit(KEY_PROG1, idev->keybit);
605 __set_bit(KEY_PROG2, idev->keybit);
606 __set_bit(KEY_PROG3, idev->keybit);
607 __set_bit(KEY_PROG4, idev->keybit);
608 __set_bit(KEY_PC, idev->keybit);
610 idev->rep[REP_DELAY] = 250;
611 idev->rep[REP_PERIOD] = 33;
613 idev->open = ati_remote2_open;
614 idev->close = ati_remote2_close;
616 idev->getkeycode = ati_remote2_getkeycode;
617 idev->setkeycode = ati_remote2_setkeycode;
619 idev->name = ar2->name;
620 idev->phys = ar2->phys;
622 usb_to_input_id(ar2->udev, &idev->id);
623 idev->dev.parent = &ar2->udev->dev;
625 retval = input_register_device(idev);
627 input_free_device(idev);
632 static int ati_remote2_urb_init(struct ati_remote2 *ar2)
634 struct usb_device *udev = ar2->udev;
637 for (i = 0; i < 2; i++) {
638 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
642 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
646 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
647 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
648 maxp = maxp > 4 ? 4 : maxp;
650 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
651 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
652 ar2, ar2->ep[i]->bInterval);
653 ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
654 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
660 static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
664 for (i = 0; i < 2; i++) {
665 usb_free_urb(ar2->urb[i]);
666 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
670 static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
675 * Configure receiver to only accept input from remote "channel"
676 * channel == 0 -> Accept input from any remote channel
677 * channel == 1 -> Only accept input from remote channel 1
678 * channel == 2 -> Only accept input from remote channel 2
680 * channel == 16 -> Only accept input from remote channel 16
684 for (i = 0; i < 16; i++) {
685 if ((1 << i) & ch_mask) {
686 if (!(~(1 << i) & ch_mask))
692 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
694 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
695 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
697 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
705 static ssize_t ati_remote2_show_channel_mask(struct device *dev,
706 struct device_attribute *attr,
709 struct usb_device *udev = to_usb_device(dev);
710 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
711 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
713 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
716 static ssize_t ati_remote2_store_channel_mask(struct device *dev,
717 struct device_attribute *attr,
718 const char *buf, size_t count)
720 struct usb_device *udev = to_usb_device(dev);
721 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
722 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
726 r = kstrtouint(buf, 0, &mask);
730 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
733 r = usb_autopm_get_interface(ar2->intf[0]);
735 dev_err(&ar2->intf[0]->dev,
736 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
740 mutex_lock(&ati_remote2_mutex);
742 if (mask != ar2->channel_mask) {
743 r = ati_remote2_setup(ar2, mask);
745 ar2->channel_mask = mask;
748 mutex_unlock(&ati_remote2_mutex);
750 usb_autopm_put_interface(ar2->intf[0]);
752 return r ? r : count;
755 static ssize_t ati_remote2_show_mode_mask(struct device *dev,
756 struct device_attribute *attr,
759 struct usb_device *udev = to_usb_device(dev);
760 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
761 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
763 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
766 static ssize_t ati_remote2_store_mode_mask(struct device *dev,
767 struct device_attribute *attr,
768 const char *buf, size_t count)
770 struct usb_device *udev = to_usb_device(dev);
771 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
772 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
776 err = kstrtouint(buf, 0, &mask);
780 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
783 ar2->mode_mask = mask;
788 static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
789 ati_remote2_store_channel_mask);
791 static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
792 ati_remote2_store_mode_mask);
794 static struct attribute *ati_remote2_attrs[] = {
795 &dev_attr_channel_mask.attr,
796 &dev_attr_mode_mask.attr,
800 static struct attribute_group ati_remote2_attr_group = {
801 .attrs = ati_remote2_attrs,
804 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
806 struct usb_device *udev = interface_to_usbdev(interface);
807 struct usb_host_interface *alt = interface->cur_altsetting;
808 struct ati_remote2 *ar2;
811 if (alt->desc.bInterfaceNumber)
814 ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
820 ar2->intf[0] = interface;
821 ar2->ep[0] = &alt->endpoint[0].desc;
823 ar2->intf[1] = usb_ifnum_to_if(udev, 1);
824 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
827 alt = ar2->intf[1]->cur_altsetting;
828 ar2->ep[1] = &alt->endpoint[0].desc;
830 r = ati_remote2_urb_init(ar2);
834 ar2->channel_mask = channel_mask;
835 ar2->mode_mask = mode_mask;
837 r = ati_remote2_setup(ar2, ar2->channel_mask);
841 usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
842 strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
844 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
846 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
850 r = ati_remote2_input_init(ar2);
854 usb_set_intfdata(interface, ar2);
856 interface->needs_remote_wakeup = 1;
861 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
863 ati_remote2_urb_cleanup(ar2);
864 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
871 static void ati_remote2_disconnect(struct usb_interface *interface)
873 struct ati_remote2 *ar2;
874 struct usb_host_interface *alt = interface->cur_altsetting;
876 if (alt->desc.bInterfaceNumber)
879 ar2 = usb_get_intfdata(interface);
880 usb_set_intfdata(interface, NULL);
882 input_unregister_device(ar2->idev);
884 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
886 ati_remote2_urb_cleanup(ar2);
888 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
893 static int ati_remote2_suspend(struct usb_interface *interface,
894 pm_message_t message)
896 struct ati_remote2 *ar2;
897 struct usb_host_interface *alt = interface->cur_altsetting;
899 if (alt->desc.bInterfaceNumber)
902 ar2 = usb_get_intfdata(interface);
904 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
906 mutex_lock(&ati_remote2_mutex);
908 if (ar2->flags & ATI_REMOTE2_OPENED)
909 ati_remote2_kill_urbs(ar2);
911 ar2->flags |= ATI_REMOTE2_SUSPENDED;
913 mutex_unlock(&ati_remote2_mutex);
918 static int ati_remote2_resume(struct usb_interface *interface)
920 struct ati_remote2 *ar2;
921 struct usb_host_interface *alt = interface->cur_altsetting;
924 if (alt->desc.bInterfaceNumber)
927 ar2 = usb_get_intfdata(interface);
929 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
931 mutex_lock(&ati_remote2_mutex);
933 if (ar2->flags & ATI_REMOTE2_OPENED)
934 r = ati_remote2_submit_urbs(ar2);
937 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
939 mutex_unlock(&ati_remote2_mutex);
944 static int ati_remote2_reset_resume(struct usb_interface *interface)
946 struct ati_remote2 *ar2;
947 struct usb_host_interface *alt = interface->cur_altsetting;
950 if (alt->desc.bInterfaceNumber)
953 ar2 = usb_get_intfdata(interface);
955 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
957 mutex_lock(&ati_remote2_mutex);
959 r = ati_remote2_setup(ar2, ar2->channel_mask);
963 if (ar2->flags & ATI_REMOTE2_OPENED)
964 r = ati_remote2_submit_urbs(ar2);
967 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
970 mutex_unlock(&ati_remote2_mutex);
975 static int ati_remote2_pre_reset(struct usb_interface *interface)
977 struct ati_remote2 *ar2;
978 struct usb_host_interface *alt = interface->cur_altsetting;
980 if (alt->desc.bInterfaceNumber)
983 ar2 = usb_get_intfdata(interface);
985 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
987 mutex_lock(&ati_remote2_mutex);
989 if (ar2->flags == ATI_REMOTE2_OPENED)
990 ati_remote2_kill_urbs(ar2);
995 static int ati_remote2_post_reset(struct usb_interface *interface)
997 struct ati_remote2 *ar2;
998 struct usb_host_interface *alt = interface->cur_altsetting;
1001 if (alt->desc.bInterfaceNumber)
1004 ar2 = usb_get_intfdata(interface);
1006 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1008 if (ar2->flags == ATI_REMOTE2_OPENED)
1009 r = ati_remote2_submit_urbs(ar2);
1011 mutex_unlock(&ati_remote2_mutex);
1016 module_usb_driver(ati_remote2_driver);