firedtv: cleanups and minor fixes
[linux-2.6-block.git] / drivers / media / dvb / firesat / firesat-rc.c
CommitLineData
612262a5
SR
1/*
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 */
c81c8b68 11
612262a5 12#include <linux/bitops.h>
c81c8b68 13#include <linux/input.h>
612262a5 14#include <linux/kernel.h>
8ae83cdf 15#include <linux/string.h>
612262a5
SR
16#include <linux/types.h>
17
18#include "firesat-rc.h"
8ae83cdf 19#include "firesat.h"
612262a5
SR
20
21/* fixed table with older keycodes, geared towards MythTV */
22const static u16 oldtable[] = {
23
24 /* code from device: 0x4501...0x451f */
c81c8b68 25
c81c8b68
GKH
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,
612262a5
SR
57
58 /* code from device: 0x4540...0x4542 */
59
c81c8b68
GKH
60 KEY_R,
61 KEY_V,
62 KEY_C,
c81c8b68
GKH
63};
64
612262a5 65/* user-modifiable table for a remote as sold in 2008 */
8ae83cdf 66const static u16 keytable[] = {
612262a5
SR
67
68 /* code from device: 0x0300...0x031f */
69
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,
102
103 /* code from device: 0x0340...0x0354 */
104
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,
126};
127
8ae83cdf 128int firesat_register_rc(struct firesat *firesat, struct device *dev)
c81c8b68 129{
8ae83cdf 130 struct input_dev *idev;
612262a5
SR
131 int i, err;
132
133 idev = input_allocate_device();
134 if (!idev)
135 return -ENOMEM;
c81c8b68 136
8ae83cdf 137 firesat->remote_ctrl_dev = idev;
612262a5 138 idev->name = "FireDTV remote control";
8ae83cdf 139 idev->dev.parent = dev;
612262a5 140 idev->evbit[0] = BIT_MASK(EV_KEY);
8ae83cdf
SR
141 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
142 if (!idev->keycode) {
143 err = -ENOMEM;
144 goto fail;
145 }
612262a5
SR
146 idev->keycodesize = sizeof(keytable[0]);
147 idev->keycodemax = ARRAY_SIZE(keytable);
c81c8b68 148
612262a5
SR
149 for (i = 0; i < ARRAY_SIZE(keytable); i++)
150 set_bit(keytable[i], idev->keybit);
c81c8b68 151
612262a5
SR
152 err = input_register_device(idev);
153 if (err)
8ae83cdf 154 goto fail_free_keymap;
c81c8b68 155
8ae83cdf
SR
156 return 0;
157
158fail_free_keymap:
159 kfree(idev->keycode);
160fail:
161 input_free_device(idev);
612262a5 162 return err;
c81c8b68
GKH
163}
164
8ae83cdf 165void firesat_unregister_rc(struct firesat *firesat)
c81c8b68 166{
8ae83cdf
SR
167 kfree(firesat->remote_ctrl_dev->keycode);
168 input_unregister_device(firesat->remote_ctrl_dev);
c81c8b68
GKH
169}
170
8ae83cdf 171void firesat_handle_rc(struct firesat *firesat, unsigned int code)
c81c8b68 172{
8ae83cdf
SR
173 u16 *keycode = firesat->remote_ctrl_dev->keycode;
174
612262a5 175 if (code >= 0x0300 && code <= 0x031f)
8ae83cdf 176 code = keycode[code - 0x0300];
612262a5 177 else if (code >= 0x0340 && code <= 0x0354)
8ae83cdf 178 code = keycode[code - 0x0320];
612262a5
SR
179 else if (code >= 0x4501 && code <= 0x451f)
180 code = oldtable[code - 0x4501];
181 else if (code >= 0x4540 && code <= 0x4542)
182 code = oldtable[code - 0x4521];
c81c8b68 183 else {
612262a5
SR
184 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
185 "from remote control\n", code);
186 return;
c81c8b68
GKH
187 }
188
8ae83cdf
SR
189 input_report_key(firesat->remote_ctrl_dev, code, 1);
190 input_report_key(firesat->remote_ctrl_dev, code, 0);
c81c8b68 191}