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 | * handle saa7134 IR remotes via linux kernel input layer. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/input.h> |
| 26 | |
| 27 | #include "saa7134-reg.h" |
| 28 | #include "saa7134.h" |
| 29 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 30 | static unsigned int disable_ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | module_param(disable_ir, int, 0444); |
| 32 | MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); |
| 33 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 34 | static unsigned int ir_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | module_param(ir_debug, int, 0644); |
| 36 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); |
| 37 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 38 | static int pinnacle_remote; |
Sylvain Pasche | b93eedb | 2006-03-25 23:14:42 -0300 | [diff] [blame] | 39 | module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ |
| 40 | MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); |
| 41 | |
Adrian Bunk | c408a6f | 2006-12-28 12:47:47 -0300 | [diff] [blame] | 42 | static int ir_rc5_remote_gap = 885; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 43 | module_param(ir_rc5_remote_gap, int, 0644); |
Adrian Bunk | c408a6f | 2006-12-28 12:47:47 -0300 | [diff] [blame] | 44 | static int ir_rc5_key_timeout = 115; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 45 | module_param(ir_rc5_key_timeout, int, 0644); |
| 46 | |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 47 | static int repeat_delay = 500; |
| 48 | module_param(repeat_delay, int, 0644); |
| 49 | MODULE_PARM_DESC(repeat_delay, "delay before key repeat started"); |
| 50 | static int repeat_period = 33; |
| 51 | module_param(repeat_period, int, 0644); |
Joe Perches | ac9bb7f | 2007-11-20 09:00:35 -0300 | [diff] [blame] | 52 | MODULE_PARM_DESC(repeat_period, "repeat period between " |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 53 | "keypresses when key is down"); |
| 54 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 55 | static unsigned int disable_other_ir; |
| 56 | module_param(disable_other_ir, int, 0644); |
| 57 | MODULE_PARM_DESC(disable_other_ir, "disable full codes of " |
| 58 | "alternative remotes from other manufacturers"); |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define dprintk(fmt, arg...) if (ir_debug) \ |
| 61 | printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 62 | #define i2cdprintk(fmt, arg...) if (ir_debug) \ |
| 63 | printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 65 | /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 66 | static int saa7134_rc5_irq(struct saa7134_dev *dev); |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 67 | static int saa7134_nec_irq(struct saa7134_dev *dev); |
| 68 | static void nec_task(unsigned long data); |
| 69 | static void saa7134_nec_timer(unsigned long data); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 70 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 71 | /* -------------------- GPIO generic keycode builder -------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | static int build_key(struct saa7134_dev *dev) |
| 74 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 75 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | u32 gpio, data; |
| 77 | |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 78 | /* here comes the additional handshake steps for some cards */ |
| 79 | switch (dev->board) { |
| 80 | case SAA7134_BOARD_GOTVIEW_7135: |
| 81 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80); |
| 82 | saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80); |
| 83 | break; |
| 84 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 86 | saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); |
| 87 | saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); |
| 88 | |
| 89 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 90 | if (ir->polling) { |
| 91 | if (ir->last_gpio == gpio) |
| 92 | return 0; |
| 93 | ir->last_gpio = gpio; |
| 94 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 96 | data = ir_extract_bits(gpio, ir->mask_keycode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | dprintk("build_key gpio=0x%x mask=0x%x data=%d\n", |
| 98 | gpio, ir->mask_keycode, data); |
| 99 | |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 100 | if (ir->polling) { |
| 101 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 102 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
| 103 | ir_input_keydown(ir->dev, &ir->ir, data, data); |
| 104 | } else { |
| 105 | ir_input_nokey(ir->dev, &ir->ir); |
| 106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 108 | else { /* IRQ driven mode - handle key press and release in one go */ |
| 109 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 110 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
| 111 | ir_input_keydown(ir->dev, &ir->ir, data, data); |
| 112 | ir_input_nokey(ir->dev, &ir->ir); |
| 113 | } |
| 114 | } |
| 115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | return 0; |
| 117 | } |
| 118 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 119 | /* --------------------- Chip specific I2C key builders ----------------- */ |
| 120 | |
| 121 | static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 122 | { |
| 123 | unsigned char b; |
| 124 | |
| 125 | /* poll IR chip */ |
| 126 | if (1 != i2c_master_recv(&ir->c,&b,1)) { |
| 127 | i2cdprintk("read error\n"); |
| 128 | return -EIO; |
| 129 | } |
| 130 | |
| 131 | /* no button press */ |
| 132 | if (b==0) |
| 133 | return 0; |
| 134 | |
| 135 | /* repeating */ |
| 136 | if (b & 0x80) |
| 137 | return 1; |
| 138 | |
| 139 | *ir_key = b; |
| 140 | *ir_raw = b; |
| 141 | return 1; |
| 142 | } |
| 143 | |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 144 | static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 145 | { |
| 146 | unsigned char buf[5], cod4, code3, code4; |
| 147 | |
| 148 | /* poll IR chip */ |
| 149 | if (5 != i2c_master_recv(&ir->c,buf,5)) |
| 150 | return -EIO; |
| 151 | |
| 152 | cod4 = buf[4]; |
| 153 | code4 = (cod4 >> 2); |
| 154 | code3 = buf[3]; |
| 155 | if (code3 == 0) |
| 156 | /* no key pressed */ |
| 157 | return 0; |
| 158 | |
| 159 | /* return key */ |
| 160 | *ir_key = code4; |
| 161 | *ir_raw = code4; |
| 162 | return 1; |
| 163 | } |
| 164 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 165 | |
| 166 | static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 167 | { |
| 168 | unsigned char data[12]; |
| 169 | u32 gpio; |
| 170 | |
| 171 | struct saa7134_dev *dev = ir->c.adapter->algo_data; |
| 172 | |
| 173 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 174 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 175 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 176 | |
| 177 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 178 | |
Mauro Carvalho Chehab | 616f887 | 2008-01-07 05:18:36 -0300 | [diff] [blame] | 179 | if (0x400000 & ~gpio) |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 180 | return 0; /* No button press */ |
| 181 | |
| 182 | ir->c.addr = 0x5a >> 1; |
| 183 | |
| 184 | if (12 != i2c_master_recv(&ir->c, data, 12)) { |
| 185 | i2cdprintk("read error\n"); |
| 186 | return -EIO; |
| 187 | } |
| 188 | /* IR of this card normally decode signals NEC-standard from |
| 189 | * - Sven IHOO MT 5.1R remote. xxyye718 |
| 190 | * - Sven DVD HD-10xx remote. xxyyf708 |
| 191 | * - BBK ... |
| 192 | * - mayby others |
| 193 | * So, skip not our, if disable full codes mode. |
| 194 | */ |
| 195 | if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir) |
| 196 | return 0; |
| 197 | |
| 198 | *ir_key = data[9]; |
| 199 | *ir_raw = data[9]; |
| 200 | |
| 201 | return 1; |
| 202 | } |
| 203 | |
Mauro Carvalho Chehab | 1c22dad | 2008-07-17 22:31:29 -0300 | [diff] [blame] | 204 | /* Common (grey or coloured) pinnacle PCTV remote handling |
| 205 | * |
| 206 | */ |
| 207 | static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw, |
| 208 | int parity_offset, int marker, int code_modulo) |
| 209 | { |
| 210 | unsigned char b[4]; |
| 211 | unsigned int start = 0,parity = 0,code = 0; |
| 212 | |
| 213 | /* poll IR chip */ |
| 214 | if (4 != i2c_master_recv(&ir->c, b, 4)) { |
| 215 | i2cdprintk("read error\n"); |
| 216 | return -EIO; |
| 217 | } |
| 218 | |
| 219 | for (start = 0; start < ARRAY_SIZE(b); start++) { |
| 220 | if (b[start] == marker) { |
| 221 | code=b[(start+parity_offset + 1) % 4]; |
| 222 | parity=b[(start+parity_offset) % 4]; |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | /* Empty Request */ |
| 227 | if (parity == 0) |
| 228 | return 0; |
| 229 | |
| 230 | /* Repeating... */ |
| 231 | if (ir->old == parity) |
| 232 | return 0; |
| 233 | |
| 234 | ir->old = parity; |
| 235 | |
| 236 | /* drop special codes when a key is held down a long time for the grey controller |
| 237 | In this case, the second bit of the code is asserted */ |
| 238 | if (marker == 0xfe && (code & 0x40)) |
| 239 | return 0; |
| 240 | |
| 241 | code %= code_modulo; |
| 242 | |
| 243 | *ir_raw = code; |
| 244 | *ir_key = code; |
| 245 | |
| 246 | i2cdprintk("Pinnacle PCTV key %02x\n", code); |
| 247 | |
| 248 | return 1; |
| 249 | } |
| 250 | |
| 251 | /* The grey pinnacle PCTV remote |
| 252 | * |
| 253 | * There are one issue with this remote: |
| 254 | * - I2c packet does not change when the same key is pressed quickly. The workaround |
| 255 | * is to hold down each key for about half a second, so that another code is generated |
| 256 | * in the i2c packet, and the function can distinguish key presses. |
| 257 | * |
| 258 | * Sylvain Pasche <sylvain.pasche@gmail.com> |
| 259 | */ |
| 260 | static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 261 | { |
| 262 | |
| 263 | return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff); |
| 264 | } |
| 265 | |
| 266 | |
| 267 | /* The new pinnacle PCTV remote (with the colored buttons) |
| 268 | * |
| 269 | * Ricardo Cerqueira <v4l@cerqueira.org> |
| 270 | */ |
| 271 | static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 272 | { |
| 273 | /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE |
| 274 | * |
| 275 | * this is the only value that results in 42 unique |
| 276 | * codes < 128 |
| 277 | */ |
| 278 | |
| 279 | return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88); |
| 280 | } |
| 281 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | void saa7134_input_irq(struct saa7134_dev *dev) |
| 283 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 284 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 286 | if (ir->nec_gpio) { |
| 287 | saa7134_nec_irq(dev); |
| 288 | } else if (!ir->polling && !ir->rc5_gpio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | build_key(dev); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 290 | } else if (ir->rc5_gpio) { |
| 291 | saa7134_rc5_irq(dev); |
| 292 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | static void saa7134_input_timer(unsigned long data) |
| 296 | { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 297 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 298 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | |
| 300 | build_key(dev); |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 301 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 304 | void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 305 | { |
| 306 | if (ir->polling) { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 307 | setup_timer(&ir->timer, saa7134_input_timer, |
| 308 | (unsigned long)dev); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 309 | ir->timer.expires = jiffies + HZ; |
| 310 | add_timer(&ir->timer); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 311 | } else if (ir->rc5_gpio) { |
| 312 | /* set timer_end for code completion */ |
| 313 | init_timer(&ir->timer_end); |
| 314 | ir->timer_end.function = ir_rc5_timer_end; |
| 315 | ir->timer_end.data = (unsigned long)ir; |
| 316 | init_timer(&ir->timer_keyup); |
| 317 | ir->timer_keyup.function = ir_rc5_timer_keyup; |
| 318 | ir->timer_keyup.data = (unsigned long)ir; |
| 319 | ir->shift_by = 2; |
| 320 | ir->start = 0x2; |
| 321 | ir->addr = 0x17; |
| 322 | ir->rc5_key_timeout = ir_rc5_key_timeout; |
| 323 | ir->rc5_remote_gap = ir_rc5_remote_gap; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 324 | } else if (ir->nec_gpio) { |
| 325 | setup_timer(&ir->timer_keyup, saa7134_nec_timer, |
| 326 | (unsigned long)dev); |
| 327 | tasklet_init(&ir->tlet, nec_task, (unsigned long)dev); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 331 | void saa7134_ir_stop(struct saa7134_dev *dev) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 332 | { |
| 333 | if (dev->remote->polling) |
| 334 | del_timer_sync(&dev->remote->timer); |
| 335 | } |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | int saa7134_input_init1(struct saa7134_dev *dev) |
| 338 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 339 | struct card_ir *ir; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 340 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | IR_KEYTAB_TYPE *ir_codes = NULL; |
| 342 | u32 mask_keycode = 0; |
| 343 | u32 mask_keydown = 0; |
| 344 | u32 mask_keyup = 0; |
| 345 | int polling = 0; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 346 | int rc5_gpio = 0; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 347 | int nec_gpio = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | int ir_type = IR_TYPE_OTHER; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 349 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Ricardo Cerqueira | cb2444d | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 351 | if (dev->has_remote != SAA7134_REMOTE_GPIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return -ENODEV; |
| 353 | if (disable_ir) |
| 354 | return -ENODEV; |
| 355 | |
| 356 | /* detect & configure */ |
| 357 | switch (dev->board) { |
| 358 | case SAA7134_BOARD_FLYVIDEO2000: |
| 359 | case SAA7134_BOARD_FLYVIDEO3000: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 360 | case SAA7134_BOARD_FLYTVPLATINUM_FM: |
Arnaud Patard | 6af90ab | 2005-11-08 21:36:55 -0800 | [diff] [blame] | 361 | case SAA7134_BOARD_FLYTVPLATINUM_MINI2: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 362 | ir_codes = ir_codes_flyvideo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | mask_keycode = 0xEC00000; |
| 364 | mask_keydown = 0x0040000; |
| 365 | break; |
| 366 | case SAA7134_BOARD_CINERGY400: |
| 367 | case SAA7134_BOARD_CINERGY600: |
| 368 | case SAA7134_BOARD_CINERGY600_MK3: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 369 | ir_codes = ir_codes_cinergy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | mask_keycode = 0x00003f; |
| 371 | mask_keyup = 0x040000; |
| 372 | break; |
| 373 | case SAA7134_BOARD_ECS_TVP3XP: |
| 374 | case SAA7134_BOARD_ECS_TVP3XP_4CB5: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 375 | ir_codes = ir_codes_eztv; |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 376 | mask_keycode = 0x00017c; |
| 377 | mask_keyup = 0x000002; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | polling = 50; // ms |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 379 | break; |
| 380 | case SAA7134_BOARD_KWORLD_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | case SAA7134_BOARD_AVACSSMARTTV: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 382 | ir_codes = ir_codes_pixelview; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | mask_keycode = 0x00001F; |
| 384 | mask_keyup = 0x000020; |
| 385 | polling = 50; // ms |
| 386 | break; |
| 387 | case SAA7134_BOARD_MD2819: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 388 | case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | case SAA7134_BOARD_AVERMEDIA_305: |
| 390 | case SAA7134_BOARD_AVERMEDIA_307: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 391 | case SAA7134_BOARD_AVERMEDIA_STUDIO_305: |
| 392 | case SAA7134_BOARD_AVERMEDIA_STUDIO_307: |
Mikhail Fedotov | 3ac706d | 2006-10-06 20:23:47 -0300 | [diff] [blame] | 393 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 394 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM: |
Albert Graham | d2761f2 | 2007-12-09 09:44:38 -0300 | [diff] [blame] | 395 | case SAA7134_BOARD_AVERMEDIA_M102: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 396 | ir_codes = ir_codes_avermedia; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | mask_keycode = 0x0007C8; |
| 398 | mask_keydown = 0x000010; |
| 399 | polling = 50; // ms |
| 400 | /* Set GPIO pin2 to high to enable the IR controller */ |
| 401 | saa_setb(SAA7134_GPIO_GPMODE0, 0x4); |
| 402 | saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); |
| 403 | break; |
Mauro Carvalho Chehab | 36f6bb9 | 2008-06-26 17:03:00 -0300 | [diff] [blame^] | 404 | case SAA7134_BOARD_AVERMEDIA_M135A: |
| 405 | ir_codes = ir_codes_avermedia_m135a; |
| 406 | mask_keydown = 0x0040000; |
| 407 | mask_keycode = 0x00013f; |
| 408 | nec_gpio = 1; |
| 409 | break; |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 410 | case SAA7134_BOARD_AVERMEDIA_777: |
pasky@ucw.cz | 29e0f1a | 2006-11-12 14:23:32 -0300 | [diff] [blame] | 411 | case SAA7134_BOARD_AVERMEDIA_A16AR: |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 412 | ir_codes = ir_codes_avermedia; |
| 413 | mask_keycode = 0x02F200; |
| 414 | mask_keydown = 0x000400; |
| 415 | polling = 50; // ms |
| 416 | /* Without this we won't receive key up events */ |
| 417 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 418 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
Linus Torvalds | 4dd7406 | 2006-11-13 09:50:11 -0800 | [diff] [blame] | 419 | break; |
Tim Farrington | 6e501a3 | 2008-06-15 13:33:42 -0300 | [diff] [blame] | 420 | case SAA7134_BOARD_AVERMEDIA_A16D: |
| 421 | ir_codes = ir_codes_avermedia_a16d; |
| 422 | mask_keycode = 0x02F200; |
| 423 | mask_keydown = 0x000400; |
| 424 | polling = 50; /* ms */ |
| 425 | /* Without this we won't receive key up events */ |
| 426 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 427 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
| 428 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 429 | case SAA7134_BOARD_KWORLD_TERMINATOR: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 430 | ir_codes = ir_codes_pixelview; |
James R. Webb | dc2286c | 2005-11-08 21:37:00 -0800 | [diff] [blame] | 431 | mask_keycode = 0x00001f; |
| 432 | mask_keyup = 0x000060; |
| 433 | polling = 50; // ms |
| 434 | break; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 435 | case SAA7134_BOARD_MANLI_MTV001: |
| 436 | case SAA7134_BOARD_MANLI_MTV002: |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 437 | ir_codes = ir_codes_manli; |
| 438 | mask_keycode = 0x001f00; |
| 439 | mask_keyup = 0x004000; |
| 440 | polling = 50; /* ms */ |
| 441 | break; |
Nickolay V. Shmyrev | a8ff417 | 2005-11-08 21:36:16 -0800 | [diff] [blame] | 442 | case SAA7134_BOARD_BEHOLD_409FM: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 443 | case SAA7134_BOARD_BEHOLD_401: |
| 444 | case SAA7134_BOARD_BEHOLD_403: |
| 445 | case SAA7134_BOARD_BEHOLD_403FM: |
| 446 | case SAA7134_BOARD_BEHOLD_405: |
| 447 | case SAA7134_BOARD_BEHOLD_405FM: |
| 448 | case SAA7134_BOARD_BEHOLD_407: |
| 449 | case SAA7134_BOARD_BEHOLD_407FM: |
| 450 | case SAA7134_BOARD_BEHOLD_409: |
| 451 | case SAA7134_BOARD_BEHOLD_505FM: |
| 452 | case SAA7134_BOARD_BEHOLD_507_9FM: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 453 | ir_codes = ir_codes_manli; |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 454 | mask_keycode = 0x003f00; |
| 455 | mask_keyup = 0x004000; |
| 456 | polling = 50; /* ms */ |
| 457 | break; |
| 458 | case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: |
| 459 | ir_codes = ir_codes_behold_columbus; |
| 460 | mask_keycode = 0x003f00; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 461 | mask_keyup = 0x004000; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 462 | polling = 50; // ms |
| 463 | break; |
Ricardo Cerqueira | 17ce1ff | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 464 | case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 465 | ir_codes = ir_codes_pctv_sedna; |
Pavel Mihaylov | c3d9319 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 466 | mask_keycode = 0x001f00; |
| 467 | mask_keyup = 0x004000; |
| 468 | polling = 50; // ms |
| 469 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 470 | case SAA7134_BOARD_GOTVIEW_7135: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 471 | ir_codes = ir_codes_gotview7135; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 472 | mask_keycode = 0x0003CC; |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 473 | mask_keydown = 0x000010; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 474 | polling = 5; /* ms */ |
| 475 | saa_setb(SAA7134_GPIO_GPMODE1, 0x80); |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 476 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | case SAA7134_BOARD_VIDEOMATE_TV_PVR: |
Nickolay V. Shmyrev | 2a9a9a8 | 2006-01-09 15:25:33 -0200 | [diff] [blame] | 478 | case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 479 | case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 480 | ir_codes = ir_codes_videomate_tv_pvr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | mask_keycode = 0x00003F; |
| 482 | mask_keyup = 0x400000; |
| 483 | polling = 50; // ms |
| 484 | break; |
Michal Majchrowicz | b04c1ba | 2006-09-13 16:42:42 -0300 | [diff] [blame] | 485 | case SAA7134_BOARD_PROTEUS_2309: |
| 486 | ir_codes = ir_codes_proteus_2309; |
| 487 | mask_keycode = 0x00007F; |
| 488 | mask_keyup = 0x000080; |
| 489 | polling = 50; // ms |
| 490 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 491 | case SAA7134_BOARD_VIDEOMATE_DVBT_300: |
| 492 | case SAA7134_BOARD_VIDEOMATE_DVBT_200: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 493 | ir_codes = ir_codes_videomate_tv_pvr; |
Nickolay V. Shmyrev | fea095f | 2005-11-08 21:36:47 -0800 | [diff] [blame] | 494 | mask_keycode = 0x003F00; |
| 495 | mask_keyup = 0x040000; |
| 496 | break; |
James Le Cuirot | f5c965a | 2007-07-02 12:53:25 -0300 | [diff] [blame] | 497 | case SAA7134_BOARD_FLYDVBS_LR300: |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 498 | case SAA7134_BOARD_FLYDVBT_LR301: |
Rudo Thomas | a802917 | 2006-02-27 00:08:46 -0300 | [diff] [blame] | 499 | case SAA7134_BOARD_FLYDVBTDUO: |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 500 | ir_codes = ir_codes_flydvb; |
| 501 | mask_keycode = 0x0001F00; |
| 502 | mask_keydown = 0x0040000; |
| 503 | break; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 504 | case SAA7134_BOARD_ASUSTeK_P7131_DUAL: |
Ed Vipas | 904ab88 | 2007-03-29 18:32:49 -0300 | [diff] [blame] | 505 | case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: |
Hermann Pitton | 0b17d0e | 2008-07-12 12:27:59 -0300 | [diff] [blame] | 506 | case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 507 | ir_codes = ir_codes_asus_pc39; |
| 508 | mask_keydown = 0x0040000; |
| 509 | rc5_gpio = 1; |
| 510 | break; |
Juan Pablo Sormani | c36c459 | 2006-12-27 12:46:36 -0300 | [diff] [blame] | 511 | case SAA7134_BOARD_ENCORE_ENLTV: |
| 512 | case SAA7134_BOARD_ENCORE_ENLTV_FM: |
| 513 | ir_codes = ir_codes_encore_enltv; |
| 514 | mask_keycode = 0x00007f; |
| 515 | mask_keyup = 0x040000; |
| 516 | polling = 50; // ms |
| 517 | break; |
Mauro Carvalho Chehab | bf1ece6 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 518 | case SAA7134_BOARD_ENCORE_ENLTV_FM53: |
| 519 | ir_codes = ir_codes_encore_enltv_fm53; |
| 520 | mask_keydown = 0x0040000; |
| 521 | mask_keycode = 0x00007f; |
| 522 | nec_gpio = 1; |
| 523 | break; |
Tony Wan | 480f75a | 2007-05-11 11:33:50 -0300 | [diff] [blame] | 524 | case SAA7134_BOARD_10MOONSTVMASTER3: |
| 525 | ir_codes = ir_codes_encore_enltv; |
| 526 | mask_keycode = 0x5f80000; |
| 527 | mask_keyup = 0x8000000; |
| 528 | polling = 50; //ms |
| 529 | break; |
Adrian Pardini | f0ba356 | 2008-02-11 12:40:53 -0300 | [diff] [blame] | 530 | case SAA7134_BOARD_GENIUS_TVGO_A11MCE: |
| 531 | ir_codes = ir_codes_genius_tvgo_a11mce; |
| 532 | mask_keycode = 0xff; |
| 533 | mask_keydown = 0xf00000; |
| 534 | polling = 50; /* ms */ |
| 535 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | } |
| 537 | if (NULL == ir_codes) { |
| 538 | printk("%s: Oops: IR config error [card=%d]\n", |
| 539 | dev->name, dev->board); |
| 540 | return -ENODEV; |
| 541 | } |
| 542 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 543 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
| 544 | input_dev = input_allocate_device(); |
| 545 | if (!ir || !input_dev) { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 546 | err = -ENOMEM; |
| 547 | goto err_out_free; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 548 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Dmitry Torokhov | d271d1c | 2005-11-20 00:56:54 -0500 | [diff] [blame] | 550 | ir->dev = input_dev; |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* init hardware-specific stuff */ |
| 553 | ir->mask_keycode = mask_keycode; |
| 554 | ir->mask_keydown = mask_keydown; |
| 555 | ir->mask_keyup = mask_keyup; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 556 | ir->polling = polling; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 557 | ir->rc5_gpio = rc5_gpio; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 558 | ir->nec_gpio = nec_gpio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | |
| 560 | /* init input device */ |
| 561 | snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", |
| 562 | saa7134_boards[dev->board].name); |
| 563 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", |
| 564 | pci_name(dev->pci)); |
| 565 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 566 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 567 | input_dev->name = ir->name; |
| 568 | input_dev->phys = ir->phys; |
| 569 | input_dev->id.bustype = BUS_PCI; |
| 570 | input_dev->id.version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | if (dev->pci->subsystem_vendor) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 572 | input_dev->id.vendor = dev->pci->subsystem_vendor; |
| 573 | input_dev->id.product = dev->pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 575 | input_dev->id.vendor = dev->pci->vendor; |
| 576 | input_dev->id.product = dev->pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
Dmitry Torokhov | 2c8a3a3 | 2007-07-16 09:28:15 -0300 | [diff] [blame] | 578 | input_dev->dev.parent = &dev->pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | dev->remote = ir; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 581 | saa7134_ir_start(dev, ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 583 | err = input_register_device(ir->dev); |
| 584 | if (err) |
| 585 | goto err_out_stop; |
| 586 | |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 587 | /* the remote isn't as bouncy as a keyboard */ |
| 588 | ir->dev->rep[REP_DELAY] = repeat_delay; |
| 589 | ir->dev->rep[REP_PERIOD] = repeat_period; |
| 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 592 | |
| 593 | err_out_stop: |
| 594 | saa7134_ir_stop(dev); |
| 595 | dev->remote = NULL; |
| 596 | err_out_free: |
| 597 | input_free_device(input_dev); |
| 598 | kfree(ir); |
| 599 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | void saa7134_input_fini(struct saa7134_dev *dev) |
| 603 | { |
| 604 | if (NULL == dev->remote) |
| 605 | return; |
| 606 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 607 | saa7134_ir_stop(dev); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 608 | input_unregister_device(dev->remote->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | kfree(dev->remote); |
| 610 | dev->remote = NULL; |
| 611 | } |
| 612 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 613 | void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir) |
| 614 | { |
| 615 | if (disable_ir) { |
Ricardo Cerqueira | cb2444d | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 616 | dprintk("Found supported i2c remote, but IR has been disabled\n"); |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 617 | ir->get_key=NULL; |
| 618 | return; |
| 619 | } |
| 620 | |
| 621 | switch (dev->board) { |
| 622 | case SAA7134_BOARD_PINNACLE_PCTV_110i: |
Hartmut Hackmann | eb591af | 2006-10-12 19:46:16 -0300 | [diff] [blame] | 623 | case SAA7134_BOARD_PINNACLE_PCTV_310i: |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 624 | snprintf(ir->c.name, sizeof(ir->c.name), "Pinnacle PCTV"); |
Sylvain Pasche | b93eedb | 2006-03-25 23:14:42 -0300 | [diff] [blame] | 625 | if (pinnacle_remote == 0) { |
| 626 | ir->get_key = get_key_pinnacle_color; |
| 627 | ir->ir_codes = ir_codes_pinnacle_color; |
| 628 | } else { |
| 629 | ir->get_key = get_key_pinnacle_grey; |
| 630 | ir->ir_codes = ir_codes_pinnacle_grey; |
| 631 | } |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 632 | break; |
| 633 | case SAA7134_BOARD_UPMOST_PURPLE_TV: |
| 634 | snprintf(ir->c.name, sizeof(ir->c.name), "Purple TV"); |
| 635 | ir->get_key = get_key_purpletv; |
| 636 | ir->ir_codes = ir_codes_purpletv; |
| 637 | break; |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 638 | case SAA7134_BOARD_HAUPPAUGE_HVR1110: |
| 639 | snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110"); |
| 640 | ir->get_key = get_key_hvr1110; |
| 641 | ir->ir_codes = ir_codes_hauppauge_new; |
| 642 | break; |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 643 | case SAA7134_BOARD_BEHOLD_607_9FM: |
| 644 | case SAA7134_BOARD_BEHOLD_M6: |
Dmitry Belimov | 878cf2a | 2008-06-10 14:22:00 -0300 | [diff] [blame] | 645 | case SAA7134_BOARD_BEHOLD_M63: |
| 646 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: |
Igor Kuznetsov | 0250527 | 2008-04-26 14:53:48 -0300 | [diff] [blame] | 647 | case SAA7134_BOARD_BEHOLD_H6: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 648 | snprintf(ir->c.name, sizeof(ir->c.name), "BeholdTV"); |
| 649 | ir->get_key = get_key_beholdm6xx; |
| 650 | ir->ir_codes = ir_codes_behold; |
| 651 | break; |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 652 | default: |
| 653 | dprintk("Shouldn't get here: Unknown board %x for I2C IR?\n",dev->board); |
| 654 | break; |
| 655 | } |
| 656 | |
| 657 | } |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 658 | |
| 659 | static int saa7134_rc5_irq(struct saa7134_dev *dev) |
| 660 | { |
| 661 | struct card_ir *ir = dev->remote; |
| 662 | struct timeval tv; |
| 663 | u32 gap; |
| 664 | unsigned long current_jiffies, timeout; |
| 665 | |
| 666 | /* get time of bit */ |
| 667 | current_jiffies = jiffies; |
| 668 | do_gettimeofday(&tv); |
| 669 | |
| 670 | /* avoid overflow with gap >1s */ |
| 671 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 672 | gap = 200000; |
| 673 | } else { |
| 674 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 675 | tv.tv_usec - ir->base_time.tv_usec; |
| 676 | } |
| 677 | |
| 678 | /* active code => add bit */ |
| 679 | if (ir->active) { |
| 680 | /* only if in the code (otherwise spurious IRQ or timer |
| 681 | late) */ |
| 682 | if (ir->last_bit < 28) { |
| 683 | ir->last_bit = (gap - ir_rc5_remote_gap / 2) / |
| 684 | ir_rc5_remote_gap; |
| 685 | ir->code |= 1 << ir->last_bit; |
| 686 | } |
| 687 | /* starting new code */ |
| 688 | } else { |
| 689 | ir->active = 1; |
| 690 | ir->code = 0; |
| 691 | ir->base_time = tv; |
| 692 | ir->last_bit = 0; |
| 693 | |
| 694 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; |
| 695 | mod_timer(&ir->timer_end, timeout); |
| 696 | } |
| 697 | |
| 698 | return 1; |
| 699 | } |
| 700 | |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 701 | |
| 702 | /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms |
| 703 | The first pulse (start) has 9 + 4.5 ms |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | */ |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 705 | |
| 706 | static void saa7134_nec_timer(unsigned long data) |
| 707 | { |
| 708 | struct saa7134_dev *dev = (struct saa7134_dev *) data; |
| 709 | struct card_ir *ir = dev->remote; |
| 710 | |
| 711 | dprintk("Cancel key repeat\n"); |
| 712 | |
| 713 | ir_input_nokey(ir->dev, &ir->ir); |
| 714 | } |
| 715 | |
| 716 | static void nec_task(unsigned long data) |
| 717 | { |
| 718 | struct saa7134_dev *dev = (struct saa7134_dev *) data; |
| 719 | struct card_ir *ir; |
| 720 | struct timeval tv; |
| 721 | int count, pulse, oldpulse, gap; |
| 722 | u32 ircode = 0, not_code = 0; |
| 723 | int ngap = 0; |
| 724 | |
| 725 | if (!data) { |
| 726 | printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n"); |
| 727 | /* GPIO will be kept disabled */ |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | ir = dev->remote; |
| 732 | |
| 733 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 734 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 735 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 736 | |
| 737 | oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; |
| 738 | pulse = oldpulse; |
| 739 | |
| 740 | do_gettimeofday(&tv); |
| 741 | ir->base_time = tv; |
| 742 | |
| 743 | /* Decode NEC pulsecode. This code can take up to 76.5 ms to run. |
| 744 | Unfortunately, using IRQ to decode pulse didn't work, since it uses |
| 745 | a pulse train of 38KHz. This means one pulse on each 52 us |
| 746 | */ |
| 747 | do { |
| 748 | /* Wait until the end of pulse/space or 5 ms */ |
| 749 | for (count = 0; count < 500; count++) { |
| 750 | udelay(10); |
| 751 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 752 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 753 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 754 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) |
| 755 | & ir->mask_keydown; |
| 756 | if (pulse != oldpulse) |
| 757 | break; |
| 758 | } |
| 759 | |
| 760 | do_gettimeofday(&tv); |
| 761 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 762 | tv.tv_usec - ir->base_time.tv_usec; |
| 763 | |
| 764 | if (!pulse) { |
| 765 | /* Bit 0 has 560 us, while bit 1 has 1120 us. |
| 766 | Do something only if bit == 1 |
| 767 | */ |
| 768 | if (ngap && (gap > 560 + 280)) { |
| 769 | unsigned int shift = ngap - 1; |
| 770 | |
| 771 | /* Address first, then command */ |
| 772 | if (shift < 8) { |
| 773 | shift += 8; |
| 774 | ircode |= 1 << shift; |
| 775 | } else if (shift < 16) { |
| 776 | not_code |= 1 << shift; |
| 777 | } else if (shift < 24) { |
| 778 | shift -= 16; |
| 779 | ircode |= 1 << shift; |
| 780 | } else { |
| 781 | shift -= 24; |
| 782 | not_code |= 1 << shift; |
| 783 | } |
| 784 | } |
| 785 | ngap++; |
| 786 | } |
| 787 | |
| 788 | |
| 789 | ir->base_time = tv; |
| 790 | |
| 791 | /* TIMEOUT - Long pulse */ |
| 792 | if (gap >= 5000) |
| 793 | break; |
| 794 | oldpulse = pulse; |
| 795 | } while (ngap < 32); |
| 796 | |
| 797 | if (ngap == 32) { |
| 798 | /* FIXME: should check if not_code == ~ircode */ |
| 799 | ir->code = ir_extract_bits(ircode, ir->mask_keycode); |
| 800 | |
| 801 | dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n", |
| 802 | ir->code, ircode, not_code); |
| 803 | |
| 804 | ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code); |
| 805 | } else |
| 806 | dprintk("Repeat last key\n"); |
| 807 | |
| 808 | /* Keep repeating the last key */ |
| 809 | mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150)); |
| 810 | |
| 811 | saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); |
| 812 | } |
| 813 | |
| 814 | static int saa7134_nec_irq(struct saa7134_dev *dev) |
| 815 | { |
| 816 | struct card_ir *ir = dev->remote; |
| 817 | |
| 818 | saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); |
| 819 | tasklet_schedule(&ir->tlet); |
| 820 | |
| 821 | return 1; |
| 822 | } |