Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 2 | /* |
| 3 | * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers |
| 4 | * |
Jarod Wilson | fda516b | 2011-07-18 16:54:29 -0300 | [diff] [blame] | 5 | * Copyright (c) 2010-2011, Jarod Wilson <jarod@redhat.com> |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 6 | * |
| 7 | * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan |
| 8 | * Conti, Martin Blatter and Daniel Melander, the latter of which was |
| 9 | * in turn also based on the lirc_atiusb driver by Paul Miller. The |
| 10 | * two mce drivers were merged into one by Jarod Wilson, with transmit |
| 11 | * support for the 1st-gen device added primarily by Patrick Calhoun, |
| 12 | * with a bit of tweaks by Jarod. Debugging improvements and proper |
| 13 | * support for what appears to be 3rd-gen hardware added by Jarod. |
| 14 | * Initial port from lirc driver to ir-core drivery by Jarod, based |
| 15 | * partially on a port to an earlier proposed IR infrastructure by |
| 16 | * Jon Smirl, which included enhancements and simplifications to the |
| 17 | * incoming IR buffer parsing routines. |
| 18 | * |
Jarod Wilson | fda516b | 2011-07-18 16:54:29 -0300 | [diff] [blame] | 19 | * Updated in July of 2011 with the aid of Microsoft's official |
| 20 | * remote/transceiver requirements and specification document, found at |
| 21 | * download.microsoft.com, title |
| 22 | * Windows-Media-Center-RC-IR-Collection-Green-Button-Specification-03-08-2011-V2.pdf |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/slab.h> |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 28 | #include <linux/workqueue.h> |
Paul Bender | 635f76b | 2010-12-16 13:23:07 -0300 | [diff] [blame] | 29 | #include <linux/usb.h> |
| 30 | #include <linux/usb/input.h> |
Jarod Wilson | fa334898 | 2011-07-18 16:54:23 -0300 | [diff] [blame] | 31 | #include <linux/pm_wakeup.h> |
Mauro Carvalho Chehab | 6bda964 | 2010-11-17 13:28:38 -0300 | [diff] [blame] | 32 | #include <media/rc-core.h> |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 33 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 34 | #define DRIVER_VERSION "1.95" |
Jarod Wilson | fda516b | 2011-07-18 16:54:29 -0300 | [diff] [blame] | 35 | #define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>" |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 36 | #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \ |
| 37 | "device driver" |
| 38 | #define DRIVER_NAME "mceusb" |
| 39 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 40 | #define USB_TX_TIMEOUT 1000 /* in milliseconds */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 41 | #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */ |
| 42 | #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] | 43 | |
| 44 | /* MCE constants */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 45 | #define MCE_IRBUF_SIZE 128 /* TX IR buffer length */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 46 | #define MCE_TIME_UNIT 50 /* Approx 50us resolution */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 47 | #define MCE_PACKET_SIZE 31 /* Max length of packet (with header) */ |
| 48 | #define MCE_IRDATA_HEADER (0x80 + MCE_PACKET_SIZE - 1) |
| 49 | /* Actual format is 0x80 + num_bytes */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 50 | #define MCE_IRDATA_TRAILER 0x80 /* End of IR data */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 51 | #define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */ |
| 52 | #define MCE_DEFAULT_TX_MASK 0x03 /* Vals: TX1=0x01, TX2=0x02, ALL=0x03 */ |
| 53 | #define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */ |
| 54 | #define MCE_PULSE_MASK 0x7f /* Pulse mask */ |
| 55 | #define MCE_MAX_PULSE_LENGTH 0x7f /* Longest transmittable pulse symbol */ |
| 56 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 57 | /* |
| 58 | * The interface between the host and the IR hardware is command-response |
| 59 | * based. All commands and responses have a consistent format, where a lead |
| 60 | * byte always identifies the type of data following it. The lead byte has |
| 61 | * a port value in the 3 highest bits and a length value in the 5 lowest |
| 62 | * bits. |
| 63 | * |
| 64 | * The length field is overloaded, with a value of 11111 indicating that the |
| 65 | * following byte is a command or response code, and the length of the entire |
| 66 | * message is determined by the code. If the length field is not 11111, then |
| 67 | * it specifies the number of bytes of port data that follow. |
| 68 | */ |
| 69 | #define MCE_CMD 0x1f |
| 70 | #define MCE_PORT_IR 0x4 /* (0x4 << 5) | MCE_CMD = 0x9f */ |
| 71 | #define MCE_PORT_SYS 0x7 /* (0x7 << 5) | MCE_CMD = 0xff */ |
Mauro Carvalho Chehab | 04ad301 | 2019-02-18 14:29:01 -0500 | [diff] [blame] | 72 | #define MCE_PORT_SER 0x6 /* 0xc0 through 0xdf flush & 0x1f bytes */ |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 73 | #define MCE_PORT_MASK 0xe0 /* Mask out command bits */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 74 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 75 | /* Command port headers */ |
| 76 | #define MCE_CMD_PORT_IR 0x9f /* IR-related cmd/rsp */ |
| 77 | #define MCE_CMD_PORT_SYS 0xff /* System (non-IR) device cmd/rsp */ |
| 78 | |
| 79 | /* Commands that set device state (2-4 bytes in length) */ |
| 80 | #define MCE_CMD_RESET 0xfe /* Reset device, 2 bytes */ |
| 81 | #define MCE_CMD_RESUME 0xaa /* Resume device after error, 2 bytes */ |
| 82 | #define MCE_CMD_SETIRCFS 0x06 /* Set tx carrier, 4 bytes */ |
| 83 | #define MCE_CMD_SETIRTIMEOUT 0x0c /* Set timeout, 4 bytes */ |
| 84 | #define MCE_CMD_SETIRTXPORTS 0x08 /* Set tx ports, 3 bytes */ |
| 85 | #define MCE_CMD_SETIRRXPORTEN 0x14 /* Set rx ports, 3 bytes */ |
| 86 | #define MCE_CMD_FLASHLED 0x23 /* Flash receiver LED, 2 bytes */ |
| 87 | |
| 88 | /* Commands that query device state (all 2 bytes, unless noted) */ |
| 89 | #define MCE_CMD_GETIRCFS 0x07 /* Get carrier */ |
| 90 | #define MCE_CMD_GETIRTIMEOUT 0x0d /* Get timeout */ |
| 91 | #define MCE_CMD_GETIRTXPORTS 0x13 /* Get tx ports */ |
| 92 | #define MCE_CMD_GETIRRXPORTEN 0x15 /* Get rx ports */ |
| 93 | #define MCE_CMD_GETPORTSTATUS 0x11 /* Get tx port status, 3 bytes */ |
| 94 | #define MCE_CMD_GETIRNUMPORTS 0x16 /* Get number of ports */ |
| 95 | #define MCE_CMD_GETWAKESOURCE 0x17 /* Get wake source */ |
| 96 | #define MCE_CMD_GETEMVER 0x22 /* Get emulator interface version */ |
| 97 | #define MCE_CMD_GETDEVDETAILS 0x21 /* Get device details (em ver2 only) */ |
| 98 | #define MCE_CMD_GETWAKESUPPORT 0x20 /* Get wake details (em ver2 only) */ |
| 99 | #define MCE_CMD_GETWAKEVERSION 0x18 /* Get wake pattern (em ver2 only) */ |
| 100 | |
| 101 | /* Misc commands */ |
| 102 | #define MCE_CMD_NOP 0xff /* No operation */ |
| 103 | |
| 104 | /* Responses to commands (non-error cases) */ |
| 105 | #define MCE_RSP_EQIRCFS 0x06 /* tx carrier, 4 bytes */ |
| 106 | #define MCE_RSP_EQIRTIMEOUT 0x0c /* rx timeout, 4 bytes */ |
| 107 | #define MCE_RSP_GETWAKESOURCE 0x17 /* wake source, 3 bytes */ |
| 108 | #define MCE_RSP_EQIRTXPORTS 0x08 /* tx port mask, 3 bytes */ |
| 109 | #define MCE_RSP_EQIRRXPORTEN 0x14 /* rx port mask, 3 bytes */ |
| 110 | #define MCE_RSP_GETPORTSTATUS 0x11 /* tx port status, 7 bytes */ |
| 111 | #define MCE_RSP_EQIRRXCFCNT 0x15 /* rx carrier count, 4 bytes */ |
| 112 | #define MCE_RSP_EQIRNUMPORTS 0x16 /* number of ports, 4 bytes */ |
| 113 | #define MCE_RSP_EQWAKESUPPORT 0x20 /* wake capabilities, 3 bytes */ |
| 114 | #define MCE_RSP_EQWAKEVERSION 0x18 /* wake pattern details, 6 bytes */ |
| 115 | #define MCE_RSP_EQDEVDETAILS 0x21 /* device capabilities, 3 bytes */ |
| 116 | #define MCE_RSP_EQEMVER 0x22 /* emulator interface ver, 3 bytes */ |
| 117 | #define MCE_RSP_FLASHLED 0x23 /* success flashing LED, 2 bytes */ |
| 118 | |
| 119 | /* Responses to error cases, must send MCE_CMD_RESUME to clear them */ |
| 120 | #define MCE_RSP_CMD_ILLEGAL 0xfe /* illegal command for port, 2 bytes */ |
| 121 | #define MCE_RSP_TX_TIMEOUT 0x81 /* tx timed out, 2 bytes */ |
| 122 | |
| 123 | /* Misc commands/responses not defined in the MCE remote/transceiver spec */ |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 124 | #define MCE_CMD_SIG_END 0x01 /* End of signal */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 125 | #define MCE_CMD_PING 0x03 /* Ping device */ |
| 126 | #define MCE_CMD_UNKNOWN 0x04 /* Unknown */ |
| 127 | #define MCE_CMD_UNKNOWN2 0x05 /* Unknown */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 128 | #define MCE_CMD_UNKNOWN3 0x09 /* Unknown */ |
| 129 | #define MCE_CMD_UNKNOWN4 0x0a /* Unknown */ |
| 130 | #define MCE_CMD_G_REVISION 0x0b /* Get hw/sw revision */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 131 | #define MCE_CMD_UNKNOWN5 0x0e /* Unknown */ |
| 132 | #define MCE_CMD_UNKNOWN6 0x0f /* Unknown */ |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 133 | #define MCE_CMD_UNKNOWN8 0x19 /* Unknown */ |
| 134 | #define MCE_CMD_UNKNOWN9 0x1b /* Unknown */ |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 135 | #define MCE_CMD_NULL 0x00 /* These show up various places... */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 136 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 137 | /* if buf[i] & MCE_PORT_MASK == 0x80 and buf[i] != MCE_CMD_PORT_IR, |
| 138 | * then we're looking at a raw IR data sample */ |
| 139 | #define MCE_COMMAND_IRDATA 0x80 |
| 140 | #define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 141 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 142 | #define VENDOR_PHILIPS 0x0471 |
| 143 | #define VENDOR_SMK 0x0609 |
| 144 | #define VENDOR_TATUNG 0x1460 |
| 145 | #define VENDOR_GATEWAY 0x107b |
| 146 | #define VENDOR_SHUTTLE 0x1308 |
| 147 | #define VENDOR_SHUTTLE2 0x051c |
| 148 | #define VENDOR_MITSUMI 0x03ee |
| 149 | #define VENDOR_TOPSEED 0x1784 |
| 150 | #define VENDOR_RICAVISION 0x179d |
| 151 | #define VENDOR_ITRON 0x195d |
| 152 | #define VENDOR_FIC 0x1509 |
| 153 | #define VENDOR_LG 0x043e |
| 154 | #define VENDOR_MICROSOFT 0x045e |
| 155 | #define VENDOR_FORMOSA 0x147a |
| 156 | #define VENDOR_FINTEK 0x1934 |
| 157 | #define VENDOR_PINNACLE 0x2304 |
| 158 | #define VENDOR_ECS 0x1019 |
| 159 | #define VENDOR_WISTRON 0x0fb8 |
| 160 | #define VENDOR_COMPRO 0x185b |
| 161 | #define VENDOR_NORTHSTAR 0x04eb |
| 162 | #define VENDOR_REALTEK 0x0bda |
| 163 | #define VENDOR_TIVO 0x105a |
Mauro Carvalho Chehab | 56e92f6 | 2010-10-18 16:32:50 -0300 | [diff] [blame] | 164 | #define VENDOR_CONEXANT 0x0572 |
Mark Lord | a4de5f0 | 2012-07-11 18:53:28 -0300 | [diff] [blame] | 165 | #define VENDOR_TWISTEDMELON 0x2596 |
Matthias Schwarzott | eda9dfd | 2013-11-21 17:26:42 -0300 | [diff] [blame] | 166 | #define VENDOR_HAUPPAUGE 0x2040 |
Mauro Carvalho Chehab | 9683e01 | 2014-07-27 17:06:02 -0300 | [diff] [blame] | 167 | #define VENDOR_PCTV 0x2013 |
Olli Salonen | e186613 | 2016-03-17 10:11:09 -0300 | [diff] [blame] | 168 | #define VENDOR_ADAPTEC 0x03f3 |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 170 | enum mceusb_model_type { |
| 171 | MCE_GEN2 = 0, /* Most boards */ |
| 172 | MCE_GEN1, |
| 173 | MCE_GEN3, |
Sean Young | aec3ead | 2018-05-09 06:11:28 -0400 | [diff] [blame] | 174 | MCE_GEN3_BROKEN_IRTIMEOUT, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 175 | MCE_GEN2_TX_INV, |
Sean Young | 35ecf2b | 2018-03-18 06:46:02 -0400 | [diff] [blame] | 176 | MCE_GEN2_TX_INV_RX_GOOD, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 177 | POLARIS_EVK, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 178 | CX_HYBRID_TV, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 179 | MULTIFUNCTION, |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 180 | TIVO_KIT, |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 181 | MCE_GEN2_NO_TX, |
Matthias Schwarzott | eda9dfd | 2013-11-21 17:26:42 -0300 | [diff] [blame] | 182 | HAUPPAUGE_CX_HYBRID_TV, |
Oleh Kravchenko | 47f42f3 | 2017-10-28 09:38:16 -0400 | [diff] [blame] | 183 | EVROMEDIA_FULL_HYBRID_FULLHD, |
Oleh Kravchenko | 8ff19cd | 2017-10-28 09:38:18 -0400 | [diff] [blame] | 184 | ASTROMETA_T2HYBRID, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 185 | }; |
| 186 | |
| 187 | struct mceusb_model { |
| 188 | u32 mce_gen1:1; |
| 189 | u32 mce_gen2:1; |
| 190 | u32 mce_gen3:1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 191 | u32 tx_mask_normal:1; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 192 | u32 no_tx:1; |
Sean Young | aec3ead | 2018-05-09 06:11:28 -0400 | [diff] [blame] | 193 | u32 broken_irtimeout:1; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 194 | /* |
| 195 | * 2nd IR receiver (short-range, wideband) for learning mode: |
| 196 | * 0, absent 2nd receiver (rx2) |
| 197 | * 1, rx2 present |
| 198 | * 2, rx2 which under counts IR carrier cycles |
| 199 | */ |
| 200 | u32 rx2; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 201 | |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 202 | int ir_intfnum; |
| 203 | |
Mauro Carvalho Chehab | 17c2b1f | 2010-10-22 11:51:50 -0300 | [diff] [blame] | 204 | const char *rc_map; /* Allow specify a per-board map */ |
Mauro Carvalho Chehab | 3459d45 | 2010-10-22 11:52:53 -0300 | [diff] [blame] | 205 | const char *name; /* per-board name */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 206 | }; |
| 207 | |
| 208 | static const struct mceusb_model mceusb_model[] = { |
| 209 | [MCE_GEN1] = { |
| 210 | .mce_gen1 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 211 | .tx_mask_normal = 1, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 212 | .rx2 = 2, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 213 | }, |
| 214 | [MCE_GEN2] = { |
| 215 | .mce_gen2 = 1, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 216 | .rx2 = 2, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 217 | }, |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 218 | [MCE_GEN2_NO_TX] = { |
| 219 | .mce_gen2 = 1, |
| 220 | .no_tx = 1, |
| 221 | }, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 222 | [MCE_GEN2_TX_INV] = { |
| 223 | .mce_gen2 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 224 | .tx_mask_normal = 1, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 225 | .rx2 = 1, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 226 | }, |
Sean Young | 35ecf2b | 2018-03-18 06:46:02 -0400 | [diff] [blame] | 227 | [MCE_GEN2_TX_INV_RX_GOOD] = { |
| 228 | .mce_gen2 = 1, |
| 229 | .tx_mask_normal = 1, |
| 230 | .rx2 = 2, |
| 231 | }, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 232 | [MCE_GEN3] = { |
| 233 | .mce_gen3 = 1, |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 234 | .tx_mask_normal = 1, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 235 | .rx2 = 2, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 236 | }, |
Sean Young | aec3ead | 2018-05-09 06:11:28 -0400 | [diff] [blame] | 237 | [MCE_GEN3_BROKEN_IRTIMEOUT] = { |
| 238 | .mce_gen3 = 1, |
| 239 | .tx_mask_normal = 1, |
| 240 | .rx2 = 2, |
| 241 | .broken_irtimeout = 1 |
| 242 | }, |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 243 | [POLARIS_EVK] = { |
Mauro Carvalho Chehab | 17c2b1f | 2010-10-22 11:51:50 -0300 | [diff] [blame] | 244 | /* |
| 245 | * In fact, the EVK is shipped without |
| 246 | * remotes, but we should have something handy, |
| 247 | * to allow testing it |
| 248 | */ |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 249 | .name = "Conexant Hybrid TV (cx231xx) MCE IR", |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 250 | .rx2 = 2, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 251 | }, |
| 252 | [CX_HYBRID_TV] = { |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 253 | .no_tx = 1, /* tx isn't wired up at all */ |
| 254 | .name = "Conexant Hybrid TV (cx231xx) MCE IR", |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 255 | }, |
Matthias Schwarzott | eda9dfd | 2013-11-21 17:26:42 -0300 | [diff] [blame] | 256 | [HAUPPAUGE_CX_HYBRID_TV] = { |
Matthias Schwarzott | eda9dfd | 2013-11-21 17:26:42 -0300 | [diff] [blame] | 257 | .no_tx = 1, /* eeprom says it has no tx */ |
| 258 | .name = "Conexant Hybrid TV (cx231xx) MCE IR no TX", |
| 259 | }, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 260 | [MULTIFUNCTION] = { |
| 261 | .mce_gen2 = 1, |
| 262 | .ir_intfnum = 2, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 263 | .rx2 = 2, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 264 | }, |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 265 | [TIVO_KIT] = { |
| 266 | .mce_gen2 = 1, |
| 267 | .rc_map = RC_MAP_TIVO, |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 268 | .rx2 = 2, |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 269 | }, |
Oleh Kravchenko | 47f42f3 | 2017-10-28 09:38:16 -0400 | [diff] [blame] | 270 | [EVROMEDIA_FULL_HYBRID_FULLHD] = { |
| 271 | .name = "Evromedia USB Full Hybrid Full HD", |
| 272 | .no_tx = 1, |
| 273 | .rc_map = RC_MAP_MSI_DIGIVOX_III, |
| 274 | }, |
Oleh Kravchenko | 8ff19cd | 2017-10-28 09:38:18 -0400 | [diff] [blame] | 275 | [ASTROMETA_T2HYBRID] = { |
| 276 | .name = "Astrometa T2Hybrid", |
| 277 | .no_tx = 1, |
| 278 | .rc_map = RC_MAP_ASTROMETA_T2HYBRID, |
| 279 | } |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 280 | }; |
| 281 | |
Arvind Yadav | 5fad16b | 2017-08-13 05:54:44 -0300 | [diff] [blame] | 282 | static const struct usb_device_id mceusb_dev_table[] = { |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 283 | /* Original Microsoft MCE IR Transceiver (often HP-branded) */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 284 | { USB_DEVICE(VENDOR_MICROSOFT, 0x006d), |
| 285 | .driver_info = MCE_GEN1 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 286 | /* Philips Infrared Transceiver - Sahara branded */ |
| 287 | { USB_DEVICE(VENDOR_PHILIPS, 0x0608) }, |
| 288 | /* Philips Infrared Transceiver - HP branded */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 289 | { USB_DEVICE(VENDOR_PHILIPS, 0x060c), |
| 290 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 291 | /* Philips SRM5100 */ |
| 292 | { USB_DEVICE(VENDOR_PHILIPS, 0x060d) }, |
| 293 | /* Philips Infrared Transceiver - Omaura */ |
| 294 | { USB_DEVICE(VENDOR_PHILIPS, 0x060f) }, |
| 295 | /* Philips Infrared Transceiver - Spinel plus */ |
| 296 | { USB_DEVICE(VENDOR_PHILIPS, 0x0613) }, |
| 297 | /* Philips eHome Infrared Transceiver */ |
| 298 | { USB_DEVICE(VENDOR_PHILIPS, 0x0815) }, |
Jarod Wilson | c13df9c | 2010-08-27 18:21:14 -0300 | [diff] [blame] | 299 | /* Philips/Spinel plus IR transceiver for ASUS */ |
| 300 | { USB_DEVICE(VENDOR_PHILIPS, 0x206c) }, |
| 301 | /* Philips/Spinel plus IR transceiver for ASUS */ |
| 302 | { USB_DEVICE(VENDOR_PHILIPS, 0x2088) }, |
Jarod Wilson | e296e12 | 2011-04-25 14:48:18 -0300 | [diff] [blame] | 303 | /* Philips IR transceiver (Dell branded) */ |
Sean Young | 8dfef67 | 2013-01-29 08:19:29 -0300 | [diff] [blame] | 304 | { USB_DEVICE(VENDOR_PHILIPS, 0x2093), |
| 305 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 306 | /* Realtek MCE IR Receiver and card reader */ |
| 307 | { USB_DEVICE(VENDOR_REALTEK, 0x0161), |
| 308 | .driver_info = MULTIFUNCTION }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 309 | /* SMK/Toshiba G83C0004D410 */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 310 | { USB_DEVICE(VENDOR_SMK, 0x031d), |
Sean Young | 35ecf2b | 2018-03-18 06:46:02 -0400 | [diff] [blame] | 311 | .driver_info = MCE_GEN2_TX_INV_RX_GOOD }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 312 | /* SMK eHome Infrared Transceiver (Sony VAIO) */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 313 | { USB_DEVICE(VENDOR_SMK, 0x0322), |
| 314 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 315 | /* bundled with Hauppauge PVR-150 */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 316 | { USB_DEVICE(VENDOR_SMK, 0x0334), |
| 317 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 318 | /* SMK eHome Infrared Transceiver */ |
| 319 | { USB_DEVICE(VENDOR_SMK, 0x0338) }, |
Jarod Wilson | b825fe1b | 2011-05-26 16:03:17 -0300 | [diff] [blame] | 320 | /* SMK/I-O Data GV-MC7/RCKIT Receiver */ |
| 321 | { USB_DEVICE(VENDOR_SMK, 0x0353), |
| 322 | .driver_info = MCE_GEN2_NO_TX }, |
Olli Salonen | 1869384 | 2016-03-17 10:11:10 -0300 | [diff] [blame] | 323 | /* SMK RXX6000 Infrared Receiver */ |
| 324 | { USB_DEVICE(VENDOR_SMK, 0x0357), |
| 325 | .driver_info = MCE_GEN2_NO_TX }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 326 | /* Tatung eHome Infrared Transceiver */ |
| 327 | { USB_DEVICE(VENDOR_TATUNG, 0x9150) }, |
| 328 | /* Shuttle eHome Infrared Transceiver */ |
| 329 | { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) }, |
| 330 | /* Shuttle eHome Infrared Transceiver */ |
| 331 | { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) }, |
| 332 | /* Gateway eHome Infrared Transceiver */ |
| 333 | { USB_DEVICE(VENDOR_GATEWAY, 0x3009) }, |
| 334 | /* Mitsumi */ |
| 335 | { USB_DEVICE(VENDOR_MITSUMI, 0x2501) }, |
| 336 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 337 | { USB_DEVICE(VENDOR_TOPSEED, 0x0001), |
| 338 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 339 | /* Topseed HP eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 340 | { USB_DEVICE(VENDOR_TOPSEED, 0x0006), |
| 341 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 342 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 343 | { USB_DEVICE(VENDOR_TOPSEED, 0x0007), |
| 344 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 345 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 346 | { USB_DEVICE(VENDOR_TOPSEED, 0x0008), |
| 347 | .driver_info = MCE_GEN3 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 348 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 349 | { USB_DEVICE(VENDOR_TOPSEED, 0x000a), |
| 350 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 351 | /* Topseed eHome Infrared Transceiver */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 352 | { USB_DEVICE(VENDOR_TOPSEED, 0x0011), |
Sean Young | aec3ead | 2018-05-09 06:11:28 -0400 | [diff] [blame] | 353 | .driver_info = MCE_GEN3_BROKEN_IRTIMEOUT }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 354 | /* Ricavision internal Infrared Transceiver */ |
| 355 | { USB_DEVICE(VENDOR_RICAVISION, 0x0010) }, |
| 356 | /* Itron ione Libra Q-11 */ |
| 357 | { USB_DEVICE(VENDOR_ITRON, 0x7002) }, |
| 358 | /* FIC eHome Infrared Transceiver */ |
| 359 | { USB_DEVICE(VENDOR_FIC, 0x9242) }, |
| 360 | /* LG eHome Infrared Transceiver */ |
| 361 | { USB_DEVICE(VENDOR_LG, 0x9803) }, |
| 362 | /* Microsoft MCE Infrared Transceiver */ |
| 363 | { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) }, |
| 364 | /* Formosa eHome Infrared Transceiver */ |
| 365 | { USB_DEVICE(VENDOR_FORMOSA, 0xe015) }, |
| 366 | /* Formosa21 / eHome Infrared Receiver */ |
| 367 | { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, |
| 368 | /* Formosa aim / Trust MCE Infrared Receiver */ |
Jarod Wilson | 2faa0ca | 2011-04-19 16:47:34 -0300 | [diff] [blame] | 369 | { USB_DEVICE(VENDOR_FORMOSA, 0xe017), |
| 370 | .driver_info = MCE_GEN2_NO_TX }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 371 | /* Formosa Industrial Computing / Beanbag Emulation Device */ |
| 372 | { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, |
| 373 | /* Formosa21 / eHome Infrared Receiver */ |
| 374 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) }, |
| 375 | /* Formosa Industrial Computing AIM IR605/A */ |
| 376 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) }, |
| 377 | /* Formosa Industrial Computing */ |
| 378 | { USB_DEVICE(VENDOR_FORMOSA, 0xe03e) }, |
Jarod Wilson | 22f1732 | 2012-03-12 13:27:03 -0300 | [diff] [blame] | 379 | /* Formosa Industrial Computing */ |
| 380 | { USB_DEVICE(VENDOR_FORMOSA, 0xe042) }, |
Jarod Wilson | fbb1f1b | 2010-12-16 13:27:11 -0300 | [diff] [blame] | 381 | /* Fintek eHome Infrared Transceiver (HP branded) */ |
Sean Young | db8ee10 | 2013-01-29 08:19:30 -0300 | [diff] [blame] | 382 | { USB_DEVICE(VENDOR_FINTEK, 0x5168), |
| 383 | .driver_info = MCE_GEN2_TX_INV }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 384 | /* Fintek eHome Infrared Transceiver */ |
| 385 | { USB_DEVICE(VENDOR_FINTEK, 0x0602) }, |
| 386 | /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */ |
| 387 | { USB_DEVICE(VENDOR_FINTEK, 0x0702) }, |
| 388 | /* Pinnacle Remote Kit */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 389 | { USB_DEVICE(VENDOR_PINNACLE, 0x0225), |
| 390 | .driver_info = MCE_GEN3 }, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 391 | /* Elitegroup Computer Systems IR */ |
| 392 | { USB_DEVICE(VENDOR_ECS, 0x0f38) }, |
| 393 | /* Wistron Corp. eHome Infrared Receiver */ |
| 394 | { USB_DEVICE(VENDOR_WISTRON, 0x0002) }, |
| 395 | /* Compro K100 */ |
| 396 | { USB_DEVICE(VENDOR_COMPRO, 0x3020) }, |
| 397 | /* Compro K100 v2 */ |
| 398 | { USB_DEVICE(VENDOR_COMPRO, 0x3082) }, |
| 399 | /* Northstar Systems, Inc. eHome Infrared Transceiver */ |
| 400 | { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, |
| 401 | /* TiVo PC IR Receiver */ |
Jarod Wilson | d8ee99e | 2011-03-24 12:59:10 -0300 | [diff] [blame] | 402 | { USB_DEVICE(VENDOR_TIVO, 0x2000), |
| 403 | .driver_info = TIVO_KIT }, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 404 | /* Conexant Hybrid TV "Shelby" Polaris SDK */ |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 405 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a1), |
| 406 | .driver_info = POLARIS_EVK }, |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 407 | /* Conexant Hybrid TV RDU253S Polaris */ |
| 408 | { USB_DEVICE(VENDOR_CONEXANT, 0x58a5), |
| 409 | .driver_info = CX_HYBRID_TV }, |
Mark Lord | a4de5f0 | 2012-07-11 18:53:28 -0300 | [diff] [blame] | 410 | /* Twisted Melon Inc. - Manta Mini Receiver */ |
| 411 | { USB_DEVICE(VENDOR_TWISTEDMELON, 0x8008) }, |
| 412 | /* Twisted Melon Inc. - Manta Pico Receiver */ |
| 413 | { USB_DEVICE(VENDOR_TWISTEDMELON, 0x8016) }, |
| 414 | /* Twisted Melon Inc. - Manta Transceiver */ |
| 415 | { USB_DEVICE(VENDOR_TWISTEDMELON, 0x8042) }, |
Matthias Schwarzott | eda9dfd | 2013-11-21 17:26:42 -0300 | [diff] [blame] | 416 | /* Hauppauge WINTV-HVR-HVR 930C-HD - based on cx231xx */ |
| 417 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb130), |
| 418 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
Mauro Carvalho Chehab | 9683e01 | 2014-07-27 17:06:02 -0300 | [diff] [blame] | 419 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb131), |
| 420 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
Matthias Schwarzott | 6675661 | 2014-08-31 08:35:10 -0300 | [diff] [blame] | 421 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb138), |
| 422 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
| 423 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb139), |
| 424 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
Brad Love | fd044de | 2018-10-05 11:19:49 -0400 | [diff] [blame] | 425 | /* Hauppauge WinTV-HVR-935C - based on cx231xx */ |
| 426 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb151), |
| 427 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
| 428 | /* Hauppauge WinTV-HVR-955Q - based on cx231xx */ |
| 429 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb123), |
| 430 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
| 431 | /* Hauppauge WinTV-HVR-975 - based on cx231xx */ |
| 432 | { USB_DEVICE(VENDOR_HAUPPAUGE, 0xb150), |
| 433 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
Mauro Carvalho Chehab | 9683e01 | 2014-07-27 17:06:02 -0300 | [diff] [blame] | 434 | { USB_DEVICE(VENDOR_PCTV, 0x0259), |
| 435 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
| 436 | { USB_DEVICE(VENDOR_PCTV, 0x025e), |
| 437 | .driver_info = HAUPPAUGE_CX_HYBRID_TV }, |
Olli Salonen | e186613 | 2016-03-17 10:11:09 -0300 | [diff] [blame] | 438 | /* Adaptec / HP eHome Receiver */ |
| 439 | { USB_DEVICE(VENDOR_ADAPTEC, 0x0094) }, |
Oleh Kravchenko | 47f42f3 | 2017-10-28 09:38:16 -0400 | [diff] [blame] | 440 | /* Evromedia USB Full Hybrid Full HD */ |
| 441 | { USB_DEVICE(0x1b80, 0xd3b2), |
| 442 | .driver_info = EVROMEDIA_FULL_HYBRID_FULLHD }, |
Oleh Kravchenko | 8ff19cd | 2017-10-28 09:38:18 -0400 | [diff] [blame] | 443 | /* Astrometa T2hybrid */ |
| 444 | { USB_DEVICE(0x15f4, 0x0135), |
| 445 | .driver_info = ASTROMETA_T2HYBRID }, |
Mauro Carvalho Chehab | 9683e01 | 2014-07-27 17:06:02 -0300 | [diff] [blame] | 446 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 447 | /* Terminating entry */ |
| 448 | { } |
| 449 | }; |
| 450 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 451 | /* data structure for each usb transceiver */ |
| 452 | struct mceusb_dev { |
| 453 | /* ir-core bits */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 454 | struct rc_dev *rc; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 455 | |
| 456 | /* optional features we can enable */ |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 457 | bool carrier_report_enabled; |
| 458 | bool wideband_rx_enabled; /* aka learning mode, short-range rx */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 459 | |
| 460 | /* core device bits */ |
| 461 | struct device *dev; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 462 | |
| 463 | /* usb */ |
| 464 | struct usb_device *usbdev; |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 465 | struct usb_interface *usbintf; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 466 | struct urb *urb_in; |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 467 | unsigned int pipe_in; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 468 | struct usb_endpoint_descriptor *usb_ep_out; |
A Sun | c779a9c | 2017-04-13 05:06:47 -0300 | [diff] [blame] | 469 | unsigned int pipe_out; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 470 | |
| 471 | /* buffers and dma */ |
| 472 | unsigned char *buf_in; |
| 473 | unsigned int len_in; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 474 | dma_addr_t dma_in; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 475 | |
| 476 | enum { |
| 477 | CMD_HEADER = 0, |
| 478 | SUBCMD, |
| 479 | CMD_DATA, |
| 480 | PARSE_IRDATA, |
| 481 | } parser_state; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 482 | |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 483 | u8 cmd, rem; /* Remaining IR data bytes in packet */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 484 | |
| 485 | struct { |
| 486 | u32 connected:1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 487 | u32 tx_mask_normal:1; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 488 | u32 microsoft_gen1:1; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 489 | u32 no_tx:1; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 490 | u32 rx2; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 491 | } flags; |
| 492 | |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 493 | /* transmit support */ |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 494 | u32 carrier; |
| 495 | unsigned char tx_mask; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 496 | |
| 497 | char name[128]; |
| 498 | char phys[64]; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 499 | enum mceusb_model_type model; |
Jarod Wilson | 4840b78 | 2011-07-18 16:54:24 -0300 | [diff] [blame] | 500 | |
| 501 | bool need_reset; /* flag to issue a device resume cmd */ |
Jarod Wilson | ab1072e | 2011-07-18 16:54:25 -0300 | [diff] [blame] | 502 | u8 emver; /* emulator interface version */ |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 503 | u8 num_txports; /* number of transmit ports */ |
| 504 | u8 num_rxports; /* number of receive sensors */ |
| 505 | u8 txports_cabled; /* bitmask of transmitters with cable */ |
| 506 | u8 rxports_active; /* bitmask of active receive sensors */ |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 507 | bool learning_active; /* wideband rx is active */ |
| 508 | |
| 509 | /* receiver carrier frequency detection support */ |
| 510 | u32 pulse_tunit; /* IR pulse "on" cumulative time units */ |
| 511 | u32 pulse_count; /* pulse "on" count in measurement interval */ |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 512 | |
| 513 | /* |
| 514 | * support for async error handler mceusb_deferred_kevent() |
| 515 | * where usb_clear_halt(), usb_reset_configuration(), |
| 516 | * usb_reset_device(), etc. must be done in process context |
| 517 | */ |
| 518 | struct work_struct kevent; |
| 519 | unsigned long kevent_flags; |
| 520 | # define EVENT_TX_HALT 0 |
| 521 | # define EVENT_RX_HALT 1 |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 522 | # define EVENT_RST_PEND 31 |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 523 | }; |
| 524 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 525 | /* MCE Device Command Strings, generally a port and command pair */ |
| 526 | static char DEVICE_RESUME[] = {MCE_CMD_NULL, MCE_CMD_PORT_SYS, |
| 527 | MCE_CMD_RESUME}; |
| 528 | static char GET_REVISION[] = {MCE_CMD_PORT_SYS, MCE_CMD_G_REVISION}; |
Jarod Wilson | ab1072e | 2011-07-18 16:54:25 -0300 | [diff] [blame] | 529 | static char GET_EMVER[] = {MCE_CMD_PORT_SYS, MCE_CMD_GETEMVER}; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 530 | static char GET_WAKEVERSION[] = {MCE_CMD_PORT_SYS, MCE_CMD_GETWAKEVERSION}; |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 531 | static char FLASH_LED[] = {MCE_CMD_PORT_SYS, MCE_CMD_FLASHLED}; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 532 | static char GET_UNKNOWN2[] = {MCE_CMD_PORT_IR, MCE_CMD_UNKNOWN2}; |
| 533 | static char GET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRCFS}; |
| 534 | static char GET_RX_TIMEOUT[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTIMEOUT}; |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 535 | static char GET_NUM_PORTS[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRNUMPORTS}; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 536 | static char GET_TX_BITMASK[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTXPORTS}; |
| 537 | static char GET_RX_SENSOR[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRRXPORTEN}; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 538 | /* sub in desired values in lower byte or bytes for full command */ |
| 539 | /* FIXME: make use of these for transmit. |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 540 | static char SET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR, |
| 541 | MCE_CMD_SETIRCFS, 0x00, 0x00}; |
| 542 | static char SET_TX_BITMASK[] = {MCE_CMD_PORT_IR, MCE_CMD_SETIRTXPORTS, 0x00}; |
| 543 | static char SET_RX_TIMEOUT[] = {MCE_CMD_PORT_IR, |
| 544 | MCE_CMD_SETIRTIMEOUT, 0x00, 0x00}; |
| 545 | static char SET_RX_SENSOR[] = {MCE_CMD_PORT_IR, |
| 546 | MCE_RSP_EQIRRXPORTEN, 0x00}; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 547 | */ |
| 548 | |
William Steidtmann | 76dea4c | 2013-04-15 17:17:11 -0300 | [diff] [blame] | 549 | static int mceusb_cmd_datasize(u8 cmd, u8 subcmd) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 550 | { |
| 551 | int datasize = 0; |
| 552 | |
| 553 | switch (cmd) { |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 554 | case MCE_CMD_NULL: |
| 555 | if (subcmd == MCE_CMD_PORT_SYS) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 556 | datasize = 1; |
| 557 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 558 | case MCE_CMD_PORT_SYS: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 559 | switch (subcmd) { |
William Steidtmann | 76dea4c | 2013-04-15 17:17:11 -0300 | [diff] [blame] | 560 | case MCE_RSP_GETPORTSTATUS: |
| 561 | datasize = 5; |
| 562 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 563 | case MCE_RSP_EQWAKEVERSION: |
| 564 | datasize = 4; |
| 565 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 566 | case MCE_CMD_G_REVISION: |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 567 | datasize = 4; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 568 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 569 | case MCE_RSP_EQWAKESUPPORT: |
William Steidtmann | 76dea4c | 2013-04-15 17:17:11 -0300 | [diff] [blame] | 570 | case MCE_RSP_GETWAKESOURCE: |
| 571 | case MCE_RSP_EQDEVDETAILS: |
| 572 | case MCE_RSP_EQEMVER: |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 573 | datasize = 1; |
| 574 | break; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 575 | } |
Sean Young | e708e5a | 2018-05-10 07:49:49 -0400 | [diff] [blame] | 576 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 577 | case MCE_CMD_PORT_IR: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 578 | switch (subcmd) { |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 579 | case MCE_CMD_UNKNOWN: |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 580 | case MCE_RSP_EQIRCFS: |
| 581 | case MCE_RSP_EQIRTIMEOUT: |
| 582 | case MCE_RSP_EQIRRXCFCNT: |
William Steidtmann | 76dea4c | 2013-04-15 17:17:11 -0300 | [diff] [blame] | 583 | case MCE_RSP_EQIRNUMPORTS: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 584 | datasize = 2; |
| 585 | break; |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 586 | case MCE_CMD_SIG_END: |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 587 | case MCE_RSP_EQIRTXPORTS: |
| 588 | case MCE_RSP_EQIRRXPORTEN: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 589 | datasize = 1; |
| 590 | break; |
| 591 | } |
| 592 | } |
| 593 | return datasize; |
| 594 | } |
| 595 | |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 596 | static void mceusb_dev_printdata(struct mceusb_dev *ir, u8 *buf, int buf_len, |
| 597 | int offset, int len, bool out) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 598 | { |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 599 | #if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG) |
| 600 | char *inout; |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 601 | u8 cmd, subcmd, *data; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 602 | struct device *dev = ir->dev; |
Jarod Wilson | e217fb4 | 2011-07-18 16:54:28 -0300 | [diff] [blame] | 603 | u32 carrier, period; |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 604 | |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 605 | if (offset < 0 || offset >= buf_len) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 606 | return; |
| 607 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 608 | dev_dbg(dev, "%cx data[%d]: %*ph (len=%d sz=%d)", |
| 609 | (out ? 't' : 'r'), offset, |
| 610 | min(len, buf_len - offset), buf + offset, len, buf_len); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 611 | |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 612 | inout = out ? "Request" : "Got"; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 613 | |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 614 | cmd = buf[offset]; |
| 615 | subcmd = (offset + 1 < buf_len) ? buf[offset + 1] : 0; |
| 616 | data = &buf[offset] + 2; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 617 | |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 618 | /* Trace meaningless 0xb1 0x60 header bytes on original receiver */ |
| 619 | if (ir->flags.microsoft_gen1 && !out && !offset) { |
| 620 | dev_dbg(dev, "MCE gen 1 header"); |
| 621 | return; |
| 622 | } |
| 623 | |
| 624 | /* Trace IR data header or trailer */ |
| 625 | if (cmd != MCE_CMD_PORT_IR && |
| 626 | (cmd & MCE_PORT_MASK) == MCE_COMMAND_IRDATA) { |
| 627 | if (cmd == MCE_IRDATA_TRAILER) |
| 628 | dev_dbg(dev, "End of raw IR data"); |
| 629 | else |
| 630 | dev_dbg(dev, "Raw IR data, %d pulse/space samples", |
| 631 | cmd & MCE_PACKET_LENGTH_MASK); |
| 632 | return; |
| 633 | } |
| 634 | |
| 635 | /* Unexpected end of buffer? */ |
| 636 | if (offset + len > buf_len) |
| 637 | return; |
| 638 | |
| 639 | /* Decode MCE command/response */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 640 | switch (cmd) { |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 641 | case MCE_CMD_NULL: |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 642 | if (subcmd == MCE_CMD_NULL) |
| 643 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 644 | if ((subcmd == MCE_CMD_PORT_SYS) && |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 645 | (data[0] == MCE_CMD_RESUME)) |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 646 | dev_dbg(dev, "Device resume requested"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 647 | else |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 648 | dev_dbg(dev, "Unknown command 0x%02x 0x%02x", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 649 | cmd, subcmd); |
| 650 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 651 | case MCE_CMD_PORT_SYS: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 652 | switch (subcmd) { |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 653 | case MCE_RSP_EQEMVER: |
| 654 | if (!out) |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 655 | dev_dbg(dev, "Emulator interface version %x", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 656 | data[0]); |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 657 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 658 | case MCE_CMD_G_REVISION: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 659 | if (len == 2) |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 660 | dev_dbg(dev, "Get hw/sw rev?"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 661 | else |
Mauro Carvalho Chehab | eef8fc3 | 2016-03-06 10:00:09 -0300 | [diff] [blame] | 662 | dev_dbg(dev, "hw/sw rev %*ph", |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 663 | 4, &buf[offset + 2]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 664 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 665 | case MCE_CMD_RESUME: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 666 | dev_dbg(dev, "Device resume requested"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 667 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 668 | case MCE_RSP_CMD_ILLEGAL: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 669 | dev_dbg(dev, "Illegal PORT_SYS command"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 670 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 671 | case MCE_RSP_EQWAKEVERSION: |
| 672 | if (!out) |
Mauro Carvalho Chehab | 25ec587 | 2016-10-18 17:44:25 -0200 | [diff] [blame] | 673 | dev_dbg(dev, "Wake version, proto: 0x%02x, payload: 0x%02x, address: 0x%02x, version: 0x%02x", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 674 | data[0], data[1], data[2], data[3]); |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 675 | break; |
| 676 | case MCE_RSP_GETPORTSTATUS: |
| 677 | if (!out) |
| 678 | /* We use data1 + 1 here, to match hw labels */ |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 679 | dev_dbg(dev, "TX port %d: blaster is%s connected", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 680 | data[0] + 1, data[3] ? " not" : ""); |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 681 | break; |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 682 | case MCE_CMD_FLASHLED: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 683 | dev_dbg(dev, "Attempting to flash LED"); |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 684 | break; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 685 | default: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 686 | dev_dbg(dev, "Unknown command 0x%02x 0x%02x", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 687 | cmd, subcmd); |
| 688 | break; |
| 689 | } |
| 690 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 691 | case MCE_CMD_PORT_IR: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 692 | switch (subcmd) { |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 693 | case MCE_CMD_SIG_END: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 694 | dev_dbg(dev, "End of signal"); |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 695 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 696 | case MCE_CMD_PING: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 697 | dev_dbg(dev, "Ping"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 698 | break; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 699 | case MCE_CMD_UNKNOWN: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 700 | dev_dbg(dev, "Resp to 9f 05 of 0x%02x 0x%02x", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 701 | data[0], data[1]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 702 | break; |
Jarod Wilson | e217fb4 | 2011-07-18 16:54:28 -0300 | [diff] [blame] | 703 | case MCE_RSP_EQIRCFS: |
Sean Young | 9dec0f4 | 2021-01-19 14:53:50 +0100 | [diff] [blame] | 704 | if (!data[0] && !data[1]) { |
| 705 | dev_dbg(dev, "%s: no carrier", inout); |
| 706 | break; |
| 707 | } |
| 708 | // prescaler should make sense |
| 709 | if (data[0] > 8) |
| 710 | break; |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 711 | period = DIV_ROUND_CLOSEST((1U << data[0] * 2) * |
| 712 | (data[1] + 1), 10); |
Jarod Wilson | e217fb4 | 2011-07-18 16:54:28 -0300 | [diff] [blame] | 713 | if (!period) |
| 714 | break; |
Sean Young | 9dec0f4 | 2021-01-19 14:53:50 +0100 | [diff] [blame] | 715 | carrier = USEC_PER_SEC / period; |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 716 | dev_dbg(dev, "%s carrier of %u Hz (period %uus)", |
Jarod Wilson | e217fb4 | 2011-07-18 16:54:28 -0300 | [diff] [blame] | 717 | inout, carrier, period); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 718 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 719 | case MCE_CMD_GETIRCFS: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 720 | dev_dbg(dev, "Get carrier mode and freq"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 721 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 722 | case MCE_RSP_EQIRTXPORTS: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 723 | dev_dbg(dev, "%s transmit blaster mask of 0x%02x", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 724 | inout, data[0]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 725 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 726 | case MCE_RSP_EQIRTIMEOUT: |
Rafi Rubin | f3e456c | 2011-07-03 17:13:52 -0300 | [diff] [blame] | 727 | /* value is in units of 50us, so x*50/1000 ms */ |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 728 | period = ((data[0] << 8) | data[1]) * |
| 729 | MCE_TIME_UNIT / 1000; |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 730 | dev_dbg(dev, "%s receive timeout of %d ms", |
Jarod Wilson | e217fb4 | 2011-07-18 16:54:28 -0300 | [diff] [blame] | 731 | inout, period); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 732 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 733 | case MCE_CMD_GETIRTIMEOUT: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 734 | dev_dbg(dev, "Get receive timeout"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 735 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 736 | case MCE_CMD_GETIRTXPORTS: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 737 | dev_dbg(dev, "Get transmit blaster mask"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 738 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 739 | case MCE_RSP_EQIRRXPORTEN: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 740 | dev_dbg(dev, "%s %s-range receive sensor in use", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 741 | inout, data[0] == 0x02 ? "short" : "long"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 742 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 743 | case MCE_CMD_GETIRRXPORTEN: |
| 744 | /* aka MCE_RSP_EQIRRXCFCNT */ |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 745 | if (out) |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 746 | dev_dbg(dev, "Get receive sensor"); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 747 | else |
| 748 | dev_dbg(dev, "RX carrier cycle count: %d", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 749 | ((data[0] << 8) | data[1])); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 750 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 751 | case MCE_RSP_EQIRNUMPORTS: |
| 752 | if (out) |
| 753 | break; |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 754 | dev_dbg(dev, "Num TX ports: %x, num RX ports: %x", |
Sean Young | ff05cf0 | 2017-08-04 05:30:20 -0400 | [diff] [blame] | 755 | data[0], data[1]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 756 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 757 | case MCE_RSP_CMD_ILLEGAL: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 758 | dev_dbg(dev, "Illegal PORT_IR command"); |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 759 | break; |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 760 | case MCE_RSP_TX_TIMEOUT: |
| 761 | dev_dbg(dev, "IR TX timeout (TX buffer underrun)"); |
| 762 | break; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 763 | default: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 764 | dev_dbg(dev, "Unknown command 0x%02x 0x%02x", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 765 | cmd, subcmd); |
| 766 | break; |
| 767 | } |
| 768 | break; |
| 769 | default: |
| 770 | break; |
| 771 | } |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 772 | #endif |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 773 | } |
| 774 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 775 | /* |
| 776 | * Schedule work that can't be done in interrupt handlers |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 777 | * (mceusb_dev_recv() and mce_write_callback()) nor tasklets. |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 778 | * Invokes mceusb_deferred_kevent() for recovering from |
| 779 | * error events specified by the kevent bit field. |
| 780 | */ |
| 781 | static void mceusb_defer_kevent(struct mceusb_dev *ir, int kevent) |
| 782 | { |
| 783 | set_bit(kevent, &ir->kevent_flags); |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 784 | |
| 785 | if (test_bit(EVENT_RST_PEND, &ir->kevent_flags)) { |
| 786 | dev_dbg(ir->dev, "kevent %d dropped pending USB Reset Device", |
| 787 | kevent); |
| 788 | return; |
| 789 | } |
| 790 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 791 | if (!schedule_work(&ir->kevent)) |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 792 | dev_dbg(ir->dev, "kevent %d already scheduled", kevent); |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 793 | else |
| 794 | dev_dbg(ir->dev, "kevent %d scheduled", kevent); |
| 795 | } |
| 796 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 797 | static void mce_write_callback(struct urb *urb) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 798 | { |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 799 | if (!urb) |
| 800 | return; |
| 801 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 802 | complete(urb->context); |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * Write (TX/send) data to MCE device USB endpoint out. |
| 807 | * Used for IR blaster TX and MCE device commands. |
| 808 | * |
| 809 | * Return: The number of bytes written (> 0) or errno (< 0). |
| 810 | */ |
| 811 | static int mce_write(struct mceusb_dev *ir, u8 *data, int size) |
| 812 | { |
| 813 | int ret; |
| 814 | struct urb *urb; |
| 815 | struct device *dev = ir->dev; |
| 816 | unsigned char *buf_out; |
| 817 | struct completion tx_done; |
| 818 | unsigned long expire; |
| 819 | unsigned long ret_wait; |
| 820 | |
| 821 | mceusb_dev_printdata(ir, data, size, 0, size, true); |
| 822 | |
| 823 | urb = usb_alloc_urb(0, GFP_KERNEL); |
| 824 | if (unlikely(!urb)) { |
| 825 | dev_err(dev, "Error: mce write couldn't allocate urb"); |
| 826 | return -ENOMEM; |
| 827 | } |
| 828 | |
| 829 | buf_out = kmalloc(size, GFP_KERNEL); |
| 830 | if (!buf_out) { |
| 831 | usb_free_urb(urb); |
| 832 | return -ENOMEM; |
| 833 | } |
| 834 | |
| 835 | init_completion(&tx_done); |
| 836 | |
| 837 | /* outbound data */ |
| 838 | if (usb_endpoint_xfer_int(ir->usb_ep_out)) |
| 839 | usb_fill_int_urb(urb, ir->usbdev, ir->pipe_out, |
| 840 | buf_out, size, mce_write_callback, &tx_done, |
| 841 | ir->usb_ep_out->bInterval); |
| 842 | else |
| 843 | usb_fill_bulk_urb(urb, ir->usbdev, ir->pipe_out, |
| 844 | buf_out, size, mce_write_callback, &tx_done); |
| 845 | memcpy(buf_out, data, size); |
| 846 | |
| 847 | ret = usb_submit_urb(urb, GFP_KERNEL); |
| 848 | if (ret) { |
| 849 | dev_err(dev, "Error: mce write submit urb error = %d", ret); |
| 850 | kfree(buf_out); |
| 851 | usb_free_urb(urb); |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | expire = msecs_to_jiffies(USB_TX_TIMEOUT); |
| 856 | ret_wait = wait_for_completion_timeout(&tx_done, expire); |
| 857 | if (!ret_wait) { |
| 858 | dev_err(dev, "Error: mce write timed out (expire = %lu (%dms))", |
| 859 | expire, USB_TX_TIMEOUT); |
| 860 | usb_kill_urb(urb); |
| 861 | ret = (urb->status == -ENOENT ? -ETIMEDOUT : urb->status); |
| 862 | } else { |
| 863 | ret = urb->status; |
| 864 | } |
| 865 | if (ret >= 0) |
| 866 | ret = urb->actual_length; /* bytes written */ |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 867 | |
| 868 | switch (urb->status) { |
| 869 | /* success */ |
| 870 | case 0: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 871 | break; |
| 872 | |
| 873 | case -ECONNRESET: |
| 874 | case -ENOENT: |
| 875 | case -EILSEQ: |
| 876 | case -ESHUTDOWN: |
| 877 | break; |
| 878 | |
| 879 | case -EPIPE: |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 880 | dev_err(ir->dev, "Error: mce write urb status = %d (TX HALT)", |
A Sun | c779a9c | 2017-04-13 05:06:47 -0300 | [diff] [blame] | 881 | urb->status); |
| 882 | mceusb_defer_kevent(ir, EVENT_TX_HALT); |
| 883 | break; |
| 884 | |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 885 | default: |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 886 | dev_err(ir->dev, "Error: mce write urb status = %d", |
| 887 | urb->status); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 888 | break; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 889 | } |
| 890 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 891 | dev_dbg(dev, "tx done status = %d (wait = %lu, expire = %lu (%dms), urb->actual_length = %d, urb->status = %d)", |
| 892 | ret, ret_wait, expire, USB_TX_TIMEOUT, |
| 893 | urb->actual_length, urb->status); |
| 894 | |
| 895 | kfree(buf_out); |
Jarod Wilson | 0b43fcd | 2011-05-24 16:44:54 -0300 | [diff] [blame] | 896 | usb_free_urb(urb); |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 897 | |
| 898 | return ret; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 899 | } |
| 900 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 901 | static void mce_command_out(struct mceusb_dev *ir, u8 *data, int size) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 902 | { |
Jarod Wilson | 4840b78 | 2011-07-18 16:54:24 -0300 | [diff] [blame] | 903 | int rsize = sizeof(DEVICE_RESUME); |
| 904 | |
| 905 | if (ir->need_reset) { |
| 906 | ir->need_reset = false; |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 907 | mce_write(ir, DEVICE_RESUME, rsize); |
Jarod Wilson | 4840b78 | 2011-07-18 16:54:24 -0300 | [diff] [blame] | 908 | msleep(10); |
| 909 | } |
| 910 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 911 | mce_write(ir, data, size); |
Jarod Wilson | 417c0a2 | 2011-07-18 16:54:22 -0300 | [diff] [blame] | 912 | msleep(10); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 913 | } |
| 914 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 915 | /* |
| 916 | * Transmit IR out the MCE device IR blaster port(s). |
| 917 | * |
| 918 | * Convert IR pulse/space sequence from LIRC to MCE format. |
| 919 | * Break up a long IR sequence into multiple parts (MCE IR data packets). |
| 920 | * |
| 921 | * u32 txbuf[] consists of IR pulse, space, ..., and pulse times in usec. |
| 922 | * Pulses and spaces are implicit by their position. |
| 923 | * The first IR sample, txbuf[0], is always a pulse. |
| 924 | * |
| 925 | * u8 irbuf[] consists of multiple IR data packets for the MCE device. |
| 926 | * A packet is 1 u8 MCE_IRDATA_HEADER and up to 30 u8 IR samples. |
| 927 | * An IR sample is 1-bit pulse/space flag with 7-bit time |
| 928 | * in MCE time units (50usec). |
| 929 | * |
| 930 | * Return: The number of IR samples sent (> 0) or errno (< 0). |
| 931 | */ |
David Härdeman | 5588dc2 | 2011-04-28 12:13:58 -0300 | [diff] [blame] | 932 | static int mceusb_tx_ir(struct rc_dev *dev, unsigned *txbuf, unsigned count) |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 933 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 934 | struct mceusb_dev *ir = dev->priv; |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 935 | u8 cmdbuf[3] = { MCE_CMD_PORT_IR, MCE_CMD_SETIRTXPORTS, 0x00 }; |
| 936 | u8 irbuf[MCE_IRBUF_SIZE]; |
| 937 | int ircount = 0; |
| 938 | unsigned int irsample; |
| 939 | int i, length, ret; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 940 | |
Sean Young | db8ee10 | 2013-01-29 08:19:30 -0300 | [diff] [blame] | 941 | /* Send the set TX ports command */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 942 | cmdbuf[2] = ir->tx_mask; |
| 943 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
Sean Young | db8ee10 | 2013-01-29 08:19:30 -0300 | [diff] [blame] | 944 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 945 | /* Generate mce IR data packet */ |
| 946 | for (i = 0; i < count; i++) { |
| 947 | irsample = txbuf[i] / MCE_TIME_UNIT; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 948 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 949 | /* loop to support long pulses/spaces > 6350us (127*50us) */ |
| 950 | while (irsample > 0) { |
| 951 | /* Insert IR header every 30th entry */ |
| 952 | if (ircount % MCE_PACKET_SIZE == 0) { |
| 953 | /* Room for IR header and one IR sample? */ |
| 954 | if (ircount >= MCE_IRBUF_SIZE - 1) { |
| 955 | /* Send near full buffer */ |
| 956 | ret = mce_write(ir, irbuf, ircount); |
| 957 | if (ret < 0) |
| 958 | return ret; |
| 959 | ircount = 0; |
| 960 | } |
| 961 | irbuf[ircount++] = MCE_IRDATA_HEADER; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 962 | } |
| 963 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 964 | /* Insert IR sample */ |
| 965 | if (irsample <= MCE_MAX_PULSE_LENGTH) { |
| 966 | irbuf[ircount] = irsample; |
| 967 | irsample = 0; |
| 968 | } else { |
| 969 | irbuf[ircount] = MCE_MAX_PULSE_LENGTH; |
| 970 | irsample -= MCE_MAX_PULSE_LENGTH; |
| 971 | } |
| 972 | /* |
| 973 | * Even i = IR pulse |
| 974 | * Odd i = IR space |
| 975 | */ |
| 976 | irbuf[ircount] |= (i & 1 ? 0 : MCE_PULSE_BIT); |
| 977 | ircount++; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 978 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 979 | /* IR buffer full? */ |
| 980 | if (ircount >= MCE_IRBUF_SIZE) { |
| 981 | /* Fix packet length in last header */ |
| 982 | length = ircount % MCE_PACKET_SIZE; |
| 983 | if (length > 0) |
| 984 | irbuf[ircount - length] -= |
| 985 | MCE_PACKET_SIZE - length; |
| 986 | /* Send full buffer */ |
| 987 | ret = mce_write(ir, irbuf, ircount); |
| 988 | if (ret < 0) |
| 989 | return ret; |
| 990 | ircount = 0; |
| 991 | } |
| 992 | } |
| 993 | } /* after for loop, 0 <= ircount < MCE_IRBUF_SIZE */ |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 994 | |
Dan Carpenter | b940a22 | 2013-02-12 08:22:08 -0300 | [diff] [blame] | 995 | /* Fix packet length in last header */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 996 | length = ircount % MCE_PACKET_SIZE; |
| 997 | if (length > 0) |
| 998 | irbuf[ircount - length] -= MCE_PACKET_SIZE - length; |
Dan Carpenter | b940a22 | 2013-02-12 08:22:08 -0300 | [diff] [blame] | 999 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1000 | /* Append IR trailer (0x80) to final partial (or empty) IR buffer */ |
| 1001 | irbuf[ircount++] = MCE_IRDATA_TRAILER; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1002 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1003 | /* Send final buffer */ |
| 1004 | ret = mce_write(ir, irbuf, ircount); |
| 1005 | if (ret < 0) |
| 1006 | return ret; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1007 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1008 | return count; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1009 | } |
| 1010 | |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1011 | /* Sets active IR outputs -- mce devices typically have two */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1012 | static int mceusb_set_tx_mask(struct rc_dev *dev, u32 mask) |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1013 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1014 | struct mceusb_dev *ir = dev->priv; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1015 | |
Sean Young | 20f5a82 | 2016-07-10 13:34:32 -0300 | [diff] [blame] | 1016 | /* return number of transmitters */ |
| 1017 | int emitters = ir->num_txports ? ir->num_txports : 2; |
| 1018 | |
| 1019 | if (mask >= (1 << emitters)) |
| 1020 | return emitters; |
| 1021 | |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1022 | if (ir->flags.tx_mask_normal) |
| 1023 | ir->tx_mask = mask; |
| 1024 | else |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 1025 | ir->tx_mask = (mask != MCE_DEFAULT_TX_MASK ? |
| 1026 | mask ^ MCE_DEFAULT_TX_MASK : mask) << 1; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1027 | |
| 1028 | return 0; |
| 1029 | } |
| 1030 | |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1031 | /* Sets the send carrier frequency and mode */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1032 | static int mceusb_set_tx_carrier(struct rc_dev *dev, u32 carrier) |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1033 | { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1034 | struct mceusb_dev *ir = dev->priv; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1035 | int clk = 10000000; |
| 1036 | int prescaler = 0, divisor = 0; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1037 | unsigned char cmdbuf[4] = { MCE_CMD_PORT_IR, |
| 1038 | MCE_CMD_SETIRCFS, 0x00, 0x00 }; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1039 | |
| 1040 | /* Carrier has changed */ |
| 1041 | if (ir->carrier != carrier) { |
| 1042 | |
| 1043 | if (carrier == 0) { |
| 1044 | ir->carrier = carrier; |
Jarod Wilson | 1cd50f2 | 2010-11-09 18:41:03 -0300 | [diff] [blame] | 1045 | cmdbuf[2] = MCE_CMD_SIG_END; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 1046 | cmdbuf[3] = MCE_IRDATA_TRAILER; |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1047 | dev_dbg(ir->dev, "disabling carrier modulation"); |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1048 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
Sean Young | 3cf8d8e | 2016-12-02 15:16:07 -0200 | [diff] [blame] | 1049 | return 0; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | for (prescaler = 0; prescaler < 4; ++prescaler) { |
| 1053 | divisor = (clk >> (2 * prescaler)) / carrier; |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 1054 | if (divisor <= 0xff) { |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1055 | ir->carrier = carrier; |
| 1056 | cmdbuf[2] = prescaler; |
| 1057 | cmdbuf[3] = divisor; |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1058 | dev_dbg(ir->dev, "requesting %u HZ carrier", |
| 1059 | carrier); |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1060 | |
| 1061 | /* Transmit new carrier to mce device */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1062 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
Sean Young | 3cf8d8e | 2016-12-02 15:16:07 -0200 | [diff] [blame] | 1063 | return 0; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | return -EINVAL; |
| 1068 | |
| 1069 | } |
| 1070 | |
Sean Young | 14d8188 | 2016-07-10 13:34:33 -0300 | [diff] [blame] | 1071 | return 0; |
Jarod Wilson | e23fb96 | 2010-06-16 17:55:52 -0300 | [diff] [blame] | 1072 | } |
| 1073 | |
Sean Young | 877f1a7 | 2018-04-08 11:06:49 -0400 | [diff] [blame] | 1074 | static int mceusb_set_timeout(struct rc_dev *dev, unsigned int timeout) |
| 1075 | { |
| 1076 | u8 cmdbuf[4] = { MCE_CMD_PORT_IR, MCE_CMD_SETIRTIMEOUT, 0, 0 }; |
| 1077 | struct mceusb_dev *ir = dev->priv; |
| 1078 | unsigned int units; |
| 1079 | |
Sean Young | 528222d8 | 2020-08-23 19:23:05 +0200 | [diff] [blame] | 1080 | units = DIV_ROUND_CLOSEST(timeout, MCE_TIME_UNIT); |
Sean Young | 877f1a7 | 2018-04-08 11:06:49 -0400 | [diff] [blame] | 1081 | |
| 1082 | cmdbuf[2] = units >> 8; |
| 1083 | cmdbuf[3] = units; |
| 1084 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1085 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
Sean Young | 877f1a7 | 2018-04-08 11:06:49 -0400 | [diff] [blame] | 1086 | |
| 1087 | /* get receiver timeout value */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1088 | mce_command_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); |
Sean Young | 877f1a7 | 2018-04-08 11:06:49 -0400 | [diff] [blame] | 1089 | |
| 1090 | return 0; |
| 1091 | } |
| 1092 | |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1093 | /* |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1094 | * Select or deselect the 2nd receiver port. |
| 1095 | * Second receiver is learning mode, wide-band, short-range receiver. |
| 1096 | * Only one receiver (long or short range) may be active at a time. |
| 1097 | */ |
| 1098 | static int mceusb_set_rx_wideband(struct rc_dev *dev, int enable) |
| 1099 | { |
| 1100 | struct mceusb_dev *ir = dev->priv; |
| 1101 | unsigned char cmdbuf[3] = { MCE_CMD_PORT_IR, |
| 1102 | MCE_CMD_SETIRRXPORTEN, 0x00 }; |
| 1103 | |
| 1104 | dev_dbg(ir->dev, "select %s-range receive sensor", |
| 1105 | enable ? "short" : "long"); |
| 1106 | if (enable) { |
| 1107 | ir->wideband_rx_enabled = true; |
| 1108 | cmdbuf[2] = 2; /* port 2 is short range receiver */ |
| 1109 | } else { |
| 1110 | ir->wideband_rx_enabled = false; |
| 1111 | cmdbuf[2] = 1; /* port 1 is long range receiver */ |
| 1112 | } |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1113 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1114 | /* response from device sets ir->learning_active */ |
| 1115 | |
| 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | /* |
| 1120 | * Enable/disable receiver carrier frequency pass through reporting. |
| 1121 | * Only the short-range receiver has carrier frequency measuring capability. |
| 1122 | * Implicitly select this receiver when enabling carrier frequency reporting. |
| 1123 | */ |
| 1124 | static int mceusb_set_rx_carrier_report(struct rc_dev *dev, int enable) |
| 1125 | { |
| 1126 | struct mceusb_dev *ir = dev->priv; |
| 1127 | unsigned char cmdbuf[3] = { MCE_CMD_PORT_IR, |
| 1128 | MCE_CMD_SETIRRXPORTEN, 0x00 }; |
| 1129 | |
| 1130 | dev_dbg(ir->dev, "%s short-range receiver carrier reporting", |
| 1131 | enable ? "enable" : "disable"); |
| 1132 | if (enable) { |
| 1133 | ir->carrier_report_enabled = true; |
| 1134 | if (!ir->learning_active) { |
| 1135 | cmdbuf[2] = 2; /* port 2 is short range receiver */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1136 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1137 | } |
| 1138 | } else { |
| 1139 | ir->carrier_report_enabled = false; |
| 1140 | /* |
| 1141 | * Revert to normal (long-range) receiver only if the |
| 1142 | * wideband (short-range) receiver wasn't explicitly |
| 1143 | * enabled. |
| 1144 | */ |
| 1145 | if (ir->learning_active && !ir->wideband_rx_enabled) { |
| 1146 | cmdbuf[2] = 1; /* port 1 is long range receiver */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1147 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | /* |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1155 | * Handle PORT_SYS/IR command response received from the MCE device. |
| 1156 | * |
| 1157 | * Assumes single response with all its data (not truncated) |
| 1158 | * in buf_in[]. The response itself determines its total length |
| 1159 | * (mceusb_cmd_datasize() + 2) and hence the minimum size of buf_in[]. |
| 1160 | * |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1161 | * We don't do anything but print debug spew for many of the command bits |
| 1162 | * we receive from the hardware, but some of them are useful information |
| 1163 | * we want to store so that we can use them. |
| 1164 | */ |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1165 | static void mceusb_handle_command(struct mceusb_dev *ir, u8 *buf_in) |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1166 | { |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1167 | u8 cmd = buf_in[0]; |
| 1168 | u8 subcmd = buf_in[1]; |
| 1169 | u8 *hi = &buf_in[2]; /* read only when required */ |
| 1170 | u8 *lo = &buf_in[3]; /* read only when required */ |
Sean Young | 183e19f | 2018-08-21 15:57:52 -0400 | [diff] [blame] | 1171 | struct ir_raw_event rawir = {}; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1172 | u32 carrier_cycles; |
| 1173 | u32 cycles_fix; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1174 | |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1175 | if (cmd == MCE_CMD_PORT_SYS) { |
| 1176 | switch (subcmd) { |
| 1177 | /* the one and only 5-byte return value command */ |
| 1178 | case MCE_RSP_GETPORTSTATUS: |
James Reynolds | 1b43bad | 2020-12-22 13:07:04 +0100 | [diff] [blame] | 1179 | if (buf_in[5] == 0 && *hi < 8) |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1180 | ir->txports_cabled |= 1 << *hi; |
| 1181 | break; |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1182 | |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1183 | /* 1-byte return value commands */ |
| 1184 | case MCE_RSP_EQEMVER: |
| 1185 | ir->emver = *hi; |
| 1186 | break; |
| 1187 | |
| 1188 | /* No return value commands */ |
| 1189 | case MCE_RSP_CMD_ILLEGAL: |
| 1190 | ir->need_reset = true; |
| 1191 | break; |
| 1192 | |
| 1193 | default: |
| 1194 | break; |
| 1195 | } |
| 1196 | |
| 1197 | return; |
| 1198 | } |
| 1199 | |
| 1200 | if (cmd != MCE_CMD_PORT_IR) |
| 1201 | return; |
| 1202 | |
| 1203 | switch (subcmd) { |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1204 | /* 2-byte return value commands */ |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1205 | case MCE_RSP_EQIRTIMEOUT: |
Sean Young | 528222d8 | 2020-08-23 19:23:05 +0200 | [diff] [blame] | 1206 | ir->rc->timeout = (*hi << 8 | *lo) * MCE_TIME_UNIT; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1207 | break; |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1208 | case MCE_RSP_EQIRNUMPORTS: |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1209 | ir->num_txports = *hi; |
| 1210 | ir->num_rxports = *lo; |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1211 | break; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1212 | case MCE_RSP_EQIRRXCFCNT: |
| 1213 | /* |
| 1214 | * The carrier cycle counter can overflow and wrap around |
| 1215 | * without notice from the device. So frequency measurement |
| 1216 | * will be inaccurate with long duration IR. |
| 1217 | * |
| 1218 | * The long-range (non learning) receiver always reports |
| 1219 | * zero count so we always ignore its report. |
| 1220 | */ |
| 1221 | if (ir->carrier_report_enabled && ir->learning_active && |
| 1222 | ir->pulse_tunit > 0) { |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1223 | carrier_cycles = (*hi << 8 | *lo); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1224 | /* |
| 1225 | * Adjust carrier cycle count by adding |
| 1226 | * 1 missed count per pulse "on" |
| 1227 | */ |
| 1228 | cycles_fix = ir->flags.rx2 == 2 ? ir->pulse_count : 0; |
| 1229 | rawir.carrier_report = 1; |
| 1230 | rawir.carrier = (1000000u / MCE_TIME_UNIT) * |
| 1231 | (carrier_cycles + cycles_fix) / |
| 1232 | ir->pulse_tunit; |
| 1233 | dev_dbg(ir->dev, "RX carrier frequency %u Hz (pulse count = %u, cycles = %u, duration = %u, rx2 = %u)", |
| 1234 | rawir.carrier, ir->pulse_count, carrier_cycles, |
| 1235 | ir->pulse_tunit, ir->flags.rx2); |
| 1236 | ir_raw_event_store(ir->rc, &rawir); |
| 1237 | } |
| 1238 | break; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1239 | |
| 1240 | /* 1-byte return value commands */ |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1241 | case MCE_RSP_EQIRTXPORTS: |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1242 | ir->tx_mask = *hi; |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1243 | break; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1244 | case MCE_RSP_EQIRRXPORTEN: |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1245 | ir->learning_active = ((*hi & 0x02) == 0x02); |
| 1246 | if (ir->rxports_active != *hi) { |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1247 | dev_info(ir->dev, "%s-range (0x%x) receiver active", |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1248 | ir->learning_active ? "short" : "long", *hi); |
| 1249 | ir->rxports_active = *hi; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1250 | } |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1251 | break; |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1252 | |
| 1253 | /* No return value commands */ |
Jarod Wilson | 4840b78 | 2011-07-18 16:54:24 -0300 | [diff] [blame] | 1254 | case MCE_RSP_CMD_ILLEGAL: |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1255 | case MCE_RSP_TX_TIMEOUT: |
Jarod Wilson | 4840b78 | 2011-07-18 16:54:24 -0300 | [diff] [blame] | 1256 | ir->need_reset = true; |
| 1257 | break; |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1258 | |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1259 | default: |
| 1260 | break; |
| 1261 | } |
| 1262 | } |
| 1263 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1264 | static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) |
| 1265 | { |
Sean Young | 183e19f | 2018-08-21 15:57:52 -0400 | [diff] [blame] | 1266 | struct ir_raw_event rawir = {}; |
Sean Young | b83bfd1 | 2012-08-13 08:59:47 -0300 | [diff] [blame] | 1267 | bool event = false; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1268 | int i = 0; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1269 | |
| 1270 | /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ |
| 1271 | if (ir->flags.microsoft_gen1) |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1272 | i = 2; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1273 | |
Jarod Wilson | 29b4494 | 2010-11-09 18:41:46 -0300 | [diff] [blame] | 1274 | /* if there's no data, just return now */ |
| 1275 | if (buf_len <= i) |
| 1276 | return; |
| 1277 | |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1278 | for (; i < buf_len; i++) { |
| 1279 | switch (ir->parser_state) { |
| 1280 | case SUBCMD: |
William Steidtmann | 76dea4c | 2013-04-15 17:17:11 -0300 | [diff] [blame] | 1281 | ir->rem = mceusb_cmd_datasize(ir->cmd, ir->buf_in[i]); |
A Sun | 5c80992 | 2017-03-26 16:04:51 -0300 | [diff] [blame] | 1282 | mceusb_dev_printdata(ir, ir->buf_in, buf_len, i - 1, |
Jarod Wilson | 36e9d26 | 2010-10-22 16:49:35 -0300 | [diff] [blame] | 1283 | ir->rem + 2, false); |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1284 | if (i + ir->rem < buf_len) |
| 1285 | mceusb_handle_command(ir, &ir->buf_in[i - 1]); |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1286 | ir->parser_state = CMD_DATA; |
| 1287 | break; |
| 1288 | case PARSE_IRDATA: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1289 | ir->rem--; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1290 | rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1291 | rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK); |
Sean Young | d458993 | 2018-05-10 07:37:51 -0400 | [diff] [blame] | 1292 | if (unlikely(!rawir.duration)) { |
A Sun | a91418a | 2019-06-19 03:53:53 -0400 | [diff] [blame] | 1293 | dev_dbg(ir->dev, "nonsensical irdata %02x with duration 0", |
| 1294 | ir->buf_in[i]); |
Sean Young | d458993 | 2018-05-10 07:37:51 -0400 | [diff] [blame] | 1295 | break; |
| 1296 | } |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1297 | if (rawir.pulse) { |
| 1298 | ir->pulse_tunit += rawir.duration; |
| 1299 | ir->pulse_count++; |
| 1300 | } |
Sean Young | 528222d8 | 2020-08-23 19:23:05 +0200 | [diff] [blame] | 1301 | rawir.duration *= MCE_TIME_UNIT; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1302 | |
Sean Young | 528222d8 | 2020-08-23 19:23:05 +0200 | [diff] [blame] | 1303 | dev_dbg(ir->dev, "Storing %s %u us (%02x)", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1304 | rawir.pulse ? "pulse" : "space", |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1305 | rawir.duration, ir->buf_in[i]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1306 | |
Sean Young | b83bfd1 | 2012-08-13 08:59:47 -0300 | [diff] [blame] | 1307 | if (ir_raw_event_store_with_filter(ir->rc, &rawir)) |
| 1308 | event = true; |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1309 | break; |
| 1310 | case CMD_DATA: |
| 1311 | ir->rem--; |
| 1312 | break; |
| 1313 | case CMD_HEADER: |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1314 | ir->cmd = ir->buf_in[i]; |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1315 | if ((ir->cmd == MCE_CMD_PORT_IR) || |
| 1316 | ((ir->cmd & MCE_PORT_MASK) != |
Jarod Wilson | 4a88391 | 2010-10-22 14:42:54 -0300 | [diff] [blame] | 1317 | MCE_COMMAND_IRDATA)) { |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1318 | /* |
| 1319 | * got PORT_SYS, PORT_IR, or unknown |
| 1320 | * command response prefix |
| 1321 | */ |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1322 | ir->parser_state = SUBCMD; |
| 1323 | continue; |
| 1324 | } |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1325 | /* |
| 1326 | * got IR data prefix (0x80 + num_bytes) |
| 1327 | * decode MCE packets of the form {0x83, AA, BB, CC} |
| 1328 | * IR data packets can span USB messages |
| 1329 | */ |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1330 | ir->rem = (ir->cmd & MCE_PACKET_LENGTH_MASK); |
A Sun | 5c80992 | 2017-03-26 16:04:51 -0300 | [diff] [blame] | 1331 | mceusb_dev_printdata(ir, ir->buf_in, buf_len, |
Jarod Wilson | 2ee95db | 2010-11-12 19:49:04 -0300 | [diff] [blame] | 1332 | i, ir->rem + 1, false); |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1333 | if (ir->rem) { |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1334 | ir->parser_state = PARSE_IRDATA; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1335 | } else { |
Sean Young | 183e19f | 2018-08-21 15:57:52 -0400 | [diff] [blame] | 1336 | struct ir_raw_event ev = { |
| 1337 | .timeout = 1, |
| 1338 | .duration = ir->rc->timeout |
| 1339 | }; |
| 1340 | |
Sean Young | 91352b5 | 2018-04-18 05:36:25 -0400 | [diff] [blame] | 1341 | if (ir_raw_event_store_with_filter(ir->rc, |
Sean Young | 183e19f | 2018-08-21 15:57:52 -0400 | [diff] [blame] | 1342 | &ev)) |
Sean Young | 91352b5 | 2018-04-18 05:36:25 -0400 | [diff] [blame] | 1343 | event = true; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1344 | ir->pulse_tunit = 0; |
| 1345 | ir->pulse_count = 0; |
| 1346 | } |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1347 | break; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1348 | } |
| 1349 | |
Mauro Carvalho Chehab | 39dc5c3 | 2010-10-22 01:35:44 -0300 | [diff] [blame] | 1350 | if (ir->parser_state != CMD_HEADER && !ir->rem) |
| 1351 | ir->parser_state = CMD_HEADER; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1352 | } |
A Sun | e431486 | 2019-09-06 09:17:20 -0300 | [diff] [blame] | 1353 | |
| 1354 | /* |
| 1355 | * Accept IR data spanning multiple rx buffers. |
| 1356 | * Reject MCE command response spanning multiple rx buffers. |
| 1357 | */ |
| 1358 | if (ir->parser_state != PARSE_IRDATA || !ir->rem) |
| 1359 | ir->parser_state = CMD_HEADER; |
| 1360 | |
Sean Young | b83bfd1 | 2012-08-13 08:59:47 -0300 | [diff] [blame] | 1361 | if (event) { |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1362 | dev_dbg(ir->dev, "processed IR data"); |
Sean Young | b83bfd1 | 2012-08-13 08:59:47 -0300 | [diff] [blame] | 1363 | ir_raw_event_handle(ir->rc); |
| 1364 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1365 | } |
| 1366 | |
Sean Young | 6ac454a | 2012-07-15 13:31:31 -0300 | [diff] [blame] | 1367 | static void mceusb_dev_recv(struct urb *urb) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1368 | { |
| 1369 | struct mceusb_dev *ir; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1370 | |
| 1371 | if (!urb) |
| 1372 | return; |
| 1373 | |
| 1374 | ir = urb->context; |
| 1375 | if (!ir) { |
| 1376 | usb_unlink_urb(urb); |
| 1377 | return; |
| 1378 | } |
| 1379 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1380 | switch (urb->status) { |
| 1381 | /* success */ |
| 1382 | case 0: |
Sean Young | d26cec2 | 2016-04-14 17:42:49 -0300 | [diff] [blame] | 1383 | mceusb_process_ir_data(ir, urb->actual_length); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1384 | break; |
| 1385 | |
| 1386 | case -ECONNRESET: |
| 1387 | case -ENOENT: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1388 | case -EILSEQ: |
Rajat Asthana | 476db72 | 2021-08-18 22:31:10 +0200 | [diff] [blame] | 1389 | case -EPROTO: |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1390 | case -ESHUTDOWN: |
| 1391 | usb_unlink_urb(urb); |
| 1392 | return; |
| 1393 | |
| 1394 | case -EPIPE: |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1395 | dev_err(ir->dev, "Error: urb status = %d (RX HALT)", |
| 1396 | urb->status); |
| 1397 | mceusb_defer_kevent(ir, EVENT_RX_HALT); |
| 1398 | return; |
| 1399 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1400 | default: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1401 | dev_err(ir->dev, "Error: urb status = %d", urb->status); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1402 | break; |
| 1403 | } |
| 1404 | |
| 1405 | usb_submit_urb(urb, GFP_ATOMIC); |
| 1406 | } |
| 1407 | |
Jarod Wilson | ab1072e | 2011-07-18 16:54:25 -0300 | [diff] [blame] | 1408 | static void mceusb_get_emulator_version(struct mceusb_dev *ir) |
| 1409 | { |
| 1410 | /* If we get no reply or an illegal command reply, its ver 1, says MS */ |
| 1411 | ir->emver = 1; |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1412 | mce_command_out(ir, GET_EMVER, sizeof(GET_EMVER)); |
Jarod Wilson | ab1072e | 2011-07-18 16:54:25 -0300 | [diff] [blame] | 1413 | } |
| 1414 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1415 | static void mceusb_gen1_init(struct mceusb_dev *ir) |
| 1416 | { |
Mauro Carvalho Chehab | ca17a4f | 2010-07-10 11:19:42 -0300 | [diff] [blame] | 1417 | int ret; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1418 | struct device *dev = ir->dev; |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 1419 | char *data; |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1420 | |
| 1421 | data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL); |
| 1422 | if (!data) { |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1423 | dev_err(dev, "%s: memory allocation failed!", __func__); |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1424 | return; |
| 1425 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1426 | |
| 1427 | /* |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 1428 | * 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] | 1429 | * on the receive control pipe and expect a certain value pair back |
| 1430 | */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1431 | ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), |
| 1432 | USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0, |
Johan Hovold | 16394e9 | 2021-10-25 13:16:34 +0100 | [diff] [blame] | 1433 | data, USB_CTRL_MSG_SZ, 3000); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1434 | dev_dbg(dev, "set address - ret = %d", ret); |
| 1435 | dev_dbg(dev, "set address - data[0] = %d, data[1] = %d", |
| 1436 | data[0], data[1]); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1437 | |
| 1438 | /* set feature: bit rate 38400 bps */ |
| 1439 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 1440 | USB_REQ_SET_FEATURE, USB_TYPE_VENDOR, |
Johan Hovold | 16394e9 | 2021-10-25 13:16:34 +0100 | [diff] [blame] | 1441 | 0xc04e, 0x0000, NULL, 0, 3000); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1442 | |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1443 | dev_dbg(dev, "set feature - ret = %d", ret); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1444 | |
| 1445 | /* bRequest 4: set char length to 8 bits */ |
| 1446 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 1447 | 4, USB_TYPE_VENDOR, |
Johan Hovold | 16394e9 | 2021-10-25 13:16:34 +0100 | [diff] [blame] | 1448 | 0x0808, 0x0000, NULL, 0, 3000); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1449 | dev_dbg(dev, "set char length - retB = %d", ret); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1450 | |
| 1451 | /* bRequest 2: set handshaking to use DTR/DSR */ |
| 1452 | ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), |
| 1453 | 2, USB_TYPE_VENDOR, |
Johan Hovold | 16394e9 | 2021-10-25 13:16:34 +0100 | [diff] [blame] | 1454 | 0x0000, 0x0100, NULL, 0, 3000); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1455 | dev_dbg(dev, "set handshake - retC = %d", ret); |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1456 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1457 | /* device resume */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1458 | mce_command_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME)); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1459 | |
| 1460 | /* get hw/sw revision? */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1461 | mce_command_out(ir, GET_REVISION, sizeof(GET_REVISION)); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1462 | |
Jarod Wilson | 657290b | 2010-06-16 17:10:05 -0300 | [diff] [blame] | 1463 | kfree(data); |
Sean Young | 8dfef67 | 2013-01-29 08:19:29 -0300 | [diff] [blame] | 1464 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1465 | |
| 1466 | static void mceusb_gen2_init(struct mceusb_dev *ir) |
| 1467 | { |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1468 | /* device resume */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1469 | mce_command_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1470 | |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1471 | /* get wake version (protocol, key, address) */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1472 | mce_command_out(ir, GET_WAKEVERSION, sizeof(GET_WAKEVERSION)); |
Jarod Wilson | a6fbd3b | 2011-07-18 16:54:21 -0300 | [diff] [blame] | 1473 | |
| 1474 | /* unknown what this one actually returns... */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1475 | mce_command_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1476 | } |
| 1477 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1478 | static void mceusb_get_parameters(struct mceusb_dev *ir) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1479 | { |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1480 | int i; |
| 1481 | unsigned char cmdbuf[3] = { MCE_CMD_PORT_SYS, |
| 1482 | MCE_CMD_GETPORTSTATUS, 0x00 }; |
| 1483 | |
| 1484 | /* defaults, if the hardware doesn't support querying */ |
| 1485 | ir->num_txports = 2; |
| 1486 | ir->num_rxports = 2; |
| 1487 | |
| 1488 | /* get number of tx and rx ports */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1489 | mce_command_out(ir, GET_NUM_PORTS, sizeof(GET_NUM_PORTS)); |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1490 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1491 | /* get the carrier and frequency */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1492 | mce_command_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1493 | |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1494 | if (ir->num_txports && !ir->flags.no_tx) |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1495 | /* get the transmitter bitmask */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1496 | mce_command_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1497 | |
| 1498 | /* get receiver timeout value */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1499 | mce_command_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1500 | |
| 1501 | /* get receiver sensor setting */ |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1502 | mce_command_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR)); |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1503 | |
| 1504 | for (i = 0; i < ir->num_txports; i++) { |
| 1505 | cmdbuf[2] = i; |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1506 | mce_command_out(ir, cmdbuf, sizeof(cmdbuf)); |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1507 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1508 | } |
| 1509 | |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 1510 | static void mceusb_flash_led(struct mceusb_dev *ir) |
| 1511 | { |
| 1512 | if (ir->emver < 2) |
| 1513 | return; |
| 1514 | |
A Sun | 9fc3ce31 | 2019-08-15 13:41:19 -0300 | [diff] [blame] | 1515 | mce_command_out(ir, FLASH_LED, sizeof(FLASH_LED)); |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 1516 | } |
| 1517 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1518 | /* |
| 1519 | * Workqueue function |
| 1520 | * for resetting or recovering device after occurrence of error events |
| 1521 | * specified in ir->kevent bit field. |
| 1522 | * Function runs (via schedule_work()) in non-interrupt context, for |
| 1523 | * calls here (such as usb_clear_halt()) requiring non-interrupt context. |
| 1524 | */ |
| 1525 | static void mceusb_deferred_kevent(struct work_struct *work) |
| 1526 | { |
| 1527 | struct mceusb_dev *ir = |
| 1528 | container_of(work, struct mceusb_dev, kevent); |
| 1529 | int status; |
| 1530 | |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1531 | dev_err(ir->dev, "kevent handler called (flags 0x%lx)", |
| 1532 | ir->kevent_flags); |
| 1533 | |
| 1534 | if (test_bit(EVENT_RST_PEND, &ir->kevent_flags)) { |
| 1535 | dev_err(ir->dev, "kevent handler canceled pending USB Reset Device"); |
| 1536 | return; |
| 1537 | } |
| 1538 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1539 | if (test_bit(EVENT_RX_HALT, &ir->kevent_flags)) { |
| 1540 | usb_unlink_urb(ir->urb_in); |
| 1541 | status = usb_clear_halt(ir->usbdev, ir->pipe_in); |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1542 | dev_err(ir->dev, "rx clear halt status = %d", status); |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1543 | if (status < 0) { |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1544 | /* |
| 1545 | * Unable to clear RX halt/stall. |
| 1546 | * Will need to call usb_reset_device(). |
| 1547 | */ |
| 1548 | dev_err(ir->dev, |
| 1549 | "stuck RX HALT state requires USB Reset Device to clear"); |
| 1550 | usb_queue_reset_device(ir->usbintf); |
| 1551 | set_bit(EVENT_RST_PEND, &ir->kevent_flags); |
| 1552 | clear_bit(EVENT_RX_HALT, &ir->kevent_flags); |
| 1553 | |
| 1554 | /* Cancel all other error events and handlers */ |
| 1555 | clear_bit(EVENT_TX_HALT, &ir->kevent_flags); |
| 1556 | return; |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1557 | } |
| 1558 | clear_bit(EVENT_RX_HALT, &ir->kevent_flags); |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1559 | status = usb_submit_urb(ir->urb_in, GFP_KERNEL); |
| 1560 | if (status < 0) { |
| 1561 | dev_err(ir->dev, "rx unhalt submit urb error = %d", |
| 1562 | status); |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1563 | } |
| 1564 | } |
A Sun | c779a9c | 2017-04-13 05:06:47 -0300 | [diff] [blame] | 1565 | |
| 1566 | if (test_bit(EVENT_TX_HALT, &ir->kevent_flags)) { |
| 1567 | status = usb_clear_halt(ir->usbdev, ir->pipe_out); |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1568 | dev_err(ir->dev, "tx clear halt status = %d", status); |
| 1569 | if (status < 0) { |
| 1570 | /* |
| 1571 | * Unable to clear TX halt/stall. |
| 1572 | * Will need to call usb_reset_device(). |
| 1573 | */ |
| 1574 | dev_err(ir->dev, |
| 1575 | "stuck TX HALT state requires USB Reset Device to clear"); |
| 1576 | usb_queue_reset_device(ir->usbintf); |
| 1577 | set_bit(EVENT_RST_PEND, &ir->kevent_flags); |
| 1578 | clear_bit(EVENT_TX_HALT, &ir->kevent_flags); |
| 1579 | |
| 1580 | /* Cancel all other error events and handlers */ |
| 1581 | clear_bit(EVENT_RX_HALT, &ir->kevent_flags); |
| 1582 | return; |
| 1583 | } |
A Sun | c779a9c | 2017-04-13 05:06:47 -0300 | [diff] [blame] | 1584 | clear_bit(EVENT_TX_HALT, &ir->kevent_flags); |
| 1585 | } |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1586 | } |
| 1587 | |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1588 | static struct rc_dev *mceusb_init_rc_dev(struct mceusb_dev *ir) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1589 | { |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1590 | struct usb_device *udev = ir->usbdev; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1591 | struct device *dev = ir->dev; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1592 | struct rc_dev *rc; |
| 1593 | int ret; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1594 | |
Andi Shyti | 0f7499f | 2016-12-16 06:50:58 -0200 | [diff] [blame] | 1595 | rc = rc_allocate_device(RC_DRIVER_IR_RAW); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1596 | if (!rc) { |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1597 | dev_err(dev, "remote dev allocation failed"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1598 | goto out; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1599 | } |
| 1600 | |
Mauro Carvalho Chehab | 3459d45 | 2010-10-22 11:52:53 -0300 | [diff] [blame] | 1601 | snprintf(ir->name, sizeof(ir->name), "%s (%04x:%04x)", |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1602 | mceusb_model[ir->model].name ? |
Paul Bender | 5ad1a55 | 2010-11-17 16:56:17 -0300 | [diff] [blame] | 1603 | mceusb_model[ir->model].name : |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1604 | "Media Center Ed. eHome Infrared Remote Transceiver", |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1605 | le16_to_cpu(ir->usbdev->descriptor.idVendor), |
| 1606 | le16_to_cpu(ir->usbdev->descriptor.idProduct)); |
| 1607 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1608 | usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1609 | |
Sean Young | 518f4b2 | 2017-07-01 12:13:19 -0400 | [diff] [blame] | 1610 | rc->device_name = ir->name; |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1611 | rc->input_phys = ir->phys; |
| 1612 | usb_to_input_id(ir->usbdev, &rc->input_id); |
| 1613 | rc->dev.parent = dev; |
| 1614 | rc->priv = ir; |
Sean Young | 6d741bf | 2017-08-07 16:20:58 -0400 | [diff] [blame] | 1615 | rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER; |
Sean Young | e6d025d | 2021-08-03 11:03:30 +0200 | [diff] [blame] | 1616 | rc->rx_resolution = MCE_TIME_UNIT; |
Sean Young | 528222d8 | 2020-08-23 19:23:05 +0200 | [diff] [blame] | 1617 | rc->min_timeout = MCE_TIME_UNIT; |
| 1618 | rc->timeout = MS_TO_US(100); |
Sean Young | aec3ead | 2018-05-09 06:11:28 -0400 | [diff] [blame] | 1619 | if (!mceusb_model[ir->model].broken_irtimeout) { |
| 1620 | rc->s_timeout = mceusb_set_timeout; |
| 1621 | rc->max_timeout = 10 * IR_DEFAULT_TIMEOUT; |
| 1622 | } else { |
| 1623 | /* |
| 1624 | * If we can't set the timeout using CMD_SETIRTIMEOUT, we can |
| 1625 | * rely on software timeouts for timeouts < 100ms. |
| 1626 | */ |
| 1627 | rc->max_timeout = rc->timeout; |
| 1628 | } |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1629 | if (!ir->flags.no_tx) { |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1630 | rc->s_tx_mask = mceusb_set_tx_mask; |
| 1631 | rc->s_tx_carrier = mceusb_set_tx_carrier; |
| 1632 | rc->tx_ir = mceusb_tx_ir; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1633 | } |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1634 | if (ir->flags.rx2 > 0) { |
Sean Young | 8b777ed | 2021-07-03 11:04:40 +0200 | [diff] [blame] | 1635 | rc->s_wideband_receiver = mceusb_set_rx_wideband; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1636 | rc->s_carrier_report = mceusb_set_rx_carrier_report; |
| 1637 | } |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1638 | rc->driver_name = DRIVER_NAME; |
Mauro Carvalho Chehab | 5b8c8d4 | 2014-07-27 17:28:48 -0300 | [diff] [blame] | 1639 | |
| 1640 | switch (le16_to_cpu(udev->descriptor.idVendor)) { |
| 1641 | case VENDOR_HAUPPAUGE: |
| 1642 | rc->map_name = RC_MAP_HAUPPAUGE; |
| 1643 | break; |
| 1644 | case VENDOR_PCTV: |
| 1645 | rc->map_name = RC_MAP_PINNACLE_PCTV_HD; |
| 1646 | break; |
| 1647 | default: |
| 1648 | rc->map_name = RC_MAP_RC6_MCE; |
| 1649 | } |
| 1650 | if (mceusb_model[ir->model].rc_map) |
| 1651 | rc->map_name = mceusb_model[ir->model].rc_map; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1652 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1653 | ret = rc_register_device(rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1654 | if (ret < 0) { |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1655 | dev_err(dev, "remote dev registration failed"); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1656 | goto out; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1657 | } |
| 1658 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1659 | return rc; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1660 | |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1661 | out: |
| 1662 | rc_free_device(rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1663 | return NULL; |
| 1664 | } |
| 1665 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1666 | static int mceusb_dev_probe(struct usb_interface *intf, |
| 1667 | const struct usb_device_id *id) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1668 | { |
| 1669 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1670 | struct usb_host_interface *idesc; |
| 1671 | struct usb_endpoint_descriptor *ep = NULL; |
| 1672 | struct usb_endpoint_descriptor *ep_in = NULL; |
| 1673 | struct usb_endpoint_descriptor *ep_out = NULL; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1674 | struct mceusb_dev *ir = NULL; |
Sean Young | e1159cb | 2016-04-14 17:42:50 -0300 | [diff] [blame] | 1675 | int pipe, maxp, i, res; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1676 | char buf[63], name[128] = ""; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1677 | enum mceusb_model_type model = id->driver_info; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1678 | bool is_gen3; |
| 1679 | bool is_microsoft_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1680 | bool tx_mask_normal; |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1681 | int ir_intfnum; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1682 | |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1683 | dev_dbg(&intf->dev, "%s called", __func__); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1684 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1685 | idesc = intf->cur_altsetting; |
| 1686 | |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1687 | is_gen3 = mceusb_model[model].mce_gen3; |
| 1688 | is_microsoft_gen1 = mceusb_model[model].mce_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1689 | tx_mask_normal = mceusb_model[model].tx_mask_normal; |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1690 | ir_intfnum = mceusb_model[model].ir_intfnum; |
Mauro Carvalho Chehab | 56e92f6 | 2010-10-18 16:32:50 -0300 | [diff] [blame] | 1691 | |
Jarod Wilson | a6994eb | 2011-03-01 12:38:28 -0300 | [diff] [blame] | 1692 | /* There are multi-function devices with non-IR interfaces */ |
| 1693 | if (idesc->desc.bInterfaceNumber != ir_intfnum) |
| 1694 | return -ENODEV; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1695 | |
| 1696 | /* step through the endpoints to find first bulk in and out endpoint */ |
| 1697 | for (i = 0; i < idesc->desc.bNumEndpoints; ++i) { |
| 1698 | ep = &idesc->endpoint[i].desc; |
| 1699 | |
Matt DeVillier | 0cacb46 | 2014-04-24 11:16:31 -0300 | [diff] [blame] | 1700 | if (ep_in == NULL) { |
| 1701 | if (usb_endpoint_is_bulk_in(ep)) { |
| 1702 | ep_in = ep; |
| 1703 | dev_dbg(&intf->dev, "acceptable bulk inbound endpoint found\n"); |
| 1704 | } else if (usb_endpoint_is_int_in(ep)) { |
| 1705 | ep_in = ep; |
| 1706 | ep_in->bInterval = 1; |
| 1707 | dev_dbg(&intf->dev, "acceptable interrupt inbound endpoint found\n"); |
| 1708 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1709 | } |
| 1710 | |
Matt DeVillier | 0cacb46 | 2014-04-24 11:16:31 -0300 | [diff] [blame] | 1711 | if (ep_out == NULL) { |
| 1712 | if (usb_endpoint_is_bulk_out(ep)) { |
| 1713 | ep_out = ep; |
| 1714 | dev_dbg(&intf->dev, "acceptable bulk outbound endpoint found\n"); |
| 1715 | } else if (usb_endpoint_is_int_out(ep)) { |
| 1716 | ep_out = ep; |
| 1717 | ep_out->bInterval = 1; |
| 1718 | dev_dbg(&intf->dev, "acceptable interrupt outbound endpoint found\n"); |
| 1719 | } |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1720 | } |
| 1721 | } |
Johan Hovold | 03eb2a5 | 2017-03-07 15:14:13 -0300 | [diff] [blame] | 1722 | if (!ep_in || !ep_out) { |
| 1723 | dev_dbg(&intf->dev, "required endpoints not found\n"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1724 | return -ENODEV; |
| 1725 | } |
| 1726 | |
Matt DeVillier | 0cacb46 | 2014-04-24 11:16:31 -0300 | [diff] [blame] | 1727 | if (usb_endpoint_xfer_int(ep_in)) |
| 1728 | pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress); |
| 1729 | else |
| 1730 | pipe = usb_rcvbulkpipe(dev, ep_in->bEndpointAddress); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1731 | maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); |
| 1732 | |
| 1733 | ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL); |
| 1734 | if (!ir) |
| 1735 | goto mem_alloc_fail; |
| 1736 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1737 | ir->pipe_in = pipe; |
Christophe JAILLET | ddecfc7 | 2020-08-15 08:12:37 +0200 | [diff] [blame] | 1738 | ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_KERNEL, &ir->dma_in); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1739 | if (!ir->buf_in) |
| 1740 | goto buf_in_alloc_fail; |
| 1741 | |
| 1742 | ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); |
| 1743 | if (!ir->urb_in) |
| 1744 | goto urb_in_alloc_fail; |
| 1745 | |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1746 | ir->usbintf = intf; |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1747 | ir->usbdev = usb_get_dev(dev); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1748 | ir->dev = &intf->dev; |
| 1749 | ir->len_in = maxp; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1750 | ir->flags.microsoft_gen1 = is_microsoft_gen1; |
Jarod Wilson | d8cc7fd | 2010-12-15 19:20:55 -0300 | [diff] [blame] | 1751 | ir->flags.tx_mask_normal = tx_mask_normal; |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1752 | ir->flags.no_tx = mceusb_model[model].no_tx; |
A Sun | 279c60f | 2018-03-16 15:52:09 -0400 | [diff] [blame] | 1753 | ir->flags.rx2 = mceusb_model[model].rx2; |
Mauro Carvalho Chehab | 37dbd3a | 2010-10-22 11:50:37 -0300 | [diff] [blame] | 1754 | ir->model = model; |
| 1755 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1756 | /* Saving usb interface data for use by the transmitter routine */ |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1757 | ir->usb_ep_out = ep_out; |
A Sun | c779a9c | 2017-04-13 05:06:47 -0300 | [diff] [blame] | 1758 | if (usb_endpoint_xfer_int(ep_out)) |
| 1759 | ir->pipe_out = usb_sndintpipe(ir->usbdev, |
| 1760 | ep_out->bEndpointAddress); |
| 1761 | else |
| 1762 | ir->pipe_out = usb_sndbulkpipe(ir->usbdev, |
| 1763 | ep_out->bEndpointAddress); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1764 | |
| 1765 | if (dev->descriptor.iManufacturer |
| 1766 | && usb_string(dev, dev->descriptor.iManufacturer, |
| 1767 | buf, sizeof(buf)) > 0) |
Mauro Carvalho Chehab | c0decac | 2018-09-10 08:19:14 -0400 | [diff] [blame] | 1768 | strscpy(name, buf, sizeof(name)); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1769 | if (dev->descriptor.iProduct |
| 1770 | && usb_string(dev, dev->descriptor.iProduct, |
| 1771 | buf, sizeof(buf)) > 0) |
| 1772 | snprintf(name + strlen(name), sizeof(name) - strlen(name), |
| 1773 | " %s", buf); |
| 1774 | |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1775 | /* |
| 1776 | * Initialize async USB error handler before registering |
| 1777 | * or activating any mceusb RX and TX functions |
| 1778 | */ |
| 1779 | INIT_WORK(&ir->kevent, mceusb_deferred_kevent); |
| 1780 | |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1781 | ir->rc = mceusb_init_rc_dev(ir); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1782 | if (!ir->rc) |
| 1783 | goto rc_dev_fail; |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1784 | |
Jarod Wilson | b48592e | 2010-07-03 22:42:14 -0300 | [diff] [blame] | 1785 | /* wire up inbound data handler */ |
A Sun | 8e175b2 | 2017-03-26 15:33:07 -0300 | [diff] [blame] | 1786 | if (usb_endpoint_xfer_int(ep_in)) |
| 1787 | usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in, maxp, |
| 1788 | mceusb_dev_recv, ir, ep_in->bInterval); |
| 1789 | else |
| 1790 | usb_fill_bulk_urb(ir->urb_in, dev, pipe, ir->buf_in, maxp, |
| 1791 | mceusb_dev_recv, ir); |
| 1792 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1793 | ir->urb_in->transfer_dma = ir->dma_in; |
| 1794 | ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 1795 | |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 1796 | /* flush buffers on the device */ |
A Sun | 5c80992 | 2017-03-26 16:04:51 -0300 | [diff] [blame] | 1797 | dev_dbg(&intf->dev, "Flushing receive buffers"); |
Sean Young | e1159cb | 2016-04-14 17:42:50 -0300 | [diff] [blame] | 1798 | res = usb_submit_urb(ir->urb_in, GFP_KERNEL); |
| 1799 | if (res) |
A Sun | 5c80992 | 2017-03-26 16:04:51 -0300 | [diff] [blame] | 1800 | dev_err(&intf->dev, "failed to flush buffers: %d", res); |
Jarod Wilson | 3a918aa | 2011-05-26 14:23:18 -0300 | [diff] [blame] | 1801 | |
Jarod Wilson | ab1072e | 2011-07-18 16:54:25 -0300 | [diff] [blame] | 1802 | /* figure out which firmware/emulator version this hardware has */ |
| 1803 | mceusb_get_emulator_version(ir); |
| 1804 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1805 | /* initialize device */ |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1806 | if (ir->flags.microsoft_gen1) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1807 | mceusb_gen1_init(ir); |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1808 | else if (!is_gen3) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1809 | mceusb_gen2_init(ir); |
| 1810 | |
Jarod Wilson | 22b0766 | 2010-07-08 12:38:57 -0300 | [diff] [blame] | 1811 | mceusb_get_parameters(ir); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1812 | |
Jarod Wilson | b71969b | 2011-07-18 16:54:27 -0300 | [diff] [blame] | 1813 | mceusb_flash_led(ir); |
| 1814 | |
Jarod Wilson | 6f6c625 | 2010-10-29 00:07:39 -0300 | [diff] [blame] | 1815 | if (!ir->flags.no_tx) |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1816 | mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1817 | |
| 1818 | usb_set_intfdata(intf, ir); |
| 1819 | |
Jarod Wilson | fa334898 | 2011-07-18 16:54:23 -0300 | [diff] [blame] | 1820 | /* enable wake via this device */ |
| 1821 | device_set_wakeup_capable(ir->dev, true); |
| 1822 | device_set_wakeup_enable(ir->dev, true); |
| 1823 | |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1824 | dev_info(&intf->dev, "Registered %s with mce emulator interface version %x", |
| 1825 | name, ir->emver); |
| 1826 | dev_info(&intf->dev, "%x tx ports (0x%x cabled) and %x rx sensors (0x%x active)", |
Jarod Wilson | a411e83 | 2011-07-18 16:54:26 -0300 | [diff] [blame] | 1827 | ir->num_txports, ir->txports_cabled, |
| 1828 | ir->num_rxports, ir->rxports_active); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1829 | |
| 1830 | return 0; |
| 1831 | |
| 1832 | /* Error-handling path */ |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1833 | rc_dev_fail: |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1834 | cancel_work_sync(&ir->kevent); |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1835 | usb_put_dev(ir->usbdev); |
Sean Young | e1159cb | 2016-04-14 17:42:50 -0300 | [diff] [blame] | 1836 | usb_kill_urb(ir->urb_in); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1837 | usb_free_urb(ir->urb_in); |
| 1838 | urb_in_alloc_fail: |
| 1839 | usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in); |
| 1840 | buf_in_alloc_fail: |
| 1841 | kfree(ir); |
| 1842 | mem_alloc_fail: |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1843 | dev_err(&intf->dev, "%s: device setup failed!", __func__); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1844 | |
| 1845 | return -ENOMEM; |
| 1846 | } |
| 1847 | |
| 1848 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1849 | static void mceusb_dev_disconnect(struct usb_interface *intf) |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1850 | { |
| 1851 | struct usb_device *dev = interface_to_usbdev(intf); |
| 1852 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
| 1853 | |
A Sun | 19d41a2 | 2019-07-14 22:51:26 -0400 | [diff] [blame] | 1854 | dev_dbg(&intf->dev, "%s called", __func__); |
| 1855 | |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1856 | usb_set_intfdata(intf, NULL); |
| 1857 | |
| 1858 | if (!ir) |
| 1859 | return; |
| 1860 | |
| 1861 | ir->usbdev = NULL; |
A Sun | a06854a | 2017-03-26 15:28:08 -0300 | [diff] [blame] | 1862 | cancel_work_sync(&ir->kevent); |
David Härdeman | d8b4b58 | 2010-10-29 16:08:23 -0300 | [diff] [blame] | 1863 | rc_unregister_device(ir->rc); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1864 | usb_kill_urb(ir->urb_in); |
| 1865 | usb_free_urb(ir->urb_in); |
| 1866 | usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in); |
Alexey Khoroshilov | e947d9a | 2014-09-08 19:10:43 -0300 | [diff] [blame] | 1867 | usb_put_dev(dev); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1868 | |
| 1869 | kfree(ir); |
| 1870 | } |
| 1871 | |
| 1872 | static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message) |
| 1873 | { |
| 1874 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1875 | dev_info(ir->dev, "suspend"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1876 | usb_kill_urb(ir->urb_in); |
| 1877 | return 0; |
| 1878 | } |
| 1879 | |
| 1880 | static int mceusb_dev_resume(struct usb_interface *intf) |
| 1881 | { |
| 1882 | struct mceusb_dev *ir = usb_get_intfdata(intf); |
Sean Young | 6b4a16c | 2014-01-20 19:10:44 -0300 | [diff] [blame] | 1883 | dev_info(ir->dev, "resume"); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1884 | if (usb_submit_urb(ir->urb_in, GFP_ATOMIC)) |
| 1885 | return -EIO; |
| 1886 | return 0; |
| 1887 | } |
| 1888 | |
| 1889 | static struct usb_driver mceusb_dev_driver = { |
| 1890 | .name = DRIVER_NAME, |
| 1891 | .probe = mceusb_dev_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1892 | .disconnect = mceusb_dev_disconnect, |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1893 | .suspend = mceusb_dev_suspend, |
| 1894 | .resume = mceusb_dev_resume, |
| 1895 | .reset_resume = mceusb_dev_resume, |
| 1896 | .id_table = mceusb_dev_table |
| 1897 | }; |
| 1898 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 1899 | module_usb_driver(mceusb_dev_driver); |
Jarod Wilson | 66e8952 | 2010-06-01 17:32:08 -0300 | [diff] [blame] | 1900 | |
| 1901 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 1902 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 1903 | MODULE_LICENSE("GPL"); |
| 1904 | MODULE_DEVICE_TABLE(usb, mceusb_dev_table); |