blob: 436c0c69a13de6ed7f12b7aa84aef86f95366e8d [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-rc.h"
19#include "firedtv.h"
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080020
Stefan Richter612262a2008-08-26 00:17:30 +020021/* fixed table with older keycodes, geared towards MythTV */
22const static u16 oldtable[] = {
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080023
Stefan Richter612262a2008-08-26 00:17:30 +020024 /* code from device: 0x4501...0x451f */
25
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080026 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,
Stefan Richter612262a2008-08-26 00:17:30 +020057
58 /* code from device: 0x4540...0x4542 */
59
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080060 KEY_R,
61 KEY_V,
62 KEY_C,
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -080063};
64
Stefan Richter612262a2008-08-26 00:17:30 +020065/* user-modifiable table for a remote as sold in 2008 */
Stefan Richter8ae83cd2008-11-02 13:45:00 +010066const static u16 keytable[] = {
Stefan Richter612262a2008-08-26 00:17:30 +020067
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
Rambaldia70f81c2009-01-17 14:47:34 +0100128int fdtv_register_rc(struct firedtv *fdtv, struct device *dev)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800129{
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100130 struct input_dev *idev;
Stefan Richter612262a2008-08-26 00:17:30 +0200131 int i, err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800132
Stefan Richter612262a2008-08-26 00:17:30 +0200133 idev = input_allocate_device();
134 if (!idev)
135 return -ENOMEM;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800136
Rambaldia70f81c2009-01-17 14:47:34 +0100137 fdtv->remote_ctrl_dev = idev;
Stefan Richter612262a2008-08-26 00:17:30 +0200138 idev->name = "FireDTV remote control";
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100139 idev->dev.parent = dev;
Stefan Richter612262a2008-08-26 00:17:30 +0200140 idev->evbit[0] = BIT_MASK(EV_KEY);
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100141 idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
142 if (!idev->keycode) {
143 err = -ENOMEM;
144 goto fail;
145 }
Stefan Richter612262a2008-08-26 00:17:30 +0200146 idev->keycodesize = sizeof(keytable[0]);
147 idev->keycodemax = ARRAY_SIZE(keytable);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800148
Stefan Richter612262a2008-08-26 00:17:30 +0200149 for (i = 0; i < ARRAY_SIZE(keytable); i++)
150 set_bit(keytable[i], idev->keybit);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800151
Stefan Richter612262a2008-08-26 00:17:30 +0200152 err = input_register_device(idev);
153 if (err)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100154 goto fail_free_keymap;
Stefan Richter612262a2008-08-26 00:17:30 +0200155
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100156 return 0;
157
158fail_free_keymap:
159 kfree(idev->keycode);
160fail:
161 input_free_device(idev);
Stefan Richter612262a2008-08-26 00:17:30 +0200162 return err;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800163}
164
Rambaldia70f81c2009-01-17 14:47:34 +0100165void fdtv_unregister_rc(struct firedtv *fdtv)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800166{
Rambaldia70f81c2009-01-17 14:47:34 +0100167 kfree(fdtv->remote_ctrl_dev->keycode);
168 input_unregister_device(fdtv->remote_ctrl_dev);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800169}
170
Rambaldia70f81c2009-01-17 14:47:34 +0100171void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code)
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800172{
Rambaldia70f81c2009-01-17 14:47:34 +0100173 u16 *keycode = fdtv->remote_ctrl_dev->keycode;
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100174
Stefan Richter612262a2008-08-26 00:17:30 +0200175 if (code >= 0x0300 && code <= 0x031f)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100176 code = keycode[code - 0x0300];
Stefan Richter612262a2008-08-26 00:17:30 +0200177 else if (code >= 0x0340 && code <= 0x0354)
Stefan Richter8ae83cd2008-11-02 13:45:00 +0100178 code = keycode[code - 0x0320];
Stefan Richter612262a2008-08-26 00:17:30 +0200179 else if (code >= 0x4501 && code <= 0x451f)
180 code = oldtable[code - 0x4501];
181 else if (code >= 0x4540 && code <= 0x4542)
182 code = oldtable[code - 0x4521];
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800183 else {
Stefan Richter612262a2008-08-26 00:17:30 +0200184 printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
185 "from remote control\n", code);
186 return;
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800187 }
188
Rambaldia70f81c2009-01-17 14:47:34 +0100189 input_report_key(fdtv->remote_ctrl_dev, code, 1);
190 input_report_key(fdtv->remote_ctrl_dev, code, 0);
Greg Kroah-Hartmanc81c8b62008-03-06 21:30:23 -0800191}