Linux 2.6.34-rc3
[pohmelfs.git] / drivers / media / dvb / firewire / firedtv-rc.c
blob599d66e5843dcd51668077ad7404618336d10ae5
1 /*
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>
17 #include <linux/workqueue.h>
19 #include "firedtv.h"
21 /* fixed table with older keycodes, geared towards MythTV */
22 static const u16 oldtable[] = {
24 /* code from device: 0x4501...0x451f */
26 KEY_ESC,
27 KEY_F9,
28 KEY_1,
29 KEY_2,
30 KEY_3,
31 KEY_4,
32 KEY_5,
33 KEY_6,
34 KEY_7,
35 KEY_8,
36 KEY_9,
37 KEY_I,
38 KEY_0,
39 KEY_ENTER,
40 KEY_RED,
41 KEY_UP,
42 KEY_GREEN,
43 KEY_F10,
44 KEY_SPACE,
45 KEY_F11,
46 KEY_YELLOW,
47 KEY_DOWN,
48 KEY_BLUE,
49 KEY_Z,
50 KEY_P,
51 KEY_PAGEDOWN,
52 KEY_LEFT,
53 KEY_W,
54 KEY_RIGHT,
55 KEY_P,
56 KEY_M,
58 /* code from device: 0x4540...0x4542 */
60 KEY_R,
61 KEY_V,
62 KEY_C,
65 /* user-modifiable table for a remote as sold in 2008 */
66 static const u16 keytable[] = {
68 /* code from device: 0x0300...0x031f */
70 [0x00] = KEY_POWER,
71 [0x01] = KEY_SLEEP,
72 [0x02] = KEY_STOP,
73 [0x03] = KEY_OK,
74 [0x04] = KEY_RIGHT,
75 [0x05] = KEY_1,
76 [0x06] = KEY_2,
77 [0x07] = KEY_3,
78 [0x08] = KEY_LEFT,
79 [0x09] = KEY_4,
80 [0x0a] = KEY_5,
81 [0x0b] = KEY_6,
82 [0x0c] = KEY_UP,
83 [0x0d] = KEY_7,
84 [0x0e] = KEY_8,
85 [0x0f] = KEY_9,
86 [0x10] = KEY_DOWN,
87 [0x11] = KEY_TITLE, /* "OSD" - fixme */
88 [0x12] = KEY_0,
89 [0x13] = KEY_F20, /* "16:9" - fixme */
90 [0x14] = KEY_SCREEN, /* "FULL" - fixme */
91 [0x15] = KEY_MUTE,
92 [0x16] = KEY_SUBTITLE,
93 [0x17] = KEY_RECORD,
94 [0x18] = KEY_TEXT,
95 [0x19] = KEY_AUDIO,
96 [0x1a] = KEY_RED,
97 [0x1b] = KEY_PREVIOUS,
98 [0x1c] = KEY_REWIND,
99 [0x1d] = KEY_PLAYPAUSE,
100 [0x1e] = KEY_NEXT,
101 [0x1f] = KEY_VOLUMEUP,
103 /* code from device: 0x0340...0x0354 */
105 [0x20] = KEY_CHANNELUP,
106 [0x21] = KEY_F21, /* "4:3" - fixme */
107 [0x22] = KEY_TV,
108 [0x23] = KEY_DVD,
109 [0x24] = KEY_VCR,
110 [0x25] = KEY_AUX,
111 [0x26] = KEY_GREEN,
112 [0x27] = KEY_YELLOW,
113 [0x28] = KEY_BLUE,
114 [0x29] = KEY_CHANNEL, /* "CH.LIST" */
115 [0x2a] = KEY_VENDOR, /* "CI" - fixme */
116 [0x2b] = KEY_VOLUMEDOWN,
117 [0x2c] = KEY_CHANNELDOWN,
118 [0x2d] = KEY_LAST,
119 [0x2e] = KEY_INFO,
120 [0x2f] = KEY_FORWARD,
121 [0x30] = KEY_LIST,
122 [0x31] = KEY_FAVORITES,
123 [0x32] = KEY_MENU,
124 [0x33] = KEY_EPG,
125 [0x34] = KEY_EXIT,
128 int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
130 struct input_dev *idev;
131 int i, err;
133 idev = input_allocate_device();
134 if (!idev)
135 return -ENOMEM;
137 fdtv->remote_ctrl_dev = idev;
138 idev->name = "FireDTV remote control";
139 idev->dev.parent = dev;
140 idev->evbit[0] = BIT_MASK(EV_KEY);
141 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
142 if (!idev->keycode) {
143 err = -ENOMEM;
144 goto fail;
146 idev->keycodesize = sizeof(keytable[0]);
147 idev->keycodemax = ARRAY_SIZE(keytable);
149 for (i = 0; i < ARRAY_SIZE(keytable); i++)
150 set_bit(keytable[i], idev->keybit);
152 err = input_register_device(idev);
153 if (err)
154 goto fail_free_keymap;
156 return 0;
158 fail_free_keymap:
159 kfree(idev->keycode);
160 fail:
161 input_free_device(idev);
162 return err;
165 void fdtv_unregister_rc(struct firedtv *fdtv)
167 cancel_work_sync(&fdtv->remote_ctrl_work);
168 kfree(fdtv->remote_ctrl_dev->keycode);
169 input_unregister_device(fdtv->remote_ctrl_dev);
172 void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
174 u16 *keycode = fdtv->remote_ctrl_dev->keycode;
176 if (code >= 0x0300 && code <= 0x031f)
177 code = keycode[code - 0x0300];
178 else if (code >= 0x0340 && code <= 0x0354)
179 code = keycode[code - 0x0320];
180 else if (code >= 0x4501 && code <= 0x451f)
181 code = oldtable[code - 0x4501];
182 else if (code >= 0x4540 && code <= 0x4542)
183 code = oldtable[code - 0x4521];
184 else {
185 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
186 "from remote control\n", code);
187 return;
190 input_report_key(fdtv->remote_ctrl_dev, code, 1);
191 input_report_key(fdtv->remote_ctrl_dev, code, 0);