2 * FireDTV driver (formerly known as FireSAT)
4 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
12 #include <linux/bitops.h>
13 #include <linux/input.h>
14 #include <linux/kernel.h>
15 #include <linux/string.h>
16 #include <linux/types.h>
20 /* fixed table with older keycodes, geared towards MythTV */
21 const static u16 oldtable[] = {
23 /* code from device: 0x4501...0x451f */
57 /* code from device: 0x4540...0x4542 */
64 /* user-modifiable table for a remote as sold in 2008 */
65 const static u16 keytable[] = {
67 /* code from device: 0x0300...0x031f */
86 [0x11] = KEY_TITLE, /* "OSD" - fixme */
88 [0x13] = KEY_F20, /* "16:9" - fixme */
89 [0x14] = KEY_SCREEN, /* "FULL" - fixme */
91 [0x16] = KEY_SUBTITLE,
96 [0x1b] = KEY_PREVIOUS,
98 [0x1d] = KEY_PLAYPAUSE,
100 [0x1f] = KEY_VOLUMEUP,
102 /* code from device: 0x0340...0x0354 */
104 [0x20] = KEY_CHANNELUP,
105 [0x21] = KEY_F21, /* "4:3" - fixme */
113 [0x29] = KEY_CHANNEL, /* "CH.LIST" */
114 [0x2a] = KEY_VENDOR, /* "CI" - fixme */
115 [0x2b] = KEY_VOLUMEDOWN,
116 [0x2c] = KEY_CHANNELDOWN,
119 [0x2f] = KEY_FORWARD,
121 [0x31] = KEY_FAVORITES,
127 int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
129 struct input_dev *idev;
132 idev = input_allocate_device();
136 fdtv->remote_ctrl_dev = idev;
137 idev->name = "FireDTV remote control";
138 idev->dev.parent = dev;
139 idev->evbit[0] = BIT_MASK(EV_KEY);
140 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
141 if (!idev->keycode) {
145 idev->keycodesize = sizeof(keytable[0]);
146 idev->keycodemax = ARRAY_SIZE(keytable);
148 for (i = 0; i < ARRAY_SIZE(keytable); i++)
149 set_bit(keytable[i], idev->keybit);
151 err = input_register_device(idev);
153 goto fail_free_keymap;
158 kfree(idev->keycode);
160 input_free_device(idev);
164 void fdtv_unregister_rc(struct firedtv *fdtv)
166 kfree(fdtv->remote_ctrl_dev->keycode);
167 input_unregister_device(fdtv->remote_ctrl_dev);
170 void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
172 u16 *keycode = fdtv->remote_ctrl_dev->keycode;
174 if (code >= 0x0300 && code <= 0x031f)
175 code = keycode[code - 0x0300];
176 else if (code >= 0x0340 && code <= 0x0354)
177 code = keycode[code - 0x0320];
178 else if (code >= 0x4501 && code <= 0x451f)
179 code = oldtable[code - 0x4501];
180 else if (code >= 0x4540 && code <= 0x4542)
181 code = oldtable[code - 0x4521];
183 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
184 "from remote control\n", code);
188 input_report_key(fdtv->remote_ctrl_dev, code, 1);
189 input_report_key(fdtv->remote_ctrl_dev, code, 0);