blob: f82d4a93feb3f205080a5bdc85d0dcf1b58f48ac [file] [log] [blame]
Stefan Richter612262a2008-08-26 00:17:30 +02001/*
2 * FireDTV driver (formerly known as FireSAT)
3 *
4 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
5 *
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.
10 */
11
12#include <linux/bitops.h>
13#include <linux/input.h>
14#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/slab.h>
Stefan Richter8ae83cd2008-11-02 13:45:00 +010016#include <linux/string.h>
Stefan Richter612262a2008-08-26 00:17:30 +020017#include <linux/types.h>
Stefan Richter56411f42009-11-08 18:28:45 -030018#include <linux/workqueue.h>
Stefan Richter612262a2008-08-26 00:17:30 +020019
Rambaldia70f81c2009-01-17 14:47:34 +010020#include "firedtv.h"
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080021
Stefan Richter612262a2008-08-26 00:17:30 +020022/* fixed table with older keycodes, geared towards MythTV */
Tobias Klauser60c7ef32009-04-26 10:03:29 -030023static const u16 oldtable[] = {
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080024
Stefan Richter612262a2008-08-26 00:17:30 +020025 /* code from device: 0x4501...0x451f */
26
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080027 KEY_ESC,
28 KEY_F9,
29 KEY_1,
30 KEY_2,
31 KEY_3,
32 KEY_4,
33 KEY_5,
34 KEY_6,
35 KEY_7,
36 KEY_8,
37 KEY_9,
38 KEY_I,
39 KEY_0,
40 KEY_ENTER,
41 KEY_RED,
42 KEY_UP,
43 KEY_GREEN,
44 KEY_F10,
45 KEY_SPACE,
46 KEY_F11,
47 KEY_YELLOW,
48 KEY_DOWN,
49 KEY_BLUE,
50 KEY_Z,
51 KEY_P,
52 KEY_PAGEDOWN,
53 KEY_LEFT,
54 KEY_W,
55 KEY_RIGHT,
56 KEY_P,
57 KEY_M,
Stefan Richter612262a2008-08-26 00:17:30 +020058
59 /* code from device: 0x4540...0x4542 */
60
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080061 KEY_R,
62 KEY_V,
63 KEY_C,
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080064};
65
Stefan Richter612262a2008-08-26 00:17:30 +020066/* user-modifiable table for a remote as sold in 2008 */
Tobias Klauser60c7ef32009-04-26 10:03:29 -030067static const u16 keytable[] = {
Stefan Richter612262a2008-08-26 00:17:30 +020068
69 /* code from device: 0x0300...0x031f */
70
71 [0x00] = KEY_POWER,
72 [0x01] = KEY_SLEEP,
73 [0x02] = KEY_STOP,
74 [0x03] = KEY_OK,
75 [0x04] = KEY_RIGHT,
76 [0x05] = KEY_1,
77 [0x06] = KEY_2,
78 [0x07] = KEY_3,
79 [0x08] = KEY_LEFT,
80 [0x09] = KEY_4,
81 [0x0a] = KEY_5,
82 [0x0b] = KEY_6,
83 [0x0c] = KEY_UP,
84 [0x0d] = KEY_7,
85 [0x0e] = KEY_8,
86 [0x0f] = KEY_9,
87 [0x10] = KEY_DOWN,
88 [0x11] = KEY_TITLE, /* "OSD" - fixme */
89 [0x12] = KEY_0,
90 [0x13] = KEY_F20, /* "16:9" - fixme */
91 [0x14] = KEY_SCREEN, /* "FULL" - fixme */
92 [0x15] = KEY_MUTE,
93 [0x16] = KEY_SUBTITLE,
94 [0x17] = KEY_RECORD,
95 [0x18] = KEY_TEXT,
96 [0x19] = KEY_AUDIO,
97 [0x1a] = KEY_RED,
98 [0x1b] = KEY_PREVIOUS,
99 [0x1c] = KEY_REWIND,
100 [0x1d] = KEY_PLAYPAUSE,
101 [0x1e] = KEY_NEXT,
102 [0x1f] = KEY_VOLUMEUP,
103
104 /* code from device: 0x0340...0x0354 */
105
106 [0x20] = KEY_CHANNELUP,
107 [0x21] = KEY_F21, /* "4:3" - fixme */
108 [0x22] = KEY_TV,
109 [0x23] = KEY_DVD,
110 [0x24] = KEY_VCR,
111 [0x25] = KEY_AUX,
112 [0x26] = KEY_GREEN,
113 [0x27] = KEY_YELLOW,
114 [0x28] = KEY_BLUE,
115 [0x29] = KEY_CHANNEL, /* "CH.LIST" */
116 [0x2a] = KEY_VENDOR, /* "CI" - fixme */
117 [0x2b] = KEY_VOLUMEDOWN,
118 [0x2c] = KEY_CHANNELDOWN,
119 [0x2d] = KEY_LAST,
120 [0x2e] = KEY_INFO,
121 [0x2f] = KEY_FORWARD,
122 [0x30] = KEY_LIST,
123 [0x31] = KEY_FAVORITES,
124 [0x32] = KEY_MENU,
125 [0x33] = KEY_EPG,
126 [0x34] = KEY_EXIT,
127};
128
Rambaldia70f81c2009-01-17 14:47:34 +0100129int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800130{
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100131 struct input_dev *idev;
Stefan Richter612262a2008-08-26 00:17:30 +0200132 int i, err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800133
Stefan Richter612262a2008-08-26 00:17:30 +0200134 idev = input_allocate_device();
135 if (!idev)
136 return -ENOMEM;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800137
Rambaldia70f81c2009-01-17 14:47:34 +0100138 fdtv->remote_ctrl_dev = idev;
Stefan Richter612262a2008-08-26 00:17:30 +0200139 idev->name = "FireDTV remote control";
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100140 idev->dev.parent = dev;
Stefan Richter612262a2008-08-26 00:17:30 +0200141 idev->evbit[0] = BIT_MASK(EV_KEY);
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100142 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
143 if (!idev->keycode) {
144 err = -ENOMEM;
145 goto fail;
146 }
Stefan Richter612262a2008-08-26 00:17:30 +0200147 idev->keycodesize = sizeof(keytable[0]);
148 idev->keycodemax = ARRAY_SIZE(keytable);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800149
Stefan Richter612262a2008-08-26 00:17:30 +0200150 for (i = 0; i < ARRAY_SIZE(keytable); i++)
151 set_bit(keytable[i], idev->keybit);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800152
Stefan Richter612262a2008-08-26 00:17:30 +0200153 err = input_register_device(idev);
154 if (err)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100155 goto fail_free_keymap;
Stefan Richter612262a2008-08-26 00:17:30 +0200156
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100157 return 0;
158
159fail_free_keymap:
160 kfree(idev->keycode);
161fail:
162 input_free_device(idev);
Stefan Richter612262a2008-08-26 00:17:30 +0200163 return err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800164}
165
Rambaldia70f81c2009-01-17 14:47:34 +0100166void fdtv_unregister_rc(struct firedtv *fdtv)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800167{
Stefan Richter56411f42009-11-08 18:28:45 -0300168 cancel_work_sync(&fdtv->remote_ctrl_work);
Rambaldia70f81c2009-01-17 14:47:34 +0100169 kfree(fdtv->remote_ctrl_dev->keycode);
170 input_unregister_device(fdtv->remote_ctrl_dev);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800171}
172
Rambaldia70f81c2009-01-17 14:47:34 +0100173void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800174{
Stefan Richter22f37712011-01-16 05:39:21 -0300175 struct input_dev *idev = fdtv->remote_ctrl_dev;
176 u16 *keycode = idev->keycode;
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100177
Stefan Richter612262a2008-08-26 00:17:30 +0200178 if (code >= 0x0300 && code <= 0x031f)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100179 code = keycode[code - 0x0300];
Stefan Richter612262a2008-08-26 00:17:30 +0200180 else if (code >= 0x0340 && code <= 0x0354)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100181 code = keycode[code - 0x0320];
Stefan Richter612262a2008-08-26 00:17:30 +0200182 else if (code >= 0x4501 && code <= 0x451f)
183 code = oldtable[code - 0x4501];
184 else if (code >= 0x4540 && code <= 0x4542)
185 code = oldtable[code - 0x4521];
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800186 else {
Stefan Richter612262a2008-08-26 00:17:30 +0200187 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
188 "from remote control\n", code);
189 return;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800190 }
191
Stefan Richter22f37712011-01-16 05:39:21 -0300192 input_report_key(idev, code, 1);
193 input_sync(idev);
194 input_report_key(idev, code, 0);
195 input_sync(idev);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800196}