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