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) \ |
Jean Delvare | 1df8e98 | 2009-05-13 16:48:07 -0300 | [diff] [blame] | 63 | printk(KERN_DEBUG "%s/ir: " fmt, ir->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 | |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 100 | switch (dev->board) { |
| 101 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: |
| 102 | if (data == ir->mask_keycode) |
| 103 | ir_input_nokey(ir->dev, &ir->ir); |
| 104 | else |
| 105 | ir_input_keydown(ir->dev, &ir->ir, data, data); |
| 106 | return 0; |
| 107 | } |
| 108 | |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 109 | if (ir->polling) { |
| 110 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 111 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
| 112 | ir_input_keydown(ir->dev, &ir->ir, data, data); |
| 113 | } else { |
| 114 | ir_input_nokey(ir->dev, &ir->ir); |
| 115 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 117 | else { /* IRQ driven mode - handle key press and release in one go */ |
| 118 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 119 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
| 120 | ir_input_keydown(ir->dev, &ir->ir, data, data); |
| 121 | ir_input_nokey(ir->dev, &ir->ir); |
| 122 | } |
| 123 | } |
| 124 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 128 | /* --------------------- Chip specific I2C key builders ----------------- */ |
| 129 | |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 130 | static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key, |
| 131 | u32 *ir_raw) |
| 132 | { |
| 133 | unsigned char b; |
| 134 | int gpio; |
| 135 | |
| 136 | /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 137 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 138 | if (dev == NULL) { |
| 139 | dprintk("get_key_msi_tvanywhere_plus: " |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 140 | "gir->c->adapter->algo_data is NULL!\n"); |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 141 | return -EIO; |
| 142 | } |
| 143 | |
| 144 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 145 | |
| 146 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 147 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 148 | |
| 149 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 150 | |
| 151 | /* GPIO&0x40 is pulsed low when a button is pressed. Don't do |
| 152 | I2C receive if gpio&0x40 is not low. */ |
| 153 | |
| 154 | if (gpio & 0x40) |
| 155 | return 0; /* No button press */ |
| 156 | |
| 157 | /* GPIO says there is a button press. Get it. */ |
| 158 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 159 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 160 | i2cdprintk("read error\n"); |
| 161 | return -EIO; |
| 162 | } |
| 163 | |
| 164 | /* No button press */ |
| 165 | |
| 166 | if (b == 0xff) |
| 167 | return 0; |
| 168 | |
| 169 | /* Button pressed */ |
| 170 | |
| 171 | dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b); |
| 172 | *ir_key = b; |
| 173 | *ir_raw = b; |
| 174 | return 1; |
| 175 | } |
| 176 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 177 | static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 178 | { |
| 179 | unsigned char b; |
| 180 | |
| 181 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 182 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 183 | i2cdprintk("read error\n"); |
| 184 | return -EIO; |
| 185 | } |
| 186 | |
| 187 | /* no button press */ |
| 188 | if (b==0) |
| 189 | return 0; |
| 190 | |
| 191 | /* repeating */ |
| 192 | if (b & 0x80) |
| 193 | return 1; |
| 194 | |
| 195 | *ir_key = b; |
| 196 | *ir_raw = b; |
| 197 | return 1; |
| 198 | } |
| 199 | |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 200 | static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 201 | { |
| 202 | unsigned char buf[5], cod4, code3, code4; |
| 203 | |
| 204 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 205 | if (5 != i2c_master_recv(ir->c, buf, 5)) |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 206 | return -EIO; |
| 207 | |
| 208 | cod4 = buf[4]; |
| 209 | code4 = (cod4 >> 2); |
| 210 | code3 = buf[3]; |
| 211 | if (code3 == 0) |
| 212 | /* no key pressed */ |
| 213 | return 0; |
| 214 | |
| 215 | /* return key */ |
| 216 | *ir_key = code4; |
| 217 | *ir_raw = code4; |
| 218 | return 1; |
| 219 | } |
| 220 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 221 | |
| 222 | static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 223 | { |
| 224 | unsigned char data[12]; |
| 225 | u32 gpio; |
| 226 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 227 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 228 | |
| 229 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 230 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 231 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 232 | |
| 233 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 234 | |
Mauro Carvalho Chehab | 616f887 | 2008-01-07 05:18:36 -0300 | [diff] [blame] | 235 | if (0x400000 & ~gpio) |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 236 | return 0; /* No button press */ |
| 237 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 238 | ir->c->addr = 0x5a >> 1; |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 239 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 240 | if (12 != i2c_master_recv(ir->c, data, 12)) { |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 241 | i2cdprintk("read error\n"); |
| 242 | return -EIO; |
| 243 | } |
| 244 | /* IR of this card normally decode signals NEC-standard from |
| 245 | * - Sven IHOO MT 5.1R remote. xxyye718 |
| 246 | * - Sven DVD HD-10xx remote. xxyyf708 |
| 247 | * - BBK ... |
| 248 | * - mayby others |
| 249 | * So, skip not our, if disable full codes mode. |
| 250 | */ |
| 251 | if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir) |
| 252 | return 0; |
| 253 | |
| 254 | *ir_key = data[9]; |
| 255 | *ir_raw = data[9]; |
| 256 | |
| 257 | return 1; |
| 258 | } |
| 259 | |
Mauro Carvalho Chehab | 1c22dad | 2008-07-17 22:31:29 -0300 | [diff] [blame] | 260 | /* Common (grey or coloured) pinnacle PCTV remote handling |
| 261 | * |
| 262 | */ |
| 263 | static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw, |
| 264 | int parity_offset, int marker, int code_modulo) |
| 265 | { |
| 266 | unsigned char b[4]; |
| 267 | unsigned int start = 0,parity = 0,code = 0; |
| 268 | |
| 269 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 270 | if (4 != i2c_master_recv(ir->c, b, 4)) { |
Mauro Carvalho Chehab | 1c22dad | 2008-07-17 22:31:29 -0300 | [diff] [blame] | 271 | i2cdprintk("read error\n"); |
| 272 | return -EIO; |
| 273 | } |
| 274 | |
| 275 | for (start = 0; start < ARRAY_SIZE(b); start++) { |
| 276 | if (b[start] == marker) { |
| 277 | code=b[(start+parity_offset + 1) % 4]; |
| 278 | parity=b[(start+parity_offset) % 4]; |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | /* Empty Request */ |
| 283 | if (parity == 0) |
| 284 | return 0; |
| 285 | |
| 286 | /* Repeating... */ |
| 287 | if (ir->old == parity) |
| 288 | return 0; |
| 289 | |
| 290 | ir->old = parity; |
| 291 | |
| 292 | /* drop special codes when a key is held down a long time for the grey controller |
| 293 | In this case, the second bit of the code is asserted */ |
| 294 | if (marker == 0xfe && (code & 0x40)) |
| 295 | return 0; |
| 296 | |
| 297 | code %= code_modulo; |
| 298 | |
| 299 | *ir_raw = code; |
| 300 | *ir_key = code; |
| 301 | |
| 302 | i2cdprintk("Pinnacle PCTV key %02x\n", code); |
| 303 | |
| 304 | return 1; |
| 305 | } |
| 306 | |
| 307 | /* The grey pinnacle PCTV remote |
| 308 | * |
| 309 | * There are one issue with this remote: |
| 310 | * - I2c packet does not change when the same key is pressed quickly. The workaround |
| 311 | * is to hold down each key for about half a second, so that another code is generated |
| 312 | * in the i2c packet, and the function can distinguish key presses. |
| 313 | * |
| 314 | * Sylvain Pasche <sylvain.pasche@gmail.com> |
| 315 | */ |
| 316 | static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 317 | { |
| 318 | |
| 319 | return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | /* The new pinnacle PCTV remote (with the colored buttons) |
| 324 | * |
| 325 | * Ricardo Cerqueira <v4l@cerqueira.org> |
| 326 | */ |
| 327 | static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 328 | { |
| 329 | /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE |
| 330 | * |
| 331 | * this is the only value that results in 42 unique |
| 332 | * codes < 128 |
| 333 | */ |
| 334 | |
| 335 | return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88); |
| 336 | } |
| 337 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | void saa7134_input_irq(struct saa7134_dev *dev) |
| 339 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 340 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 342 | if (ir->nec_gpio) { |
| 343 | saa7134_nec_irq(dev); |
| 344 | } else if (!ir->polling && !ir->rc5_gpio) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | build_key(dev); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 346 | } else if (ir->rc5_gpio) { |
| 347 | saa7134_rc5_irq(dev); |
| 348 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | static void saa7134_input_timer(unsigned long data) |
| 352 | { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 353 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 354 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
| 356 | build_key(dev); |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 357 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 360 | void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 361 | { |
| 362 | if (ir->polling) { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 363 | setup_timer(&ir->timer, saa7134_input_timer, |
| 364 | (unsigned long)dev); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 365 | ir->timer.expires = jiffies + HZ; |
| 366 | add_timer(&ir->timer); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 367 | } else if (ir->rc5_gpio) { |
| 368 | /* set timer_end for code completion */ |
| 369 | init_timer(&ir->timer_end); |
| 370 | ir->timer_end.function = ir_rc5_timer_end; |
| 371 | ir->timer_end.data = (unsigned long)ir; |
| 372 | init_timer(&ir->timer_keyup); |
| 373 | ir->timer_keyup.function = ir_rc5_timer_keyup; |
| 374 | ir->timer_keyup.data = (unsigned long)ir; |
| 375 | ir->shift_by = 2; |
| 376 | ir->start = 0x2; |
| 377 | ir->addr = 0x17; |
| 378 | ir->rc5_key_timeout = ir_rc5_key_timeout; |
| 379 | ir->rc5_remote_gap = ir_rc5_remote_gap; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 380 | } else if (ir->nec_gpio) { |
| 381 | setup_timer(&ir->timer_keyup, saa7134_nec_timer, |
| 382 | (unsigned long)dev); |
| 383 | tasklet_init(&ir->tlet, nec_task, (unsigned long)dev); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | |
Maxim Levitsky | c458473 | 2007-10-12 00:57:15 -0300 | [diff] [blame] | 387 | void saa7134_ir_stop(struct saa7134_dev *dev) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 388 | { |
| 389 | if (dev->remote->polling) |
| 390 | del_timer_sync(&dev->remote->timer); |
| 391 | } |
| 392 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | int saa7134_input_init1(struct saa7134_dev *dev) |
| 394 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 395 | struct card_ir *ir; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 396 | struct input_dev *input_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | IR_KEYTAB_TYPE *ir_codes = NULL; |
| 398 | u32 mask_keycode = 0; |
| 399 | u32 mask_keydown = 0; |
| 400 | u32 mask_keyup = 0; |
| 401 | int polling = 0; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 402 | int rc5_gpio = 0; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 403 | int nec_gpio = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | int ir_type = IR_TYPE_OTHER; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 405 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Ricardo Cerqueira | cb2444d | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 407 | if (dev->has_remote != SAA7134_REMOTE_GPIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | return -ENODEV; |
| 409 | if (disable_ir) |
| 410 | return -ENODEV; |
| 411 | |
| 412 | /* detect & configure */ |
| 413 | switch (dev->board) { |
| 414 | case SAA7134_BOARD_FLYVIDEO2000: |
| 415 | case SAA7134_BOARD_FLYVIDEO3000: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 416 | case SAA7134_BOARD_FLYTVPLATINUM_FM: |
Arnaud Patard | 6af90ab | 2005-11-08 21:36:55 -0800 | [diff] [blame] | 417 | case SAA7134_BOARD_FLYTVPLATINUM_MINI2: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 418 | ir_codes = ir_codes_flyvideo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | mask_keycode = 0xEC00000; |
| 420 | mask_keydown = 0x0040000; |
| 421 | break; |
| 422 | case SAA7134_BOARD_CINERGY400: |
| 423 | case SAA7134_BOARD_CINERGY600: |
| 424 | case SAA7134_BOARD_CINERGY600_MK3: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 425 | ir_codes = ir_codes_cinergy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | mask_keycode = 0x00003f; |
| 427 | mask_keyup = 0x040000; |
| 428 | break; |
| 429 | case SAA7134_BOARD_ECS_TVP3XP: |
| 430 | case SAA7134_BOARD_ECS_TVP3XP_4CB5: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 431 | ir_codes = ir_codes_eztv; |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 432 | mask_keycode = 0x00017c; |
| 433 | mask_keyup = 0x000002; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | polling = 50; // ms |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 435 | break; |
| 436 | case SAA7134_BOARD_KWORLD_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | case SAA7134_BOARD_AVACSSMARTTV: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 438 | ir_codes = ir_codes_pixelview; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | mask_keycode = 0x00001F; |
| 440 | mask_keyup = 0x000020; |
| 441 | polling = 50; // ms |
| 442 | break; |
| 443 | case SAA7134_BOARD_MD2819: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 444 | case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | case SAA7134_BOARD_AVERMEDIA_305: |
| 446 | case SAA7134_BOARD_AVERMEDIA_307: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 447 | case SAA7134_BOARD_AVERMEDIA_STUDIO_305: |
| 448 | case SAA7134_BOARD_AVERMEDIA_STUDIO_307: |
Mikhail Fedotov | 3ac706d | 2006-10-06 20:23:47 -0300 | [diff] [blame] | 449 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507: |
Andy Shevchenko | df0dbbe | 2009-04-08 14:01:19 -0300 | [diff] [blame] | 450 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 451 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM: |
Albert Graham | d2761f2 | 2007-12-09 09:44:38 -0300 | [diff] [blame] | 452 | case SAA7134_BOARD_AVERMEDIA_M102: |
Pham Thanh Nam | 6a2d802 | 2008-12-30 23:26:09 -0300 | [diff] [blame] | 453 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 454 | ir_codes = ir_codes_avermedia; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | mask_keycode = 0x0007C8; |
| 456 | mask_keydown = 0x000010; |
| 457 | polling = 50; // ms |
| 458 | /* Set GPIO pin2 to high to enable the IR controller */ |
| 459 | saa_setb(SAA7134_GPIO_GPMODE0, 0x4); |
| 460 | saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); |
| 461 | break; |
Mauro Carvalho Chehab | 36f6bb9 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 462 | case SAA7134_BOARD_AVERMEDIA_M135A: |
| 463 | ir_codes = ir_codes_avermedia_m135a; |
| 464 | mask_keydown = 0x0040000; |
| 465 | mask_keycode = 0x00013f; |
| 466 | nec_gpio = 1; |
| 467 | break; |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 468 | case SAA7134_BOARD_AVERMEDIA_777: |
pasky@ucw.cz | 29e0f1a | 2006-11-12 14:23:32 -0300 | [diff] [blame] | 469 | case SAA7134_BOARD_AVERMEDIA_A16AR: |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 470 | ir_codes = ir_codes_avermedia; |
| 471 | mask_keycode = 0x02F200; |
| 472 | mask_keydown = 0x000400; |
| 473 | polling = 50; // ms |
| 474 | /* Without this we won't receive key up events */ |
| 475 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 476 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
Linus Torvalds | 4dd7406 | 2006-11-13 09:50:11 -0800 | [diff] [blame] | 477 | break; |
Tim Farrington | 6e501a3 | 2008-06-15 13:33:42 -0300 | [diff] [blame] | 478 | case SAA7134_BOARD_AVERMEDIA_A16D: |
| 479 | ir_codes = ir_codes_avermedia_a16d; |
| 480 | mask_keycode = 0x02F200; |
| 481 | mask_keydown = 0x000400; |
| 482 | polling = 50; /* ms */ |
| 483 | /* Without this we won't receive key up events */ |
| 484 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 485 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
| 486 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 487 | case SAA7134_BOARD_KWORLD_TERMINATOR: |
Nickolay V. Shmyrev | b639f9d | 2006-01-23 09:44:10 -0200 | [diff] [blame] | 488 | ir_codes = ir_codes_pixelview; |
James R. Webb | dc2286c | 2005-11-08 21:37:00 -0800 | [diff] [blame] | 489 | mask_keycode = 0x00001f; |
| 490 | mask_keyup = 0x000060; |
| 491 | polling = 50; // ms |
| 492 | break; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 493 | case SAA7134_BOARD_MANLI_MTV001: |
| 494 | case SAA7134_BOARD_MANLI_MTV002: |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 495 | ir_codes = ir_codes_manli; |
| 496 | mask_keycode = 0x001f00; |
| 497 | mask_keyup = 0x004000; |
| 498 | polling = 50; /* ms */ |
| 499 | break; |
Nickolay V. Shmyrev | a8ff417 | 2005-11-08 21:36:16 -0800 | [diff] [blame] | 500 | case SAA7134_BOARD_BEHOLD_409FM: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 501 | case SAA7134_BOARD_BEHOLD_401: |
| 502 | case SAA7134_BOARD_BEHOLD_403: |
| 503 | case SAA7134_BOARD_BEHOLD_403FM: |
| 504 | case SAA7134_BOARD_BEHOLD_405: |
| 505 | case SAA7134_BOARD_BEHOLD_405FM: |
| 506 | case SAA7134_BOARD_BEHOLD_407: |
| 507 | case SAA7134_BOARD_BEHOLD_407FM: |
| 508 | case SAA7134_BOARD_BEHOLD_409: |
| 509 | case SAA7134_BOARD_BEHOLD_505FM: |
Dmitri Belimov | 84d728c | 2009-04-23 02:32:49 -0300 | [diff] [blame] | 510 | case SAA7134_BOARD_BEHOLD_505RDS: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 511 | case SAA7134_BOARD_BEHOLD_507_9FM: |
Dmitri Belimov | 84d728c | 2009-04-23 02:32:49 -0300 | [diff] [blame] | 512 | case SAA7134_BOARD_BEHOLD_507RDS_MK3: |
| 513 | case SAA7134_BOARD_BEHOLD_507RDS_MK5: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 514 | ir_codes = ir_codes_manli; |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 515 | mask_keycode = 0x003f00; |
| 516 | mask_keyup = 0x004000; |
| 517 | polling = 50; /* ms */ |
| 518 | break; |
| 519 | case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: |
| 520 | ir_codes = ir_codes_behold_columbus; |
| 521 | mask_keycode = 0x003f00; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 522 | mask_keyup = 0x004000; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 523 | polling = 50; // ms |
| 524 | break; |
Ricardo Cerqueira | 17ce1ff | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 525 | case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 526 | ir_codes = ir_codes_pctv_sedna; |
Pavel Mihaylov | c3d9319 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 527 | mask_keycode = 0x001f00; |
| 528 | mask_keyup = 0x004000; |
| 529 | polling = 50; // ms |
| 530 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 531 | case SAA7134_BOARD_GOTVIEW_7135: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 532 | ir_codes = ir_codes_gotview7135; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 533 | mask_keycode = 0x0003CC; |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 534 | mask_keydown = 0x000010; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 535 | polling = 5; /* ms */ |
| 536 | saa_setb(SAA7134_GPIO_GPMODE1, 0x80); |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 537 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | case SAA7134_BOARD_VIDEOMATE_TV_PVR: |
Nickolay V. Shmyrev | 2a9a9a8 | 2006-01-09 15:25:33 -0200 | [diff] [blame] | 539 | case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 540 | case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 541 | ir_codes = ir_codes_videomate_tv_pvr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | mask_keycode = 0x00003F; |
| 543 | mask_keyup = 0x400000; |
| 544 | polling = 50; // ms |
| 545 | break; |
Michal Majchrowicz | b04c1ba | 2006-09-13 16:42:42 -0300 | [diff] [blame] | 546 | case SAA7134_BOARD_PROTEUS_2309: |
| 547 | ir_codes = ir_codes_proteus_2309; |
| 548 | mask_keycode = 0x00007F; |
| 549 | mask_keyup = 0x000080; |
| 550 | polling = 50; // ms |
| 551 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 552 | case SAA7134_BOARD_VIDEOMATE_DVBT_300: |
| 553 | case SAA7134_BOARD_VIDEOMATE_DVBT_200: |
Ricardo Cerqueira | 4c0f631 | 2006-01-23 09:42:06 -0200 | [diff] [blame] | 554 | ir_codes = ir_codes_videomate_tv_pvr; |
Nickolay V. Shmyrev | fea095f | 2005-11-08 21:36:47 -0800 | [diff] [blame] | 555 | mask_keycode = 0x003F00; |
| 556 | mask_keyup = 0x040000; |
| 557 | break; |
James Le Cuirot | f5c965a | 2007-07-02 12:53:25 -0300 | [diff] [blame] | 558 | case SAA7134_BOARD_FLYDVBS_LR300: |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 559 | case SAA7134_BOARD_FLYDVBT_LR301: |
Rudo Thomas | a802917 | 2006-02-27 00:08:46 -0300 | [diff] [blame] | 560 | case SAA7134_BOARD_FLYDVBTDUO: |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 561 | ir_codes = ir_codes_flydvb; |
| 562 | mask_keycode = 0x0001F00; |
| 563 | mask_keydown = 0x0040000; |
| 564 | break; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 565 | case SAA7134_BOARD_ASUSTeK_P7131_DUAL: |
Ed Vipas | 904ab88 | 2007-03-29 18:32:49 -0300 | [diff] [blame] | 566 | case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: |
Mauro Carvalho Chehab | dfb4ba1 | 2009-08-20 10:13:40 -0300 | [diff] [blame] | 567 | case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 568 | ir_codes = ir_codes_asus_pc39; |
| 569 | mask_keydown = 0x0040000; |
| 570 | rc5_gpio = 1; |
| 571 | break; |
Juan Pablo Sormani | c36c459 | 2006-12-27 12:46:36 -0300 | [diff] [blame] | 572 | case SAA7134_BOARD_ENCORE_ENLTV: |
| 573 | case SAA7134_BOARD_ENCORE_ENLTV_FM: |
| 574 | ir_codes = ir_codes_encore_enltv; |
| 575 | mask_keycode = 0x00007f; |
| 576 | mask_keyup = 0x040000; |
| 577 | polling = 50; // ms |
| 578 | break; |
Mauro Carvalho Chehab | bf1ece6 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 579 | case SAA7134_BOARD_ENCORE_ENLTV_FM53: |
| 580 | ir_codes = ir_codes_encore_enltv_fm53; |
| 581 | mask_keydown = 0x0040000; |
| 582 | mask_keycode = 0x00007f; |
| 583 | nec_gpio = 1; |
| 584 | break; |
Tony Wan | 480f75a | 2007-05-11 11:33:50 -0300 | [diff] [blame] | 585 | case SAA7134_BOARD_10MOONSTVMASTER3: |
| 586 | ir_codes = ir_codes_encore_enltv; |
| 587 | mask_keycode = 0x5f80000; |
| 588 | mask_keyup = 0x8000000; |
| 589 | polling = 50; //ms |
| 590 | break; |
Adrian Pardini | f0ba356 | 2008-02-11 12:40:53 -0300 | [diff] [blame] | 591 | case SAA7134_BOARD_GENIUS_TVGO_A11MCE: |
| 592 | ir_codes = ir_codes_genius_tvgo_a11mce; |
| 593 | mask_keycode = 0xff; |
| 594 | mask_keydown = 0xf00000; |
| 595 | polling = 50; /* ms */ |
| 596 | break; |
Mauro Carvalho Chehab | 9b00019 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 597 | case SAA7134_BOARD_REAL_ANGEL_220: |
| 598 | ir_codes = ir_codes_real_audio_220_32_keys; |
| 599 | mask_keycode = 0x3f00; |
| 600 | mask_keyup = 0x4000; |
| 601 | polling = 50; /* ms */ |
| 602 | break; |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 603 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: |
| 604 | ir_codes = ir_codes_kworld_plus_tv_analog; |
| 605 | mask_keycode = 0x7f; |
| 606 | polling = 40; /* ms */ |
| 607 | break; |
Igor M. Liplianin | ecfcfec | 2009-08-13 21:42:21 -0300 | [diff] [blame] | 608 | case SAA7134_BOARD_VIDEOMATE_S350: |
| 609 | ir_codes = ir_codes_videomate_s350; |
| 610 | mask_keycode = 0x003f00; |
| 611 | mask_keydown = 0x040000; |
| 612 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | if (NULL == ir_codes) { |
| 615 | printk("%s: Oops: IR config error [card=%d]\n", |
| 616 | dev->name, dev->board); |
| 617 | return -ENODEV; |
| 618 | } |
| 619 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 620 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
| 621 | input_dev = input_allocate_device(); |
| 622 | if (!ir || !input_dev) { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 623 | err = -ENOMEM; |
| 624 | goto err_out_free; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 625 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | |
Dmitry Torokhov | d271d1c | 2005-11-20 00:56:54 -0500 | [diff] [blame] | 627 | ir->dev = input_dev; |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | /* init hardware-specific stuff */ |
| 630 | ir->mask_keycode = mask_keycode; |
| 631 | ir->mask_keydown = mask_keydown; |
| 632 | ir->mask_keyup = mask_keyup; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 633 | ir->polling = polling; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 634 | ir->rc5_gpio = rc5_gpio; |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 635 | ir->nec_gpio = nec_gpio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
| 637 | /* init input device */ |
| 638 | snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", |
| 639 | saa7134_boards[dev->board].name); |
| 640 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", |
| 641 | pci_name(dev->pci)); |
| 642 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 643 | ir_input_init(input_dev, &ir->ir, ir_type, ir_codes); |
| 644 | input_dev->name = ir->name; |
| 645 | input_dev->phys = ir->phys; |
| 646 | input_dev->id.bustype = BUS_PCI; |
| 647 | input_dev->id.version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (dev->pci->subsystem_vendor) { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 649 | input_dev->id.vendor = dev->pci->subsystem_vendor; |
| 650 | input_dev->id.product = dev->pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } else { |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 652 | input_dev->id.vendor = dev->pci->vendor; |
| 653 | input_dev->id.product = dev->pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | } |
Dmitry Torokhov | 2c8a3a3 | 2007-07-16 09:28:15 -0300 | [diff] [blame] | 655 | input_dev->dev.parent = &dev->pci->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | dev->remote = ir; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 658 | saa7134_ir_start(dev, ir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 660 | err = input_register_device(ir->dev); |
| 661 | if (err) |
| 662 | goto err_out_stop; |
| 663 | |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 664 | /* the remote isn't as bouncy as a keyboard */ |
| 665 | ir->dev->rep[REP_DELAY] = repeat_delay; |
| 666 | ir->dev->rep[REP_PERIOD] = repeat_period; |
| 667 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 669 | |
| 670 | err_out_stop: |
| 671 | saa7134_ir_stop(dev); |
| 672 | dev->remote = NULL; |
| 673 | err_out_free: |
| 674 | input_free_device(input_dev); |
| 675 | kfree(ir); |
| 676 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void saa7134_input_fini(struct saa7134_dev *dev) |
| 680 | { |
| 681 | if (NULL == dev->remote) |
| 682 | return; |
| 683 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 684 | saa7134_ir_stop(dev); |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 685 | input_unregister_device(dev->remote->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | kfree(dev->remote); |
| 687 | dev->remote = NULL; |
| 688 | } |
| 689 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 690 | void saa7134_probe_i2c_ir(struct saa7134_dev *dev) |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 691 | { |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 692 | struct i2c_board_info info; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 693 | struct IR_i2c_init_data init_data; |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 694 | const unsigned short addr_list[] = { |
| 695 | 0x7a, 0x47, 0x71, 0x2d, |
| 696 | I2C_CLIENT_END |
| 697 | }; |
| 698 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 699 | struct i2c_msg msg_msi = { |
| 700 | .addr = 0x50, |
| 701 | .flags = I2C_M_RD, |
| 702 | .len = 0, |
| 703 | .buf = NULL, |
| 704 | }; |
| 705 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 706 | int rc; |
| 707 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 708 | if (disable_ir) { |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 709 | dprintk("IR has been disabled, not probing for i2c remote\n"); |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 710 | return; |
| 711 | } |
| 712 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 713 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 714 | memset(&init_data, 0, sizeof(struct IR_i2c_init_data)); |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 715 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 716 | |
| 717 | switch (dev->board) { |
| 718 | case SAA7134_BOARD_PINNACLE_PCTV_110i: |
| 719 | case SAA7134_BOARD_PINNACLE_PCTV_310i: |
| 720 | init_data.name = "Pinnacle PCTV"; |
| 721 | if (pinnacle_remote == 0) { |
| 722 | init_data.get_key = get_key_pinnacle_color; |
| 723 | init_data.ir_codes = ir_codes_pinnacle_color; |
hermann pitton | a138ebc | 2009-08-19 22:30:58 -0300 | [diff] [blame^] | 724 | info.addr = 0x47; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 725 | } else { |
| 726 | init_data.get_key = get_key_pinnacle_grey; |
| 727 | init_data.ir_codes = ir_codes_pinnacle_grey; |
hermann pitton | a138ebc | 2009-08-19 22:30:58 -0300 | [diff] [blame^] | 728 | info.addr = 0x47; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 729 | } |
| 730 | break; |
| 731 | case SAA7134_BOARD_UPMOST_PURPLE_TV: |
| 732 | init_data.name = "Purple TV"; |
| 733 | init_data.get_key = get_key_purpletv; |
| 734 | init_data.ir_codes = ir_codes_purpletv; |
| 735 | break; |
| 736 | case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS: |
| 737 | init_data.name = "MSI TV@nywhere Plus"; |
| 738 | init_data.get_key = get_key_msi_tvanywhere_plus; |
| 739 | init_data.ir_codes = ir_codes_msi_tvanywhere_plus; |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 740 | info.addr = 0x30; |
| 741 | /* MSI TV@nywhere Plus controller doesn't seem to |
| 742 | respond to probes unless we read something from |
| 743 | an existing device. Weird... |
| 744 | REVISIT: might no longer be needed */ |
| 745 | rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); |
| 746 | dprintk(KERN_DEBUG "probe 0x%02x @ %s: %s\n", |
| 747 | msg_msi.addr, dev->i2c_adap.name, |
| 748 | (1 == rc) ? "yes" : "no"); |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 749 | break; |
| 750 | case SAA7134_BOARD_HAUPPAUGE_HVR1110: |
| 751 | init_data.name = "HVR 1110"; |
| 752 | init_data.get_key = get_key_hvr1110; |
| 753 | init_data.ir_codes = ir_codes_hauppauge_new; |
| 754 | break; |
| 755 | case SAA7134_BOARD_BEHOLD_607FM_MK3: |
| 756 | case SAA7134_BOARD_BEHOLD_607FM_MK5: |
| 757 | case SAA7134_BOARD_BEHOLD_609FM_MK3: |
| 758 | case SAA7134_BOARD_BEHOLD_609FM_MK5: |
| 759 | case SAA7134_BOARD_BEHOLD_607RDS_MK3: |
| 760 | case SAA7134_BOARD_BEHOLD_607RDS_MK5: |
| 761 | case SAA7134_BOARD_BEHOLD_609RDS_MK3: |
| 762 | case SAA7134_BOARD_BEHOLD_609RDS_MK5: |
| 763 | case SAA7134_BOARD_BEHOLD_M6: |
| 764 | case SAA7134_BOARD_BEHOLD_M63: |
| 765 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: |
| 766 | case SAA7134_BOARD_BEHOLD_H6: |
| 767 | init_data.name = "BeholdTV"; |
| 768 | init_data.get_key = get_key_beholdm6xx; |
| 769 | init_data.ir_codes = ir_codes_behold; |
| 770 | break; |
Jean Delvare | d9a88e6 | 2009-05-13 16:52:44 -0300 | [diff] [blame] | 771 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_501: |
| 772 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: |
| 773 | info.addr = 0x40; |
| 774 | break; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | if (init_data.name) |
| 778 | info.platform_data = &init_data; |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 779 | /* No need to probe if address is known */ |
| 780 | if (info.addr) { |
| 781 | i2c_new_device(&dev->i2c_adap, &info); |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 782 | return; |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 783 | } |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 784 | |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 785 | /* Address not known, fallback to probing */ |
Jean Delvare | d9a88e6 | 2009-05-13 16:52:44 -0300 | [diff] [blame] | 786 | i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 787 | } |
| 788 | |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 789 | static int saa7134_rc5_irq(struct saa7134_dev *dev) |
| 790 | { |
| 791 | struct card_ir *ir = dev->remote; |
| 792 | struct timeval tv; |
| 793 | u32 gap; |
| 794 | unsigned long current_jiffies, timeout; |
| 795 | |
| 796 | /* get time of bit */ |
| 797 | current_jiffies = jiffies; |
| 798 | do_gettimeofday(&tv); |
| 799 | |
| 800 | /* avoid overflow with gap >1s */ |
| 801 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 802 | gap = 200000; |
| 803 | } else { |
| 804 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 805 | tv.tv_usec - ir->base_time.tv_usec; |
| 806 | } |
| 807 | |
| 808 | /* active code => add bit */ |
| 809 | if (ir->active) { |
| 810 | /* only if in the code (otherwise spurious IRQ or timer |
| 811 | late) */ |
| 812 | if (ir->last_bit < 28) { |
| 813 | ir->last_bit = (gap - ir_rc5_remote_gap / 2) / |
| 814 | ir_rc5_remote_gap; |
| 815 | ir->code |= 1 << ir->last_bit; |
| 816 | } |
| 817 | /* starting new code */ |
| 818 | } else { |
| 819 | ir->active = 1; |
| 820 | ir->code = 0; |
| 821 | ir->base_time = tv; |
| 822 | ir->last_bit = 0; |
| 823 | |
| 824 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; |
| 825 | mod_timer(&ir->timer_end, timeout); |
| 826 | } |
| 827 | |
| 828 | return 1; |
| 829 | } |
| 830 | |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 831 | |
| 832 | /* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms |
| 833 | The first pulse (start) has 9 + 4.5 ms |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | */ |
Mauro Carvalho Chehab | 622ecb3 | 2008-08-05 10:03:17 -0300 | [diff] [blame] | 835 | |
| 836 | static void saa7134_nec_timer(unsigned long data) |
| 837 | { |
| 838 | struct saa7134_dev *dev = (struct saa7134_dev *) data; |
| 839 | struct card_ir *ir = dev->remote; |
| 840 | |
| 841 | dprintk("Cancel key repeat\n"); |
| 842 | |
| 843 | ir_input_nokey(ir->dev, &ir->ir); |
| 844 | } |
| 845 | |
| 846 | static void nec_task(unsigned long data) |
| 847 | { |
| 848 | struct saa7134_dev *dev = (struct saa7134_dev *) data; |
| 849 | struct card_ir *ir; |
| 850 | struct timeval tv; |
| 851 | int count, pulse, oldpulse, gap; |
| 852 | u32 ircode = 0, not_code = 0; |
| 853 | int ngap = 0; |
| 854 | |
| 855 | if (!data) { |
| 856 | printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n"); |
| 857 | /* GPIO will be kept disabled */ |
| 858 | return; |
| 859 | } |
| 860 | |
| 861 | ir = dev->remote; |
| 862 | |
| 863 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 864 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 865 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 866 | |
| 867 | oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; |
| 868 | pulse = oldpulse; |
| 869 | |
| 870 | do_gettimeofday(&tv); |
| 871 | ir->base_time = tv; |
| 872 | |
| 873 | /* Decode NEC pulsecode. This code can take up to 76.5 ms to run. |
| 874 | Unfortunately, using IRQ to decode pulse didn't work, since it uses |
| 875 | a pulse train of 38KHz. This means one pulse on each 52 us |
| 876 | */ |
| 877 | do { |
| 878 | /* Wait until the end of pulse/space or 5 ms */ |
| 879 | for (count = 0; count < 500; count++) { |
| 880 | udelay(10); |
| 881 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 882 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 883 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 884 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) |
| 885 | & ir->mask_keydown; |
| 886 | if (pulse != oldpulse) |
| 887 | break; |
| 888 | } |
| 889 | |
| 890 | do_gettimeofday(&tv); |
| 891 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 892 | tv.tv_usec - ir->base_time.tv_usec; |
| 893 | |
| 894 | if (!pulse) { |
| 895 | /* Bit 0 has 560 us, while bit 1 has 1120 us. |
| 896 | Do something only if bit == 1 |
| 897 | */ |
| 898 | if (ngap && (gap > 560 + 280)) { |
| 899 | unsigned int shift = ngap - 1; |
| 900 | |
| 901 | /* Address first, then command */ |
| 902 | if (shift < 8) { |
| 903 | shift += 8; |
| 904 | ircode |= 1 << shift; |
| 905 | } else if (shift < 16) { |
| 906 | not_code |= 1 << shift; |
| 907 | } else if (shift < 24) { |
| 908 | shift -= 16; |
| 909 | ircode |= 1 << shift; |
| 910 | } else { |
| 911 | shift -= 24; |
| 912 | not_code |= 1 << shift; |
| 913 | } |
| 914 | } |
| 915 | ngap++; |
| 916 | } |
| 917 | |
| 918 | |
| 919 | ir->base_time = tv; |
| 920 | |
| 921 | /* TIMEOUT - Long pulse */ |
| 922 | if (gap >= 5000) |
| 923 | break; |
| 924 | oldpulse = pulse; |
| 925 | } while (ngap < 32); |
| 926 | |
| 927 | if (ngap == 32) { |
| 928 | /* FIXME: should check if not_code == ~ircode */ |
| 929 | ir->code = ir_extract_bits(ircode, ir->mask_keycode); |
| 930 | |
| 931 | dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n", |
| 932 | ir->code, ircode, not_code); |
| 933 | |
| 934 | ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code); |
| 935 | } else |
| 936 | dprintk("Repeat last key\n"); |
| 937 | |
| 938 | /* Keep repeating the last key */ |
| 939 | mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150)); |
| 940 | |
| 941 | saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); |
| 942 | } |
| 943 | |
| 944 | static int saa7134_nec_irq(struct saa7134_dev *dev) |
| 945 | { |
| 946 | struct card_ir *ir = dev->remote; |
| 947 | |
| 948 | saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18); |
| 949 | tasklet_schedule(&ir->tlet); |
| 950 | |
| 951 | return 1; |
| 952 | } |