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 | * Copyright (c) 2003 Gerd Knorr |
| 4 | * Copyright (c) 2003 Pavel Machek |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/moduleparam.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/input.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include "bttv.h" |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 29 | #include "bttvp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | /* ---------------------------------------------------------------------- */ |
| 32 | |
| 33 | static IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE] = { |
| 34 | [ 34 ] = KEY_KP0, |
| 35 | [ 40 ] = KEY_KP1, |
| 36 | [ 24 ] = KEY_KP2, |
| 37 | [ 56 ] = KEY_KP3, |
| 38 | [ 36 ] = KEY_KP4, |
| 39 | [ 20 ] = KEY_KP5, |
| 40 | [ 52 ] = KEY_KP6, |
| 41 | [ 44 ] = KEY_KP7, |
| 42 | [ 28 ] = KEY_KP8, |
| 43 | [ 60 ] = KEY_KP9, |
| 44 | |
| 45 | [ 48 ] = KEY_EJECTCD, // Unmarked on my controller |
| 46 | [ 0 ] = KEY_POWER, |
| 47 | [ 18 ] = BTN_LEFT, // DISPLAY/L |
| 48 | [ 50 ] = BTN_RIGHT, // LOOP/R |
| 49 | [ 10 ] = KEY_MUTE, |
| 50 | [ 38 ] = KEY_RECORD, |
| 51 | [ 22 ] = KEY_PAUSE, |
| 52 | [ 54 ] = KEY_STOP, |
| 53 | [ 30 ] = KEY_VOLUMEDOWN, |
| 54 | [ 62 ] = KEY_VOLUMEUP, |
| 55 | |
| 56 | [ 32 ] = KEY_TUNER, // TV/FM |
| 57 | [ 16 ] = KEY_CD, |
| 58 | [ 8 ] = KEY_VIDEO, |
| 59 | [ 4 ] = KEY_AUDIO, |
| 60 | [ 12 ] = KEY_ZOOM, // full screen |
| 61 | [ 2 ] = KEY_INFO, // preview |
| 62 | [ 42 ] = KEY_SEARCH, // autoscan |
| 63 | [ 26 ] = KEY_STOP, // freeze |
| 64 | [ 58 ] = KEY_RECORD, // capture |
| 65 | [ 6 ] = KEY_PLAY, // unmarked |
| 66 | [ 46 ] = KEY_RED, // unmarked |
| 67 | [ 14 ] = KEY_GREEN, // unmarked |
| 68 | |
| 69 | [ 33 ] = KEY_YELLOW, // unmarked |
| 70 | [ 17 ] = KEY_CHANNELDOWN, |
| 71 | [ 49 ] = KEY_CHANNELUP, |
| 72 | [ 1 ] = KEY_BLUE, // unmarked |
| 73 | }; |
| 74 | |
| 75 | /* Matt Jesson <dvb@jesson.eclipse.co.uk */ |
| 76 | static IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = { |
| 77 | [ 0x28 ] = KEY_KP0, //'0' / 'enter' |
| 78 | [ 0x22 ] = KEY_KP1, //'1' |
| 79 | [ 0x12 ] = KEY_KP2, //'2' / 'up arrow' |
| 80 | [ 0x32 ] = KEY_KP3, //'3' |
| 81 | [ 0x24 ] = KEY_KP4, //'4' / 'left arrow' |
| 82 | [ 0x14 ] = KEY_KP5, //'5' |
| 83 | [ 0x34 ] = KEY_KP6, //'6' / 'right arrow' |
| 84 | [ 0x26 ] = KEY_KP7, //'7' |
| 85 | [ 0x16 ] = KEY_KP8, //'8' / 'down arrow' |
| 86 | [ 0x36 ] = KEY_KP9, //'9' |
| 87 | |
| 88 | [ 0x20 ] = KEY_LIST, // 'source' |
| 89 | [ 0x10 ] = KEY_TEXT, // 'teletext' |
| 90 | [ 0x00 ] = KEY_POWER, // 'power' |
| 91 | [ 0x04 ] = KEY_AUDIO, // 'audio' |
| 92 | [ 0x06 ] = KEY_ZOOM, // 'full screen' |
| 93 | [ 0x18 ] = KEY_VIDEO, // 'display' |
| 94 | [ 0x38 ] = KEY_SEARCH, // 'loop' |
| 95 | [ 0x08 ] = KEY_INFO, // 'preview' |
| 96 | [ 0x2a ] = KEY_REWIND, // 'backward <<' |
| 97 | [ 0x1a ] = KEY_FASTFORWARD, // 'forward >>' |
| 98 | [ 0x3a ] = KEY_RECORD, // 'capture' |
| 99 | [ 0x0a ] = KEY_MUTE, // 'mute' |
| 100 | [ 0x2c ] = KEY_RECORD, // 'record' |
| 101 | [ 0x1c ] = KEY_PAUSE, // 'pause' |
| 102 | [ 0x3c ] = KEY_STOP, // 'stop' |
| 103 | [ 0x0c ] = KEY_PLAY, // 'play' |
| 104 | [ 0x2e ] = KEY_RED, // 'red' |
| 105 | [ 0x01 ] = KEY_BLUE, // 'blue' / 'cancel' |
| 106 | [ 0x0e ] = KEY_YELLOW, // 'yellow' / 'ok' |
| 107 | [ 0x21 ] = KEY_GREEN, // 'green' |
| 108 | [ 0x11 ] = KEY_CHANNELDOWN, // 'channel -' |
| 109 | [ 0x31 ] = KEY_CHANNELUP, // 'channel +' |
| 110 | [ 0x1e ] = KEY_VOLUMEDOWN, // 'volume -' |
| 111 | [ 0x3e ] = KEY_VOLUMEUP, // 'volume +' |
| 112 | }; |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* Attila Kondoros <attila.kondoros@chello.hu> */ |
| 115 | static IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = { |
| 116 | |
| 117 | [ 1 ] = KEY_KP1, |
| 118 | [ 2 ] = KEY_KP2, |
| 119 | [ 3 ] = KEY_KP3, |
| 120 | [ 4 ] = KEY_KP4, |
| 121 | [ 5 ] = KEY_KP5, |
| 122 | [ 6 ] = KEY_KP6, |
| 123 | [ 7 ] = KEY_KP7, |
| 124 | [ 8 ] = KEY_KP8, |
| 125 | [ 9 ] = KEY_KP9, |
| 126 | [ 0 ] = KEY_KP0, |
| 127 | [ 23 ] = KEY_LAST, // +100 |
| 128 | [ 10 ] = KEY_LIST, // recall |
| 129 | |
| 130 | |
| 131 | [ 28 ] = KEY_TUNER, // TV/FM |
| 132 | [ 21 ] = KEY_SEARCH, // scan |
| 133 | [ 18 ] = KEY_POWER, // power |
| 134 | [ 31 ] = KEY_VOLUMEDOWN, // vol up |
| 135 | [ 27 ] = KEY_VOLUMEUP, // vol down |
| 136 | [ 30 ] = KEY_CHANNELDOWN, // chn up |
| 137 | [ 26 ] = KEY_CHANNELUP, // chn down |
| 138 | |
| 139 | [ 17 ] = KEY_VIDEO, // video |
| 140 | [ 15 ] = KEY_ZOOM, // full screen |
| 141 | [ 19 ] = KEY_MUTE, // mute/unmute |
| 142 | [ 16 ] = KEY_TEXT, // min |
| 143 | |
| 144 | [ 13 ] = KEY_STOP, // freeze |
| 145 | [ 14 ] = KEY_RECORD, // record |
| 146 | [ 29 ] = KEY_PLAYPAUSE, // stop |
| 147 | [ 25 ] = KEY_PLAY, // play |
| 148 | |
| 149 | [ 22 ] = KEY_GOTO, // osd |
| 150 | [ 20 ] = KEY_REFRESH, // default |
| 151 | [ 12 ] = KEY_KPPLUS, // fine tune >>>> |
| 152 | [ 24 ] = KEY_KPMINUS // fine tune <<<< |
| 153 | }; |
| 154 | |
| 155 | /* ---------------------------------------------------------------------- */ |
| 156 | |
Ricardo Cerqueira | cc9d8d4 | 2005-11-08 21:36:20 -0800 | [diff] [blame] | 157 | static IR_KEYTAB_TYPE ir_codes_conceptronic[IR_KEYTAB_SIZE] = { |
| 158 | |
| 159 | [ 30 ] = KEY_POWER, // power |
Nickolay V. Shmyrev | 84cd961 | 2005-11-08 21:36:24 -0800 | [diff] [blame] | 160 | [ 7 ] = KEY_MEDIA, // source |
Ricardo Cerqueira | cc9d8d4 | 2005-11-08 21:36:20 -0800 | [diff] [blame] | 161 | [ 28 ] = KEY_SEARCH, // scan |
| 162 | |
| 163 | /* FIXME: duplicate keycodes? |
| 164 | * |
| 165 | * These four keys seem to share the same GPIO as CH+, CH-, <<< and >>> |
| 166 | * The GPIO values are |
| 167 | * 6397fb for both "Scan <" and "CH -", |
| 168 | * 639ffb for "Scan >" and "CH+", |
| 169 | * 6384fb for "Tune <" and "<<<", |
| 170 | * 638cfb for "Tune >" and ">>>", regardless of the mask. |
| 171 | * |
| 172 | * [ 23 ] = KEY_BACK, // fm scan << |
| 173 | * [ 31 ] = KEY_FORWARD, // fm scan >> |
| 174 | * |
| 175 | * [ 4 ] = KEY_LEFT, // fm tuning < |
| 176 | * [ 12 ] = KEY_RIGHT, // fm tuning > |
| 177 | * |
| 178 | * For now, these four keys are disabled. Pressing them will generate |
| 179 | * the CH+/CH-/<<</>>> events |
| 180 | */ |
| 181 | |
| 182 | [ 3 ] = KEY_TUNER, // TV/FM |
| 183 | |
| 184 | [ 0 ] = KEY_RECORD, |
| 185 | [ 8 ] = KEY_STOP, |
| 186 | [ 17 ] = KEY_PLAY, |
| 187 | |
| 188 | [ 26 ] = KEY_PLAYPAUSE, // freeze |
| 189 | [ 25 ] = KEY_ZOOM, // zoom |
| 190 | [ 15 ] = KEY_TEXT, // min |
| 191 | |
| 192 | [ 1 ] = KEY_KP1, |
| 193 | [ 11 ] = KEY_KP2, |
| 194 | [ 27 ] = KEY_KP3, |
| 195 | [ 5 ] = KEY_KP4, |
| 196 | [ 9 ] = KEY_KP5, |
| 197 | [ 21 ] = KEY_KP6, |
| 198 | [ 6 ] = KEY_KP7, |
| 199 | [ 10 ] = KEY_KP8, |
| 200 | [ 18 ] = KEY_KP9, |
| 201 | [ 2 ] = KEY_KP0, |
| 202 | [ 16 ] = KEY_LAST, // +100 |
| 203 | [ 19 ] = KEY_LIST, // recall |
| 204 | |
| 205 | [ 31 ] = KEY_CHANNELUP, // chn down |
| 206 | [ 23 ] = KEY_CHANNELDOWN, // chn up |
| 207 | [ 22 ] = KEY_VOLUMEUP, // vol down |
| 208 | [ 20 ] = KEY_VOLUMEDOWN, // vol up |
| 209 | |
| 210 | [ 4 ] = KEY_KPMINUS, // <<< |
| 211 | [ 14 ] = KEY_SETUP, // function |
| 212 | [ 12 ] = KEY_KPPLUS, // >>> |
| 213 | |
| 214 | [ 13 ] = KEY_GOTO, // mts |
| 215 | [ 29 ] = KEY_REFRESH, // reset |
| 216 | [ 24 ] = KEY_MUTE // mute/unmute |
| 217 | }; |
| 218 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 219 | static IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = { |
| 220 | [0x00] = KEY_KP0, |
| 221 | [0x01] = KEY_KP1, |
| 222 | [0x02] = KEY_KP2, |
| 223 | [0x03] = KEY_KP3, |
| 224 | [0x04] = KEY_KP4, |
| 225 | [0x05] = KEY_KP5, |
| 226 | [0x06] = KEY_KP6, |
| 227 | [0x07] = KEY_KP7, |
| 228 | [0x08] = KEY_KP8, |
| 229 | [0x09] = KEY_KP9, |
| 230 | [0x0a] = KEY_TV, |
| 231 | [0x0b] = KEY_AUX, |
| 232 | [0x0c] = KEY_DVD, |
| 233 | [0x0d] = KEY_POWER, |
| 234 | [0x0e] = KEY_MHP, /* labelled 'Picture' */ |
| 235 | [0x0f] = KEY_AUDIO, |
| 236 | [0x10] = KEY_INFO, |
| 237 | [0x11] = KEY_F13, /* 16:9 */ |
| 238 | [0x12] = KEY_F14, /* 14:9 */ |
| 239 | [0x13] = KEY_EPG, |
| 240 | [0x14] = KEY_EXIT, |
| 241 | [0x15] = KEY_MENU, |
| 242 | [0x16] = KEY_UP, |
| 243 | [0x17] = KEY_DOWN, |
| 244 | [0x18] = KEY_LEFT, |
| 245 | [0x19] = KEY_RIGHT, |
| 246 | [0x1a] = KEY_ENTER, |
| 247 | [0x1b] = KEY_CHANNELUP, |
| 248 | [0x1c] = KEY_CHANNELDOWN, |
| 249 | [0x1d] = KEY_VOLUMEUP, |
| 250 | [0x1e] = KEY_VOLUMEDOWN, |
| 251 | [0x1f] = KEY_RED, |
| 252 | [0x20] = KEY_GREEN, |
| 253 | [0x21] = KEY_YELLOW, |
| 254 | [0x22] = KEY_BLUE, |
| 255 | [0x23] = KEY_SUBTITLE, |
| 256 | [0x24] = KEY_F15, /* AD */ |
| 257 | [0x25] = KEY_TEXT, |
| 258 | [0x26] = KEY_MUTE, |
| 259 | [0x27] = KEY_REWIND, |
| 260 | [0x28] = KEY_STOP, |
| 261 | [0x29] = KEY_PLAY, |
| 262 | [0x2a] = KEY_FASTFORWARD, |
| 263 | [0x2b] = KEY_F16, /* chapter */ |
| 264 | [0x2c] = KEY_PAUSE, |
| 265 | [0x2d] = KEY_PLAY, |
| 266 | [0x2e] = KEY_RECORD, |
| 267 | [0x2f] = KEY_F17, /* picture in picture */ |
| 268 | [0x30] = KEY_KPPLUS, /* zoom in */ |
| 269 | [0x31] = KEY_KPMINUS, /* zoom out */ |
| 270 | [0x32] = KEY_F18, /* capture */ |
| 271 | [0x33] = KEY_F19, /* web */ |
| 272 | [0x34] = KEY_EMAIL, |
| 273 | [0x35] = KEY_PHONE, |
| 274 | [0x36] = KEY_PC |
| 275 | }; |
| 276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | static int debug; |
| 278 | module_param(debug, int, 0644); /* debug level (0,1,2) */ |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 279 | static int repeat_delay = 500; |
| 280 | module_param(repeat_delay, int, 0644); |
| 281 | static int repeat_period = 33; |
| 282 | module_param(repeat_period, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 284 | #define DEVNAME "bttv-input" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | /* ---------------------------------------------------------------------- */ |
| 287 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 288 | static void ir_handle_key(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 290 | struct bttv_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | u32 gpio,data; |
| 292 | |
| 293 | /* read gpio value */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 294 | gpio = bttv_gpio_read(&btv->c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | if (ir->polling) { |
| 296 | if (ir->last_gpio == gpio) |
| 297 | return; |
| 298 | ir->last_gpio = gpio; |
| 299 | } |
| 300 | |
| 301 | /* extract data */ |
| 302 | data = ir_extract_bits(gpio, ir->mask_keycode); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 303 | dprintk(KERN_INFO DEVNAME ": irq gpio=0x%x code=%d | %s%s%s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | gpio, data, |
| 305 | ir->polling ? "poll" : "irq", |
| 306 | (gpio & ir->mask_keydown) ? " down" : "", |
| 307 | (gpio & ir->mask_keyup) ? " up" : ""); |
| 308 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 309 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 310 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
| 311 | ir_input_keydown(ir->dev,&ir->ir,data,data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } else { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 313 | ir_input_nokey(ir->dev,&ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 318 | void bttv_input_irq(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 320 | struct bttv_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
| 322 | if (!ir->polling) |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 323 | ir_handle_key(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 326 | static void bttv_input_timer(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 328 | struct bttv *btv = (struct bttv*)data; |
| 329 | struct bttv_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | unsigned long timeout; |
| 331 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 332 | ir_handle_key(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | timeout = jiffies + (ir->polling * HZ / 1000); |
| 334 | mod_timer(&ir->timer, timeout); |
| 335 | } |
| 336 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 337 | /* ---------------------------------------------------------------*/ |
| 338 | |
| 339 | static int rc5_remote_gap = 885; |
| 340 | module_param(rc5_remote_gap, int, 0644); |
| 341 | static int rc5_key_timeout = 200; |
| 342 | module_param(rc5_key_timeout, int, 0644); |
| 343 | |
| 344 | #define RC5_START(x) (((x)>>12)&3) |
| 345 | #define RC5_TOGGLE(x) (((x)>>11)&1) |
| 346 | #define RC5_ADDR(x) (((x)>>6)&31) |
| 347 | #define RC5_INSTR(x) ((x)&63) |
| 348 | |
| 349 | /* decode raw bit pattern to RC5 code */ |
| 350 | static u32 rc5_decode(unsigned int code) |
| 351 | { |
| 352 | unsigned int org_code = code; |
| 353 | unsigned int pair; |
| 354 | unsigned int rc5 = 0; |
| 355 | int i; |
| 356 | |
| 357 | code = (code << 1) | 1; |
| 358 | for (i = 0; i < 14; ++i) { |
| 359 | pair = code & 0x3; |
| 360 | code >>= 2; |
| 361 | |
| 362 | rc5 <<= 1; |
| 363 | switch (pair) { |
| 364 | case 0: |
| 365 | case 2: |
| 366 | break; |
| 367 | case 1: |
| 368 | rc5 |= 1; |
| 369 | break; |
| 370 | case 3: |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 371 | dprintk(KERN_WARNING "bad code: %x\n", org_code); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 372 | return 0; |
| 373 | } |
| 374 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 375 | dprintk(KERN_WARNING "code=%x, rc5=%x, start=%x, toggle=%x, address=%x, " |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 376 | "instr=%x\n", rc5, org_code, RC5_START(rc5), |
| 377 | RC5_TOGGLE(rc5), RC5_ADDR(rc5), RC5_INSTR(rc5)); |
| 378 | return rc5; |
| 379 | } |
| 380 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 381 | static int bttv_rc5_irq(struct bttv *btv) |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 382 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 383 | struct bttv_ir *ir = btv->remote; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 384 | struct timeval tv; |
| 385 | u32 gpio; |
| 386 | u32 gap; |
| 387 | unsigned long current_jiffies, timeout; |
| 388 | |
| 389 | /* read gpio port */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 390 | gpio = bttv_gpio_read(&btv->c); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 391 | |
| 392 | /* remote IRQ? */ |
| 393 | if (!(gpio & 0x20)) |
| 394 | return 0; |
| 395 | |
| 396 | /* get time of bit */ |
| 397 | current_jiffies = jiffies; |
| 398 | do_gettimeofday(&tv); |
| 399 | |
| 400 | /* avoid overflow with gap >1s */ |
| 401 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 402 | gap = 200000; |
| 403 | } else { |
| 404 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 405 | tv.tv_usec - ir->base_time.tv_usec; |
| 406 | } |
| 407 | |
| 408 | /* active code => add bit */ |
| 409 | if (ir->active) { |
| 410 | /* only if in the code (otherwise spurious IRQ or timer |
| 411 | late) */ |
| 412 | if (ir->last_bit < 28) { |
| 413 | ir->last_bit = (gap - rc5_remote_gap / 2) / |
| 414 | rc5_remote_gap; |
| 415 | ir->code |= 1 << ir->last_bit; |
| 416 | } |
| 417 | /* starting new code */ |
| 418 | } else { |
| 419 | ir->active = 1; |
| 420 | ir->code = 0; |
| 421 | ir->base_time = tv; |
| 422 | ir->last_bit = 0; |
| 423 | |
| 424 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; |
| 425 | mod_timer(&ir->timer_end, timeout); |
| 426 | } |
| 427 | |
| 428 | /* toggle GPIO pin 4 to reset the irq */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 429 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
| 430 | bttv_gpio_write(&btv->c, gpio | (1 << 4)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 431 | return 1; |
| 432 | } |
| 433 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 434 | |
| 435 | static void bttv_rc5_timer_end(unsigned long data) |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 436 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 437 | struct bttv_ir *ir = (struct bttv_ir *)data; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 438 | struct timeval tv; |
| 439 | unsigned long current_jiffies, timeout; |
| 440 | u32 gap; |
| 441 | |
| 442 | /* get time */ |
| 443 | current_jiffies = jiffies; |
| 444 | do_gettimeofday(&tv); |
| 445 | |
| 446 | /* avoid overflow with gap >1s */ |
| 447 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 448 | gap = 200000; |
| 449 | } else { |
| 450 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 451 | tv.tv_usec - ir->base_time.tv_usec; |
| 452 | } |
| 453 | |
| 454 | /* Allow some timmer jitter (RC5 is ~24ms anyway so this is ok) */ |
| 455 | if (gap < 28000) { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 456 | dprintk(KERN_WARNING "spurious timer_end\n"); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 457 | return; |
| 458 | } |
| 459 | |
| 460 | ir->active = 0; |
| 461 | if (ir->last_bit < 20) { |
| 462 | /* ignore spurious codes (caused by light/other remotes) */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 463 | dprintk(KERN_WARNING "short code: %x\n", ir->code); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 464 | } else { |
| 465 | u32 rc5 = rc5_decode(ir->code); |
| 466 | |
| 467 | /* two start bits? */ |
| 468 | if (RC5_START(rc5) != 3) { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 469 | dprintk(KERN_WARNING "rc5 start bits invalid: %u\n", RC5_START(rc5)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 470 | |
| 471 | /* right address? */ |
| 472 | } else if (RC5_ADDR(rc5) == 0x0) { |
| 473 | u32 toggle = RC5_TOGGLE(rc5); |
| 474 | u32 instr = RC5_INSTR(rc5); |
| 475 | |
| 476 | /* Good code, decide if repeat/repress */ |
| 477 | if (toggle != RC5_TOGGLE(ir->last_rc5) || |
| 478 | instr != RC5_INSTR(ir->last_rc5)) { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 479 | dprintk(KERN_WARNING "instruction %x, toggle %x\n", instr, |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 480 | toggle); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 481 | ir_input_nokey(ir->dev, &ir->ir); |
| 482 | ir_input_keydown(ir->dev, &ir->ir, instr, |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 483 | instr); |
| 484 | } |
| 485 | |
| 486 | /* Set/reset key-up timer */ |
| 487 | timeout = current_jiffies + (500 + rc5_key_timeout |
| 488 | * HZ) / 1000; |
| 489 | mod_timer(&ir->timer_keyup, timeout); |
| 490 | |
| 491 | /* Save code for repeat test */ |
| 492 | ir->last_rc5 = rc5; |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 497 | static void bttv_rc5_timer_keyup(unsigned long data) |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 498 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 499 | struct bttv_ir *ir = (struct bttv_ir *)data; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 500 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 501 | dprintk(KERN_DEBUG "key released\n"); |
| 502 | ir_input_nokey(ir->dev, &ir->ir); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* ---------------------------------------------------------------------- */ |
| 506 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 507 | int bttv_input_init(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 509 | struct bttv_ir *ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | IR_KEYTAB_TYPE *ir_codes = NULL; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 511 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | int ir_type = IR_TYPE_OTHER; |
| 513 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 514 | if (!btv->has_remote) |
| 515 | return -ENODEV; |
| 516 | |
| 517 | ir = kzalloc(sizeof(*ir),GFP_KERNEL); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 518 | input_dev = input_allocate_device(); |
| 519 | if (!ir || !input_dev) { |
| 520 | kfree(ir); |
| 521 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | return -ENOMEM; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 523 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 524 | memset(ir,0,sizeof(*ir)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | /* detect & configure */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 527 | switch (btv->c.type) { |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 528 | case BTTV_BOARD_AVERMEDIA: |
| 529 | case BTTV_BOARD_AVPHONE98: |
| 530 | case BTTV_BOARD_AVERMEDIA98: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | ir_codes = ir_codes_avermedia; |
| 532 | ir->mask_keycode = 0xf88000; |
| 533 | ir->mask_keydown = 0x010000; |
| 534 | ir->polling = 50; // ms |
| 535 | break; |
| 536 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 537 | case BTTV_BOARD_AVDVBT_761: |
| 538 | case BTTV_BOARD_AVDVBT_771: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | ir_codes = ir_codes_avermedia_dvbt; |
| 540 | ir->mask_keycode = 0x0f00c0; |
| 541 | ir->mask_keydown = 0x000020; |
| 542 | ir->polling = 50; // ms |
| 543 | break; |
| 544 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 545 | case BTTV_BOARD_PXELVWPLTVPAK: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | ir_codes = ir_codes_pixelview; |
| 547 | ir->mask_keycode = 0x003e00; |
| 548 | ir->mask_keyup = 0x010000; |
| 549 | ir->polling = 50; // ms |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 550 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 551 | case BTTV_BOARD_PV_BT878P_9B: |
| 552 | case BTTV_BOARD_PV_BT878P_PLUS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | ir_codes = ir_codes_pixelview; |
| 554 | ir->mask_keycode = 0x001f00; |
| 555 | ir->mask_keyup = 0x008000; |
| 556 | ir->polling = 50; // ms |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 557 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 559 | case BTTV_BOARD_WINFAST2000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | ir_codes = ir_codes_winfast; |
| 561 | ir->mask_keycode = 0x1f8; |
| 562 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 563 | case BTTV_BOARD_MAGICTVIEW061: |
| 564 | case BTTV_BOARD_MAGICTVIEW063: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | ir_codes = ir_codes_winfast; |
| 566 | ir->mask_keycode = 0x0008e000; |
| 567 | ir->mask_keydown = 0x00200000; |
| 568 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 569 | case BTTV_BOARD_APAC_VIEWCOMP: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | ir_codes = ir_codes_apac_viewcomp; |
| 571 | ir->mask_keycode = 0x001f00; |
| 572 | ir->mask_keyup = 0x008000; |
| 573 | ir->polling = 50; // ms |
| 574 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 575 | case BTTV_BOARD_CONCEPTRONIC_CTVFMI2: |
Ricardo Cerqueira | cc9d8d4 | 2005-11-08 21:36:20 -0800 | [diff] [blame] | 576 | ir_codes = ir_codes_conceptronic; |
| 577 | ir->mask_keycode = 0x001F00; |
| 578 | ir->mask_keyup = 0x006000; |
| 579 | ir->polling = 50; // ms |
| 580 | break; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 581 | case BTTV_BOARD_NEBULA_DIGITV: |
| 582 | ir_codes = ir_codes_nebula; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 583 | btv->custom_irq = bttv_rc5_irq; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 584 | ir->rc5_gpio = 1; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 585 | break; |
Julian Calaby | 2d05ae6 | 2006-01-11 19:40:09 -0200 | [diff] [blame] | 586 | case BTTV_BOARD_MACHTV_MAGICTV: |
| 587 | ir_codes = ir_codes_apac_viewcomp; |
| 588 | ir->mask_keycode = 0x001F00; |
| 589 | ir->mask_keyup = 0x004000; |
| 590 | ir->polling = 50; /* ms */ |
| 591 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | } |
| 593 | if (NULL == ir_codes) { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 594 | dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n",btv->c.type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | kfree(ir); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 596 | input_free_device(input_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | return -ENODEV; |
| 598 | } |
| 599 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 600 | if (ir->rc5_gpio) { |
| 601 | u32 gpio; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 602 | /* enable remote irq */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 603 | bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4); |
| 604 | gpio = bttv_gpio_read(&btv->c); |
| 605 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
| 606 | bttv_gpio_write(&btv->c, gpio | (1 << 4)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 607 | } else { |
| 608 | /* init hardware-specific stuff */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 609 | bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 610 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | |
| 612 | /* init input device */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 613 | ir->dev = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 615 | snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", |
| 616 | btv->c.type); |
| 617 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", |
| 618 | pci_name(btv->c.pci)); |
| 619 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 620 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 621 | input_dev->name = ir->name; |
| 622 | input_dev->phys = ir->phys; |
| 623 | input_dev->id.bustype = BUS_PCI; |
| 624 | input_dev->id.version = 1; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 625 | if (btv->c.pci->subsystem_vendor) { |
| 626 | input_dev->id.vendor = btv->c.pci->subsystem_vendor; |
| 627 | input_dev->id.product = btv->c.pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } else { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 629 | input_dev->id.vendor = btv->c.pci->vendor; |
| 630 | input_dev->id.product = btv->c.pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 632 | input_dev->cdev.dev = &btv->c.pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 634 | btv->remote = ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | if (ir->polling) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | init_timer(&ir->timer); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 637 | ir->timer.function = bttv_input_timer; |
| 638 | ir->timer.data = (unsigned long)btv; |
| 639 | ir->timer.expires = jiffies + HZ; |
| 640 | add_timer(&ir->timer); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 641 | } else if (ir->rc5_gpio) { |
| 642 | /* set timer_end for code completion */ |
| 643 | init_timer(&ir->timer_end); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 644 | ir->timer_end.function = bttv_rc5_timer_end; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 645 | ir->timer_end.data = (unsigned long)ir; |
| 646 | |
| 647 | init_timer(&ir->timer_keyup); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 648 | ir->timer_keyup.function = bttv_rc5_timer_keyup; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 649 | ir->timer_keyup.data = (unsigned long)ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | /* all done */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 653 | input_register_device(btv->remote->dev); |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 654 | printk(DEVNAME ": %s detected at %s\n",ir->name,ir->phys); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 655 | |
| 656 | /* the remote isn't as bouncy as a keyboard */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 657 | ir->dev->rep[REP_DELAY] = repeat_delay; |
| 658 | ir->dev->rep[REP_PERIOD] = repeat_period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 663 | void bttv_input_fini(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 665 | if (btv->remote == NULL) |
| 666 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 668 | if (btv->remote->polling) { |
| 669 | del_timer_sync(&btv->remote->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | flush_scheduled_work(); |
| 671 | } |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 672 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 673 | |
| 674 | if (btv->remote->rc5_gpio) { |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 675 | u32 gpio; |
| 676 | |
Andrew Morton | bc61b01 | 2006-01-09 15:25:28 -0200 | [diff] [blame] | 677 | del_timer_sync(&btv->remote->timer_end); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 678 | flush_scheduled_work(); |
| 679 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 680 | gpio = bttv_gpio_read(&btv->c); |
| 681 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 684 | input_unregister_device(btv->remote->dev); |
| 685 | kfree(btv->remote); |
| 686 | btv->remote = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | } |
| 688 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | /* |
| 691 | * Local variables: |
| 692 | * c-basic-offset: 8 |
| 693 | * End: |
| 694 | */ |