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>
15 #define DRIVER_DESC "ATI/Philips USB RF remote driver"
16 #define DRIVER_VERSION "0.3"
18 MODULE_DESCRIPTION(DRIVER_DESC);
19 MODULE_VERSION(DRIVER_VERSION);
20 MODULE_AUTHOR("Ville Syrjala <syrjala@sci.fi>");
21 MODULE_LICENSE("GPL");
24 * ATI Remote Wonder II Channel Configuration
26 * The remote control can by assigned one of sixteen "channels" in order to facilitate
27 * the use of multiple remote controls within range of each other.
28 * A remote's "channel" may be altered by pressing and holding the "PC" button for
29 * approximately 3 seconds, after which the button will slowly flash the count of the
30 * currently configured "channel", using the numeric keypad enter a number between 1 and
31 * 16 and then press the "PC" button again, the button will slowly flash the count of the
32 * newly configured "channel".
36 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
37 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
40 static int ati_remote2_set_mask(const char *val,
41 const struct kernel_param *kp,
50 ret = strict_strtoul(val, 0, &mask);
57 *(unsigned int *)kp->arg = mask;
62 static int ati_remote2_set_channel_mask(const char *val,
63 const struct kernel_param *kp)
65 pr_debug("%s()\n", __func__);
67 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
70 static int ati_remote2_get_channel_mask(char *buffer,
71 const struct kernel_param *kp)
73 pr_debug("%s()\n", __func__);
75 return sprintf(buffer, "0x%04x", *(unsigned int *)kp->arg);
78 static int ati_remote2_set_mode_mask(const char *val,
79 const struct kernel_param *kp)
81 pr_debug("%s()\n", __func__);
83 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_MODE_MASK);
86 static int ati_remote2_get_mode_mask(char *buffer,
87 const struct kernel_param *kp)
89 pr_debug("%s()\n", __func__);
91 return sprintf(buffer, "0x%02x", *(unsigned int *)kp->arg);
94 static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
95 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
96 static struct kernel_param_ops param_ops_channel_mask = {
97 .set = ati_remote2_set_channel_mask,
98 .get = ati_remote2_get_channel_mask,
100 module_param(channel_mask, channel_mask, 0644);
101 MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
103 static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
104 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
105 static struct kernel_param_ops param_ops_mode_mask = {
106 .set = ati_remote2_set_mode_mask,
107 .get = ati_remote2_get_mode_mask,
109 module_param(mode_mask, mode_mask, 0644);
110 MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
112 static struct usb_device_id ati_remote2_id_table[] = {
113 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
116 MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
118 static DEFINE_MUTEX(ati_remote2_mutex);
121 ATI_REMOTE2_OPENED = 0x1,
122 ATI_REMOTE2_SUSPENDED = 0x2,
134 static const struct {
137 } ati_remote2_key_table[] = {
150 { 0x10, KEY_VOLUMEUP },
151 { 0x11, KEY_VOLUMEDOWN },
152 { 0x20, KEY_CHANNELUP },
153 { 0x21, KEY_CHANNELDOWN },
154 { 0x28, KEY_FORWARD },
155 { 0x29, KEY_REWIND },
159 { 0x37, KEY_RECORD },
162 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
176 { 0x8e, KEY_VENDOR },
177 { 0x96, KEY_COFFEE },
180 { 0xbe, KEY_QUESTION },
187 struct input_dev *idev;
188 struct usb_device *udev;
190 struct usb_interface *intf[2];
191 struct usb_endpoint_descriptor *ep[2];
194 dma_addr_t buf_dma[2];
196 unsigned long jiffies;
202 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
203 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
207 unsigned int channel_mask;
208 unsigned int mode_mask;
211 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
212 static void ati_remote2_disconnect(struct usb_interface *interface);
213 static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
214 static int ati_remote2_resume(struct usb_interface *interface);
215 static int ati_remote2_reset_resume(struct usb_interface *interface);
216 static int ati_remote2_pre_reset(struct usb_interface *interface);
217 static int ati_remote2_post_reset(struct usb_interface *interface);
219 static struct usb_driver ati_remote2_driver = {
220 .name = "ati_remote2",
221 .probe = ati_remote2_probe,
222 .disconnect = ati_remote2_disconnect,
223 .id_table = ati_remote2_id_table,
224 .suspend = ati_remote2_suspend,
225 .resume = ati_remote2_resume,
226 .reset_resume = ati_remote2_reset_resume,
227 .pre_reset = ati_remote2_pre_reset,
228 .post_reset = ati_remote2_post_reset,
229 .supports_autosuspend = 1,
232 static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
236 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
238 dev_err(&ar2->intf[0]->dev,
239 "%s(): usb_submit_urb() = %d\n", __func__, r);
242 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
244 usb_kill_urb(ar2->urb[0]);
245 dev_err(&ar2->intf[1]->dev,
246 "%s(): usb_submit_urb() = %d\n", __func__, r);
253 static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
255 usb_kill_urb(ar2->urb[1]);
256 usb_kill_urb(ar2->urb[0]);
259 static int ati_remote2_open(struct input_dev *idev)
261 struct ati_remote2 *ar2 = input_get_drvdata(idev);
264 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
266 r = usb_autopm_get_interface(ar2->intf[0]);
268 dev_err(&ar2->intf[0]->dev,
269 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
273 mutex_lock(&ati_remote2_mutex);
275 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
276 r = ati_remote2_submit_urbs(ar2);
281 ar2->flags |= ATI_REMOTE2_OPENED;
283 mutex_unlock(&ati_remote2_mutex);
285 usb_autopm_put_interface(ar2->intf[0]);
290 mutex_unlock(&ati_remote2_mutex);
291 usb_autopm_put_interface(ar2->intf[0]);
296 static void ati_remote2_close(struct input_dev *idev)
298 struct ati_remote2 *ar2 = input_get_drvdata(idev);
300 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
302 mutex_lock(&ati_remote2_mutex);
304 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
305 ati_remote2_kill_urbs(ar2);
307 ar2->flags &= ~ATI_REMOTE2_OPENED;
309 mutex_unlock(&ati_remote2_mutex);
312 static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
314 struct input_dev *idev = ar2->idev;
315 u8 *data = ar2->buf[0];
318 channel = data[0] >> 4;
320 if (!((1 << channel) & ar2->channel_mask))
323 mode = data[0] & 0x0F;
325 if (mode > ATI_REMOTE2_PC) {
326 dev_err(&ar2->intf[0]->dev,
327 "Unknown mode byte (%02x %02x %02x %02x)\n",
328 data[3], data[2], data[1], data[0]);
332 if (!((1 << mode) & ar2->mode_mask))
335 input_event(idev, EV_REL, REL_X, (s8) data[1]);
336 input_event(idev, EV_REL, REL_Y, (s8) data[2]);
340 static int ati_remote2_lookup(unsigned int hw_code)
344 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
345 if (ati_remote2_key_table[i].hw_code == hw_code)
351 static void ati_remote2_input_key(struct ati_remote2 *ar2)
353 struct input_dev *idev = ar2->idev;
354 u8 *data = ar2->buf[1];
355 int channel, mode, hw_code, index;
357 channel = data[0] >> 4;
359 if (!((1 << channel) & ar2->channel_mask))
362 mode = data[0] & 0x0F;
364 if (mode > ATI_REMOTE2_PC) {
365 dev_err(&ar2->intf[1]->dev,
366 "Unknown mode byte (%02x %02x %02x %02x)\n",
367 data[3], data[2], data[1], data[0]);
372 if (hw_code == 0x3f) {
374 * For some incomprehensible reason the mouse pad generates
375 * events which look identical to the events from the last
376 * pressed mode key. Naturally we don't want to generate key
377 * events for the mouse pad so we filter out any subsequent
378 * events from the same mode key.
380 if (ar2->mode == mode)
387 if (!((1 << mode) & ar2->mode_mask))
390 index = ati_remote2_lookup(hw_code);
392 dev_err(&ar2->intf[1]->dev,
393 "Unknown code byte (%02x %02x %02x %02x)\n",
394 data[3], data[2], data[1], data[0]);
399 case 0: /* release */
402 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
406 /* No repeat for mouse buttons. */
407 if (ar2->keycode[mode][index] == BTN_LEFT ||
408 ar2->keycode[mode][index] == BTN_RIGHT)
411 if (!time_after_eq(jiffies, ar2->jiffies))
414 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
417 dev_err(&ar2->intf[1]->dev,
418 "Unknown state byte (%02x %02x %02x %02x)\n",
419 data[3], data[2], data[1], data[0]);
423 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
427 static void ati_remote2_complete_mouse(struct urb *urb)
429 struct ati_remote2 *ar2 = urb->context;
432 switch (urb->status) {
434 usb_mark_last_busy(ar2->udev);
435 ati_remote2_input_mouse(ar2);
441 dev_dbg(&ar2->intf[0]->dev,
442 "%s(): urb status = %d\n", __func__, urb->status);
445 usb_mark_last_busy(ar2->udev);
446 dev_err(&ar2->intf[0]->dev,
447 "%s(): urb status = %d\n", __func__, urb->status);
450 r = usb_submit_urb(urb, GFP_ATOMIC);
452 dev_err(&ar2->intf[0]->dev,
453 "%s(): usb_submit_urb() = %d\n", __func__, r);
456 static void ati_remote2_complete_key(struct urb *urb)
458 struct ati_remote2 *ar2 = urb->context;
461 switch (urb->status) {
463 usb_mark_last_busy(ar2->udev);
464 ati_remote2_input_key(ar2);
470 dev_dbg(&ar2->intf[1]->dev,
471 "%s(): urb status = %d\n", __func__, urb->status);
474 usb_mark_last_busy(ar2->udev);
475 dev_err(&ar2->intf[1]->dev,
476 "%s(): urb status = %d\n", __func__, urb->status);
479 r = usb_submit_urb(urb, GFP_ATOMIC);
481 dev_err(&ar2->intf[1]->dev,
482 "%s(): usb_submit_urb() = %d\n", __func__, r);
485 static int ati_remote2_getkeycode(struct input_dev *idev,
486 struct input_keymap_entry *ke)
488 struct ati_remote2 *ar2 = input_get_drvdata(idev);
492 unsigned int scancode;
494 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
496 if (index >= ATI_REMOTE2_MODES *
497 ARRAY_SIZE(ati_remote2_key_table))
500 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
501 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
502 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
504 if (input_scancode_to_scalar(ke, &scancode))
507 mode = scancode >> 8;
508 if (mode > ATI_REMOTE2_PC)
511 offset = ati_remote2_lookup(scancode & 0xff);
515 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
518 ke->keycode = ar2->keycode[mode][offset];
519 ke->len = sizeof(scancode);
520 memcpy(&ke->scancode, &scancode, sizeof(scancode));
526 static int ati_remote2_setkeycode(struct input_dev *idev,
527 const struct input_keymap_entry *ke,
528 unsigned int *old_keycode)
530 struct ati_remote2 *ar2 = input_get_drvdata(idev);
534 unsigned int scancode;
536 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
537 if (ke->index >= ATI_REMOTE2_MODES *
538 ARRAY_SIZE(ati_remote2_key_table))
541 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
542 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
544 if (input_scancode_to_scalar(ke, &scancode))
547 mode = scancode >> 8;
548 if (mode > ATI_REMOTE2_PC)
551 offset = ati_remote2_lookup(scancode & 0xff);
556 *old_keycode = ar2->keycode[mode][offset];
557 ar2->keycode[mode][offset] = ke->keycode;
558 __set_bit(ke->keycode, idev->keybit);
560 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
561 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
562 if (ar2->keycode[mode][index] == *old_keycode)
567 __clear_bit(*old_keycode, idev->keybit);
572 static int ati_remote2_input_init(struct ati_remote2 *ar2)
574 struct input_dev *idev;
575 int index, mode, retval;
577 idev = input_allocate_device();
582 input_set_drvdata(idev, ar2);
584 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
585 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
587 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
589 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
590 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
591 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
592 __set_bit(ar2->keycode[mode][index], idev->keybit);
596 /* AUX1-AUX4 and PC generate the same scancode. */
597 index = ati_remote2_lookup(0x3f);
598 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
599 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
600 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
601 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
602 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
603 __set_bit(KEY_PROG1, idev->keybit);
604 __set_bit(KEY_PROG2, idev->keybit);
605 __set_bit(KEY_PROG3, idev->keybit);
606 __set_bit(KEY_PROG4, idev->keybit);
607 __set_bit(KEY_PC, idev->keybit);
609 idev->rep[REP_DELAY] = 250;
610 idev->rep[REP_PERIOD] = 33;
612 idev->open = ati_remote2_open;
613 idev->close = ati_remote2_close;
615 idev->getkeycode = ati_remote2_getkeycode;
616 idev->setkeycode = ati_remote2_setkeycode;
618 idev->name = ar2->name;
619 idev->phys = ar2->phys;
621 usb_to_input_id(ar2->udev, &idev->id);
622 idev->dev.parent = &ar2->udev->dev;
624 retval = input_register_device(idev);
626 input_free_device(idev);
631 static int ati_remote2_urb_init(struct ati_remote2 *ar2)
633 struct usb_device *udev = ar2->udev;
636 for (i = 0; i < 2; i++) {
637 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
641 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
645 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
646 maxp = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
647 maxp = maxp > 4 ? 4 : maxp;
649 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
650 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
651 ar2, ar2->ep[i]->bInterval);
652 ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
653 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
659 static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
663 for (i = 0; i < 2; i++) {
664 usb_free_urb(ar2->urb[i]);
665 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
669 static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
674 * Configure receiver to only accept input from remote "channel"
675 * channel == 0 -> Accept input from any remote channel
676 * channel == 1 -> Only accept input from remote channel 1
677 * channel == 2 -> Only accept input from remote channel 2
679 * channel == 16 -> Only accept input from remote channel 16
683 for (i = 0; i < 16; i++) {
684 if ((1 << i) & ch_mask) {
685 if (!(~(1 << i) & ch_mask))
691 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
693 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
694 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
696 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
704 static ssize_t ati_remote2_show_channel_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%04x\n", ar2->channel_mask);
715 static ssize_t ati_remote2_store_channel_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);
725 if (strict_strtoul(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);
773 if (strict_strtoul(buf, 0, &mask))
776 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
779 ar2->mode_mask = mask;
784 static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
785 ati_remote2_store_channel_mask);
787 static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
788 ati_remote2_store_mode_mask);
790 static struct attribute *ati_remote2_attrs[] = {
791 &dev_attr_channel_mask.attr,
792 &dev_attr_mode_mask.attr,
796 static struct attribute_group ati_remote2_attr_group = {
797 .attrs = ati_remote2_attrs,
800 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
802 struct usb_device *udev = interface_to_usbdev(interface);
803 struct usb_host_interface *alt = interface->cur_altsetting;
804 struct ati_remote2 *ar2;
807 if (alt->desc.bInterfaceNumber)
810 ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
816 ar2->intf[0] = interface;
817 ar2->ep[0] = &alt->endpoint[0].desc;
819 ar2->intf[1] = usb_ifnum_to_if(udev, 1);
820 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
823 alt = ar2->intf[1]->cur_altsetting;
824 ar2->ep[1] = &alt->endpoint[0].desc;
826 r = ati_remote2_urb_init(ar2);
830 ar2->channel_mask = channel_mask;
831 ar2->mode_mask = mode_mask;
833 r = ati_remote2_setup(ar2, ar2->channel_mask);
837 usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
838 strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
840 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
842 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
846 r = ati_remote2_input_init(ar2);
850 usb_set_intfdata(interface, ar2);
852 interface->needs_remote_wakeup = 1;
857 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
859 ati_remote2_urb_cleanup(ar2);
860 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
867 static void ati_remote2_disconnect(struct usb_interface *interface)
869 struct ati_remote2 *ar2;
870 struct usb_host_interface *alt = interface->cur_altsetting;
872 if (alt->desc.bInterfaceNumber)
875 ar2 = usb_get_intfdata(interface);
876 usb_set_intfdata(interface, NULL);
878 input_unregister_device(ar2->idev);
880 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
882 ati_remote2_urb_cleanup(ar2);
884 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
889 static int ati_remote2_suspend(struct usb_interface *interface,
890 pm_message_t message)
892 struct ati_remote2 *ar2;
893 struct usb_host_interface *alt = interface->cur_altsetting;
895 if (alt->desc.bInterfaceNumber)
898 ar2 = usb_get_intfdata(interface);
900 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
902 mutex_lock(&ati_remote2_mutex);
904 if (ar2->flags & ATI_REMOTE2_OPENED)
905 ati_remote2_kill_urbs(ar2);
907 ar2->flags |= ATI_REMOTE2_SUSPENDED;
909 mutex_unlock(&ati_remote2_mutex);
914 static int ati_remote2_resume(struct usb_interface *interface)
916 struct ati_remote2 *ar2;
917 struct usb_host_interface *alt = interface->cur_altsetting;
920 if (alt->desc.bInterfaceNumber)
923 ar2 = usb_get_intfdata(interface);
925 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
927 mutex_lock(&ati_remote2_mutex);
929 if (ar2->flags & ATI_REMOTE2_OPENED)
930 r = ati_remote2_submit_urbs(ar2);
933 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
935 mutex_unlock(&ati_remote2_mutex);
940 static int ati_remote2_reset_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 r = ati_remote2_setup(ar2, ar2->channel_mask);
959 if (ar2->flags & ATI_REMOTE2_OPENED)
960 r = ati_remote2_submit_urbs(ar2);
963 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
966 mutex_unlock(&ati_remote2_mutex);
971 static int ati_remote2_pre_reset(struct usb_interface *interface)
973 struct ati_remote2 *ar2;
974 struct usb_host_interface *alt = interface->cur_altsetting;
976 if (alt->desc.bInterfaceNumber)
979 ar2 = usb_get_intfdata(interface);
981 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
983 mutex_lock(&ati_remote2_mutex);
985 if (ar2->flags == ATI_REMOTE2_OPENED)
986 ati_remote2_kill_urbs(ar2);
991 static int ati_remote2_post_reset(struct usb_interface *interface)
993 struct ati_remote2 *ar2;
994 struct usb_host_interface *alt = interface->cur_altsetting;
997 if (alt->desc.bInterfaceNumber)
1000 ar2 = usb_get_intfdata(interface);
1002 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1004 if (ar2->flags == ATI_REMOTE2_OPENED)
1005 r = ati_remote2_submit_urbs(ar2);
1007 mutex_unlock(&ati_remote2_mutex);
1012 static int __init ati_remote2_init(void)
1016 r = usb_register(&ati_remote2_driver);
1018 printk(KERN_ERR "ati_remote2: usb_register() = %d\n", r);
1020 printk(KERN_INFO "ati_remote2: " DRIVER_DESC " " DRIVER_VERSION "\n");
1025 static void __exit ati_remote2_exit(void)
1027 usb_deregister(&ati_remote2_driver);
1030 module_init(ati_remote2_init);
1031 module_exit(ati_remote2_exit);