blob: 27bca2e283dfc4a0a00ea070da033788997b27df [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>
Stefan Richter8ae83cd2008-11-02 13:45:00 +010015#include <linux/string.h>
Stefan Richter612262a2008-08-26 00:17:30 +020016#include <linux/types.h>
17
Rambaldia70f81c2009-01-17 14:47:34 +010018#include "firedtv.h"
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080019
Stefan Richter612262a2008-08-26 00:17:30 +020020/* fixed table with older keycodes, geared towards MythTV */
Tobias Klauser60c7ef32009-04-26 10:03:29 -030021static const u16 oldtable[] = {
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080022
Stefan Richter612262a2008-08-26 00:17:30 +020023 /* code from device: 0x4501...0x451f */
24
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080025 KEY_ESC,
26 KEY_F9,
27 KEY_1,
28 KEY_2,
29 KEY_3,
30 KEY_4,
31 KEY_5,
32 KEY_6,
33 KEY_7,
34 KEY_8,
35 KEY_9,
36 KEY_I,
37 KEY_0,
38 KEY_ENTER,
39 KEY_RED,
40 KEY_UP,
41 KEY_GREEN,
42 KEY_F10,
43 KEY_SPACE,
44 KEY_F11,
45 KEY_YELLOW,
46 KEY_DOWN,
47 KEY_BLUE,
48 KEY_Z,
49 KEY_P,
50 KEY_PAGEDOWN,
51 KEY_LEFT,
52 KEY_W,
53 KEY_RIGHT,
54 KEY_P,
55 KEY_M,
Stefan Richter612262a2008-08-26 00:17:30 +020056
57 /* code from device: 0x4540...0x4542 */
58
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080059 KEY_R,
60 KEY_V,
61 KEY_C,
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080062};
63
Stefan Richter612262a2008-08-26 00:17:30 +020064/* user-modifiable table for a remote as sold in 2008 */
Tobias Klauser60c7ef32009-04-26 10:03:29 -030065static const u16 keytable[] = {
Stefan Richter612262a2008-08-26 00:17:30 +020066
67 /* code from device: 0x0300...0x031f */
68
69 [0x00] = KEY_POWER,
70 [0x01] = KEY_SLEEP,
71 [0x02] = KEY_STOP,
72 [0x03] = KEY_OK,
73 [0x04] = KEY_RIGHT,
74 [0x05] = KEY_1,
75 [0x06] = KEY_2,
76 [0x07] = KEY_3,
77 [0x08] = KEY_LEFT,
78 [0x09] = KEY_4,
79 [0x0a] = KEY_5,
80 [0x0b] = KEY_6,
81 [0x0c] = KEY_UP,
82 [0x0d] = KEY_7,
83 [0x0e] = KEY_8,
84 [0x0f] = KEY_9,
85 [0x10] = KEY_DOWN,
86 [0x11] = KEY_TITLE, /* "OSD" - fixme */
87 [0x12] = KEY_0,
88 [0x13] = KEY_F20, /* "16:9" - fixme */
89 [0x14] = KEY_SCREEN, /* "FULL" - fixme */
90 [0x15] = KEY_MUTE,
91 [0x16] = KEY_SUBTITLE,
92 [0x17] = KEY_RECORD,
93 [0x18] = KEY_TEXT,
94 [0x19] = KEY_AUDIO,
95 [0x1a] = KEY_RED,
96 [0x1b] = KEY_PREVIOUS,
97 [0x1c] = KEY_REWIND,
98 [0x1d] = KEY_PLAYPAUSE,
99 [0x1e] = KEY_NEXT,
100 [0x1f] = KEY_VOLUMEUP,
101
102 /* code from device: 0x0340...0x0354 */
103
104 [0x20] = KEY_CHANNELUP,
105 [0x21] = KEY_F21, /* "4:3" - fixme */
106 [0x22] = KEY_TV,
107 [0x23] = KEY_DVD,
108 [0x24] = KEY_VCR,
109 [0x25] = KEY_AUX,
110 [0x26] = KEY_GREEN,
111 [0x27] = KEY_YELLOW,
112 [0x28] = KEY_BLUE,
113 [0x29] = KEY_CHANNEL, /* "CH.LIST" */
114 [0x2a] = KEY_VENDOR, /* "CI" - fixme */
115 [0x2b] = KEY_VOLUMEDOWN,
116 [0x2c] = KEY_CHANNELDOWN,
117 [0x2d] = KEY_LAST,
118 [0x2e] = KEY_INFO,
119 [0x2f] = KEY_FORWARD,
120 [0x30] = KEY_LIST,
121 [0x31] = KEY_FAVORITES,
122 [0x32] = KEY_MENU,
123 [0x33] = KEY_EPG,
124 [0x34] = KEY_EXIT,
125};
126
Rambaldia70f81c2009-01-17 14:47:34 +0100127int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800128{
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100129 struct input_dev *idev;
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
Rambaldia70f81c2009-01-17 14:47:34 +0100136 fdtv->remote_ctrl_dev = idev;
Stefan Richter612262a2008-08-26 00:17:30 +0200137 idev->name = "FireDTV remote control";
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100138 idev->dev.parent = dev;
Stefan Richter612262a2008-08-26 00:17:30 +0200139 idev->evbit[0] = BIT_MASK(EV_KEY);
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100140 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
141 if (!idev->keycode) {
142 err = -ENOMEM;
143 goto fail;
144 }
Stefan Richter612262a2008-08-26 00:17:30 +0200145 idev->keycodesize = sizeof(keytable[0]);
146 idev->keycodemax = ARRAY_SIZE(keytable);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800147
Stefan Richter612262a2008-08-26 00:17:30 +0200148 for (i = 0; i < ARRAY_SIZE(keytable); i++)
149 set_bit(keytable[i], idev->keybit);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800150
Stefan Richter612262a2008-08-26 00:17:30 +0200151 err = input_register_device(idev);
152 if (err)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100153 goto fail_free_keymap;
Stefan Richter612262a2008-08-26 00:17:30 +0200154
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100155 return 0;
156
157fail_free_keymap:
158 kfree(idev->keycode);
159fail:
160 input_free_device(idev);
Stefan Richter612262a2008-08-26 00:17:30 +0200161 return err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800162}
163
Rambaldia70f81c2009-01-17 14:47:34 +0100164void fdtv_unregister_rc(struct firedtv *fdtv)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800165{
Rambaldia70f81c2009-01-17 14:47:34 +0100166 kfree(fdtv->remote_ctrl_dev->keycode);
167 input_unregister_device(fdtv->remote_ctrl_dev);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800168}
169
Rambaldia70f81c2009-01-17 14:47:34 +0100170void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800171{
Rambaldia70f81c2009-01-17 14:47:34 +0100172 u16 *keycode = fdtv->remote_ctrl_dev->keycode;
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100173
Stefan Richter612262a2008-08-26 00:17:30 +0200174 if (code >= 0x0300 && code <= 0x031f)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100175 code = keycode[code - 0x0300];
Stefan Richter612262a2008-08-26 00:17:30 +0200176 else if (code >= 0x0340 && code <= 0x0354)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100177 code = keycode[code - 0x0320];
Stefan Richter612262a2008-08-26 00:17:30 +0200178 else if (code >= 0x4501 && code <= 0x451f)
179 code = oldtable[code - 0x4501];
180 else if (code >= 0x4540 && code <= 0x4542)
181 code = oldtable[code - 0x4521];
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800182 else {
Stefan Richter612262a2008-08-26 00:17:30 +0200183 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
184 "from remote control\n", code);
185 return;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800186 }
187
Rambaldia70f81c2009-01-17 14:47:34 +0100188 input_report_key(fdtv->remote_ctrl_dev, code, 1);
189 input_report_key(fdtv->remote_ctrl_dev, code, 0);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800190}