1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * FireDTV driver (formerly known as FireSAT)
5 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
8 #include <linux/bitops.h>
9 #include <linux/input.h>
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/string.h>
13 #include <linux/types.h>
14 #include <linux/workqueue.h>
18 /* fixed table with older keycodes, geared towards MythTV */
19 static const u16 oldtable
[] = {
21 /* code from device: 0x4501...0x451f */
55 /* code from device: 0x4540...0x4542 */
62 /* user-modifiable table for a remote as sold in 2008 */
63 static const u16 keytable
[] = {
65 /* code from device: 0x0300...0x031f */
84 [0x11] = KEY_TITLE
, /* "OSD" - fixme */
86 [0x13] = KEY_F20
, /* "16:9" - fixme */
87 [0x14] = KEY_SCREEN
, /* "FULL" - fixme */
89 [0x16] = KEY_SUBTITLE
,
94 [0x1b] = KEY_PREVIOUS
,
96 [0x1d] = KEY_PLAYPAUSE
,
98 [0x1f] = KEY_VOLUMEUP
,
100 /* code from device: 0x0340...0x0354 */
102 [0x20] = KEY_CHANNELUP
,
103 [0x21] = KEY_F21
, /* "4:3" - fixme */
111 [0x29] = KEY_CHANNEL
, /* "CH.LIST" */
112 [0x2a] = KEY_VENDOR
, /* "CI" - fixme */
113 [0x2b] = KEY_VOLUMEDOWN
,
114 [0x2c] = KEY_CHANNELDOWN
,
117 [0x2f] = KEY_FORWARD
,
119 [0x31] = KEY_FAVORITES
,
125 int fdtv_register_rc(struct firedtv
*fdtv
, struct device
*dev
)
127 struct input_dev
*idev
;
130 idev
= input_allocate_device();
134 fdtv
->remote_ctrl_dev
= idev
;
135 idev
->name
= "FireDTV remote control";
136 idev
->dev
.parent
= dev
;
137 idev
->evbit
[0] = BIT_MASK(EV_KEY
);
138 idev
->keycode
= kmemdup(keytable
, sizeof(keytable
), GFP_KERNEL
);
139 if (!idev
->keycode
) {
143 idev
->keycodesize
= sizeof(keytable
[0]);
144 idev
->keycodemax
= ARRAY_SIZE(keytable
);
146 for (i
= 0; i
< ARRAY_SIZE(keytable
); i
++)
147 set_bit(keytable
[i
], idev
->keybit
);
149 err
= input_register_device(idev
);
151 goto fail_free_keymap
;
156 kfree(idev
->keycode
);
158 input_free_device(idev
);
162 void fdtv_unregister_rc(struct firedtv
*fdtv
)
164 cancel_work_sync(&fdtv
->remote_ctrl_work
);
165 kfree(fdtv
->remote_ctrl_dev
->keycode
);
166 input_unregister_device(fdtv
->remote_ctrl_dev
);
169 void fdtv_handle_rc(struct firedtv
*fdtv
, unsigned int code
)
171 struct input_dev
*idev
= fdtv
->remote_ctrl_dev
;
172 u16
*keycode
= idev
->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 dev_dbg(fdtv
->device
,
184 "invalid key code 0x%04x from remote control\n",
189 input_report_key(idev
, code
, 1);
191 input_report_key(idev
, code
, 0);