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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/input.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.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 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 31 | |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 32 | static int ir_debug; |
| 33 | module_param(ir_debug, int, 0644); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 34 | static int repeat_delay = 500; |
| 35 | module_param(repeat_delay, int, 0644); |
| 36 | static int repeat_period = 33; |
| 37 | module_param(repeat_period, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Adrian Bunk | c408a6f | 2006-12-28 12:47:47 -0300 | [diff] [blame] | 39 | static int ir_rc5_remote_gap = 885; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 40 | module_param(ir_rc5_remote_gap, int, 0644); |
Adrian Bunk | c408a6f | 2006-12-28 12:47:47 -0300 | [diff] [blame] | 41 | static int ir_rc5_key_timeout = 200; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 42 | module_param(ir_rc5_key_timeout, int, 0644); |
| 43 | |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 44 | #undef dprintk |
| 45 | #define dprintk(arg...) do { \ |
| 46 | if (ir_debug >= 1) \ |
| 47 | printk(arg); \ |
| 48 | } while (0) |
| 49 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 50 | #define DEVNAME "bttv-input" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 52 | #define MODULE_NAME "bttv" |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /* ---------------------------------------------------------------------- */ |
| 55 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 56 | static void ir_handle_key(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 58 | struct card_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | u32 gpio,data; |
| 60 | |
| 61 | /* read gpio value */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 62 | gpio = bttv_gpio_read(&btv->c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (ir->polling) { |
| 64 | if (ir->last_gpio == gpio) |
| 65 | return; |
| 66 | ir->last_gpio = gpio; |
| 67 | } |
| 68 | |
| 69 | /* extract data */ |
| 70 | data = ir_extract_bits(gpio, ir->mask_keycode); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 71 | 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] | 72 | gpio, data, |
| 73 | ir->polling ? "poll" : "irq", |
| 74 | (gpio & ir->mask_keydown) ? " down" : "", |
| 75 | (gpio & ir->mask_keyup) ? " up" : ""); |
| 76 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 77 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 78 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
Mauro Carvalho Chehab | 8573b74 | 2009-11-27 22:40:22 -0300 | [diff] [blame] | 79 | ir_input_keydown(ir->dev, &ir->ir, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | } else { |
Mauro Carvalho Chehab | b3d9813 | 2008-01-07 09:30:31 -0300 | [diff] [blame] | 81 | /* HACK: Probably, ir->mask_keydown is missing |
| 82 | for this board */ |
| 83 | if (btv->c.type == BTTV_BOARD_WINFAST2000) |
Mauro Carvalho Chehab | 8573b74 | 2009-11-27 22:40:22 -0300 | [diff] [blame] | 84 | ir_input_keydown(ir->dev, &ir->ir, data); |
Mauro Carvalho Chehab | b3d9813 | 2008-01-07 09:30:31 -0300 | [diff] [blame] | 85 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 86 | ir_input_nokey(ir->dev,&ir->ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | } |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 91 | static void ir_enltv_handle_key(struct bttv *btv) |
| 92 | { |
| 93 | struct card_ir *ir = btv->remote; |
| 94 | u32 gpio, data, keyup; |
| 95 | |
| 96 | /* read gpio value */ |
| 97 | gpio = bttv_gpio_read(&btv->c); |
| 98 | |
| 99 | /* extract data */ |
| 100 | data = ir_extract_bits(gpio, ir->mask_keycode); |
| 101 | |
| 102 | /* Check if it is keyup */ |
| 103 | keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0; |
| 104 | |
| 105 | if ((ir->last_gpio & 0x7f) != data) { |
| 106 | dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n", |
| 107 | gpio, data, |
| 108 | (gpio & ir->mask_keyup) ? " up" : "up/down"); |
| 109 | |
Mauro Carvalho Chehab | 8573b74 | 2009-11-27 22:40:22 -0300 | [diff] [blame] | 110 | ir_input_keydown(ir->dev, &ir->ir, data); |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 111 | if (keyup) |
| 112 | ir_input_nokey(ir->dev, &ir->ir); |
| 113 | } else { |
| 114 | if ((ir->last_gpio & 1 << 31) == keyup) |
| 115 | return; |
| 116 | |
| 117 | dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n", |
| 118 | gpio, data, |
| 119 | (gpio & ir->mask_keyup) ? " up" : "down"); |
| 120 | |
| 121 | if (keyup) |
| 122 | ir_input_nokey(ir->dev, &ir->ir); |
| 123 | else |
Mauro Carvalho Chehab | 8573b74 | 2009-11-27 22:40:22 -0300 | [diff] [blame] | 124 | ir_input_keydown(ir->dev, &ir->ir, data); |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | ir->last_gpio = data | keyup; |
| 128 | } |
| 129 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 130 | void bttv_input_irq(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 132 | struct card_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | if (!ir->polling) |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 135 | ir_handle_key(btv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 138 | static void bttv_input_timer(unsigned long data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 140 | struct bttv *btv = (struct bttv*)data; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 141 | struct card_ir *ir = btv->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 143 | if (btv->c.type == BTTV_BOARD_ENLTV_FM_2) |
| 144 | ir_enltv_handle_key(btv); |
| 145 | else |
| 146 | ir_handle_key(btv); |
Dmitry Torokhov | c190495 | 2007-01-02 03:29:48 -0300 | [diff] [blame] | 147 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 150 | /* ---------------------------------------------------------------*/ |
| 151 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 152 | static int bttv_rc5_irq(struct bttv *btv) |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 153 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 154 | struct card_ir *ir = btv->remote; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 155 | struct timeval tv; |
| 156 | u32 gpio; |
| 157 | u32 gap; |
Dmitry Torokhov | c190495 | 2007-01-02 03:29:48 -0300 | [diff] [blame] | 158 | unsigned long current_jiffies; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 159 | |
| 160 | /* read gpio port */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 161 | gpio = bttv_gpio_read(&btv->c); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 162 | |
| 163 | /* remote IRQ? */ |
| 164 | if (!(gpio & 0x20)) |
| 165 | return 0; |
| 166 | |
| 167 | /* get time of bit */ |
| 168 | current_jiffies = jiffies; |
| 169 | do_gettimeofday(&tv); |
| 170 | |
| 171 | /* avoid overflow with gap >1s */ |
| 172 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 173 | gap = 200000; |
| 174 | } else { |
| 175 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 176 | tv.tv_usec - ir->base_time.tv_usec; |
| 177 | } |
| 178 | |
| 179 | /* active code => add bit */ |
| 180 | if (ir->active) { |
| 181 | /* only if in the code (otherwise spurious IRQ or timer |
| 182 | late) */ |
| 183 | if (ir->last_bit < 28) { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 184 | ir->last_bit = (gap - ir_rc5_remote_gap / 2) / |
| 185 | ir_rc5_remote_gap; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 186 | ir->code |= 1 << ir->last_bit; |
| 187 | } |
| 188 | /* starting new code */ |
| 189 | } else { |
| 190 | ir->active = 1; |
| 191 | ir->code = 0; |
| 192 | ir->base_time = tv; |
| 193 | ir->last_bit = 0; |
| 194 | |
Dmitry Torokhov | c190495 | 2007-01-02 03:29:48 -0300 | [diff] [blame] | 195 | mod_timer(&ir->timer_end, |
| 196 | current_jiffies + msecs_to_jiffies(30)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /* toggle GPIO pin 4 to reset the irq */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 200 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
| 201 | bttv_gpio_write(&btv->c, gpio | (1 << 4)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 202 | return 1; |
| 203 | } |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | /* ---------------------------------------------------------------------- */ |
| 206 | |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 207 | static void bttv_ir_start(struct bttv *btv, struct card_ir *ir) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 208 | { |
| 209 | if (ir->polling) { |
Dmitry Torokhov | c190495 | 2007-01-02 03:29:48 -0300 | [diff] [blame] | 210 | setup_timer(&ir->timer, bttv_input_timer, (unsigned long)btv); |
Mauro Carvalho Chehab | fe06fe0 | 2007-07-17 16:36:20 -0300 | [diff] [blame] | 211 | ir->timer.expires = jiffies + msecs_to_jiffies(1000); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 212 | add_timer(&ir->timer); |
| 213 | } else if (ir->rc5_gpio) { |
| 214 | /* set timer_end for code completion */ |
| 215 | init_timer(&ir->timer_end); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 216 | ir->timer_end.function = ir_rc5_timer_end; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 217 | ir->timer_end.data = (unsigned long)ir; |
| 218 | |
| 219 | init_timer(&ir->timer_keyup); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 220 | ir->timer_keyup.function = ir_rc5_timer_keyup; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 221 | ir->timer_keyup.data = (unsigned long)ir; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 222 | ir->shift_by = 1; |
| 223 | ir->start = 3; |
| 224 | ir->addr = 0x0; |
| 225 | ir->rc5_key_timeout = ir_rc5_key_timeout; |
| 226 | ir->rc5_remote_gap = ir_rc5_remote_gap; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
| 230 | static void bttv_ir_stop(struct bttv *btv) |
| 231 | { |
Tejun Heo | 8c71778 | 2010-12-24 16:14:20 +0100 | [diff] [blame^] | 232 | if (btv->remote->polling) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 233 | del_timer_sync(&btv->remote->timer); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 234 | |
| 235 | if (btv->remote->rc5_gpio) { |
| 236 | u32 gpio; |
| 237 | |
| 238 | del_timer_sync(&btv->remote->timer_end); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 239 | |
| 240 | gpio = bttv_gpio_read(&btv->c); |
| 241 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
| 242 | } |
| 243 | } |
| 244 | |
Mauro Carvalho Chehab | c0c4682 | 2010-09-22 23:24:04 -0300 | [diff] [blame] | 245 | /* |
| 246 | * Get_key functions used by I2C remotes |
| 247 | */ |
| 248 | |
| 249 | static int get_key_pv951(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 250 | { |
| 251 | unsigned char b; |
| 252 | |
| 253 | /* poll IR chip */ |
| 254 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
| 255 | dprintk(KERN_INFO DEVNAME ": read error\n"); |
| 256 | return -EIO; |
| 257 | } |
| 258 | |
| 259 | /* ignore 0xaa */ |
| 260 | if (b==0xaa) |
| 261 | return 0; |
| 262 | dprintk(KERN_INFO DEVNAME ": key %02x\n", b); |
| 263 | |
| 264 | *ir_key = b; |
| 265 | *ir_raw = b; |
| 266 | return 1; |
| 267 | } |
| 268 | |
| 269 | /* Instantiate the I2C IR receiver device, if present */ |
| 270 | void __devinit init_bttv_i2c_ir(struct bttv *btv) |
| 271 | { |
| 272 | const unsigned short addr_list[] = { |
| 273 | 0x1a, 0x18, 0x64, 0x30, 0x71, |
| 274 | I2C_CLIENT_END |
| 275 | }; |
| 276 | struct i2c_board_info info; |
| 277 | |
| 278 | if (0 != btv->i2c_rc) |
| 279 | return; |
| 280 | |
| 281 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 282 | memset(&btv->init_data, 0, sizeof(btv->init_data)); |
| 283 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
| 284 | |
| 285 | switch (btv->c.type) { |
| 286 | case BTTV_BOARD_PV951: |
| 287 | btv->init_data.name = "PV951"; |
| 288 | btv->init_data.get_key = get_key_pv951; |
| 289 | btv->init_data.ir_codes = RC_MAP_PV951; |
| 290 | btv->init_data.type = IR_TYPE_OTHER; |
| 291 | info.addr = 0x4b; |
| 292 | break; |
| 293 | default: |
| 294 | /* |
| 295 | * The external IR receiver is at i2c address 0x34 (0x35 for |
| 296 | * reads). Future Hauppauge cards will have an internal |
| 297 | * receiver at 0x30 (0x31 for reads). In theory, both can be |
| 298 | * fitted, and Hauppauge suggest an external overrides an |
| 299 | * internal. |
| 300 | * That's why we probe 0x1a (~0x34) first. CB |
| 301 | */ |
| 302 | |
| 303 | i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); |
| 304 | return; |
| 305 | } |
| 306 | |
| 307 | if (btv->init_data.name) |
| 308 | info.platform_data = &btv->init_data; |
| 309 | i2c_new_device(&btv->c.i2c_adap, &info); |
| 310 | |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | int __devexit fini_bttv_i2c(struct bttv *btv) |
| 315 | { |
| 316 | if (0 != btv->i2c_rc) |
| 317 | return 0; |
| 318 | |
| 319 | return i2c_del_adapter(&btv->c.i2c_adap); |
| 320 | } |
| 321 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 322 | int bttv_input_init(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 324 | struct card_ir *ir; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 325 | char *ir_codes = NULL; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 326 | struct input_dev *input_dev; |
Mauro Carvalho Chehab | 971e829 | 2009-12-14 13:53:37 -0300 | [diff] [blame] | 327 | u64 ir_type = IR_TYPE_OTHER; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 328 | int err = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 330 | if (!btv->has_remote) |
| 331 | return -ENODEV; |
| 332 | |
| 333 | ir = kzalloc(sizeof(*ir),GFP_KERNEL); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 334 | input_dev = input_allocate_device(); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 335 | if (!ir || !input_dev) |
| 336 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
| 338 | /* detect & configure */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 339 | switch (btv->c.type) { |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 340 | case BTTV_BOARD_AVERMEDIA: |
| 341 | case BTTV_BOARD_AVPHONE98: |
| 342 | case BTTV_BOARD_AVERMEDIA98: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 343 | ir_codes = RC_MAP_AVERMEDIA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | ir->mask_keycode = 0xf88000; |
| 345 | ir->mask_keydown = 0x010000; |
| 346 | ir->polling = 50; // ms |
| 347 | break; |
| 348 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 349 | case BTTV_BOARD_AVDVBT_761: |
| 350 | case BTTV_BOARD_AVDVBT_771: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 351 | ir_codes = RC_MAP_AVERMEDIA_DVBT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | ir->mask_keycode = 0x0f00c0; |
| 353 | ir->mask_keydown = 0x000020; |
| 354 | ir->polling = 50; // ms |
| 355 | break; |
| 356 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 357 | case BTTV_BOARD_PXELVWPLTVPAK: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 358 | ir_codes = RC_MAP_PIXELVIEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | ir->mask_keycode = 0x003e00; |
| 360 | ir->mask_keyup = 0x010000; |
| 361 | ir->polling = 50; // ms |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 362 | break; |
Mauro Carvalho Chehab | c663155 | 2006-08-23 11:17:30 -0300 | [diff] [blame] | 363 | case BTTV_BOARD_PV_M4900: |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 364 | case BTTV_BOARD_PV_BT878P_9B: |
| 365 | case BTTV_BOARD_PV_BT878P_PLUS: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 366 | ir_codes = RC_MAP_PIXELVIEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | ir->mask_keycode = 0x001f00; |
| 368 | ir->mask_keyup = 0x008000; |
| 369 | ir->polling = 50; // ms |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 370 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 372 | case BTTV_BOARD_WINFAST2000: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 373 | ir_codes = RC_MAP_WINFAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | ir->mask_keycode = 0x1f8; |
| 375 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 376 | case BTTV_BOARD_MAGICTVIEW061: |
| 377 | case BTTV_BOARD_MAGICTVIEW063: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 378 | ir_codes = RC_MAP_WINFAST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | ir->mask_keycode = 0x0008e000; |
| 380 | ir->mask_keydown = 0x00200000; |
| 381 | break; |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 382 | case BTTV_BOARD_APAC_VIEWCOMP: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 383 | ir_codes = RC_MAP_APAC_VIEWCOMP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | ir->mask_keycode = 0x001f00; |
| 385 | ir->mask_keyup = 0x008000; |
| 386 | ir->polling = 50; // ms |
| 387 | break; |
Mauro Carvalho Chehab | ed44f66 | 2009-08-22 14:43:50 -0300 | [diff] [blame] | 388 | case BTTV_BOARD_ASKEY_CPH03X: |
Mauro Carvalho Chehab | 5a25e84 | 2005-11-08 21:36:52 -0800 | [diff] [blame] | 389 | case BTTV_BOARD_CONCEPTRONIC_CTVFMI2: |
BoyZonder | 4ab2b99b | 2006-02-27 00:08:15 -0300 | [diff] [blame] | 390 | case BTTV_BOARD_CONTVFMI: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 391 | ir_codes = RC_MAP_PIXELVIEW; |
Ricardo Cerqueira | cc9d8d4 | 2005-11-08 21:36:20 -0800 | [diff] [blame] | 392 | ir->mask_keycode = 0x001F00; |
| 393 | ir->mask_keyup = 0x006000; |
| 394 | ir->polling = 50; // ms |
| 395 | break; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 396 | case BTTV_BOARD_NEBULA_DIGITV: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 397 | ir_codes = RC_MAP_NEBULA; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 398 | btv->custom_irq = bttv_rc5_irq; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 399 | ir->rc5_gpio = 1; |
Mauro Carvalho Chehab | 674434c | 2005-12-12 00:37:28 -0800 | [diff] [blame] | 400 | break; |
Julian Calaby | 2d05ae6 | 2006-01-11 19:40:09 -0200 | [diff] [blame] | 401 | case BTTV_BOARD_MACHTV_MAGICTV: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 402 | ir_codes = RC_MAP_APAC_VIEWCOMP; |
Julian Calaby | 2d05ae6 | 2006-01-11 19:40:09 -0200 | [diff] [blame] | 403 | ir->mask_keycode = 0x001F00; |
| 404 | ir->mask_keyup = 0x004000; |
| 405 | ir->polling = 50; /* ms */ |
| 406 | break; |
Mauro Lacy | e80faad | 2008-04-22 14:45:58 -0300 | [diff] [blame] | 407 | case BTTV_BOARD_KOZUMI_KTV_01C: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 408 | ir_codes = RC_MAP_PCTV_SEDNA; |
Mauro Lacy | e80faad | 2008-04-22 14:45:58 -0300 | [diff] [blame] | 409 | ir->mask_keycode = 0x001f00; |
| 410 | ir->mask_keyup = 0x006000; |
| 411 | ir->polling = 50; /* ms */ |
| 412 | break; |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 413 | case BTTV_BOARD_ENLTV_FM_2: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 414 | ir_codes = RC_MAP_ENCORE_ENLTV2; |
Mauro Carvalho Chehab | 7d341a6 | 2008-08-05 10:14:13 -0300 | [diff] [blame] | 415 | ir->mask_keycode = 0x00fd00; |
| 416 | ir->mask_keyup = 0x000080; |
| 417 | ir->polling = 1; /* ms */ |
| 418 | ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c), |
| 419 | ir->mask_keycode); |
| 420 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } |
| 422 | if (NULL == ir_codes) { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 423 | dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type); |
| 424 | err = -ENODEV; |
| 425 | goto err_out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 428 | if (ir->rc5_gpio) { |
| 429 | u32 gpio; |
Trent Piepho | 657de3c | 2006-06-20 00:30:57 -0300 | [diff] [blame] | 430 | /* enable remote irq */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 431 | bttv_gpio_inout(&btv->c, (1 << 4), 1 << 4); |
| 432 | gpio = bttv_gpio_read(&btv->c); |
| 433 | bttv_gpio_write(&btv->c, gpio & ~(1 << 4)); |
| 434 | bttv_gpio_write(&btv->c, gpio | (1 << 4)); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 435 | } else { |
| 436 | /* init hardware-specific stuff */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 437 | bttv_gpio_inout(&btv->c, ir->mask_keycode | ir->mask_keydown, 0); |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
| 440 | /* init input device */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 441 | ir->dev = input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 443 | snprintf(ir->name, sizeof(ir->name), "bttv IR (card=%d)", |
| 444 | btv->c.type); |
| 445 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", |
| 446 | pci_name(btv->c.pci)); |
| 447 | |
Mauro Carvalho Chehab | 579e7d6 | 2009-12-11 11:20:59 -0300 | [diff] [blame] | 448 | err = ir_input_init(input_dev, &ir->ir, ir_type); |
Mauro Carvalho Chehab | 055cd55 | 2009-11-29 08:19:59 -0300 | [diff] [blame] | 449 | if (err < 0) |
| 450 | goto err_out_free; |
| 451 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 452 | input_dev->name = ir->name; |
| 453 | input_dev->phys = ir->phys; |
| 454 | input_dev->id.bustype = BUS_PCI; |
| 455 | input_dev->id.version = 1; |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 456 | if (btv->c.pci->subsystem_vendor) { |
| 457 | input_dev->id.vendor = btv->c.pci->subsystem_vendor; |
| 458 | input_dev->id.product = btv->c.pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } else { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 460 | input_dev->id.vendor = btv->c.pci->vendor; |
| 461 | input_dev->id.product = btv->c.pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | } |
Dmitry Torokhov | 2c8a3a3 | 2007-07-16 09:28:15 -0300 | [diff] [blame] | 463 | input_dev->dev.parent = &btv->c.pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 465 | btv->remote = ir; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 466 | bttv_ir_start(btv, ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | /* all done */ |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 469 | err = ir_input_register(btv->remote->dev, ir_codes, NULL, MODULE_NAME); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 470 | if (err) |
| 471 | goto err_out_stop; |
Mark Weaver | 6c6c0b2 | 2005-11-13 16:07:52 -0800 | [diff] [blame] | 472 | |
| 473 | /* the remote isn't as bouncy as a keyboard */ |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 474 | ir->dev->rep[REP_DELAY] = repeat_delay; |
| 475 | ir->dev->rep[REP_PERIOD] = repeat_period; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
| 477 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 478 | |
| 479 | err_out_stop: |
| 480 | bttv_ir_stop(btv); |
| 481 | btv->remote = NULL; |
| 482 | err_out_free: |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 483 | kfree(ir); |
| 484 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | } |
| 486 | |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 487 | void bttv_input_fini(struct bttv *btv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 489 | if (btv->remote == NULL) |
| 490 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 492 | bttv_ir_stop(btv); |
Mauro Carvalho Chehab | 38ef6aa | 2009-12-11 09:47:42 -0300 | [diff] [blame] | 493 | ir_input_unregister(btv->remote->dev); |
Ricardo Cerqueira | 4abdfed | 2006-01-09 15:25:25 -0200 | [diff] [blame] | 494 | kfree(btv->remote); |
| 495 | btv->remote = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |