// SPDX-License-Identifier: GPL-2.0-or-later /* * USB ATI Remote support * * Copyright (c) 2011, 2012 Anssi Hannula <anssi.hannula@iki.fi> * Version 2.2.0 Copyright (c) 2004 Torrey Hoffman <thoffman@arnor.net> * Version 2.1.1 Copyright (c) 2002 Vladimir Dergachev * * This 2.2.0 version is a rewrite / cleanup of the 2.1.1 driver, including * porting to the 2.6 kernel interfaces, along with other modification * to better match the style of the existing usb/input drivers. However, the * protocol and hardware handling is essentially unchanged from 2.1.1. * * The 2.1.1 driver was derived from the usbati_remote and usbkbd drivers by * Vojtech Pavlik. * * Changes: * * Feb 2004: Torrey Hoffman <thoffman@arnor.net> * Version 2.2.0 * Jun 2004: Torrey Hoffman <thoffman@arnor.net> * Version 2.2.1 * Added key repeat support contributed by: * Vincent Vanackere <vanackere@lif.univ-mrs.fr> * Added support for the "Lola" remote contributed by: * Seth Cohn <sethcohn@yahoo.com> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Hardware & software notes * * These remote controls are distributed by ATI as part of their * "All-In-Wonder" video card packages. The receiver self-identifies as a * "USB Receiver" with manufacturer "X10 Wireless Technology Inc". * * The "Lola" remote is available from X10. See: * http://www.x10.com/products/lola_sg1.htm * The Lola is similar to the ATI remote but has no mouse support, and slightly * different keys. * * It is possible to use multiple receivers and remotes on multiple computers * simultaneously by configuring them to use specific channels. * * The RF protocol used by the remote supports 16 distinct channels, 1 to 16. * Actually, it may even support more, at least in some revisions of the * hardware. * * Each remote can be configured to transmit on one channel as follows: * - Press and hold the "hand icon" button. * - When the red LED starts to blink, let go of the "hand icon" button. * - When it stops blinking, input the channel code as two digits, from 01 * to 16, and press the hand icon again. * * The timing can be a little tricky. Try loading the module with debug=1 * to have the kernel print out messages about the remote control number * and mask. Note: debugging prints remote numbers as zero-based hexadecimal. * * The driver has a "channel_mask" parameter. This bitmask specifies which * channels will be ignored by the module. To mask out channels, just add * all the 2^channel_number values together. * * For instance, set channel_mask = 2^4 = 16 (binary 10000) to make ati_remote * ignore signals coming from remote controls transmitting on channel 4, but * accept all other channels. * * Or, set channel_mask = 65533, (0xFFFD), and all channels except 1 will be * ignored. * * The default is 0 (respond to all channels). Bit 0 and bits 17-32 of this * parameter are unused.
*/
#define NAME_BUFSIZE 80 /* size of product name, path buffers */ #define DATA_BUFSIZE 63 /* size of URB data buffers */
/* * Duplicate event filtering time. * Sequential, identical KIND_FILTERED inputs with less than * FILTER_TIME milliseconds between them are considered as repeat * events. The hardware generates 5 events for the first keypress * and we have to take this into account for an accurate repeat * behaviour.
*/ #define FILTER_TIME 60 /* msec */ #define REPEAT_DELAY 500 /* msec */
staticunsignedlong channel_mask;
module_param(channel_mask, ulong, 0644);
MODULE_PARM_DESC(channel_mask, "Bitmask of remote control channels to ignore");
staticint debug;
module_param(debug, int, 0644);
MODULE_PARM_DESC(debug, "Enable extra debug messages and information");
#define dbginfo(dev, format, arg...) \ do { if (debug) dev_info(dev , format , ## arg); } while (0)
struct ati_receiver_type { /* either default_keymap or get_default_keymap should be set */ constchar *default_keymap; constchar *(*get_default_keymap)(struct usb_interface *interface);
};
/* * There are many different Medion remotes shipped with a receiver * with the same usb id, but the receivers have subtle differences * in the USB descriptors allowing us to detect them.
*/
if (udev->manufacturer && udev->product) { if (udev->actconfig->desc.bmAttributes & USB_CONFIG_ATT_WAKEUP) {
int users; /* 0-2, users are rc and input */ struct mutex open_mutex;
};
/* "Kinds" of messages sent from the hardware to the driver. */ #define KIND_END 0 #define KIND_LITERAL 1 /* Simply pass to input system as EV_KEY */ #define KIND_FILTERED 2 /* Add artificial key-up events, drop keyrepeats */ #define KIND_ACCEL 3 /* Translate to EV_REL mouse-move events */
/* Translation table from hardware messages to input events. */ staticconststruct { unsignedchar kind; unsignedchar data; /* Raw key code from remote */ unsignedshort code; /* Input layer translation */
} ati_remote_tbl[] = { /* Directional control pad axes. Code is xxyy */
{KIND_ACCEL, 0x70, 0xff00}, /* left */
{KIND_ACCEL, 0x71, 0x0100}, /* right */
{KIND_ACCEL, 0x72, 0x00ff}, /* up */
{KIND_ACCEL, 0x73, 0x0001}, /* down */
/* Directional control pad diagonals */
{KIND_ACCEL, 0x74, 0xffff}, /* left up */
{KIND_ACCEL, 0x75, 0x01ff}, /* right up */
{KIND_ACCEL, 0x77, 0xff01}, /* left down */
{KIND_ACCEL, 0x76, 0x0101}, /* right down */
/* "Mouse button" buttons. The code below uses the fact that the
* lsbit of the raw code is a down/up indicator. */
{KIND_LITERAL, 0x78, BTN_LEFT}, /* left btn down */
{KIND_LITERAL, 0x79, BTN_LEFT}, /* left btn up */
{KIND_LITERAL, 0x7c, BTN_RIGHT},/* right btn down */
{KIND_LITERAL, 0x7d, BTN_RIGHT},/* right btn up */
/* Artificial "double-click" events are generated by the hardware.
* They are mapped to the "side" and "extra" mouse buttons here. */
{KIND_FILTERED, 0x7a, BTN_SIDE}, /* left dblclick */
{KIND_FILTERED, 0x7e, BTN_EXTRA},/* right dblclick */
/* Non-mouse events are handled by rc-core */
{KIND_END, 0x00, 0}
};
if (ati_remote->users++ != 0) goto out; /* one was already active */
/* On first open, submit the read urb which was set up previously. */
ati_remote->irq_urb->dev = ati_remote->udev; if (usb_submit_urb(ati_remote->irq_urb, GFP_KERNEL)) {
dev_err(&ati_remote->interface->dev, "%s: usb_submit_urb failed!\n", __func__);
err = -EIO;
}
/* * ati_remote_compute_accel * * Implements acceleration curve for directional control pad * If elapsed time since last event is > 1/4 second, user "stopped", * so reset acceleration. Otherwise, user is probably holding the control * pad down, so we increase acceleration, ramping up over two seconds to * a maximum speed.
*/ staticint ati_remote_compute_accel(struct ati_remote *ati_remote)
{ unsignedlong now = jiffies, reset_time; int i;
reset_time = msecs_to_jiffies(250);
if (time_after(now, ati_remote->old_jiffies + reset_time)) {
ati_remote->acc_jiffies = now; return 1;
} for (i = 0; i < ARRAY_SIZE(accel) - 1; i++) { unsignedlong timeout = msecs_to_jiffies(accel[i].msecs);
/* * ati_remote_report_input
*/ staticvoid ati_remote_input_report(struct urb *urb)
{ struct ati_remote *ati_remote = urb->context; unsignedchar *data= ati_remote->inbuf; struct input_dev *dev = ati_remote->idev; int index = -1; int remote_num; unsignedchar scancode;
u32 wheel_keycode = KEY_RESERVED; int i;
/* * data[0] = 0x14 * data[1] = data[2] + data[3] + 0xd5 (a checksum byte) * data[2] = the key code (with toggle bit in MSB with some models) * data[3] = channel << 4 (the low 4 bits must be zero)
*/
if (scancode >= 0x70) { /* * This is either a mouse or scrollwheel event, depending on * the remote/keymap. * Get the keycode assigned to scancode 0x78/0x70. If it is * set, assume this is a scrollwheel up/down event.
*/
wheel_keycode = rc_g_keycode_from_table(ati_remote->rdev,
scancode & 0x78);
if (wheel_keycode == KEY_RESERVED) { /* scrollwheel was not mapped, assume mouse */
/* Look up event code index in the mouse translation * table.
*/ for (i = 0; ati_remote_tbl[i].kind != KIND_END; i++) { if (scancode == ati_remote_tbl[i].data) {
index = i; break;
}
}
}
}
if (index >= 0 && ati_remote_tbl[index].kind == KIND_LITERAL) { /* * The lsbit of the raw key code is a down/up flag. * Invert it to match the input layer's conventions.
*/
input_event(dev, EV_KEY, ati_remote_tbl[index].code,
!(data[2] & 1));
/* Ensure we skip at least the 4 first duplicate events * (generated by a single keypress), and continue skipping * until repeat_delay msecs have passed.
*/ if (ati_remote->repeat_count > 0 &&
(ati_remote->repeat_count < 5 ||
time_before(now, ati_remote->first_jiffies +
msecs_to_jiffies(repeat_delay)))) return;
if (index >= 0) {
input_event(dev, EV_KEY, ati_remote_tbl[index].code, 1);
input_event(dev, EV_KEY, ati_remote_tbl[index].code, 0);
} else { /* Not a mouse event, hand it to rc-core. */ int count = 1;
if (wheel_keycode != KEY_RESERVED) { /* * This is a scrollwheel event, send the * scroll up (0x78) / down (0x70) scancode * repeatedly as many times as indicated by * rest of the scancode.
*/
count = (scancode & 0x07) + 1;
scancode &= 0x78;
}
while (count--) { /* * We don't use the rc-core repeat handling yet as * it would cause ghost repeats which would be a * regression for this driver.
*/
rc_keydown_notimeout(ati_remote->rdev,
RC_PROTO_OTHER,
scancode, data[2]);
rc_keyup(ati_remote->rdev);
} goto nosync;
}
/* * Other event kinds are from the directional control pad, and * have an acceleration factor applied to them. Without this * acceleration, the control pad is mostly unusable.
*/ int acc = ati_remote_compute_accel(ati_remote); if (dx)
input_report_rel(dev, REL_X, dx * acc); if (dy)
input_report_rel(dev, REL_Y, dy * acc);
ati_remote->old_jiffies = jiffies;
/* set default keymap according to receiver model */ if (type) { if (type->default_keymap)
rc_dev->map_name = type->default_keymap; elseif (type->get_default_keymap)
rc_dev->map_name = type->get_default_keymap(interface);
}
/* Device Hardware Initialization - fills in ati_remote->idev from udev. */
err = ati_remote_initialize(ati_remote); if (err) goto exit_kill_urbs;
/* Set up and register rc device */
err = rc_register_device(ati_remote->rdev); if (err) goto exit_kill_urbs;
/* Set up and register mouse input device */ if (mouse) {
input_dev = input_allocate_device(); if (!input_dev) {
err = -ENOMEM; goto exit_unregister_device;
}
usb_kill_urb(ati_remote->irq_urb);
usb_kill_urb(ati_remote->out_urb); if (ati_remote->idev)
input_unregister_device(ati_remote->idev);
rc_unregister_device(ati_remote->rdev);
ati_remote_free_buffers(ati_remote);
kfree(ati_remote);
}
/* usb specific object to register with the usb subsystem */ staticstruct usb_driver ati_remote_driver = {
.name = "ati_remote",
.probe = ati_remote_probe,
.disconnect = ati_remote_disconnect,
.id_table = ati_remote_table,
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.