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"
41 static int ati_remote2_set_mask(
const char *
val,
58 *(
unsigned int *)kp->
arg = mask;
63 static int ati_remote2_set_channel_mask(
const char *
val,
71 static int ati_remote2_get_channel_mask(
char *
buffer,
76 return sprintf(buffer,
"0x%04x", *(
unsigned int *)kp->
arg);
79 static int ati_remote2_set_mode_mask(
const char *
val,
87 static int ati_remote2_get_mode_mask(
char *buffer,
92 return sprintf(buffer,
"0x%02x", *(
unsigned int *)kp->
arg);
96 #define param_check_channel_mask(name, p) __param_check(name, p, unsigned int)
98 .set = ati_remote2_set_channel_mask,
99 .get = ati_remote2_get_channel_mask,
102 MODULE_PARM_DESC(channel_mask,
"Bitmask of channels to accept <15:Channel16>...<1:Channel2><0:Channel1>");
105 #define param_check_mode_mask(name, p) __param_check(name, p, unsigned int)
107 .set = ati_remote2_set_mode_mask,
108 .get = ati_remote2_get_mode_mask,
111 MODULE_PARM_DESC(mode_mask,
"Bitmask of modes to accept <4:PC><3:AUX4><2:AUX3><1:AUX2><0:AUX1>");
114 { USB_DEVICE(0x0471, 0x0602) },
135 static const struct {
138 } ati_remote2_key_table[] = {
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)
240 "%s(): usb_submit_urb() = %d\n", __func__, r);
247 "%s(): usb_submit_urb() = %d\n", __func__, r);
254 static void ati_remote2_kill_urbs(
struct ati_remote2 *ar2)
260 static int ati_remote2_open(
struct input_dev *
idev)
267 r = usb_autopm_get_interface(ar2->
intf[0]);
270 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
277 r = ati_remote2_submit_urbs(ar2);
286 usb_autopm_put_interface(ar2->
intf[0]);
292 usb_autopm_put_interface(ar2->
intf[0]);
297 static void ati_remote2_close(
struct input_dev *idev)
306 ati_remote2_kill_urbs(ar2);
313 static void ati_remote2_input_mouse(
struct ati_remote2 *ar2)
315 struct input_dev *idev = ar2->
idev;
319 channel = data[0] >> 4;
324 mode = data[0] & 0x0F;
328 "Unknown mode byte (%02x %02x %02x %02x)\n",
329 data[3], data[2], data[1], data[0]);
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];
358 channel = data[0] >> 4;
363 mode = data[0] & 0x0F;
367 "Unknown mode byte (%02x %02x %02x %02x)\n",
368 data[3], data[2], data[1], data[0]);
373 if (hw_code == 0x3f) {
381 if (ar2->
mode == mode)
391 index = ati_remote2_lookup(hw_code);
394 "Unknown code byte (%02x %02x %02x %02x)\n",
395 data[3], data[2], data[1], data[0]);
419 "Unknown state byte (%02x %02x %02x %02x)\n",
420 data[3], data[2], data[1], data[0]);
428 static void ati_remote2_complete_mouse(
struct urb *
urb)
433 switch (urb->status) {
435 usb_mark_last_busy(ar2->
udev);
436 ati_remote2_input_mouse(ar2);
443 "%s(): urb status = %d\n", __func__, urb->status);
446 usb_mark_last_busy(ar2->
udev);
448 "%s(): urb status = %d\n", __func__, urb->status);
454 "%s(): usb_submit_urb() = %d\n", __func__, r);
457 static void ati_remote2_complete_key(
struct urb *urb)
462 switch (urb->status) {
464 usb_mark_last_busy(ar2->
udev);
465 ati_remote2_input_key(ar2);
472 "%s(): urb status = %d\n", __func__, urb->status);
475 usb_mark_last_busy(ar2->
udev);
477 "%s(): urb status = %d\n", __func__, urb->status);
483 "%s(): usb_submit_urb() = %d\n", __func__, r);
486 static int ati_remote2_getkeycode(
struct input_dev *idev,
493 unsigned int scancode;
503 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code;
505 if (input_scancode_to_scalar(ke, &scancode))
508 mode = scancode >> 8;
512 offset = ati_remote2_lookup(scancode & 0xff);
520 ke->
len =
sizeof(scancode);
527 static int ati_remote2_setkeycode(
struct input_dev *idev,
529 unsigned int *old_keycode)
535 unsigned int scancode;
545 if (input_scancode_to_scalar(ke, &scancode))
548 mode = scancode >> 8;
552 offset = ati_remote2_lookup(scancode & 0xff);
562 for (index = 0; index <
ARRAY_SIZE(ati_remote2_key_table); index++) {
563 if (ar2->
keycode[mode][index] == *old_keycode)
573 static int ati_remote2_input_init(
struct ati_remote2 *ar2)
575 struct input_dev *
idev;
578 idev = input_allocate_device();
583 input_set_drvdata(idev, ar2);
591 for (index = 0; index <
ARRAY_SIZE(ati_remote2_key_table); index++) {
598 index = ati_remote2_lookup(0x3f);
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++) {
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);
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++) {
670 static int ati_remote2_setup(
struct ati_remote2 *ar2,
unsigned int ch_mask)
684 for (i = 0; i < 16; i++) {
685 if ((1 << i) & ch_mask) {
686 if (!(~(1 << i) & ch_mask))
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",
709 struct usb_device *udev = to_usb_device(dev);
720 struct usb_device *udev = to_usb_device(dev);
733 r = usb_autopm_get_interface(ar2->
intf[0]);
736 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
743 r = ati_remote2_setup(ar2, mask);
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,
759 struct usb_device *udev = to_usb_device(dev);
766 static ssize_t ati_remote2_store_mode_mask(
struct device *dev,
768 const char *buf,
size_t count)
770 struct usb_device *udev = to_usb_device(dev);
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,
801 .attrs = ati_remote2_attrs,
806 struct usb_device *udev = interface_to_usbdev(interface);
807 struct usb_host_interface *alt = interface->cur_altsetting;
811 if (alt->desc.bInterfaceNumber)
821 ar2->
ep[0] = &alt->endpoint[0].desc;
827 alt = ar2->
intf[1]->cur_altsetting;
828 ar2->
ep[1] = &alt->endpoint[0].desc;
830 r = ati_remote2_urb_init(ar2);
841 usb_make_path(udev, ar2->
phys,
sizeof(ar2->
phys));
850 r = ati_remote2_input_init(ar2);
854 usb_set_intfdata(interface, ar2);
856 interface->needs_remote_wakeup = 1;
863 ati_remote2_urb_cleanup(ar2);
871 static void ati_remote2_disconnect(
struct usb_interface *interface)
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);
886 ati_remote2_urb_cleanup(ar2);
893 static int ati_remote2_suspend(
struct usb_interface *interface,
897 struct usb_host_interface *alt = interface->cur_altsetting;
899 if (alt->desc.bInterfaceNumber)
902 ar2 = usb_get_intfdata(interface);
909 ati_remote2_kill_urbs(ar2);
918 static int ati_remote2_resume(
struct usb_interface *interface)
921 struct usb_host_interface *alt = interface->cur_altsetting;
924 if (alt->desc.bInterfaceNumber)
927 ar2 = usb_get_intfdata(interface);
934 r = ati_remote2_submit_urbs(ar2);
944 static int ati_remote2_reset_resume(
struct usb_interface *interface)
947 struct usb_host_interface *alt = interface->cur_altsetting;
950 if (alt->desc.bInterfaceNumber)
953 ar2 = usb_get_intfdata(interface);
964 r = ati_remote2_submit_urbs(ar2);
975 static int ati_remote2_pre_reset(
struct usb_interface *interface)
978 struct usb_host_interface *alt = interface->cur_altsetting;
980 if (alt->desc.bInterfaceNumber)
983 ar2 = usb_get_intfdata(interface);
990 ati_remote2_kill_urbs(ar2);
995 static int ati_remote2_post_reset(
struct usb_interface *interface)
998 struct usb_host_interface *alt = interface->cur_altsetting;
1001 if (alt->desc.bInterfaceNumber)
1004 ar2 = usb_get_intfdata(interface);
1009 r = ati_remote2_submit_urbs(ar2);