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