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>
21 /* fixed table with older keycodes, geared towards MythTV */
22 static const u16 oldtable
[] = {
24 /* code from device: 0x4501...0x451f */
58 /* code from device: 0x4540...0x4542 */
65 /* user-modifiable table for a remote as sold in 2008 */
66 static const u16 keytable
[] = {
68 /* code from device: 0x0300...0x031f */
87 [0x11] = KEY_TITLE
, /* "OSD" - fixme */
89 [0x13] = KEY_F20
, /* "16:9" - fixme */
90 [0x14] = KEY_SCREEN
, /* "FULL" - fixme */
92 [0x16] = KEY_SUBTITLE
,
97 [0x1b] = KEY_PREVIOUS
,
99 [0x1d] = KEY_PLAYPAUSE
,
101 [0x1f] = KEY_VOLUMEUP
,
103 /* code from device: 0x0340...0x0354 */
105 [0x20] = KEY_CHANNELUP
,
106 [0x21] = KEY_F21
, /* "4:3" - fixme */
114 [0x29] = KEY_CHANNEL
, /* "CH.LIST" */
115 [0x2a] = KEY_VENDOR
, /* "CI" - fixme */
116 [0x2b] = KEY_VOLUMEDOWN
,
117 [0x2c] = KEY_CHANNELDOWN
,
120 [0x2f] = KEY_FORWARD
,
122 [0x31] = KEY_FAVORITES
,
128 int fdtv_register_rc(struct firedtv
*fdtv
, struct device
*dev
)
130 struct input_dev
*idev
;
133 idev
= input_allocate_device();
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
) {
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
);
154 goto fail_free_keymap
;
159 kfree(idev
->keycode
);
161 input_free_device(idev
);
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];
185 printk(KERN_DEBUG
"firedtv: invalid key code 0x%04x "
186 "from remote control\n", code
);
190 input_report_key(fdtv
->remote_ctrl_dev
, code
, 1);
191 input_report_key(fdtv
->remote_ctrl_dev
, code
, 0);