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. */
213 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); in ati_remote2_submit_urbs()
215 dev_err(&ar2->intf[0]->dev, in ati_remote2_submit_urbs()
219 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); in ati_remote2_submit_urbs()
221 usb_kill_urb(ar2->urb[0]); in ati_remote2_submit_urbs()
222 dev_err(&ar2->intf[1]->dev, in ati_remote2_submit_urbs()
232 usb_kill_urb(ar2->urb[1]); in ati_remote2_kill_urbs()
233 usb_kill_urb(ar2->urb[0]); in ati_remote2_kill_urbs()
241 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_open()
243 r = usb_autopm_get_interface(ar2->intf[0]); in ati_remote2_open()
245 dev_err(&ar2->intf[0]->dev, in ati_remote2_open()
252 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) { in ati_remote2_open()
258 ar2->flags |= ATI_REMOTE2_OPENED; in ati_remote2_open()
262 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_open()
268 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_open()
277 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_close()
281 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) in ati_remote2_close()
284 ar2->flags &= ~ATI_REMOTE2_OPENED; in ati_remote2_close()
291 struct input_dev *idev = ar2->idev; in ati_remote2_input_mouse()
292 u8 *data = ar2->buf[0]; in ati_remote2_input_mouse()
293 int channel, mode; in ati_remote2_input_mouse() local
297 if (!((1 << channel) & ar2->channel_mask)) in ati_remote2_input_mouse()
300 mode = data[0] & 0x0F; in ati_remote2_input_mouse()
302 if (mode > ATI_REMOTE2_PC) { in ati_remote2_input_mouse()
303 dev_err(&ar2->intf[0]->dev, in ati_remote2_input_mouse()
304 "Unknown mode byte (%02x %02x %02x %02x)\n", in ati_remote2_input_mouse()
309 if (!((1 << mode) & ar2->mode_mask)) in ati_remote2_input_mouse()
325 return -1; in ati_remote2_lookup()
330 struct input_dev *idev = ar2->idev; in ati_remote2_input_key()
331 u8 *data = ar2->buf[1]; in ati_remote2_input_key()
332 int channel, mode, hw_code, index; in ati_remote2_input_key() local
336 if (!((1 << channel) & ar2->channel_mask)) in ati_remote2_input_key()
339 mode = data[0] & 0x0F; in ati_remote2_input_key()
341 if (mode > ATI_REMOTE2_PC) { in ati_remote2_input_key()
342 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
343 "Unknown mode byte (%02x %02x %02x %02x)\n", in ati_remote2_input_key()
353 * pressed mode key. Naturally we don't want to generate key in ati_remote2_input_key()
355 * events from the same mode key. in ati_remote2_input_key()
357 if (ar2->mode == mode) in ati_remote2_input_key()
361 ar2->mode = mode; in ati_remote2_input_key()
364 if (!((1 << mode) & ar2->mode_mask)) in ati_remote2_input_key()
369 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
379 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_DELAY]); in ati_remote2_input_key()
384 if (ar2->keycode[mode][index] == BTN_LEFT || in ati_remote2_input_key()
385 ar2->keycode[mode][index] == BTN_RIGHT) in ati_remote2_input_key()
388 if (!time_after_eq(jiffies, ar2->jiffies)) in ati_remote2_input_key()
391 ar2->jiffies = jiffies + msecs_to_jiffies(idev->rep[REP_PERIOD]); in ati_remote2_input_key()
394 dev_err(&ar2->intf[1]->dev, in ati_remote2_input_key()
400 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]); in ati_remote2_input_key()
406 struct ati_remote2 *ar2 = urb->context; in ati_remote2_complete_mouse()
409 switch (urb->status) { in ati_remote2_complete_mouse()
411 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_mouse()
414 case -ENOENT: in ati_remote2_complete_mouse()
415 case -EILSEQ: in ati_remote2_complete_mouse()
416 case -ECONNRESET: in ati_remote2_complete_mouse()
417 case -ESHUTDOWN: in ati_remote2_complete_mouse()
418 dev_dbg(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
419 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_mouse()
422 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_mouse()
423 dev_err(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
424 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_mouse()
429 dev_err(&ar2->intf[0]->dev, in ati_remote2_complete_mouse()
435 struct ati_remote2 *ar2 = urb->context; in ati_remote2_complete_key()
438 switch (urb->status) { in ati_remote2_complete_key()
440 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_key()
443 case -ENOENT: in ati_remote2_complete_key()
444 case -EILSEQ: in ati_remote2_complete_key()
445 case -ECONNRESET: in ati_remote2_complete_key()
446 case -ESHUTDOWN: in ati_remote2_complete_key()
447 dev_dbg(&ar2->intf[1]->dev, in ati_remote2_complete_key()
448 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_key()
451 usb_mark_last_busy(ar2->udev); in ati_remote2_complete_key()
452 dev_err(&ar2->intf[1]->dev, in ati_remote2_complete_key()
453 "%s(): urb status = %d\n", __func__, urb->status); in ati_remote2_complete_key()
458 dev_err(&ar2->intf[1]->dev, in ati_remote2_complete_key()
466 unsigned int mode; in ati_remote2_getkeycode() local
471 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ati_remote2_getkeycode()
472 index = ke->index; in ati_remote2_getkeycode()
475 return -EINVAL; in ati_remote2_getkeycode()
477 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_getkeycode()
478 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_getkeycode()
479 scancode = (mode << 8) + ati_remote2_key_table[offset].hw_code; in ati_remote2_getkeycode()
482 return -EINVAL; in ati_remote2_getkeycode()
484 mode = scancode >> 8; in ati_remote2_getkeycode()
485 if (mode > ATI_REMOTE2_PC) in ati_remote2_getkeycode()
486 return -EINVAL; in ati_remote2_getkeycode()
490 return -EINVAL; in ati_remote2_getkeycode()
492 index = mode * ARRAY_SIZE(ati_remote2_key_table) + offset; in ati_remote2_getkeycode()
495 ke->keycode = ar2->keycode[mode][offset]; in ati_remote2_getkeycode()
496 ke->len = sizeof(scancode); in ati_remote2_getkeycode()
497 memcpy(&ke->scancode, &scancode, sizeof(scancode)); in ati_remote2_getkeycode()
498 ke->index = index; in ati_remote2_getkeycode()
508 unsigned int mode; in ati_remote2_setkeycode() local
513 if (ke->flags & INPUT_KEYMAP_BY_INDEX) { in ati_remote2_setkeycode()
514 if (ke->index >= ATI_REMOTE2_MODES * in ati_remote2_setkeycode()
516 return -EINVAL; in ati_remote2_setkeycode()
518 mode = ke->index / ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_setkeycode()
519 offset = ke->index % ARRAY_SIZE(ati_remote2_key_table); in ati_remote2_setkeycode()
522 return -EINVAL; in ati_remote2_setkeycode()
524 mode = scancode >> 8; in ati_remote2_setkeycode()
525 if (mode > ATI_REMOTE2_PC) in ati_remote2_setkeycode()
526 return -EINVAL; in ati_remote2_setkeycode()
530 return -EINVAL; in ati_remote2_setkeycode()
533 *old_keycode = ar2->keycode[mode][offset]; in ati_remote2_setkeycode()
534 ar2->keycode[mode][offset] = ke->keycode; in ati_remote2_setkeycode()
535 __set_bit(ke->keycode, idev->keybit); in ati_remote2_setkeycode()
537 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { in ati_remote2_setkeycode()
539 if (ar2->keycode[mode][index] == *old_keycode) in ati_remote2_setkeycode()
544 __clear_bit(*old_keycode, idev->keybit); in ati_remote2_setkeycode()
552 int index, mode, retval; in ati_remote2_input_init() local
556 return -ENOMEM; in ati_remote2_input_init()
558 ar2->idev = idev; in ati_remote2_input_init()
561 idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) | BIT_MASK(EV_REL); in ati_remote2_input_init()
562 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | in ati_remote2_input_init()
564 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); in ati_remote2_input_init()
566 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) { in ati_remote2_input_init()
568 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode; in ati_remote2_input_init()
569 __set_bit(ar2->keycode[mode][index], idev->keybit); in ati_remote2_input_init()
573 /* AUX1-AUX4 and PC generate the same scancode. */ in ati_remote2_input_init()
575 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1; in ati_remote2_input_init()
576 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2; in ati_remote2_input_init()
577 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3; in ati_remote2_input_init()
578 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4; in ati_remote2_input_init()
579 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC; in ati_remote2_input_init()
580 __set_bit(KEY_PROG1, idev->keybit); in ati_remote2_input_init()
581 __set_bit(KEY_PROG2, idev->keybit); in ati_remote2_input_init()
582 __set_bit(KEY_PROG3, idev->keybit); in ati_remote2_input_init()
583 __set_bit(KEY_PROG4, idev->keybit); in ati_remote2_input_init()
584 __set_bit(KEY_PC, idev->keybit); in ati_remote2_input_init()
586 idev->rep[REP_DELAY] = 250; in ati_remote2_input_init()
587 idev->rep[REP_PERIOD] = 33; in ati_remote2_input_init()
589 idev->open = ati_remote2_open; in ati_remote2_input_init()
590 idev->close = ati_remote2_close; in ati_remote2_input_init()
592 idev->getkeycode = ati_remote2_getkeycode; in ati_remote2_input_init()
593 idev->setkeycode = ati_remote2_setkeycode; in ati_remote2_input_init()
595 idev->name = ar2->name; in ati_remote2_input_init()
596 idev->phys = ar2->phys; in ati_remote2_input_init()
598 usb_to_input_id(ar2->udev, &idev->id); in ati_remote2_input_init()
599 idev->dev.parent = &ar2->udev->dev; in ati_remote2_input_init()
610 struct usb_device *udev = ar2->udev; in ati_remote2_urb_init()
614 ar2->buf[i] = usb_alloc_coherent(udev, 4, GFP_KERNEL, &ar2->buf_dma[i]); in ati_remote2_urb_init()
615 if (!ar2->buf[i]) in ati_remote2_urb_init()
616 return -ENOMEM; in ati_remote2_urb_init()
618 ar2->urb[i] = usb_alloc_urb(0, GFP_KERNEL); in ati_remote2_urb_init()
619 if (!ar2->urb[i]) in ati_remote2_urb_init()
620 return -ENOMEM; in ati_remote2_urb_init()
622 pipe = usb_rcvintpipe(udev, ar2->ep[i]->bEndpointAddress); in ati_remote2_urb_init()
626 usb_fill_int_urb(ar2->urb[i], udev, pipe, ar2->buf[i], maxp, in ati_remote2_urb_init()
628 ar2, ar2->ep[i]->bInterval); in ati_remote2_urb_init()
629 ar2->urb[i]->transfer_dma = ar2->buf_dma[i]; in ati_remote2_urb_init()
630 ar2->urb[i]->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; in ati_remote2_urb_init()
641 usb_free_urb(ar2->urb[i]); in ati_remote2_urb_cleanup()
642 usb_free_coherent(ar2->udev, 4, ar2->buf[i], ar2->buf_dma[i]); in ati_remote2_urb_cleanup()
652 * channel == 0 -> Accept input from any remote channel in ati_remote2_setup()
653 * channel == 1 -> Only accept input from remote channel 1 in ati_remote2_setup()
654 * channel == 2 -> Only accept input from remote channel 2 in ati_remote2_setup()
656 * channel == 16 -> Only accept input from remote channel 16 in ati_remote2_setup()
668 r = usb_control_msg(ar2->udev, usb_sndctrlpipe(ar2->udev, 0), in ati_remote2_setup()
673 dev_err(&ar2->udev->dev, "%s - failed to set channel due to error: %d\n", in ati_remote2_setup()
689 return sprintf(buf, "0x%04x\n", ar2->channel_mask); in ati_remote2_show_channel_mask()
707 return -EINVAL; in ati_remote2_store_channel_mask()
709 r = usb_autopm_get_interface(ar2->intf[0]); in ati_remote2_store_channel_mask()
711 dev_err(&ar2->intf[0]->dev, in ati_remote2_store_channel_mask()
718 if (mask != ar2->channel_mask) { in ati_remote2_store_channel_mask()
721 ar2->channel_mask = mask; in ati_remote2_store_channel_mask()
726 usb_autopm_put_interface(ar2->intf[0]); in ati_remote2_store_channel_mask()
739 return sprintf(buf, "0x%02x\n", ar2->mode_mask); in ati_remote2_show_mode_mask()
757 return -EINVAL; in ati_remote2_store_mode_mask()
759 ar2->mode_mask = mask; in ati_remote2_store_mode_mask()
780 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_probe()
784 if (alt->desc.bInterfaceNumber) in ati_remote2_probe()
785 return -ENODEV; in ati_remote2_probe()
789 return -ENOMEM; in ati_remote2_probe()
791 ar2->udev = udev; in ati_remote2_probe()
794 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) { in ati_remote2_probe()
795 dev_err(&interface->dev, in ati_remote2_probe()
797 r = -ENODEV; in ati_remote2_probe()
800 ar2->intf[0] = interface; in ati_remote2_probe()
801 ar2->ep[0] = &alt->endpoint[0].desc; in ati_remote2_probe()
804 ar2->intf[1] = usb_ifnum_to_if(udev, 1); in ati_remote2_probe()
805 if ((udev->actconfig->desc.bNumInterfaces < 2) || !ar2->intf[1]) { in ati_remote2_probe()
806 dev_err(&interface->dev, "%s(): need 2 interfaces, found %d\n", in ati_remote2_probe()
807 __func__, udev->actconfig->desc.bNumInterfaces); in ati_remote2_probe()
808 r = -ENODEV; in ati_remote2_probe()
812 r = usb_driver_claim_interface(&ati_remote2_driver, ar2->intf[1], ar2); in ati_remote2_probe()
817 alt = ar2->intf[1]->cur_altsetting; in ati_remote2_probe()
818 if (alt->desc.bNumEndpoints < 1 || !alt->endpoint) { in ati_remote2_probe()
819 dev_err(&interface->dev, in ati_remote2_probe()
821 r = -ENODEV; in ati_remote2_probe()
824 ar2->ep[1] = &alt->endpoint[0].desc; in ati_remote2_probe()
830 ar2->channel_mask = channel_mask; in ati_remote2_probe()
831 ar2->mode_mask = mode_mask; in ati_remote2_probe()
833 r = ati_remote2_setup(ar2, ar2->channel_mask); in ati_remote2_probe()
837 usb_make_path(udev, ar2->phys, sizeof(ar2->phys)); in ati_remote2_probe()
838 strlcat(ar2->phys, "/input0", sizeof(ar2->phys)); in ati_remote2_probe()
840 strlcat(ar2->name, "ATI Remote Wonder II", sizeof(ar2->name)); in ati_remote2_probe()
848 interface->needs_remote_wakeup = 1; in ati_remote2_probe()
855 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); in ati_remote2_probe()
865 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_disconnect()
867 if (alt->desc.bInterfaceNumber) in ati_remote2_disconnect()
873 input_unregister_device(ar2->idev); in ati_remote2_disconnect()
877 usb_driver_release_interface(&ati_remote2_driver, ar2->intf[1]); in ati_remote2_disconnect()
886 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_suspend()
888 if (alt->desc.bInterfaceNumber) in ati_remote2_suspend()
893 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_suspend()
897 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_suspend()
900 ar2->flags |= ATI_REMOTE2_SUSPENDED; in ati_remote2_suspend()
910 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_resume()
913 if (alt->desc.bInterfaceNumber) in ati_remote2_resume()
918 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_resume()
922 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_resume()
926 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; in ati_remote2_resume()
936 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_reset_resume()
939 if (alt->desc.bInterfaceNumber) in ati_remote2_reset_resume()
944 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_reset_resume()
948 r = ati_remote2_setup(ar2, ar2->channel_mask); in ati_remote2_reset_resume()
952 if (ar2->flags & ATI_REMOTE2_OPENED) in ati_remote2_reset_resume()
956 ar2->flags &= ~ATI_REMOTE2_SUSPENDED; in ati_remote2_reset_resume()
967 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_pre_reset()
969 if (alt->desc.bInterfaceNumber) in ati_remote2_pre_reset()
974 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_pre_reset()
978 if (ar2->flags == ATI_REMOTE2_OPENED) in ati_remote2_pre_reset()
987 struct usb_host_interface *alt = interface->cur_altsetting; in ati_remote2_post_reset()
990 if (alt->desc.bInterfaceNumber) in ati_remote2_post_reset()
995 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__); in ati_remote2_post_reset()
997 if (ar2->flags == ATI_REMOTE2_OPENED) in ati_remote2_post_reset()