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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #include "saa7134-reg.h" |
| 28 | #include "saa7134.h" |
| 29 | |
Mauro Carvalho Chehab | d302548 | 2010-10-06 22:02:58 -0300 | [diff] [blame] | 30 | #define MODULE_NAME "saa7134" |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 31 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 32 | static unsigned int disable_ir; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | module_param(disable_ir, int, 0444); |
| 34 | MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); |
| 35 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 36 | static unsigned int ir_debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | module_param(ir_debug, int, 0644); |
| 38 | MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); |
| 39 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 40 | static int pinnacle_remote; |
Sylvain Pasche | b93eedb | 2006-03-25 23:14:42 -0300 | [diff] [blame] | 41 | module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ |
| 42 | MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); |
| 43 | |
Adrian Bunk | c408a6f | 2006-12-28 12:47:47 -0300 | [diff] [blame] | 44 | static int ir_rc5_remote_gap = 885; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 45 | module_param(ir_rc5_remote_gap, int, 0644); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 46 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 47 | static unsigned int disable_other_ir; |
| 48 | module_param(disable_other_ir, int, 0644); |
| 49 | MODULE_PARM_DESC(disable_other_ir, "disable full codes of " |
| 50 | "alternative remotes from other manufacturers"); |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define dprintk(fmt, arg...) if (ir_debug) \ |
| 53 | printk(KERN_DEBUG "%s/ir: " fmt, dev->name , ## arg) |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 54 | #define i2cdprintk(fmt, arg...) if (ir_debug) \ |
Jean Delvare | 1df8e98 | 2009-05-13 16:48:07 -0300 | [diff] [blame] | 55 | printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 57 | /* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */ |
| 58 | static int saa7134_rc5_irq(struct saa7134_dev *dev); |
| 59 | static int saa7134_nec_irq(struct saa7134_dev *dev); |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 60 | static int saa7134_raw_decode_irq(struct saa7134_dev *dev); |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 61 | static void nec_task(unsigned long data); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 62 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 63 | /* -------------------- GPIO generic keycode builder -------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | static int build_key(struct saa7134_dev *dev) |
| 66 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 67 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | u32 gpio, data; |
| 69 | |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 70 | /* here comes the additional handshake steps for some cards */ |
| 71 | switch (dev->board) { |
| 72 | case SAA7134_BOARD_GOTVIEW_7135: |
| 73 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x80); |
| 74 | saa_clearb(SAA7134_GPIO_GPSTATUS1, 0x80); |
| 75 | break; |
| 76 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 78 | saa_clearb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); |
| 79 | saa_setb(SAA7134_GPIO_GPMODE3,SAA7134_GPIO_GPRESCAN); |
| 80 | |
| 81 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 82 | if (ir->polling) { |
| 83 | if (ir->last_gpio == gpio) |
| 84 | return 0; |
| 85 | ir->last_gpio = gpio; |
| 86 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 88 | data = ir_extract_bits(gpio, ir->mask_keycode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | dprintk("build_key gpio=0x%x mask=0x%x data=%d\n", |
| 90 | gpio, ir->mask_keycode, data); |
| 91 | |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 92 | switch (dev->board) { |
| 93 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: |
| 94 | if (data == ir->mask_keycode) |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 95 | ir_keyup(ir->dev); |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 96 | else |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 97 | ir_keydown_notimeout(ir->dev, data, 0); |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 98 | return 0; |
| 99 | } |
| 100 | |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 101 | if (ir->polling) { |
| 102 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 103 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 104 | ir_keydown_notimeout(ir->dev, data, 0); |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 105 | } else { |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 106 | ir_keyup(ir->dev); |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 107 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 109 | else { /* IRQ driven mode - handle key press and release in one go */ |
| 110 | if ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || |
| 111 | (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { |
David Härdeman | 62c6503 | 2010-10-29 16:08:07 -0300 | [diff] [blame] | 112 | ir_keydown_notimeout(ir->dev, data, 0); |
| 113 | ir_keyup(ir->dev); |
Peter Missel | 0602fbb | 2006-01-09 18:21:23 -0200 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | return 0; |
| 118 | } |
| 119 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 120 | /* --------------------- Chip specific I2C key builders ----------------- */ |
| 121 | |
Lukas Karas | d995a18 | 2009-11-24 12:06:52 -0300 | [diff] [blame] | 122 | static int get_key_flydvb_trio(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 123 | { |
| 124 | int gpio; |
| 125 | int attempt = 0; |
| 126 | unsigned char b; |
| 127 | |
| 128 | /* We need this to access GPI Used by the saa_readl macro. */ |
| 129 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
| 130 | |
| 131 | if (dev == NULL) { |
Dan Carpenter | 129c34d | 2010-05-26 11:58:10 -0300 | [diff] [blame] | 132 | i2cdprintk("get_key_flydvb_trio: " |
| 133 | "ir->c->adapter->algo_data is NULL!\n"); |
Lukas Karas | d995a18 | 2009-11-24 12:06:52 -0300 | [diff] [blame] | 134 | return -EIO; |
| 135 | } |
| 136 | |
| 137 | /* rising SAA7134_GPIGPRESCAN reads the status */ |
| 138 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 139 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 140 | |
| 141 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 142 | |
| 143 | if (0x40000 & ~gpio) |
| 144 | return 0; /* No button press */ |
| 145 | |
| 146 | /* No button press - only before first key pressed */ |
| 147 | if (b == 0xFF) |
| 148 | return 0; |
| 149 | |
| 150 | /* poll IR chip */ |
| 151 | /* weak up the IR chip */ |
| 152 | b = 0; |
| 153 | |
| 154 | while (1 != i2c_master_send(ir->c, &b, 1)) { |
| 155 | if ((attempt++) < 10) { |
| 156 | /* |
| 157 | * wait a bit for next attempt - |
| 158 | * I don't know how make it better |
| 159 | */ |
| 160 | msleep(10); |
| 161 | continue; |
| 162 | } |
| 163 | i2cdprintk("send wake up byte to pic16C505 (IR chip)" |
| 164 | "failed %dx\n", attempt); |
| 165 | return -EIO; |
| 166 | } |
| 167 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
| 168 | i2cdprintk("read error\n"); |
| 169 | return -EIO; |
| 170 | } |
| 171 | |
| 172 | *ir_key = b; |
| 173 | *ir_raw = b; |
| 174 | return 1; |
| 175 | } |
| 176 | |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 177 | static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key, |
| 178 | u32 *ir_raw) |
| 179 | { |
| 180 | unsigned char b; |
| 181 | int gpio; |
| 182 | |
| 183 | /* <dev> is needed to access GPIO. Used by the saa_readl macro. */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 184 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 185 | if (dev == NULL) { |
Dan Carpenter | 129c34d | 2010-05-26 11:58:10 -0300 | [diff] [blame] | 186 | i2cdprintk("get_key_msi_tvanywhere_plus: " |
| 187 | "ir->c->adapter->algo_data is NULL!\n"); |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 188 | return -EIO; |
| 189 | } |
| 190 | |
| 191 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 192 | |
| 193 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 194 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 195 | |
| 196 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 197 | |
| 198 | /* GPIO&0x40 is pulsed low when a button is pressed. Don't do |
| 199 | I2C receive if gpio&0x40 is not low. */ |
| 200 | |
| 201 | if (gpio & 0x40) |
| 202 | return 0; /* No button press */ |
| 203 | |
| 204 | /* GPIO says there is a button press. Get it. */ |
| 205 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 206 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
Brian Rogers | ba340b4 | 2008-10-13 08:37:06 -0300 | [diff] [blame] | 207 | i2cdprintk("read error\n"); |
| 208 | return -EIO; |
| 209 | } |
| 210 | |
| 211 | /* No button press */ |
| 212 | |
| 213 | if (b == 0xff) |
| 214 | return 0; |
| 215 | |
| 216 | /* Button pressed */ |
| 217 | |
| 218 | dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b); |
| 219 | *ir_key = b; |
| 220 | *ir_raw = b; |
| 221 | return 1; |
| 222 | } |
| 223 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 224 | static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 225 | { |
| 226 | unsigned char b; |
| 227 | |
| 228 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 229 | if (1 != i2c_master_recv(ir->c, &b, 1)) { |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 230 | i2cdprintk("read error\n"); |
| 231 | return -EIO; |
| 232 | } |
| 233 | |
| 234 | /* no button press */ |
| 235 | if (b==0) |
| 236 | return 0; |
| 237 | |
| 238 | /* repeating */ |
| 239 | if (b & 0x80) |
| 240 | return 1; |
| 241 | |
| 242 | *ir_key = b; |
| 243 | *ir_raw = b; |
| 244 | return 1; |
| 245 | } |
| 246 | |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 247 | static int get_key_hvr1110(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 248 | { |
| 249 | unsigned char buf[5], cod4, code3, code4; |
| 250 | |
| 251 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 252 | if (5 != i2c_master_recv(ir->c, buf, 5)) |
Thomas Genty | 177aaaf | 2006-11-29 21:57:24 -0300 | [diff] [blame] | 253 | return -EIO; |
| 254 | |
| 255 | cod4 = buf[4]; |
| 256 | code4 = (cod4 >> 2); |
| 257 | code3 = buf[3]; |
| 258 | if (code3 == 0) |
| 259 | /* no key pressed */ |
| 260 | return 0; |
| 261 | |
| 262 | /* return key */ |
| 263 | *ir_key = code4; |
| 264 | *ir_raw = code4; |
| 265 | return 1; |
| 266 | } |
| 267 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 268 | |
| 269 | static int get_key_beholdm6xx(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 270 | { |
| 271 | unsigned char data[12]; |
| 272 | u32 gpio; |
| 273 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 274 | struct saa7134_dev *dev = ir->c->adapter->algo_data; |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 275 | |
| 276 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 277 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 278 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 279 | |
| 280 | gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2); |
| 281 | |
Mauro Carvalho Chehab | 616f887 | 2008-01-07 05:18:36 -0300 | [diff] [blame] | 282 | if (0x400000 & ~gpio) |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 283 | return 0; /* No button press */ |
| 284 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 285 | ir->c->addr = 0x5a >> 1; |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 286 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 287 | if (12 != i2c_master_recv(ir->c, data, 12)) { |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 288 | i2cdprintk("read error\n"); |
| 289 | return -EIO; |
| 290 | } |
| 291 | /* IR of this card normally decode signals NEC-standard from |
| 292 | * - Sven IHOO MT 5.1R remote. xxyye718 |
| 293 | * - Sven DVD HD-10xx remote. xxyyf708 |
| 294 | * - BBK ... |
| 295 | * - mayby others |
| 296 | * So, skip not our, if disable full codes mode. |
| 297 | */ |
| 298 | if (data[10] != 0x6b && data[11] != 0x86 && disable_other_ir) |
| 299 | return 0; |
| 300 | |
Dmitri Belimov | 2d21ffe | 2009-09-07 20:36:05 -0300 | [diff] [blame] | 301 | /* Wrong data decode fix */ |
| 302 | if (data[9] != (unsigned char)(~data[8])) |
| 303 | return 0; |
| 304 | |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 305 | *ir_key = data[9]; |
| 306 | *ir_raw = data[9]; |
| 307 | |
| 308 | return 1; |
| 309 | } |
| 310 | |
Mauro Carvalho Chehab | 1c22dad | 2008-07-17 22:31:29 -0300 | [diff] [blame] | 311 | /* Common (grey or coloured) pinnacle PCTV remote handling |
| 312 | * |
| 313 | */ |
| 314 | static int get_key_pinnacle(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw, |
| 315 | int parity_offset, int marker, int code_modulo) |
| 316 | { |
| 317 | unsigned char b[4]; |
| 318 | unsigned int start = 0,parity = 0,code = 0; |
| 319 | |
| 320 | /* poll IR chip */ |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 321 | if (4 != i2c_master_recv(ir->c, b, 4)) { |
Mauro Carvalho Chehab | 1c22dad | 2008-07-17 22:31:29 -0300 | [diff] [blame] | 322 | i2cdprintk("read error\n"); |
| 323 | return -EIO; |
| 324 | } |
| 325 | |
| 326 | for (start = 0; start < ARRAY_SIZE(b); start++) { |
| 327 | if (b[start] == marker) { |
| 328 | code=b[(start+parity_offset + 1) % 4]; |
| 329 | parity=b[(start+parity_offset) % 4]; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | /* Empty Request */ |
| 334 | if (parity == 0) |
| 335 | return 0; |
| 336 | |
| 337 | /* Repeating... */ |
| 338 | if (ir->old == parity) |
| 339 | return 0; |
| 340 | |
| 341 | ir->old = parity; |
| 342 | |
| 343 | /* drop special codes when a key is held down a long time for the grey controller |
| 344 | In this case, the second bit of the code is asserted */ |
| 345 | if (marker == 0xfe && (code & 0x40)) |
| 346 | return 0; |
| 347 | |
| 348 | code %= code_modulo; |
| 349 | |
| 350 | *ir_raw = code; |
| 351 | *ir_key = code; |
| 352 | |
| 353 | i2cdprintk("Pinnacle PCTV key %02x\n", code); |
| 354 | |
| 355 | return 1; |
| 356 | } |
| 357 | |
| 358 | /* The grey pinnacle PCTV remote |
| 359 | * |
| 360 | * There are one issue with this remote: |
| 361 | * - I2c packet does not change when the same key is pressed quickly. The workaround |
| 362 | * is to hold down each key for about half a second, so that another code is generated |
| 363 | * in the i2c packet, and the function can distinguish key presses. |
| 364 | * |
| 365 | * Sylvain Pasche <sylvain.pasche@gmail.com> |
| 366 | */ |
| 367 | static int get_key_pinnacle_grey(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 368 | { |
| 369 | |
| 370 | return get_key_pinnacle(ir, ir_key, ir_raw, 1, 0xfe, 0xff); |
| 371 | } |
| 372 | |
| 373 | |
| 374 | /* The new pinnacle PCTV remote (with the colored buttons) |
| 375 | * |
| 376 | * Ricardo Cerqueira <v4l@cerqueira.org> |
| 377 | */ |
| 378 | static int get_key_pinnacle_color(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
| 379 | { |
| 380 | /* code_modulo parameter (0x88) is used to reduce code value to fit inside IR_KEYTAB_SIZE |
| 381 | * |
| 382 | * this is the only value that results in 42 unique |
| 383 | * codes < 128 |
| 384 | */ |
| 385 | |
| 386 | return get_key_pinnacle(ir, ir_key, ir_raw, 2, 0x80, 0x88); |
| 387 | } |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | void saa7134_input_irq(struct saa7134_dev *dev) |
| 390 | { |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 391 | struct card_ir *ir; |
| 392 | |
| 393 | if (!dev || !dev->remote) |
| 394 | return; |
| 395 | |
| 396 | ir = dev->remote; |
| 397 | if (!ir->running) |
| 398 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 400 | if (ir->nec_gpio) { |
| 401 | saa7134_nec_irq(dev); |
| 402 | } else if (!ir->polling && !ir->rc5_gpio && !ir->raw_decode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | build_key(dev); |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 404 | } else if (ir->rc5_gpio) { |
| 405 | saa7134_rc5_irq(dev); |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 406 | } else if (ir->raw_decode) { |
| 407 | saa7134_raw_decode_irq(dev); |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 408 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | static void saa7134_input_timer(unsigned long data) |
| 412 | { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 413 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 414 | struct card_ir *ir = dev->remote; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
| 416 | build_key(dev); |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 417 | mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | } |
| 419 | |
Mauro Carvalho Chehab | e051f69 | 2010-09-29 13:46:23 -0300 | [diff] [blame] | 420 | static void ir_raw_decode_timer_end(unsigned long data) |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 421 | { |
| 422 | struct saa7134_dev *dev = (struct saa7134_dev *)data; |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 423 | struct card_ir *ir = dev->remote; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 424 | |
Mauro Carvalho Chehab | ada3963 | 2010-03-21 12:24:24 -0300 | [diff] [blame] | 425 | ir_raw_event_handle(dev->remote->dev); |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 426 | |
| 427 | ir->active = 0; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 430 | static int __saa7134_ir_start(void *priv) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 431 | { |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 432 | struct saa7134_dev *dev = priv; |
| 433 | struct card_ir *ir; |
| 434 | |
| 435 | if (!dev) |
| 436 | return -EINVAL; |
| 437 | |
| 438 | ir = dev->remote; |
| 439 | if (!ir) |
| 440 | return -EINVAL; |
| 441 | |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 442 | if (ir->running) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 443 | return 0; |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 444 | |
| 445 | ir->running = 1; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 446 | if (ir->polling) { |
Dmitry Torokhov | b4ba788 | 2007-05-21 11:41:02 -0300 | [diff] [blame] | 447 | setup_timer(&ir->timer, saa7134_input_timer, |
| 448 | (unsigned long)dev); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 449 | ir->timer.expires = jiffies + HZ; |
| 450 | add_timer(&ir->timer); |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 451 | } else if (ir->rc5_gpio) { |
| 452 | /* set timer_end for code completion */ |
| 453 | init_timer(&ir->timer_end); |
| 454 | ir->timer_end.function = ir_rc5_timer_end; |
| 455 | ir->timer_end.data = (unsigned long)ir; |
| 456 | ir->shift_by = 2; |
| 457 | ir->start = 0x2; |
| 458 | ir->addr = 0x17; |
| 459 | ir->rc5_remote_gap = ir_rc5_remote_gap; |
| 460 | } else if (ir->nec_gpio) { |
| 461 | tasklet_init(&ir->tlet, nec_task, (unsigned long)dev); |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 462 | } else if (ir->raw_decode) { |
| 463 | /* set timer_end for code completion */ |
| 464 | init_timer(&ir->timer_end); |
| 465 | ir->timer_end.function = ir_raw_decode_timer_end; |
| 466 | ir->timer_end.data = (unsigned long)dev; |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 467 | ir->active = 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 468 | } |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 469 | |
| 470 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 471 | } |
| 472 | |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 473 | static void __saa7134_ir_stop(void *priv) |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 474 | { |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 475 | struct saa7134_dev *dev = priv; |
| 476 | struct card_ir *ir; |
| 477 | |
| 478 | if (!dev) |
| 479 | return; |
| 480 | |
| 481 | ir = dev->remote; |
| 482 | if (!ir) |
| 483 | return; |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 484 | |
| 485 | if (!ir->running) |
| 486 | return; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 487 | if (dev->remote->polling) |
| 488 | del_timer_sync(&dev->remote->timer); |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 489 | else if (ir->rc5_gpio) |
| 490 | del_timer_sync(&ir->timer_end); |
| 491 | else if (ir->nec_gpio) |
| 492 | tasklet_kill(&ir->tlet); |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 493 | else if (ir->raw_decode) { |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 494 | del_timer_sync(&ir->timer_end); |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 495 | ir->active = 0; |
| 496 | } |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 497 | |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 498 | ir->running = 0; |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 499 | |
| 500 | return; |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 501 | } |
| 502 | |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 503 | int saa7134_ir_start(struct saa7134_dev *dev) |
| 504 | { |
| 505 | if (dev->remote->users) |
| 506 | return __saa7134_ir_start(dev); |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | void saa7134_ir_stop(struct saa7134_dev *dev) |
| 512 | { |
| 513 | if (dev->remote->users) |
| 514 | __saa7134_ir_stop(dev); |
| 515 | } |
| 516 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 517 | static int saa7134_ir_open(struct rc_dev *rc) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 518 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 519 | struct saa7134_dev *dev = rc->priv; |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 520 | |
| 521 | dev->remote->users++; |
| 522 | return __saa7134_ir_start(dev); |
| 523 | } |
| 524 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 525 | static void saa7134_ir_close(struct rc_dev *rc) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 526 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 527 | struct saa7134_dev *dev = rc->priv; |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 528 | |
| 529 | dev->remote->users--; |
| 530 | if (!dev->remote->users) |
| 531 | __saa7134_ir_stop(dev); |
| 532 | } |
| 533 | |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 534 | |
| 535 | static int saa7134_ir_change_protocol(struct rc_dev *rc, u64 ir_type) |
| 536 | { |
| 537 | struct saa7134_dev *dev = rc->priv; |
| 538 | struct card_ir *ir = dev->remote; |
| 539 | u32 nec_gpio, rc5_gpio; |
| 540 | |
| 541 | if (ir_type == IR_TYPE_RC5) { |
| 542 | dprintk("Changing protocol to RC5\n"); |
| 543 | nec_gpio = 0; |
| 544 | rc5_gpio = 1; |
| 545 | } else if (ir_type == IR_TYPE_NEC) { |
| 546 | dprintk("Changing protocol to NEC\n"); |
| 547 | nec_gpio = 1; |
| 548 | rc5_gpio = 0; |
| 549 | } else { |
| 550 | dprintk("IR protocol type %ud is not supported\n", |
| 551 | (unsigned)ir_type); |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | |
| 555 | if (ir->running) { |
| 556 | saa7134_ir_stop(dev); |
| 557 | ir->nec_gpio = nec_gpio; |
| 558 | ir->rc5_gpio = rc5_gpio; |
| 559 | saa7134_ir_start(dev); |
| 560 | } else { |
| 561 | ir->nec_gpio = nec_gpio; |
| 562 | ir->rc5_gpio = rc5_gpio; |
| 563 | } |
| 564 | |
| 565 | return 0; |
| 566 | } |
| 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | int saa7134_input_init1(struct saa7134_dev *dev) |
| 569 | { |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 570 | struct card_ir *ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 571 | struct rc_dev *rc; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 572 | char *ir_codes = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | u32 mask_keycode = 0; |
| 574 | u32 mask_keydown = 0; |
| 575 | u32 mask_keyup = 0; |
| 576 | int polling = 0; |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 577 | int rc5_gpio = 0; |
| 578 | int nec_gpio = 0; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 579 | int raw_decode = 0; |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 580 | int allow_protocol_change = 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 581 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | |
Ricardo Cerqueira | cb2444d | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 583 | if (dev->has_remote != SAA7134_REMOTE_GPIO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | return -ENODEV; |
| 585 | if (disable_ir) |
| 586 | return -ENODEV; |
| 587 | |
| 588 | /* detect & configure */ |
| 589 | switch (dev->board) { |
| 590 | case SAA7134_BOARD_FLYVIDEO2000: |
| 591 | case SAA7134_BOARD_FLYVIDEO3000: |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 592 | case SAA7134_BOARD_FLYTVPLATINUM_FM: |
Arnaud Patard | 6af90ab | 2005-11-08 21:36:55 -0800 | [diff] [blame] | 593 | case SAA7134_BOARD_FLYTVPLATINUM_MINI2: |
Eugene Yudin | 23389b8 | 2009-08-29 09:32:11 -0300 | [diff] [blame] | 594 | case SAA7134_BOARD_ROVERMEDIA_LINK_PRO_FM: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 595 | ir_codes = RC_MAP_FLYVIDEO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | mask_keycode = 0xEC00000; |
| 597 | mask_keydown = 0x0040000; |
| 598 | break; |
| 599 | case SAA7134_BOARD_CINERGY400: |
| 600 | case SAA7134_BOARD_CINERGY600: |
| 601 | case SAA7134_BOARD_CINERGY600_MK3: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 602 | ir_codes = RC_MAP_CINERGY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | mask_keycode = 0x00003f; |
| 604 | mask_keyup = 0x040000; |
| 605 | break; |
| 606 | case SAA7134_BOARD_ECS_TVP3XP: |
| 607 | case SAA7134_BOARD_ECS_TVP3XP_4CB5: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 608 | ir_codes = RC_MAP_EZTV; |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 609 | mask_keycode = 0x00017c; |
| 610 | mask_keyup = 0x000002; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | polling = 50; // ms |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 612 | break; |
| 613 | case SAA7134_BOARD_KWORLD_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | case SAA7134_BOARD_AVACSSMARTTV: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 615 | ir_codes = RC_MAP_PIXELVIEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | mask_keycode = 0x00001F; |
| 617 | mask_keyup = 0x000020; |
| 618 | polling = 50; // ms |
| 619 | break; |
| 620 | case SAA7134_BOARD_MD2819: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 621 | case SAA7134_BOARD_KWORLD_VSTREAM_XPERT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | case SAA7134_BOARD_AVERMEDIA_305: |
| 623 | case SAA7134_BOARD_AVERMEDIA_307: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 624 | case SAA7134_BOARD_AVERMEDIA_STUDIO_305: |
Vasiliy Temnikov | 5a5e1da | 2009-08-26 22:10:55 -0300 | [diff] [blame] | 625 | case SAA7134_BOARD_AVERMEDIA_STUDIO_505: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 626 | case SAA7134_BOARD_AVERMEDIA_STUDIO_307: |
Mikhail Fedotov | 3ac706d | 2006-10-06 20:23:47 -0300 | [diff] [blame] | 627 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507: |
Andy Shevchenko | df0dbbe | 2009-04-08 14:01:19 -0300 | [diff] [blame] | 628 | case SAA7134_BOARD_AVERMEDIA_STUDIO_507UA: |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 629 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM: |
Albert Graham | d2761f2 | 2007-12-09 09:44:38 -0300 | [diff] [blame] | 630 | case SAA7134_BOARD_AVERMEDIA_M102: |
Pham Thanh Nam | 6a2d802 | 2008-12-30 23:26:09 -0300 | [diff] [blame] | 631 | case SAA7134_BOARD_AVERMEDIA_GO_007_FM_PLUS: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 632 | ir_codes = RC_MAP_AVERMEDIA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | mask_keycode = 0x0007C8; |
| 634 | mask_keydown = 0x000010; |
| 635 | polling = 50; // ms |
| 636 | /* Set GPIO pin2 to high to enable the IR controller */ |
| 637 | saa_setb(SAA7134_GPIO_GPMODE0, 0x4); |
| 638 | saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); |
| 639 | break; |
Mauro Carvalho Chehab | 36f6bb9 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 640 | case SAA7134_BOARD_AVERMEDIA_M135A: |
Herton Ronaldo Krzesinski | 63fc31e | 2010-05-10 15:43:31 -0300 | [diff] [blame] | 641 | ir_codes = RC_MAP_AVERMEDIA_M135A; |
Mauro Carvalho Chehab | 2f16f63 | 2010-04-03 18:51:50 -0300 | [diff] [blame] | 642 | mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */ |
| 643 | mask_keyup = 0x0040000; |
Mauro Carvalho Chehab | d152b8b | 2010-03-20 00:23:30 -0300 | [diff] [blame] | 644 | mask_keycode = 0xffff; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 645 | raw_decode = 1; |
Mauro Carvalho Chehab | 36f6bb9 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 646 | break; |
Herton Ronaldo Krzesinski | 9e1d9e7 | 2010-05-08 02:23:37 -0300 | [diff] [blame] | 647 | case SAA7134_BOARD_AVERMEDIA_M733A: |
| 648 | ir_codes = RC_MAP_AVERMEDIA_M733A_RM_K6; |
| 649 | mask_keydown = 0x0040000; |
| 650 | mask_keyup = 0x0040000; |
| 651 | mask_keycode = 0xffff; |
| 652 | raw_decode = 1; |
| 653 | break; |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 654 | case SAA7134_BOARD_AVERMEDIA_777: |
pasky@ucw.cz | 29e0f1a | 2006-11-12 14:23:32 -0300 | [diff] [blame] | 655 | case SAA7134_BOARD_AVERMEDIA_A16AR: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 656 | ir_codes = RC_MAP_AVERMEDIA; |
pasky@ucw.cz | 450efcf | 2006-11-12 14:22:32 -0300 | [diff] [blame] | 657 | mask_keycode = 0x02F200; |
| 658 | mask_keydown = 0x000400; |
| 659 | polling = 50; // ms |
| 660 | /* Without this we won't receive key up events */ |
| 661 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 662 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
Linus Torvalds | 4dd7406 | 2006-11-13 09:50:11 -0800 | [diff] [blame] | 663 | break; |
Tim Farrington | 6e501a3 | 2008-06-15 13:33:42 -0300 | [diff] [blame] | 664 | case SAA7134_BOARD_AVERMEDIA_A16D: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 665 | ir_codes = RC_MAP_AVERMEDIA_A16D; |
Tim Farrington | 6e501a3 | 2008-06-15 13:33:42 -0300 | [diff] [blame] | 666 | mask_keycode = 0x02F200; |
| 667 | mask_keydown = 0x000400; |
| 668 | polling = 50; /* ms */ |
| 669 | /* Without this we won't receive key up events */ |
| 670 | saa_setb(SAA7134_GPIO_GPMODE1, 0x1); |
| 671 | saa_setb(SAA7134_GPIO_GPSTATUS1, 0x1); |
| 672 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 673 | case SAA7134_BOARD_KWORLD_TERMINATOR: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 674 | ir_codes = RC_MAP_PIXELVIEW; |
James R. Webb | dc2286c | 2005-11-08 21:37:00 -0800 | [diff] [blame] | 675 | mask_keycode = 0x00001f; |
| 676 | mask_keyup = 0x000060; |
| 677 | polling = 50; // ms |
| 678 | break; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 679 | case SAA7134_BOARD_MANLI_MTV001: |
| 680 | case SAA7134_BOARD_MANLI_MTV002: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 681 | ir_codes = RC_MAP_MANLI; |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 682 | mask_keycode = 0x001f00; |
| 683 | mask_keyup = 0x004000; |
| 684 | polling = 50; /* ms */ |
| 685 | break; |
Nickolay V. Shmyrev | a8ff417 | 2005-11-08 21:36:16 -0800 | [diff] [blame] | 686 | case SAA7134_BOARD_BEHOLD_409FM: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 687 | case SAA7134_BOARD_BEHOLD_401: |
| 688 | case SAA7134_BOARD_BEHOLD_403: |
| 689 | case SAA7134_BOARD_BEHOLD_403FM: |
| 690 | case SAA7134_BOARD_BEHOLD_405: |
| 691 | case SAA7134_BOARD_BEHOLD_405FM: |
| 692 | case SAA7134_BOARD_BEHOLD_407: |
| 693 | case SAA7134_BOARD_BEHOLD_407FM: |
| 694 | case SAA7134_BOARD_BEHOLD_409: |
| 695 | case SAA7134_BOARD_BEHOLD_505FM: |
Dmitri Belimov | 9c6f97a | 2009-12-21 02:00:38 -0300 | [diff] [blame] | 696 | case SAA7134_BOARD_BEHOLD_505RDS_MK5: |
| 697 | case SAA7134_BOARD_BEHOLD_505RDS_MK3: |
Andrey J. Melnikoff (TEMHOTA) | e8018c9 | 2008-01-07 05:17:39 -0300 | [diff] [blame] | 698 | case SAA7134_BOARD_BEHOLD_507_9FM: |
Dmitri Belimov | 84d728c | 2009-04-23 02:32:49 -0300 | [diff] [blame] | 699 | case SAA7134_BOARD_BEHOLD_507RDS_MK3: |
| 700 | case SAA7134_BOARD_BEHOLD_507RDS_MK5: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 701 | ir_codes = RC_MAP_MANLI; |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 702 | mask_keycode = 0x003f00; |
| 703 | mask_keyup = 0x004000; |
| 704 | polling = 50; /* ms */ |
| 705 | break; |
| 706 | case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 707 | ir_codes = RC_MAP_BEHOLD_COLUMBUS; |
Dmitry Belimov | b34dddb | 2008-04-23 14:09:08 -0300 | [diff] [blame] | 708 | mask_keycode = 0x003f00; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 709 | mask_keyup = 0x004000; |
Mauro Carvalho Chehab | ac19ecc | 2005-06-23 22:05:09 -0700 | [diff] [blame] | 710 | polling = 50; // ms |
| 711 | break; |
Ricardo Cerqueira | 17ce1ff | 2005-11-08 21:38:47 -0800 | [diff] [blame] | 712 | case SAA7134_BOARD_SEDNA_PC_TV_CARDBUS: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 713 | ir_codes = RC_MAP_PCTV_SEDNA; |
Pavel Mihaylov | c3d9319 | 2005-11-08 21:38:43 -0800 | [diff] [blame] | 714 | mask_keycode = 0x001f00; |
| 715 | mask_keyup = 0x004000; |
| 716 | polling = 50; // ms |
| 717 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 718 | case SAA7134_BOARD_GOTVIEW_7135: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 719 | ir_codes = RC_MAP_GOTVIEW7135; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 720 | mask_keycode = 0x0003CC; |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 721 | mask_keydown = 0x000010; |
Pedro | 0938e31 | 2007-10-17 17:58:40 -0300 | [diff] [blame] | 722 | polling = 5; /* ms */ |
| 723 | saa_setb(SAA7134_GPIO_GPMODE1, 0x80); |
Nickolay V. Shmyrev | 6b96144 | 2005-11-08 21:36:22 -0800 | [diff] [blame] | 724 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | case SAA7134_BOARD_VIDEOMATE_TV_PVR: |
Nickolay V. Shmyrev | 2a9a9a8 | 2006-01-09 15:25:33 -0200 | [diff] [blame] | 726 | case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: |
Mauro Carvalho Chehab | 330a115 | 2005-07-12 13:59:01 -0700 | [diff] [blame] | 727 | case SAA7134_BOARD_VIDEOMATE_TV_GOLD_PLUSII: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 728 | ir_codes = RC_MAP_VIDEOMATE_TV_PVR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | mask_keycode = 0x00003F; |
| 730 | mask_keyup = 0x400000; |
| 731 | polling = 50; // ms |
| 732 | break; |
Michal Majchrowicz | b04c1ba | 2006-09-13 16:42:42 -0300 | [diff] [blame] | 733 | case SAA7134_BOARD_PROTEUS_2309: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 734 | ir_codes = RC_MAP_PROTEUS_2309; |
Michal Majchrowicz | b04c1ba | 2006-09-13 16:42:42 -0300 | [diff] [blame] | 735 | mask_keycode = 0x00007F; |
| 736 | mask_keyup = 0x000080; |
| 737 | polling = 50; // ms |
| 738 | break; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 739 | case SAA7134_BOARD_VIDEOMATE_DVBT_300: |
| 740 | case SAA7134_BOARD_VIDEOMATE_DVBT_200: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 741 | ir_codes = RC_MAP_VIDEOMATE_TV_PVR; |
Nickolay V. Shmyrev | fea095f | 2005-11-08 21:36:47 -0800 | [diff] [blame] | 742 | mask_keycode = 0x003F00; |
| 743 | mask_keyup = 0x040000; |
| 744 | break; |
James Le Cuirot | f5c965a | 2007-07-02 12:53:25 -0300 | [diff] [blame] | 745 | case SAA7134_BOARD_FLYDVBS_LR300: |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 746 | case SAA7134_BOARD_FLYDVBT_LR301: |
Rudo Thomas | a802917 | 2006-02-27 00:08:46 -0300 | [diff] [blame] | 747 | case SAA7134_BOARD_FLYDVBTDUO: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 748 | ir_codes = RC_MAP_FLYDVB; |
Giampiero Giancipoli | 3d8466e | 2006-02-07 06:49:09 -0200 | [diff] [blame] | 749 | mask_keycode = 0x0001F00; |
| 750 | mask_keydown = 0x0040000; |
| 751 | break; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 752 | case SAA7134_BOARD_ASUSTeK_P7131_DUAL: |
Ed Vipas | 904ab88 | 2007-03-29 18:32:49 -0300 | [diff] [blame] | 753 | case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: |
Mauro Carvalho Chehab | dfb4ba1 | 2009-08-20 10:13:40 -0300 | [diff] [blame] | 754 | case SAA7134_BOARD_ASUSTeK_P7131_ANALOG: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 755 | ir_codes = RC_MAP_ASUS_PC39; |
Mauro Carvalho Chehab | fe8b6713 | 2010-09-30 14:46:47 -0300 | [diff] [blame] | 756 | mask_keydown = 0x0040000; /* Enable GPIO18 line on both edges */ |
| 757 | mask_keyup = 0x0040000; |
| 758 | mask_keycode = 0xffff; |
| 759 | raw_decode = 1; |
Hermann Pitton | 9160723 | 2006-12-07 21:45:28 -0300 | [diff] [blame] | 760 | break; |
Juan Pablo Sormani | c36c459 | 2006-12-27 12:46:36 -0300 | [diff] [blame] | 761 | case SAA7134_BOARD_ENCORE_ENLTV: |
| 762 | case SAA7134_BOARD_ENCORE_ENLTV_FM: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 763 | ir_codes = RC_MAP_ENCORE_ENLTV; |
Juan Pablo Sormani | c36c459 | 2006-12-27 12:46:36 -0300 | [diff] [blame] | 764 | mask_keycode = 0x00007f; |
| 765 | mask_keyup = 0x040000; |
| 766 | polling = 50; // ms |
| 767 | break; |
Mauro Carvalho Chehab | bf1ece6 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 768 | case SAA7134_BOARD_ENCORE_ENLTV_FM53: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 769 | ir_codes = RC_MAP_ENCORE_ENLTV_FM53; |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 770 | mask_keydown = 0x0040000; |
| 771 | mask_keycode = 0x00007f; |
| 772 | nec_gpio = 1; |
Mauro Carvalho Chehab | bf1ece6 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 773 | break; |
Tony Wan | 480f75a | 2007-05-11 11:33:50 -0300 | [diff] [blame] | 774 | case SAA7134_BOARD_10MOONSTVMASTER3: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 775 | ir_codes = RC_MAP_ENCORE_ENLTV; |
Tony Wan | 480f75a | 2007-05-11 11:33:50 -0300 | [diff] [blame] | 776 | mask_keycode = 0x5f80000; |
| 777 | mask_keyup = 0x8000000; |
| 778 | polling = 50; //ms |
| 779 | break; |
Adrian Pardini | f0ba356 | 2008-02-11 12:40:53 -0300 | [diff] [blame] | 780 | case SAA7134_BOARD_GENIUS_TVGO_A11MCE: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 781 | ir_codes = RC_MAP_GENIUS_TVGO_A11MCE; |
Adrian Pardini | f0ba356 | 2008-02-11 12:40:53 -0300 | [diff] [blame] | 782 | mask_keycode = 0xff; |
| 783 | mask_keydown = 0xf00000; |
| 784 | polling = 50; /* ms */ |
| 785 | break; |
Mauro Carvalho Chehab | 9b00019 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 786 | case SAA7134_BOARD_REAL_ANGEL_220: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 787 | ir_codes = RC_MAP_REAL_AUDIO_220_32_KEYS; |
Mauro Carvalho Chehab | 9b00019 | 2008-06-26 17:03:00 -0300 | [diff] [blame] | 788 | mask_keycode = 0x3f00; |
| 789 | mask_keyup = 0x4000; |
| 790 | polling = 50; /* ms */ |
| 791 | break; |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 792 | case SAA7134_BOARD_KWORLD_PLUS_TV_ANALOG: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 793 | ir_codes = RC_MAP_KWORLD_PLUS_TV_ANALOG; |
Mauro Carvalho Chehab | 26d5f3a | 2008-12-07 13:19:29 -0300 | [diff] [blame] | 794 | mask_keycode = 0x7f; |
| 795 | polling = 40; /* ms */ |
| 796 | break; |
Igor M. Liplianin | ecfcfec | 2009-08-13 21:42:21 -0300 | [diff] [blame] | 797 | case SAA7134_BOARD_VIDEOMATE_S350: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 798 | ir_codes = RC_MAP_VIDEOMATE_S350; |
Igor M. Liplianin | ecfcfec | 2009-08-13 21:42:21 -0300 | [diff] [blame] | 799 | mask_keycode = 0x003f00; |
| 800 | mask_keydown = 0x040000; |
| 801 | break; |
Michael Obst | 0700ade | 2009-10-31 14:05:42 -0300 | [diff] [blame] | 802 | case SAA7134_BOARD_LEADTEK_WINFAST_DTV1000S: |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 803 | ir_codes = RC_MAP_WINFAST; |
Michael Obst | 0700ade | 2009-10-31 14:05:42 -0300 | [diff] [blame] | 804 | mask_keycode = 0x5f00; |
| 805 | mask_keyup = 0x020000; |
Michael Krufky | 117e134 | 2009-11-01 11:16:10 -0300 | [diff] [blame] | 806 | polling = 50; /* ms */ |
Michael Obst | 0700ade | 2009-10-31 14:05:42 -0300 | [diff] [blame] | 807 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | if (NULL == ir_codes) { |
| 810 | printk("%s: Oops: IR config error [card=%d]\n", |
| 811 | dev->name, dev->board); |
| 812 | return -ENODEV; |
| 813 | } |
| 814 | |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 815 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 816 | rc = rc_allocate_device(); |
| 817 | if (!ir || !rc) { |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 818 | err = -ENOMEM; |
| 819 | goto err_out_free; |
Dmitry Torokhov | b7df391 | 2005-09-15 02:01:53 -0500 | [diff] [blame] | 820 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 822 | ir->dev = rc; |
Mauro Carvalho Chehab | 0210894 | 2010-03-20 00:25:37 -0300 | [diff] [blame] | 823 | dev->remote = ir; |
| 824 | |
| 825 | ir->running = 0; |
Dmitry Torokhov | d271d1c | 2005-11-20 00:56:54 -0500 | [diff] [blame] | 826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 827 | /* init hardware-specific stuff */ |
| 828 | ir->mask_keycode = mask_keycode; |
| 829 | ir->mask_keydown = mask_keydown; |
| 830 | ir->mask_keyup = mask_keyup; |
Mauro Carvalho Chehab | 4ac9791 | 2005-11-08 21:37:43 -0800 | [diff] [blame] | 831 | ir->polling = polling; |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 832 | ir->rc5_gpio = rc5_gpio; |
| 833 | ir->nec_gpio = nec_gpio; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 834 | ir->raw_decode = raw_decode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | /* init input device */ |
| 837 | snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", |
| 838 | saa7134_boards[dev->board].name); |
| 839 | snprintf(ir->phys, sizeof(ir->phys), "pci-%s/ir0", |
| 840 | pci_name(dev->pci)); |
| 841 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 842 | rc->priv = dev; |
| 843 | rc->open = saa7134_ir_open; |
| 844 | rc->close = saa7134_ir_close; |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 845 | if (raw_decode) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 846 | rc->driver_type = RC_DRIVER_IR_RAW; |
Mauro Carvalho Chehab | 626cf69 | 2010-04-06 23:21:46 -0300 | [diff] [blame] | 847 | |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 848 | if (!raw_decode && allow_protocol_change) { |
| 849 | rc->allowed_protos = IR_TYPE_RC5 | IR_TYPE_NEC; |
| 850 | rc->change_protocol = saa7134_ir_change_protocol; |
| 851 | } |
| 852 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 853 | rc->input_name = ir->name; |
| 854 | rc->input_phys = ir->phys; |
| 855 | rc->input_id.bustype = BUS_PCI; |
| 856 | rc->input_id.version = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | if (dev->pci->subsystem_vendor) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 858 | rc->input_id.vendor = dev->pci->subsystem_vendor; |
| 859 | rc->input_id.product = dev->pci->subsystem_device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } else { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 861 | rc->input_id.vendor = dev->pci->vendor; |
| 862 | rc->input_id.product = dev->pci->device; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 864 | rc->dev.parent = &dev->pci->dev; |
| 865 | rc->map_name = ir_codes; |
| 866 | rc->driver_name = MODULE_NAME; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 868 | err = rc_register_device(rc); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 869 | if (err) |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 870 | goto err_out_free; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 871 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 872 | return 0; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 873 | |
Mauro Carvalho Chehab | 716aab4 | 2010-03-31 14:40:35 -0300 | [diff] [blame] | 874 | err_out_free: |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 875 | rc_free_device(rc); |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 876 | dev->remote = NULL; |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 877 | kfree(ir); |
| 878 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | void saa7134_input_fini(struct saa7134_dev *dev) |
| 882 | { |
| 883 | if (NULL == dev->remote) |
| 884 | return; |
| 885 | |
Dmitry Torokhov | b07b478 | 2006-11-20 10:23:04 -0300 | [diff] [blame] | 886 | saa7134_ir_stop(dev); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 887 | rc_unregister_device(dev->remote->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | kfree(dev->remote); |
| 889 | dev->remote = NULL; |
| 890 | } |
| 891 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 892 | void saa7134_probe_i2c_ir(struct saa7134_dev *dev) |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 893 | { |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 894 | struct i2c_board_info info; |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 895 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 896 | struct i2c_msg msg_msi = { |
| 897 | .addr = 0x50, |
| 898 | .flags = I2C_M_RD, |
| 899 | .len = 0, |
| 900 | .buf = NULL, |
| 901 | }; |
| 902 | |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 903 | int rc; |
| 904 | |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 905 | if (disable_ir) { |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 906 | dprintk("IR has been disabled, not probing for i2c remote\n"); |
Ricardo Cerqueira | ac9cd97 | 2005-11-08 21:37:56 -0800 | [diff] [blame] | 907 | return; |
| 908 | } |
| 909 | |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 910 | memset(&info, 0, sizeof(struct i2c_board_info)); |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 911 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 912 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 913 | |
| 914 | switch (dev->board) { |
| 915 | case SAA7134_BOARD_PINNACLE_PCTV_110i: |
| 916 | case SAA7134_BOARD_PINNACLE_PCTV_310i: |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 917 | dev->init_data.name = "Pinnacle PCTV"; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 918 | if (pinnacle_remote == 0) { |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 919 | dev->init_data.get_key = get_key_pinnacle_color; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 920 | dev->init_data.ir_codes = RC_MAP_PINNACLE_COLOR; |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 921 | info.addr = 0x47; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 922 | } else { |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 923 | dev->init_data.get_key = get_key_pinnacle_grey; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 924 | dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY; |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 925 | info.addr = 0x47; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 926 | } |
| 927 | break; |
| 928 | case SAA7134_BOARD_UPMOST_PURPLE_TV: |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 929 | dev->init_data.name = "Purple TV"; |
| 930 | dev->init_data.get_key = get_key_purpletv; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 931 | dev->init_data.ir_codes = RC_MAP_PURPLETV; |
Jean Delvare | aef02aa | 2009-10-02 08:47:22 -0300 | [diff] [blame] | 932 | info.addr = 0x7a; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 933 | break; |
| 934 | case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS: |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 935 | dev->init_data.name = "MSI TV@nywhere Plus"; |
| 936 | dev->init_data.get_key = get_key_msi_tvanywhere_plus; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 937 | dev->init_data.ir_codes = RC_MAP_MSI_TVANYWHERE_PLUS; |
Mauro Carvalho Chehab | c72ba8e | 2010-09-23 01:23:10 -0300 | [diff] [blame] | 938 | /* |
| 939 | * MSI TV@nyware Plus requires more frequent polling |
| 940 | * otherwise it will miss some keypresses |
| 941 | */ |
| 942 | dev->init_data.polling_interval = 50; |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 943 | info.addr = 0x30; |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 944 | /* MSI TV@nywhere Plus controller doesn't seem to |
| 945 | respond to probes unless we read something from |
| 946 | an existing device. Weird... |
| 947 | REVISIT: might no longer be needed */ |
| 948 | rc = i2c_transfer(&dev->i2c_adap, &msg_msi, 1); |
Joe Perches | c429e7b | 2010-10-25 23:44:25 -0300 | [diff] [blame] | 949 | dprintk("probe 0x%02x @ %s: %s\n", |
Jean Delvare | ec218a4 | 2009-05-13 16:51:46 -0300 | [diff] [blame] | 950 | msg_msi.addr, dev->i2c_adap.name, |
| 951 | (1 == rc) ? "yes" : "no"); |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 952 | break; |
| 953 | case SAA7134_BOARD_HAUPPAUGE_HVR1110: |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 954 | dev->init_data.name = "HVR 1110"; |
| 955 | dev->init_data.get_key = get_key_hvr1110; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 956 | dev->init_data.ir_codes = RC_MAP_HAUPPAUGE_NEW; |
Jean Delvare | 30093e8 | 2009-10-02 09:48:04 -0300 | [diff] [blame] | 957 | info.addr = 0x71; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 958 | break; |
| 959 | case SAA7134_BOARD_BEHOLD_607FM_MK3: |
| 960 | case SAA7134_BOARD_BEHOLD_607FM_MK5: |
| 961 | case SAA7134_BOARD_BEHOLD_609FM_MK3: |
| 962 | case SAA7134_BOARD_BEHOLD_609FM_MK5: |
| 963 | case SAA7134_BOARD_BEHOLD_607RDS_MK3: |
| 964 | case SAA7134_BOARD_BEHOLD_607RDS_MK5: |
| 965 | case SAA7134_BOARD_BEHOLD_609RDS_MK3: |
| 966 | case SAA7134_BOARD_BEHOLD_609RDS_MK5: |
| 967 | case SAA7134_BOARD_BEHOLD_M6: |
| 968 | case SAA7134_BOARD_BEHOLD_M63: |
| 969 | case SAA7134_BOARD_BEHOLD_M6_EXTRA: |
| 970 | case SAA7134_BOARD_BEHOLD_H6: |
Dmitri Belimov | 2012c87f | 2009-08-26 01:01:12 -0300 | [diff] [blame] | 971 | case SAA7134_BOARD_BEHOLD_X7: |
Dmitri Belimov | 0faa2ed | 2010-04-06 01:00:05 -0300 | [diff] [blame] | 972 | case SAA7134_BOARD_BEHOLD_H7: |
| 973 | case SAA7134_BOARD_BEHOLD_A7: |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 974 | dev->init_data.name = "BeholdTV"; |
| 975 | dev->init_data.get_key = get_key_beholdm6xx; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 976 | dev->init_data.ir_codes = RC_MAP_BEHOLD; |
Dmitri Belimov | 2ffbb64 | 2010-03-04 02:40:37 -0300 | [diff] [blame] | 977 | dev->init_data.type = IR_TYPE_NEC; |
Jean Delvare | 30093e8 | 2009-10-02 09:48:04 -0300 | [diff] [blame] | 978 | info.addr = 0x2d; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 979 | break; |
Jean Delvare | d9a88e6 | 2009-05-13 16:52:44 -0300 | [diff] [blame] | 980 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_501: |
| 981 | case SAA7134_BOARD_AVERMEDIA_CARDBUS_506: |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 982 | info.addr = 0x40; |
Jean Delvare | d9a88e6 | 2009-05-13 16:52:44 -0300 | [diff] [blame] | 983 | break; |
Lukas Karas | d995a18 | 2009-11-24 12:06:52 -0300 | [diff] [blame] | 984 | case SAA7134_BOARD_FLYDVB_TRIO: |
| 985 | dev->init_data.name = "FlyDVB Trio"; |
| 986 | dev->init_data.get_key = get_key_flydvb_trio; |
Mauro Carvalho Chehab | 02858ee | 2010-04-02 20:01:00 -0300 | [diff] [blame] | 987 | dev->init_data.ir_codes = RC_MAP_FLYDVB; |
Lukas Karas | d995a18 | 2009-11-24 12:06:52 -0300 | [diff] [blame] | 988 | info.addr = 0x0b; |
| 989 | break; |
Jean Delvare | 30093e8 | 2009-10-02 09:48:04 -0300 | [diff] [blame] | 990 | default: |
| 991 | dprintk("No I2C IR support for board %x\n", dev->board); |
| 992 | return; |
Jean Delvare | 4d7a2d6 | 2009-05-13 16:49:32 -0300 | [diff] [blame] | 993 | } |
| 994 | |
Mauro Carvalho Chehab | 7aedd5ec | 2009-09-07 02:22:01 -0300 | [diff] [blame] | 995 | if (dev->init_data.name) |
Jean Delvare | 43e16ea | 2009-10-02 05:47:08 -0300 | [diff] [blame] | 996 | info.platform_data = &dev->init_data; |
Jean Delvare | 30093e8 | 2009-10-02 09:48:04 -0300 | [diff] [blame] | 997 | i2c_new_device(&dev->i2c_adap, &info); |
Jean Delvare | c668f32 | 2009-05-13 16:48:50 -0300 | [diff] [blame] | 998 | } |
| 999 | |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1000 | static int saa7134_raw_decode_irq(struct saa7134_dev *dev) |
| 1001 | { |
| 1002 | struct card_ir *ir = dev->remote; |
| 1003 | unsigned long timeout; |
Mauro Carvalho Chehab | 2f16f63 | 2010-04-03 18:51:50 -0300 | [diff] [blame] | 1004 | int space; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1005 | |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1006 | /* Generate initial event */ |
| 1007 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 1008 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
Mauro Carvalho Chehab | 2f16f63 | 2010-04-03 18:51:50 -0300 | [diff] [blame] | 1009 | space = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; |
David Härdeman | 724e249 | 2010-04-08 13:10:00 -0300 | [diff] [blame] | 1010 | ir_raw_event_store_edge(dev->remote->dev, space ? IR_SPACE : IR_PULSE); |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1011 | |
Mauro Carvalho Chehab | 9f15478 | 2010-03-21 13:00:55 -0300 | [diff] [blame] | 1012 | |
| 1013 | /* |
| 1014 | * Wait 15 ms from the start of the first IR event before processing |
| 1015 | * the event. This time is enough for NEC protocol. May need adjustments |
| 1016 | * to work with other protocols. |
| 1017 | */ |
| 1018 | if (!ir->active) { |
| 1019 | timeout = jiffies + jiffies_to_msecs(15); |
| 1020 | mod_timer(&ir->timer_end, timeout); |
| 1021 | ir->active = 1; |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1022 | } |
| 1023 | |
Mauro Carvalho Chehab | a3572c3 | 2010-03-20 20:59:44 -0300 | [diff] [blame] | 1024 | return 1; |
| 1025 | } |
Mauro Carvalho Chehab | 8ea43d0 | 2010-11-13 16:49:10 -0300 | [diff] [blame^] | 1026 | |
| 1027 | static int saa7134_rc5_irq(struct saa7134_dev *dev) |
| 1028 | { |
| 1029 | struct card_ir *ir = dev->remote; |
| 1030 | struct timeval tv; |
| 1031 | u32 gap; |
| 1032 | unsigned long current_jiffies, timeout; |
| 1033 | |
| 1034 | /* get time of bit */ |
| 1035 | current_jiffies = jiffies; |
| 1036 | do_gettimeofday(&tv); |
| 1037 | |
| 1038 | /* avoid overflow with gap >1s */ |
| 1039 | if (tv.tv_sec - ir->base_time.tv_sec > 1) { |
| 1040 | gap = 200000; |
| 1041 | } else { |
| 1042 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 1043 | tv.tv_usec - ir->base_time.tv_usec; |
| 1044 | } |
| 1045 | |
| 1046 | /* active code => add bit */ |
| 1047 | if (ir->active) { |
| 1048 | /* only if in the code (otherwise spurious IRQ or timer |
| 1049 | late) */ |
| 1050 | if (ir->last_bit < 28) { |
| 1051 | ir->last_bit = (gap - ir_rc5_remote_gap / 2) / |
| 1052 | ir_rc5_remote_gap; |
| 1053 | ir->code |= 1 << ir->last_bit; |
| 1054 | } |
| 1055 | /* starting new code */ |
| 1056 | } else { |
| 1057 | ir->active = 1; |
| 1058 | ir->code = 0; |
| 1059 | ir->base_time = tv; |
| 1060 | ir->last_bit = 0; |
| 1061 | |
| 1062 | timeout = current_jiffies + (500 + 30 * HZ) / 1000; |
| 1063 | mod_timer(&ir->timer_end, timeout); |
| 1064 | } |
| 1065 | |
| 1066 | return 1; |
| 1067 | } |
| 1068 | |
| 1069 | static void nec_task(unsigned long data) |
| 1070 | { |
| 1071 | struct saa7134_dev *dev = (struct saa7134_dev *) data; |
| 1072 | struct card_ir *ir; |
| 1073 | struct timeval tv; |
| 1074 | int count, pulse, oldpulse, gap; |
| 1075 | u32 ircode = 0, not_code = 0; |
| 1076 | int ngap = 0; |
| 1077 | |
| 1078 | if (!data) { |
| 1079 | printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n"); |
| 1080 | /* GPIO will be kept disabled */ |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | ir = dev->remote; |
| 1085 | |
| 1086 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 1087 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 1088 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 1089 | |
| 1090 | oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown; |
| 1091 | pulse = oldpulse; |
| 1092 | |
| 1093 | do_gettimeofday(&tv); |
| 1094 | ir->base_time = tv; |
| 1095 | |
| 1096 | /* Decode NEC pulsecode. This code can take up to 76.5 ms to run. |
| 1097 | Unfortunately, using IRQ to decode pulse didn't work, since it uses |
| 1098 | a pulse train of 38KHz. This means one pulse on each 52 us |
| 1099 | */ |
| 1100 | do { |
| 1101 | /* Wait until the end of pulse/space or 5 ms */ |
| 1102 | for (count = 0; count < 500; count++) { |
| 1103 | udelay(10); |
| 1104 | /* rising SAA7134_GPIO_GPRESCAN reads the status */ |
| 1105 | saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 1106 | saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN); |
| 1107 | pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) |
| 1108 | & ir->mask_keydown; |
| 1109 | if (pulse != oldpulse) |
| 1110 | break; |
| 1111 | } |
| 1112 | |
| 1113 | do_gettimeofday(&tv); |
| 1114 | gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) + |
| 1115 | tv.tv_usec - ir->base_time.tv_usec; |
| 1116 | |
| 1117 | if (!pulse) { |
| 1118 | /* Bit 0 has 560 us, while bit 1 has 1120 us. |
| 1119 | Do something only if bit == 1 |
| 1120 | */ |
| 1121 | if (ngap && (gap > 560 + 280)) { |
| 1122 | unsigned int shift = ngap - 1; |
| 1123 | |
| 1124 | /* Address first, then command */ |
| 1125 | if (shift < 8) { |
| 1126 | shift += 8; |
| 1127 | ircode |= 1 << shift; |
| 1128 | } else if (shift < 16) { |
| 1129 | not_code |= 1 << shift; |
| 1130 | } else if (shift < 24) { |
| 1131 | shift -= 16; |
| 1132 | ircode |= 1 << shift; |
| 1133 | } else { |
| 1134 | shift -= 24; |
| 1135 | not_code |= 1 << shift; |
| 1136 | } |
| 1137 | } |
| 1138 | ngap++; |
| 1139 | } |
| 1140 | |
| 1141 | |
| 1142 | ir->base_time = tv; |
| 1143 | |
| 1144 | /* TIMEOUT - Long pulse */ |
| 1145 | if (gap >= 5000) |
| 1146 | break; |
| 1147 | oldpulse = pulse; |
| 1148 | } while (ngap < 32); |
| 1149 | |
| 1150 | if (ngap == 32) { |
| 1151 | /* FIXME: should check if not_code == ~ircode */ |
| 1152 | ir->code = ir_extract_bits(ircode, ir->mask_keycode); |
| 1153 | |
| 1154 | dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n", |
| 1155 | ir->code, ircode, not_code); |
| 1156 | |
| 1157 | ir_keydown(ir->dev, ir->code, 0); |
| 1158 | } else { |
| 1159 | dprintk("Repeat last key\n"); |
| 1160 | ir_repeat(ir->dev); |
| 1161 | } |
| 1162 | |
| 1163 | saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P); |
| 1164 | } |
| 1165 | |
| 1166 | static int saa7134_nec_irq(struct saa7134_dev *dev) |
| 1167 | { |
| 1168 | struct card_ir *ir = dev->remote; |
| 1169 | |
| 1170 | saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18_P); |
| 1171 | tasklet_schedule(&ir->tlet); |
| 1172 | |
| 1173 | return 1; |
| 1174 | } |