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 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 65 | /* poll decoder */ |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 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 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 72 | /* external device (if used) */ |
| 73 | struct i2c_client *i2c_dev; |
| 74 | |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 75 | int (*get_key_i2c)(struct i2c_client *, u32 *); |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 76 | int (*get_key)(struct em28xx_IR *, struct em28xx_ir_poll_result *); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | /********************************************************** |
| 80 | I2C IR based get keycodes - should be used with ir-kbd-i2c |
| 81 | **********************************************************/ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 82 | |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 83 | static int em28xx_get_key_terratec(struct i2c_client *i2c_dev, u32 *ir_key) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 84 | { |
| 85 | unsigned char b; |
| 86 | |
| 87 | /* poll IR chip */ |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 88 | if (1 != i2c_master_recv(i2c_dev, &b, 1)) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 89 | return -EIO; |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 90 | |
| 91 | /* it seems that 0xFE indicates that a button is still hold |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 92 | down, while 0xff indicates that no button is hold |
| 93 | down. 0xfe sequences are sometimes interrupted by 0xFF */ |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 94 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 95 | if (b == 0xff) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 96 | return 0; |
| 97 | |
Mauro Carvalho Chehab | 4f9c05a | 2005-11-08 21:37:36 -0800 | [diff] [blame] | 98 | if (b == 0xfe) |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 99 | /* keep old data */ |
| 100 | return 1; |
| 101 | |
| 102 | *ir_key = b; |
Markus Rechberger | e43f14a | 2005-11-08 21:37:35 -0800 | [diff] [blame] | 103 | return 1; |
| 104 | } |
| 105 | |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 106 | static int em28xx_get_key_em_haup(struct i2c_client *i2c_dev, u32 *ir_key) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 107 | { |
| 108 | unsigned char buf[2]; |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 109 | u16 code; |
| 110 | int size; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 111 | |
| 112 | /* poll IR chip */ |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 113 | size = i2c_master_recv(i2c_dev, buf, sizeof(buf)); |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 114 | |
| 115 | if (size != 2) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 116 | return -EIO; |
| 117 | |
| 118 | /* Does eliminate repeated parity code */ |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 119 | if (buf[1] == 0xff) |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 120 | return 0; |
| 121 | |
Mauro Carvalho Chehab | b779974 | 2009-12-05 23:24:50 -0300 | [diff] [blame] | 122 | /* |
| 123 | * Rearranges bits to the right order. |
| 124 | * The bit order were determined experimentally by using |
| 125 | * The original Hauppauge Grey IR and another RC5 that uses addr=0x08 |
| 126 | * The RC5 code has 14 bits, but we've experimentally determined |
| 127 | * the meaning for only 11 bits. |
| 128 | * So, the code translation is not complete. Yet, it is enough to |
| 129 | * work with the provided RC5 IR. |
| 130 | */ |
| 131 | code = |
| 132 | ((buf[0] & 0x01) ? 0x0020 : 0) | /* 0010 0000 */ |
| 133 | ((buf[0] & 0x02) ? 0x0010 : 0) | /* 0001 0000 */ |
| 134 | ((buf[0] & 0x04) ? 0x0008 : 0) | /* 0000 1000 */ |
| 135 | ((buf[0] & 0x08) ? 0x0004 : 0) | /* 0000 0100 */ |
| 136 | ((buf[0] & 0x10) ? 0x0002 : 0) | /* 0000 0010 */ |
| 137 | ((buf[0] & 0x20) ? 0x0001 : 0) | /* 0000 0001 */ |
| 138 | ((buf[1] & 0x08) ? 0x1000 : 0) | /* 0001 0000 */ |
| 139 | ((buf[1] & 0x10) ? 0x0800 : 0) | /* 0000 1000 */ |
| 140 | ((buf[1] & 0x20) ? 0x0400 : 0) | /* 0000 0100 */ |
| 141 | ((buf[1] & 0x40) ? 0x0200 : 0) | /* 0000 0010 */ |
| 142 | ((buf[1] & 0x80) ? 0x0100 : 0); /* 0000 0001 */ |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 143 | |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 144 | /* return key */ |
| 145 | *ir_key = code; |
Mauro Carvalho Chehab | d5e5265 | 2005-11-08 21:37:32 -0800 | [diff] [blame] | 146 | return 1; |
| 147 | } |
| 148 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 149 | static int em28xx_get_key_pinnacle_usb_grey(struct i2c_client *i2c_dev, |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 150 | u32 *ir_key) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 151 | { |
| 152 | unsigned char buf[3]; |
| 153 | |
| 154 | /* poll IR chip */ |
| 155 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 156 | if (3 != i2c_master_recv(i2c_dev, buf, 3)) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 157 | return -EIO; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 158 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 159 | if (buf[0] != 0x00) |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 160 | return 0; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 161 | |
| 162 | *ir_key = buf[2]&0x3f; |
Markus Rechberger | 366cc64 | 2006-01-15 21:04:27 -0200 | [diff] [blame] | 163 | |
| 164 | return 1; |
| 165 | } |
| 166 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 167 | static int em28xx_get_key_winfast_usbii_deluxe(struct i2c_client *i2c_dev, |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 168 | u32 *ir_key) |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 169 | { |
| 170 | unsigned char subaddr, keydetect, key; |
| 171 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 172 | struct i2c_msg msg[] = { { .addr = i2c_dev->addr, .flags = 0, .buf = &subaddr, .len = 1}, |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 173 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 174 | { .addr = i2c_dev->addr, .flags = I2C_M_RD, .buf = &keydetect, .len = 1} }; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 175 | |
| 176 | subaddr = 0x10; |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 177 | if (2 != i2c_transfer(i2c_dev->adapter, msg, 2)) |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 178 | return -EIO; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 179 | if (keydetect == 0x00) |
| 180 | return 0; |
| 181 | |
| 182 | subaddr = 0x00; |
| 183 | msg[1].buf = &key; |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 184 | if (2 != i2c_transfer(i2c_dev->adapter, msg, 2)) |
Frank Schaefer | 62ec3f8 | 2013-01-13 10:20:40 -0300 | [diff] [blame] | 185 | return -EIO; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 186 | if (key == 0x00) |
| 187 | return 0; |
| 188 | |
| 189 | *ir_key = key; |
Magnus Alm | ca39d84 | 2009-11-13 05:48:24 -0300 | [diff] [blame] | 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 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 283 | static int em28xx_i2c_ir_handle_key(struct em28xx_IR *ir) |
| 284 | { |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 285 | static u32 ir_key; |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 286 | int rc; |
| 287 | |
Frank Schaefer | 146b7ee | 2013-01-13 10:20:42 -0300 | [diff] [blame^] | 288 | rc = ir->get_key_i2c(ir->i2c_dev, &ir_key); |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 289 | if (rc < 0) { |
| 290 | dprintk("ir->get_key_i2c() failed: %d\n", rc); |
| 291 | return rc; |
| 292 | } |
| 293 | |
| 294 | if (rc) { |
| 295 | dprintk("%s: keycode = 0x%04x\n", __func__, ir_key); |
| 296 | rc_keydown(ir->rc, ir_key, 0); |
| 297 | } |
| 298 | return 0; |
| 299 | } |
| 300 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 301 | static void em28xx_ir_handle_key(struct em28xx_IR *ir) |
| 302 | { |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 303 | int result; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 304 | struct em28xx_ir_poll_result poll_result; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 305 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 306 | /* read the registers containing the IR status */ |
| 307 | result = ir->get_key(ir, &poll_result); |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 308 | if (unlikely(result < 0)) { |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 309 | dprintk("ir->get_key() failed: %d\n", result); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 310 | return; |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 311 | } |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 312 | |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 313 | if (unlikely(poll_result.read_count != ir->last_readcount)) { |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 314 | dprintk("%s: toggle: %d, count: %d, key 0x%04x\n", __func__, |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 315 | poll_result.toggle_bit, poll_result.read_count, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 316 | poll_result.scancode); |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 317 | if (ir->full_code) |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 318 | rc_keydown(ir->rc, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 319 | poll_result.scancode, |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 320 | poll_result.toggle_bit); |
| 321 | else |
Mauro Carvalho Chehab | ca86674 | 2010-11-17 13:53:11 -0300 | [diff] [blame] | 322 | rc_keydown(ir->rc, |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 323 | poll_result.scancode & 0xff, |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 324 | poll_result.toggle_bit); |
David Härdeman | a469585 | 2010-06-07 16:32:23 -0300 | [diff] [blame] | 325 | |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 326 | if (ir->dev->chip_id == CHIP_ID_EM2874 || |
| 327 | ir->dev->chip_id == CHIP_ID_EM2884) |
Mauro Carvalho Chehab | 603044d | 2010-06-27 08:32:11 -0300 | [diff] [blame] | 328 | /* The em2874 clears the readcount field every time the |
| 329 | register is read. The em2860/2880 datasheet says that it |
| 330 | is supposed to clear the readcount, but it doesn't. So with |
| 331 | the em2874, we are looking for a non-zero read count as |
| 332 | opposed to a readcount that is incrementing */ |
| 333 | ir->last_readcount = 0; |
| 334 | else |
| 335 | ir->last_readcount = poll_result.read_count; |
| 336 | } |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 337 | } |
| 338 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 339 | static void em28xx_i2c_ir_work(struct work_struct *work) |
| 340 | { |
| 341 | struct em28xx_IR *ir = container_of(work, struct em28xx_IR, work.work); |
| 342 | |
| 343 | em28xx_i2c_ir_handle_key(ir); |
| 344 | schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); |
| 345 | } |
| 346 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 347 | static void em28xx_ir_work(struct work_struct *work) |
| 348 | { |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 349 | 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] | 350 | |
| 351 | em28xx_ir_handle_key(ir); |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 352 | schedule_delayed_work(&ir->work, msecs_to_jiffies(ir->polling)); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 353 | } |
| 354 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 355 | static int em28xx_ir_start(struct rc_dev *rc) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 356 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 357 | struct em28xx_IR *ir = rc->priv; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 358 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 359 | if (ir->i2c_dev) /* external i2c device */ |
| 360 | INIT_DELAYED_WORK(&ir->work, em28xx_i2c_ir_work); |
| 361 | else /* internal device */ |
| 362 | INIT_DELAYED_WORK(&ir->work, em28xx_ir_work); |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 363 | schedule_delayed_work(&ir->work, 0); |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 364 | |
| 365 | return 0; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 366 | } |
| 367 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 368 | static void em28xx_ir_stop(struct rc_dev *rc) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 369 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 370 | struct em28xx_IR *ir = rc->priv; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 371 | |
Jean Delvare | f263bac | 2009-03-07 07:43:01 -0300 | [diff] [blame] | 372 | cancel_delayed_work_sync(&ir->work); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 373 | } |
| 374 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 375 | 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] | 376 | { |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 377 | struct em28xx_IR *ir = rc_dev->priv; |
| 378 | struct em28xx *dev = ir->dev; |
| 379 | |
| 380 | /* Adjust xclk based on IR table for RC5/NEC tables */ |
| 381 | if (*rc_type & RC_BIT_RC5) { |
| 382 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 383 | ir->full_code = 1; |
| 384 | *rc_type = RC_BIT_RC5; |
| 385 | } else if (*rc_type & RC_BIT_NEC) { |
| 386 | dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; |
| 387 | ir->full_code = 1; |
| 388 | *rc_type = RC_BIT_NEC; |
| 389 | } else if (*rc_type & RC_BIT_UNKNOWN) { |
| 390 | *rc_type = RC_BIT_UNKNOWN; |
| 391 | } else { |
| 392 | *rc_type = ir->rc_type; |
| 393 | return -EINVAL; |
| 394 | } |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 395 | em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, |
| 396 | EM28XX_XCLK_IR_RC5_MODE); |
| 397 | |
| 398 | ir->rc_type = *rc_type; |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static int em2874_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) |
| 404 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 405 | struct em28xx_IR *ir = rc_dev->priv; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 406 | struct em28xx *dev = ir->dev; |
| 407 | u8 ir_config = EM2874_IR_RC5; |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 408 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 409 | /* 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] | 410 | if (*rc_type & RC_BIT_RC5) { |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 411 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 412 | ir->full_code = 1; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 413 | *rc_type = RC_BIT_RC5; |
| 414 | } else if (*rc_type & RC_BIT_NEC) { |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 415 | dev->board.xclk &= ~EM28XX_XCLK_IR_RC5_MODE; |
Mauro Carvalho Chehab | 105e368 | 2012-12-15 08:29:11 -0300 | [diff] [blame] | 416 | ir_config = EM2874_IR_NEC | EM2874_IR_NEC_NO_PARITY; |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 417 | ir->full_code = 1; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 418 | *rc_type = RC_BIT_NEC; |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 419 | } else if (*rc_type & RC_BIT_RC6_0) { |
| 420 | dev->board.xclk |= EM28XX_XCLK_IR_RC5_MODE; |
| 421 | ir_config = EM2874_IR_RC6_MODE_0; |
| 422 | ir->full_code = 1; |
| 423 | *rc_type = RC_BIT_RC6_0; |
| 424 | } else if (*rc_type & RC_BIT_UNKNOWN) { |
| 425 | *rc_type = RC_BIT_UNKNOWN; |
| 426 | } else { |
| 427 | *rc_type = ir->rc_type; |
| 428 | return -EINVAL; |
| 429 | } |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 430 | em28xx_write_regs(dev, EM2874_R50_IR_CONFIG, &ir_config, 1); |
Mauro Carvalho Chehab | 1bad429 | 2009-12-05 08:27:49 -0300 | [diff] [blame] | 431 | em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, dev->board.xclk, |
| 432 | EM28XX_XCLK_IR_RC5_MODE); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 433 | |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 434 | ir->rc_type = *rc_type; |
| 435 | |
| 436 | return 0; |
| 437 | } |
| 438 | static int em28xx_ir_change_protocol(struct rc_dev *rc_dev, u64 *rc_type) |
| 439 | { |
| 440 | struct em28xx_IR *ir = rc_dev->priv; |
| 441 | struct em28xx *dev = ir->dev; |
| 442 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 443 | /* Setup the proper handler based on the chip */ |
| 444 | switch (dev->chip_id) { |
| 445 | case CHIP_ID_EM2860: |
| 446 | case CHIP_ID_EM2883: |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 447 | return em2860_ir_change_protocol(rc_dev, rc_type); |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 448 | case CHIP_ID_EM2884: |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 449 | case CHIP_ID_EM2874: |
Antti Palosaari | a24ec44 | 2011-05-25 16:56:37 -0300 | [diff] [blame] | 450 | case CHIP_ID_EM28174: |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 451 | return em2874_ir_change_protocol(rc_dev, rc_type); |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 452 | default: |
Mauro Carvalho Chehab | 20ae974 | 2011-11-20 12:23:54 -0200 | [diff] [blame] | 453 | printk("Unrecognized em28xx chip id 0x%02x: IR not supported\n", |
| 454 | dev->chip_id); |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 455 | return -EINVAL; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 456 | } |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 457 | } |
| 458 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 459 | static struct i2c_client *em28xx_probe_i2c_ir(struct em28xx *dev) |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 460 | { |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 461 | int i = 0; |
| 462 | struct i2c_client *i2c_dev = NULL; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 463 | /* Leadtek winfast tv USBII deluxe can find a non working IR-device */ |
| 464 | /* at address 0x18, so if that address is needed for another board in */ |
| 465 | /* the future, please put it after 0x1f. */ |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 466 | const unsigned short addr_list[] = { |
| 467 | 0x1f, 0x30, 0x47, I2C_CLIENT_END |
| 468 | }; |
| 469 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 470 | while (addr_list[i] != I2C_CLIENT_END) { |
| 471 | if (i2c_probe_func_quick_read(&dev->i2c_adap, addr_list[i]) == 1) { |
| 472 | i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL); |
| 473 | if (i2c_dev) { |
| 474 | i2c_dev->addr = addr_list[i]; |
| 475 | i2c_dev->adapter = &dev->i2c_adap; |
| 476 | /* NOTE: as long as we don't register the device |
| 477 | * at the i2c subsystem, no other fields need to |
| 478 | * be set up */ |
| 479 | } |
| 480 | break; |
| 481 | } |
| 482 | i++; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 483 | } |
| 484 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 485 | return i2c_dev; |
Ezequiel García | 9d9f479 | 2012-03-26 09:13:33 -0300 | [diff] [blame] | 486 | } |
| 487 | |
Ezequiel García | 769af21 | 2012-03-26 09:13:34 -0300 | [diff] [blame] | 488 | /********************************************************** |
| 489 | Handle Webcam snapshot button |
| 490 | **********************************************************/ |
| 491 | |
| 492 | static void em28xx_query_sbutton(struct work_struct *work) |
| 493 | { |
| 494 | /* Poll the register and see if the button is depressed */ |
| 495 | struct em28xx *dev = |
| 496 | container_of(work, struct em28xx, sbutton_query_work.work); |
| 497 | int ret; |
| 498 | |
| 499 | ret = em28xx_read_reg(dev, EM28XX_R0C_USBSUSP); |
| 500 | |
| 501 | if (ret & EM28XX_R0C_USBSUSP_SNAPSHOT) { |
| 502 | u8 cleared; |
| 503 | /* Button is depressed, clear the register */ |
| 504 | cleared = ((u8) ret) & ~EM28XX_R0C_USBSUSP_SNAPSHOT; |
| 505 | em28xx_write_regs(dev, EM28XX_R0C_USBSUSP, &cleared, 1); |
| 506 | |
| 507 | /* Not emulate the keypress */ |
| 508 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 509 | 1); |
| 510 | /* Now unpress the key */ |
| 511 | input_report_key(dev->sbutton_input_dev, EM28XX_SNAPSHOT_KEY, |
| 512 | 0); |
| 513 | } |
| 514 | |
| 515 | /* Schedule next poll */ |
| 516 | schedule_delayed_work(&dev->sbutton_query_work, |
| 517 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 518 | } |
| 519 | |
| 520 | static void em28xx_register_snapshot_button(struct em28xx *dev) |
| 521 | { |
| 522 | struct input_dev *input_dev; |
| 523 | int err; |
| 524 | |
| 525 | em28xx_info("Registering snapshot button...\n"); |
| 526 | input_dev = input_allocate_device(); |
| 527 | if (!input_dev) { |
| 528 | em28xx_errdev("input_allocate_device failed\n"); |
| 529 | return; |
| 530 | } |
| 531 | |
| 532 | usb_make_path(dev->udev, dev->snapshot_button_path, |
| 533 | sizeof(dev->snapshot_button_path)); |
| 534 | strlcat(dev->snapshot_button_path, "/sbutton", |
| 535 | sizeof(dev->snapshot_button_path)); |
| 536 | INIT_DELAYED_WORK(&dev->sbutton_query_work, em28xx_query_sbutton); |
| 537 | |
| 538 | input_dev->name = "em28xx snapshot button"; |
| 539 | input_dev->phys = dev->snapshot_button_path; |
| 540 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP); |
| 541 | set_bit(EM28XX_SNAPSHOT_KEY, input_dev->keybit); |
| 542 | input_dev->keycodesize = 0; |
| 543 | input_dev->keycodemax = 0; |
| 544 | input_dev->id.bustype = BUS_USB; |
| 545 | input_dev->id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 546 | input_dev->id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 547 | input_dev->id.version = 1; |
| 548 | input_dev->dev.parent = &dev->udev->dev; |
| 549 | |
| 550 | err = input_register_device(input_dev); |
| 551 | if (err) { |
| 552 | em28xx_errdev("input_register_device failed\n"); |
| 553 | input_free_device(input_dev); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | dev->sbutton_input_dev = input_dev; |
| 558 | schedule_delayed_work(&dev->sbutton_query_work, |
| 559 | msecs_to_jiffies(EM28XX_SBUTTON_QUERY_INTERVAL)); |
| 560 | return; |
| 561 | |
| 562 | } |
| 563 | |
| 564 | static void em28xx_deregister_snapshot_button(struct em28xx *dev) |
| 565 | { |
| 566 | if (dev->sbutton_input_dev != NULL) { |
| 567 | em28xx_info("Deregistering snapshot button\n"); |
| 568 | cancel_delayed_work_sync(&dev->sbutton_query_work); |
| 569 | input_unregister_device(dev->sbutton_input_dev); |
| 570 | dev->sbutton_input_dev = NULL; |
| 571 | } |
| 572 | return; |
| 573 | } |
| 574 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 575 | static int em28xx_ir_init(struct em28xx *dev) |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 576 | { |
| 577 | struct em28xx_IR *ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 578 | struct rc_dev *rc; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 579 | int err = -ENOMEM; |
David Härdeman | c003ab1 | 2012-10-11 19:11:54 -0300 | [diff] [blame] | 580 | u64 rc_type; |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 581 | struct i2c_client *i2c_rc_dev = NULL; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 582 | |
Mauro Carvalho Chehab | 8303dc9 | 2013-01-04 17:27:47 -0300 | [diff] [blame] | 583 | if (dev->board.has_snapshot_button) |
| 584 | em28xx_register_snapshot_button(dev); |
| 585 | |
| 586 | if (dev->board.has_ir_i2c) { |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 587 | i2c_rc_dev = em28xx_probe_i2c_ir(dev); |
| 588 | if (!i2c_rc_dev) { |
| 589 | dev->board.has_ir_i2c = 0; |
| 590 | em28xx_warn("No i2c IR remote control device found.\n"); |
| 591 | return -ENODEV; |
| 592 | } |
Mauro Carvalho Chehab | 8303dc9 | 2013-01-04 17:27:47 -0300 | [diff] [blame] | 593 | } |
| 594 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 595 | if (dev->board.ir_codes == NULL && !dev->board.has_ir_i2c) { |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 596 | /* No remote control support */ |
Martin Blumenstingl | b83f671 | 2012-05-30 15:47:40 -0300 | [diff] [blame] | 597 | em28xx_warn("Remote control support is not available for " |
| 598 | "this card.\n"); |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | ir = kzalloc(sizeof(*ir), GFP_KERNEL); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 603 | rc = rc_allocate_device(); |
| 604 | if (!ir || !rc) |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 605 | goto error; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 606 | |
| 607 | /* record handles to ourself */ |
| 608 | ir->dev = dev; |
| 609 | dev->ir = ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 610 | ir->rc = rc; |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 611 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 612 | rc->priv = ir; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 613 | rc->open = em28xx_ir_start; |
| 614 | rc->close = em28xx_ir_stop; |
Mauro Carvalho Chehab | c373cab | 2010-04-07 22:57:04 -0300 | [diff] [blame] | 615 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 616 | if (dev->board.has_ir_i2c) { /* external i2c device */ |
| 617 | switch (dev->model) { |
| 618 | case EM2800_BOARD_TERRATEC_CINERGY_200: |
| 619 | case EM2820_BOARD_TERRATEC_CINERGY_250: |
| 620 | rc->map_name = RC_MAP_EM_TERRATEC; |
| 621 | ir->get_key_i2c = em28xx_get_key_terratec; |
| 622 | break; |
| 623 | case EM2820_BOARD_PINNACLE_USB_2: |
| 624 | rc->map_name = RC_MAP_PINNACLE_GREY; |
| 625 | ir->get_key_i2c = em28xx_get_key_pinnacle_usb_grey; |
| 626 | break; |
| 627 | case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2: |
| 628 | rc->map_name = RC_MAP_HAUPPAUGE; |
| 629 | ir->get_key_i2c = em28xx_get_key_em_haup; |
| 630 | rc->allowed_protos = RC_BIT_RC5; |
| 631 | break; |
| 632 | case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE: |
| 633 | rc->map_name = RC_MAP_WINFAST_USBII_DELUXE; |
| 634 | ir->get_key_i2c = em28xx_get_key_winfast_usbii_deluxe; |
| 635 | break; |
| 636 | default: |
| 637 | err = -ENODEV; |
| 638 | goto error; |
| 639 | } |
Mauro Carvalho Chehab | 0dae883 | 2012-12-15 08:29:12 -0300 | [diff] [blame] | 640 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 641 | ir->i2c_dev = i2c_rc_dev; |
| 642 | } else { /* internal device */ |
| 643 | switch (dev->chip_id) { |
| 644 | case CHIP_ID_EM2860: |
| 645 | case CHIP_ID_EM2883: |
| 646 | rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC; |
| 647 | ir->get_key = default_polling_getkey; |
| 648 | break; |
| 649 | case CHIP_ID_EM2884: |
| 650 | case CHIP_ID_EM2874: |
| 651 | case CHIP_ID_EM28174: |
| 652 | ir->get_key = em2874_polling_getkey; |
| 653 | rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC | |
| 654 | RC_BIT_RC6_0; |
| 655 | break; |
| 656 | default: |
| 657 | err = -ENODEV; |
| 658 | goto error; |
| 659 | } |
| 660 | |
| 661 | rc->change_protocol = em28xx_ir_change_protocol; |
| 662 | rc->map_name = dev->board.ir_codes; |
| 663 | |
| 664 | /* By default, keep protocol field untouched */ |
| 665 | rc_type = RC_BIT_UNKNOWN; |
| 666 | err = em28xx_ir_change_protocol(rc, &rc_type); |
| 667 | if (err) |
| 668 | goto error; |
| 669 | } |
Mauro Carvalho Chehab | 950b0f5 | 2009-12-14 02:54:22 -0300 | [diff] [blame] | 670 | |
Devin Heitmueller | 4b92253 | 2008-11-13 03:15:55 -0300 | [diff] [blame] | 671 | /* This is how often we ask the chip for IR information */ |
| 672 | ir->polling = 100; /* ms */ |
| 673 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 674 | /* init input device */ |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 675 | snprintf(ir->name, sizeof(ir->name), "em28xx IR (%s)", dev->name); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 676 | |
| 677 | usb_make_path(dev->udev, ir->phys, sizeof(ir->phys)); |
| 678 | strlcat(ir->phys, "/input0", sizeof(ir->phys)); |
| 679 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 680 | rc->input_name = ir->name; |
| 681 | rc->input_phys = ir->phys; |
| 682 | rc->input_id.bustype = BUS_USB; |
| 683 | rc->input_id.version = 1; |
| 684 | rc->input_id.vendor = le16_to_cpu(dev->udev->descriptor.idVendor); |
| 685 | rc->input_id.product = le16_to_cpu(dev->udev->descriptor.idProduct); |
| 686 | rc->dev.parent = &dev->udev->dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 687 | rc->driver_name = MODULE_NAME; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 688 | |
| 689 | /* all done */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 690 | err = rc_register_device(rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 691 | if (err) |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 692 | goto error; |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 693 | |
| 694 | return 0; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 695 | |
Frank Schaefer | 2f5741a | 2012-12-22 10:13:38 -0300 | [diff] [blame] | 696 | error: |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 697 | if (ir && ir->i2c_dev) |
| 698 | kfree(ir->i2c_dev); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 699 | dev->ir = NULL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 700 | rc_free_device(rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 701 | kfree(ir); |
| 702 | return err; |
| 703 | } |
| 704 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 705 | static int em28xx_ir_fini(struct em28xx *dev) |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 706 | { |
| 707 | struct em28xx_IR *ir = dev->ir; |
| 708 | |
Ezequiel García | 2fd6f8d | 2012-03-26 09:13:32 -0300 | [diff] [blame] | 709 | em28xx_deregister_snapshot_button(dev); |
| 710 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 711 | /* skip detach on non attached boards */ |
| 712 | if (!ir) |
| 713 | return 0; |
| 714 | |
Mauro Carvalho Chehab | 6d51477 | 2011-07-29 02:26:59 -0300 | [diff] [blame] | 715 | if (ir->rc) |
| 716 | rc_unregister_device(ir->rc); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 717 | |
Frank Schaefer | 768da3db | 2013-01-13 10:20:41 -0300 | [diff] [blame] | 718 | kfree(ir->i2c_dev); |
| 719 | |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 720 | /* done */ |
Mauro Carvalho Chehab | 6d51477 | 2011-07-29 02:26:59 -0300 | [diff] [blame] | 721 | kfree(ir); |
Mauro Carvalho Chehab | a924a49 | 2008-11-12 08:41:29 -0300 | [diff] [blame] | 722 | dev->ir = NULL; |
| 723 | return 0; |
| 724 | } |
| 725 | |
Ezequiel García | f4d4e76 | 2012-03-26 09:13:35 -0300 | [diff] [blame] | 726 | static struct em28xx_ops rc_ops = { |
| 727 | .id = EM28XX_RC, |
| 728 | .name = "Em28xx Input Extension", |
| 729 | .init = em28xx_ir_init, |
| 730 | .fini = em28xx_ir_fini, |
| 731 | }; |
| 732 | |
| 733 | static int __init em28xx_rc_register(void) |
| 734 | { |
| 735 | return em28xx_register_extension(&rc_ops); |
| 736 | } |
| 737 | |
| 738 | static void __exit em28xx_rc_unregister(void) |
| 739 | { |
| 740 | em28xx_unregister_extension(&rc_ops); |
| 741 | } |
| 742 | |
| 743 | MODULE_LICENSE("GPL"); |
| 744 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@redhat.com>"); |
| 745 | MODULE_DESCRIPTION("Em28xx Input driver"); |
| 746 | |
| 747 | module_init(em28xx_rc_register); |
| 748 | module_exit(em28xx_rc_unregister); |