firesat-rc.c 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * FireDTV driver (formerly known as FireSAT)
 *
 * Copyright (C) 2004 Andreas Monitzer <andy@monitzer.com>
 *
 *	This program is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU General Public License as
 *	published by the Free Software Foundation; either version 2 of
 *	the License, or (at your option) any later version.
 */
G
Greg Kroah-Hartman 已提交
11

12
#include <linux/bitops.h>
G
Greg Kroah-Hartman 已提交
13
#include <linux/input.h>
14
#include <linux/kernel.h>
15
#include <linux/string.h>
16 17 18
#include <linux/types.h>

#include "firesat-rc.h"
19
#include "firesat.h"
20 21 22 23 24

/* fixed table with older keycodes, geared towards MythTV */
const static u16 oldtable[] = {

	/* code from device: 0x4501...0x451f */
G
Greg Kroah-Hartman 已提交
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

	KEY_ESC,
	KEY_F9,
	KEY_1,
	KEY_2,
	KEY_3,
	KEY_4,
	KEY_5,
	KEY_6,
	KEY_7,
	KEY_8,
	KEY_9,
	KEY_I,
	KEY_0,
	KEY_ENTER,
	KEY_RED,
	KEY_UP,
	KEY_GREEN,
	KEY_F10,
	KEY_SPACE,
	KEY_F11,
	KEY_YELLOW,
	KEY_DOWN,
	KEY_BLUE,
	KEY_Z,
	KEY_P,
	KEY_PAGEDOWN,
	KEY_LEFT,
	KEY_W,
	KEY_RIGHT,
	KEY_P,
	KEY_M,
57 58 59

	/* code from device: 0x4540...0x4542 */

G
Greg Kroah-Hartman 已提交
60 61 62 63 64
	KEY_R,
	KEY_V,
	KEY_C,
};

65
/* user-modifiable table for a remote as sold in 2008 */
66
const static u16 keytable[] = {
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

	/* code from device: 0x0300...0x031f */

	[0x00] = KEY_POWER,
	[0x01] = KEY_SLEEP,
	[0x02] = KEY_STOP,
	[0x03] = KEY_OK,
	[0x04] = KEY_RIGHT,
	[0x05] = KEY_1,
	[0x06] = KEY_2,
	[0x07] = KEY_3,
	[0x08] = KEY_LEFT,
	[0x09] = KEY_4,
	[0x0a] = KEY_5,
	[0x0b] = KEY_6,
	[0x0c] = KEY_UP,
	[0x0d] = KEY_7,
	[0x0e] = KEY_8,
	[0x0f] = KEY_9,
	[0x10] = KEY_DOWN,
	[0x11] = KEY_TITLE,	/* "OSD" - fixme */
	[0x12] = KEY_0,
	[0x13] = KEY_F20,	/* "16:9" - fixme */
	[0x14] = KEY_SCREEN,	/* "FULL" - fixme */
	[0x15] = KEY_MUTE,
	[0x16] = KEY_SUBTITLE,
	[0x17] = KEY_RECORD,
	[0x18] = KEY_TEXT,
	[0x19] = KEY_AUDIO,
	[0x1a] = KEY_RED,
	[0x1b] = KEY_PREVIOUS,
	[0x1c] = KEY_REWIND,
	[0x1d] = KEY_PLAYPAUSE,
	[0x1e] = KEY_NEXT,
	[0x1f] = KEY_VOLUMEUP,

	/* code from device: 0x0340...0x0354 */

	[0x20] = KEY_CHANNELUP,
	[0x21] = KEY_F21,	/* "4:3" - fixme */
	[0x22] = KEY_TV,
	[0x23] = KEY_DVD,
	[0x24] = KEY_VCR,
	[0x25] = KEY_AUX,
	[0x26] = KEY_GREEN,
	[0x27] = KEY_YELLOW,
	[0x28] = KEY_BLUE,
	[0x29] = KEY_CHANNEL,	/* "CH.LIST" */
	[0x2a] = KEY_VENDOR,	/* "CI" - fixme */
	[0x2b] = KEY_VOLUMEDOWN,
	[0x2c] = KEY_CHANNELDOWN,
	[0x2d] = KEY_LAST,
	[0x2e] = KEY_INFO,
	[0x2f] = KEY_FORWARD,
	[0x30] = KEY_LIST,
	[0x31] = KEY_FAVORITES,
	[0x32] = KEY_MENU,
	[0x33] = KEY_EPG,
	[0x34] = KEY_EXIT,
};

128
int firesat_register_rc(struct firesat *firesat, struct device *dev)
G
Greg Kroah-Hartman 已提交
129
{
130
	struct input_dev *idev;
131 132 133 134 135
	int i, err;

	idev = input_allocate_device();
	if (!idev)
		return -ENOMEM;
G
Greg Kroah-Hartman 已提交
136

137
	firesat->remote_ctrl_dev = idev;
138
	idev->name = "FireDTV remote control";
139
	idev->dev.parent = dev;
140
	idev->evbit[0] = BIT_MASK(EV_KEY);
141 142 143 144 145
	idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL);
	if (!idev->keycode) {
		err = -ENOMEM;
		goto fail;
	}
146 147
	idev->keycodesize = sizeof(keytable[0]);
	idev->keycodemax = ARRAY_SIZE(keytable);
G
Greg Kroah-Hartman 已提交
148

149 150
	for (i = 0; i < ARRAY_SIZE(keytable); i++)
		set_bit(keytable[i], idev->keybit);
G
Greg Kroah-Hartman 已提交
151

152 153
	err = input_register_device(idev);
	if (err)
154
		goto fail_free_keymap;
G
Greg Kroah-Hartman 已提交
155

156 157 158 159 160 161
	return 0;

fail_free_keymap:
	kfree(idev->keycode);
fail:
	input_free_device(idev);
162
	return err;
G
Greg Kroah-Hartman 已提交
163 164
}

165
void firesat_unregister_rc(struct firesat *firesat)
G
Greg Kroah-Hartman 已提交
166
{
167 168
	kfree(firesat->remote_ctrl_dev->keycode);
	input_unregister_device(firesat->remote_ctrl_dev);
G
Greg Kroah-Hartman 已提交
169 170
}

171
void firesat_handle_rc(struct firesat *firesat, unsigned int code)
G
Greg Kroah-Hartman 已提交
172
{
173 174
	u16 *keycode = firesat->remote_ctrl_dev->keycode;

175
	if (code >= 0x0300 && code <= 0x031f)
176
		code = keycode[code - 0x0300];
177
	else if (code >= 0x0340 && code <= 0x0354)
178
		code = keycode[code - 0x0320];
179 180 181 182
	else if (code >= 0x4501 && code <= 0x451f)
		code = oldtable[code - 0x4501];
	else if (code >= 0x4540 && code <= 0x4542)
		code = oldtable[code - 0x4521];
G
Greg Kroah-Hartman 已提交
183
	else {
184 185 186
		printk(KERN_DEBUG "firedtv: invalid key code 0x%04x "
		       "from remote control\n", code);
		return;
G
Greg Kroah-Hartman 已提交
187 188
	}

189 190
	input_report_key(firesat->remote_ctrl_dev, code, 1);
	input_report_key(firesat->remote_ctrl_dev, code, 0);
G
Greg Kroah-Hartman 已提交
191
}