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 /* general constants */
112 #define SEND_FLAG_IN_PROGRESS 1
113 #define SEND_FLAG_COMPLETE 2
114 #define RECV_FLAG_IN_PROGRESS 3
115 #define RECV_FLAG_COMPLETE 4
120 #define VENDOR_PHILIPS 0x0471
121 #define VENDOR_SMK 0x0609
122 #define VENDOR_TATUNG 0x1460
123 #define VENDOR_GATEWAY 0x107b
124 #define VENDOR_SHUTTLE 0x1308
125 #define VENDOR_SHUTTLE2 0x051c
126 #define VENDOR_MITSUMI 0x03ee
127 #define VENDOR_TOPSEED 0x1784
128 #define VENDOR_RICAVISION 0x179d
129 #define VENDOR_ITRON 0x195d
130 #define VENDOR_FIC 0x1509
131 #define VENDOR_LG 0x043e
132 #define VENDOR_MICROSOFT 0x045e
133 #define VENDOR_FORMOSA 0x147a
134 #define VENDOR_FINTEK 0x1934
135 #define VENDOR_PINNACLE 0x2304
136 #define VENDOR_ECS 0x1019
137 #define VENDOR_WISTRON 0x0fb8
138 #define VENDOR_COMPRO 0x185b
139 #define VENDOR_NORTHSTAR 0x04eb
140 #define VENDOR_REALTEK 0x0bda
141 #define VENDOR_TIVO 0x105a
142 #define VENDOR_CONEXANT 0x0572
144 enum mceusb_model_type
{
145 MCE_GEN2
= 0, /* Most boards */
154 struct mceusb_model
{
158 u32 tx_mask_normal
:1;
163 const char *rc_map
; /* Allow specify a per-board map */
164 const char *name
; /* per-board name */
167 static const struct mceusb_model mceusb_model
[] = {
175 [MCE_GEN2_TX_INV
] = {
185 * In fact, the EVK is shipped without
186 * remotes, but we should have something handy,
187 * to allow testing it
189 .rc_map
= RC_MAP_HAUPPAUGE
,
190 .name
= "Conexant Hybrid TV (cx231xx) MCE IR",
193 .no_tx
= 1, /* tx isn't wired up at all */
194 .name
= "Conexant Hybrid TV (cx231xx) MCE IR",
202 static struct usb_device_id mceusb_dev_table
[] = {
203 /* Original Microsoft MCE IR Transceiver (often HP-branded) */
204 { USB_DEVICE(VENDOR_MICROSOFT
, 0x006d),
205 .driver_info
= MCE_GEN1
},
206 /* Philips Infrared Transceiver - Sahara branded */
207 { USB_DEVICE(VENDOR_PHILIPS
, 0x0608) },
208 /* Philips Infrared Transceiver - HP branded */
209 { USB_DEVICE(VENDOR_PHILIPS
, 0x060c),
210 .driver_info
= MCE_GEN2_TX_INV
},
211 /* Philips SRM5100 */
212 { USB_DEVICE(VENDOR_PHILIPS
, 0x060d) },
213 /* Philips Infrared Transceiver - Omaura */
214 { USB_DEVICE(VENDOR_PHILIPS
, 0x060f) },
215 /* Philips Infrared Transceiver - Spinel plus */
216 { USB_DEVICE(VENDOR_PHILIPS
, 0x0613) },
217 /* Philips eHome Infrared Transceiver */
218 { USB_DEVICE(VENDOR_PHILIPS
, 0x0815) },
219 /* Philips/Spinel plus IR transceiver for ASUS */
220 { USB_DEVICE(VENDOR_PHILIPS
, 0x206c) },
221 /* Philips/Spinel plus IR transceiver for ASUS */
222 { USB_DEVICE(VENDOR_PHILIPS
, 0x2088) },
223 /* Realtek MCE IR Receiver and card reader */
224 { USB_DEVICE(VENDOR_REALTEK
, 0x0161),
225 .driver_info
= MULTIFUNCTION
},
226 /* SMK/Toshiba G83C0004D410 */
227 { USB_DEVICE(VENDOR_SMK
, 0x031d),
228 .driver_info
= MCE_GEN2_TX_INV
},
229 /* SMK eHome Infrared Transceiver (Sony VAIO) */
230 { USB_DEVICE(VENDOR_SMK
, 0x0322),
231 .driver_info
= MCE_GEN2_TX_INV
},
232 /* bundled with Hauppauge PVR-150 */
233 { USB_DEVICE(VENDOR_SMK
, 0x0334),
234 .driver_info
= MCE_GEN2_TX_INV
},
235 /* SMK eHome Infrared Transceiver */
236 { USB_DEVICE(VENDOR_SMK
, 0x0338) },
237 /* Tatung eHome Infrared Transceiver */
238 { USB_DEVICE(VENDOR_TATUNG
, 0x9150) },
239 /* Shuttle eHome Infrared Transceiver */
240 { USB_DEVICE(VENDOR_SHUTTLE
, 0xc001) },
241 /* Shuttle eHome Infrared Transceiver */
242 { USB_DEVICE(VENDOR_SHUTTLE2
, 0xc001) },
243 /* Gateway eHome Infrared Transceiver */
244 { USB_DEVICE(VENDOR_GATEWAY
, 0x3009) },
246 { USB_DEVICE(VENDOR_MITSUMI
, 0x2501) },
247 /* Topseed eHome Infrared Transceiver */
248 { USB_DEVICE(VENDOR_TOPSEED
, 0x0001),
249 .driver_info
= MCE_GEN2_TX_INV
},
250 /* Topseed HP eHome Infrared Transceiver */
251 { USB_DEVICE(VENDOR_TOPSEED
, 0x0006),
252 .driver_info
= MCE_GEN2_TX_INV
},
253 /* Topseed eHome Infrared Transceiver */
254 { USB_DEVICE(VENDOR_TOPSEED
, 0x0007),
255 .driver_info
= MCE_GEN2_TX_INV
},
256 /* Topseed eHome Infrared Transceiver */
257 { USB_DEVICE(VENDOR_TOPSEED
, 0x0008),
258 .driver_info
= MCE_GEN3
},
259 /* Topseed eHome Infrared Transceiver */
260 { USB_DEVICE(VENDOR_TOPSEED
, 0x000a),
261 .driver_info
= MCE_GEN2_TX_INV
},
262 /* Topseed eHome Infrared Transceiver */
263 { USB_DEVICE(VENDOR_TOPSEED
, 0x0011),
264 .driver_info
= MCE_GEN3
},
265 /* Ricavision internal Infrared Transceiver */
266 { USB_DEVICE(VENDOR_RICAVISION
, 0x0010) },
267 /* Itron ione Libra Q-11 */
268 { USB_DEVICE(VENDOR_ITRON
, 0x7002) },
269 /* FIC eHome Infrared Transceiver */
270 { USB_DEVICE(VENDOR_FIC
, 0x9242) },
271 /* LG eHome Infrared Transceiver */
272 { USB_DEVICE(VENDOR_LG
, 0x9803) },
273 /* Microsoft MCE Infrared Transceiver */
274 { USB_DEVICE(VENDOR_MICROSOFT
, 0x00a0) },
275 /* Formosa eHome Infrared Transceiver */
276 { USB_DEVICE(VENDOR_FORMOSA
, 0xe015) },
277 /* Formosa21 / eHome Infrared Receiver */
278 { USB_DEVICE(VENDOR_FORMOSA
, 0xe016) },
279 /* Formosa aim / Trust MCE Infrared Receiver */
280 { USB_DEVICE(VENDOR_FORMOSA
, 0xe017) },
281 /* Formosa Industrial Computing / Beanbag Emulation Device */
282 { USB_DEVICE(VENDOR_FORMOSA
, 0xe018) },
283 /* Formosa21 / eHome Infrared Receiver */
284 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03a) },
285 /* Formosa Industrial Computing AIM IR605/A */
286 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03c) },
287 /* Formosa Industrial Computing */
288 { USB_DEVICE(VENDOR_FORMOSA
, 0xe03e) },
289 /* Fintek eHome Infrared Transceiver (HP branded) */
290 { USB_DEVICE(VENDOR_FINTEK
, 0x5168) },
291 /* Fintek eHome Infrared Transceiver */
292 { USB_DEVICE(VENDOR_FINTEK
, 0x0602) },
293 /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
294 { USB_DEVICE(VENDOR_FINTEK
, 0x0702) },
295 /* Pinnacle Remote Kit */
296 { USB_DEVICE(VENDOR_PINNACLE
, 0x0225),
297 .driver_info
= MCE_GEN3
},
298 /* Elitegroup Computer Systems IR */
299 { USB_DEVICE(VENDOR_ECS
, 0x0f38) },
300 /* Wistron Corp. eHome Infrared Receiver */
301 { USB_DEVICE(VENDOR_WISTRON
, 0x0002) },
303 { USB_DEVICE(VENDOR_COMPRO
, 0x3020) },
305 { USB_DEVICE(VENDOR_COMPRO
, 0x3082) },
306 /* Northstar Systems, Inc. eHome Infrared Transceiver */
307 { USB_DEVICE(VENDOR_NORTHSTAR
, 0xe004) },
308 /* TiVo PC IR Receiver */
309 { USB_DEVICE(VENDOR_TIVO
, 0x2000) },
310 /* Conexant Hybrid TV "Shelby" Polaris SDK */
311 { USB_DEVICE(VENDOR_CONEXANT
, 0x58a1),
312 .driver_info
= POLARIS_EVK
},
313 /* Conexant Hybrid TV RDU253S Polaris */
314 { USB_DEVICE(VENDOR_CONEXANT
, 0x58a5),
315 .driver_info
= CX_HYBRID_TV
},
316 /* Terminating entry */
320 /* data structure for each usb transceiver */
325 /* optional features we can enable */
326 bool carrier_report_enabled
;
327 bool learning_enabled
;
329 /* core device bits */
333 struct usb_device
*usbdev
;
335 struct usb_endpoint_descriptor
*usb_ep_in
;
336 struct usb_endpoint_descriptor
*usb_ep_out
;
338 /* buffers and dma */
339 unsigned char *buf_in
;
351 u8 cmd
, rem
; /* Remaining IR data bytes in packet */
355 u32 tx_mask_normal
:1;
356 u32 microsoft_gen1
:1;
360 /* transmit support */
363 unsigned char tx_mask
;
367 enum mceusb_model_type model
;
371 * MCE Device Command Strings
372 * Device command responses vary from device to device...
373 * - DEVICE_RESET resets the hardware to its default state
374 * - GET_REVISION fetches the hardware/software revision, common
375 * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
376 * - GET_CARRIER_FREQ gets the carrier mode and frequency of the
377 * device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
378 * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
379 * ((clk / frequency) - 1)
380 * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
381 * response in the form of 9f 0c msb lsb
382 * - GET_TX_BITMASK fetches the transmitter bitmask, replies in
383 * the form of 9f 08 bm, where bm is the bitmask
384 * - GET_RX_SENSOR fetches the RX sensor setting -- long-range
385 * general use one or short-range learning one, in the form of
386 * 9f 14 ss, where ss is either 01 for long-range or 02 for short
387 * - SET_CARRIER_FREQ sets a new carrier mode and frequency
388 * - SET_TX_BITMASK sets the transmitter bitmask
389 * - SET_RX_TIMEOUT sets the receiver timeout
390 * - SET_RX_SENSOR sets which receiver sensor to use
392 static char DEVICE_RESET
[] = {MCE_COMMAND_NULL
, MCE_HW_CMD_HEADER
,
393 MCE_CMD_DEVICE_RESET
};
394 static char GET_REVISION
[] = {MCE_HW_CMD_HEADER
, MCE_CMD_G_REVISION
};
395 static char GET_UNKNOWN
[] = {MCE_HW_CMD_HEADER
, MCE_CMD_UNKNOWN7
};
396 static char GET_UNKNOWN2
[] = {MCE_COMMAND_HEADER
, MCE_CMD_UNKNOWN2
};
397 static char GET_CARRIER_FREQ
[] = {MCE_COMMAND_HEADER
, MCE_CMD_G_CARRIER
};
398 static char GET_RX_TIMEOUT
[] = {MCE_COMMAND_HEADER
, MCE_CMD_G_TIMEOUT
};
399 static char GET_TX_BITMASK
[] = {MCE_COMMAND_HEADER
, MCE_CMD_G_TXMASK
};
400 static char GET_RX_SENSOR
[] = {MCE_COMMAND_HEADER
, MCE_CMD_G_RXSENSOR
};
401 /* sub in desired values in lower byte or bytes for full command */
402 /* FIXME: make use of these for transmit.
403 static char SET_CARRIER_FREQ[] = {MCE_COMMAND_HEADER,
404 MCE_CMD_S_CARRIER, 0x00, 0x00};
405 static char SET_TX_BITMASK[] = {MCE_COMMAND_HEADER, MCE_CMD_S_TXMASK, 0x00};
406 static char SET_RX_TIMEOUT[] = {MCE_COMMAND_HEADER,
407 MCE_CMD_S_TIMEOUT, 0x00, 0x00};
408 static char SET_RX_SENSOR[] = {MCE_COMMAND_HEADER,
409 MCE_CMD_S_RXSENSOR, 0x00};
412 static int mceusb_cmdsize(u8 cmd
, u8 subcmd
)
417 case MCE_COMMAND_NULL
:
418 if (subcmd
== MCE_HW_CMD_HEADER
)
421 case MCE_HW_CMD_HEADER
:
423 case MCE_CMD_G_REVISION
:
427 case MCE_COMMAND_HEADER
:
429 case MCE_CMD_UNKNOWN
:
430 case MCE_CMD_S_CARRIER
:
431 case MCE_CMD_S_TIMEOUT
:
432 case MCE_RSP_PULSE_COUNT
:
435 case MCE_CMD_SIG_END
:
436 case MCE_CMD_S_TXMASK
:
437 case MCE_CMD_S_RXSENSOR
:
445 static void mceusb_dev_printdata(struct mceusb_dev
*ir
, char *buf
,
446 int offset
, int len
, bool out
)
448 char codes
[USB_BUFLEN
* 3 + 1];
450 u8 cmd
, subcmd
, data1
, data2
;
451 struct device
*dev
= ir
->dev
;
452 int i
, start
, skip
= 0;
457 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
458 if (ir
->flags
.microsoft_gen1
&& !out
&& !offset
)
464 for (i
= 0; i
< len
&& i
< USB_BUFLEN
; i
++)
465 snprintf(codes
+ i
* 3, 4, "%02x ", buf
[i
+ offset
] & 0xff);
467 dev_info(dev
, "%sx data: %s(length=%d)\n",
468 (out
? "t" : "r"), codes
, len
);
471 strcpy(inout
, "Request\0");
473 strcpy(inout
, "Got\0");
475 start
= offset
+ skip
;
476 cmd
= buf
[start
] & 0xff;
477 subcmd
= buf
[start
+ 1] & 0xff;
478 data1
= buf
[start
+ 2] & 0xff;
479 data2
= buf
[start
+ 3] & 0xff;
482 case MCE_COMMAND_NULL
:
483 if ((subcmd
== MCE_HW_CMD_HEADER
) &&
484 (data1
== MCE_CMD_DEVICE_RESET
))
485 dev_info(dev
, "Device reset requested\n");
487 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
490 case MCE_HW_CMD_HEADER
:
492 case MCE_CMD_G_REVISION
:
494 dev_info(dev
, "Get hw/sw rev?\n");
496 dev_info(dev
, "hw/sw rev 0x%02x 0x%02x "
497 "0x%02x 0x%02x\n", data1
, data2
,
498 buf
[start
+ 4], buf
[start
+ 5]);
500 case MCE_CMD_DEVICE_RESET
:
501 dev_info(dev
, "Device reset requested\n");
503 case MCE_RSP_CMD_INVALID
:
504 dev_info(dev
, "Previous command not supported\n");
506 case MCE_CMD_UNKNOWN7
:
507 case MCE_CMD_UNKNOWN9
:
509 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
514 case MCE_COMMAND_HEADER
:
516 case MCE_CMD_SIG_END
:
517 dev_info(dev
, "End of signal\n");
520 dev_info(dev
, "Ping\n");
522 case MCE_CMD_UNKNOWN
:
523 dev_info(dev
, "Resp to 9f 05 of 0x%02x 0x%02x\n",
526 case MCE_CMD_S_CARRIER
:
527 dev_info(dev
, "%s carrier mode and freq of "
528 "0x%02x 0x%02x\n", inout
, data1
, data2
);
530 case MCE_CMD_G_CARRIER
:
531 dev_info(dev
, "Get carrier mode and freq\n");
533 case MCE_CMD_S_TXMASK
:
534 dev_info(dev
, "%s transmit blaster mask of 0x%02x\n",
537 case MCE_CMD_S_TIMEOUT
:
538 /* value is in units of 50us, so x*50/100 or x/2 ms */
539 dev_info(dev
, "%s receive timeout of %d ms\n",
540 inout
, ((data1
<< 8) | data2
) / 2);
542 case MCE_CMD_G_TIMEOUT
:
543 dev_info(dev
, "Get receive timeout\n");
545 case MCE_CMD_G_TXMASK
:
546 dev_info(dev
, "Get transmit blaster mask\n");
548 case MCE_CMD_S_RXSENSOR
:
549 dev_info(dev
, "%s %s-range receive sensor in use\n",
550 inout
, data1
== 0x02 ? "short" : "long");
552 case MCE_CMD_G_RXSENSOR
:
553 /* aka MCE_RSP_PULSE_COUNT */
555 dev_info(dev
, "Get receive sensor\n");
556 else if (ir
->learning_enabled
)
557 dev_info(dev
, "RX pulse count: %d\n",
558 ((data1
<< 8) | data2
));
560 case MCE_RSP_CMD_INVALID
:
561 dev_info(dev
, "Error! Hardware is likely wedged...\n");
563 case MCE_CMD_UNKNOWN2
:
564 case MCE_CMD_UNKNOWN3
:
565 case MCE_CMD_UNKNOWN5
:
567 dev_info(dev
, "Unknown command 0x%02x 0x%02x\n",
576 if (cmd
== MCE_IRDATA_TRAILER
)
577 dev_info(dev
, "End of raw IR data\n");
578 else if ((cmd
!= MCE_COMMAND_HEADER
) &&
579 ((cmd
& MCE_COMMAND_MASK
) == MCE_COMMAND_IRDATA
))
580 dev_info(dev
, "Raw IR data, %d pulse/space samples\n", ir
->rem
);
583 static void mce_async_callback(struct urb
*urb
, struct pt_regs
*regs
)
585 struct mceusb_dev
*ir
;
593 len
= urb
->actual_length
;
595 dev_dbg(ir
->dev
, "callback called (status=%d len=%d)\n",
598 mceusb_dev_printdata(ir
, urb
->transfer_buffer
, 0, len
, true);
603 /* request incoming or send outgoing usb packet - used to initialize remote */
604 static void mce_request_packet(struct mceusb_dev
*ir
,
605 struct usb_endpoint_descriptor
*ep
,
606 unsigned char *data
, int size
, int urb_type
)
609 struct urb
*async_urb
;
610 struct device
*dev
= ir
->dev
;
611 unsigned char *async_buf
;
613 if (urb_type
== MCEUSB_TX
) {
614 async_urb
= usb_alloc_urb(0, GFP_KERNEL
);
615 if (unlikely(!async_urb
)) {
616 dev_err(dev
, "Error, couldn't allocate urb!\n");
620 async_buf
= kzalloc(size
, GFP_KERNEL
);
622 dev_err(dev
, "Error, couldn't allocate buf!\n");
623 usb_free_urb(async_urb
);
628 usb_fill_int_urb(async_urb
, ir
->usbdev
,
629 usb_sndintpipe(ir
->usbdev
, ep
->bEndpointAddress
),
630 async_buf
, size
, (usb_complete_t
)mce_async_callback
,
632 memcpy(async_buf
, data
, size
);
634 } else if (urb_type
== MCEUSB_RX
) {
635 /* standard request */
636 async_urb
= ir
->urb_in
;
637 ir
->send_flags
= RECV_FLAG_IN_PROGRESS
;
640 dev_err(dev
, "Error! Unknown urb type %d\n", urb_type
);
644 dev_dbg(dev
, "receive request called (size=%#x)\n", size
);
646 async_urb
->transfer_buffer_length
= size
;
647 async_urb
->dev
= ir
->usbdev
;
649 res
= usb_submit_urb(async_urb
, GFP_ATOMIC
);
651 dev_dbg(dev
, "receive request FAILED! (res=%d)\n", res
);
654 dev_dbg(dev
, "receive request complete (res=%d)\n", res
);
657 static void mce_async_out(struct mceusb_dev
*ir
, unsigned char *data
, int size
)
659 mce_request_packet(ir
, ir
->usb_ep_out
, data
, size
, MCEUSB_TX
);
662 static void mce_sync_in(struct mceusb_dev
*ir
, unsigned char *data
, int size
)
664 mce_request_packet(ir
, ir
->usb_ep_in
, data
, size
, MCEUSB_RX
);
667 /* Send data out the IR blaster port(s) */
668 static int mceusb_tx_ir(struct rc_dev
*dev
, int *txbuf
, u32 n
)
670 struct mceusb_dev
*ir
= dev
->priv
;
672 int count
, cmdcount
= 0;
673 unsigned char *cmdbuf
; /* MCE command buffer */
674 long signal_duration
= 0; /* Singnal length in us */
675 struct timeval start_time
, end_time
;
677 do_gettimeofday(&start_time
);
679 count
= n
/ sizeof(int);
681 cmdbuf
= kzalloc(sizeof(int) * MCE_CMDBUF_SIZE
, GFP_KERNEL
);
685 /* MCE tx init header */
686 cmdbuf
[cmdcount
++] = MCE_COMMAND_HEADER
;
687 cmdbuf
[cmdcount
++] = MCE_CMD_S_TXMASK
;
688 cmdbuf
[cmdcount
++] = ir
->tx_mask
;
690 /* Generate mce packet data */
691 for (i
= 0; (i
< count
) && (cmdcount
< MCE_CMDBUF_SIZE
); i
++) {
692 signal_duration
+= txbuf
[i
];
693 txbuf
[i
] = txbuf
[i
] / MCE_TIME_UNIT
;
695 do { /* loop to support long pulses/spaces > 127*50us=6.35ms */
697 /* Insert mce packet header every 4th entry */
698 if ((cmdcount
< MCE_CMDBUF_SIZE
) &&
699 (cmdcount
- MCE_TX_HEADER_LENGTH
) %
700 MCE_CODE_LENGTH
== 0)
701 cmdbuf
[cmdcount
++] = MCE_IRDATA_HEADER
;
703 /* Insert mce packet data */
704 if (cmdcount
< MCE_CMDBUF_SIZE
)
706 (txbuf
[i
] < MCE_PULSE_BIT
?
707 txbuf
[i
] : MCE_MAX_PULSE_LENGTH
) |
708 (i
& 1 ? 0x00 : MCE_PULSE_BIT
);
714 } while ((txbuf
[i
] > MCE_MAX_PULSE_LENGTH
) &&
715 (txbuf
[i
] -= MCE_MAX_PULSE_LENGTH
));
718 /* Fix packet length in last header */
719 cmdbuf
[cmdcount
- (cmdcount
- MCE_TX_HEADER_LENGTH
) % MCE_CODE_LENGTH
] =
720 MCE_COMMAND_IRDATA
+ (cmdcount
- MCE_TX_HEADER_LENGTH
) %
723 /* Check if we have room for the empty packet at the end */
724 if (cmdcount
>= MCE_CMDBUF_SIZE
) {
729 /* All mce commands end with an empty packet (0x80) */
730 cmdbuf
[cmdcount
++] = MCE_IRDATA_TRAILER
;
732 /* Transmit the command to the mce device */
733 mce_async_out(ir
, cmdbuf
, cmdcount
);
736 * The lircd gap calculation expects the write function to
737 * wait the time it takes for the ircommand to be sent before
740 do_gettimeofday(&end_time
);
741 signal_duration
-= (end_time
.tv_usec
- start_time
.tv_usec
) +
742 (end_time
.tv_sec
- start_time
.tv_sec
) * 1000000;
744 /* delay with the closest number of ticks */
745 set_current_state(TASK_INTERRUPTIBLE
);
746 schedule_timeout(usecs_to_jiffies(signal_duration
));
750 return ret
? ret
: n
;
753 /* Sets active IR outputs -- mce devices typically have two */
754 static int mceusb_set_tx_mask(struct rc_dev
*dev
, u32 mask
)
756 struct mceusb_dev
*ir
= dev
->priv
;
758 if (ir
->flags
.tx_mask_normal
)
761 ir
->tx_mask
= (mask
!= MCE_DEFAULT_TX_MASK
?
762 mask
^ MCE_DEFAULT_TX_MASK
: mask
) << 1;
767 /* Sets the send carrier frequency and mode */
768 static int mceusb_set_tx_carrier(struct rc_dev
*dev
, u32 carrier
)
770 struct mceusb_dev
*ir
= dev
->priv
;
772 int prescaler
= 0, divisor
= 0;
773 unsigned char cmdbuf
[4] = { MCE_COMMAND_HEADER
,
774 MCE_CMD_S_CARRIER
, 0x00, 0x00 };
776 /* Carrier has changed */
777 if (ir
->carrier
!= carrier
) {
780 ir
->carrier
= carrier
;
781 cmdbuf
[2] = MCE_CMD_SIG_END
;
782 cmdbuf
[3] = MCE_IRDATA_TRAILER
;
783 dev_dbg(ir
->dev
, "%s: disabling carrier "
784 "modulation\n", __func__
);
785 mce_async_out(ir
, cmdbuf
, sizeof(cmdbuf
));
789 for (prescaler
= 0; prescaler
< 4; ++prescaler
) {
790 divisor
= (clk
>> (2 * prescaler
)) / carrier
;
791 if (divisor
<= 0xff) {
792 ir
->carrier
= carrier
;
793 cmdbuf
[2] = prescaler
;
795 dev_dbg(ir
->dev
, "%s: requesting %u HZ "
796 "carrier\n", __func__
, carrier
);
798 /* Transmit new carrier to mce device */
799 mce_async_out(ir
, cmdbuf
, sizeof(cmdbuf
));
812 * We don't do anything but print debug spew for many of the command bits
813 * we receive from the hardware, but some of them are useful information
814 * we want to store so that we can use them.
816 static void mceusb_handle_command(struct mceusb_dev
*ir
, int index
)
818 u8 hi
= ir
->buf_in
[index
+ 1] & 0xff;
819 u8 lo
= ir
->buf_in
[index
+ 2] & 0xff;
821 switch (ir
->buf_in
[index
]) {
822 /* 2-byte return value commands */
823 case MCE_CMD_S_TIMEOUT
:
824 ir
->rc
->timeout
= US_TO_NS((hi
<< 8 | lo
) / 2);
827 /* 1-byte return value commands */
828 case MCE_CMD_S_TXMASK
:
831 case MCE_CMD_S_RXSENSOR
:
832 ir
->learning_enabled
= (hi
== 0x02);
839 static void mceusb_process_ir_data(struct mceusb_dev
*ir
, int buf_len
)
841 DEFINE_IR_RAW_EVENT(rawir
);
844 /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
845 if (ir
->flags
.microsoft_gen1
)
848 /* if there's no data, just return now */
852 for (; i
< buf_len
; i
++) {
853 switch (ir
->parser_state
) {
855 ir
->rem
= mceusb_cmdsize(ir
->cmd
, ir
->buf_in
[i
]);
856 mceusb_dev_printdata(ir
, ir
->buf_in
, i
- 1,
858 mceusb_handle_command(ir
, i
);
859 ir
->parser_state
= CMD_DATA
;
863 init_ir_raw_event(&rawir
);
864 rawir
.pulse
= ((ir
->buf_in
[i
] & MCE_PULSE_BIT
) != 0);
865 rawir
.duration
= (ir
->buf_in
[i
] & MCE_PULSE_MASK
)
866 * US_TO_NS(MCE_TIME_UNIT
);
868 dev_dbg(ir
->dev
, "Storing %s with duration %d\n",
869 rawir
.pulse
? "pulse" : "space",
872 ir_raw_event_store_with_filter(ir
->rc
, &rawir
);
878 /* decode mce packets of the form (84),AA,BB,CC,DD */
879 /* IR data packets can span USB messages - rem */
880 ir
->cmd
= ir
->buf_in
[i
];
881 if ((ir
->cmd
== MCE_COMMAND_HEADER
) ||
882 ((ir
->cmd
& MCE_COMMAND_MASK
) !=
883 MCE_COMMAND_IRDATA
)) {
884 ir
->parser_state
= SUBCMD
;
887 ir
->rem
= (ir
->cmd
& MCE_PACKET_LENGTH_MASK
);
888 mceusb_dev_printdata(ir
, ir
->buf_in
,
889 i
, ir
->rem
+ 1, false);
891 ir
->parser_state
= PARSE_IRDATA
;
893 ir_raw_event_reset(ir
->rc
);
897 if (ir
->parser_state
!= CMD_HEADER
&& !ir
->rem
)
898 ir
->parser_state
= CMD_HEADER
;
900 dev_dbg(ir
->dev
, "processed IR data, calling ir_raw_event_handle\n");
901 ir_raw_event_handle(ir
->rc
);
904 static void mceusb_dev_recv(struct urb
*urb
, struct pt_regs
*regs
)
906 struct mceusb_dev
*ir
;
918 buf_len
= urb
->actual_length
;
920 if (ir
->send_flags
== RECV_FLAG_IN_PROGRESS
) {
921 ir
->send_flags
= SEND_FLAG_COMPLETE
;
922 dev_dbg(ir
->dev
, "setup answer received %d bytes\n",
926 switch (urb
->status
) {
929 mceusb_process_ir_data(ir
, buf_len
);
940 dev_dbg(ir
->dev
, "Error: urb status = %d\n", urb
->status
);
944 usb_submit_urb(urb
, GFP_ATOMIC
);
947 static void mceusb_gen1_init(struct mceusb_dev
*ir
)
950 int maxp
= ir
->len_in
;
951 struct device
*dev
= ir
->dev
;
954 data
= kzalloc(USB_CTRL_MSG_SZ
, GFP_KERNEL
);
956 dev_err(dev
, "%s: memory allocation failed!\n", __func__
);
961 * This is a strange one. Windows issues a set address to the device
962 * on the receive control pipe and expect a certain value pair back
964 ret
= usb_control_msg(ir
->usbdev
, usb_rcvctrlpipe(ir
->usbdev
, 0),
965 USB_REQ_SET_ADDRESS
, USB_TYPE_VENDOR
, 0, 0,
966 data
, USB_CTRL_MSG_SZ
, HZ
* 3);
967 dev_dbg(dev
, "%s - ret = %d\n", __func__
, ret
);
968 dev_dbg(dev
, "%s - data[0] = %d, data[1] = %d\n",
969 __func__
, data
[0], data
[1]);
971 /* set feature: bit rate 38400 bps */
972 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
973 USB_REQ_SET_FEATURE
, USB_TYPE_VENDOR
,
974 0xc04e, 0x0000, NULL
, 0, HZ
* 3);
976 dev_dbg(dev
, "%s - ret = %d\n", __func__
, ret
);
978 /* bRequest 4: set char length to 8 bits */
979 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
981 0x0808, 0x0000, NULL
, 0, HZ
* 3);
982 dev_dbg(dev
, "%s - retB = %d\n", __func__
, ret
);
984 /* bRequest 2: set handshaking to use DTR/DSR */
985 ret
= usb_control_msg(ir
->usbdev
, usb_sndctrlpipe(ir
->usbdev
, 0),
987 0x0000, 0x0100, NULL
, 0, HZ
* 3);
988 dev_dbg(dev
, "%s - retC = %d\n", __func__
, ret
);
991 mce_async_out(ir
, DEVICE_RESET
, sizeof(DEVICE_RESET
));
992 mce_sync_in(ir
, NULL
, maxp
);
994 /* get hw/sw revision? */
995 mce_async_out(ir
, GET_REVISION
, sizeof(GET_REVISION
));
996 mce_sync_in(ir
, NULL
, maxp
);
1001 static void mceusb_gen2_init(struct mceusb_dev
*ir
)
1003 int maxp
= ir
->len_in
;
1006 mce_async_out(ir
, DEVICE_RESET
, sizeof(DEVICE_RESET
));
1007 mce_sync_in(ir
, NULL
, maxp
);
1009 /* get hw/sw revision? */
1010 mce_async_out(ir
, GET_REVISION
, sizeof(GET_REVISION
));
1011 mce_sync_in(ir
, NULL
, maxp
);
1013 /* unknown what the next two actually return... */
1014 mce_async_out(ir
, GET_UNKNOWN
, sizeof(GET_UNKNOWN
));
1015 mce_sync_in(ir
, NULL
, maxp
);
1016 mce_async_out(ir
, GET_UNKNOWN2
, sizeof(GET_UNKNOWN2
));
1017 mce_sync_in(ir
, NULL
, maxp
);
1020 static void mceusb_get_parameters(struct mceusb_dev
*ir
)
1022 int maxp
= ir
->len_in
;
1024 /* get the carrier and frequency */
1025 mce_async_out(ir
, GET_CARRIER_FREQ
, sizeof(GET_CARRIER_FREQ
));
1026 mce_sync_in(ir
, NULL
, maxp
);
1028 if (!ir
->flags
.no_tx
) {
1029 /* get the transmitter bitmask */
1030 mce_async_out(ir
, GET_TX_BITMASK
, sizeof(GET_TX_BITMASK
));
1031 mce_sync_in(ir
, NULL
, maxp
);
1034 /* get receiver timeout value */
1035 mce_async_out(ir
, GET_RX_TIMEOUT
, sizeof(GET_RX_TIMEOUT
));
1036 mce_sync_in(ir
, NULL
, maxp
);
1038 /* get receiver sensor setting */
1039 mce_async_out(ir
, GET_RX_SENSOR
, sizeof(GET_RX_SENSOR
));
1040 mce_sync_in(ir
, NULL
, maxp
);
1043 static struct rc_dev
*mceusb_init_rc_dev(struct mceusb_dev
*ir
)
1045 struct device
*dev
= ir
->dev
;
1049 rc
= rc_allocate_device();
1051 dev_err(dev
, "remote dev allocation failed\n");
1055 snprintf(ir
->name
, sizeof(ir
->name
), "%s (%04x:%04x)",
1056 mceusb_model
[ir
->model
].name
?
1057 mceusb_model
[ir
->model
].name
:
1058 "Media Center Ed. eHome Infrared Remote Transceiver",
1059 le16_to_cpu(ir
->usbdev
->descriptor
.idVendor
),
1060 le16_to_cpu(ir
->usbdev
->descriptor
.idProduct
));
1062 usb_make_path(ir
->usbdev
, ir
->phys
, sizeof(ir
->phys
));
1064 rc
->input_name
= ir
->name
;
1065 rc
->input_phys
= ir
->phys
;
1066 usb_to_input_id(ir
->usbdev
, &rc
->input_id
);
1067 rc
->dev
.parent
= dev
;
1069 rc
->driver_type
= RC_DRIVER_IR_RAW
;
1070 rc
->allowed_protos
= RC_TYPE_ALL
;
1071 rc
->timeout
= US_TO_NS(1000);
1072 if (!ir
->flags
.no_tx
) {
1073 rc
->s_tx_mask
= mceusb_set_tx_mask
;
1074 rc
->s_tx_carrier
= mceusb_set_tx_carrier
;
1075 rc
->tx_ir
= mceusb_tx_ir
;
1077 rc
->driver_name
= DRIVER_NAME
;
1078 rc
->map_name
= mceusb_model
[ir
->model
].rc_map
?
1079 mceusb_model
[ir
->model
].rc_map
: RC_MAP_RC6_MCE
;
1081 ret
= rc_register_device(rc
);
1083 dev_err(dev
, "remote dev registration failed\n");
1094 static int __devinit
mceusb_dev_probe(struct usb_interface
*intf
,
1095 const struct usb_device_id
*id
)
1097 struct usb_device
*dev
= interface_to_usbdev(intf
);
1098 struct usb_host_interface
*idesc
;
1099 struct usb_endpoint_descriptor
*ep
= NULL
;
1100 struct usb_endpoint_descriptor
*ep_in
= NULL
;
1101 struct usb_endpoint_descriptor
*ep_out
= NULL
;
1102 struct mceusb_dev
*ir
= NULL
;
1104 char buf
[63], name
[128] = "";
1105 enum mceusb_model_type model
= id
->driver_info
;
1107 bool is_microsoft_gen1
;
1108 bool tx_mask_normal
;
1111 dev_dbg(&intf
->dev
, "%s called\n", __func__
);
1113 idesc
= intf
->cur_altsetting
;
1115 is_gen3
= mceusb_model
[model
].mce_gen3
;
1116 is_microsoft_gen1
= mceusb_model
[model
].mce_gen1
;
1117 tx_mask_normal
= mceusb_model
[model
].tx_mask_normal
;
1118 ir_intfnum
= mceusb_model
[model
].ir_intfnum
;
1120 /* There are multi-function devices with non-IR interfaces */
1121 if (idesc
->desc
.bInterfaceNumber
!= ir_intfnum
)
1124 /* step through the endpoints to find first bulk in and out endpoint */
1125 for (i
= 0; i
< idesc
->desc
.bNumEndpoints
; ++i
) {
1126 ep
= &idesc
->endpoint
[i
].desc
;
1129 && ((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1131 && (((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1132 == USB_ENDPOINT_XFER_BULK
)
1133 || ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1134 == USB_ENDPOINT_XFER_INT
))) {
1137 ep_in
->bmAttributes
= USB_ENDPOINT_XFER_INT
;
1138 ep_in
->bInterval
= 1;
1139 dev_dbg(&intf
->dev
, "acceptable inbound endpoint "
1143 if ((ep_out
== NULL
)
1144 && ((ep
->bEndpointAddress
& USB_ENDPOINT_DIR_MASK
)
1146 && (((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1147 == USB_ENDPOINT_XFER_BULK
)
1148 || ((ep
->bmAttributes
& USB_ENDPOINT_XFERTYPE_MASK
)
1149 == USB_ENDPOINT_XFER_INT
))) {
1152 ep_out
->bmAttributes
= USB_ENDPOINT_XFER_INT
;
1153 ep_out
->bInterval
= 1;
1154 dev_dbg(&intf
->dev
, "acceptable outbound endpoint "
1158 if (ep_in
== NULL
) {
1159 dev_dbg(&intf
->dev
, "inbound and/or endpoint not found\n");
1163 pipe
= usb_rcvintpipe(dev
, ep_in
->bEndpointAddress
);
1164 maxp
= usb_maxpacket(dev
, pipe
, usb_pipeout(pipe
));
1166 ir
= kzalloc(sizeof(struct mceusb_dev
), GFP_KERNEL
);
1168 goto mem_alloc_fail
;
1170 ir
->buf_in
= usb_alloc_coherent(dev
, maxp
, GFP_ATOMIC
, &ir
->dma_in
);
1172 goto buf_in_alloc_fail
;
1174 ir
->urb_in
= usb_alloc_urb(0, GFP_KERNEL
);
1176 goto urb_in_alloc_fail
;
1179 ir
->dev
= &intf
->dev
;
1181 ir
->flags
.microsoft_gen1
= is_microsoft_gen1
;
1182 ir
->flags
.tx_mask_normal
= tx_mask_normal
;
1183 ir
->flags
.no_tx
= mceusb_model
[model
].no_tx
;
1186 /* Saving usb interface data for use by the transmitter routine */
1187 ir
->usb_ep_in
= ep_in
;
1188 ir
->usb_ep_out
= ep_out
;
1190 if (dev
->descriptor
.iManufacturer
1191 && usb_string(dev
, dev
->descriptor
.iManufacturer
,
1192 buf
, sizeof(buf
)) > 0)
1193 strlcpy(name
, buf
, sizeof(name
));
1194 if (dev
->descriptor
.iProduct
1195 && usb_string(dev
, dev
->descriptor
.iProduct
,
1196 buf
, sizeof(buf
)) > 0)
1197 snprintf(name
+ strlen(name
), sizeof(name
) - strlen(name
),
1200 ir
->rc
= mceusb_init_rc_dev(ir
);
1204 /* flush buffers on the device */
1205 mce_sync_in(ir
, NULL
, maxp
);
1206 mce_sync_in(ir
, NULL
, maxp
);
1208 /* wire up inbound data handler */
1209 usb_fill_int_urb(ir
->urb_in
, dev
, pipe
, ir
->buf_in
,
1210 maxp
, (usb_complete_t
) mceusb_dev_recv
, ir
, ep_in
->bInterval
);
1211 ir
->urb_in
->transfer_dma
= ir
->dma_in
;
1212 ir
->urb_in
->transfer_flags
|= URB_NO_TRANSFER_DMA_MAP
;
1214 /* initialize device */
1215 if (ir
->flags
.microsoft_gen1
)
1216 mceusb_gen1_init(ir
);
1218 mceusb_gen2_init(ir
);
1220 mceusb_get_parameters(ir
);
1222 if (!ir
->flags
.no_tx
)
1223 mceusb_set_tx_mask(ir
->rc
, MCE_DEFAULT_TX_MASK
);
1225 usb_set_intfdata(intf
, ir
);
1227 dev_info(&intf
->dev
, "Registered %s on usb%d:%d\n", name
,
1228 dev
->bus
->busnum
, dev
->devnum
);
1232 /* Error-handling path */
1234 usb_free_urb(ir
->urb_in
);
1236 usb_free_coherent(dev
, maxp
, ir
->buf_in
, ir
->dma_in
);
1240 dev_err(&intf
->dev
, "%s: device setup failed!\n", __func__
);
1246 static void __devexit
mceusb_dev_disconnect(struct usb_interface
*intf
)
1248 struct usb_device
*dev
= interface_to_usbdev(intf
);
1249 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1251 usb_set_intfdata(intf
, NULL
);
1257 rc_unregister_device(ir
->rc
);
1258 usb_kill_urb(ir
->urb_in
);
1259 usb_free_urb(ir
->urb_in
);
1260 usb_free_coherent(dev
, ir
->len_in
, ir
->buf_in
, ir
->dma_in
);
1265 static int mceusb_dev_suspend(struct usb_interface
*intf
, pm_message_t message
)
1267 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1268 dev_info(ir
->dev
, "suspend\n");
1269 usb_kill_urb(ir
->urb_in
);
1273 static int mceusb_dev_resume(struct usb_interface
*intf
)
1275 struct mceusb_dev
*ir
= usb_get_intfdata(intf
);
1276 dev_info(ir
->dev
, "resume\n");
1277 if (usb_submit_urb(ir
->urb_in
, GFP_ATOMIC
))
1282 static struct usb_driver mceusb_dev_driver
= {
1283 .name
= DRIVER_NAME
,
1284 .probe
= mceusb_dev_probe
,
1285 .disconnect
= mceusb_dev_disconnect
,
1286 .suspend
= mceusb_dev_suspend
,
1287 .resume
= mceusb_dev_resume
,
1288 .reset_resume
= mceusb_dev_resume
,
1289 .id_table
= mceusb_dev_table
1292 static int __init
mceusb_dev_init(void)
1296 ret
= usb_register(&mceusb_dev_driver
);
1298 printk(KERN_ERR DRIVER_NAME
1299 ": usb register failed, result = %d\n", ret
);
1304 static void __exit
mceusb_dev_exit(void)
1306 usb_deregister(&mceusb_dev_driver
);
1309 module_init(mceusb_dev_init
);
1310 module_exit(mceusb_dev_exit
);
1312 MODULE_DESCRIPTION(DRIVER_DESC
);
1313 MODULE_AUTHOR(DRIVER_AUTHOR
);
1314 MODULE_LICENSE("GPL");
1315 MODULE_DEVICE_TABLE(usb
, mceusb_dev_table
);
1317 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1318 MODULE_PARM_DESC(debug
, "Debug enabled or not");