63
69
#define MCE_PULSE_MASK 0x7f /* Pulse mask */
64
70
#define MCE_MAX_PULSE_LENGTH 0x7f /* Longest transmittable pulse symbol */
66
#define MCE_HW_CMD_HEADER 0xff /* MCE hardware command header */
67
#define MCE_COMMAND_HEADER 0x9f /* MCE command header */
68
#define MCE_COMMAND_MASK 0xe0 /* Mask out command bits */
69
#define MCE_COMMAND_NULL 0x00 /* These show up various places... */
70
/* if buf[i] & MCE_COMMAND_MASK == 0x80 and buf[i] != MCE_COMMAND_HEADER,
71
* then we're looking at a raw IR data sample */
72
#define MCE_COMMAND_IRDATA 0x80
73
#define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */
75
/* Sub-commands, which follow MCE_COMMAND_HEADER or MCE_HW_CMD_HEADER */
73
* The interface between the host and the IR hardware is command-response
74
* based. All commands and responses have a consistent format, where a lead
75
* byte always identifies the type of data following it. The lead byte has
76
* a port value in the 3 highest bits and a length value in the 5 lowest
79
* The length field is overloaded, with a value of 11111 indicating that the
80
* following byte is a command or response code, and the length of the entire
81
* message is determined by the code. If the length field is not 11111, then
82
* it specifies the number of bytes of port data that follow.
85
#define MCE_PORT_IR 0x4 /* (0x4 << 5) | MCE_CMD = 0x9f */
86
#define MCE_PORT_SYS 0x7 /* (0x7 << 5) | MCE_CMD = 0xff */
87
#define MCE_PORT_SER 0x6 /* 0xc0 thru 0xdf flush & 0x1f bytes */
88
#define MCE_PORT_MASK 0xe0 /* Mask out command bits */
90
/* Command port headers */
91
#define MCE_CMD_PORT_IR 0x9f /* IR-related cmd/rsp */
92
#define MCE_CMD_PORT_SYS 0xff /* System (non-IR) device cmd/rsp */
94
/* Commands that set device state (2-4 bytes in length) */
95
#define MCE_CMD_RESET 0xfe /* Reset device, 2 bytes */
96
#define MCE_CMD_RESUME 0xaa /* Resume device after error, 2 bytes */
97
#define MCE_CMD_SETIRCFS 0x06 /* Set tx carrier, 4 bytes */
98
#define MCE_CMD_SETIRTIMEOUT 0x0c /* Set timeout, 4 bytes */
99
#define MCE_CMD_SETIRTXPORTS 0x08 /* Set tx ports, 3 bytes */
100
#define MCE_CMD_SETIRRXPORTEN 0x14 /* Set rx ports, 3 bytes */
101
#define MCE_CMD_FLASHLED 0x23 /* Flash receiver LED, 2 bytes */
103
/* Commands that query device state (all 2 bytes, unless noted) */
104
#define MCE_CMD_GETIRCFS 0x07 /* Get carrier */
105
#define MCE_CMD_GETIRTIMEOUT 0x0d /* Get timeout */
106
#define MCE_CMD_GETIRTXPORTS 0x13 /* Get tx ports */
107
#define MCE_CMD_GETIRRXPORTEN 0x15 /* Get rx ports */
108
#define MCE_CMD_GETPORTSTATUS 0x11 /* Get tx port status, 3 bytes */
109
#define MCE_CMD_GETIRNUMPORTS 0x16 /* Get number of ports */
110
#define MCE_CMD_GETWAKESOURCE 0x17 /* Get wake source */
111
#define MCE_CMD_GETEMVER 0x22 /* Get emulator interface version */
112
#define MCE_CMD_GETDEVDETAILS 0x21 /* Get device details (em ver2 only) */
113
#define MCE_CMD_GETWAKESUPPORT 0x20 /* Get wake details (em ver2 only) */
114
#define MCE_CMD_GETWAKEVERSION 0x18 /* Get wake pattern (em ver2 only) */
117
#define MCE_CMD_NOP 0xff /* No operation */
119
/* Responses to commands (non-error cases) */
120
#define MCE_RSP_EQIRCFS 0x06 /* tx carrier, 4 bytes */
121
#define MCE_RSP_EQIRTIMEOUT 0x0c /* rx timeout, 4 bytes */
122
#define MCE_RSP_GETWAKESOURCE 0x17 /* wake source, 3 bytes */
123
#define MCE_RSP_EQIRTXPORTS 0x08 /* tx port mask, 3 bytes */
124
#define MCE_RSP_EQIRRXPORTEN 0x14 /* rx port mask, 3 bytes */
125
#define MCE_RSP_GETPORTSTATUS 0x11 /* tx port status, 7 bytes */
126
#define MCE_RSP_EQIRRXCFCNT 0x15 /* rx carrier count, 4 bytes */
127
#define MCE_RSP_EQIRNUMPORTS 0x16 /* number of ports, 4 bytes */
128
#define MCE_RSP_EQWAKESUPPORT 0x20 /* wake capabilities, 3 bytes */
129
#define MCE_RSP_EQWAKEVERSION 0x18 /* wake pattern details, 6 bytes */
130
#define MCE_RSP_EQDEVDETAILS 0x21 /* device capabilities, 3 bytes */
131
#define MCE_RSP_EQEMVER 0x22 /* emulator interface ver, 3 bytes */
132
#define MCE_RSP_FLASHLED 0x23 /* success flashing LED, 2 bytes */
134
/* Responses to error cases, must send MCE_CMD_RESUME to clear them */
135
#define MCE_RSP_CMD_ILLEGAL 0xfe /* illegal command for port, 2 bytes */
136
#define MCE_RSP_TX_TIMEOUT 0x81 /* tx timed out, 2 bytes */
138
/* Misc commands/responses not defined in the MCE remote/transceiver spec */
76
139
#define MCE_CMD_SIG_END 0x01 /* End of signal */
77
140
#define MCE_CMD_PING 0x03 /* Ping device */
78
141
#define MCE_CMD_UNKNOWN 0x04 /* Unknown */
79
142
#define MCE_CMD_UNKNOWN2 0x05 /* Unknown */
80
#define MCE_CMD_S_CARRIER 0x06 /* Set TX carrier frequency */
81
#define MCE_CMD_G_CARRIER 0x07 /* Get TX carrier frequency */
82
#define MCE_CMD_S_TXMASK 0x08 /* Set TX port bitmask */
83
143
#define MCE_CMD_UNKNOWN3 0x09 /* Unknown */
84
144
#define MCE_CMD_UNKNOWN4 0x0a /* Unknown */
85
145
#define MCE_CMD_G_REVISION 0x0b /* Get hw/sw revision */
86
#define MCE_CMD_S_TIMEOUT 0x0c /* Set RX timeout value */
87
#define MCE_CMD_G_TIMEOUT 0x0d /* Get RX timeout value */
88
146
#define MCE_CMD_UNKNOWN5 0x0e /* Unknown */
89
147
#define MCE_CMD_UNKNOWN6 0x0f /* Unknown */
90
#define MCE_CMD_G_RXPORTSTS 0x11 /* Get RX port status */
91
#define MCE_CMD_G_TXMASK 0x13 /* Set TX port bitmask */
92
#define MCE_CMD_S_RXSENSOR 0x14 /* Set RX sensor (std/learning) */
93
#define MCE_CMD_G_RXSENSOR 0x15 /* Get RX sensor (std/learning) */
94
#define MCE_RSP_PULSE_COUNT 0x15 /* RX pulse count (only if learning) */
95
#define MCE_CMD_TX_PORTS 0x16 /* Get number of TX ports */
96
#define MCE_CMD_G_WAKESRC 0x17 /* Get wake source */
97
#define MCE_CMD_UNKNOWN7 0x18 /* Unknown */
98
148
#define MCE_CMD_UNKNOWN8 0x19 /* Unknown */
99
149
#define MCE_CMD_UNKNOWN9 0x1b /* Unknown */
100
#define MCE_CMD_DEVICE_RESET 0xaa /* Reset the hardware */
101
#define MCE_RSP_CMD_INVALID 0xfe /* Invalid command issued */
150
#define MCE_CMD_NULL 0x00 /* These show up various places... */
152
/* if buf[i] & MCE_PORT_MASK == 0x80 and buf[i] != MCE_CMD_PORT_IR,
153
* then we're looking at a raw IR data sample */
154
#define MCE_COMMAND_IRDATA 0x80
155
#define MCE_PACKET_LENGTH_MASK 0x1f /* Packet length mask */
104
157
/* module parameters */
105
158
#ifdef CONFIG_USB_DEBUG
390
443
enum mceusb_model_type model;
445
bool need_reset; /* flag to issue a device resume cmd */
446
u8 emver; /* emulator interface version */
447
u8 num_txports; /* number of transmit ports */
448
u8 num_rxports; /* number of receive sensors */
449
u8 txports_cabled; /* bitmask of transmitters with cable */
450
u8 rxports_active; /* bitmask of active receive sensors */
394
* MCE Device Command Strings
395
* Device command responses vary from device to device...
396
* - DEVICE_RESET resets the hardware to its default state
397
* - GET_REVISION fetches the hardware/software revision, common
398
* replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
399
* - GET_CARRIER_FREQ gets the carrier mode and frequency of the
400
* device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
401
* meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
402
* ((clk / frequency) - 1)
403
* - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
404
* response in the form of 9f 0c msb lsb
405
* - GET_TX_BITMASK fetches the transmitter bitmask, replies in
406
* the form of 9f 08 bm, where bm is the bitmask
407
* - GET_RX_SENSOR fetches the RX sensor setting -- long-range
408
* general use one or short-range learning one, in the form of
409
* 9f 14 ss, where ss is either 01 for long-range or 02 for short
410
* - SET_CARRIER_FREQ sets a new carrier mode and frequency
411
* - SET_TX_BITMASK sets the transmitter bitmask
412
* - SET_RX_TIMEOUT sets the receiver timeout
413
* - SET_RX_SENSOR sets which receiver sensor to use
415
static char DEVICE_RESET[] = {MCE_COMMAND_NULL, MCE_HW_CMD_HEADER,
416
MCE_CMD_DEVICE_RESET};
417
static char GET_REVISION[] = {MCE_HW_CMD_HEADER, MCE_CMD_G_REVISION};
418
static char GET_UNKNOWN[] = {MCE_HW_CMD_HEADER, MCE_CMD_UNKNOWN7};
419
static char GET_UNKNOWN2[] = {MCE_COMMAND_HEADER, MCE_CMD_UNKNOWN2};
420
static char GET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER, MCE_CMD_G_CARRIER};
421
static char GET_RX_TIMEOUT[] = {MCE_COMMAND_HEADER, MCE_CMD_G_TIMEOUT};
422
static char GET_TX_BITMASK[] = {MCE_COMMAND_HEADER, MCE_CMD_G_TXMASK};
423
static char GET_RX_SENSOR[] = {MCE_COMMAND_HEADER, MCE_CMD_G_RXSENSOR};
453
/* MCE Device Command Strings, generally a port and command pair */
454
static char DEVICE_RESUME[] = {MCE_CMD_NULL, MCE_CMD_PORT_SYS,
456
static char GET_REVISION[] = {MCE_CMD_PORT_SYS, MCE_CMD_G_REVISION};
457
static char GET_EMVER[] = {MCE_CMD_PORT_SYS, MCE_CMD_GETEMVER};
458
static char GET_WAKEVERSION[] = {MCE_CMD_PORT_SYS, MCE_CMD_GETWAKEVERSION};
459
static char FLASH_LED[] = {MCE_CMD_PORT_SYS, MCE_CMD_FLASHLED};
460
static char GET_UNKNOWN2[] = {MCE_CMD_PORT_IR, MCE_CMD_UNKNOWN2};
461
static char GET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRCFS};
462
static char GET_RX_TIMEOUT[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTIMEOUT};
463
static char GET_NUM_PORTS[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRNUMPORTS};
464
static char GET_TX_BITMASK[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRTXPORTS};
465
static char GET_RX_SENSOR[] = {MCE_CMD_PORT_IR, MCE_CMD_GETIRRXPORTEN};
424
466
/* sub in desired values in lower byte or bytes for full command */
425
467
/* FIXME: make use of these for transmit.
426
static char SET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER,
427
MCE_CMD_S_CARRIER, 0x00, 0x00};
428
static char SET_TX_BITMASK[] = {MCE_COMMAND_HEADER, MCE_CMD_S_TXMASK, 0x00};
429
static char SET_RX_TIMEOUT[] = {MCE_COMMAND_HEADER,
430
MCE_CMD_S_TIMEOUT, 0x00, 0x00};
431
static char SET_RX_SENSOR[] = {MCE_COMMAND_HEADER,
432
MCE_CMD_S_RXSENSOR, 0x00};
468
static char SET_CARRIER_FREQ[] = {MCE_CMD_PORT_IR,
469
MCE_CMD_SETIRCFS, 0x00, 0x00};
470
static char SET_TX_BITMASK[] = {MCE_CMD_PORT_IR, MCE_CMD_SETIRTXPORTS, 0x00};
471
static char SET_RX_TIMEOUT[] = {MCE_CMD_PORT_IR,
472
MCE_CMD_SETIRTIMEOUT, 0x00, 0x00};
473
static char SET_RX_SENSOR[] = {MCE_CMD_PORT_IR,
474
MCE_RSP_EQIRRXPORTEN, 0x00};
435
477
static int mceusb_cmdsize(u8 cmd, u8 subcmd)
520
579
"0x%02x 0x%02x\n", data1, data2,
521
580
buf[start + 4], buf[start + 5]);
523
case MCE_CMD_DEVICE_RESET:
524
dev_info(dev, "Device reset requested\n");
526
case MCE_RSP_CMD_INVALID:
527
dev_info(dev, "Previous command not supported\n");
529
case MCE_CMD_UNKNOWN7:
530
case MCE_CMD_UNKNOWN9:
583
dev_info(dev, "Device resume requested\n");
585
case MCE_RSP_CMD_ILLEGAL:
586
dev_info(dev, "Illegal PORT_SYS command\n");
588
case MCE_RSP_EQWAKEVERSION:
590
dev_info(dev, "Wake version, proto: 0x%02x, "
591
"payload: 0x%02x, address: 0x%02x, "
593
data1, data2, data3, data4);
595
case MCE_RSP_GETPORTSTATUS:
597
/* We use data1 + 1 here, to match hw labels */
598
dev_info(dev, "TX port %d: blaster is%s connected\n",
599
data1 + 1, data4 ? " not" : "");
601
case MCE_CMD_FLASHLED:
602
dev_info(dev, "Attempting to flash LED\n");
532
605
dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
537
case MCE_COMMAND_HEADER:
610
case MCE_CMD_PORT_IR:
538
611
switch (subcmd) {
539
612
case MCE_CMD_SIG_END:
540
613
dev_info(dev, "End of signal\n");
546
619
dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n",
549
case MCE_CMD_S_CARRIER:
550
dev_info(dev, "%s carrier mode and freq of "
551
"0x%02x 0x%02x\n", inout, data1, data2);
622
case MCE_RSP_EQIRCFS:
623
period = DIV_ROUND_CLOSEST(
624
(1 << data1 * 2) * (data2 + 1), 10);
627
carrier = (1000 * 1000) / period;
628
dev_info(dev, "%s carrier of %u Hz (period %uus)\n",
629
inout, carrier, period);
553
case MCE_CMD_G_CARRIER:
631
case MCE_CMD_GETIRCFS:
554
632
dev_info(dev, "Get carrier mode and freq\n");
556
case MCE_CMD_S_TXMASK:
634
case MCE_RSP_EQIRTXPORTS:
557
635
dev_info(dev, "%s transmit blaster mask of 0x%02x\n",
560
case MCE_CMD_S_TIMEOUT:
638
case MCE_RSP_EQIRTIMEOUT:
561
639
/* value is in units of 50us, so x*50/1000 ms */
640
period = ((data1 << 8) | data2) * MCE_TIME_UNIT / 1000;
562
641
dev_info(dev, "%s receive timeout of %d ms\n",
564
((data1 << 8) | data2) * MCE_TIME_UNIT / 1000);
566
case MCE_CMD_G_TIMEOUT:
644
case MCE_CMD_GETIRTIMEOUT:
567
645
dev_info(dev, "Get receive timeout\n");
569
case MCE_CMD_G_TXMASK:
647
case MCE_CMD_GETIRTXPORTS:
570
648
dev_info(dev, "Get transmit blaster mask\n");
572
case MCE_CMD_S_RXSENSOR:
650
case MCE_RSP_EQIRRXPORTEN:
573
651
dev_info(dev, "%s %s-range receive sensor in use\n",
574
652
inout, data1 == 0x02 ? "short" : "long");
576
case MCE_CMD_G_RXSENSOR:
577
/* aka MCE_RSP_PULSE_COUNT */
654
case MCE_CMD_GETIRRXPORTEN:
655
/* aka MCE_RSP_EQIRRXCFCNT */
579
657
dev_info(dev, "Get receive sensor\n");
580
658
else if (ir->learning_enabled)
581
659
dev_info(dev, "RX pulse count: %d\n",
582
660
((data1 << 8) | data2));
584
case MCE_RSP_CMD_INVALID:
585
dev_info(dev, "Error! Hardware is likely wedged...\n");
587
case MCE_CMD_UNKNOWN2:
588
case MCE_CMD_UNKNOWN3:
589
case MCE_CMD_UNKNOWN5:
662
case MCE_RSP_EQIRNUMPORTS:
665
dev_info(dev, "Num TX ports: %x, num RX ports: %x\n",
668
case MCE_RSP_CMD_ILLEGAL:
669
dev_info(dev, "Illegal PORT_IR command\n");
591
672
dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
1025
1134
static void mceusb_gen2_init(struct mceusb_dev *ir)
1028
mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
1137
mce_async_out(ir, DEVICE_RESUME, sizeof(DEVICE_RESUME));
1030
1139
/* get hw/sw revision? */
1031
1140
mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
1033
/* unknown what the next two actually return... */
1034
mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN));
1142
/* get wake version (protocol, key, address) */
1143
mce_async_out(ir, GET_WAKEVERSION, sizeof(GET_WAKEVERSION));
1145
/* unknown what this one actually returns... */
1035
1146
mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2));
1038
1149
static void mceusb_get_parameters(struct mceusb_dev *ir)
1152
unsigned char cmdbuf[3] = { MCE_CMD_PORT_SYS,
1153
MCE_CMD_GETPORTSTATUS, 0x00 };
1155
/* defaults, if the hardware doesn't support querying */
1156
ir->num_txports = 2;
1157
ir->num_rxports = 2;
1159
/* get number of tx and rx ports */
1160
mce_async_out(ir, GET_NUM_PORTS, sizeof(GET_NUM_PORTS));
1040
1162
/* get the carrier and frequency */
1041
1163
mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ));
1043
if (!ir->flags.no_tx)
1165
if (ir->num_txports && !ir->flags.no_tx)
1044
1166
/* get the transmitter bitmask */
1045
1167
mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK));
1231
1369
mceusb_get_parameters(ir);
1371
mceusb_flash_led(ir);
1233
1373
if (!ir->flags.no_tx)
1234
1374
mceusb_set_tx_mask(ir->rc, MCE_DEFAULT_TX_MASK);
1236
1376
usb_set_intfdata(intf, ir);
1238
dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name,
1239
dev->bus->busnum, dev->devnum);
1378
/* enable wake via this device */
1379
device_set_wakeup_capable(ir->dev, true);
1380
device_set_wakeup_enable(ir->dev, true);
1382
dev_info(&intf->dev, "Registered %s with mce emulator interface "
1383
"version %x\n", name, ir->emver);
1384
dev_info(&intf->dev, "%x tx ports (0x%x cabled) and "
1385
"%x rx sensors (0x%x active)\n",
1386
ir->num_txports, ir->txports_cabled,
1387
ir->num_rxports, ir->rxports_active);