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