Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 2 | handle em28xx IR remotes via linux kernel input layer. |
| 3 | |
| 4 | Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> |
| 5 | Markus Rechberger <mrechberger@gmail.com> |
Mauro Carvalho Chehab | 2e7c6dc | 2006-04-03 07:53:40 -0300 | [diff] [blame] | 6 | Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 7 | Sascha Sommer <saschasommer@freenet.de> |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 25 | #include <linux/init.h> |
| 26 | #include <linux/delay.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 27 | #include <linux/interrupt.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 28 | #include <linux/usb.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 30 | |
Mauro Carvalho Chehab | f7abcd3 | 2005-11-08 21:38:25 -0800 | [diff] [blame] | 31 | #include "em28xx.h" |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 32 | |
Devin Heitmueller | a9fc52b | 2008-06-28 08:57:06 -0300 | [diff] [blame] | 33 | #define EM28XX_SNAPSHOT_KEY KEY_CAMERA |
| 34 | #define EM28XX_SBUTTON_QUERY_INTERVAL 500 |
| 35 | #define EM28XX_R0C_USBSUSP_SNAPSHOT 0x20 |
| 36 | |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 37 | static unsigned int ir_debug; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 38 | module_param(ir_debug, int, 0644); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 39 | MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | 727e625 | 2010-03-12 21:18:14 -0300 | [diff] [blame] | 41 | #define MODULE_NAME "em28xx" |
| 42 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 43 | #define dprintk(fmt, arg...) \ |
| 44 | if (ir_debug) { \ |
| 45 | printk(KERN_DEBUG "%s/ir: " fmt, ir->name , ## arg); \ |
| 46 | } |
| 47 | |
| 48 | /********************************************************** |
| 49 | Polling structure used by em28xx IR's |
| 50 | **********************************************************/ |
| 51 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 52 | struct em28xx_ir_poll_result { |
| 53 | unsigned int toggle_bit:1; |
| 54 | unsigned int read_count:7; |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 55 | |
| 56 | u32 scancode; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 57 | }; |
| 58 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 59 | struct em28xx_IR { |
| 60 | struct em28xx *dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 61 | struct rc_dev *rc; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 62 | char name[32]; |
| 63 | char phys[32]; |
| 64 | |
| 65 | /* poll external decoder */ |
| 66 | int polling; |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 67 | struct delayed_work work; |
Mauro Carvalho Chehab | 0278155 | 2009-11-27 23:28:40 -0300 | [diff] [blame] | 68 | unsigned int full_code:1; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 69 | unsigned int last_readcount; |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 70 | u64 rc_type; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 71 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 72 | int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /********************************************************** |
| 76 | I2C IR based get keycodes - should be used with ir-kbd-i2c |
| 77 | **********************************************************/ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 78 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 79 | static int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 80 | { |
| 81 | unsigned char b; |
| 82 | |
| 83 | /* poll IR chip */ |
Frank Schaefer | 62ec3f8 | 2013-01-13 10:20:40 -0300 | [diff] [blame^] | 84 | if (1 != i2c_master_recv(ir->c, &b, 1)) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 85 | return -EIO; |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 86 | |
| 87 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 88 | down, while 0xff indicates that no button is hold |
| 89 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 90 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 91 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 92 | return 0; |
| 93 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 94 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 95 | /* keep old data */ |
| 96 | return 1; |
| 97 | |
| 98 | *ir_key = b; |
| 99 | *ir_raw = b; |
| 100 | return 1; |
| 101 | } |
| 102 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 103 | static int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 104 | { |
| 105 | unsigned char buf[2]; |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 106 | u16 code; |
| 107 | int size; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 108 | |
| 109 | /* poll IR chip */ |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 110 | size = i2c_master_recv(ir->c, buf, sizeof(buf)); |
| 111 | |
| 112 | if (size != 2) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 113 | return -EIO; |
| 114 | |
| 115 | /* Does eliminate repeated parity code */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 116 | if (buf[1] == 0xff) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 117 | return 0; |
| 118 | |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 119 | /* |
| 120 | * Rearranges bits to the right order. |
| 121 | * The bit order were determined experimentally by using |
| 122 | * The original Hauppauge Grey IR and another RC5 that uses addr=0x08 |
| 123 | * The RC5 code has 14 bits, but we've experimentally determined |
| 124 | * the meaning for only 11 bits. |
| 125 | * So, the code translation is not complete. Yet, it is enough to |
| 126 | * work with the provided RC5 IR. |
| 127 | */ |
| 128 | code = |
| 129 | ((buf[0] & 0x01) ? 0x0020 : 0) | /* 0010 0000 */ |
| 130 | ((buf[0] & 0x02) ? 0x0010 : 0) | /* 0001 0000 */ |
| 131 | ((buf[0] & 0x04) ? 0x0008 : 0) | /* 0000 1000 */ |
| 132 | ((buf[0] & 0x08) ? 0x0004 : 0) | /* 0000 0100 */ |
| 133 | ((buf[0] & 0x10) ? 0x0002 : 0) | /* 0000 0010 */ |
| 134 | ((buf[0] & 0x20) ? 0x0001 : 0) | /* 0000 0001 */ |
| 135 | ((buf[1] & 0x08) ? 0x1000 : 0) | /* 0001 0000 */ |
| 136 | ((buf[1] & 0x10) ? 0x0800 : 0) | /* 0000 1000 */ |
| 137 | ((buf[1] & 0x20) ? 0x0400 : 0) | /* 0000 0100 */ |
| 138 | ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */ |
| 139 | ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 140 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 141 | /* return key */ |
| 142 | *ir_key = code; |
| 143 | *ir_raw = code; |
| 144 | return 1; |
| 145 | } |
| 146 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 147 | static int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, |
Mauro Carvalho Chehab | c8793b0 | 2008-01-13 15:42:17 -0300 | [diff] [blame] | 148 | u32 *ir_raw) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 149 | { |
| 150 | unsigned char buf[3]; |
| 151 | |
| 152 | /* poll IR chip */ |
| 153 | |
Frank Schaefer | 62ec3f8 | 2013-01-13 10:20:40 -0300 | [diff] [blame^] | 154 | if (3 != i2c_master_recv(ir->c, buf, 3)) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 155 | return -EIO; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 156 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 157 | if (buf[0] != 0x00) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 158 | return 0; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 159 | |
| 160 | *ir_key = buf[2]&0x3f; |
| 161 | *ir_raw = buf[2]&0x3f; |
| 162 | |
| 163 | return 1; |
| 164 | } |
| 165 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 166 | static int em28xx_get_key_winfast_usbii_deluxe(struct IR_i2c *ir, u32 *ir_key, |
| 167 | u32 *ir_raw) |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 168 | { |
| 169 | unsigned char subaddr, keydetect, key; |
| 170 | |
| 171 | struct i2c_msg msg[] = { { .addr = ir->c->addr, .flags = 0, .buf = &subaddr, .len = 1}, |
| 172 | |
| 173 | { .addr = ir->c->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} }; |
| 174 | |
| 175 | subaddr = 0x10; |
Frank Schaefer | 62ec3f8 | 2013-01-13 10:20:40 -0300 | [diff] [blame^] | 176 | if (2 != i2c_transfer(ir->c->adapter, msg, 2)) |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 177 | return -EIO; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 178 | if (keydetect == 0x00) |
| 179 | return 0; |
| 180 | |
| 181 | subaddr = 0x00; |
| 182 | msg[1].buf = &key; |
Frank Schaefer | 62ec3f8 | 2013-01-13 10:20:40 -0300 | [diff] [blame^] | 183 | if (2 != i2c_transfer(ir->c->adapter, msg, 2)) |
| 184 | return -EIO; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 185 | if (key == 0x00) |
| 186 | return 0; |
| 187 | |
| 188 | *ir_key = key; |
| 189 | *ir_raw = key; |
| 190 | return 1; |
| 191 | } |
| 192 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 193 | /********************************************************** |
| 194 | Poll based get keycode functions |
| 195 | **********************************************************/ |
| 196 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 197 | /* This is for the em2860/em2880 */ |
| 198 | static int default_polling_getkey(struct em28xx_IR *ir, |
| 199 | struct em28xx_ir_poll_result *poll_result) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 200 | { |
| 201 | struct em28xx *dev = ir->dev; |
| 202 | int rc; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 203 | u8 msg[3] = { 0, 0, 0 }; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 204 | |
Mauro Carvalho Chehab | 0a6b8a8 | 2008-11-12 18:46:01 -0300 | [diff] [blame] | 205 | /* Read key toggle, brand, and key code |
| 206 | on registers 0x45, 0x46 and 0x47 |
| 207 | */ |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 208 | rc = dev->em28xx_read_reg_req_len(dev, 0, EM28XX_R45_IR, |
Mauro Carvalho Chehab | 0a6b8a8 | 2008-11-12 18:46:01 -0300 | [diff] [blame] | 209 | msg, sizeof(msg)); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 210 | if (rc < 0) |
| 211 | return rc; |
| 212 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 213 | /* Infrared toggle (Reg 0x45[7]) */ |
| 214 | poll_result->toggle_bit = (msg[0] >> 7); |
| 215 | |
| 216 | /* Infrared read count (Reg 0x45[6:0] */ |
| 217 | poll_result->read_count = (msg[0] & 0x7f); |
| 218 | |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 219 | /* Remote Control Address/Data (Regs 0x46/0x47) */ |
| 220 | poll_result->scancode = msg[1] << 8 | msg[2]; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int em2874_polling_getkey(struct em28xx_IR *ir, |
| 226 | struct em28xx_ir_poll_result *poll_result) |
| 227 | { |
| 228 | struct em28xx *dev = ir->dev; |
| 229 | int rc; |
| 230 | u8 msg[5] = { 0, 0, 0, 0, 0 }; |
| 231 | |
| 232 | /* Read key toggle, brand, and key code |
| 233 | on registers 0x51-55 |
| 234 | */ |
| 235 | rc = dev->em28xx_read_reg_req_len(dev, 0, EM2874_R51_IR, |
| 236 | msg, sizeof(msg)); |
| 237 | if (rc < 0) |
| 238 | return rc; |
| 239 | |
| 240 | /* Infrared toggle (Reg 0x51[7]) */ |
| 241 | poll_result->toggle_bit = (msg[0] >> 7); |
| 242 | |
| 243 | /* Infrared read count (Reg 0x51[6:0] */ |
| 244 | poll_result->read_count = (msg[0] & 0x7f); |
| 245 | |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 246 | /* |
| 247 | * Remote Control Address (Reg 0x52) |
| 248 | * Remote Control Data (Reg 0x53-0x55) |
| 249 | */ |
| 250 | switch (ir->rc_type) { |
| 251 | case RC_BIT_RC5: |
| 252 | poll_result->scancode = msg[1] << 8 | msg[2]; |
| 253 | break; |
| 254 | case RC_BIT_NEC: |
| 255 | if ((msg[3] ^ msg[4]) != 0xff) /* 32 bits NEC */ |
| 256 | poll_result->scancode = (msg[1] << 24) | |
| 257 | (msg[2] << 16) | |
| 258 | (msg[3] << 8) | |
| 259 | msg[4]; |
| 260 | else if ((msg[1] ^ msg[2]) != 0xff) /* 24 bits NEC */ |
| 261 | poll_result->scancode = (msg[1] << 16) | |
| 262 | (msg[2] << 8) | |
| 263 | msg[3]; |
| 264 | else /* Normal NEC */ |
| 265 | poll_result->scancode = msg[1] << 8 | msg[3]; |
| 266 | break; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 267 | case RC_BIT_RC6_0: |
| 268 | poll_result->scancode = msg[1] << 8 | msg[2]; |
| 269 | break; |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 270 | default: |
| 271 | poll_result->scancode = (msg[1] << 24) | (msg[2] << 16) | |
| 272 | (msg[3] << 8) | msg[4]; |
| 273 | break; |
| 274 | } |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 275 | |
| 276 | return 0; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | /********************************************************** |
| 280 | Polling code for em28xx |
| 281 | **********************************************************/ |
| 282 | |
| 283 | static void em28xx_ir_handle_key(struct em28xx_IR *ir) |
| 284 | { |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 285 | int result; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 286 | struct em28xx_ir_poll_result poll_result; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 287 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 288 | /* read the registers containing the IR status */ |
| 289 | result = ir->get_key(ir, &poll_result); |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 290 | if (unlikely(result < 0)) { |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 291 | dprintk("ir->get_key() failed %d\n", result); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 292 | return; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 293 | } |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 294 | |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 295 | if (unlikely(poll_result.read_count != ir->last_readcount)) { |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 296 | dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__, |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 297 | poll_result.toggle_bit, poll_result.read_count, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 298 | poll_result.scancode); |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 299 | if (ir->full_code) |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 300 | rc_keydown(ir->rc, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 301 | poll_result.scancode, |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 302 | poll_result.toggle_bit); |
| 303 | else |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 304 | rc_keydown(ir->rc, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 305 | poll_result.scancode & 0xff, |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 306 | poll_result.toggle_bit); |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 307 | |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 308 | if (ir->dev->chip_id == CHIP_ID_EM2874 || |
| 309 | ir->dev->chip_id == CHIP_ID_EM2884) |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 310 | /* The em2874 clears the readcount field every time the |
| 311 | register is read. The em2860/2880 datasheet says that it |
| 312 | is supposed to clear the readcount, but it doesn't. So with |
| 313 | the em2874, we are looking for a non-zero read count as |
| 314 | opposed to a readcount that is incrementing */ |
| 315 | ir->last_readcount = 0; |
| 316 | else |
| 317 | ir->last_readcount = poll_result.read_count; |
| 318 | } |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 319 | } |
| 320 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 321 | static void em28xx_ir_work(struct work_struct *work) |
| 322 | { |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 323 | struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 324 | |
| 325 | em28xx_ir_handle_key(ir); |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 326 | schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 327 | } |
| 328 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 329 | static int em28xx_ir_start(struct rc_dev *rc) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 330 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 331 | struct em28xx_IR *ir = rc->priv; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 332 | |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 333 | INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); |
| 334 | schedule_delayed_work(&ir->work, 0); |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 335 | |
| 336 | return 0; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 337 | } |
| 338 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 339 | static void em28xx_ir_stop(struct rc_dev *rc) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 340 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 341 | struct em28xx_IR *ir = rc->priv; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 342 | |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 343 | cancel_delayed_work_sync(&ir->work); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 344 | } |
| 345 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 346 | static int em2860_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 347 | { |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 348 | struct em28xx_IR *ir = rc_dev->priv; |
| 349 | struct em28xx *dev = ir->dev; |
| 350 | |
| 351 | /* Adjust xclk based on IR table for RC5/NEC tables */ |
| 352 | if (*rc_type & RC_BIT_RC5) { |
| 353 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 354 | ir->full_code = 1; |
| 355 | *rc_type = RC_BIT_RC5; |
| 356 | } else if (*rc_type & RC_BIT_NEC) { |
| 357 | dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; |
| 358 | ir->full_code = 1; |
| 359 | *rc_type = RC_BIT_NEC; |
| 360 | } else if (*rc_type & RC_BIT_UNKNOWN) { |
| 361 | *rc_type = RC_BIT_UNKNOWN; |
| 362 | } else { |
| 363 | *rc_type = ir->rc_type; |
| 364 | return -EINVAL; |
| 365 | } |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 366 | em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, |
| 367 | EM28XX_XCLK_IR_RC5_MODE); |
| 368 | |
| 369 | ir->rc_type = *rc_type; |
| 370 | |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) |
| 375 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 376 | struct em28xx_IR *ir = rc_dev->priv; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 377 | struct em28xx *dev = ir->dev; |
| 378 | u8 ir_config = EM2874_IR_RC5; |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 379 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 380 | /* Adjust xclk and set type based on IR table for RC5/NEC/RC6 tables */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 381 | if (*rc_type & RC_BIT_RC5) { |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 382 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 383 | ir->full_code = 1; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 384 | *rc_type = RC_BIT_RC5; |
| 385 | } else if (*rc_type & RC_BIT_NEC) { |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 386 | dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 387 | ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY; |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 388 | ir->full_code = 1; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 389 | *rc_type = RC_BIT_NEC; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 390 | } else if (*rc_type & RC_BIT_RC6_0) { |
| 391 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 392 | ir_config = EM2874_IR_RC6_MODE_0; |
| 393 | ir->full_code = 1; |
| 394 | *rc_type = RC_BIT_RC6_0; |
| 395 | } else if (*rc_type & RC_BIT_UNKNOWN) { |
| 396 | *rc_type = RC_BIT_UNKNOWN; |
| 397 | } else { |
| 398 | *rc_type = ir->rc_type; |
| 399 | return -EINVAL; |
| 400 | } |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 401 | em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1); |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 402 | em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, |
| 403 | EM28XX_XCLK_IR_RC5_MODE); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 404 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 405 | ir->rc_type = *rc_type; |
| 406 | |
| 407 | return 0; |
| 408 | } |
| 409 | static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) |
| 410 | { |
| 411 | struct em28xx_IR *ir = rc_dev->priv; |
| 412 | struct em28xx *dev = ir->dev; |
| 413 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 414 | /* Setup the proper handler based on the chip */ |
| 415 | switch (dev->chip_id) { |
| 416 | case CHIP_ID_EM2860: |
| 417 | case CHIP_ID_EM2883: |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 418 | return em2860_ir_change_protocol(rc_dev, rc_type); |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 419 | case CHIP_ID_EM2884: |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 420 | case CHIP_ID_EM2874: |
Antti Palosaari | a24ec44 | 2011-05-25 16:56:37 -0300 | [diff] [blame] | 421 | case CHIP_ID_EM28174: |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 422 | return em2874_ir_change_protocol(rc_dev, rc_type); |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 423 | default: |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 424 | printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n", |
| 425 | dev->chip_id); |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 426 | return -EINVAL; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 427 | } |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 428 | } |
| 429 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 430 | static void em28xx_register_i2c_ir(struct em28xx *dev) |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 431 | { |
| 432 | /* Leadtek winfast tv USBII deluxe can find a non working IR-device */ |
| 433 | /* at address 0x18, so if that address is needed for another board in */ |
| 434 | /* the future, please put it after 0x1f. */ |
| 435 | struct i2c_board_info info; |
| 436 | const unsigned short addr_list[] = { |
| 437 | 0x1f, 0x30, 0x47, I2C_CLIENT_END |
| 438 | }; |
| 439 | |
| 440 | memset(&info, 0, sizeof(struct i2c_board_info)); |
| 441 | memset(&dev->init_data, 0, sizeof(dev->init_data)); |
| 442 | strlcpy(info.type, "ir_video", I2C_NAME_SIZE); |
| 443 | |
| 444 | /* detect & configure */ |
| 445 | switch (dev->model) { |
| 446 | case EM2800_BOARD_TERRATEC_CINERGY_200: |
| 447 | case EM2820_BOARD_TERRATEC_CINERGY_250: |
| 448 | dev->init_data.ir_codes = RC_MAP_EM_TERRATEC; |
| 449 | dev->init_data.get_key = em28xx_get_key_terratec; |
Mauro Carvalho Chehab | d40580e | 2013-01-04 17:37:26 -0300 | [diff] [blame] | 450 | dev->init_data.name = "Terratec Cinergy 200/250"; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 451 | break; |
| 452 | case EM2820_BOARD_PINNACLE_USB_2: |
| 453 | dev->init_data.ir_codes = RC_MAP_PINNACLE_GREY; |
| 454 | dev->init_data.get_key = em28xx_get_key_pinnacle_usb_grey; |
Mauro Carvalho Chehab | d40580e | 2013-01-04 17:37:26 -0300 | [diff] [blame] | 455 | dev->init_data.name = "Pinnacle USB2"; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 456 | break; |
| 457 | case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2: |
| 458 | dev->init_data.ir_codes = RC_MAP_HAUPPAUGE; |
| 459 | dev->init_data.get_key = em28xx_get_key_em_haup; |
Mauro Carvalho Chehab | d40580e | 2013-01-04 17:37:26 -0300 | [diff] [blame] | 460 | dev->init_data.name = "WinTV USB2"; |
Mauro Carvalho Chehab | 3ac693c | 2013-01-04 18:01:59 -0300 | [diff] [blame] | 461 | dev->init_data.type = RC_BIT_RC5; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 462 | break; |
| 463 | case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE: |
| 464 | dev->init_data.ir_codes = RC_MAP_WINFAST_USBII_DELUXE; |
| 465 | dev->init_data.get_key = em28xx_get_key_winfast_usbii_deluxe; |
Mauro Carvalho Chehab | d40580e | 2013-01-04 17:37:26 -0300 | [diff] [blame] | 466 | dev->init_data.name = "Winfast TV USBII Deluxe"; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 467 | break; |
| 468 | } |
| 469 | |
| 470 | if (dev->init_data.name) |
| 471 | info.platform_data = &dev->init_data; |
| 472 | i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL); |
| 473 | } |
| 474 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 475 | /********************************************************** |
| 476 | Handle Webcam snapshot button |
| 477 | **********************************************************/ |
| 478 | |
| 479 | static void em28xx_query_sbutton(struct work_struct *work) |
| 480 | { |
| 481 | /* Poll the register and see if the button is depressed */ |
| 482 | struct em28xx *dev = |
| 483 | container_of(work, struct em28xx, sbutton_query_work.work); |
| 484 | int ret; |
| 485 | |
| 486 | ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP); |
| 487 | |
| 488 | if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) { |
| 489 | u8 cleared; |
| 490 | /* Button is depressed, clear the register */ |
| 491 | cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT; |
| 492 | em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1); |
| 493 | |
| 494 | /* Not emulate the keypress */ |
| 495 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 496 | 1); |
| 497 | /* Now unpress the key */ |
| 498 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 499 | 0); |
| 500 | } |
| 501 | |
| 502 | /* Schedule next poll */ |
| 503 | schedule_delayed_work(&dev->sbutton_query_work, |
| 504 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 505 | } |
| 506 | |
| 507 | static void em28xx_register_snapshot_button(struct em28xx *dev) |
| 508 | { |
| 509 | struct input_dev *input_dev; |
| 510 | int err; |
| 511 | |
| 512 | em28xx_info("Registering snapshot button...\n"); |
| 513 | input_dev = input_allocate_device(); |
| 514 | if (!input_dev) { |
| 515 | em28xx_errdev("input_allocate_device failed\n"); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | usb_make_path(dev->udev, dev->snapshot_button_path, |
| 520 | sizeof(dev->snapshot_button_path)); |
| 521 | strlcat(dev->snapshot_button_path, "/sbutton", |
| 522 | sizeof(dev->snapshot_button_path)); |
| 523 | INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton); |
| 524 | |
| 525 | input_dev->name = "em28xx snapshot button"; |
| 526 | input_dev->phys = dev->snapshot_button_path; |
| 527 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 528 | set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit); |
| 529 | input_dev->keycodesize = 0; |
| 530 | input_dev->keycodemax = 0; |
| 531 | input_dev->id.bustype = BUS_USB; |
| 532 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 533 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 534 | input_dev->id.version = 1; |
| 535 | input_dev->dev.parent = &dev->udev->dev; |
| 536 | |
| 537 | err = input_register_device(input_dev); |
| 538 | if (err) { |
| 539 | em28xx_errdev("input_register_device failed\n"); |
| 540 | input_free_device(input_dev); |
| 541 | return; |
| 542 | } |
| 543 | |
| 544 | dev->sbutton_input_dev = input_dev; |
| 545 | schedule_delayed_work(&dev->sbutton_query_work, |
| 546 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 547 | return; |
| 548 | |
| 549 | } |
| 550 | |
| 551 | static void em28xx_deregister_snapshot_button(struct em28xx *dev) |
| 552 | { |
| 553 | if (dev->sbutton_input_dev != NULL) { |
| 554 | em28xx_info("Deregistering snapshot button\n"); |
| 555 | cancel_delayed_work_sync(&dev->sbutton_query_work); |
| 556 | input_unregister_device(dev->sbutton_input_dev); |
| 557 | dev->sbutton_input_dev = NULL; |
| 558 | } |
| 559 | return; |
| 560 | } |
| 561 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 562 | static int em28xx_ir_init(struct em28xx *dev) |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 563 | { |
| 564 | struct em28xx_IR *ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 565 | struct rc_dev *rc; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 566 | int err = -ENOMEM; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 567 | u64 rc_type; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 568 | |
Mauro Carvalho Chehab | 8303dc9 | 2013-01-04 17:27:47 -0300 | [diff] [blame] | 569 | if (dev->board.has_snapshot_button) |
| 570 | em28xx_register_snapshot_button(dev); |
| 571 | |
| 572 | if (dev->board.has_ir_i2c) { |
| 573 | em28xx_register_i2c_ir(dev); |
| 574 | #if defined(CONFIG_MODULES) && defined(MODULE) |
| 575 | request_module("ir-kbd-i2c"); |
| 576 | #endif |
| 577 | return 0; |
| 578 | } |
| 579 | |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 580 | if (dev->board.ir_codes == NULL) { |
| 581 | /* No remote control support */ |
Martin Blumenstingl | b83f671 | 2012-05-30 15:47:40 -0300 | [diff] [blame] | 582 | em28xx_warn("Remote control support is not available for " |
| 583 | "this card.\n"); |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 588 | rc = rc_allocate_device(); |
| 589 | if (!ir || !rc) |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 590 | goto error; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 591 | |
| 592 | /* record handles to ourself */ |
| 593 | ir->dev = dev; |
| 594 | dev->ir = ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 595 | ir->rc = rc; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 596 | |
| 597 | /* |
| 598 | * em2874 supports more protocols. For now, let's just announce |
| 599 | * the two protocols that were already tested |
| 600 | */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 601 | rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 602 | rc->priv = ir; |
| 603 | rc->change_protocol = em28xx_ir_change_protocol; |
| 604 | rc->open = em28xx_ir_start; |
| 605 | rc->close = em28xx_ir_stop; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 606 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 607 | switch (dev->chip_id) { |
| 608 | case CHIP_ID_EM2860: |
| 609 | case CHIP_ID_EM2883: |
| 610 | rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC; |
Frank Schaefer | 6ea887e | 2012-12-27 19:02:47 -0300 | [diff] [blame] | 611 | ir->get_key = default_polling_getkey; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 612 | break; |
| 613 | case CHIP_ID_EM2884: |
| 614 | case CHIP_ID_EM2874: |
| 615 | case CHIP_ID_EM28174: |
Frank Schaefer | 6ea887e | 2012-12-27 19:02:47 -0300 | [diff] [blame] | 616 | ir->get_key = em2874_polling_getkey; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 617 | rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC | RC_BIT_RC6_0; |
| 618 | break; |
| 619 | default: |
| 620 | err = -ENODEV; |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 621 | goto error; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 622 | } |
| 623 | |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 624 | /* By default, keep protocol field untouched */ |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 625 | rc_type = RC_BIT_UNKNOWN; |
| 626 | err = em28xx_ir_change_protocol(rc, &rc_type); |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 627 | if (err) |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 628 | goto error; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 629 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 630 | /* This is how often we ask the chip for IR information */ |
| 631 | ir->polling = 100; /* ms */ |
| 632 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 633 | /* init input device */ |
| 634 | snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", |
| 635 | dev->name); |
| 636 | |
| 637 | usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); |
| 638 | strlcat(ir->phys, "/input0", sizeof(ir->phys)); |
| 639 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 640 | rc->input_name = ir->name; |
| 641 | rc->input_phys = ir->phys; |
| 642 | rc->input_id.bustype = BUS_USB; |
| 643 | rc->input_id.version = 1; |
| 644 | rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 645 | rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 646 | rc->dev.parent = &dev->udev->dev; |
| 647 | rc->map_name = dev->board.ir_codes; |
| 648 | rc->driver_name = MODULE_NAME; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 649 | |
| 650 | /* all done */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 651 | err = rc_register_device(rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 652 | if (err) |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 653 | goto error; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 654 | |
| 655 | return 0; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 656 | |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 657 | error: |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 658 | dev->ir = NULL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 659 | rc_free_device(rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 660 | kfree(ir); |
| 661 | return err; |
| 662 | } |
| 663 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 664 | static int em28xx_ir_fini(struct em28xx *dev) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 665 | { |
| 666 | struct em28xx_IR *ir = dev->ir; |
| 667 | |
Ezequiel García | 2fd6f8d | 2012-03-26 09:13:32 -0300 | [diff] [blame] | 668 | em28xx_deregister_snapshot_button(dev); |
| 669 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 670 | /* skip detach on non attached boards */ |
| 671 | if (!ir) |
| 672 | return 0; |
| 673 | |
Mauro Carvalho Chehab | 6d51477 | 2011-07-29 02:26:59 -0300 | [diff] [blame] | 674 | if (ir->rc) |
| 675 | rc_unregister_device(ir->rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 676 | |
| 677 | /* done */ |
Mauro Carvalho Chehab | 6d51477 | 2011-07-29 02:26:59 -0300 | [diff] [blame] | 678 | kfree(ir); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 679 | dev->ir = NULL; |
| 680 | return 0; |
| 681 | } |
| 682 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 683 | static struct em28xx_ops rc_ops = { |
| 684 | .id = EM28XX_RC, |
| 685 | .name = "Em28xx Input Extension", |
| 686 | .init = em28xx_ir_init, |
| 687 | .fini = em28xx_ir_fini, |
| 688 | }; |
| 689 | |
| 690 | static int __init em28xx_rc_register(void) |
| 691 | { |
| 692 | return em28xx_register_extension(&rc_ops); |
| 693 | } |
| 694 | |
| 695 | static void __exit em28xx_rc_unregister(void) |
| 696 | { |
| 697 | em28xx_unregister_extension(&rc_ops); |
| 698 | } |
| 699 | |
| 700 | MODULE_LICENSE("GPL"); |
| 701 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); |
| 702 | MODULE_DESCRIPTION("Em28xx Input driver"); |
| 703 | |
| 704 | module_init(em28xx_rc_register); |
| 705 | module_exit(em28xx_rc_unregister); |