40 #include <linux/device.h>
41 #include <linux/module.h>
42 #include <linux/slab.h>
48 #define DRIVER_VERSION "1.92"
50 #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \
52 #define DRIVER_NAME "mceusb"
55 #define USB_CTRL_MSG_SZ 2
56 #define MCE_G1_INIT_MSGS 40
59 #define MCE_CMDBUF_SIZE 384
60 #define MCE_TIME_UNIT 50
61 #define MCE_CODE_LENGTH 5
62 #define MCE_PACKET_SIZE 4
63 #define MCE_IRDATA_HEADER 0x84
64 #define MCE_IRDATA_TRAILER 0x80
65 #define MCE_TX_HEADER_LENGTH 3
66 #define MCE_MAX_CHANNELS 2
67 #define MCE_DEFAULT_TX_MASK 0x03
68 #define MCE_PULSE_BIT 0x80
69 #define MCE_PULSE_MASK 0x7f
70 #define MCE_MAX_PULSE_LENGTH 0x7f
85 #define MCE_PORT_IR 0x4
86 #define MCE_PORT_SYS 0x7
87 #define MCE_PORT_SER 0x6
88 #define MCE_PORT_MASK 0xe0
91 #define MCE_CMD_PORT_IR 0x9f
92 #define MCE_CMD_PORT_SYS 0xff
95 #define MCE_CMD_RESET 0xfe
96 #define MCE_CMD_RESUME 0xaa
97 #define MCE_CMD_SETIRCFS 0x06
98 #define MCE_CMD_SETIRTIMEOUT 0x0c
99 #define MCE_CMD_SETIRTXPORTS 0x08
100 #define MCE_CMD_SETIRRXPORTEN 0x14
101 #define MCE_CMD_FLASHLED 0x23
104 #define MCE_CMD_GETIRCFS 0x07
105 #define MCE_CMD_GETIRTIMEOUT 0x0d
106 #define MCE_CMD_GETIRTXPORTS 0x13
107 #define MCE_CMD_GETIRRXPORTEN 0x15
108 #define MCE_CMD_GETPORTSTATUS 0x11
109 #define MCE_CMD_GETIRNUMPORTS 0x16
110 #define MCE_CMD_GETWAKESOURCE 0x17
111 #define MCE_CMD_GETEMVER 0x22
112 #define MCE_CMD_GETDEVDETAILS 0x21
113 #define MCE_CMD_GETWAKESUPPORT 0x20
114 #define MCE_CMD_GETWAKEVERSION 0x18
117 #define MCE_CMD_NOP 0xff
120 #define MCE_RSP_EQIRCFS 0x06
121 #define MCE_RSP_EQIRTIMEOUT 0x0c
122 #define MCE_RSP_GETWAKESOURCE 0x17
123 #define MCE_RSP_EQIRTXPORTS 0x08
124 #define MCE_RSP_EQIRRXPORTEN 0x14
125 #define MCE_RSP_GETPORTSTATUS 0x11
126 #define MCE_RSP_EQIRRXCFCNT 0x15
127 #define MCE_RSP_EQIRNUMPORTS 0x16
128 #define MCE_RSP_EQWAKESUPPORT 0x20
129 #define MCE_RSP_EQWAKEVERSION 0x18
130 #define MCE_RSP_EQDEVDETAILS 0x21
131 #define MCE_RSP_EQEMVER 0x22
132 #define MCE_RSP_FLASHLED 0x23
135 #define MCE_RSP_CMD_ILLEGAL 0xfe
136 #define MCE_RSP_TX_TIMEOUT 0x81
139 #define MCE_CMD_SIG_END 0x01
140 #define MCE_CMD_PING 0x03
141 #define MCE_CMD_UNKNOWN 0x04
142 #define MCE_CMD_UNKNOWN2 0x05
143 #define MCE_CMD_UNKNOWN3 0x09
144 #define MCE_CMD_UNKNOWN4 0x0a
145 #define MCE_CMD_G_REVISION 0x0b
146 #define MCE_CMD_UNKNOWN5 0x0e
147 #define MCE_CMD_UNKNOWN6 0x0f
148 #define MCE_CMD_UNKNOWN8 0x19
149 #define MCE_CMD_UNKNOWN9 0x1b
150 #define MCE_CMD_NULL 0x00
154 #define MCE_COMMAND_IRDATA 0x80
155 #define MCE_PACKET_LENGTH_MASK 0x1f
158 #ifdef CONFIG_USB_DEBUG
159 static bool debug = 1;
164 #define mce_dbg(dev, fmt, ...) \
167 dev_info(dev, fmt, ## __VA_ARGS__); \
171 #define SEND_FLAG_IN_PROGRESS 1
172 #define SEND_FLAG_COMPLETE 2
173 #define RECV_FLAG_IN_PROGRESS 3
174 #define RECV_FLAG_COMPLETE 4
179 #define VENDOR_PHILIPS 0x0471
180 #define VENDOR_SMK 0x0609
181 #define VENDOR_TATUNG 0x1460
182 #define VENDOR_GATEWAY 0x107b
183 #define VENDOR_SHUTTLE 0x1308
184 #define VENDOR_SHUTTLE2 0x051c
185 #define VENDOR_MITSUMI 0x03ee
186 #define VENDOR_TOPSEED 0x1784
187 #define VENDOR_RICAVISION 0x179d
188 #define VENDOR_ITRON 0x195d
189 #define VENDOR_FIC 0x1509
190 #define VENDOR_LG 0x043e
191 #define VENDOR_MICROSOFT 0x045e
192 #define VENDOR_FORMOSA 0x147a
193 #define VENDOR_FINTEK 0x1934
194 #define VENDOR_PINNACLE 0x2304
195 #define VENDOR_ECS 0x1019
196 #define VENDOR_WISTRON 0x0fb8
197 #define VENDOR_COMPRO 0x185b
198 #define VENDOR_NORTHSTAR 0x04eb
199 #define VENDOR_REALTEK 0x0bda
200 #define VENDOR_TIVO 0x105a
201 #define VENDOR_CONEXANT 0x0572
202 #define VENDOR_TWISTEDMELON 0x2596
256 .name =
"Conexant Hybrid TV (cx231xx) MCE IR",
260 .name =
"Conexant Hybrid TV (cx231xx) MCE IR",
537 if (ir->
flags.microsoft_gen1 && !out && !offset)
544 snprintf(codes + i * 3, 4,
"%02x ", buf[i + offset] & 0xff);
546 dev_info(dev,
"%sx data: %s(length=%d)\n",
547 (out ?
"t" :
"r"), codes, len);
550 strcpy(inout,
"Request\0");
554 start = offset +
skip;
555 cmd = buf[
start] & 0xff;
556 subcmd = buf[start + 1] & 0xff;
557 data1 = buf[start + 2] & 0xff;
558 data2 = buf[start + 3] & 0xff;
559 data3 = buf[start + 4] & 0xff;
560 data4 = buf[start + 5] & 0xff;
568 dev_info(dev,
"Device resume requested\n");
570 dev_info(dev,
"Unknown command 0x%02x 0x%02x\n",
577 dev_info(dev,
"Emulator interface version %x\n",
584 dev_info(dev,
"hw/sw rev 0x%02x 0x%02x "
585 "0x%02x 0x%02x\n", data1, data2,
586 buf[start + 4], buf[start + 5]);
589 dev_info(dev,
"Device resume requested\n");
592 dev_info(dev,
"Illegal PORT_SYS command\n");
596 dev_info(dev,
"Wake version, proto: 0x%02x, "
597 "payload: 0x%02x, address: 0x%02x, "
599 data1, data2, data3, data4);
604 dev_info(dev,
"TX port %d: blaster is%s connected\n",
605 data1 + 1, data4 ?
" not" :
"");
608 dev_info(dev,
"Attempting to flash LED\n");
611 dev_info(dev,
"Unknown command 0x%02x 0x%02x\n",
625 dev_info(dev,
"Resp to 9f 05 of 0x%02x 0x%02x\n",
630 (1
U << data1 * 2) * (data2 + 1), 10);
633 carrier = (1000 * 1000) / period;
634 dev_info(dev,
"%s carrier of %u Hz (period %uus)\n",
635 inout, carrier, period);
638 dev_info(dev,
"Get carrier mode and freq\n");
641 dev_info(dev,
"%s transmit blaster mask of 0x%02x\n",
647 dev_info(dev,
"%s receive timeout of %d ms\n",
651 dev_info(dev,
"Get receive timeout\n");
654 dev_info(dev,
"Get transmit blaster mask\n");
657 dev_info(dev,
"%s %s-range receive sensor in use\n",
658 inout, data1 == 0x02 ?
"short" :
"long");
663 dev_info(dev,
"Get receive sensor\n");
665 dev_info(dev,
"RX pulse count: %d\n",
666 ((data1 << 8) | data2));
671 dev_info(dev,
"Num TX ports: %x, num RX ports: %x\n",
675 dev_info(dev,
"Illegal PORT_IR command\n");
678 dev_info(dev,
"Unknown command 0x%02x 0x%02x\n",
688 dev_info(dev,
"End of raw IR data\n");
691 dev_info(dev,
"Raw IR data, %d pulse/space samples\n", ir->
rem);
694 static void mce_async_callback(
struct urb *
urb)
704 len = urb->actual_length;
706 mceusb_dev_printdata(ir, urb->transfer_buffer, 0, len,
true);
710 kfree(urb->transfer_buffer);
715 static void mce_request_packet(
struct mceusb_dev *ir,
unsigned char *
data,
716 int size,
int urb_type)
719 struct urb *async_urb;
721 unsigned char *async_buf;
726 dev_err(dev,
"Error, couldn't allocate urb!\n");
732 dev_err(dev,
"Error, couldn't allocate buf!\n");
738 pipe = usb_sndintpipe(ir->
usbdev,
740 usb_fill_int_urb(async_urb, ir->
usbdev, pipe,
741 async_buf, size, mce_async_callback,
743 memcpy(async_buf, data, size);
751 dev_err(dev,
"Error! Unknown urb type %d\n", urb_type);
755 mce_dbg(dev,
"receive request called (size=%#x)\n", size);
757 async_urb->transfer_buffer_length =
size;
758 async_urb->dev = ir->
usbdev;
762 mce_dbg(dev,
"receive request FAILED! (res=%d)\n", res);
765 mce_dbg(dev,
"receive request complete (res=%d)\n", res);
768 static void mce_async_out(
struct mceusb_dev *ir,
unsigned char *data,
int size)
770 int rsize =
sizeof(DEVICE_RESUME);
774 mce_request_packet(ir, DEVICE_RESUME, rsize,
MCEUSB_TX);
778 mce_request_packet(ir, data, size,
MCEUSB_TX);
782 static void mce_flush_rx_buffer(
struct mceusb_dev *ir,
int size)
788 static int mceusb_tx_ir(
struct rc_dev *dev,
unsigned *txbuf,
unsigned count)
802 cmdbuf[cmdcount++] = ir->
tx_mask;
846 mce_async_out(ir, cmdbuf, cmdcount);
850 return ret ? ret :
count;
858 if (ir->
flags.tx_mask_normal)
868 static int mceusb_set_tx_carrier(
struct rc_dev *dev,
u32 carrier)
872 int prescaler = 0,
divisor = 0;
884 "modulation\n", __func__);
885 mce_async_out(ir, cmdbuf,
sizeof(cmdbuf));
889 for (prescaler = 0; prescaler < 4; ++prescaler) {
893 cmdbuf[2] = prescaler;
896 "carrier\n", __func__, carrier);
899 mce_async_out(ir, cmdbuf,
sizeof(cmdbuf));
921 switch (ir->
buf_in[index]) {
924 if ((ir->
buf_in[index + 4] & 0xff) == 0x00)
956 static void mceusb_process_ir_data(
struct mceusb_dev *ir,
int buf_len)
963 if (ir->
flags.microsoft_gen1)
970 for (; i < buf_len; i++) {
974 mceusb_dev_printdata(ir, ir->
buf_in, i - 1,
976 mceusb_handle_command(ir, i);
981 init_ir_raw_event(&rawir);
986 mce_dbg(ir->
dev,
"Storing %s with duration %d\n",
987 rawir.pulse ?
"pulse" :
"space",
1007 mceusb_dev_printdata(ir, ir->
buf_in,
1008 i, ir->
rem + 1,
false);
1012 ir_raw_event_reset(ir->
rc);
1020 mce_dbg(ir->
dev,
"processed IR data, calling ir_raw_event_handle\n");
1025 static void mceusb_dev_recv(
struct urb *urb)
1039 buf_len = urb->actual_length;
1043 mce_dbg(ir->
dev,
"setup answer received %d bytes\n",
1047 switch (urb->status) {
1050 mceusb_process_ir_data(ir, buf_len);
1061 mce_dbg(ir->
dev,
"Error: urb status = %d\n", urb->status);
1068 static void mceusb_get_emulator_version(
struct mceusb_dev *ir)
1072 mce_async_out(ir, GET_EMVER,
sizeof(GET_EMVER));
1075 static void mceusb_gen1_init(
struct mceusb_dev *ir)
1083 dev_err(dev,
"%s: memory allocation failed!\n", __func__);
1094 mce_dbg(dev,
"%s - ret = %d\n", __func__, ret);
1095 mce_dbg(dev,
"%s - data[0] = %d, data[1] = %d\n",
1096 __func__, data[0], data[1]);
1101 0xc04e, 0x0000,
NULL, 0,
HZ * 3);
1103 mce_dbg(dev,
"%s - ret = %d\n", __func__, ret);
1108 0x0808, 0x0000,
NULL, 0,
HZ * 3);
1109 mce_dbg(dev,
"%s - retB = %d\n", __func__, ret);
1114 0x0000, 0x0100,
NULL, 0,
HZ * 3);
1115 mce_dbg(dev,
"%s - retC = %d\n", __func__, ret);
1118 mce_async_out(ir, DEVICE_RESUME,
sizeof(DEVICE_RESUME));
1121 mce_async_out(ir, GET_REVISION,
sizeof(GET_REVISION));
1126 static void mceusb_gen2_init(
struct mceusb_dev *ir)
1129 mce_async_out(ir, DEVICE_RESUME,
sizeof(DEVICE_RESUME));
1132 mce_async_out(ir, GET_REVISION,
sizeof(GET_REVISION));
1135 mce_async_out(ir, GET_WAKEVERSION,
sizeof(GET_WAKEVERSION));
1138 mce_async_out(ir, GET_UNKNOWN2,
sizeof(GET_UNKNOWN2));
1141 static void mceusb_get_parameters(
struct mceusb_dev *ir)
1152 mce_async_out(ir, GET_NUM_PORTS,
sizeof(GET_NUM_PORTS));
1155 mce_async_out(ir, GET_CARRIER_FREQ,
sizeof(GET_CARRIER_FREQ));
1159 mce_async_out(ir, GET_TX_BITMASK,
sizeof(GET_TX_BITMASK));
1162 mce_async_out(ir, GET_RX_TIMEOUT,
sizeof(GET_RX_TIMEOUT));
1165 mce_async_out(ir, GET_RX_SENSOR,
sizeof(GET_RX_SENSOR));
1169 mce_async_out(ir, cmdbuf,
sizeof(cmdbuf));
1173 static void mceusb_flash_led(
struct mceusb_dev *ir)
1178 mce_async_out(ir, FLASH_LED,
sizeof(FLASH_LED));
1189 dev_err(dev,
"remote dev allocation failed\n");
1196 "Media Center Ed. eHome Infrared Remote Transceiver",
1210 if (!ir->
flags.no_tx) {
1213 rc->
tx_ir = mceusb_tx_ir;
1221 dev_err(dev,
"remote dev registration failed\n");
1235 struct usb_device *dev = interface_to_usbdev(intf);
1236 struct usb_host_interface *idesc;
1242 char buf[63],
name[128] =
"";
1245 bool is_microsoft_gen1;
1249 mce_dbg(&intf->dev,
"%s called\n", __func__);
1251 idesc = intf->cur_altsetting;
1259 if (idesc->desc.bInterfaceNumber != ir_intfnum)
1263 for (i = 0; i < idesc->desc.bNumEndpoints; ++
i) {
1264 ep = &idesc->endpoint[
i].desc;
1277 mce_dbg(&intf->dev,
"acceptable inbound endpoint "
1281 if ((ep_out ==
NULL)
1292 mce_dbg(&intf->dev,
"acceptable outbound endpoint "
1296 if (ep_in ==
NULL) {
1297 mce_dbg(&intf->dev,
"inbound and/or endpoint not found\n");
1302 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
1306 goto mem_alloc_fail;
1310 goto buf_in_alloc_fail;
1314 goto urb_in_alloc_fail;
1317 ir->
dev = &intf->dev;
1319 ir->
flags.microsoft_gen1 = is_microsoft_gen1;
1327 if (dev->descriptor.iManufacturer
1328 &&
usb_string(dev, dev->descriptor.iManufacturer,
1329 buf,
sizeof(buf)) > 0)
1330 strlcpy(name, buf,
sizeof(name));
1331 if (dev->descriptor.iProduct
1333 buf,
sizeof(buf)) > 0)
1337 ir->
rc = mceusb_init_rc_dev(ir);
1342 usb_fill_int_urb(ir->
urb_in, dev, pipe, ir->
buf_in, maxp,
1345 ir->
urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1348 mce_dbg(&intf->dev,
"Flushing receive buffers\n");
1349 mce_flush_rx_buffer(ir, maxp);
1352 mceusb_get_emulator_version(ir);
1355 if (ir->
flags.microsoft_gen1)
1356 mceusb_gen1_init(ir);
1358 mceusb_gen2_init(ir);
1360 mceusb_get_parameters(ir);
1362 mceusb_flash_led(ir);
1364 if (!ir->
flags.no_tx)
1367 usb_set_intfdata(intf, ir);
1373 dev_info(&intf->dev,
"Registered %s with mce emulator interface "
1374 "version %x\n", name, ir->
emver);
1375 dev_info(&intf->dev,
"%x tx ports (0x%x cabled) and "
1376 "%x rx sensors (0x%x active)\n",
1390 dev_err(&intf->dev,
"%s: device setup failed!\n", __func__);
1398 struct usb_device *dev = interface_to_usbdev(intf);
1399 struct mceusb_dev *ir = usb_get_intfdata(intf);
1401 usb_set_intfdata(intf,
NULL);
1417 struct mceusb_dev *ir = usb_get_intfdata(intf);
1425 struct mceusb_dev *ir = usb_get_intfdata(intf);
1432 static struct usb_driver mceusb_dev_driver = {
1434 .probe = mceusb_dev_probe,
1436 .suspend = mceusb_dev_suspend,
1437 .resume = mceusb_dev_resume,
1438 .reset_resume = mceusb_dev_resume,
1439 .id_table = mceusb_dev_table