Lines Matching +full:ati +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
3 * ati_remote2 - ATI/Philips USB RF remote driver
5 * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
6 * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
13 #define DRIVER_DESC "ATI/Philips USB RF remote driver"
20 * ATI Remote Wonder II Channel Configuration
44 return -EINVAL; in ati_remote2_set_mask()
51 return -EINVAL; in ati_remote2_set_mask()
53 *(unsigned int *)kp->arg = mask; in ati_remote2_set_mask()
71 return sprintf(buffer, "0x%04x\n", *(unsigned int *)kp->arg); in ati_remote2_get_channel_mask()
87 return sprintf(buffer, "0x%02x\n", *(unsigned int *)kp->arg); in ati_remote2_get_mode_mask()
109 { USB_DEVICE(0x0471, 0x0602) }, /* ATI Remote Wonder II */
158 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
193 int mode; member
198 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
232 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); in ati_remote2_submit_urbs()
234 dev_err(&ar2->intf[0]->dev, in ati_remote2_submit_urbs()
238 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); in ati_remote2_submit_urbs()
240 usb_kill_urb(ar2->urb[0]); in ati_remote2_submit_urbs()
241 dev_err(&ar2->intf[1]->dev, in ati_remote2_submit_urbs()
251 usb_kill_urb(ar2->urb[1]); in ati_remote2_kill_urbs()
252 usb_kill_urb(ar2->urb[0]); in ati_remote2_kill_urbs()
260 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_open()
262 r = usb_autopm_get_interface(ar2->intf[0]); in ati_remote2_open()
264 dev_err(&ar2->intf[0]->dev, in ati_remote2_open()
271 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { in ati_remote2_open()
277 ar2->flags |= ATI_REMOTE2_OPENED; in ati_remote2_open()
281 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_open()
287 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_open()
296 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_close()
300 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) in ati_remote2_close()
303 ar2->flags &= ~ATI_REMOTE2_OPENED; in ati_remote2_close()
310 struct input_dev *idev = ar2->idev; in ati_remote2_input_mouse()
311 u8 *data = ar2->buf[0]; in ati_remote2_input_mouse()
312 int channel, mode; in ati_remote2_input_mouse() local
316 if (!((1 << channel) & ar2->channel_mask)) in ati_remote2_input_mouse()
319 mode = data[0] & 0x0F; in ati_remote2_input_mouse()
321 if (mode > ATI_REMOTE2_PC) { in ati_remote2_input_mouse()
322 dev_err(&ar2->intf[0]->dev, in ati_remote2_input_mouse()
323 "Unknown mode byte (%02x %02x %02x %02x)\n", in ati_remote2_input_mouse()
328 if (!((1 << mode) & ar2->mode_mask)) in ati_remote2_input_mouse()
344 return -1; in ati_remote2_lookup()
349 struct input_dev *idev = ar2->idev; in ati_remote2_input_key()
350 u8 *data = ar2->buf[1]; in ati_remote2_input_key()
351 int channel, mode, hw_code, index; in ati_remote2_input_key() local
355 if (!((1 << channel) & ar2->channel_mask)) in ati_remote2_input_key()
358 mode = data[0] & 0x0F; in ati_remote2_input_key()
360 if (mode > ATI_REMOTE2_PC) { in ati_remote2_input_key()
361 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
362 "Unknown mode byte (%02x %02x %02x %02x)\n", in ati_remote2_input_key()
372 * pressed mode key. Naturally we don't want to generate key in ati_remote2_input_key()
374 * events from the same mode key. in ati_remote2_input_key()
376 if (ar2->mode == mode) in ati_remote2_input_key()
380 ar2->mode = mode; in ati_remote2_input_key()
383 if (!((1 << mode) & ar2->mode_mask)) in ati_remote2_input_key()
388 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
398 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]); in ati_remote2_input_key()
403 if (ar2->keycode[mode][index] == BTN_LEFT || in ati_remote2_input_key()
404 ar2->keycode[mode][index] == BTN_RIGHT) in ati_remote2_input_key()
407 if (!time_after_eq(jiffies, ar2->jiffies)) in ati_remote2_input_key()
410 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]); in ati_remote2_input_key()
413 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
419 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]); in ati_remote2_input_key()
425 struct ati_remote2 *ar2 = urb->context; in ati_remote2_complete_mouse()
428 switch (urb->status) { in ati_remote2_complete_mouse()
430 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_mouse()
433 case -ENOENT: in ati_remote2_complete_mouse()
434 case -EILSEQ: in ati_remote2_complete_mouse()
435 case -ECONNRESET: in ati_remote2_complete_mouse()
436 case -ESHUTDOWN: in ati_remote2_complete_mouse()
437 dev_dbg(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
438 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_mouse()
441 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_mouse()
442 dev_err(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
443 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_mouse()
448 dev_err(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
454 struct ati_remote2 *ar2 = urb->context; in ati_remote2_complete_key()
457 switch (urb->status) { in ati_remote2_complete_key()
459 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_key()
462 case -ENOENT: in ati_remote2_complete_key()
463 case -EILSEQ: in ati_remote2_complete_key()
464 case -ECONNRESET: in ati_remote2_complete_key()
465 case -ESHUTDOWN: in ati_remote2_complete_key()
466 dev_dbg(&ar2->intf[1]->dev, in ati_remote2_complete_key()
467 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_key()
470 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_key()
471 dev_err(&ar2->intf[1]->dev, in ati_remote2_complete_key()
472 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_key()
477 dev_err(&ar2->intf[1]->dev, in ati_remote2_complete_key()
485 unsigned int mode; in ati_remote2_getkeycode() local
490 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ati_remote2_getkeycode()
491 index = ke->index; in ati_remote2_getkeycode()
494 return -EINVAL; in ati_remote2_getkeycode()
496 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_getkeycode()
497 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_getkeycode()
498 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code; in ati_remote2_getkeycode()
501 return -EINVAL; in ati_remote2_getkeycode()
503 mode = scancode >> 8; in ati_remote2_getkeycode()
504 if (mode > ATI_REMOTE2_PC) in ati_remote2_getkeycode()
505 return -EINVAL; in ati_remote2_getkeycode()
509 return -EINVAL; in ati_remote2_getkeycode()
511 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset; in ati_remote2_getkeycode()
514 ke->keycode = ar2->keycode[mode][offset]; in ati_remote2_getkeycode()
515 ke->len = sizeof(scancode); in ati_remote2_getkeycode()
516 memcpy(&ke->scancode, &scancode, sizeof(scancode)); in ati_remote2_getkeycode()
517 ke->index = index; in ati_remote2_getkeycode()
527 unsigned int mode; in ati_remote2_setkeycode() local
532 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ati_remote2_setkeycode()
533 if (ke->index >= ATI_REMOTE2_MODES * in ati_remote2_setkeycode()
535 return -EINVAL; in ati_remote2_setkeycode()
537 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_setkeycode()
538 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_setkeycode()
541 return -EINVAL; in ati_remote2_setkeycode()
543 mode = scancode >> 8; in ati_remote2_setkeycode()
544 if (mode > ATI_REMOTE2_PC) in ati_remote2_setkeycode()
545 return -EINVAL; in ati_remote2_setkeycode()
549 return -EINVAL; in ati_remote2_setkeycode()
552 *old_keycode = ar2->keycode[mode][offset]; in ati_remote2_setkeycode()
553 ar2->keycode[mode][offset] = ke->keycode; in ati_remote2_setkeycode()
554 __set_bit(ke->keycode, idev->keybit); in ati_remote2_setkeycode()
556 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { in ati_remote2_setkeycode()
558 if (ar2->keycode[mode][index] == *old_keycode) in ati_remote2_setkeycode()
563 __clear_bit(*old_keycode, idev->keybit); in ati_remote2_setkeycode()
571 int index, mode, retval; in ati_remote2_input_init() local
575 return -ENOMEM; in ati_remote2_input_init()
577 ar2->idev = idev; in ati_remote2_input_init()
580 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL); in ati_remote2_input_init()
581 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | in ati_remote2_input_init()
583 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); in ati_remote2_input_init()
585 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { in ati_remote2_input_init()
587 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode; in ati_remote2_input_init()
588 __set_bit(ar2->keycode[mode][index], idev->keybit); in ati_remote2_input_init()
592 /* AUX1-AUX4 and PC generate the same scancode. */ in ati_remote2_input_init()
594 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1; in ati_remote2_input_init()
595 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2; in ati_remote2_input_init()
596 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3; in ati_remote2_input_init()
597 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4; in ati_remote2_input_init()
598 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC; in ati_remote2_input_init()
599 __set_bit(KEY_PROG1, idev->keybit); in ati_remote2_input_init()
600 __set_bit(KEY_PROG2, idev->keybit); in ati_remote2_input_init()
601 __set_bit(KEY_PROG3, idev->keybit); in ati_remote2_input_init()
602 __set_bit(KEY_PROG4, idev->keybit); in ati_remote2_input_init()
603 __set_bit(KEY_PC, idev->keybit); in ati_remote2_input_init()
605 idev->rep[REP_DELAY] = 250; in ati_remote2_input_init()
606 idev->rep[REP_PERIOD] = 33; in ati_remote2_input_init()
608 idev->open = ati_remote2_open; in ati_remote2_input_init()
609 idev->close = ati_remote2_close; in ati_remote2_input_init()
611 idev->getkeycode = ati_remote2_getkeycode; in ati_remote2_input_init()
612 idev->setkeycode = ati_remote2_setkeycode; in ati_remote2_input_init()
614 idev->name = ar2->name; in ati_remote2_input_init()
615 idev->phys = ar2->phys; in ati_remote2_input_init()
617 usb_to_input_id(ar2->udev, &idev->id); in ati_remote2_input_init()
618 idev->dev.parent = &ar2->udev->dev; in ati_remote2_input_init()
629 struct usb_device *udev = ar2->udev; in ati_remote2_urb_init()
633 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]); in ati_remote2_urb_init()
634 if (!ar2->buf[i]) in ati_remote2_urb_init()
635 return -ENOMEM; in ati_remote2_urb_init()
637 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL); in ati_remote2_urb_init()
638 if (!ar2->urb[i]) in ati_remote2_urb_init()
639 return -ENOMEM; in ati_remote2_urb_init()
641 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress); in ati_remote2_urb_init()
645 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp, in ati_remote2_urb_init()
647 ar2, ar2->ep[i]->bInterval); in ati_remote2_urb_init()
648 ar2->urb[i]->transfer_dma = ar2->buf_dma[i]; in ati_remote2_urb_init()
649 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in ati_remote2_urb_init()
660 usb_free_urb(ar2->urb[i]); in ati_remote2_urb_cleanup()
661 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]); in ati_remote2_urb_cleanup()
671 * channel == 0 -> Accept input from any remote channel in ati_remote2_setup()
672 * channel == 1 -> Only accept input from remote channel 1 in ati_remote2_setup()
673 * channel == 2 -> Only accept input from remote channel 2 in ati_remote2_setup()
675 * channel == 16 -> Only accept input from remote channel 16 in ati_remote2_setup()
687 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0), in ati_remote2_setup()
692 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n", in ati_remote2_setup()
708 return sprintf(buf, "0x%04x\n", ar2->channel_mask); in ati_remote2_show_channel_mask()
726 return -EINVAL; in ati_remote2_store_channel_mask()
728 r = usb_autopm_get_interface(ar2->intf[0]); in ati_remote2_store_channel_mask()
730 dev_err(&ar2->intf[0]->dev, in ati_remote2_store_channel_mask()
737 if (mask != ar2->channel_mask) { in ati_remote2_store_channel_mask()
740 ar2->channel_mask = mask; in ati_remote2_store_channel_mask()
745 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_store_channel_mask()
758 return sprintf(buf, "0x%02x\n", ar2->mode_mask); in ati_remote2_show_mode_mask()
776 return -EINVAL; in ati_remote2_store_mode_mask()
778 ar2->mode_mask = mask; in ati_remote2_store_mode_mask()
802 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_probe()
806 if (alt->desc.bInterfaceNumber) in ati_remote2_probe()
807 return -ENODEV; in ati_remote2_probe()
811 return -ENOMEM; in ati_remote2_probe()
813 ar2->udev = udev; in ati_remote2_probe()
816 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) { in ati_remote2_probe()
817 dev_err(&interface->dev, in ati_remote2_probe()
819 r = -ENODEV; in ati_remote2_probe()
822 ar2->intf[0] = interface; in ati_remote2_probe()
823 ar2->ep[0] = &alt->endpoint[0].desc; in ati_remote2_probe()
826 ar2->intf[1] = usb_ifnum_to_if(udev, 1); in ati_remote2_probe()
827 if ((udev->actconfig->desc.bNumInterfaces < 2) || !ar2->intf[1]) { in ati_remote2_probe()
828 dev_err(&interface->dev, "%s(): need 2 interfaces, found %d\n", in ati_remote2_probe()
829 __func__, udev->actconfig->desc.bNumInterfaces); in ati_remote2_probe()
830 r = -ENODEV; in ati_remote2_probe()
834 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2); in ati_remote2_probe()
839 alt = ar2->intf[1]->cur_altsetting; in ati_remote2_probe()
840 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) { in ati_remote2_probe()
841 dev_err(&interface->dev, in ati_remote2_probe()
843 r = -ENODEV; in ati_remote2_probe()
846 ar2->ep[1] = &alt->endpoint[0].desc; in ati_remote2_probe()
852 ar2->channel_mask = channel_mask; in ati_remote2_probe()
853 ar2->mode_mask = mode_mask; in ati_remote2_probe()
855 r = ati_remote2_setup(ar2, ar2->channel_mask); in ati_remote2_probe()
859 usb_make_path(udev, ar2->phys, sizeof(ar2->phys)); in ati_remote2_probe()
860 strlcat(ar2->phys, "/input0", sizeof(ar2->phys)); in ati_remote2_probe()
862 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name)); in ati_remote2_probe()
864 r = sysfs_create_group(&udev->dev.kobj, &ati_remote2_attr_group); in ati_remote2_probe()
874 interface->needs_remote_wakeup = 1; in ati_remote2_probe()
879 sysfs_remove_group(&udev->dev.kobj, &ati_remote2_attr_group); in ati_remote2_probe()
883 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); in ati_remote2_probe()
893 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_disconnect()
895 if (alt->desc.bInterfaceNumber) in ati_remote2_disconnect()
901 input_unregister_device(ar2->idev); in ati_remote2_disconnect()
903 sysfs_remove_group(&ar2->udev->dev.kobj, &ati_remote2_attr_group); in ati_remote2_disconnect()
907 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); in ati_remote2_disconnect()
916 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_suspend()
918 if (alt->desc.bInterfaceNumber) in ati_remote2_suspend()
923 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_suspend()
927 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_suspend()
930 ar2->flags |= ATI_REMOTE2_SUSPENDED; in ati_remote2_suspend()
940 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_resume()
943 if (alt->desc.bInterfaceNumber) in ati_remote2_resume()
948 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_resume()
952 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_resume()
956 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; in ati_remote2_resume()
966 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_reset_resume()
969 if (alt->desc.bInterfaceNumber) in ati_remote2_reset_resume()
974 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_reset_resume()
978 r = ati_remote2_setup(ar2, ar2->channel_mask); in ati_remote2_reset_resume()
982 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_reset_resume()
986 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; in ati_remote2_reset_resume()
997 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_pre_reset()
999 if (alt->desc.bInterfaceNumber) in ati_remote2_pre_reset()
1004 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_pre_reset()
1008 if (ar2->flags == ATI_REMOTE2_OPENED) in ati_remote2_pre_reset()
1017 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_post_reset()
1020 if (alt->desc.bInterfaceNumber) in ati_remote2_post_reset()
1025 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_post_reset()
1027 if (ar2->flags == ATI_REMOTE2_OPENED) in ati_remote2_post_reset()