2 * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers
4 * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
6 * Based on the original lirc_mceusb and lirc_mceusb2 drivers, by Dan
7 * Conti, Martin Blatter and Daniel Melander, the latter of which was
8 * in turn also based on the lirc_atiusb driver by Paul Miller. The
9 * two mce drivers were merged into one by Jarod Wilson, with transmit
10 * support for the 1st-gen device added primarily by Patrick Calhoun,
11 * with a bit of tweaks by Jarod. Debugging improvements and proper
12 * support for what appears to be 3rd-gen hardware added by Jarod.
13 * Initial port from lirc driver to ir-core drivery by Jarod, based
14 * partially on a port to an earlier proposed IR infrastructure by
15 * Jon Smirl, which included enhancements and simplifications to the
16 * incoming IR buffer parsing routines.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #include <linux/device.h>
36 #include <linux/module.h>
37 #include <linux/slab.h>
38 #include <linux/usb.h>
39 #include <linux/usb/input.h>
40 #include <media/rc-core.h>
42 #define DRIVER_VERSION "1.91"
43 #define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
44 #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \
46 #define DRIVER_NAME "mceusb"
48 #define USB_BUFLEN 32 /* USB reception buffer length */
49 #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */
50 #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */
53 #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */
54 #define MCE_TIME_UNIT 50 /* Approx 50us resolution */
55 #define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */
56 #define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */
57 #define MCE_IRDATA_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */
58 #define MCE_IRDATA_TRAILER 0x80 /* End of IR data */
59 #define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */
60 #define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */
61 #define MCE_DEFAULT_TX_MASK 0x03 /* Vals: TX1=0x01, TX2=0x02, ALL=0x03 */
62 #define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */
63 #define MCE_PULSE_MASK 0x7f /* Pulse mask */
64 #define MCE_MAX_PULSE_LENGTH 0x7f /* Longest transmittable pulse symbol */
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 */
76 #define MCE_CMD_SIG_END 0x01 /* End of signal */
77 #define MCE_CMD_PING 0x03 /* Ping device */
78 #define MCE_CMD_UNKNOWN 0x04 /* Unknown */
79 #define MCE_CMD_UNKNOWN2 0x05 /* Unknown */
80 #define MCE_CMD_S_CARRIER 0x06 /* Set TX carrier frequency */
81 #define MCE_CMD_G_CARRIER 0x07 /* Get TX carrier frequency */
82 #define MCE_CMD_S_TXMASK 0x08 /* Set TX port bitmask */
83 #define MCE_CMD_UNKNOWN3 0x09 /* Unknown */
84 #define MCE_CMD_UNKNOWN4 0x0a /* Unknown */
85 #define MCE_CMD_G_REVISION 0x0b /* Get hw/sw revision */
86 #define MCE_CMD_S_TIMEOUT 0x0c /* Set RX timeout value */
87 #define MCE_CMD_G_TIMEOUT 0x0d /* Get RX timeout value */
88 #define MCE_CMD_UNKNOWN5 0x0e /* Unknown */
89 #define MCE_CMD_UNKNOWN6 0x0f /* Unknown */
90 #define MCE_CMD_G_RXPORTSTS 0x11 /* Get RX port status */
91 #define MCE_CMD_G_TXMASK 0x13 /* Set TX port bitmask */
92 #define MCE_CMD_S_RXSENSOR 0x14 /* Set RX sensor (std/learning) */
93 #define MCE_CMD_G_RXSENSOR 0x15 /* Get RX sensor (std/learning) */
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 #define MCE_CMD_UNKNOWN8 0x19 /* Unknown */
99 #define MCE_CMD_UNKNOWN9 0x1b /* Unknown */
100 #define MCE_CMD_DEVICE_RESET 0xaa /* Reset the hardware */
101 #define MCE_RSP_CMD_INVALID 0xfe /* Invalid command issued */
104 /* module parameters */
105 #ifdef CONFIG_USB_DEBUG
106 static int debug
= 1;
111 #define mce_dbg(dev, fmt, ...) \
114 dev_info(dev, fmt, ## __VA_ARGS__); \
117 /* general constants */
118 #define SEND_FLAG_IN_PROGRESS 1
119 #define SEND_FLAG_COMPLETE 2
120 #define RECV_FLAG_IN_PROGRESS 3
121 #define RECV_FLAG_COMPLETE 4
126 #define VENDOR_PHILIPS 0x0471
127 #define VENDOR_SMK 0x0609
128 #define VENDOR_TATUNG 0x1460
129 #define VENDOR_GATEWAY 0x107b
130 #define VENDOR_SHUTTLE 0x1308
131 #define VENDOR_SHUTTLE2 0x051c
132 #define VENDOR_MITSUMI 0x03ee
133 #define VENDOR_TOPSEED 0x1784
134 #define VENDOR_RICAVISION 0x179d
135 #define VENDOR_ITRON 0x195d
136 #define VENDOR_FIC 0x1509
137 #define VENDOR_LG 0x043e
138 #define VENDOR_MICROSOFT 0x045e
139 #define VENDOR_FORMOSA 0x147a
140 #define VENDOR_FINTEK 0x1934
141 #define VENDOR_PINNACLE 0x2304
142 #define VENDOR_ECS 0x1019
143 #define VENDOR_WISTRON 0x0fb8
144 #define VENDOR_COMPRO 0x185b
145 #define VENDOR_NORTHSTAR 0x04eb
146 #define VENDOR_REALTEK 0x0bda
147 #define VENDOR_TIVO 0x105a
148 #define VENDOR_CONEXANT 0x0572
150 enum mceusb_model_type
{
151 MCE_GEN2
= 0, /* Most boards */
162 struct mceusb_model
{
166 u32 tx_mask_normal
:1;
171 const char *rc_map
; /* Allow specify a per-board map */
172 const char *name
; /* per-board name */
175 static const struct mceusb_model mceusb_model
[] = {
187 [MCE_GEN2_TX_INV
] = {
197 * In fact, the EVK is shipped without
198 * remotes, but we should have something handy,
199 * to allow testing it
201 .rc_map
= RC_MAP_HAUPPAUGE
,
202 .name
= "Conexant Hybrid TV (cx231xx) MCE IR",
205 .no_tx
= 1, /* tx isn't wired up at all */
206 .name
= "Conexant Hybrid TV (cx231xx) MCE IR",
214 .rc_map
= RC_MAP_TIVO
,
218 static struct usb_device_id mceusb_dev_table
[] = {
219 /* Original Microsoft MCE IR Transceiver (often HP-branded) */
220 { USB_DEVICE(VENDOR_MICROSOFT
, 0x006d),
221 .driver_info
= MCE_GEN1
},
222 /* Philips Infrared Transceiver - Sahara branded */
223 { USB_DEVICE(VENDOR_PHILIPS
, 0x0608) },
224 /* Philips Infrared Transceiver - HP branded */
225 { USB_DEVICE(VENDOR_PHILIPS
, 0x060c),
226 .driver_info
= MCE_GEN2_TX_INV
},
227 /* Philips SRM5100 */
228 { USB_DEVICE(VENDOR_PHILIPS
, 0x060d) },
229 /* Philips Infrared Transceiver - Omaura */
230 { USB_DEVICE(VENDOR_PHILIPS
, 0x060f) },
231 /* Philips Infrared Transceiver - Spinel plus */
232 { USB_DEVICE(VENDOR_PHILIPS
, 0x0613) },
233 /* Philips eHome Infrared Transceiver */
234 { USB_DEVICE(VENDOR_PHILIPS
, 0x0815) },
235 /* Philips/Spinel plus IR transceiver for ASUS */
236 { USB_DEVICE(VENDOR_PHILIPS
, 0x206c) },
237 /* Philips/Spinel plus IR transceiver for ASUS */
238 { USB_DEVICE(VENDOR_PHILIPS
, 0x2088) },
239 /* Philips IR transceiver (Dell branded) */
240 { USB_DEVICE(VENDOR_PHILIPS
, 0x2093) },
241 /* Realtek MCE IR Receiver and card reader */
242 { USB_DEVICE(VENDOR_REALTEK
, 0x0161),
243 .driver_info
= MULTIFUNCTION
},
244 /* SMK/Toshiba G83C0004D410 */
245 { USB_DEVICE(VENDOR_SMK
, 0x031d),
246 .driver_info
= MCE_GEN2_TX_INV
},
247 /* SMK eHome Infrared Transceiver (Sony VAIO) */
248 { USB_DEVICE(VENDOR_SMK
, 0x0322),
249 .driver_info
= MCE_GEN2_TX_INV
},
250 /* bundled with Hauppauge PVR-150 */
251 { USB_DEVICE(VENDOR_SMK
, 0x0334),
252 .driver_info
= MCE_GEN2_TX_INV
},
253 /* SMK eHome Infrared Transceiver */
254 { USB_DEVICE(VENDOR_SMK
, 0x0338) },
255 /* SMK/I-O Data GV-MC7/RCKIT Receiver */
256 { USB_DEVICE(VENDOR_SMK
, 0x0353),
257 .driver_info
= MCE_GEN2_NO_TX
},
258 /* Tatung eHome Infrared Transceiver */
259 { USB_DEVICE(VENDOR_TATUNG
, 0x9150) },
260 /* Shuttle eHome Infrared Transceiver */
261 { USB_DEVICE(VENDOR_SHUTTLE
, 0xc001) },
262 /* Shuttle eHome Infrared Transceiver */
263 { USB_DEVICE(VENDOR_SHUTTLE2
, 0xc001) },
264 /* Gateway eHome Infrared Transceiver */
265 { USB_DEVICE(VENDOR_GATEWAY
, 0x3009) },
267 { USB_DEVICE(VENDOR_MITSUMI
, 0x2501) },
268 /* Topseed eHome Infrared Transceiver */
269 { USB_DEVICE(VENDOR_TOPSEED
, 0x0001),
270 .driver_info
= MCE_GEN2_TX_INV
},
271 /* Topseed HP eHome Infrared Transceiver */
272 { USB_DEVICE(VENDOR_TOPSEED
, 0x0006),
273 .driver_info
= MCE_GEN2_TX_INV
},
274 /* Topseed eHome Infrared Transceiver */
275 { USB_DEVICE(VENDOR_TOPSEED
, 0x0007),
276 .driver_info
= MCE_GEN2_TX_INV
},
277 /* Topseed eHome Infrared Transceiver */
278 { USB_DEVICE(VENDOR_TOPSEED
, 0x0008),
279 .driver_info
= MCE_GEN3
},
280 /* Topseed eHome Infrared Transceiver */
281 { USB_DEVICE(VENDOR_TOPSEED
, 0x000a),
282 .driver_info
= MCE_GEN2_TX_INV
},
283 /* Topseed eHome Infrared Transceiver */
284 { USB_DEVICE(VENDOR_TOPSEED
, 0x0011),
285 .driver_info
= MCE_GEN3
},
286 /* Ricavision internal Infrared Transceiver */
287 { USB_DEVICE(VENDOR_RICAVISION
, 0x0010) },
288 /* Itron ione Libra Q-11 */
289 { USB_DEVICE(VENDOR_ITRON
, 0x7002) },
290 /* FIC eHome Infrared Transceiver */
291 { USB_DEVICE(VENDOR_FIC
, 0x9242) },
292 /* LG eHome Infrared Transceiver */
293 { USB_DEVICE(VENDOR_LG
, 0x9803) },
294 /* Microsoft MCE Infrared Transceiver */
295 { USB_DEVICE(VENDOR_MICROSOFT
, 0x00a0) },
296 /* Formosa eHome Infrared Transceiver */
297 { USB_DEVICE(VENDOR_FORMOSA
, 0xe015) },
298 /* Formosa21 / eHome Infrared Receiver */
299 { USB_DEVICE(VENDOR_FORMOSA
, 0xe016) },
300 /* Formosa aim / Trust MCE Infrared Receiver */
301 { USB_DEVICE(VENDOR_FORMOSA
, 0xe017),
302 .driver_info
= MCE_GEN2_NO_TX
},
303 /* Formosa Industrial Computing / Beanbag Emulation Device */
304 { USB_DEVICE(VENDOR_FORMOSA
, 0xe018) },
305 /* Formosa21 / eHome Infrared Receiver */
306 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03a) },
307 /* Formosa Industrial Computing AIM IR605/A */
308 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03c) },
309 /* Formosa Industrial Computing */
310 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03e) },
311 /* Fintek eHome Infrared Transceiver (HP branded) */
312 { USB_DEVICE(VENDOR_FINTEK
, 0x5168) },
313 /* Fintek eHome Infrared Transceiver */
314 { USB_DEVICE(VENDOR_FINTEK
, 0x0602) },
315 /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
316 { USB_DEVICE(VENDOR_FINTEK
, 0x0702) },
317 /* Pinnacle Remote Kit */
318 { USB_DEVICE(VENDOR_PINNACLE
, 0x0225),
319 .driver_info
= MCE_GEN3
},
320 /* Elitegroup Computer Systems IR */
321 { USB_DEVICE(VENDOR_ECS
, 0x0f38) },
322 /* Wistron Corp. eHome Infrared Receiver */
323 { USB_DEVICE(VENDOR_WISTRON
, 0x0002) },
325 { USB_DEVICE(VENDOR_COMPRO
, 0x3020) },
327 { USB_DEVICE(VENDOR_COMPRO
, 0x3082) },
328 /* Northstar Systems, Inc. eHome Infrared Transceiver */
329 { USB_DEVICE(VENDOR_NORTHSTAR
, 0xe004) },
330 /* TiVo PC IR Receiver */
331 { USB_DEVICE(VENDOR_TIVO
, 0x2000),
332 .driver_info
= TIVO_KIT
},
333 /* Conexant Hybrid TV "Shelby" Polaris SDK */
334 { USB_DEVICE(VENDOR_CONEXANT
, 0x58a1),
335 .driver_info
= POLARIS_EVK
},
336 /* Conexant Hybrid TV RDU253S Polaris */
337 { USB_DEVICE(VENDOR_CONEXANT
, 0x58a5),
338 .driver_info
= CX_HYBRID_TV
},
339 /* Terminating entry */
343 /* data structure for each usb transceiver */
348 /* optional features we can enable */
349 bool carrier_report_enabled
;
350 bool learning_enabled
;
352 /* core device bits */
356 struct usb_device
*usbdev
;
358 struct usb_endpoint_descriptor
*usb_ep_in
;
359 struct usb_endpoint_descriptor
*usb_ep_out
;
361 /* buffers and dma */
362 unsigned char *buf_in
;
374 u8 cmd
, rem
; /* Remaining IR data bytes in packet */
378 u32 tx_mask_normal
:1;
379 u32 microsoft_gen1
:1;
383 /* transmit support */
386 unsigned char tx_mask
;
390 enum mceusb_model_type model
;
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
};
424 /* sub in desired values in lower byte or bytes for full command */
425 /* 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};
435 static int mceusb_cmdsize(u8 cmd
, u8 subcmd
)
440 case MCE_COMMAND_NULL
:
441 if (subcmd
== MCE_HW_CMD_HEADER
)
444 case MCE_HW_CMD_HEADER
:
446 case MCE_CMD_G_REVISION
:
450 case MCE_COMMAND_HEADER
:
452 case MCE_CMD_UNKNOWN
:
453 case MCE_CMD_S_CARRIER
:
454 case MCE_CMD_S_TIMEOUT
:
455 case MCE_RSP_PULSE_COUNT
:
458 case MCE_CMD_SIG_END
:
459 case MCE_CMD_S_TXMASK
:
460 case MCE_CMD_S_RXSENSOR
:
468 static void mceusb_dev_printdata(struct mceusb_dev
*ir
, char *buf
,
469 int offset
, int len
, bool out
)
471 char codes
[USB_BUFLEN
* 3 + 1];
473 u8 cmd
, subcmd
, data1
, data2
;
474 struct device
*dev
= ir
->dev
;
475 int i
, start
, skip
= 0;
480 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
481 if (ir
->flags
.microsoft_gen1
&& !out
&& !offset
)
487 for (i
= 0; i
< len
&& i
< USB_BUFLEN
; i
++)
488 snprintf(codes
+ i
* 3, 4, "%02x ", buf
[i
+ offset
] & 0xff);
490 dev_info(dev
, "%sx data: %s(length=%d)\n",
491 (out
? "t" : "r"), codes
, len
);
494 strcpy(inout
, "Request\0");
496 strcpy(inout
, "Got\0");
498 start
= offset
+ skip
;
499 cmd
= buf
[start
] & 0xff;
500 subcmd
= buf
[start
+ 1] & 0xff;
501 data1
= buf
[start
+ 2] & 0xff;
502 data2
= buf
[start
+ 3] & 0xff;
505 case MCE_COMMAND_NULL
:
506 if ((subcmd
== MCE_HW_CMD_HEADER
) &&
507 (data1
== MCE_CMD_DEVICE_RESET
))
508 dev_info(dev
, "Device reset requested\n");
510 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
513 case MCE_HW_CMD_HEADER
:
515 case MCE_CMD_G_REVISION
:
517 dev_info(dev
, "Get hw/sw rev?\n");
519 dev_info(dev
, "hw/sw rev 0x%02x 0x%02x "
520 "0x%02x 0x%02x\n", data1
, data2
,
521 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
:
532 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
537 case MCE_COMMAND_HEADER
:
539 case MCE_CMD_SIG_END
:
540 dev_info(dev
, "End of signal\n");
543 dev_info(dev
, "Ping\n");
545 case MCE_CMD_UNKNOWN
:
546 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
);
553 case MCE_CMD_G_CARRIER
:
554 dev_info(dev
, "Get carrier mode and freq\n");
556 case MCE_CMD_S_TXMASK
:
557 dev_info(dev
, "%s transmit blaster mask of 0x%02x\n",
560 case MCE_CMD_S_TIMEOUT
:
561 /* value is in units of 50us, so x*50/100 or x/2 ms */
562 dev_info(dev
, "%s receive timeout of %d ms\n",
563 inout
, ((data1
<< 8) | data2
) / 2);
565 case MCE_CMD_G_TIMEOUT
:
566 dev_info(dev
, "Get receive timeout\n");
568 case MCE_CMD_G_TXMASK
:
569 dev_info(dev
, "Get transmit blaster mask\n");
571 case MCE_CMD_S_RXSENSOR
:
572 dev_info(dev
, "%s %s-range receive sensor in use\n",
573 inout
, data1
== 0x02 ? "short" : "long");
575 case MCE_CMD_G_RXSENSOR
:
576 /* aka MCE_RSP_PULSE_COUNT */
578 dev_info(dev
, "Get receive sensor\n");
579 else if (ir
->learning_enabled
)
580 dev_info(dev
, "RX pulse count: %d\n",
581 ((data1
<< 8) | data2
));
583 case MCE_RSP_CMD_INVALID
:
584 dev_info(dev
, "Error! Hardware is likely wedged...\n");
586 case MCE_CMD_UNKNOWN2
:
587 case MCE_CMD_UNKNOWN3
:
588 case MCE_CMD_UNKNOWN5
:
590 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
599 if (cmd
== MCE_IRDATA_TRAILER
)
600 dev_info(dev
, "End of raw IR data\n");
601 else if ((cmd
!= MCE_COMMAND_HEADER
) &&
602 ((cmd
& MCE_COMMAND_MASK
) == MCE_COMMAND_IRDATA
))
603 dev_info(dev
, "Raw IR data, %d pulse/space samples\n", ir
->rem
);
606 static void mce_async_callback(struct urb
*urb
, struct pt_regs
*regs
)
608 struct mceusb_dev
*ir
;
616 len
= urb
->actual_length
;
618 mce_dbg(ir
->dev
, "callback called (status=%d len=%d)\n",
621 mceusb_dev_printdata(ir
, urb
->transfer_buffer
, 0, len
, true);
624 /* the transfer buffer and urb were allocated in mce_request_packet */
625 kfree(urb
->transfer_buffer
);
629 /* request incoming or send outgoing usb packet - used to initialize remote */
630 static void mce_request_packet(struct mceusb_dev
*ir
, unsigned char *data
,
631 int size
, int urb_type
)
634 struct urb
*async_urb
;
635 struct device
*dev
= ir
->dev
;
636 unsigned char *async_buf
;
638 if (urb_type
== MCEUSB_TX
) {
639 async_urb
= usb_alloc_urb(0, GFP_KERNEL
);
640 if (unlikely(!async_urb
)) {
641 dev_err(dev
, "Error, couldn't allocate urb!\n");
645 async_buf
= kzalloc(size
, GFP_KERNEL
);
647 dev_err(dev
, "Error, couldn't allocate buf!\n");
648 usb_free_urb(async_urb
);
653 pipe
= usb_sndintpipe(ir
->usbdev
,
654 ir
->usb_ep_out
->bEndpointAddress
);
655 usb_fill_int_urb(async_urb
, ir
->usbdev
, pipe
,
656 async_buf
, size
, (usb_complete_t
)mce_async_callback
,
657 ir
, ir
->usb_ep_out
->bInterval
);
658 memcpy(async_buf
, data
, size
);
660 } else if (urb_type
== MCEUSB_RX
) {
661 /* standard request */
662 async_urb
= ir
->urb_in
;
663 ir
->send_flags
= RECV_FLAG_IN_PROGRESS
;
666 dev_err(dev
, "Error! Unknown urb type %d\n", urb_type
);
670 mce_dbg(dev
, "receive request called (size=%#x)\n", size
);
672 async_urb
->transfer_buffer_length
= size
;
673 async_urb
->dev
= ir
->usbdev
;
675 res
= usb_submit_urb(async_urb
, GFP_ATOMIC
);
677 mce_dbg(dev
, "receive request FAILED! (res=%d)\n", res
);
680 mce_dbg(dev
, "receive request complete (res=%d)\n", res
);
683 static void mce_async_out(struct mceusb_dev
*ir
, unsigned char *data
, int size
)
685 mce_request_packet(ir
, data
, size
, MCEUSB_TX
);
688 static void mce_flush_rx_buffer(struct mceusb_dev
*ir
, int size
)
690 mce_request_packet(ir
, NULL
, size
, MCEUSB_RX
);
693 /* Send data out the IR blaster port(s) */
694 static int mceusb_tx_ir(struct rc_dev
*dev
, int *txbuf
, u32 n
)
696 struct mceusb_dev
*ir
= dev
->priv
;
698 int count
, cmdcount
= 0;
699 unsigned char *cmdbuf
; /* MCE command buffer */
700 long signal_duration
= 0; /* Singnal length in us */
701 struct timeval start_time
, end_time
;
703 do_gettimeofday(&start_time
);
705 count
= n
/ sizeof(int);
707 cmdbuf
= kzalloc(sizeof(int) * MCE_CMDBUF_SIZE
, GFP_KERNEL
);
711 /* MCE tx init header */
712 cmdbuf
[cmdcount
++] = MCE_COMMAND_HEADER
;
713 cmdbuf
[cmdcount
++] = MCE_CMD_S_TXMASK
;
714 cmdbuf
[cmdcount
++] = ir
->tx_mask
;
716 /* Generate mce packet data */
717 for (i
= 0; (i
< count
) && (cmdcount
< MCE_CMDBUF_SIZE
); i
++) {
718 signal_duration
+= txbuf
[i
];
719 txbuf
[i
] = txbuf
[i
] / MCE_TIME_UNIT
;
721 do { /* loop to support long pulses/spaces > 127*50us=6.35ms */
723 /* Insert mce packet header every 4th entry */
724 if ((cmdcount
< MCE_CMDBUF_SIZE
) &&
725 (cmdcount
- MCE_TX_HEADER_LENGTH
) %
726 MCE_CODE_LENGTH
== 0)
727 cmdbuf
[cmdcount
++] = MCE_IRDATA_HEADER
;
729 /* Insert mce packet data */
730 if (cmdcount
< MCE_CMDBUF_SIZE
)
732 (txbuf
[i
] < MCE_PULSE_BIT
?
733 txbuf
[i
] : MCE_MAX_PULSE_LENGTH
) |
734 (i
& 1 ? 0x00 : MCE_PULSE_BIT
);
740 } while ((txbuf
[i
] > MCE_MAX_PULSE_LENGTH
) &&
741 (txbuf
[i
] -= MCE_MAX_PULSE_LENGTH
));
744 /* Fix packet length in last header */
745 cmdbuf
[cmdcount
- (cmdcount
- MCE_TX_HEADER_LENGTH
) % MCE_CODE_LENGTH
] =
746 MCE_COMMAND_IRDATA
+ (cmdcount
- MCE_TX_HEADER_LENGTH
) %
749 /* Check if we have room for the empty packet at the end */
750 if (cmdcount
>= MCE_CMDBUF_SIZE
) {
755 /* All mce commands end with an empty packet (0x80) */
756 cmdbuf
[cmdcount
++] = MCE_IRDATA_TRAILER
;
758 /* Transmit the command to the mce device */
759 mce_async_out(ir
, cmdbuf
, cmdcount
);
762 * The lircd gap calculation expects the write function to
763 * wait the time it takes for the ircommand to be sent before
766 do_gettimeofday(&end_time
);
767 signal_duration
-= (end_time
.tv_usec
- start_time
.tv_usec
) +
768 (end_time
.tv_sec
- start_time
.tv_sec
) * 1000000;
770 /* delay with the closest number of ticks */
771 set_current_state(TASK_INTERRUPTIBLE
);
772 schedule_timeout(usecs_to_jiffies(signal_duration
));
776 return ret
? ret
: n
;
779 /* Sets active IR outputs -- mce devices typically have two */
780 static int mceusb_set_tx_mask(struct rc_dev
*dev
, u32 mask
)
782 struct mceusb_dev
*ir
= dev
->priv
;
784 if (ir
->flags
.tx_mask_normal
)
787 ir
->tx_mask
= (mask
!= MCE_DEFAULT_TX_MASK
?
788 mask
^ MCE_DEFAULT_TX_MASK
: mask
) << 1;
793 /* Sets the send carrier frequency and mode */
794 static int mceusb_set_tx_carrier(struct rc_dev
*dev
, u32 carrier
)
796 struct mceusb_dev
*ir
= dev
->priv
;
798 int prescaler
= 0, divisor
= 0;
799 unsigned char cmdbuf
[4] = { MCE_COMMAND_HEADER
,
800 MCE_CMD_S_CARRIER
, 0x00, 0x00 };
802 /* Carrier has changed */
803 if (ir
->carrier
!= carrier
) {
806 ir
->carrier
= carrier
;
807 cmdbuf
[2] = MCE_CMD_SIG_END
;
808 cmdbuf
[3] = MCE_IRDATA_TRAILER
;
809 mce_dbg(ir
->dev
, "%s: disabling carrier "
810 "modulation\n", __func__
);
811 mce_async_out(ir
, cmdbuf
, sizeof(cmdbuf
));
815 for (prescaler
= 0; prescaler
< 4; ++prescaler
) {
816 divisor
= (clk
>> (2 * prescaler
)) / carrier
;
817 if (divisor
<= 0xff) {
818 ir
->carrier
= carrier
;
819 cmdbuf
[2] = prescaler
;
821 mce_dbg(ir
->dev
, "%s: requesting %u HZ "
822 "carrier\n", __func__
, carrier
);
824 /* Transmit new carrier to mce device */
825 mce_async_out(ir
, cmdbuf
, sizeof(cmdbuf
));
838 * We don't do anything but print debug spew for many of the command bits
839 * we receive from the hardware, but some of them are useful information
840 * we want to store so that we can use them.
842 static void mceusb_handle_command(struct mceusb_dev
*ir
, int index
)
844 u8 hi
= ir
->buf_in
[index
+ 1] & 0xff;
845 u8 lo
= ir
->buf_in
[index
+ 2] & 0xff;
847 switch (ir
->buf_in
[index
]) {
848 /* 2-byte return value commands */
849 case MCE_CMD_S_TIMEOUT
:
850 ir
->rc
->timeout
= US_TO_NS((hi
<< 8 | lo
) / 2);
853 /* 1-byte return value commands */
854 case MCE_CMD_S_TXMASK
:
857 case MCE_CMD_S_RXSENSOR
:
858 ir
->learning_enabled
= (hi
== 0x02);
865 static void mceusb_process_ir_data(struct mceusb_dev
*ir
, int buf_len
)
867 DEFINE_IR_RAW_EVENT(rawir
);
870 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
871 if (ir
->flags
.microsoft_gen1
)
874 /* if there's no data, just return now */
878 for (; i
< buf_len
; i
++) {
879 switch (ir
->parser_state
) {
881 ir
->rem
= mceusb_cmdsize(ir
->cmd
, ir
->buf_in
[i
]);
882 mceusb_dev_printdata(ir
, ir
->buf_in
, i
- 1,
884 mceusb_handle_command(ir
, i
);
885 ir
->parser_state
= CMD_DATA
;
889 init_ir_raw_event(&rawir
);
890 rawir
.pulse
= ((ir
->buf_in
[i
] & MCE_PULSE_BIT
) != 0);
891 rawir
.duration
= (ir
->buf_in
[i
] & MCE_PULSE_MASK
)
892 * US_TO_NS(MCE_TIME_UNIT
);
894 mce_dbg(ir
->dev
, "Storing %s with duration %d\n",
895 rawir
.pulse
? "pulse" : "space",
898 ir_raw_event_store_with_filter(ir
->rc
, &rawir
);
904 /* decode mce packets of the form (84),AA,BB,CC,DD */
905 /* IR data packets can span USB messages - rem */
906 ir
->cmd
= ir
->buf_in
[i
];
907 if ((ir
->cmd
== MCE_COMMAND_HEADER
) ||
908 ((ir
->cmd
& MCE_COMMAND_MASK
) !=
909 MCE_COMMAND_IRDATA
)) {
910 ir
->parser_state
= SUBCMD
;
913 ir
->rem
= (ir
->cmd
& MCE_PACKET_LENGTH_MASK
);
914 mceusb_dev_printdata(ir
, ir
->buf_in
,
915 i
, ir
->rem
+ 1, false);
917 ir
->parser_state
= PARSE_IRDATA
;
919 ir_raw_event_reset(ir
->rc
);
923 if (ir
->parser_state
!= CMD_HEADER
&& !ir
->rem
)
924 ir
->parser_state
= CMD_HEADER
;
926 mce_dbg(ir
->dev
, "processed IR data, calling ir_raw_event_handle\n");
927 ir_raw_event_handle(ir
->rc
);
930 static void mceusb_dev_recv(struct urb
*urb
, struct pt_regs
*regs
)
932 struct mceusb_dev
*ir
;
944 buf_len
= urb
->actual_length
;
946 if (ir
->send_flags
== RECV_FLAG_IN_PROGRESS
) {
947 ir
->send_flags
= SEND_FLAG_COMPLETE
;
948 mce_dbg(ir
->dev
, "setup answer received %d bytes\n",
952 switch (urb
->status
) {
955 mceusb_process_ir_data(ir
, buf_len
);
966 mce_dbg(ir
->dev
, "Error: urb status = %d\n", urb
->status
);
970 usb_submit_urb(urb
, GFP_ATOMIC
);
973 static void mceusb_gen1_init(struct mceusb_dev
*ir
)
976 struct device
*dev
= ir
->dev
;
979 data
= kzalloc(USB_CTRL_MSG_SZ
, GFP_KERNEL
);
981 dev_err(dev
, "%s: memory allocation failed!\n", __func__
);
986 * This is a strange one. Windows issues a set address to the device
987 * on the receive control pipe and expect a certain value pair back
989 ret
= usb_control_msg(ir
->usbdev
, usb_rcvctrlpipe(ir
->usbdev
, 0),
990 USB_REQ_SET_ADDRESS
, USB_TYPE_VENDOR
, 0, 0,
991 data
, USB_CTRL_MSG_SZ
, HZ
* 3);
992 mce_dbg(dev
, "%s - ret = %d\n", __func__
, ret
);
993 mce_dbg(dev
, "%s - data[0] = %d, data[1] = %d\n",
994 __func__
, data
[0], data
[1]);
996 /* set feature: bit rate 38400 bps */
997 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
998 USB_REQ_SET_FEATURE
, USB_TYPE_VENDOR
,
999 0xc04e, 0x0000, NULL
, 0, HZ
* 3);
1001 mce_dbg(dev
, "%s - ret = %d\n", __func__
, ret
);
1003 /* bRequest 4: set char length to 8 bits */
1004 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
1006 0x0808, 0x0000, NULL
, 0, HZ
* 3);
1007 mce_dbg(dev
, "%s - retB = %d\n", __func__
, ret
);
1009 /* bRequest 2: set handshaking to use DTR/DSR */
1010 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
1012 0x0000, 0x0100, NULL
, 0, HZ
* 3);
1013 mce_dbg(dev
, "%s - retC = %d\n", __func__
, ret
);
1016 mce_async_out(ir
, DEVICE_RESET
, sizeof(DEVICE_RESET
));
1018 /* get hw/sw revision? */
1019 mce_async_out(ir
, GET_REVISION
, sizeof(GET_REVISION
));
1024 static void mceusb_gen2_init(struct mceusb_dev
*ir
)
1027 mce_async_out(ir
, DEVICE_RESET
, sizeof(DEVICE_RESET
));
1029 /* get hw/sw revision? */
1030 mce_async_out(ir
, GET_REVISION
, sizeof(GET_REVISION
));
1032 /* unknown what the next two actually return... */
1033 mce_async_out(ir
, GET_UNKNOWN
, sizeof(GET_UNKNOWN
));
1034 mce_async_out(ir
, GET_UNKNOWN2
, sizeof(GET_UNKNOWN2
));
1037 static void mceusb_get_parameters(struct mceusb_dev
*ir
)
1039 /* get the carrier and frequency */
1040 mce_async_out(ir
, GET_CARRIER_FREQ
, sizeof(GET_CARRIER_FREQ
));
1042 if (!ir
->flags
.no_tx
)
1043 /* get the transmitter bitmask */
1044 mce_async_out(ir
, GET_TX_BITMASK
, sizeof(GET_TX_BITMASK
));
1046 /* get receiver timeout value */
1047 mce_async_out(ir
, GET_RX_TIMEOUT
, sizeof(GET_RX_TIMEOUT
));
1049 /* get receiver sensor setting */
1050 mce_async_out(ir
, GET_RX_SENSOR
, sizeof(GET_RX_SENSOR
));
1053 static struct rc_dev
*mceusb_init_rc_dev(struct mceusb_dev
*ir
)
1055 struct device
*dev
= ir
->dev
;
1059 rc
= rc_allocate_device();
1061 dev_err(dev
, "remote dev allocation failed\n");
1065 snprintf(ir
->name
, sizeof(ir
->name
), "%s (%04x:%04x)",
1066 mceusb_model
[ir
->model
].name
?
1067 mceusb_model
[ir
->model
].name
:
1068 "Media Center Ed. eHome Infrared Remote Transceiver",
1069 le16_to_cpu(ir
->usbdev
->descriptor
.idVendor
),
1070 le16_to_cpu(ir
->usbdev
->descriptor
.idProduct
));
1072 usb_make_path(ir
->usbdev
, ir
->phys
, sizeof(ir
->phys
));
1074 rc
->input_name
= ir
->name
;
1075 rc
->input_phys
= ir
->phys
;
1076 usb_to_input_id(ir
->usbdev
, &rc
->input_id
);
1077 rc
->dev
.parent
= dev
;
1079 rc
->driver_type
= RC_DRIVER_IR_RAW
;
1080 rc
->allowed_protos
= RC_TYPE_ALL
;
1081 rc
->timeout
= US_TO_NS(1000);
1082 if (!ir
->flags
.no_tx
) {
1083 rc
->s_tx_mask
= mceusb_set_tx_mask
;
1084 rc
->s_tx_carrier
= mceusb_set_tx_carrier
;
1085 rc
->tx_ir
= mceusb_tx_ir
;
1087 rc
->driver_name
= DRIVER_NAME
;
1088 rc
->map_name
= mceusb_model
[ir
->model
].rc_map
?
1089 mceusb_model
[ir
->model
].rc_map
: RC_MAP_RC6_MCE
;
1091 ret
= rc_register_device(rc
);
1093 dev_err(dev
, "remote dev registration failed\n");
1104 static int __devinit
mceusb_dev_probe(struct usb_interface
*intf
,
1105 const struct usb_device_id
*id
)
1107 struct usb_device
*dev
= interface_to_usbdev(intf
);
1108 struct usb_host_interface
*idesc
;
1109 struct usb_endpoint_descriptor
*ep
= NULL
;
1110 struct usb_endpoint_descriptor
*ep_in
= NULL
;
1111 struct usb_endpoint_descriptor
*ep_out
= NULL
;
1112 struct mceusb_dev
*ir
= NULL
;
1114 char buf
[63], name
[128] = "";
1115 enum mceusb_model_type model
= id
->driver_info
;
1117 bool is_microsoft_gen1
;
1118 bool tx_mask_normal
;
1121 mce_dbg(&intf
->dev
, "%s called\n", __func__
);
1123 idesc
= intf
->cur_altsetting
;
1125 is_gen3
= mceusb_model
[model
].mce_gen3
;
1126 is_microsoft_gen1
= mceusb_model
[model
].mce_gen1
;
1127 tx_mask_normal
= mceusb_model
[model
].tx_mask_normal
;
1128 ir_intfnum
= mceusb_model
[model
].ir_intfnum
;
1130 /* There are multi-function devices with non-IR interfaces */
1131 if (idesc
->desc
.bInterfaceNumber
!= ir_intfnum
)
1134 /* step through the endpoints to find first bulk in and out endpoint */
1135 for (i
= 0; i
< idesc
->desc
.bNumEndpoints
; ++i
) {
1136 ep
= &idesc
->endpoint
[i
].desc
;
1139 && ((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1141 && (((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1142 == USB_ENDPOINT_XFER_BULK
)
1143 || ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1144 == USB_ENDPOINT_XFER_INT
))) {
1147 ep_in
->bmAttributes
= USB_ENDPOINT_XFER_INT
;
1148 ep_in
->bInterval
= 1;
1149 mce_dbg(&intf
->dev
, "acceptable inbound endpoint "
1153 if ((ep_out
== NULL
)
1154 && ((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1156 && (((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1157 == USB_ENDPOINT_XFER_BULK
)
1158 || ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1159 == USB_ENDPOINT_XFER_INT
))) {
1162 ep_out
->bmAttributes
= USB_ENDPOINT_XFER_INT
;
1163 ep_out
->bInterval
= 1;
1164 mce_dbg(&intf
->dev
, "acceptable outbound endpoint "
1168 if (ep_in
== NULL
) {
1169 mce_dbg(&intf
->dev
, "inbound and/or endpoint not found\n");
1173 pipe
= usb_rcvintpipe(dev
, ep_in
->bEndpointAddress
);
1174 maxp
= usb_maxpacket(dev
, pipe
, usb_pipeout(pipe
));
1176 ir
= kzalloc(sizeof(struct mceusb_dev
), GFP_KERNEL
);
1178 goto mem_alloc_fail
;
1180 ir
->buf_in
= usb_alloc_coherent(dev
, maxp
, GFP_ATOMIC
, &ir
->dma_in
);
1182 goto buf_in_alloc_fail
;
1184 ir
->urb_in
= usb_alloc_urb(0, GFP_KERNEL
);
1186 goto urb_in_alloc_fail
;
1189 ir
->dev
= &intf
->dev
;
1191 ir
->flags
.microsoft_gen1
= is_microsoft_gen1
;
1192 ir
->flags
.tx_mask_normal
= tx_mask_normal
;
1193 ir
->flags
.no_tx
= mceusb_model
[model
].no_tx
;
1196 /* Saving usb interface data for use by the transmitter routine */
1197 ir
->usb_ep_in
= ep_in
;
1198 ir
->usb_ep_out
= ep_out
;
1200 if (dev
->descriptor
.iManufacturer
1201 && usb_string(dev
, dev
->descriptor
.iManufacturer
,
1202 buf
, sizeof(buf
)) > 0)
1203 strlcpy(name
, buf
, sizeof(name
));
1204 if (dev
->descriptor
.iProduct
1205 && usb_string(dev
, dev
->descriptor
.iProduct
,
1206 buf
, sizeof(buf
)) > 0)
1207 snprintf(name
+ strlen(name
), sizeof(name
) - strlen(name
),
1210 ir
->rc
= mceusb_init_rc_dev(ir
);
1214 /* wire up inbound data handler */
1215 usb_fill_int_urb(ir
->urb_in
, dev
, pipe
, ir
->buf_in
,
1216 maxp
, (usb_complete_t
) mceusb_dev_recv
, ir
, ep_in
->bInterval
);
1217 ir
->urb_in
->transfer_dma
= ir
->dma_in
;
1218 ir
->urb_in
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1220 /* flush buffers on the device */
1221 mce_dbg(&intf
->dev
, "Flushing receive buffers\n");
1222 mce_flush_rx_buffer(ir
, maxp
);
1224 /* initialize device */
1225 if (ir
->flags
.microsoft_gen1
)
1226 mceusb_gen1_init(ir
);
1228 mceusb_gen2_init(ir
);
1230 mceusb_get_parameters(ir
);
1232 if (!ir
->flags
.no_tx
)
1233 mceusb_set_tx_mask(ir
->rc
, MCE_DEFAULT_TX_MASK
);
1235 usb_set_intfdata(intf
, ir
);
1237 dev_info(&intf
->dev
, "Registered %s on usb%d:%d\n", name
,
1238 dev
->bus
->busnum
, dev
->devnum
);
1242 /* Error-handling path */
1244 usb_free_urb(ir
->urb_in
);
1246 usb_free_coherent(dev
, maxp
, ir
->buf_in
, ir
->dma_in
);
1250 dev_err(&intf
->dev
, "%s: device setup failed!\n", __func__
);
1256 static void __devexit
mceusb_dev_disconnect(struct usb_interface
*intf
)
1258 struct usb_device
*dev
= interface_to_usbdev(intf
);
1259 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1261 usb_set_intfdata(intf
, NULL
);
1267 rc_unregister_device(ir
->rc
);
1268 usb_kill_urb(ir
->urb_in
);
1269 usb_free_urb(ir
->urb_in
);
1270 usb_free_coherent(dev
, ir
->len_in
, ir
->buf_in
, ir
->dma_in
);
1275 static int mceusb_dev_suspend(struct usb_interface
*intf
, pm_message_t message
)
1277 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1278 dev_info(ir
->dev
, "suspend\n");
1279 usb_kill_urb(ir
->urb_in
);
1283 static int mceusb_dev_resume(struct usb_interface
*intf
)
1285 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1286 dev_info(ir
->dev
, "resume\n");
1287 if (usb_submit_urb(ir
->urb_in
, GFP_ATOMIC
))
1292 static struct usb_driver mceusb_dev_driver
= {
1293 .name
= DRIVER_NAME
,
1294 .probe
= mceusb_dev_probe
,
1295 .disconnect
= mceusb_dev_disconnect
,
1296 .suspend
= mceusb_dev_suspend
,
1297 .resume
= mceusb_dev_resume
,
1298 .reset_resume
= mceusb_dev_resume
,
1299 .id_table
= mceusb_dev_table
1302 static int __init
mceusb_dev_init(void)
1306 ret
= usb_register(&mceusb_dev_driver
);
1308 printk(KERN_ERR DRIVER_NAME
1309 ": usb register failed, result = %d\n", ret
);
1314 static void __exit
mceusb_dev_exit(void)
1316 usb_deregister(&mceusb_dev_driver
);
1319 module_init(mceusb_dev_init
);
1320 module_exit(mceusb_dev_exit
);
1322 MODULE_DESCRIPTION(DRIVER_DESC
);
1323 MODULE_AUTHOR(DRIVER_AUTHOR
);
1324 MODULE_LICENSE("GPL");
1325 MODULE_DEVICE_TABLE(usb
, mceusb_dev_table
);
1327 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1328 MODULE_PARM_DESC(debug
, "Debug enabled or not");