blob: d3e08f9fe9f7f17d43366614050538dffc019b0f [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>
15#include <linux/types.h>
16
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080017#include "firesat-rc.h"
18
Stefan Richter612262a2008-08-26 00:17:30 +020019/* fixed table with older keycodes, geared towards MythTV */
20const static u16 oldtable[] = {
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080021
Stefan Richter612262a2008-08-26 00:17:30 +020022 /* code from device: 0x4501...0x451f */
23
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080024 KEY_ESC,
25 KEY_F9,
26 KEY_1,
27 KEY_2,
28 KEY_3,
29 KEY_4,
30 KEY_5,
31 KEY_6,
32 KEY_7,
33 KEY_8,
34 KEY_9,
35 KEY_I,
36 KEY_0,
37 KEY_ENTER,
38 KEY_RED,
39 KEY_UP,
40 KEY_GREEN,
41 KEY_F10,
42 KEY_SPACE,
43 KEY_F11,
44 KEY_YELLOW,
45 KEY_DOWN,
46 KEY_BLUE,
47 KEY_Z,
48 KEY_P,
49 KEY_PAGEDOWN,
50 KEY_LEFT,
51 KEY_W,
52 KEY_RIGHT,
53 KEY_P,
54 KEY_M,
Stefan Richter612262a2008-08-26 00:17:30 +020055
56 /* code from device: 0x4540...0x4542 */
57
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080058 KEY_R,
59 KEY_V,
60 KEY_C,
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080061};
62
Stefan Richter612262a2008-08-26 00:17:30 +020063/* user-modifiable table for a remote as sold in 2008 */
64static u16 keytable[] = {
65
66 /* code from device: 0x0300...0x031f */
67
68 [0x00] = KEY_POWER,
69 [0x01] = KEY_SLEEP,
70 [0x02] = KEY_STOP,
71 [0x03] = KEY_OK,
72 [0x04] = KEY_RIGHT,
73 [0x05] = KEY_1,
74 [0x06] = KEY_2,
75 [0x07] = KEY_3,
76 [0x08] = KEY_LEFT,
77 [0x09] = KEY_4,
78 [0x0a] = KEY_5,
79 [0x0b] = KEY_6,
80 [0x0c] = KEY_UP,
81 [0x0d] = KEY_7,
82 [0x0e] = KEY_8,
83 [0x0f] = KEY_9,
84 [0x10] = KEY_DOWN,
85 [0x11] = KEY_TITLE, /* "OSD" - fixme */
86 [0x12] = KEY_0,
87 [0x13] = KEY_F20, /* "16:9" - fixme */
88 [0x14] = KEY_SCREEN, /* "FULL" - fixme */
89 [0x15] = KEY_MUTE,
90 [0x16] = KEY_SUBTITLE,
91 [0x17] = KEY_RECORD,
92 [0x18] = KEY_TEXT,
93 [0x19] = KEY_AUDIO,
94 [0x1a] = KEY_RED,
95 [0x1b] = KEY_PREVIOUS,
96 [0x1c] = KEY_REWIND,
97 [0x1d] = KEY_PLAYPAUSE,
98 [0x1e] = KEY_NEXT,
99 [0x1f] = KEY_VOLUMEUP,
100
101 /* code from device: 0x0340...0x0354 */
102
103 [0x20] = KEY_CHANNELUP,
104 [0x21] = KEY_F21, /* "4:3" - fixme */
105 [0x22] = KEY_TV,
106 [0x23] = KEY_DVD,
107 [0x24] = KEY_VCR,
108 [0x25] = KEY_AUX,
109 [0x26] = KEY_GREEN,
110 [0x27] = KEY_YELLOW,
111 [0x28] = KEY_BLUE,
112 [0x29] = KEY_CHANNEL, /* "CH.LIST" */
113 [0x2a] = KEY_VENDOR, /* "CI" - fixme */
114 [0x2b] = KEY_VOLUMEDOWN,
115 [0x2c] = KEY_CHANNELDOWN,
116 [0x2d] = KEY_LAST,
117 [0x2e] = KEY_INFO,
118 [0x2f] = KEY_FORWARD,
119 [0x30] = KEY_LIST,
120 [0x31] = KEY_FAVORITES,
121 [0x32] = KEY_MENU,
122 [0x33] = KEY_EPG,
123 [0x34] = KEY_EXIT,
124};
125
126static struct input_dev *idev;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800127
128int firesat_register_rc(void)
129{
Stefan Richter612262a2008-08-26 00:17:30 +0200130 int i, err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800131
Stefan Richter612262a2008-08-26 00:17:30 +0200132 idev = input_allocate_device();
133 if (!idev)
134 return -ENOMEM;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800135
Stefan Richter612262a2008-08-26 00:17:30 +0200136 idev->name = "FireDTV remote control";
137 idev->evbit[0] = BIT_MASK(EV_KEY);
138 idev->keycode = keytable;
139 idev->keycodesize = sizeof(keytable[0]);
140 idev->keycodemax = ARRAY_SIZE(keytable);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800141
Stefan Richter612262a2008-08-26 00:17:30 +0200142 for (i = 0; i < ARRAY_SIZE(keytable); i++)
143 set_bit(keytable[i], idev->keybit);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800144
Stefan Richter612262a2008-08-26 00:17:30 +0200145 err = input_register_device(idev);
146 if (err)
147 input_free_device(idev);
148
149 return err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800150}
151
Stefan Richter612262a2008-08-26 00:17:30 +0200152void firesat_unregister_rc(void)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800153{
Stefan Richter612262a2008-08-26 00:17:30 +0200154 input_unregister_device(idev);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800155}
156
Stefan Richter612262a2008-08-26 00:17:30 +0200157void firesat_handle_rc(unsigned int code)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800158{
Stefan Richter612262a2008-08-26 00:17:30 +0200159 if (code >= 0x0300 && code <= 0x031f)
160 code = keytable[code - 0x0300];
161 else if (code >= 0x0340 && code <= 0x0354)
162 code = keytable[code - 0x0320];
163 else if (code >= 0x4501 && code <= 0x451f)
164 code = oldtable[code - 0x4501];
165 else if (code >= 0x4540 && code <= 0x4542)
166 code = oldtable[code - 0x4521];
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800167 else {
Stefan Richter612262a2008-08-26 00:17:30 +0200168 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
169 "from remote control\n", code);
170 return;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800171 }
172
Stefan Richter612262a2008-08-26 00:17:30 +0200173 input_report_key(idev, code, 1);
174 input_report_key(idev, code, 0);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800175}