1 // SPDX-License-Identifier: GPL-2.0-only
3 * ati_remote2 - ATI/Philips USB RF remote driver
9 #include <linux/usb/input.h>
10 #include <linux/slab.h>
11 #include <linux/module.h>
13 #define DRIVER_DESC "ATI/Philips USB RF remote driver"
15 MODULE_DESCRIPTION(DRIVER_DESC);
17 MODULE_LICENSE("GPL");
20 * ATI Remote Wonder II Channel Configuration
22 * The remote control can be assigned one of sixteen "channels" in order to facilitate
23 * the use of multiple remote controls within range of each other.
24 * A remote's "channel" may be altered by pressing and holding the "PC" button for
25 * approximately 3 seconds, after which the button will slowly flash the count of the
26 * currently configured "channel", using the numeric keypad enter a number between 1 and
27 * 16 and then press the "PC" button again, the button will slowly flash the count of the
28 * newly configured "channel".
32 ATI_REMOTE2_MAX_CHANNEL_MASK = 0xFFFF,
33 ATI_REMOTE2_MAX_MODE_MASK = 0x1F,
36 static int ati_remote2_set_mask(const char *val,
37 const struct kernel_param *kp,
46 ret = kstrtouint(val, 0, &mask);
53 *(unsigned int *)kp->arg = mask;
58 static int ati_remote2_set_channel_mask(const char *val,
59 const struct kernel_param *kp)
61 pr_debug("%s()\n", __func__);
63 return ati_remote2_set_mask(val, kp, ATI_REMOTE2_MAX_CHANNEL_MASK);
66 static int ati_remote2_get_channel_mask(char *buffer,
67 const struct kernel_param *kp)
69 pr_debug("%s()\n", __func__);
71 return sprintf(buffer, "0x%04x\n", *(unsigned int *)kp->arg);
74 static int ati_remote2_set_mode_mask(const char *val,
75 const 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,
83 const struct kernel_param *kp)
85 pr_debug("%s()\n", __func__);
87 return sprintf(buffer, "0x%02x\n", *(unsigned int *)kp->arg);
90 static unsigned int channel_mask = ATI_REMOTE2_MAX_CHANNEL_MASK;
91 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
92 static const struct kernel_param_ops param_ops_channel_mask = {
93 .set = ati_remote2_set_channel_mask,
94 .get = ati_remote2_get_channel_mask,
96 module_param(channel_mask, channel_mask, 0644);
97 MODULE_PARM_DESC(channel_mask, "Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
99 static unsigned int mode_mask = ATI_REMOTE2_MAX_MODE_MASK;
100 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
101 static const struct kernel_param_ops param_ops_mode_mask = {
102 .set = ati_remote2_set_mode_mask,
103 .get = ati_remote2_get_mode_mask,
105 module_param(mode_mask, mode_mask, 0644);
106 MODULE_PARM_DESC(mode_mask, "Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
108 static const struct usb_device_id ati_remote2_id_table[] = {
109 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
112 MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
114 static DEFINE_MUTEX(ati_remote2_mutex);
117 ATI_REMOTE2_OPENED = 0x1,
118 ATI_REMOTE2_SUSPENDED = 0x2,
130 static const struct {
133 } ati_remote2_key_table[] = {
146 { 0x10, KEY_VOLUMEUP },
147 { 0x11, KEY_VOLUMEDOWN },
148 { 0x20, KEY_CHANNELUP },
149 { 0x21, KEY_CHANNELDOWN },
150 { 0x28, KEY_FORWARD },
151 { 0x29, KEY_REWIND },
155 { 0x37, KEY_RECORD },
158 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
172 { 0x8e, KEY_VENDOR },
173 { 0x96, KEY_COFFEE },
176 { 0xbe, KEY_QUESTION },
183 struct input_dev *idev;
184 struct usb_device *udev;
186 struct usb_interface *intf[2];
187 struct usb_endpoint_descriptor *ep[2];
190 dma_addr_t buf_dma[2];
192 unsigned long jiffies;
198 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
199 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
203 unsigned int channel_mask;
204 unsigned int mode_mask;
207 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
208 static void ati_remote2_disconnect(struct usb_interface *interface);
209 static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
210 static int ati_remote2_resume(struct usb_interface *interface);
211 static int ati_remote2_reset_resume(struct usb_interface *interface);
212 static int ati_remote2_pre_reset(struct usb_interface *interface);
213 static int ati_remote2_post_reset(struct usb_interface *interface);
215 static struct usb_driver ati_remote2_driver = {
216 .name = "ati_remote2",
217 .probe = ati_remote2_probe,
218 .disconnect = ati_remote2_disconnect,
219 .id_table = ati_remote2_id_table,
220 .suspend = ati_remote2_suspend,
221 .resume = ati_remote2_resume,
222 .reset_resume = ati_remote2_reset_resume,
223 .pre_reset = ati_remote2_pre_reset,
224 .post_reset = ati_remote2_post_reset,
225 .supports_autosuspend = 1,
228 static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
232 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
234 dev_err(&ar2->intf[0]->dev,
235 "%s(): usb_submit_urb() = %d\n", __func__, r);
238 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
240 usb_kill_urb(ar2->urb[0]);
241 dev_err(&ar2->intf[1]->dev,
242 "%s(): usb_submit_urb() = %d\n", __func__, r);
249 static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
251 usb_kill_urb(ar2->urb[1]);
252 usb_kill_urb(ar2->urb[0]);
255 static int ati_remote2_open(struct input_dev *idev)
257 struct ati_remote2 *ar2 = input_get_drvdata(idev);
260 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
262 r = usb_autopm_get_interface(ar2->intf[0]);
264 dev_err(&ar2->intf[0]->dev,
265 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
269 mutex_lock(&ati_remote2_mutex);
271 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
272 r = ati_remote2_submit_urbs(ar2);
277 ar2->flags |= ATI_REMOTE2_OPENED;
279 mutex_unlock(&ati_remote2_mutex);
281 usb_autopm_put_interface(ar2->intf[0]);
286 mutex_unlock(&ati_remote2_mutex);
287 usb_autopm_put_interface(ar2->intf[0]);
292 static void ati_remote2_close(struct input_dev *idev)
294 struct ati_remote2 *ar2 = input_get_drvdata(idev);
296 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
298 mutex_lock(&ati_remote2_mutex);
300 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
301 ati_remote2_kill_urbs(ar2);
303 ar2->flags &= ~ATI_REMOTE2_OPENED;
305 mutex_unlock(&ati_remote2_mutex);
308 static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
310 struct input_dev *idev = ar2->idev;
311 u8 *data = ar2->buf[0];
314 channel = data[0] >> 4;
316 if (!((1 << channel) & ar2->channel_mask))
319 mode = data[0] & 0x0F;
321 if (mode > ATI_REMOTE2_PC) {
322 dev_err(&ar2->intf[0]->dev,
323 "Unknown mode byte (%02x %02x %02x %02x)\n",
324 data[3], data[2], data[1], data[0]);
328 if (!((1 << mode) & ar2->mode_mask))
331 input_event(idev, EV_REL, REL_X, (s8) data[1]);
332 input_event(idev, EV_REL, REL_Y, (s8) data[2]);
336 static int ati_remote2_lookup(unsigned int hw_code)
340 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
341 if (ati_remote2_key_table[i].hw_code == hw_code)
347 static void ati_remote2_input_key(struct ati_remote2 *ar2)
349 struct input_dev *idev = ar2->idev;
350 u8 *data = ar2->buf[1];
351 int channel, mode, hw_code, index;
353 channel = data[0] >> 4;
355 if (!((1 << channel) & ar2->channel_mask))
358 mode = data[0] & 0x0F;
360 if (mode > ATI_REMOTE2_PC) {
361 dev_err(&ar2->intf[1]->dev,
362 "Unknown mode byte (%02x %02x %02x %02x)\n",
363 data[3], data[2], data[1], data[0]);
368 if (hw_code == 0x3f) {
370 * For some incomprehensible reason the mouse pad generates
371 * events which look identical to the events from the last
372 * pressed mode key. Naturally we don't want to generate key
373 * events for the mouse pad so we filter out any subsequent
374 * events from the same mode key.
376 if (ar2->mode == mode)
383 if (!((1 << mode) & ar2->mode_mask))
386 index = ati_remote2_lookup(hw_code);
388 dev_err(&ar2->intf[1]->dev,
389 "Unknown code byte (%02x %02x %02x %02x)\n",
390 data[3], data[2], data[1], data[0]);
395 case 0: /* release */
398 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]);
402 /* No repeat for mouse buttons. */
403 if (ar2->keycode[mode][index] == BTN_LEFT ||
404 ar2->keycode[mode][index] == BTN_RIGHT)
407 if (!time_after_eq(jiffies, ar2->jiffies))
410 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]);
413 dev_err(&ar2->intf[1]->dev,
414 "Unknown state byte (%02x %02x %02x %02x)\n",
415 data[3], data[2], data[1], data[0]);
419 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
423 static void ati_remote2_complete_mouse(struct urb *urb)
425 struct ati_remote2 *ar2 = urb->context;
428 switch (urb->status) {
430 usb_mark_last_busy(ar2->udev);
431 ati_remote2_input_mouse(ar2);
437 dev_dbg(&ar2->intf[0]->dev,
438 "%s(): urb status = %d\n", __func__, urb->status);
441 usb_mark_last_busy(ar2->udev);
442 dev_err(&ar2->intf[0]->dev,
443 "%s(): urb status = %d\n", __func__, urb->status);
446 r = usb_submit_urb(urb, GFP_ATOMIC);
448 dev_err(&ar2->intf[0]->dev,
449 "%s(): usb_submit_urb() = %d\n", __func__, r);
452 static void ati_remote2_complete_key(struct urb *urb)
454 struct ati_remote2 *ar2 = urb->context;
457 switch (urb->status) {
459 usb_mark_last_busy(ar2->udev);
460 ati_remote2_input_key(ar2);
466 dev_dbg(&ar2->intf[1]->dev,
467 "%s(): urb status = %d\n", __func__, urb->status);
470 usb_mark_last_busy(ar2->udev);
471 dev_err(&ar2->intf[1]->dev,
472 "%s(): urb status = %d\n", __func__, urb->status);
475 r = usb_submit_urb(urb, GFP_ATOMIC);
477 dev_err(&ar2->intf[1]->dev,
478 "%s(): usb_submit_urb() = %d\n", __func__, r);
481 static int ati_remote2_getkeycode(struct input_dev *idev,
482 struct input_keymap_entry *ke)
484 struct ati_remote2 *ar2 = input_get_drvdata(idev);
488 unsigned int scancode;
490 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
492 if (index >= ATI_REMOTE2_MODES *
493 ARRAY_SIZE(ati_remote2_key_table))
496 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
497 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
498 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
500 if (input_scancode_to_scalar(ke, &scancode))
503 mode = scancode >> 8;
504 if (mode > ATI_REMOTE2_PC)
507 offset = ati_remote2_lookup(scancode & 0xff);
511 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset;
514 ke->keycode = ar2->keycode[mode][offset];
515 ke->len = sizeof(scancode);
516 memcpy(&ke->scancode, &scancode, sizeof(scancode));
522 static int ati_remote2_setkeycode(struct input_dev *idev,
523 const struct input_keymap_entry *ke,
524 unsigned int *old_keycode)
526 struct ati_remote2 *ar2 = input_get_drvdata(idev);
530 unsigned int scancode;
532 if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
533 if (ke->index >= ATI_REMOTE2_MODES *
534 ARRAY_SIZE(ati_remote2_key_table))
537 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table);
538 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table);
540 if (input_scancode_to_scalar(ke, &scancode))
543 mode = scancode >> 8;
544 if (mode > ATI_REMOTE2_PC)
547 offset = ati_remote2_lookup(scancode & 0xff);
552 *old_keycode = ar2->keycode[mode][offset];
553 ar2->keycode[mode][offset] = ke->keycode;
554 __set_bit(ke->keycode, idev->keybit);
556 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
557 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
558 if (ar2->keycode[mode][index] == *old_keycode)
563 __clear_bit(*old_keycode, idev->keybit);
568 static int ati_remote2_input_init(struct ati_remote2 *ar2)
570 struct input_dev *idev;
571 int index, mode, retval;
573 idev = input_allocate_device();
578 input_set_drvdata(idev, ar2);
580 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL);
581 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
583 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
585 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
586 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
587 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
588 __set_bit(ar2->keycode[mode][index], idev->keybit);
592 /* AUX1-AUX4 and PC generate the same scancode. */
593 index = ati_remote2_lookup(0x3f);
594 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
595 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
596 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
597 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
598 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
599 __set_bit(KEY_PROG1, idev->keybit);
600 __set_bit(KEY_PROG2, idev->keybit);
601 __set_bit(KEY_PROG3, idev->keybit);
602 __set_bit(KEY_PROG4, idev->keybit);
603 __set_bit(KEY_PC, idev->keybit);
605 idev->rep[REP_DELAY] = 250;
606 idev->rep[REP_PERIOD] = 33;
608 idev->open = ati_remote2_open;
609 idev->close = ati_remote2_close;
611 idev->getkeycode = ati_remote2_getkeycode;
612 idev->setkeycode = ati_remote2_setkeycode;
614 idev->name = ar2->name;
615 idev->phys = ar2->phys;
617 usb_to_input_id(ar2->udev, &idev->id);
618 idev->dev.parent = &ar2->udev->dev;
620 retval = input_register_device(idev);
622 input_free_device(idev);
627 static int ati_remote2_urb_init(struct ati_remote2 *ar2)
629 struct usb_device *udev = ar2->udev;
632 for (i = 0; i < 2; i++) {
633 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]);
637 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL);
641 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress);
642 maxp = usb_maxpacket(udev, pipe);
643 maxp = maxp > 4 ? 4 : maxp;
645 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp,
646 i ? ati_remote2_complete_key : ati_remote2_complete_mouse,
647 ar2, ar2->ep[i]->bInterval);
648 ar2->urb[i]->transfer_dma = ar2->buf_dma[i];
649 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
655 static void ati_remote2_urb_cleanup(struct ati_remote2 *ar2)
659 for (i = 0; i < 2; i++) {
660 usb_free_urb(ar2->urb[i]);
661 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]);
665 static int ati_remote2_setup(struct ati_remote2 *ar2, unsigned int ch_mask)
670 * Configure receiver to only accept input from remote "channel"
671 * channel == 0 -> Accept input from any remote channel
672 * channel == 1 -> Only accept input from remote channel 1
673 * channel == 2 -> Only accept input from remote channel 2
675 * channel == 16 -> Only accept input from remote channel 16
679 for (i = 0; i < 16; i++) {
680 if ((1 << i) & ch_mask) {
681 if (!(~(1 << i) & ch_mask))
687 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0),
689 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
690 channel, 0x0, NULL, 0, USB_CTRL_SET_TIMEOUT);
692 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n",
700 static ssize_t ati_remote2_show_channel_mask(struct device *dev,
701 struct device_attribute *attr,
704 struct usb_device *udev = to_usb_device(dev);
705 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
706 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
708 return sprintf(buf, "0x%04x\n", ar2->channel_mask);
711 static ssize_t ati_remote2_store_channel_mask(struct device *dev,
712 struct device_attribute *attr,
713 const char *buf, size_t count)
715 struct usb_device *udev = to_usb_device(dev);
716 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
717 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
721 r = kstrtouint(buf, 0, &mask);
725 if (mask & ~ATI_REMOTE2_MAX_CHANNEL_MASK)
728 r = usb_autopm_get_interface(ar2->intf[0]);
730 dev_err(&ar2->intf[0]->dev,
731 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
735 mutex_lock(&ati_remote2_mutex);
737 if (mask != ar2->channel_mask) {
738 r = ati_remote2_setup(ar2, mask);
740 ar2->channel_mask = mask;
743 mutex_unlock(&ati_remote2_mutex);
745 usb_autopm_put_interface(ar2->intf[0]);
747 return r ? r : count;
750 static ssize_t ati_remote2_show_mode_mask(struct device *dev,
751 struct device_attribute *attr,
754 struct usb_device *udev = to_usb_device(dev);
755 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
756 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
758 return sprintf(buf, "0x%02x\n", ar2->mode_mask);
761 static ssize_t ati_remote2_store_mode_mask(struct device *dev,
762 struct device_attribute *attr,
763 const char *buf, size_t count)
765 struct usb_device *udev = to_usb_device(dev);
766 struct usb_interface *intf = usb_ifnum_to_if(udev, 0);
767 struct ati_remote2 *ar2 = usb_get_intfdata(intf);
771 err = kstrtouint(buf, 0, &mask);
775 if (mask & ~ATI_REMOTE2_MAX_MODE_MASK)
778 ar2->mode_mask = mask;
783 static DEVICE_ATTR(channel_mask, 0644, ati_remote2_show_channel_mask,
784 ati_remote2_store_channel_mask);
786 static DEVICE_ATTR(mode_mask, 0644, ati_remote2_show_mode_mask,
787 ati_remote2_store_mode_mask);
789 static struct attribute *ati_remote2_attrs[] = {
790 &dev_attr_channel_mask.attr,
791 &dev_attr_mode_mask.attr,
795 static struct attribute_group ati_remote2_attr_group = {
796 .attrs = ati_remote2_attrs,
799 static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id)
801 struct usb_device *udev = interface_to_usbdev(interface);
802 struct usb_host_interface *alt = interface->cur_altsetting;
803 struct ati_remote2 *ar2;
806 if (alt->desc.bInterfaceNumber)
809 ar2 = kzalloc(sizeof (struct ati_remote2), GFP_KERNEL);
815 /* Sanity check, first interface must have an endpoint */
816 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
817 dev_err(&interface->dev,
818 "%s(): interface 0 must have an endpoint\n", __func__);
822 ar2->intf[0] = interface;
823 ar2->ep[0] = &alt->endpoint[0].desc;
825 /* Sanity check, the device must have two interfaces */
826 ar2->intf[1] = usb_ifnum_to_if(udev, 1);
827 if ((udev->actconfig->desc.bNumInterfaces < 2) || !ar2->intf[1]) {
828 dev_err(&interface->dev, "%s(): need 2 interfaces, found %d\n",
829 __func__, udev->actconfig->desc.bNumInterfaces);
834 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2);
838 /* Sanity check, second interface must have an endpoint */
839 alt = ar2->intf[1]->cur_altsetting;
840 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) {
841 dev_err(&interface->dev,
842 "%s(): interface 1 must have an endpoint\n", __func__);
846 ar2->ep[1] = &alt->endpoint[0].desc;
848 r = ati_remote2_urb_init(ar2);
852 ar2->channel_mask = channel_mask;
853 ar2->mode_mask = mode_mask;
855 r = ati_remote2_setup(ar2, ar2->channel_mask);
859 usb_make_path(udev, ar2->phys, sizeof(ar2->phys));
860 strlcat(ar2->phys, "/input0", sizeof(ar2->phys));
862 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name));
864 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group);
868 r = ati_remote2_input_init(ar2);
872 usb_set_intfdata(interface, ar2);
874 interface->needs_remote_wakeup = 1;
879 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group);
881 ati_remote2_urb_cleanup(ar2);
883 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
890 static void ati_remote2_disconnect(struct usb_interface *interface)
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);
899 usb_set_intfdata(interface, NULL);
901 input_unregister_device(ar2->idev);
903 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group);
905 ati_remote2_urb_cleanup(ar2);
907 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]);
912 static int ati_remote2_suspend(struct usb_interface *interface,
913 pm_message_t message)
915 struct ati_remote2 *ar2;
916 struct usb_host_interface *alt = interface->cur_altsetting;
918 if (alt->desc.bInterfaceNumber)
921 ar2 = usb_get_intfdata(interface);
923 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
925 mutex_lock(&ati_remote2_mutex);
927 if (ar2->flags & ATI_REMOTE2_OPENED)
928 ati_remote2_kill_urbs(ar2);
930 ar2->flags |= ATI_REMOTE2_SUSPENDED;
932 mutex_unlock(&ati_remote2_mutex);
937 static int ati_remote2_resume(struct usb_interface *interface)
939 struct ati_remote2 *ar2;
940 struct usb_host_interface *alt = interface->cur_altsetting;
943 if (alt->desc.bInterfaceNumber)
946 ar2 = usb_get_intfdata(interface);
948 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
950 mutex_lock(&ati_remote2_mutex);
952 if (ar2->flags & ATI_REMOTE2_OPENED)
953 r = ati_remote2_submit_urbs(ar2);
956 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
958 mutex_unlock(&ati_remote2_mutex);
963 static int ati_remote2_reset_resume(struct usb_interface *interface)
965 struct ati_remote2 *ar2;
966 struct usb_host_interface *alt = interface->cur_altsetting;
969 if (alt->desc.bInterfaceNumber)
972 ar2 = usb_get_intfdata(interface);
974 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
976 mutex_lock(&ati_remote2_mutex);
978 r = ati_remote2_setup(ar2, ar2->channel_mask);
982 if (ar2->flags & ATI_REMOTE2_OPENED)
983 r = ati_remote2_submit_urbs(ar2);
986 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
989 mutex_unlock(&ati_remote2_mutex);
994 static int ati_remote2_pre_reset(struct usb_interface *interface)
996 struct ati_remote2 *ar2;
997 struct usb_host_interface *alt = interface->cur_altsetting;
999 if (alt->desc.bInterfaceNumber)
1002 ar2 = usb_get_intfdata(interface);
1004 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1006 mutex_lock(&ati_remote2_mutex);
1008 if (ar2->flags == ATI_REMOTE2_OPENED)
1009 ati_remote2_kill_urbs(ar2);
1014 static int ati_remote2_post_reset(struct usb_interface *interface)
1016 struct ati_remote2 *ar2;
1017 struct usb_host_interface *alt = interface->cur_altsetting;
1020 if (alt->desc.bInterfaceNumber)
1023 ar2 = usb_get_intfdata(interface);
1025 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
1027 if (ar2->flags == ATI_REMOTE2_OPENED)
1028 r = ati_remote2_submit_urbs(ar2);
1030 mutex_unlock(&ati_remote2_mutex);
1035 module_usb_driver(ati_remote2_driver);