Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 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 | */ |
| 11 | |
| 12 | #include <linux/bitops.h> |
| 13 | #include <linux/input.h> |
| 14 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 16 | #include <linux/string.h> |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 17 | #include <linux/types.h> |
Stefan Richter | 56411f4 | 2009-11-08 18:28:45 -0300 | [diff] [blame] | 18 | #include <linux/workqueue.h> |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 19 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 20 | #include "firedtv.h" |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 21 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 22 | /* fixed table with older keycodes, geared towards MythTV */ |
Tobias Klauser | 60c7ef3 | 2009-04-26 10:03:29 -0300 | [diff] [blame] | 23 | static const u16 oldtable[] = { |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 24 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 25 | /* code from device: 0x4501...0x451f */ |
| 26 | |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 27 | KEY_ESC, |
| 28 | KEY_F9, |
| 29 | KEY_1, |
| 30 | KEY_2, |
| 31 | KEY_3, |
| 32 | KEY_4, |
| 33 | KEY_5, |
| 34 | KEY_6, |
| 35 | KEY_7, |
| 36 | KEY_8, |
| 37 | KEY_9, |
| 38 | KEY_I, |
| 39 | KEY_0, |
| 40 | KEY_ENTER, |
| 41 | KEY_RED, |
| 42 | KEY_UP, |
| 43 | KEY_GREEN, |
| 44 | KEY_F10, |
| 45 | KEY_SPACE, |
| 46 | KEY_F11, |
| 47 | KEY_YELLOW, |
| 48 | KEY_DOWN, |
| 49 | KEY_BLUE, |
| 50 | KEY_Z, |
| 51 | KEY_P, |
| 52 | KEY_PAGEDOWN, |
| 53 | KEY_LEFT, |
| 54 | KEY_W, |
| 55 | KEY_RIGHT, |
| 56 | KEY_P, |
| 57 | KEY_M, |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 58 | |
| 59 | /* code from device: 0x4540...0x4542 */ |
| 60 | |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 61 | KEY_R, |
| 62 | KEY_V, |
| 63 | KEY_C, |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 64 | }; |
| 65 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 66 | /* user-modifiable table for a remote as sold in 2008 */ |
Tobias Klauser | 60c7ef3 | 2009-04-26 10:03:29 -0300 | [diff] [blame] | 67 | static const u16 keytable[] = { |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 68 | |
| 69 | /* code from device: 0x0300...0x031f */ |
| 70 | |
| 71 | [0x00] = KEY_POWER, |
| 72 | [0x01] = KEY_SLEEP, |
| 73 | [0x02] = KEY_STOP, |
| 74 | [0x03] = KEY_OK, |
| 75 | [0x04] = KEY_RIGHT, |
| 76 | [0x05] = KEY_1, |
| 77 | [0x06] = KEY_2, |
| 78 | [0x07] = KEY_3, |
| 79 | [0x08] = KEY_LEFT, |
| 80 | [0x09] = KEY_4, |
| 81 | [0x0a] = KEY_5, |
| 82 | [0x0b] = KEY_6, |
| 83 | [0x0c] = KEY_UP, |
| 84 | [0x0d] = KEY_7, |
| 85 | [0x0e] = KEY_8, |
| 86 | [0x0f] = KEY_9, |
| 87 | [0x10] = KEY_DOWN, |
| 88 | [0x11] = KEY_TITLE, /* "OSD" - fixme */ |
| 89 | [0x12] = KEY_0, |
| 90 | [0x13] = KEY_F20, /* "16:9" - fixme */ |
| 91 | [0x14] = KEY_SCREEN, /* "FULL" - fixme */ |
| 92 | [0x15] = KEY_MUTE, |
| 93 | [0x16] = KEY_SUBTITLE, |
| 94 | [0x17] = KEY_RECORD, |
| 95 | [0x18] = KEY_TEXT, |
| 96 | [0x19] = KEY_AUDIO, |
| 97 | [0x1a] = KEY_RED, |
| 98 | [0x1b] = KEY_PREVIOUS, |
| 99 | [0x1c] = KEY_REWIND, |
| 100 | [0x1d] = KEY_PLAYPAUSE, |
| 101 | [0x1e] = KEY_NEXT, |
| 102 | [0x1f] = KEY_VOLUMEUP, |
| 103 | |
| 104 | /* code from device: 0x0340...0x0354 */ |
| 105 | |
| 106 | [0x20] = KEY_CHANNELUP, |
| 107 | [0x21] = KEY_F21, /* "4:3" - fixme */ |
| 108 | [0x22] = KEY_TV, |
| 109 | [0x23] = KEY_DVD, |
| 110 | [0x24] = KEY_VCR, |
| 111 | [0x25] = KEY_AUX, |
| 112 | [0x26] = KEY_GREEN, |
| 113 | [0x27] = KEY_YELLOW, |
| 114 | [0x28] = KEY_BLUE, |
| 115 | [0x29] = KEY_CHANNEL, /* "CH.LIST" */ |
| 116 | [0x2a] = KEY_VENDOR, /* "CI" - fixme */ |
| 117 | [0x2b] = KEY_VOLUMEDOWN, |
| 118 | [0x2c] = KEY_CHANNELDOWN, |
| 119 | [0x2d] = KEY_LAST, |
| 120 | [0x2e] = KEY_INFO, |
| 121 | [0x2f] = KEY_FORWARD, |
| 122 | [0x30] = KEY_LIST, |
| 123 | [0x31] = KEY_FAVORITES, |
| 124 | [0x32] = KEY_MENU, |
| 125 | [0x33] = KEY_EPG, |
| 126 | [0x34] = KEY_EXIT, |
| 127 | }; |
| 128 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 129 | int fdtv_register_rc(struct firedtv *fdtv, struct device *dev) |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 130 | { |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 131 | struct input_dev *idev; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 132 | int i, err; |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 133 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 134 | idev = input_allocate_device(); |
| 135 | if (!idev) |
| 136 | return -ENOMEM; |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 137 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 138 | fdtv->remote_ctrl_dev = idev; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 139 | idev->name = "FireDTV remote control"; |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 140 | idev->dev.parent = dev; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 141 | idev->evbit[0] = BIT_MASK(EV_KEY); |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 142 | idev->keycode = kmemdup(keytable, sizeof(keytable), GFP_KERNEL); |
| 143 | if (!idev->keycode) { |
| 144 | err = -ENOMEM; |
| 145 | goto fail; |
| 146 | } |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 147 | idev->keycodesize = sizeof(keytable[0]); |
| 148 | idev->keycodemax = ARRAY_SIZE(keytable); |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 149 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 150 | for (i = 0; i < ARRAY_SIZE(keytable); i++) |
| 151 | set_bit(keytable[i], idev->keybit); |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 152 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 153 | err = input_register_device(idev); |
| 154 | if (err) |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 155 | goto fail_free_keymap; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 156 | |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | |
| 159 | fail_free_keymap: |
| 160 | kfree(idev->keycode); |
| 161 | fail: |
| 162 | input_free_device(idev); |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 163 | return err; |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 166 | void fdtv_unregister_rc(struct firedtv *fdtv) |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 167 | { |
Stefan Richter | 56411f4 | 2009-11-08 18:28:45 -0300 | [diff] [blame] | 168 | cancel_work_sync(&fdtv->remote_ctrl_work); |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 169 | kfree(fdtv->remote_ctrl_dev->keycode); |
| 170 | input_unregister_device(fdtv->remote_ctrl_dev); |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 171 | } |
| 172 | |
Rambaldi | a70f81c | 2009-01-17 14:47:34 +0100 | [diff] [blame] | 173 | void fdtv_handle_rc(struct firedtv *fdtv, unsigned int code) |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 174 | { |
Stefan Richter | 22f3771 | 2011-01-16 05:39:21 -0300 | [diff] [blame] | 175 | struct input_dev *idev = fdtv->remote_ctrl_dev; |
| 176 | u16 *keycode = idev->keycode; |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 177 | |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 178 | if (code >= 0x0300 && code <= 0x031f) |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 179 | code = keycode[code - 0x0300]; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 180 | else if (code >= 0x0340 && code <= 0x0354) |
Stefan Richter | 8ae83cd | 2008-11-02 13:45:00 +0100 | [diff] [blame] | 181 | code = keycode[code - 0x0320]; |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 182 | else if (code >= 0x4501 && code <= 0x451f) |
| 183 | code = oldtable[code - 0x4501]; |
| 184 | else if (code >= 0x4540 && code <= 0x4542) |
| 185 | code = oldtable[code - 0x4521]; |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 186 | else { |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame] | 187 | printk(KERN_DEBUG "firedtv: invalid key code 0x%04x " |
| 188 | "from remote control\n", code); |
| 189 | return; |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 190 | } |
| 191 | |
Stefan Richter | 22f3771 | 2011-01-16 05:39:21 -0300 | [diff] [blame] | 192 | input_report_key(idev, code, 1); |
| 193 | input_sync(idev); |
| 194 | input_report_key(idev, code, 0); |
| 195 | input_sync(idev); |
Greg Kroah-Hartman | c81c8b6 | 2008-03-06 21:30:23 -0800 | [diff] [blame] | 196 | } |