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