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/slab.h>
16 #include <linux/string.h>
17 #include <linux/types.h>
18 #include <linux/workqueue.h>
22 /* fixed table with older keycodes, geared towards MythTV */
23 static const u16 oldtable
[] = {
25 /* code from device: 0x4501...0x451f */
59 /* code from device: 0x4540...0x4542 */
66 /* user-modifiable table for a remote as sold in 2008 */
67 static const u16 keytable
[] = {
69 /* code from device: 0x0300...0x031f */
88 [0x11] = KEY_TITLE
, /* "OSD" - fixme */
90 [0x13] = KEY_F20
, /* "16:9" - fixme */
91 [0x14] = KEY_SCREEN
, /* "FULL" - fixme */
93 [0x16] = KEY_SUBTITLE
,
98 [0x1b] = KEY_PREVIOUS
,
100 [0x1d] = KEY_PLAYPAUSE
,
102 [0x1f] = KEY_VOLUMEUP
,
104 /* code from device: 0x0340...0x0354 */
106 [0x20] = KEY_CHANNELUP
,
107 [0x21] = KEY_F21
, /* "4:3" - fixme */
115 [0x29] = KEY_CHANNEL
, /* "CH.LIST" */
116 [0x2a] = KEY_VENDOR
, /* "CI" - fixme */
117 [0x2b] = KEY_VOLUMEDOWN
,
118 [0x2c] = KEY_CHANNELDOWN
,
121 [0x2f] = KEY_FORWARD
,
123 [0x31] = KEY_FAVORITES
,
129 int fdtv_register_rc(struct firedtv
*fdtv
, struct device
*dev
)
131 struct input_dev
*idev
;
134 idev
= input_allocate_device();
138 fdtv
->remote_ctrl_dev
= idev
;
139 idev
->name
= "FireDTV remote control";
140 idev
->dev
.parent
= dev
;
141 idev
->evbit
[0] = BIT_MASK(EV_KEY
);
142 idev
->keycode
= kmemdup(keytable
, sizeof(keytable
), GFP_KERNEL
);
143 if (!idev
->keycode
) {
147 idev
->keycodesize
= sizeof(keytable
[0]);
148 idev
->keycodemax
= ARRAY_SIZE(keytable
);
150 for (i
= 0; i
< ARRAY_SIZE(keytable
); i
++)
151 set_bit(keytable
[i
], idev
->keybit
);
153 err
= input_register_device(idev
);
155 goto fail_free_keymap
;
160 kfree(idev
->keycode
);
162 input_free_device(idev
);
166 void fdtv_unregister_rc(struct firedtv
*fdtv
)
168 cancel_work_sync(&fdtv
->remote_ctrl_work
);
169 kfree(fdtv
->remote_ctrl_dev
->keycode
);
170 input_unregister_device(fdtv
->remote_ctrl_dev
);
173 void fdtv_handle_rc(struct firedtv
*fdtv
, unsigned int code
)
175 struct input_dev
*idev
= fdtv
->remote_ctrl_dev
;
176 u16
*keycode
= idev
->keycode
;
178 if (code
>= 0x0300 && code
<= 0x031f)
179 code
= keycode
[code
- 0x0300];
180 else if (code
>= 0x0340 && code
<= 0x0354)
181 code
= keycode
[code
- 0x0320];
182 else if (code
>= 0x4501 && code
<= 0x451f)
183 code
= oldtable
[code
- 0x4501];
184 else if (code
>= 0x4540 && code
<= 0x4542)
185 code
= oldtable
[code
- 0x4521];
187 dev_dbg(fdtv
->device
,
188 "invalid key code 0x%04x from remote control\n",
193 input_report_key(idev
, code
, 1);
195 input_report_key(idev
, code
, 0);