Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers |
| 3 | * |
| 4 | * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com> |
| 5 | * |
| 6 | * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan |
| 7 | * Conti, Martin Blatter and Daniel Melander, the latter of which was |
| 8 | * in turn also based on the lirc_atiusb driver by Paul Miller. The |
| 9 | * two mce drivers were merged into one by Jarod Wilson, with transmit |
| 10 | * support for the 1st-gen device added primarily by Patrick Calhoun, |
| 11 | * with a bit of tweaks by Jarod. Debugging improvements and proper |
| 12 | * support for what appears to be 3rd-gen hardware added by Jarod. |
| 13 | * Initial port from lirc driver to ir-core drivery by Jarod, based |
| 14 | * partially on a port to an earlier proposed IR infrastructure by |
| 15 | * Jon Smirl, which included enhancements and simplifications to the |
| 16 | * incoming IR buffer parsing routines. |
| 17 | * |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #include <linux/device.h> |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/slab.h> |
Paul Bender | 635f76b | 2010-12-16 13:23:07 -0300 | [diff] [blame] | 38 | #include <linux/usb.h> |
| 39 | #include <linux/usb/input.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 40 | #include <media/rc-core.h> |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 41 | |
| 42 | #define DRIVER_VERSION "1.91" |
| 43 | #define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>" |
| 44 | #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \ |
| 45 | "device driver" |
| 46 | #define DRIVER_NAME "mceusb" |
| 47 | |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 48 | #define USB_BUFLEN 32 /* USB reception buffer length */ |
| 49 | #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */ |
| 50 | #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 51 | |
| 52 | /* MCE constants */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 53 | #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */ |
| 54 | #define MCE_TIME_UNIT 50 /* Approx 50us resolution */ |
| 55 | #define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */ |
| 56 | #define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */ |
| 57 | #define MCE_IRDATA_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */ |
| 58 | #define MCE_IRDATA_TRAILER 0x80 /* End of IR data */ |
| 59 | #define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */ |
| 60 | #define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */ |
| 61 | #define MCE_DEFAULT_TX_MASK 0x03 /* Vals: TX1=0x01, TX2=0x02, ALL=0x03 */ |
| 62 | #define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */ |
| 63 | #define MCE_PULSE_MASK 0x7f /* Pulse mask */ |
| 64 | #define MCE_MAX_PULSE_LENGTH 0x7f /* Longest transmittable pulse symbol */ |
| 65 | |
| 66 | #define MCE_HW_CMD_HEADER 0xff /* MCE hardware command header */ |
| 67 | #define MCE_COMMAND_HEADER 0x9f /* MCE command header */ |
| 68 | #define MCE_COMMAND_MASK 0xe0 /* Mask out command bits */ |
| 69 | #define MCE_COMMAND_NULL 0x00 /* These show up various places... */ |
| 70 | /* if buf[i] & MCE_COMMAND_MASK == 0x80 and buf[i] != MCE_COMMAND_HEADER, |
| 71 | * then we're looking at a raw IR data sample */ |
| 72 | #define MCE_COMMAND_IRDATA 0x80 |
| 73 | #define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */ |
| 74 | |
| 75 | /* Sub-commands, which follow MCE_COMMAND_HEADER or MCE_HW_CMD_HEADER */ |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 76 | #define MCE_CMD_SIG_END 0x01 /* End of signal */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 77 | #define MCE_CMD_PING 0x03 /* Ping device */ |
| 78 | #define MCE_CMD_UNKNOWN 0x04 /* Unknown */ |
| 79 | #define MCE_CMD_UNKNOWN2 0x05 /* Unknown */ |
| 80 | #define MCE_CMD_S_CARRIER 0x06 /* Set TX carrier frequency */ |
| 81 | #define MCE_CMD_G_CARRIER 0x07 /* Get TX carrier frequency */ |
| 82 | #define MCE_CMD_S_TXMASK 0x08 /* Set TX port bitmask */ |
| 83 | #define MCE_CMD_UNKNOWN3 0x09 /* Unknown */ |
| 84 | #define MCE_CMD_UNKNOWN4 0x0a /* Unknown */ |
| 85 | #define MCE_CMD_G_REVISION 0x0b /* Get hw/sw revision */ |
| 86 | #define MCE_CMD_S_TIMEOUT 0x0c /* Set RX timeout value */ |
| 87 | #define MCE_CMD_G_TIMEOUT 0x0d /* Get RX timeout value */ |
| 88 | #define MCE_CMD_UNKNOWN5 0x0e /* Unknown */ |
| 89 | #define MCE_CMD_UNKNOWN6 0x0f /* Unknown */ |
| 90 | #define MCE_CMD_G_RXPORTSTS 0x11 /* Get RX port status */ |
| 91 | #define MCE_CMD_G_TXMASK 0x13 /* Set TX port bitmask */ |
| 92 | #define MCE_CMD_S_RXSENSOR 0x14 /* Set RX sensor (std/learning) */ |
| 93 | #define MCE_CMD_G_RXSENSOR 0x15 /* Get RX sensor (std/learning) */ |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 94 | #define MCE_RSP_PULSE_COUNT 0x15 /* RX pulse count (only if learning) */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 95 | #define MCE_CMD_TX_PORTS 0x16 /* Get number of TX ports */ |
| 96 | #define MCE_CMD_G_WAKESRC 0x17 /* Get wake source */ |
| 97 | #define MCE_CMD_UNKNOWN7 0x18 /* Unknown */ |
| 98 | #define MCE_CMD_UNKNOWN8 0x19 /* Unknown */ |
| 99 | #define MCE_CMD_UNKNOWN9 0x1b /* Unknown */ |
| 100 | #define MCE_CMD_DEVICE_RESET 0xaa /* Reset the hardware */ |
| 101 | #define MCE_RSP_CMD_INVALID 0xfe /* Invalid command issued */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 102 | |
| 103 | |
| 104 | /* module parameters */ |
| 105 | #ifdef CONFIG_USB_DEBUG |
| 106 | static int debug = 1; |
| 107 | #else |
| 108 | static int debug; |
| 109 | #endif |
| 110 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 111 | #define mce_dbg(dev, fmt, ...) \ |
| 112 | do { \ |
| 113 | if (debug) \ |
| 114 | dev_info(dev, fmt, ## __VA_ARGS__); \ |
| 115 | } while (0) |
| 116 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 117 | /* general constants */ |
| 118 | #define SEND_FLAG_IN_PROGRESS 1 |
| 119 | #define SEND_FLAG_COMPLETE 2 |
| 120 | #define RECV_FLAG_IN_PROGRESS 3 |
| 121 | #define RECV_FLAG_COMPLETE 4 |
| 122 | |
| 123 | #define MCEUSB_RX 1 |
| 124 | #define MCEUSB_TX 2 |
| 125 | |
| 126 | #define VENDOR_PHILIPS 0x0471 |
| 127 | #define VENDOR_SMK 0x0609 |
| 128 | #define VENDOR_TATUNG 0x1460 |
| 129 | #define VENDOR_GATEWAY 0x107b |
| 130 | #define VENDOR_SHUTTLE 0x1308 |
| 131 | #define VENDOR_SHUTTLE2 0x051c |
| 132 | #define VENDOR_MITSUMI 0x03ee |
| 133 | #define VENDOR_TOPSEED 0x1784 |
| 134 | #define VENDOR_RICAVISION 0x179d |
| 135 | #define VENDOR_ITRON 0x195d |
| 136 | #define VENDOR_FIC 0x1509 |
| 137 | #define VENDOR_LG 0x043e |
| 138 | #define VENDOR_MICROSOFT 0x045e |
| 139 | #define VENDOR_FORMOSA 0x147a |
| 140 | #define VENDOR_FINTEK 0x1934 |
| 141 | #define VENDOR_PINNACLE 0x2304 |
| 142 | #define VENDOR_ECS 0x1019 |
| 143 | #define VENDOR_WISTRON 0x0fb8 |
| 144 | #define VENDOR_COMPRO 0x185b |
| 145 | #define VENDOR_NORTHSTAR 0x04eb |
| 146 | #define VENDOR_REALTEK 0x0bda |
| 147 | #define VENDOR_TIVO 0x105a |
Mauro Carvalho Chehab | 56e92f6 | 2010-10-18 16:32:50 -0300 | [diff] [blame] | 148 | #define VENDOR_CONEXANT 0x0572 |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 149 | |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 150 | enum mceusb_model_type { |
| 151 | MCE_GEN2 = 0, /* Most boards */ |
| 152 | MCE_GEN1, |
| 153 | MCE_GEN3, |
| 154 | MCE_GEN2_TX_INV, |
| 155 | POLARIS_EVK, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 156 | CX_HYBRID_TV, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 157 | MULTIFUNCTION, |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 158 | TIVO_KIT, |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 159 | MCE_GEN2_NO_TX, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | struct mceusb_model { |
| 163 | u32 mce_gen1:1; |
| 164 | u32 mce_gen2:1; |
| 165 | u32 mce_gen3:1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 166 | u32 tx_mask_normal:1; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 167 | u32 no_tx:1; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 168 | |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 169 | int ir_intfnum; |
| 170 | |
Mauro Carvalho Chehab | 17c2b1f | 2010-10-22 11:51:50 -0300 | [diff] [blame] | 171 | const char *rc_map; /* Allow specify a per-board map */ |
Mauro Carvalho Chehab | 3459d45 | 2010-10-22 11:52:53 -0300 | [diff] [blame] | 172 | const char *name; /* per-board name */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 173 | }; |
| 174 | |
| 175 | static const struct mceusb_model mceusb_model[] = { |
| 176 | [MCE_GEN1] = { |
| 177 | .mce_gen1 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 178 | .tx_mask_normal = 1, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 179 | }, |
| 180 | [MCE_GEN2] = { |
| 181 | .mce_gen2 = 1, |
| 182 | }, |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 183 | [MCE_GEN2_NO_TX] = { |
| 184 | .mce_gen2 = 1, |
| 185 | .no_tx = 1, |
| 186 | }, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 187 | [MCE_GEN2_TX_INV] = { |
| 188 | .mce_gen2 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 189 | .tx_mask_normal = 1, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 190 | }, |
| 191 | [MCE_GEN3] = { |
| 192 | .mce_gen3 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 193 | .tx_mask_normal = 1, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 194 | }, |
| 195 | [POLARIS_EVK] = { |
Mauro Carvalho Chehab | 17c2b1f | 2010-10-22 11:51:50 -0300 | [diff] [blame] | 196 | /* |
| 197 | * In fact, the EVK is shipped without |
| 198 | * remotes, but we should have something handy, |
| 199 | * to allow testing it |
| 200 | */ |
Mauro Carvalho Chehab | 15195d3 | 2011-01-24 12:18:47 -0300 | [diff] [blame] | 201 | .rc_map = RC_MAP_HAUPPAUGE, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 202 | .name = "Conexant Hybrid TV (cx231xx) MCE IR", |
| 203 | }, |
| 204 | [CX_HYBRID_TV] = { |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 205 | .no_tx = 1, /* tx isn't wired up at all */ |
| 206 | .name = "Conexant Hybrid TV (cx231xx) MCE IR", |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 207 | }, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 208 | [MULTIFUNCTION] = { |
| 209 | .mce_gen2 = 1, |
| 210 | .ir_intfnum = 2, |
| 211 | }, |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 212 | [TIVO_KIT] = { |
| 213 | .mce_gen2 = 1, |
| 214 | .rc_map = RC_MAP_TIVO, |
| 215 | }, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 216 | }; |
| 217 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 218 | static struct usb_device_id mceusb_dev_table[] = { |
| 219 | /* Original Microsoft MCE IR Transceiver (often HP-branded) */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 220 | { USB_DEVICE(VENDOR_MICROSOFT, 0x006d), |
| 221 | .driver_info = MCE_GEN1 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 222 | /* Philips Infrared Transceiver - Sahara branded */ |
| 223 | { USB_DEVICE(VENDOR_PHILIPS, 0x0608) }, |
| 224 | /* Philips Infrared Transceiver - HP branded */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 225 | { USB_DEVICE(VENDOR_PHILIPS, 0x060c), |
| 226 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 227 | /* Philips SRM5100 */ |
| 228 | { USB_DEVICE(VENDOR_PHILIPS, 0x060d) }, |
| 229 | /* Philips Infrared Transceiver - Omaura */ |
| 230 | { USB_DEVICE(VENDOR_PHILIPS, 0x060f) }, |
| 231 | /* Philips Infrared Transceiver - Spinel plus */ |
| 232 | { USB_DEVICE(VENDOR_PHILIPS, 0x0613) }, |
| 233 | /* Philips eHome Infrared Transceiver */ |
| 234 | { USB_DEVICE(VENDOR_PHILIPS, 0x0815) }, |
Jarod Wilson | c13df9c | 2010-08-27 18:21:14 -0300 | [diff] [blame] | 235 | /* Philips/Spinel plus IR transceiver for ASUS */ |
| 236 | { USB_DEVICE(VENDOR_PHILIPS, 0x206c) }, |
| 237 | /* Philips/Spinel plus IR transceiver for ASUS */ |
| 238 | { USB_DEVICE(VENDOR_PHILIPS, 0x2088) }, |
Jarod Wilson | e296e12 | 2011-04-25 14:48:18 -0300 | [diff] [blame] | 239 | /* Philips IR transceiver (Dell branded) */ |
| 240 | { USB_DEVICE(VENDOR_PHILIPS, 0x2093) }, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 241 | /* Realtek MCE IR Receiver and card reader */ |
| 242 | { USB_DEVICE(VENDOR_REALTEK, 0x0161), |
| 243 | .driver_info = MULTIFUNCTION }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 244 | /* SMK/Toshiba G83C0004D410 */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 245 | { USB_DEVICE(VENDOR_SMK, 0x031d), |
| 246 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 247 | /* SMK eHome Infrared Transceiver (Sony VAIO) */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 248 | { USB_DEVICE(VENDOR_SMK, 0x0322), |
| 249 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 250 | /* bundled with Hauppauge PVR-150 */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 251 | { USB_DEVICE(VENDOR_SMK, 0x0334), |
| 252 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 253 | /* SMK eHome Infrared Transceiver */ |
| 254 | { USB_DEVICE(VENDOR_SMK, 0x0338) }, |
Jarod Wilson | b825fe1b | 2011-05-26 16:03:17 -0300 | [diff] [blame] | 255 | /* SMK/I-O Data GV-MC7/RCKIT Receiver */ |
| 256 | { USB_DEVICE(VENDOR_SMK, 0x0353), |
| 257 | .driver_info = MCE_GEN2_NO_TX }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 258 | /* Tatung eHome Infrared Transceiver */ |
| 259 | { USB_DEVICE(VENDOR_TATUNG, 0x9150) }, |
| 260 | /* Shuttle eHome Infrared Transceiver */ |
| 261 | { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) }, |
| 262 | /* Shuttle eHome Infrared Transceiver */ |
| 263 | { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) }, |
| 264 | /* Gateway eHome Infrared Transceiver */ |
| 265 | { USB_DEVICE(VENDOR_GATEWAY, 0x3009) }, |
| 266 | /* Mitsumi */ |
| 267 | { USB_DEVICE(VENDOR_MITSUMI, 0x2501) }, |
| 268 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 269 | { USB_DEVICE(VENDOR_TOPSEED, 0x0001), |
| 270 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 271 | /* Topseed HP eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 272 | { USB_DEVICE(VENDOR_TOPSEED, 0x0006), |
| 273 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 274 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 275 | { USB_DEVICE(VENDOR_TOPSEED, 0x0007), |
| 276 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 277 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 278 | { USB_DEVICE(VENDOR_TOPSEED, 0x0008), |
| 279 | .driver_info = MCE_GEN3 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 280 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 281 | { USB_DEVICE(VENDOR_TOPSEED, 0x000a), |
| 282 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 283 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 284 | { USB_DEVICE(VENDOR_TOPSEED, 0x0011), |
Jarod Wilson | 7d9a46f | 2011-03-04 20:20:47 -0300 | [diff] [blame] | 285 | .driver_info = MCE_GEN3 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 286 | /* Ricavision internal Infrared Transceiver */ |
| 287 | { USB_DEVICE(VENDOR_RICAVISION, 0x0010) }, |
| 288 | /* Itron ione Libra Q-11 */ |
| 289 | { USB_DEVICE(VENDOR_ITRON, 0x7002) }, |
| 290 | /* FIC eHome Infrared Transceiver */ |
| 291 | { USB_DEVICE(VENDOR_FIC, 0x9242) }, |
| 292 | /* LG eHome Infrared Transceiver */ |
| 293 | { USB_DEVICE(VENDOR_LG, 0x9803) }, |
| 294 | /* Microsoft MCE Infrared Transceiver */ |
| 295 | { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) }, |
| 296 | /* Formosa eHome Infrared Transceiver */ |
| 297 | { USB_DEVICE(VENDOR_FORMOSA, 0xe015) }, |
| 298 | /* Formosa21 / eHome Infrared Receiver */ |
| 299 | { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, |
| 300 | /* Formosa aim / Trust MCE Infrared Receiver */ |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 301 | { USB_DEVICE(VENDOR_FORMOSA, 0xe017), |
| 302 | .driver_info = MCE_GEN2_NO_TX }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 303 | /* Formosa Industrial Computing / Beanbag Emulation Device */ |
| 304 | { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, |
| 305 | /* Formosa21 / eHome Infrared Receiver */ |
| 306 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) }, |
| 307 | /* Formosa Industrial Computing AIM IR605/A */ |
| 308 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) }, |
| 309 | /* Formosa Industrial Computing */ |
| 310 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03e) }, |
Jarod Wilson | fbb1f1b | 2010-12-16 13:27:11 -0300 | [diff] [blame] | 311 | /* Fintek eHome Infrared Transceiver (HP branded) */ |
| 312 | { USB_DEVICE(VENDOR_FINTEK, 0x5168) }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 313 | /* Fintek eHome Infrared Transceiver */ |
| 314 | { USB_DEVICE(VENDOR_FINTEK, 0x0602) }, |
| 315 | /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */ |
| 316 | { USB_DEVICE(VENDOR_FINTEK, 0x0702) }, |
| 317 | /* Pinnacle Remote Kit */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 318 | { USB_DEVICE(VENDOR_PINNACLE, 0x0225), |
| 319 | .driver_info = MCE_GEN3 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 320 | /* Elitegroup Computer Systems IR */ |
| 321 | { USB_DEVICE(VENDOR_ECS, 0x0f38) }, |
| 322 | /* Wistron Corp. eHome Infrared Receiver */ |
| 323 | { USB_DEVICE(VENDOR_WISTRON, 0x0002) }, |
| 324 | /* Compro K100 */ |
| 325 | { USB_DEVICE(VENDOR_COMPRO, 0x3020) }, |
| 326 | /* Compro K100 v2 */ |
| 327 | { USB_DEVICE(VENDOR_COMPRO, 0x3082) }, |
| 328 | /* Northstar Systems, Inc. eHome Infrared Transceiver */ |
| 329 | { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, |
| 330 | /* TiVo PC IR Receiver */ |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 331 | { USB_DEVICE(VENDOR_TIVO, 0x2000), |
| 332 | .driver_info = TIVO_KIT }, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 333 | /* Conexant Hybrid TV "Shelby" Polaris SDK */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 334 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a1), |
| 335 | .driver_info = POLARIS_EVK }, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 336 | /* Conexant Hybrid TV RDU253S Polaris */ |
| 337 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a5), |
| 338 | .driver_info = CX_HYBRID_TV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 339 | /* Terminating entry */ |
| 340 | { } |
| 341 | }; |
| 342 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 343 | /* data structure for each usb transceiver */ |
| 344 | struct mceusb_dev { |
| 345 | /* ir-core bits */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 346 | struct rc_dev *rc; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 347 | |
| 348 | /* optional features we can enable */ |
| 349 | bool carrier_report_enabled; |
| 350 | bool learning_enabled; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 351 | |
| 352 | /* core device bits */ |
| 353 | struct device *dev; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 354 | |
| 355 | /* usb */ |
| 356 | struct usb_device *usbdev; |
| 357 | struct urb *urb_in; |
| 358 | struct usb_endpoint_descriptor *usb_ep_in; |
| 359 | struct usb_endpoint_descriptor *usb_ep_out; |
| 360 | |
| 361 | /* buffers and dma */ |
| 362 | unsigned char *buf_in; |
| 363 | unsigned int len_in; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 364 | dma_addr_t dma_in; |
| 365 | dma_addr_t dma_out; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 366 | |
| 367 | enum { |
| 368 | CMD_HEADER = 0, |
| 369 | SUBCMD, |
| 370 | CMD_DATA, |
| 371 | PARSE_IRDATA, |
| 372 | } parser_state; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 373 | |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 374 | u8 cmd, rem; /* Remaining IR data bytes in packet */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 375 | |
| 376 | struct { |
| 377 | u32 connected:1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 378 | u32 tx_mask_normal:1; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 379 | u32 microsoft_gen1:1; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 380 | u32 no_tx:1; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 381 | } flags; |
| 382 | |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 383 | /* transmit support */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 384 | int send_flags; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 385 | u32 carrier; |
| 386 | unsigned char tx_mask; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 387 | |
| 388 | char name[128]; |
| 389 | char phys[64]; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 390 | enum mceusb_model_type model; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 391 | }; |
| 392 | |
| 393 | /* |
| 394 | * MCE Device Command Strings |
| 395 | * Device command responses vary from device to device... |
| 396 | * - DEVICE_RESET resets the hardware to its default state |
| 397 | * - GET_REVISION fetches the hardware/software revision, common |
| 398 | * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42 |
| 399 | * - GET_CARRIER_FREQ gets the carrier mode and frequency of the |
| 400 | * device, with replies in the form of 9f 06 MM FF, where MM is 0-3, |
| 401 | * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is |
| 402 | * ((clk / frequency) - 1) |
| 403 | * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us, |
| 404 | * response in the form of 9f 0c msb lsb |
| 405 | * - GET_TX_BITMASK fetches the transmitter bitmask, replies in |
| 406 | * the form of 9f 08 bm, where bm is the bitmask |
| 407 | * - GET_RX_SENSOR fetches the RX sensor setting -- long-range |
| 408 | * general use one or short-range learning one, in the form of |
| 409 | * 9f 14 ss, where ss is either 01 for long-range or 02 for short |
| 410 | * - SET_CARRIER_FREQ sets a new carrier mode and frequency |
| 411 | * - SET_TX_BITMASK sets the transmitter bitmask |
| 412 | * - SET_RX_TIMEOUT sets the receiver timeout |
| 413 | * - SET_RX_SENSOR sets which receiver sensor to use |
| 414 | */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 415 | static char DEVICE_RESET[] = {MCE_COMMAND_NULL, MCE_HW_CMD_HEADER, |
| 416 | MCE_CMD_DEVICE_RESET}; |
| 417 | static char GET_REVISION[] = {MCE_HW_CMD_HEADER, MCE_CMD_G_REVISION}; |
| 418 | static char GET_UNKNOWN[] = {MCE_HW_CMD_HEADER, MCE_CMD_UNKNOWN7}; |
| 419 | static char GET_UNKNOWN2[] = {MCE_COMMAND_HEADER, MCE_CMD_UNKNOWN2}; |
| 420 | static char GET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER, MCE_CMD_G_CARRIER}; |
| 421 | static char GET_RX_TIMEOUT[] = {MCE_COMMAND_HEADER, MCE_CMD_G_TIMEOUT}; |
| 422 | static char GET_TX_BITMASK[] = {MCE_COMMAND_HEADER, MCE_CMD_G_TXMASK}; |
| 423 | static char GET_RX_SENSOR[] = {MCE_COMMAND_HEADER, MCE_CMD_G_RXSENSOR}; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 424 | /* sub in desired values in lower byte or bytes for full command */ |
| 425 | /* FIXME: make use of these for transmit. |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 426 | static char SET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER, |
| 427 | MCE_CMD_S_CARRIER, 0x00, 0x00}; |
| 428 | static char SET_TX_BITMASK[] = {MCE_COMMAND_HEADER, MCE_CMD_S_TXMASK, 0x00}; |
| 429 | static char SET_RX_TIMEOUT[] = {MCE_COMMAND_HEADER, |
| 430 | MCE_CMD_S_TIMEOUT, 0x00, 0x00}; |
| 431 | static char SET_RX_SENSOR[] = {MCE_COMMAND_HEADER, |
| 432 | MCE_CMD_S_RXSENSOR, 0x00}; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 433 | */ |
| 434 | |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 435 | static int mceusb_cmdsize(u8 cmd, u8 subcmd) |
| 436 | { |
| 437 | int datasize = 0; |
| 438 | |
| 439 | switch (cmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 440 | case MCE_COMMAND_NULL: |
| 441 | if (subcmd == MCE_HW_CMD_HEADER) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 442 | datasize = 1; |
| 443 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 444 | case MCE_HW_CMD_HEADER: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 445 | switch (subcmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 446 | case MCE_CMD_G_REVISION: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 447 | datasize = 2; |
| 448 | break; |
| 449 | } |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 450 | case MCE_COMMAND_HEADER: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 451 | switch (subcmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 452 | case MCE_CMD_UNKNOWN: |
| 453 | case MCE_CMD_S_CARRIER: |
| 454 | case MCE_CMD_S_TIMEOUT: |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 455 | case MCE_RSP_PULSE_COUNT: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 456 | datasize = 2; |
| 457 | break; |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 458 | case MCE_CMD_SIG_END: |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 459 | case MCE_CMD_S_TXMASK: |
| 460 | case MCE_CMD_S_RXSENSOR: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 461 | datasize = 1; |
| 462 | break; |
| 463 | } |
| 464 | } |
| 465 | return datasize; |
| 466 | } |
| 467 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 468 | static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf, |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 469 | int offset, int len, bool out) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 470 | { |
| 471 | char codes[USB_BUFLEN * 3 + 1]; |
| 472 | char inout[9]; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 473 | u8 cmd, subcmd, data1, data2; |
| 474 | struct device *dev = ir->dev; |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 475 | int i, start, skip = 0; |
| 476 | |
| 477 | if (!debug) |
| 478 | return; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 479 | |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 480 | /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ |
Jarod Wilson | 29b4494 | 2010-11-09 18:41:46 -0300 | [diff] [blame] | 481 | if (ir->flags.microsoft_gen1 && !out && !offset) |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 482 | skip = 2; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 483 | |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 484 | if (len <= skip) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 485 | return; |
| 486 | |
| 487 | for (i = 0; i < len && i < USB_BUFLEN; i++) |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 488 | snprintf(codes + i * 3, 4, "%02x ", buf[i + offset] & 0xff); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 489 | |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 490 | dev_info(dev, "%sx data: %s(length=%d)\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 491 | (out ? "t" : "r"), codes, len); |
| 492 | |
| 493 | if (out) |
| 494 | strcpy(inout, "Request\0"); |
| 495 | else |
| 496 | strcpy(inout, "Got\0"); |
| 497 | |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 498 | start = offset + skip; |
| 499 | cmd = buf[start] & 0xff; |
| 500 | subcmd = buf[start + 1] & 0xff; |
| 501 | data1 = buf[start + 2] & 0xff; |
| 502 | data2 = buf[start + 3] & 0xff; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 503 | |
| 504 | switch (cmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 505 | case MCE_COMMAND_NULL: |
| 506 | if ((subcmd == MCE_HW_CMD_HEADER) && |
| 507 | (data1 == MCE_CMD_DEVICE_RESET)) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 508 | dev_info(dev, "Device reset requested\n"); |
| 509 | else |
| 510 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", |
| 511 | cmd, subcmd); |
| 512 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 513 | case MCE_HW_CMD_HEADER: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 514 | switch (subcmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 515 | case MCE_CMD_G_REVISION: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 516 | if (len == 2) |
| 517 | dev_info(dev, "Get hw/sw rev?\n"); |
| 518 | else |
| 519 | dev_info(dev, "hw/sw rev 0x%02x 0x%02x " |
| 520 | "0x%02x 0x%02x\n", data1, data2, |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 521 | buf[start + 4], buf[start + 5]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 522 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 523 | case MCE_CMD_DEVICE_RESET: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 524 | dev_info(dev, "Device reset requested\n"); |
| 525 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 526 | case MCE_RSP_CMD_INVALID: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 527 | dev_info(dev, "Previous command not supported\n"); |
| 528 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 529 | case MCE_CMD_UNKNOWN7: |
| 530 | case MCE_CMD_UNKNOWN9: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 531 | default: |
| 532 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", |
| 533 | cmd, subcmd); |
| 534 | break; |
| 535 | } |
| 536 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 537 | case MCE_COMMAND_HEADER: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 538 | switch (subcmd) { |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 539 | case MCE_CMD_SIG_END: |
| 540 | dev_info(dev, "End of signal\n"); |
| 541 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 542 | case MCE_CMD_PING: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 543 | dev_info(dev, "Ping\n"); |
| 544 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 545 | case MCE_CMD_UNKNOWN: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 546 | dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n", |
| 547 | data1, data2); |
| 548 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 549 | case MCE_CMD_S_CARRIER: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 550 | dev_info(dev, "%s carrier mode and freq of " |
| 551 | "0x%02x 0x%02x\n", inout, data1, data2); |
| 552 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 553 | case MCE_CMD_G_CARRIER: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 554 | dev_info(dev, "Get carrier mode and freq\n"); |
| 555 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 556 | case MCE_CMD_S_TXMASK: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 557 | dev_info(dev, "%s transmit blaster mask of 0x%02x\n", |
| 558 | inout, data1); |
| 559 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 560 | case MCE_CMD_S_TIMEOUT: |
Rafi Rubin | f3e456c | 2011-07-03 17:13:52 -0300 | [diff] [blame] | 561 | /* value is in units of 50us, so x*50/1000 ms */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 562 | dev_info(dev, "%s receive timeout of %d ms\n", |
Rafi Rubin | f3e456c | 2011-07-03 17:13:52 -0300 | [diff] [blame] | 563 | inout, |
| 564 | ((data1 << 8) | data2) * MCE_TIME_UNIT / 1000); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 565 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 566 | case MCE_CMD_G_TIMEOUT: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 567 | dev_info(dev, "Get receive timeout\n"); |
| 568 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 569 | case MCE_CMD_G_TXMASK: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 570 | dev_info(dev, "Get transmit blaster mask\n"); |
| 571 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 572 | case MCE_CMD_S_RXSENSOR: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 573 | dev_info(dev, "%s %s-range receive sensor in use\n", |
| 574 | inout, data1 == 0x02 ? "short" : "long"); |
| 575 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 576 | case MCE_CMD_G_RXSENSOR: |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 577 | /* aka MCE_RSP_PULSE_COUNT */ |
| 578 | if (out) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 579 | dev_info(dev, "Get receive sensor\n"); |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 580 | else if (ir->learning_enabled) |
| 581 | dev_info(dev, "RX pulse count: %d\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 582 | ((data1 << 8) | data2)); |
| 583 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 584 | case MCE_RSP_CMD_INVALID: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 585 | dev_info(dev, "Error! Hardware is likely wedged...\n"); |
| 586 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 587 | case MCE_CMD_UNKNOWN2: |
| 588 | case MCE_CMD_UNKNOWN3: |
| 589 | case MCE_CMD_UNKNOWN5: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 590 | default: |
| 591 | dev_info(dev, "Unknown command 0x%02x 0x%02x\n", |
| 592 | cmd, subcmd); |
| 593 | break; |
| 594 | } |
| 595 | break; |
| 596 | default: |
| 597 | break; |
| 598 | } |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 599 | |
| 600 | if (cmd == MCE_IRDATA_TRAILER) |
| 601 | dev_info(dev, "End of raw IR data\n"); |
| 602 | else if ((cmd != MCE_COMMAND_HEADER) && |
| 603 | ((cmd & MCE_COMMAND_MASK) == MCE_COMMAND_IRDATA)) |
| 604 | dev_info(dev, "Raw IR data, %d pulse/space samples\n", ir->rem); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 605 | } |
| 606 | |
Jarod Wilson | 7c29440 | 2010-08-02 18:21:06 -0300 | [diff] [blame] | 607 | static void mce_async_callback(struct urb *urb, struct pt_regs *regs) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 608 | { |
| 609 | struct mceusb_dev *ir; |
| 610 | int len; |
| 611 | |
| 612 | if (!urb) |
| 613 | return; |
| 614 | |
| 615 | ir = urb->context; |
| 616 | if (ir) { |
| 617 | len = urb->actual_length; |
| 618 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 619 | mce_dbg(ir->dev, "callback called (status=%d len=%d)\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 620 | urb->status, len); |
| 621 | |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 622 | mceusb_dev_printdata(ir, urb->transfer_buffer, 0, len, true); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 623 | } |
| 624 | |
Jarod Wilson | 0b43fcd | 2011-05-24 16:44:54 -0300 | [diff] [blame] | 625 | /* the transfer buffer and urb were allocated in mce_request_packet */ |
| 626 | kfree(urb->transfer_buffer); |
| 627 | usb_free_urb(urb); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* request incoming or send outgoing usb packet - used to initialize remote */ |
Jarod Wilson | 51ea629 | 2011-05-10 14:09:59 -0300 | [diff] [blame] | 631 | static void mce_request_packet(struct mceusb_dev *ir, unsigned char *data, |
| 632 | int size, int urb_type) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 633 | { |
Jarod Wilson | 51ea629 | 2011-05-10 14:09:59 -0300 | [diff] [blame] | 634 | int res, pipe; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 635 | struct urb *async_urb; |
| 636 | struct device *dev = ir->dev; |
| 637 | unsigned char *async_buf; |
| 638 | |
| 639 | if (urb_type == MCEUSB_TX) { |
| 640 | async_urb = usb_alloc_urb(0, GFP_KERNEL); |
| 641 | if (unlikely(!async_urb)) { |
| 642 | dev_err(dev, "Error, couldn't allocate urb!\n"); |
| 643 | return; |
| 644 | } |
| 645 | |
| 646 | async_buf = kzalloc(size, GFP_KERNEL); |
| 647 | if (!async_buf) { |
| 648 | dev_err(dev, "Error, couldn't allocate buf!\n"); |
| 649 | usb_free_urb(async_urb); |
| 650 | return; |
| 651 | } |
| 652 | |
| 653 | /* outbound data */ |
Jarod Wilson | 51ea629 | 2011-05-10 14:09:59 -0300 | [diff] [blame] | 654 | pipe = usb_sndintpipe(ir->usbdev, |
| 655 | ir->usb_ep_out->bEndpointAddress); |
| 656 | usb_fill_int_urb(async_urb, ir->usbdev, pipe, |
Jarod Wilson | 7c29440 | 2010-08-02 18:21:06 -0300 | [diff] [blame] | 657 | async_buf, size, (usb_complete_t)mce_async_callback, |
Jarod Wilson | 51ea629 | 2011-05-10 14:09:59 -0300 | [diff] [blame] | 658 | ir, ir->usb_ep_out->bInterval); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 659 | memcpy(async_buf, data, size); |
| 660 | |
| 661 | } else if (urb_type == MCEUSB_RX) { |
| 662 | /* standard request */ |
| 663 | async_urb = ir->urb_in; |
| 664 | ir->send_flags = RECV_FLAG_IN_PROGRESS; |
| 665 | |
| 666 | } else { |
| 667 | dev_err(dev, "Error! Unknown urb type %d\n", urb_type); |
| 668 | return; |
| 669 | } |
| 670 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 671 | mce_dbg(dev, "receive request called (size=%#x)\n", size); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 672 | |
| 673 | async_urb->transfer_buffer_length = size; |
| 674 | async_urb->dev = ir->usbdev; |
| 675 | |
| 676 | res = usb_submit_urb(async_urb, GFP_ATOMIC); |
| 677 | if (res) { |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 678 | mce_dbg(dev, "receive request FAILED! (res=%d)\n", res); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 679 | return; |
| 680 | } |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 681 | mce_dbg(dev, "receive request complete (res=%d)\n", res); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size) |
| 685 | { |
Jarod Wilson | 51ea629 | 2011-05-10 14:09:59 -0300 | [diff] [blame] | 686 | mce_request_packet(ir, data, size, MCEUSB_TX); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 687 | } |
| 688 | |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 689 | static void mce_flush_rx_buffer(struct mceusb_dev *ir, int size) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 690 | { |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 691 | mce_request_packet(ir, NULL, size, MCEUSB_RX); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 692 | } |
| 693 | |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 694 | /* Send data out the IR blaster port(s) */ |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame^] | 695 | static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count) |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 696 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 697 | struct mceusb_dev *ir = dev->priv; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 698 | int i, ret = 0; |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame^] | 699 | int cmdcount = 0; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 700 | unsigned char *cmdbuf; /* MCE command buffer */ |
| 701 | long signal_duration = 0; /* Singnal length in us */ |
| 702 | struct timeval start_time, end_time; |
| 703 | |
| 704 | do_gettimeofday(&start_time); |
| 705 | |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame^] | 706 | cmdbuf = kzalloc(sizeof(unsigned) * MCE_CMDBUF_SIZE, GFP_KERNEL); |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 707 | if (!cmdbuf) |
| 708 | return -ENOMEM; |
| 709 | |
| 710 | /* MCE tx init header */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 711 | cmdbuf[cmdcount++] = MCE_COMMAND_HEADER; |
| 712 | cmdbuf[cmdcount++] = MCE_CMD_S_TXMASK; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 713 | cmdbuf[cmdcount++] = ir->tx_mask; |
| 714 | |
| 715 | /* Generate mce packet data */ |
| 716 | for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) { |
| 717 | signal_duration += txbuf[i]; |
| 718 | txbuf[i] = txbuf[i] / MCE_TIME_UNIT; |
| 719 | |
| 720 | do { /* loop to support long pulses/spaces > 127*50us=6.35ms */ |
| 721 | |
| 722 | /* Insert mce packet header every 4th entry */ |
| 723 | if ((cmdcount < MCE_CMDBUF_SIZE) && |
| 724 | (cmdcount - MCE_TX_HEADER_LENGTH) % |
| 725 | MCE_CODE_LENGTH == 0) |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 726 | cmdbuf[cmdcount++] = MCE_IRDATA_HEADER; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 727 | |
| 728 | /* Insert mce packet data */ |
| 729 | if (cmdcount < MCE_CMDBUF_SIZE) |
| 730 | cmdbuf[cmdcount++] = |
| 731 | (txbuf[i] < MCE_PULSE_BIT ? |
| 732 | txbuf[i] : MCE_MAX_PULSE_LENGTH) | |
| 733 | (i & 1 ? 0x00 : MCE_PULSE_BIT); |
| 734 | else { |
| 735 | ret = -EINVAL; |
| 736 | goto out; |
| 737 | } |
| 738 | |
| 739 | } while ((txbuf[i] > MCE_MAX_PULSE_LENGTH) && |
| 740 | (txbuf[i] -= MCE_MAX_PULSE_LENGTH)); |
| 741 | } |
| 742 | |
| 743 | /* Fix packet length in last header */ |
| 744 | cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] = |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 745 | MCE_COMMAND_IRDATA + (cmdcount - MCE_TX_HEADER_LENGTH) % |
| 746 | MCE_CODE_LENGTH - 1; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 747 | |
| 748 | /* Check if we have room for the empty packet at the end */ |
| 749 | if (cmdcount >= MCE_CMDBUF_SIZE) { |
| 750 | ret = -EINVAL; |
| 751 | goto out; |
| 752 | } |
| 753 | |
| 754 | /* All mce commands end with an empty packet (0x80) */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 755 | cmdbuf[cmdcount++] = MCE_IRDATA_TRAILER; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 756 | |
| 757 | /* Transmit the command to the mce device */ |
| 758 | mce_async_out(ir, cmdbuf, cmdcount); |
| 759 | |
| 760 | /* |
| 761 | * The lircd gap calculation expects the write function to |
| 762 | * wait the time it takes for the ircommand to be sent before |
| 763 | * it returns. |
| 764 | */ |
| 765 | do_gettimeofday(&end_time); |
| 766 | signal_duration -= (end_time.tv_usec - start_time.tv_usec) + |
| 767 | (end_time.tv_sec - start_time.tv_sec) * 1000000; |
| 768 | |
| 769 | /* delay with the closest number of ticks */ |
| 770 | set_current_state(TASK_INTERRUPTIBLE); |
| 771 | schedule_timeout(usecs_to_jiffies(signal_duration)); |
| 772 | |
| 773 | out: |
| 774 | kfree(cmdbuf); |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame^] | 775 | return ret ? ret : count; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 776 | } |
| 777 | |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 778 | /* Sets active IR outputs -- mce devices typically have two */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 779 | static int mceusb_set_tx_mask(struct rc_dev *dev, u32 mask) |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 780 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 781 | struct mceusb_dev *ir = dev->priv; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 782 | |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 783 | if (ir->flags.tx_mask_normal) |
| 784 | ir->tx_mask = mask; |
| 785 | else |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 786 | ir->tx_mask = (mask != MCE_DEFAULT_TX_MASK ? |
| 787 | mask ^ MCE_DEFAULT_TX_MASK : mask) << 1; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 792 | /* Sets the send carrier frequency and mode */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 793 | static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier) |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 794 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 795 | struct mceusb_dev *ir = dev->priv; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 796 | int clk = 10000000; |
| 797 | int prescaler = 0, divisor = 0; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 798 | unsigned char cmdbuf[4] = { MCE_COMMAND_HEADER, |
| 799 | MCE_CMD_S_CARRIER, 0x00, 0x00 }; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 800 | |
| 801 | /* Carrier has changed */ |
| 802 | if (ir->carrier != carrier) { |
| 803 | |
| 804 | if (carrier == 0) { |
| 805 | ir->carrier = carrier; |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 806 | cmdbuf[2] = MCE_CMD_SIG_END; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 807 | cmdbuf[3] = MCE_IRDATA_TRAILER; |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 808 | mce_dbg(ir->dev, "%s: disabling carrier " |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 809 | "modulation\n", __func__); |
| 810 | mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); |
| 811 | return carrier; |
| 812 | } |
| 813 | |
| 814 | for (prescaler = 0; prescaler < 4; ++prescaler) { |
| 815 | divisor = (clk >> (2 * prescaler)) / carrier; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 816 | if (divisor <= 0xff) { |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 817 | ir->carrier = carrier; |
| 818 | cmdbuf[2] = prescaler; |
| 819 | cmdbuf[3] = divisor; |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 820 | mce_dbg(ir->dev, "%s: requesting %u HZ " |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 821 | "carrier\n", __func__, carrier); |
| 822 | |
| 823 | /* Transmit new carrier to mce device */ |
| 824 | mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); |
| 825 | return carrier; |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | return -EINVAL; |
| 830 | |
| 831 | } |
| 832 | |
| 833 | return carrier; |
| 834 | } |
| 835 | |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 836 | /* |
| 837 | * We don't do anything but print debug spew for many of the command bits |
| 838 | * we receive from the hardware, but some of them are useful information |
| 839 | * we want to store so that we can use them. |
| 840 | */ |
| 841 | static void mceusb_handle_command(struct mceusb_dev *ir, int index) |
| 842 | { |
| 843 | u8 hi = ir->buf_in[index + 1] & 0xff; |
| 844 | u8 lo = ir->buf_in[index + 2] & 0xff; |
| 845 | |
| 846 | switch (ir->buf_in[index]) { |
| 847 | /* 2-byte return value commands */ |
| 848 | case MCE_CMD_S_TIMEOUT: |
Rafi Rubin | f3e456c | 2011-07-03 17:13:52 -0300 | [diff] [blame] | 849 | ir->rc->timeout = US_TO_NS((hi << 8 | lo) * MCE_TIME_UNIT); |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 850 | break; |
| 851 | |
| 852 | /* 1-byte return value commands */ |
| 853 | case MCE_CMD_S_TXMASK: |
| 854 | ir->tx_mask = hi; |
| 855 | break; |
| 856 | case MCE_CMD_S_RXSENSOR: |
| 857 | ir->learning_enabled = (hi == 0x02); |
| 858 | break; |
| 859 | default: |
| 860 | break; |
| 861 | } |
| 862 | } |
| 863 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 864 | static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) |
| 865 | { |
Maxim Levitsky | 4651918 | 2010-10-16 19:56:28 -0300 | [diff] [blame] | 866 | DEFINE_IR_RAW_EVENT(rawir); |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 867 | int i = 0; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 868 | |
| 869 | /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ |
| 870 | if (ir->flags.microsoft_gen1) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 871 | i = 2; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 872 | |
Jarod Wilson | 29b4494 | 2010-11-09 18:41:46 -0300 | [diff] [blame] | 873 | /* if there's no data, just return now */ |
| 874 | if (buf_len <= i) |
| 875 | return; |
| 876 | |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 877 | for (; i < buf_len; i++) { |
| 878 | switch (ir->parser_state) { |
| 879 | case SUBCMD: |
| 880 | ir->rem = mceusb_cmdsize(ir->cmd, ir->buf_in[i]); |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 881 | mceusb_dev_printdata(ir, ir->buf_in, i - 1, |
| 882 | ir->rem + 2, false); |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 883 | mceusb_handle_command(ir, i); |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 884 | ir->parser_state = CMD_DATA; |
| 885 | break; |
| 886 | case PARSE_IRDATA: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 887 | ir->rem--; |
Jarod Wilson | 5bd9d73 | 2011-01-26 12:20:09 -0300 | [diff] [blame] | 888 | init_ir_raw_event(&rawir); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 889 | rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0); |
| 890 | rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK) |
Jarod Wilson | b4608fa | 2011-01-18 17:31:24 -0300 | [diff] [blame] | 891 | * US_TO_NS(MCE_TIME_UNIT); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 892 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 893 | mce_dbg(ir->dev, "Storing %s with duration %d\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 894 | rawir.pulse ? "pulse" : "space", |
| 895 | rawir.duration); |
| 896 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 897 | ir_raw_event_store_with_filter(ir->rc, &rawir); |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 898 | break; |
| 899 | case CMD_DATA: |
| 900 | ir->rem--; |
| 901 | break; |
| 902 | case CMD_HEADER: |
| 903 | /* decode mce packets of the form (84),AA,BB,CC,DD */ |
| 904 | /* IR data packets can span USB messages - rem */ |
| 905 | ir->cmd = ir->buf_in[i]; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 906 | if ((ir->cmd == MCE_COMMAND_HEADER) || |
| 907 | ((ir->cmd & MCE_COMMAND_MASK) != |
| 908 | MCE_COMMAND_IRDATA)) { |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 909 | ir->parser_state = SUBCMD; |
| 910 | continue; |
| 911 | } |
| 912 | ir->rem = (ir->cmd & MCE_PACKET_LENGTH_MASK); |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 913 | mceusb_dev_printdata(ir, ir->buf_in, |
| 914 | i, ir->rem + 1, false); |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 915 | if (ir->rem) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 916 | ir->parser_state = PARSE_IRDATA; |
Jarod Wilson | 5bd9d73 | 2011-01-26 12:20:09 -0300 | [diff] [blame] | 917 | else |
| 918 | ir_raw_event_reset(ir->rc); |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 919 | break; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 920 | } |
| 921 | |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 922 | if (ir->parser_state != CMD_HEADER && !ir->rem) |
| 923 | ir->parser_state = CMD_HEADER; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 924 | } |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 925 | mce_dbg(ir->dev, "processed IR data, calling ir_raw_event_handle\n"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 926 | ir_raw_event_handle(ir->rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 927 | } |
| 928 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 929 | static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs) |
| 930 | { |
| 931 | struct mceusb_dev *ir; |
| 932 | int buf_len; |
| 933 | |
| 934 | if (!urb) |
| 935 | return; |
| 936 | |
| 937 | ir = urb->context; |
| 938 | if (!ir) { |
| 939 | usb_unlink_urb(urb); |
| 940 | return; |
| 941 | } |
| 942 | |
| 943 | buf_len = urb->actual_length; |
| 944 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 945 | if (ir->send_flags == RECV_FLAG_IN_PROGRESS) { |
| 946 | ir->send_flags = SEND_FLAG_COMPLETE; |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 947 | mce_dbg(ir->dev, "setup answer received %d bytes\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 948 | buf_len); |
| 949 | } |
| 950 | |
| 951 | switch (urb->status) { |
| 952 | /* success */ |
| 953 | case 0: |
| 954 | mceusb_process_ir_data(ir, buf_len); |
| 955 | break; |
| 956 | |
| 957 | case -ECONNRESET: |
| 958 | case -ENOENT: |
| 959 | case -ESHUTDOWN: |
| 960 | usb_unlink_urb(urb); |
| 961 | return; |
| 962 | |
| 963 | case -EPIPE: |
| 964 | default: |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 965 | mce_dbg(ir->dev, "Error: urb status = %d\n", urb->status); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 966 | break; |
| 967 | } |
| 968 | |
| 969 | usb_submit_urb(urb, GFP_ATOMIC); |
| 970 | } |
| 971 | |
| 972 | static void mceusb_gen1_init(struct mceusb_dev *ir) |
| 973 | { |
Mauro Carvalho Chehab | ca17a4f | 2010-07-10 11:19:42 -0300 | [diff] [blame] | 974 | int ret; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 975 | struct device *dev = ir->dev; |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 976 | char *data; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 977 | |
| 978 | data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL); |
| 979 | if (!data) { |
| 980 | dev_err(dev, "%s: memory allocation failed!\n", __func__); |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 981 | return; |
| 982 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 983 | |
| 984 | /* |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 985 | * This is a strange one. Windows issues a set address to the device |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 986 | * on the receive control pipe and expect a certain value pair back |
| 987 | */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 988 | ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), |
| 989 | USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0, |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 990 | data, USB_CTRL_MSG_SZ, HZ * 3); |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 991 | mce_dbg(dev, "%s - ret = %d\n", __func__, ret); |
| 992 | mce_dbg(dev, "%s - data[0] = %d, data[1] = %d\n", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 993 | __func__, data[0], data[1]); |
| 994 | |
| 995 | /* set feature: bit rate 38400 bps */ |
| 996 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 997 | USB_REQ_SET_FEATURE, USB_TYPE_VENDOR, |
| 998 | 0xc04e, 0x0000, NULL, 0, HZ * 3); |
| 999 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1000 | mce_dbg(dev, "%s - ret = %d\n", __func__, ret); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1001 | |
| 1002 | /* bRequest 4: set char length to 8 bits */ |
| 1003 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 1004 | 4, USB_TYPE_VENDOR, |
| 1005 | 0x0808, 0x0000, NULL, 0, HZ * 3); |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1006 | mce_dbg(dev, "%s - retB = %d\n", __func__, ret); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1007 | |
| 1008 | /* bRequest 2: set handshaking to use DTR/DSR */ |
| 1009 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 1010 | 2, USB_TYPE_VENDOR, |
| 1011 | 0x0000, 0x0100, NULL, 0, HZ * 3); |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1012 | mce_dbg(dev, "%s - retC = %d\n", __func__, ret); |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1013 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1014 | /* device reset */ |
| 1015 | mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1016 | |
| 1017 | /* get hw/sw revision? */ |
| 1018 | mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1019 | |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1020 | kfree(data); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1021 | }; |
| 1022 | |
| 1023 | static void mceusb_gen2_init(struct mceusb_dev *ir) |
| 1024 | { |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1025 | /* device reset */ |
| 1026 | mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1027 | |
| 1028 | /* get hw/sw revision? */ |
| 1029 | mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1030 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1031 | /* unknown what the next two actually return... */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1032 | mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN)); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1033 | mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1034 | } |
| 1035 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1036 | static void mceusb_get_parameters(struct mceusb_dev *ir) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1037 | { |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1038 | /* get the carrier and frequency */ |
| 1039 | mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1040 | |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 1041 | if (!ir->flags.no_tx) |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1042 | /* get the transmitter bitmask */ |
| 1043 | mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1044 | |
| 1045 | /* get receiver timeout value */ |
| 1046 | mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1047 | |
| 1048 | /* get receiver sensor setting */ |
| 1049 | mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1050 | } |
| 1051 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1052 | static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1053 | { |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1054 | struct device *dev = ir->dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1055 | struct rc_dev *rc; |
| 1056 | int ret; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1057 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1058 | rc = rc_allocate_device(); |
| 1059 | if (!rc) { |
| 1060 | dev_err(dev, "remote dev allocation failed\n"); |
| 1061 | goto out; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1062 | } |
| 1063 | |
Mauro Carvalho Chehab | 3459d45 | 2010-10-22 11:52:53 -0300 | [diff] [blame] | 1064 | snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)", |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1065 | mceusb_model[ir->model].name ? |
Paul Bender | 5ad1a55 | 2010-11-17 16:56:17 -0300 | [diff] [blame] | 1066 | mceusb_model[ir->model].name : |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1067 | "Media Center Ed. eHome Infrared Remote Transceiver", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1068 | le16_to_cpu(ir->usbdev->descriptor.idVendor), |
| 1069 | le16_to_cpu(ir->usbdev->descriptor.idProduct)); |
| 1070 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1071 | usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1072 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1073 | rc->input_name = ir->name; |
| 1074 | rc->input_phys = ir->phys; |
| 1075 | usb_to_input_id(ir->usbdev, &rc->input_id); |
| 1076 | rc->dev.parent = dev; |
| 1077 | rc->priv = ir; |
| 1078 | rc->driver_type = RC_DRIVER_IR_RAW; |
Mauro Carvalho Chehab | 52b6614 | 2010-11-17 14:20:52 -0300 | [diff] [blame] | 1079 | rc->allowed_protos = RC_TYPE_ALL; |
Rafi Rubin | 9824ae4 | 2011-07-03 17:13:53 -0300 | [diff] [blame] | 1080 | rc->timeout = MS_TO_NS(100); |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1081 | if (!ir->flags.no_tx) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1082 | rc->s_tx_mask = mceusb_set_tx_mask; |
| 1083 | rc->s_tx_carrier = mceusb_set_tx_carrier; |
| 1084 | rc->tx_ir = mceusb_tx_ir; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1085 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1086 | rc->driver_name = DRIVER_NAME; |
| 1087 | rc->map_name = mceusb_model[ir->model].rc_map ? |
| 1088 | mceusb_model[ir->model].rc_map : RC_MAP_RC6_MCE; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1089 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1090 | ret = rc_register_device(rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1091 | if (ret < 0) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1092 | dev_err(dev, "remote dev registration failed\n"); |
| 1093 | goto out; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1094 | } |
| 1095 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1096 | return rc; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1097 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1098 | out: |
| 1099 | rc_free_device(rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1100 | return NULL; |
| 1101 | } |
| 1102 | |
| 1103 | static int __devinit mceusb_dev_probe(struct usb_interface *intf, |
| 1104 | const struct usb_device_id *id) |
| 1105 | { |
| 1106 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1107 | struct usb_host_interface *idesc; |
| 1108 | struct usb_endpoint_descriptor *ep = NULL; |
| 1109 | struct usb_endpoint_descriptor *ep_in = NULL; |
| 1110 | struct usb_endpoint_descriptor *ep_out = NULL; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1111 | struct mceusb_dev *ir = NULL; |
Jarod Wilson | d732a72 | 2010-06-16 17:10:46 -0300 | [diff] [blame] | 1112 | int pipe, maxp, i; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1113 | char buf[63], name[128] = ""; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1114 | enum mceusb_model_type model = id->driver_info; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1115 | bool is_gen3; |
| 1116 | bool is_microsoft_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1117 | bool tx_mask_normal; |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1118 | int ir_intfnum; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1119 | |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1120 | mce_dbg(&intf->dev, "%s called\n", __func__); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1121 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1122 | idesc = intf->cur_altsetting; |
| 1123 | |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1124 | is_gen3 = mceusb_model[model].mce_gen3; |
| 1125 | is_microsoft_gen1 = mceusb_model[model].mce_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1126 | tx_mask_normal = mceusb_model[model].tx_mask_normal; |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1127 | ir_intfnum = mceusb_model[model].ir_intfnum; |
Mauro Carvalho Chehab | 56e92f6 | 2010-10-18 16:32:50 -0300 | [diff] [blame] | 1128 | |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1129 | /* There are multi-function devices with non-IR interfaces */ |
| 1130 | if (idesc->desc.bInterfaceNumber != ir_intfnum) |
| 1131 | return -ENODEV; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1132 | |
| 1133 | /* step through the endpoints to find first bulk in and out endpoint */ |
| 1134 | for (i = 0; i < idesc->desc.bNumEndpoints; ++i) { |
| 1135 | ep = &idesc->endpoint[i].desc; |
| 1136 | |
| 1137 | if ((ep_in == NULL) |
| 1138 | && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
| 1139 | == USB_DIR_IN) |
| 1140 | && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1141 | == USB_ENDPOINT_XFER_BULK) |
| 1142 | || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1143 | == USB_ENDPOINT_XFER_INT))) { |
| 1144 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1145 | ep_in = ep; |
| 1146 | ep_in->bmAttributes = USB_ENDPOINT_XFER_INT; |
Jarod Wilson | d732a72 | 2010-06-16 17:10:46 -0300 | [diff] [blame] | 1147 | ep_in->bInterval = 1; |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1148 | mce_dbg(&intf->dev, "acceptable inbound endpoint " |
Jarod Wilson | d732a72 | 2010-06-16 17:10:46 -0300 | [diff] [blame] | 1149 | "found\n"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | if ((ep_out == NULL) |
| 1153 | && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) |
| 1154 | == USB_DIR_OUT) |
| 1155 | && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1156 | == USB_ENDPOINT_XFER_BULK) |
| 1157 | || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) |
| 1158 | == USB_ENDPOINT_XFER_INT))) { |
| 1159 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1160 | ep_out = ep; |
| 1161 | ep_out->bmAttributes = USB_ENDPOINT_XFER_INT; |
Jarod Wilson | d732a72 | 2010-06-16 17:10:46 -0300 | [diff] [blame] | 1162 | ep_out->bInterval = 1; |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1163 | mce_dbg(&intf->dev, "acceptable outbound endpoint " |
Jarod Wilson | d732a72 | 2010-06-16 17:10:46 -0300 | [diff] [blame] | 1164 | "found\n"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | if (ep_in == NULL) { |
Jarod Wilson | 5ae8f9a | 2011-05-26 15:51:11 -0300 | [diff] [blame] | 1168 | mce_dbg(&intf->dev, "inbound and/or endpoint not found\n"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1169 | return -ENODEV; |
| 1170 | } |
| 1171 | |
| 1172 | pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress); |
| 1173 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); |
| 1174 | |
| 1175 | ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL); |
| 1176 | if (!ir) |
| 1177 | goto mem_alloc_fail; |
| 1178 | |
| 1179 | ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_ATOMIC, &ir->dma_in); |
| 1180 | if (!ir->buf_in) |
| 1181 | goto buf_in_alloc_fail; |
| 1182 | |
| 1183 | ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); |
| 1184 | if (!ir->urb_in) |
| 1185 | goto urb_in_alloc_fail; |
| 1186 | |
| 1187 | ir->usbdev = dev; |
| 1188 | ir->dev = &intf->dev; |
| 1189 | ir->len_in = maxp; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1190 | ir->flags.microsoft_gen1 = is_microsoft_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1191 | ir->flags.tx_mask_normal = tx_mask_normal; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1192 | ir->flags.no_tx = mceusb_model[model].no_tx; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1193 | ir->model = model; |
| 1194 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1195 | /* Saving usb interface data for use by the transmitter routine */ |
| 1196 | ir->usb_ep_in = ep_in; |
| 1197 | ir->usb_ep_out = ep_out; |
| 1198 | |
| 1199 | if (dev->descriptor.iManufacturer |
| 1200 | && usb_string(dev, dev->descriptor.iManufacturer, |
| 1201 | buf, sizeof(buf)) > 0) |
| 1202 | strlcpy(name, buf, sizeof(name)); |
| 1203 | if (dev->descriptor.iProduct |
| 1204 | && usb_string(dev, dev->descriptor.iProduct, |
| 1205 | buf, sizeof(buf)) > 0) |
| 1206 | snprintf(name + strlen(name), sizeof(name) - strlen(name), |
| 1207 | " %s", buf); |
| 1208 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1209 | ir->rc = mceusb_init_rc_dev(ir); |
| 1210 | if (!ir->rc) |
| 1211 | goto rc_dev_fail; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1212 | |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 1213 | /* wire up inbound data handler */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1214 | usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in, |
| 1215 | maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval); |
| 1216 | ir->urb_in->transfer_dma = ir->dma_in; |
| 1217 | ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1218 | |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 1219 | /* flush buffers on the device */ |
| 1220 | mce_dbg(&intf->dev, "Flushing receive buffers\n"); |
| 1221 | mce_flush_rx_buffer(ir, maxp); |
| 1222 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1223 | /* initialize device */ |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1224 | if (ir->flags.microsoft_gen1) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1225 | mceusb_gen1_init(ir); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1226 | else if (!is_gen3) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1227 | mceusb_gen2_init(ir); |
| 1228 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1229 | mceusb_get_parameters(ir); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1230 | |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1231 | if (!ir->flags.no_tx) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1232 | mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1233 | |
| 1234 | usb_set_intfdata(intf, ir); |
| 1235 | |
| 1236 | dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name, |
| 1237 | dev->bus->busnum, dev->devnum); |
| 1238 | |
| 1239 | return 0; |
| 1240 | |
| 1241 | /* Error-handling path */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1242 | rc_dev_fail: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1243 | usb_free_urb(ir->urb_in); |
| 1244 | urb_in_alloc_fail: |
| 1245 | usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in); |
| 1246 | buf_in_alloc_fail: |
| 1247 | kfree(ir); |
| 1248 | mem_alloc_fail: |
| 1249 | dev_err(&intf->dev, "%s: device setup failed!\n", __func__); |
| 1250 | |
| 1251 | return -ENOMEM; |
| 1252 | } |
| 1253 | |
| 1254 | |
| 1255 | static void __devexit mceusb_dev_disconnect(struct usb_interface *intf) |
| 1256 | { |
| 1257 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1258 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
| 1259 | |
| 1260 | usb_set_intfdata(intf, NULL); |
| 1261 | |
| 1262 | if (!ir) |
| 1263 | return; |
| 1264 | |
| 1265 | ir->usbdev = NULL; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1266 | rc_unregister_device(ir->rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1267 | usb_kill_urb(ir->urb_in); |
| 1268 | usb_free_urb(ir->urb_in); |
| 1269 | usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in); |
| 1270 | |
| 1271 | kfree(ir); |
| 1272 | } |
| 1273 | |
| 1274 | static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message) |
| 1275 | { |
| 1276 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
| 1277 | dev_info(ir->dev, "suspend\n"); |
| 1278 | usb_kill_urb(ir->urb_in); |
| 1279 | return 0; |
| 1280 | } |
| 1281 | |
| 1282 | static int mceusb_dev_resume(struct usb_interface *intf) |
| 1283 | { |
| 1284 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
| 1285 | dev_info(ir->dev, "resume\n"); |
| 1286 | if (usb_submit_urb(ir->urb_in, GFP_ATOMIC)) |
| 1287 | return -EIO; |
| 1288 | return 0; |
| 1289 | } |
| 1290 | |
| 1291 | static struct usb_driver mceusb_dev_driver = { |
| 1292 | .name = DRIVER_NAME, |
| 1293 | .probe = mceusb_dev_probe, |
| 1294 | .disconnect = mceusb_dev_disconnect, |
| 1295 | .suspend = mceusb_dev_suspend, |
| 1296 | .resume = mceusb_dev_resume, |
| 1297 | .reset_resume = mceusb_dev_resume, |
| 1298 | .id_table = mceusb_dev_table |
| 1299 | }; |
| 1300 | |
| 1301 | static int __init mceusb_dev_init(void) |
| 1302 | { |
| 1303 | int ret; |
| 1304 | |
| 1305 | ret = usb_register(&mceusb_dev_driver); |
| 1306 | if (ret < 0) |
| 1307 | printk(KERN_ERR DRIVER_NAME |
| 1308 | ": usb register failed, result = %d\n", ret); |
| 1309 | |
| 1310 | return ret; |
| 1311 | } |
| 1312 | |
| 1313 | static void __exit mceusb_dev_exit(void) |
| 1314 | { |
| 1315 | usb_deregister(&mceusb_dev_driver); |
| 1316 | } |
| 1317 | |
| 1318 | module_init(mceusb_dev_init); |
| 1319 | module_exit(mceusb_dev_exit); |
| 1320 | |
| 1321 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1322 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1323 | MODULE_LICENSE("GPL"); |
| 1324 | MODULE_DEVICE_TABLE(usb, mceusb_dev_table); |
| 1325 | |
| 1326 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 1327 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |