Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * Device driver for GPIO attached remote control interfaces |
| 4 | * on Conexant 2388x based TV/DVB cards. |
| 5 | * |
| 6 | * Copyright (c) 2003 Pavel Machek |
| 7 | * Copyright (c) 2004 Gerd Knorr |
| 8 | * Copyright (c) 2004 Chris Pascoe |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 23 | */ |
| 24 | |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/input.h> |
| 28 | #include <linux/pci.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/moduleparam.h> |
| 31 | |
| 32 | #include <media/ir-common.h> |
| 33 | |
| 34 | #include "cx88.h" |
| 35 | |
| 36 | /* ---------------------------------------------------------------------- */ |
| 37 | |
| 38 | /* DigitalNow DNTV Live DVB-T Remote */ |
| 39 | static IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE] = { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 40 | [0x00] = KEY_ESC, /* 'go up a level?' */ |
| 41 | /* Keys 0 to 9 */ |
| 42 | [0x0a] = KEY_KP0, |
| 43 | [0x01] = KEY_KP1, |
| 44 | [0x02] = KEY_KP2, |
| 45 | [0x03] = KEY_KP3, |
| 46 | [0x04] = KEY_KP4, |
| 47 | [0x05] = KEY_KP5, |
| 48 | [0x06] = KEY_KP6, |
| 49 | [0x07] = KEY_KP7, |
| 50 | [0x08] = KEY_KP8, |
| 51 | [0x09] = KEY_KP9, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 53 | [0x0b] = KEY_TUNER, /* tv/fm */ |
| 54 | [0x0c] = KEY_SEARCH, /* scan */ |
| 55 | [0x0d] = KEY_STOP, |
| 56 | [0x0e] = KEY_PAUSE, |
| 57 | [0x0f] = KEY_LIST, /* source */ |
| 58 | |
| 59 | [0x10] = KEY_MUTE, |
| 60 | [0x11] = KEY_REWIND, /* backward << */ |
| 61 | [0x12] = KEY_POWER, |
| 62 | [0x13] = KEY_S, /* snap */ |
| 63 | [0x14] = KEY_AUDIO, /* stereo */ |
| 64 | [0x15] = KEY_CLEAR, /* reset */ |
| 65 | [0x16] = KEY_PLAY, |
| 66 | [0x17] = KEY_ENTER, |
| 67 | [0x18] = KEY_ZOOM, /* full screen */ |
| 68 | [0x19] = KEY_FASTFORWARD, /* forward >> */ |
| 69 | [0x1a] = KEY_CHANNELUP, |
| 70 | [0x1b] = KEY_VOLUMEUP, |
| 71 | [0x1c] = KEY_INFO, /* preview */ |
| 72 | [0x1d] = KEY_RECORD, /* record */ |
| 73 | [0x1e] = KEY_CHANNELDOWN, |
| 74 | [0x1f] = KEY_VOLUMEDOWN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | /* ---------------------------------------------------------------------- */ |
| 78 | |
| 79 | /* IO-DATA BCTV7E Remote */ |
| 80 | static IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE] = { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 81 | [0x40] = KEY_TV, |
| 82 | [0x20] = KEY_RADIO, /* FM */ |
| 83 | [0x60] = KEY_EPG, |
| 84 | [0x00] = KEY_POWER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 86 | /* Keys 0 to 9 */ |
| 87 | [0x44] = KEY_KP0, /* 10 */ |
| 88 | [0x50] = KEY_KP1, |
| 89 | [0x30] = KEY_KP2, |
| 90 | [0x70] = KEY_KP3, |
| 91 | [0x48] = KEY_KP4, |
| 92 | [0x28] = KEY_KP5, |
| 93 | [0x68] = KEY_KP6, |
| 94 | [0x58] = KEY_KP7, |
| 95 | [0x38] = KEY_KP8, |
| 96 | [0x78] = KEY_KP9, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 98 | [0x10] = KEY_L, /* Live */ |
| 99 | [0x08] = KEY_T, /* Time Shift */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 101 | [0x18] = KEY_PLAYPAUSE, /* Play */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 103 | [0x24] = KEY_ENTER, /* 11 */ |
| 104 | [0x64] = KEY_ESC, /* 12 */ |
| 105 | [0x04] = KEY_M, /* Multi */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 107 | [0x54] = KEY_VIDEO, |
| 108 | [0x34] = KEY_CHANNELUP, |
| 109 | [0x74] = KEY_VOLUMEUP, |
| 110 | [0x14] = KEY_MUTE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 112 | [0x4c] = KEY_S, /* SVIDEO */ |
| 113 | [0x2c] = KEY_CHANNELDOWN, |
| 114 | [0x6c] = KEY_VOLUMEDOWN, |
| 115 | [0x0c] = KEY_ZOOM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 117 | [0x5c] = KEY_PAUSE, |
| 118 | [0x3c] = KEY_C, /* || (red) */ |
| 119 | [0x7c] = KEY_RECORD, /* recording */ |
| 120 | [0x1c] = KEY_STOP, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 122 | [0x41] = KEY_REWIND, /* backward << */ |
| 123 | [0x21] = KEY_PLAY, |
| 124 | [0x61] = KEY_FASTFORWARD, /* forward >> */ |
| 125 | [0x01] = KEY_NEXT, /* skip >| */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | }; |
| 127 | |
| 128 | /* ---------------------------------------------------------------------- */ |
| 129 | |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 130 | /* ADS Tech Instant TV DVB-T PCI Remote */ |
| 131 | static IR_KEYTAB_TYPE ir_codes_adstech_dvb_t_pci[IR_KEYTAB_SIZE] = { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 132 | /* Keys 0 to 9 */ |
| 133 | [0x4d] = KEY_0, |
| 134 | [0x57] = KEY_1, |
| 135 | [0x4f] = KEY_2, |
| 136 | [0x53] = KEY_3, |
| 137 | [0x56] = KEY_4, |
| 138 | [0x4e] = KEY_5, |
| 139 | [0x5e] = KEY_6, |
| 140 | [0x54] = KEY_7, |
| 141 | [0x4c] = KEY_8, |
| 142 | [0x5c] = KEY_9, |
| 143 | |
| 144 | [0x5b] = KEY_POWER, |
| 145 | [0x5f] = KEY_MUTE, |
| 146 | [0x55] = KEY_GOTO, |
| 147 | [0x5d] = KEY_SEARCH, |
| 148 | [0x17] = KEY_EPG, /* Guide */ |
| 149 | [0x1f] = KEY_MENU, |
| 150 | [0x0f] = KEY_UP, |
| 151 | [0x46] = KEY_DOWN, |
| 152 | [0x16] = KEY_LEFT, |
| 153 | [0x1e] = KEY_RIGHT, |
| 154 | [0x0e] = KEY_SELECT, /* Enter */ |
| 155 | [0x5a] = KEY_INFO, |
| 156 | [0x52] = KEY_EXIT, |
| 157 | [0x59] = KEY_PREVIOUS, |
| 158 | [0x51] = KEY_NEXT, |
| 159 | [0x58] = KEY_REWIND, |
| 160 | [0x50] = KEY_FORWARD, |
| 161 | [0x44] = KEY_PLAYPAUSE, |
| 162 | [0x07] = KEY_STOP, |
| 163 | [0x1b] = KEY_RECORD, |
| 164 | [0x13] = KEY_TUNER, /* Live */ |
| 165 | [0x0a] = KEY_A, |
| 166 | [0x12] = KEY_B, |
| 167 | [0x03] = KEY_PROG1, /* 1 */ |
| 168 | [0x01] = KEY_PROG2, /* 2 */ |
| 169 | [0x00] = KEY_PROG3, /* 3 */ |
| 170 | [0x06] = KEY_DVD, |
| 171 | [0x48] = KEY_AUX, /* Photo */ |
| 172 | [0x40] = KEY_VIDEO, |
| 173 | [0x19] = KEY_AUDIO, /* Music */ |
| 174 | [0x0b] = KEY_CHANNELUP, |
| 175 | [0x08] = KEY_CHANNELDOWN, |
| 176 | [0x15] = KEY_VOLUMEUP, |
| 177 | [0x1c] = KEY_VOLUMEDOWN, |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | /* ---------------------------------------------------------------------- */ |
| 181 | |
| 182 | /* MSI TV@nywhere remote */ |
| 183 | static IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 184 | /* Keys 0 to 9 */ |
| 185 | [0x00] = KEY_0, |
| 186 | [0x01] = KEY_1, |
| 187 | [0x02] = KEY_2, |
| 188 | [0x03] = KEY_3, |
| 189 | [0x04] = KEY_4, |
| 190 | [0x05] = KEY_5, |
| 191 | [0x06] = KEY_6, |
| 192 | [0x07] = KEY_7, |
| 193 | [0x08] = KEY_8, |
| 194 | [0x09] = KEY_9, |
| 195 | |
| 196 | [0x0c] = KEY_MUTE, |
| 197 | [0x0f] = KEY_SCREEN, /* Full Screen */ |
| 198 | [0x10] = KEY_F, /* Funtion */ |
| 199 | [0x11] = KEY_T, /* Time shift */ |
| 200 | [0x12] = KEY_POWER, |
| 201 | [0x13] = KEY_MEDIA, /* MTS */ |
| 202 | [0x14] = KEY_SLOW, |
| 203 | [0x16] = KEY_REWIND, /* backward << */ |
| 204 | [0x17] = KEY_ENTER, /* Return */ |
| 205 | [0x18] = KEY_FASTFORWARD, /* forward >> */ |
| 206 | [0x1a] = KEY_CHANNELUP, |
| 207 | [0x1b] = KEY_VOLUMEUP, |
| 208 | [0x1e] = KEY_CHANNELDOWN, |
| 209 | [0x1f] = KEY_VOLUMEDOWN, |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | /* ---------------------------------------------------------------------- */ |
| 213 | |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 214 | /* Cinergy 1400 DVB-T */ |
| 215 | static IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = { |
| 216 | [0x01] = KEY_POWER, |
| 217 | [0x02] = KEY_1, |
| 218 | [0x03] = KEY_2, |
| 219 | [0x04] = KEY_3, |
| 220 | [0x05] = KEY_4, |
| 221 | [0x06] = KEY_5, |
| 222 | [0x07] = KEY_6, |
| 223 | [0x08] = KEY_7, |
| 224 | [0x09] = KEY_8, |
| 225 | [0x0a] = KEY_9, |
| 226 | [0x0c] = KEY_0, |
| 227 | |
| 228 | [0x0b] = KEY_VIDEO, |
| 229 | [0x0d] = KEY_REFRESH, |
| 230 | [0x0e] = KEY_SELECT, |
| 231 | [0x0f] = KEY_EPG, |
| 232 | [0x10] = KEY_UP, |
| 233 | [0x11] = KEY_LEFT, |
| 234 | [0x12] = KEY_OK, |
| 235 | [0x13] = KEY_RIGHT, |
| 236 | [0x14] = KEY_DOWN, |
| 237 | [0x15] = KEY_TEXT, |
| 238 | [0x16] = KEY_INFO, |
| 239 | |
| 240 | [0x17] = KEY_RED, |
| 241 | [0x18] = KEY_GREEN, |
| 242 | [0x19] = KEY_YELLOW, |
| 243 | [0x1a] = KEY_BLUE, |
| 244 | |
| 245 | [0x1b] = KEY_CHANNELUP, |
| 246 | [0x1c] = KEY_VOLUMEUP, |
| 247 | [0x1d] = KEY_MUTE, |
| 248 | [0x1e] = KEY_VOLUMEDOWN, |
| 249 | [0x1f] = KEY_CHANNELDOWN, |
| 250 | |
| 251 | [0x40] = KEY_PAUSE, |
| 252 | [0x4c] = KEY_PLAY, |
| 253 | [0x58] = KEY_RECORD, |
| 254 | [0x54] = KEY_PREVIOUS, |
| 255 | [0x48] = KEY_STOP, |
| 256 | [0x5c] = KEY_NEXT, |
| 257 | }; |
| 258 | |
| 259 | /* ---------------------------------------------------------------------- */ |
| 260 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | struct cx88_IR { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 262 | struct cx88_core *core; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 263 | struct input_dev *input; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 264 | struct ir_input_state ir; |
| 265 | char name[32]; |
| 266 | char phys[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | /* sample from gpio pin 16 */ |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 269 | int sampling; |
| 270 | u32 samples[16]; |
| 271 | int scount; |
| 272 | unsigned long release; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
| 274 | /* poll external decoder */ |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 275 | int polling; |
| 276 | struct work_struct work; |
| 277 | struct timer_list timer; |
| 278 | u32 gpio_addr; |
| 279 | u32 last_gpio; |
| 280 | u32 mask_keycode; |
| 281 | u32 mask_keydown; |
| 282 | u32 mask_keyup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
| 285 | static int ir_debug = 0; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 286 | module_param(ir_debug, int, 0644); /* debug level [IR] */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
| 288 | |
| 289 | #define ir_dprintk(fmt, arg...) if (ir_debug) \ |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 290 | printk(KERN_DEBUG "%s IR: " fmt , ir->core->name , ##arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | /* ---------------------------------------------------------------------- */ |
| 293 | |
| 294 | static void cx88_ir_handle_key(struct cx88_IR *ir) |
| 295 | { |
| 296 | struct cx88_core *core = ir->core; |
| 297 | u32 gpio, data; |
| 298 | |
| 299 | /* read gpio value */ |
| 300 | gpio = cx_read(ir->gpio_addr); |
| 301 | if (ir->polling) { |
| 302 | if (ir->last_gpio == gpio) |
| 303 | return; |
| 304 | ir->last_gpio = gpio; |
| 305 | } |
| 306 | |
| 307 | /* extract data */ |
| 308 | data = ir_extract_bits(gpio, ir->mask_keycode); |
| 309 | ir_dprintk("irq gpio=0x%x code=%d | %s%s%s\n", |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 310 | gpio, data, |
| 311 | ir->polling ? "poll" : "irq", |
| 312 | (gpio & ir->mask_keydown) ? " down" : "", |
| 313 | (gpio & ir->mask_keyup) ? " up" : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
| 315 | if (ir->mask_keydown) { |
| 316 | /* bit set on keydown */ |
| 317 | if (gpio & ir->mask_keydown) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 318 | ir_input_keydown(ir->input, &ir->ir, data, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 320 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | } else if (ir->mask_keyup) { |
| 324 | /* bit cleared on keydown */ |
| 325 | if (0 == (gpio & ir->mask_keyup)) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 326 | ir_input_keydown(ir->input, &ir->ir, data, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 328 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | } else { |
| 332 | /* can't distinguish keydown/up :-/ */ |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 333 | ir_input_keydown(ir->input, &ir->ir, data, data); |
| 334 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | } |
| 337 | |
| 338 | static void ir_timer(unsigned long data) |
| 339 | { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 340 | struct cx88_IR *ir = (struct cx88_IR *)data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | schedule_work(&ir->work); |
| 343 | } |
| 344 | |
| 345 | static void cx88_ir_work(void *data) |
| 346 | { |
| 347 | struct cx88_IR *ir = data; |
| 348 | unsigned long timeout; |
| 349 | |
| 350 | cx88_ir_handle_key(ir); |
| 351 | timeout = jiffies + (ir->polling * HZ / 1000); |
| 352 | mod_timer(&ir->timer, timeout); |
| 353 | } |
| 354 | |
| 355 | /* ---------------------------------------------------------------------- */ |
| 356 | |
| 357 | int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci) |
| 358 | { |
| 359 | struct cx88_IR *ir; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 360 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | IR_KEYTAB_TYPE *ir_codes = NULL; |
| 362 | int ir_type = IR_TYPE_OTHER; |
| 363 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 364 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
| 365 | input_dev = input_allocate_device(); |
| 366 | if (!ir || !input_dev) { |
| 367 | kfree(ir); |
| 368 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return -ENOMEM; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | ir->input = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | /* detect & configure */ |
| 375 | switch (core->board) { |
| 376 | case CX88_BOARD_DNTV_LIVE_DVB_T: |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 377 | case CX88_BOARD_KWORLD_DVB_T: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 378 | ir_codes = ir_codes_dntv_live_dvb_t; |
| 379 | ir->gpio_addr = MO_GP1_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | ir->mask_keycode = 0x1f; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 381 | ir->mask_keyup = 0x60; |
| 382 | ir->polling = 50; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 384 | case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: |
| 385 | ir_codes = ir_codes_cinergy_1400; |
| 386 | ir_type = IR_TYPE_PD; |
| 387 | ir->sampling = 1; |
| 388 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | case CX88_BOARD_HAUPPAUGE: |
| 390 | case CX88_BOARD_HAUPPAUGE_DVB_T1: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 391 | ir_codes = ir_codes_hauppauge_new; |
| 392 | ir_type = IR_TYPE_RC5; |
| 393 | ir->sampling = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | break; |
| 395 | case CX88_BOARD_WINFAST2000XP_EXPERT: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 396 | ir_codes = ir_codes_winfast; |
| 397 | ir->gpio_addr = MO_GP0_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | ir->mask_keycode = 0x8f8; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 399 | ir->mask_keyup = 0x100; |
| 400 | ir->polling = 1; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | break; |
| 402 | case CX88_BOARD_IODATA_GVBCTV7E: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 403 | ir_codes = ir_codes_iodata_bctv7e; |
| 404 | ir->gpio_addr = MO_GP0_IO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | ir->mask_keycode = 0xfd; |
| 406 | ir->mask_keydown = 0x02; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 407 | ir->polling = 5; /* ms */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | break; |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 409 | case CX88_BOARD_PIXELVIEW_PLAYTV_ULTRA_PRO: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 410 | ir_codes = ir_codes_pixelview; |
| 411 | ir->gpio_addr = MO_GP1_IO; |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 412 | ir->mask_keycode = 0x1f; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 413 | ir->mask_keyup = 0x80; |
| 414 | ir->polling = 1; /* ms */ |
Manuel Capinha | 239df2e | 2005-06-23 22:04:53 -0700 | [diff] [blame] | 415 | break; |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 416 | case CX88_BOARD_ADSTECH_DVB_T_PCI: |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 417 | ir_codes = ir_codes_adstech_dvb_t_pci; |
| 418 | ir->gpio_addr = MO_GP1_IO; |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 419 | ir->mask_keycode = 0xbf; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 420 | ir->mask_keyup = 0x40; |
| 421 | ir->polling = 50; /* ms */ |
Mauro Carvalho Chehab | a82decf | 2005-07-07 17:58:36 -0700 | [diff] [blame] | 422 | break; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 423 | case CX88_BOARD_MSI_TVANYWHERE_MASTER: |
| 424 | ir_codes = ir_codes_msi_tvanywhere; |
| 425 | ir->gpio_addr = MO_GP1_IO; |
| 426 | ir->mask_keycode = 0x1f; |
| 427 | ir->mask_keyup = 0x40; |
| 428 | ir->polling = 1; /* ms */ |
| 429 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | } |
Mauro Carvalho Chehab | b45009b | 2005-06-23 22:05:03 -0700 | [diff] [blame] | 431 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | if (NULL == ir_codes) { |
| 433 | kfree(ir); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 434 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return -ENODEV; |
| 436 | } |
| 437 | |
| 438 | /* init input device */ |
| 439 | snprintf(ir->name, sizeof(ir->name), "cx88 IR (%s)", |
| 440 | cx88_boards[core->board].name); |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 441 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", pci_name(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 443 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 444 | input_dev->name = ir->name; |
| 445 | input_dev->phys = ir->phys; |
| 446 | input_dev->id.bustype = BUS_PCI; |
| 447 | input_dev->id.version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | if (pci->subsystem_vendor) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 449 | input_dev->id.vendor = pci->subsystem_vendor; |
| 450 | input_dev->id.product = pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 452 | input_dev->id.vendor = pci->vendor; |
| 453 | input_dev->id.product = pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 455 | input_dev->cdev.dev = &pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* record handles to ourself */ |
| 457 | ir->core = core; |
| 458 | core->ir = ir; |
| 459 | |
| 460 | if (ir->polling) { |
| 461 | INIT_WORK(&ir->work, cx88_ir_work, ir); |
| 462 | init_timer(&ir->timer); |
| 463 | ir->timer.function = ir_timer; |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 464 | ir->timer.data = (unsigned long)ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | schedule_work(&ir->work); |
| 466 | } |
| 467 | if (ir->sampling) { |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 468 | core->pci_irqmask |= (1 << 18); /* IR_SMP_INT */ |
| 469 | cx_write(MO_DDS_IO, 0xa80a80); /* 4 kHz sample rate */ |
| 470 | cx_write(MO_DDSCFG_IO, 0x5); /* enable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | /* all done */ |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 474 | input_register_device(ir->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | int cx88_ir_fini(struct cx88_core *core) |
| 480 | { |
| 481 | struct cx88_IR *ir = core->ir; |
| 482 | |
| 483 | /* skip detach on non attached boards */ |
| 484 | if (NULL == ir) |
| 485 | return 0; |
| 486 | |
| 487 | if (ir->polling) { |
| 488 | del_timer(&ir->timer); |
| 489 | flush_scheduled_work(); |
| 490 | } |
| 491 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 492 | input_unregister_device(ir->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | kfree(ir); |
| 494 | |
| 495 | /* done */ |
| 496 | core->ir = NULL; |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /* ---------------------------------------------------------------------- */ |
| 501 | |
| 502 | void cx88_ir_irq(struct cx88_core *core) |
| 503 | { |
| 504 | struct cx88_IR *ir = core->ir; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 505 | u32 samples, ircode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | int i; |
| 507 | |
| 508 | if (NULL == ir) |
| 509 | return; |
| 510 | if (!ir->sampling) |
| 511 | return; |
| 512 | |
| 513 | samples = cx_read(MO_SAMPLE_IO); |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 514 | if (0 != samples && 0xffffffff != samples) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | /* record sample data */ |
| 516 | if (ir->scount < ARRAY_SIZE(ir->samples)) |
| 517 | ir->samples[ir->scount++] = samples; |
| 518 | return; |
| 519 | } |
| 520 | if (!ir->scount) { |
| 521 | /* nothing to sample */ |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 522 | if (ir->ir.keypressed && time_after(jiffies, ir->release)) |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 523 | ir_input_nokey(ir->input, &ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return; |
| 525 | } |
| 526 | |
| 527 | /* have a complete sample */ |
| 528 | if (ir->scount < ARRAY_SIZE(ir->samples)) |
| 529 | ir->samples[ir->scount++] = samples; |
| 530 | for (i = 0; i < ir->scount; i++) |
| 531 | ir->samples[i] = ~ir->samples[i]; |
| 532 | if (ir_debug) |
Mauro Carvalho Chehab | 41ef7c1 | 2005-07-12 13:58:44 -0700 | [diff] [blame] | 533 | ir_dump_samples(ir->samples, ir->scount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | /* decode it */ |
| 536 | switch (core->board) { |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 537 | case CX88_BOARD_TERRATEC_CINERGY_1400_DVB_T1: |
| 538 | ircode = ir_decode_pulsedistance(ir->samples, ir->scount, 1, 4); |
| 539 | |
| 540 | if (ircode == 0xffffffff) { /* decoding error */ |
| 541 | ir_dprintk("pulse distance decoding error\n"); |
| 542 | break; |
| 543 | } |
| 544 | |
| 545 | ir_dprintk("pulse distance decoded: %x\n", ircode); |
| 546 | |
| 547 | if (ircode == 0) { /* key still pressed */ |
| 548 | ir_dprintk("pulse distance decoded repeat code\n"); |
| 549 | ir->release = jiffies + msecs_to_jiffies(120); |
| 550 | break; |
| 551 | } |
| 552 | |
| 553 | if ((ircode & 0xffff) != 0xeb04) { /* wrong address */ |
| 554 | ir_dprintk("pulse distance decoded wrong address\n"); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 555 | break; |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | if (((~ircode >> 24) & 0xff) != ((ircode >> 16) & 0xff)) { /* wrong checksum */ |
| 559 | ir_dprintk("pulse distance decoded wrong check sum\n"); |
| 560 | break; |
| 561 | } |
| 562 | |
| 563 | ir_dprintk("Key Code: %x\n", (ircode >> 16) & 0x7f); |
| 564 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 565 | ir_input_keydown(ir->input, &ir->ir, (ircode >> 16) & 0x7f, (ircode >> 16) & 0xff); |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 566 | ir->release = jiffies + msecs_to_jiffies(120); |
| 567 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | case CX88_BOARD_HAUPPAUGE: |
| 569 | case CX88_BOARD_HAUPPAUGE_DVB_T1: |
Mauro Carvalho Chehab | e52e98a | 2005-09-09 13:03:41 -0700 | [diff] [blame] | 570 | ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); |
| 571 | ir_dprintk("biphase decoded: %x\n", ircode); |
| 572 | if ((ircode & 0xfffff000) != 0x3000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | break; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 574 | ir_input_keydown(ir->input, &ir->ir, ircode & 0x3f, ircode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | ir->release = jiffies + msecs_to_jiffies(120); |
| 576 | break; |
| 577 | } |
| 578 | |
| 579 | ir->scount = 0; |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | /* ---------------------------------------------------------------------- */ |
| 584 | |
| 585 | MODULE_AUTHOR("Gerd Knorr, Pavel Machek, Chris Pascoe"); |
| 586 | MODULE_DESCRIPTION("input driver for cx88 GPIO-based IR remote controls"); |
| 587 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | /* |
| 589 | * Local variables: |
| 590 | * c-basic-offset: 8 |
| 591 | * End: |
| 592 | */ |