mceusb.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. /*
  2. * Driver for USB Windows Media Center Ed. eHome Infrared Transceivers
  3. *
  4. * Copyright (c) 2010 by Jarod Wilson <jarod@redhat.com>
  5. *
  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.
  17. *
  18. *
  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.
  23. *
  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.
  28. *
  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
  32. *
  33. */
  34. #include <linux/device.h>
  35. #include <linux/module.h>
  36. #include <linux/slab.h>
  37. #include <linux/usb.h>
  38. #include <linux/input.h>
  39. #include <media/ir-core.h>
  40. #include <media/ir-common.h>
  41. #define DRIVER_VERSION "1.91"
  42. #define DRIVER_AUTHOR "Jarod Wilson <jarod@wilsonet.com>"
  43. #define DRIVER_DESC "Windows Media Center Ed. eHome Infrared Transceiver " \
  44. "device driver"
  45. #define DRIVER_NAME "mceusb"
  46. #define USB_BUFLEN 32 /* USB reception buffer length */
  47. #define USB_CTRL_MSG_SZ 2 /* Size of usb ctrl msg on gen1 hw */
  48. #define MCE_G1_INIT_MSGS 40 /* Init messages on gen1 hw to throw out */
  49. /* MCE constants */
  50. #define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */
  51. #define MCE_TIME_UNIT 50 /* Approx 50us resolution */
  52. #define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */
  53. #define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */
  54. #define MCE_PACKET_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */
  55. #define MCE_CONTROL_HEADER 0x9F /* MCE status header */
  56. #define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */
  57. #define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */
  58. #define MCE_DEFAULT_TX_MASK 0x03 /* Val opts: TX1=0x01, TX2=0x02, ALL=0x03 */
  59. #define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */
  60. #define MCE_PULSE_MASK 0x7F /* Pulse mask */
  61. #define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */
  62. #define MCE_PACKET_LENGTH_MASK 0x1F /* Packet length mask */
  63. /* module parameters */
  64. #ifdef CONFIG_USB_DEBUG
  65. static int debug = 1;
  66. #else
  67. static int debug;
  68. #endif
  69. /* general constants */
  70. #define SEND_FLAG_IN_PROGRESS 1
  71. #define SEND_FLAG_COMPLETE 2
  72. #define RECV_FLAG_IN_PROGRESS 3
  73. #define RECV_FLAG_COMPLETE 4
  74. #define MCEUSB_RX 1
  75. #define MCEUSB_TX 2
  76. #define VENDOR_PHILIPS 0x0471
  77. #define VENDOR_SMK 0x0609
  78. #define VENDOR_TATUNG 0x1460
  79. #define VENDOR_GATEWAY 0x107b
  80. #define VENDOR_SHUTTLE 0x1308
  81. #define VENDOR_SHUTTLE2 0x051c
  82. #define VENDOR_MITSUMI 0x03ee
  83. #define VENDOR_TOPSEED 0x1784
  84. #define VENDOR_RICAVISION 0x179d
  85. #define VENDOR_ITRON 0x195d
  86. #define VENDOR_FIC 0x1509
  87. #define VENDOR_LG 0x043e
  88. #define VENDOR_MICROSOFT 0x045e
  89. #define VENDOR_FORMOSA 0x147a
  90. #define VENDOR_FINTEK 0x1934
  91. #define VENDOR_PINNACLE 0x2304
  92. #define VENDOR_ECS 0x1019
  93. #define VENDOR_WISTRON 0x0fb8
  94. #define VENDOR_COMPRO 0x185b
  95. #define VENDOR_NORTHSTAR 0x04eb
  96. #define VENDOR_REALTEK 0x0bda
  97. #define VENDOR_TIVO 0x105a
  98. static struct usb_device_id mceusb_dev_table[] = {
  99. /* Original Microsoft MCE IR Transceiver (often HP-branded) */
  100. { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
  101. /* Philips Infrared Transceiver - Sahara branded */
  102. { USB_DEVICE(VENDOR_PHILIPS, 0x0608) },
  103. /* Philips Infrared Transceiver - HP branded */
  104. { USB_DEVICE(VENDOR_PHILIPS, 0x060c) },
  105. /* Philips SRM5100 */
  106. { USB_DEVICE(VENDOR_PHILIPS, 0x060d) },
  107. /* Philips Infrared Transceiver - Omaura */
  108. { USB_DEVICE(VENDOR_PHILIPS, 0x060f) },
  109. /* Philips Infrared Transceiver - Spinel plus */
  110. { USB_DEVICE(VENDOR_PHILIPS, 0x0613) },
  111. /* Philips eHome Infrared Transceiver */
  112. { USB_DEVICE(VENDOR_PHILIPS, 0x0815) },
  113. /* Realtek MCE IR Receiver */
  114. { USB_DEVICE(VENDOR_REALTEK, 0x0161) },
  115. /* SMK/Toshiba G83C0004D410 */
  116. { USB_DEVICE(VENDOR_SMK, 0x031d) },
  117. /* SMK eHome Infrared Transceiver (Sony VAIO) */
  118. { USB_DEVICE(VENDOR_SMK, 0x0322) },
  119. /* bundled with Hauppauge PVR-150 */
  120. { USB_DEVICE(VENDOR_SMK, 0x0334) },
  121. /* SMK eHome Infrared Transceiver */
  122. { USB_DEVICE(VENDOR_SMK, 0x0338) },
  123. /* Tatung eHome Infrared Transceiver */
  124. { USB_DEVICE(VENDOR_TATUNG, 0x9150) },
  125. /* Shuttle eHome Infrared Transceiver */
  126. { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) },
  127. /* Shuttle eHome Infrared Transceiver */
  128. { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) },
  129. /* Gateway eHome Infrared Transceiver */
  130. { USB_DEVICE(VENDOR_GATEWAY, 0x3009) },
  131. /* Mitsumi */
  132. { USB_DEVICE(VENDOR_MITSUMI, 0x2501) },
  133. /* Topseed eHome Infrared Transceiver */
  134. { USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
  135. /* Topseed HP eHome Infrared Transceiver */
  136. { USB_DEVICE(VENDOR_TOPSEED, 0x0006) },
  137. /* Topseed eHome Infrared Transceiver */
  138. { USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
  139. /* Topseed eHome Infrared Transceiver */
  140. { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
  141. /* Topseed eHome Infrared Transceiver */
  142. { USB_DEVICE(VENDOR_TOPSEED, 0x000a) },
  143. /* Topseed eHome Infrared Transceiver */
  144. { USB_DEVICE(VENDOR_TOPSEED, 0x0011) },
  145. /* Ricavision internal Infrared Transceiver */
  146. { USB_DEVICE(VENDOR_RICAVISION, 0x0010) },
  147. /* Itron ione Libra Q-11 */
  148. { USB_DEVICE(VENDOR_ITRON, 0x7002) },
  149. /* FIC eHome Infrared Transceiver */
  150. { USB_DEVICE(VENDOR_FIC, 0x9242) },
  151. /* LG eHome Infrared Transceiver */
  152. { USB_DEVICE(VENDOR_LG, 0x9803) },
  153. /* Microsoft MCE Infrared Transceiver */
  154. { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) },
  155. /* Formosa eHome Infrared Transceiver */
  156. { USB_DEVICE(VENDOR_FORMOSA, 0xe015) },
  157. /* Formosa21 / eHome Infrared Receiver */
  158. { USB_DEVICE(VENDOR_FORMOSA, 0xe016) },
  159. /* Formosa aim / Trust MCE Infrared Receiver */
  160. { USB_DEVICE(VENDOR_FORMOSA, 0xe017) },
  161. /* Formosa Industrial Computing / Beanbag Emulation Device */
  162. { USB_DEVICE(VENDOR_FORMOSA, 0xe018) },
  163. /* Formosa21 / eHome Infrared Receiver */
  164. { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) },
  165. /* Formosa Industrial Computing AIM IR605/A */
  166. { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) },
  167. /* Formosa Industrial Computing */
  168. { USB_DEVICE(VENDOR_FORMOSA, 0xe03e) },
  169. /* Fintek eHome Infrared Transceiver */
  170. { USB_DEVICE(VENDOR_FINTEK, 0x0602) },
  171. /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */
  172. { USB_DEVICE(VENDOR_FINTEK, 0x0702) },
  173. /* Pinnacle Remote Kit */
  174. { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
  175. /* Elitegroup Computer Systems IR */
  176. { USB_DEVICE(VENDOR_ECS, 0x0f38) },
  177. /* Wistron Corp. eHome Infrared Receiver */
  178. { USB_DEVICE(VENDOR_WISTRON, 0x0002) },
  179. /* Compro K100 */
  180. { USB_DEVICE(VENDOR_COMPRO, 0x3020) },
  181. /* Compro K100 v2 */
  182. { USB_DEVICE(VENDOR_COMPRO, 0x3082) },
  183. /* Northstar Systems, Inc. eHome Infrared Transceiver */
  184. { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) },
  185. /* TiVo PC IR Receiver */
  186. { USB_DEVICE(VENDOR_TIVO, 0x2000) },
  187. /* Terminating entry */
  188. { }
  189. };
  190. static struct usb_device_id gen3_list[] = {
  191. { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
  192. { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
  193. {}
  194. };
  195. static struct usb_device_id microsoft_gen1_list[] = {
  196. { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
  197. {}
  198. };
  199. static struct usb_device_id std_tx_mask_list[] = {
  200. { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) },
  201. { USB_DEVICE(VENDOR_PHILIPS, 0x060c) },
  202. { USB_DEVICE(VENDOR_SMK, 0x031d) },
  203. { USB_DEVICE(VENDOR_SMK, 0x0322) },
  204. { USB_DEVICE(VENDOR_SMK, 0x0334) },
  205. { USB_DEVICE(VENDOR_TOPSEED, 0x0001) },
  206. { USB_DEVICE(VENDOR_TOPSEED, 0x0006) },
  207. { USB_DEVICE(VENDOR_TOPSEED, 0x0007) },
  208. { USB_DEVICE(VENDOR_TOPSEED, 0x0008) },
  209. { USB_DEVICE(VENDOR_TOPSEED, 0x000a) },
  210. { USB_DEVICE(VENDOR_TOPSEED, 0x0011) },
  211. { USB_DEVICE(VENDOR_PINNACLE, 0x0225) },
  212. {}
  213. };
  214. /* data structure for each usb transceiver */
  215. struct mceusb_dev {
  216. /* ir-core bits */
  217. struct ir_input_dev *irdev;
  218. struct ir_dev_props *props;
  219. struct ir_raw_event rawir;
  220. /* core device bits */
  221. struct device *dev;
  222. struct input_dev *idev;
  223. /* usb */
  224. struct usb_device *usbdev;
  225. struct urb *urb_in;
  226. struct usb_endpoint_descriptor *usb_ep_in;
  227. struct usb_endpoint_descriptor *usb_ep_out;
  228. /* buffers and dma */
  229. unsigned char *buf_in;
  230. unsigned int len_in;
  231. u8 cmd; /* MCE command type */
  232. u8 rem; /* Remaining IR data bytes in packet */
  233. dma_addr_t dma_in;
  234. dma_addr_t dma_out;
  235. struct {
  236. u32 connected:1;
  237. u32 tx_mask_inverted:1;
  238. u32 microsoft_gen1:1;
  239. u32 reserved:29;
  240. } flags;
  241. /* transmit support */
  242. int send_flags;
  243. u32 carrier;
  244. unsigned char tx_mask;
  245. char name[128];
  246. char phys[64];
  247. };
  248. /*
  249. * MCE Device Command Strings
  250. * Device command responses vary from device to device...
  251. * - DEVICE_RESET resets the hardware to its default state
  252. * - GET_REVISION fetches the hardware/software revision, common
  253. * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42
  254. * - GET_CARRIER_FREQ gets the carrier mode and frequency of the
  255. * device, with replies in the form of 9f 06 MM FF, where MM is 0-3,
  256. * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is
  257. * ((clk / frequency) - 1)
  258. * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us,
  259. * response in the form of 9f 0c msb lsb
  260. * - GET_TX_BITMASK fetches the transmitter bitmask, replies in
  261. * the form of 9f 08 bm, where bm is the bitmask
  262. * - GET_RX_SENSOR fetches the RX sensor setting -- long-range
  263. * general use one or short-range learning one, in the form of
  264. * 9f 14 ss, where ss is either 01 for long-range or 02 for short
  265. * - SET_CARRIER_FREQ sets a new carrier mode and frequency
  266. * - SET_TX_BITMASK sets the transmitter bitmask
  267. * - SET_RX_TIMEOUT sets the receiver timeout
  268. * - SET_RX_SENSOR sets which receiver sensor to use
  269. */
  270. static char DEVICE_RESET[] = {0x00, 0xff, 0xaa};
  271. static char GET_REVISION[] = {0xff, 0x0b};
  272. static char GET_UNKNOWN[] = {0xff, 0x18};
  273. static char GET_UNKNOWN2[] = {0x9f, 0x05};
  274. static char GET_CARRIER_FREQ[] = {0x9f, 0x07};
  275. static char GET_RX_TIMEOUT[] = {0x9f, 0x0d};
  276. static char GET_TX_BITMASK[] = {0x9f, 0x13};
  277. static char GET_RX_SENSOR[] = {0x9f, 0x15};
  278. /* sub in desired values in lower byte or bytes for full command */
  279. /* FIXME: make use of these for transmit.
  280. static char SET_CARRIER_FREQ[] = {0x9f, 0x06, 0x00, 0x00};
  281. static char SET_TX_BITMASK[] = {0x9f, 0x08, 0x00};
  282. static char SET_RX_TIMEOUT[] = {0x9f, 0x0c, 0x00, 0x00};
  283. static char SET_RX_SENSOR[] = {0x9f, 0x14, 0x00};
  284. */
  285. static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf,
  286. int len, bool out)
  287. {
  288. char codes[USB_BUFLEN * 3 + 1];
  289. char inout[9];
  290. int i;
  291. u8 cmd, subcmd, data1, data2;
  292. struct device *dev = ir->dev;
  293. int idx = 0;
  294. /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
  295. if (ir->flags.microsoft_gen1 && !out)
  296. idx = 2;
  297. if (len <= idx)
  298. return;
  299. for (i = 0; i < len && i < USB_BUFLEN; i++)
  300. snprintf(codes + i * 3, 4, "%02x ", buf[i] & 0xFF);
  301. dev_info(dev, "%sx data: %s (length=%d)\n",
  302. (out ? "t" : "r"), codes, len);
  303. if (out)
  304. strcpy(inout, "Request\0");
  305. else
  306. strcpy(inout, "Got\0");
  307. cmd = buf[idx] & 0xff;
  308. subcmd = buf[idx + 1] & 0xff;
  309. data1 = buf[idx + 2] & 0xff;
  310. data2 = buf[idx + 3] & 0xff;
  311. switch (cmd) {
  312. case 0x00:
  313. if (subcmd == 0xff && data1 == 0xaa)
  314. dev_info(dev, "Device reset requested\n");
  315. else
  316. dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
  317. cmd, subcmd);
  318. break;
  319. case 0xff:
  320. switch (subcmd) {
  321. case 0x0b:
  322. if (len == 2)
  323. dev_info(dev, "Get hw/sw rev?\n");
  324. else
  325. dev_info(dev, "hw/sw rev 0x%02x 0x%02x "
  326. "0x%02x 0x%02x\n", data1, data2,
  327. buf[idx + 4], buf[idx + 5]);
  328. break;
  329. case 0xaa:
  330. dev_info(dev, "Device reset requested\n");
  331. break;
  332. case 0xfe:
  333. dev_info(dev, "Previous command not supported\n");
  334. break;
  335. case 0x18:
  336. case 0x1b:
  337. default:
  338. dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
  339. cmd, subcmd);
  340. break;
  341. }
  342. break;
  343. case 0x9f:
  344. switch (subcmd) {
  345. case 0x03:
  346. dev_info(dev, "Ping\n");
  347. break;
  348. case 0x04:
  349. dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n",
  350. data1, data2);
  351. break;
  352. case 0x06:
  353. dev_info(dev, "%s carrier mode and freq of "
  354. "0x%02x 0x%02x\n", inout, data1, data2);
  355. break;
  356. case 0x07:
  357. dev_info(dev, "Get carrier mode and freq\n");
  358. break;
  359. case 0x08:
  360. dev_info(dev, "%s transmit blaster mask of 0x%02x\n",
  361. inout, data1);
  362. break;
  363. case 0x0c:
  364. /* value is in units of 50us, so x*50/100 or x/2 ms */
  365. dev_info(dev, "%s receive timeout of %d ms\n",
  366. inout, ((data1 << 8) | data2) / 2);
  367. break;
  368. case 0x0d:
  369. dev_info(dev, "Get receive timeout\n");
  370. break;
  371. case 0x13:
  372. dev_info(dev, "Get transmit blaster mask\n");
  373. break;
  374. case 0x14:
  375. dev_info(dev, "%s %s-range receive sensor in use\n",
  376. inout, data1 == 0x02 ? "short" : "long");
  377. break;
  378. case 0x15:
  379. if (len == 2)
  380. dev_info(dev, "Get receive sensor\n");
  381. else
  382. dev_info(dev, "Received pulse count is %d\n",
  383. ((data1 << 8) | data2));
  384. break;
  385. case 0xfe:
  386. dev_info(dev, "Error! Hardware is likely wedged...\n");
  387. break;
  388. case 0x05:
  389. case 0x09:
  390. case 0x0f:
  391. default:
  392. dev_info(dev, "Unknown command 0x%02x 0x%02x\n",
  393. cmd, subcmd);
  394. break;
  395. }
  396. break;
  397. default:
  398. break;
  399. }
  400. }
  401. static void usb_async_callback(struct urb *urb, struct pt_regs *regs)
  402. {
  403. struct mceusb_dev *ir;
  404. int len;
  405. if (!urb)
  406. return;
  407. ir = urb->context;
  408. if (ir) {
  409. len = urb->actual_length;
  410. dev_dbg(ir->dev, "callback called (status=%d len=%d)\n",
  411. urb->status, len);
  412. if (debug)
  413. mceusb_dev_printdata(ir, urb->transfer_buffer,
  414. len, true);
  415. }
  416. }
  417. /* request incoming or send outgoing usb packet - used to initialize remote */
  418. static void mce_request_packet(struct mceusb_dev *ir,
  419. struct usb_endpoint_descriptor *ep,
  420. unsigned char *data, int size, int urb_type)
  421. {
  422. int res;
  423. struct urb *async_urb;
  424. struct device *dev = ir->dev;
  425. unsigned char *async_buf;
  426. if (urb_type == MCEUSB_TX) {
  427. async_urb = usb_alloc_urb(0, GFP_KERNEL);
  428. if (unlikely(!async_urb)) {
  429. dev_err(dev, "Error, couldn't allocate urb!\n");
  430. return;
  431. }
  432. async_buf = kzalloc(size, GFP_KERNEL);
  433. if (!async_buf) {
  434. dev_err(dev, "Error, couldn't allocate buf!\n");
  435. usb_free_urb(async_urb);
  436. return;
  437. }
  438. /* outbound data */
  439. usb_fill_int_urb(async_urb, ir->usbdev,
  440. usb_sndintpipe(ir->usbdev, ep->bEndpointAddress),
  441. async_buf, size, (usb_complete_t) usb_async_callback,
  442. ir, ep->bInterval);
  443. memcpy(async_buf, data, size);
  444. } else if (urb_type == MCEUSB_RX) {
  445. /* standard request */
  446. async_urb = ir->urb_in;
  447. ir->send_flags = RECV_FLAG_IN_PROGRESS;
  448. } else {
  449. dev_err(dev, "Error! Unknown urb type %d\n", urb_type);
  450. return;
  451. }
  452. dev_dbg(dev, "receive request called (size=%#x)\n", size);
  453. async_urb->transfer_buffer_length = size;
  454. async_urb->dev = ir->usbdev;
  455. res = usb_submit_urb(async_urb, GFP_ATOMIC);
  456. if (res) {
  457. dev_dbg(dev, "receive request FAILED! (res=%d)\n", res);
  458. return;
  459. }
  460. dev_dbg(dev, "receive request complete (res=%d)\n", res);
  461. }
  462. static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size)
  463. {
  464. mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_TX);
  465. }
  466. static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size)
  467. {
  468. mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_RX);
  469. }
  470. /* Send data out the IR blaster port(s) */
  471. static int mceusb_tx_ir(void *priv, int *txbuf, u32 n)
  472. {
  473. struct mceusb_dev *ir = priv;
  474. int i, ret = 0;
  475. int count, cmdcount = 0;
  476. unsigned char *cmdbuf; /* MCE command buffer */
  477. long signal_duration = 0; /* Singnal length in us */
  478. struct timeval start_time, end_time;
  479. do_gettimeofday(&start_time);
  480. count = n / sizeof(int);
  481. cmdbuf = kzalloc(sizeof(int) * MCE_CMDBUF_SIZE, GFP_KERNEL);
  482. if (!cmdbuf)
  483. return -ENOMEM;
  484. /* MCE tx init header */
  485. cmdbuf[cmdcount++] = MCE_CONTROL_HEADER;
  486. cmdbuf[cmdcount++] = 0x08;
  487. cmdbuf[cmdcount++] = ir->tx_mask;
  488. /* Generate mce packet data */
  489. for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) {
  490. signal_duration += txbuf[i];
  491. txbuf[i] = txbuf[i] / MCE_TIME_UNIT;
  492. do { /* loop to support long pulses/spaces > 127*50us=6.35ms */
  493. /* Insert mce packet header every 4th entry */
  494. if ((cmdcount < MCE_CMDBUF_SIZE) &&
  495. (cmdcount - MCE_TX_HEADER_LENGTH) %
  496. MCE_CODE_LENGTH == 0)
  497. cmdbuf[cmdcount++] = MCE_PACKET_HEADER;
  498. /* Insert mce packet data */
  499. if (cmdcount < MCE_CMDBUF_SIZE)
  500. cmdbuf[cmdcount++] =
  501. (txbuf[i] < MCE_PULSE_BIT ?
  502. txbuf[i] : MCE_MAX_PULSE_LENGTH) |
  503. (i & 1 ? 0x00 : MCE_PULSE_BIT);
  504. else {
  505. ret = -EINVAL;
  506. goto out;
  507. }
  508. } while ((txbuf[i] > MCE_MAX_PULSE_LENGTH) &&
  509. (txbuf[i] -= MCE_MAX_PULSE_LENGTH));
  510. }
  511. /* Fix packet length in last header */
  512. cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] =
  513. 0x80 + (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH - 1;
  514. /* Check if we have room for the empty packet at the end */
  515. if (cmdcount >= MCE_CMDBUF_SIZE) {
  516. ret = -EINVAL;
  517. goto out;
  518. }
  519. /* All mce commands end with an empty packet (0x80) */
  520. cmdbuf[cmdcount++] = 0x80;
  521. /* Transmit the command to the mce device */
  522. mce_async_out(ir, cmdbuf, cmdcount);
  523. /*
  524. * The lircd gap calculation expects the write function to
  525. * wait the time it takes for the ircommand to be sent before
  526. * it returns.
  527. */
  528. do_gettimeofday(&end_time);
  529. signal_duration -= (end_time.tv_usec - start_time.tv_usec) +
  530. (end_time.tv_sec - start_time.tv_sec) * 1000000;
  531. /* delay with the closest number of ticks */
  532. set_current_state(TASK_INTERRUPTIBLE);
  533. schedule_timeout(usecs_to_jiffies(signal_duration));
  534. out:
  535. kfree(cmdbuf);
  536. return ret ? ret : n;
  537. }
  538. /* Sets active IR outputs -- mce devices typically (all?) have two */
  539. static int mceusb_set_tx_mask(void *priv, u32 mask)
  540. {
  541. struct mceusb_dev *ir = priv;
  542. if (ir->flags.tx_mask_inverted)
  543. ir->tx_mask = (mask != 0x03 ? mask ^ 0x03 : mask) << 1;
  544. else
  545. ir->tx_mask = mask;
  546. return 0;
  547. }
  548. /* Sets the send carrier frequency and mode */
  549. static int mceusb_set_tx_carrier(void *priv, u32 carrier)
  550. {
  551. struct mceusb_dev *ir = priv;
  552. int clk = 10000000;
  553. int prescaler = 0, divisor = 0;
  554. unsigned char cmdbuf[4] = { 0x9f, 0x06, 0x00, 0x00 };
  555. /* Carrier has changed */
  556. if (ir->carrier != carrier) {
  557. if (carrier == 0) {
  558. ir->carrier = carrier;
  559. cmdbuf[2] = 0x01;
  560. cmdbuf[3] = 0x80;
  561. dev_dbg(ir->dev, "%s: disabling carrier "
  562. "modulation\n", __func__);
  563. mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
  564. return carrier;
  565. }
  566. for (prescaler = 0; prescaler < 4; ++prescaler) {
  567. divisor = (clk >> (2 * prescaler)) / carrier;
  568. if (divisor <= 0xFF) {
  569. ir->carrier = carrier;
  570. cmdbuf[2] = prescaler;
  571. cmdbuf[3] = divisor;
  572. dev_dbg(ir->dev, "%s: requesting %u HZ "
  573. "carrier\n", __func__, carrier);
  574. /* Transmit new carrier to mce device */
  575. mce_async_out(ir, cmdbuf, sizeof(cmdbuf));
  576. return carrier;
  577. }
  578. }
  579. return -EINVAL;
  580. }
  581. return carrier;
  582. }
  583. static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len)
  584. {
  585. struct ir_raw_event rawir = { .pulse = false, .duration = 0 };
  586. int i, start_index = 0;
  587. u8 hdr = MCE_CONTROL_HEADER;
  588. /* skip meaningless 0xb1 0x60 header bytes on orig receiver */
  589. if (ir->flags.microsoft_gen1)
  590. start_index = 2;
  591. for (i = start_index; i < buf_len;) {
  592. if (ir->rem == 0) {
  593. /* decode mce packets of the form (84),AA,BB,CC,DD */
  594. /* IR data packets can span USB messages - rem */
  595. hdr = ir->buf_in[i];
  596. ir->rem = (hdr & MCE_PACKET_LENGTH_MASK);
  597. ir->cmd = (hdr & ~MCE_PACKET_LENGTH_MASK);
  598. dev_dbg(ir->dev, "New data. rem: 0x%02x, cmd: 0x%02x\n",
  599. ir->rem, ir->cmd);
  600. i++;
  601. }
  602. /* don't process MCE commands */
  603. if (hdr == MCE_CONTROL_HEADER || hdr == 0xff) {
  604. ir->rem = 0;
  605. return;
  606. }
  607. for (; (ir->rem > 0) && (i < buf_len); i++) {
  608. ir->rem--;
  609. rawir.pulse = ((ir->buf_in[i] & MCE_PULSE_BIT) != 0);
  610. rawir.duration = (ir->buf_in[i] & MCE_PULSE_MASK)
  611. * MCE_TIME_UNIT * 1000;
  612. if ((ir->buf_in[i] & MCE_PULSE_MASK) == 0x7f) {
  613. if (ir->rawir.pulse == rawir.pulse)
  614. ir->rawir.duration += rawir.duration;
  615. else {
  616. ir->rawir.duration = rawir.duration;
  617. ir->rawir.pulse = rawir.pulse;
  618. }
  619. continue;
  620. }
  621. rawir.duration += ir->rawir.duration;
  622. ir->rawir.duration = 0;
  623. ir->rawir.pulse = rawir.pulse;
  624. dev_dbg(ir->dev, "Storing %s with duration %d\n",
  625. rawir.pulse ? "pulse" : "space",
  626. rawir.duration);
  627. ir_raw_event_store(ir->idev, &rawir);
  628. }
  629. if (ir->buf_in[i] == 0x80 || ir->buf_in[i] == 0x9f)
  630. ir->rem = 0;
  631. dev_dbg(ir->dev, "calling ir_raw_event_handle\n");
  632. ir_raw_event_handle(ir->idev);
  633. }
  634. }
  635. static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs)
  636. {
  637. struct mceusb_dev *ir;
  638. int buf_len;
  639. if (!urb)
  640. return;
  641. ir = urb->context;
  642. if (!ir) {
  643. usb_unlink_urb(urb);
  644. return;
  645. }
  646. buf_len = urb->actual_length;
  647. if (debug)
  648. mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len, false);
  649. if (ir->send_flags == RECV_FLAG_IN_PROGRESS) {
  650. ir->send_flags = SEND_FLAG_COMPLETE;
  651. dev_dbg(&ir->irdev->dev, "setup answer received %d bytes\n",
  652. buf_len);
  653. }
  654. switch (urb->status) {
  655. /* success */
  656. case 0:
  657. mceusb_process_ir_data(ir, buf_len);
  658. break;
  659. case -ECONNRESET:
  660. case -ENOENT:
  661. case -ESHUTDOWN:
  662. usb_unlink_urb(urb);
  663. return;
  664. case -EPIPE:
  665. default:
  666. break;
  667. }
  668. usb_submit_urb(urb, GFP_ATOMIC);
  669. }
  670. static void mceusb_gen1_init(struct mceusb_dev *ir)
  671. {
  672. int ret;
  673. int maxp = ir->len_in;
  674. struct device *dev = ir->dev;
  675. char *data;
  676. data = kzalloc(USB_CTRL_MSG_SZ, GFP_KERNEL);
  677. if (!data) {
  678. dev_err(dev, "%s: memory allocation failed!\n", __func__);
  679. return;
  680. }
  681. /*
  682. * This is a strange one. Windows issues a set address to the device
  683. * on the receive control pipe and expect a certain value pair back
  684. */
  685. ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0),
  686. USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0,
  687. data, USB_CTRL_MSG_SZ, HZ * 3);
  688. dev_dbg(dev, "%s - ret = %d\n", __func__, ret);
  689. dev_dbg(dev, "%s - data[0] = %d, data[1] = %d\n",
  690. __func__, data[0], data[1]);
  691. /* set feature: bit rate 38400 bps */
  692. ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
  693. USB_REQ_SET_FEATURE, USB_TYPE_VENDOR,
  694. 0xc04e, 0x0000, NULL, 0, HZ * 3);
  695. dev_dbg(dev, "%s - ret = %d\n", __func__, ret);
  696. /* bRequest 4: set char length to 8 bits */
  697. ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
  698. 4, USB_TYPE_VENDOR,
  699. 0x0808, 0x0000, NULL, 0, HZ * 3);
  700. dev_dbg(dev, "%s - retB = %d\n", __func__, ret);
  701. /* bRequest 2: set handshaking to use DTR/DSR */
  702. ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0),
  703. 2, USB_TYPE_VENDOR,
  704. 0x0000, 0x0100, NULL, 0, HZ * 3);
  705. dev_dbg(dev, "%s - retC = %d\n", __func__, ret);
  706. /* device reset */
  707. mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
  708. mce_sync_in(ir, NULL, maxp);
  709. /* get hw/sw revision? */
  710. mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
  711. mce_sync_in(ir, NULL, maxp);
  712. kfree(data);
  713. };
  714. static void mceusb_gen2_init(struct mceusb_dev *ir)
  715. {
  716. int maxp = ir->len_in;
  717. /* device reset */
  718. mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET));
  719. mce_sync_in(ir, NULL, maxp);
  720. /* get hw/sw revision? */
  721. mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION));
  722. mce_sync_in(ir, NULL, maxp);
  723. /* unknown what the next two actually return... */
  724. mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN));
  725. mce_sync_in(ir, NULL, maxp);
  726. mce_async_out(ir, GET_UNKNOWN2, sizeof(GET_UNKNOWN2));
  727. mce_sync_in(ir, NULL, maxp);
  728. }
  729. static void mceusb_get_parameters(struct mceusb_dev *ir)
  730. {
  731. int maxp = ir->len_in;
  732. /* get the carrier and frequency */
  733. mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ));
  734. mce_sync_in(ir, NULL, maxp);
  735. /* get the transmitter bitmask */
  736. mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK));
  737. mce_sync_in(ir, NULL, maxp);
  738. /* get receiver timeout value */
  739. mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT));
  740. mce_sync_in(ir, NULL, maxp);
  741. /* get receiver sensor setting */
  742. mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR));
  743. mce_sync_in(ir, NULL, maxp);
  744. }
  745. static struct input_dev *mceusb_init_input_dev(struct mceusb_dev *ir)
  746. {
  747. struct input_dev *idev;
  748. struct ir_dev_props *props;
  749. struct ir_input_dev *irdev;
  750. struct device *dev = ir->dev;
  751. int ret = -ENODEV;
  752. idev = input_allocate_device();
  753. if (!idev) {
  754. dev_err(dev, "remote input dev allocation failed\n");
  755. goto idev_alloc_failed;
  756. }
  757. ret = -ENOMEM;
  758. props = kzalloc(sizeof(struct ir_dev_props), GFP_KERNEL);
  759. if (!props) {
  760. dev_err(dev, "remote ir dev props allocation failed\n");
  761. goto props_alloc_failed;
  762. }
  763. irdev = kzalloc(sizeof(struct ir_input_dev), GFP_KERNEL);
  764. if (!irdev) {
  765. dev_err(dev, "remote ir input dev allocation failed\n");
  766. goto ir_dev_alloc_failed;
  767. }
  768. snprintf(ir->name, sizeof(ir->name), "Media Center Ed. eHome "
  769. "Infrared Remote Transceiver (%04x:%04x)",
  770. le16_to_cpu(ir->usbdev->descriptor.idVendor),
  771. le16_to_cpu(ir->usbdev->descriptor.idProduct));
  772. idev->name = ir->name;
  773. usb_make_path(ir->usbdev, ir->phys, sizeof(ir->phys));
  774. strlcat(ir->phys, "/input0", sizeof(ir->phys));
  775. idev->phys = ir->phys;
  776. props->priv = ir;
  777. props->driver_type = RC_DRIVER_IR_RAW;
  778. props->allowed_protos = IR_TYPE_ALL;
  779. props->s_tx_mask = mceusb_set_tx_mask;
  780. props->s_tx_carrier = mceusb_set_tx_carrier;
  781. props->tx_ir = mceusb_tx_ir;
  782. ir->props = props;
  783. ir->irdev = irdev;
  784. input_set_drvdata(idev, irdev);
  785. ret = ir_input_register(idev, RC_MAP_RC6_MCE, props, DRIVER_NAME);
  786. if (ret < 0) {
  787. dev_err(dev, "remote input device register failed\n");
  788. goto irdev_failed;
  789. }
  790. return idev;
  791. irdev_failed:
  792. kfree(irdev);
  793. ir_dev_alloc_failed:
  794. kfree(props);
  795. props_alloc_failed:
  796. input_free_device(idev);
  797. idev_alloc_failed:
  798. return NULL;
  799. }
  800. static int __devinit mceusb_dev_probe(struct usb_interface *intf,
  801. const struct usb_device_id *id)
  802. {
  803. struct usb_device *dev = interface_to_usbdev(intf);
  804. struct usb_host_interface *idesc;
  805. struct usb_endpoint_descriptor *ep = NULL;
  806. struct usb_endpoint_descriptor *ep_in = NULL;
  807. struct usb_endpoint_descriptor *ep_out = NULL;
  808. struct usb_host_config *config;
  809. struct mceusb_dev *ir = NULL;
  810. int pipe, maxp, i;
  811. char buf[63], name[128] = "";
  812. bool is_gen3;
  813. bool is_microsoft_gen1;
  814. bool tx_mask_inverted;
  815. dev_dbg(&intf->dev, ": %s called\n", __func__);
  816. config = dev->actconfig;
  817. idesc = intf->cur_altsetting;
  818. is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0;
  819. is_microsoft_gen1 = usb_match_id(intf, microsoft_gen1_list) ? 1 : 0;
  820. tx_mask_inverted = usb_match_id(intf, std_tx_mask_list) ? 0 : 1;
  821. /* step through the endpoints to find first bulk in and out endpoint */
  822. for (i = 0; i < idesc->desc.bNumEndpoints; ++i) {
  823. ep = &idesc->endpoint[i].desc;
  824. if ((ep_in == NULL)
  825. && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  826. == USB_DIR_IN)
  827. && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  828. == USB_ENDPOINT_XFER_BULK)
  829. || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  830. == USB_ENDPOINT_XFER_INT))) {
  831. ep_in = ep;
  832. ep_in->bmAttributes = USB_ENDPOINT_XFER_INT;
  833. ep_in->bInterval = 1;
  834. dev_dbg(&intf->dev, ": acceptable inbound endpoint "
  835. "found\n");
  836. }
  837. if ((ep_out == NULL)
  838. && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK)
  839. == USB_DIR_OUT)
  840. && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  841. == USB_ENDPOINT_XFER_BULK)
  842. || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK)
  843. == USB_ENDPOINT_XFER_INT))) {
  844. ep_out = ep;
  845. ep_out->bmAttributes = USB_ENDPOINT_XFER_INT;
  846. ep_out->bInterval = 1;
  847. dev_dbg(&intf->dev, ": acceptable outbound endpoint "
  848. "found\n");
  849. }
  850. }
  851. if (ep_in == NULL) {
  852. dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n");
  853. return -ENODEV;
  854. }
  855. pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress);
  856. maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
  857. ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL);
  858. if (!ir)
  859. goto mem_alloc_fail;
  860. ir->buf_in = usb_alloc_coherent(dev, maxp, GFP_ATOMIC, &ir->dma_in);
  861. if (!ir->buf_in)
  862. goto buf_in_alloc_fail;
  863. ir->urb_in = usb_alloc_urb(0, GFP_KERNEL);
  864. if (!ir->urb_in)
  865. goto urb_in_alloc_fail;
  866. ir->usbdev = dev;
  867. ir->dev = &intf->dev;
  868. ir->len_in = maxp;
  869. ir->flags.microsoft_gen1 = is_microsoft_gen1;
  870. ir->flags.tx_mask_inverted = tx_mask_inverted;
  871. /* Saving usb interface data for use by the transmitter routine */
  872. ir->usb_ep_in = ep_in;
  873. ir->usb_ep_out = ep_out;
  874. if (dev->descriptor.iManufacturer
  875. && usb_string(dev, dev->descriptor.iManufacturer,
  876. buf, sizeof(buf)) > 0)
  877. strlcpy(name, buf, sizeof(name));
  878. if (dev->descriptor.iProduct
  879. && usb_string(dev, dev->descriptor.iProduct,
  880. buf, sizeof(buf)) > 0)
  881. snprintf(name + strlen(name), sizeof(name) - strlen(name),
  882. " %s", buf);
  883. ir->idev = mceusb_init_input_dev(ir);
  884. if (!ir->idev)
  885. goto input_dev_fail;
  886. /* flush buffers on the device */
  887. mce_sync_in(ir, NULL, maxp);
  888. mce_sync_in(ir, NULL, maxp);
  889. /* wire up inbound data handler */
  890. usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in,
  891. maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval);
  892. ir->urb_in->transfer_dma = ir->dma_in;
  893. ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  894. /* initialize device */
  895. if (ir->flags.microsoft_gen1)
  896. mceusb_gen1_init(ir);
  897. else if (!is_gen3)
  898. mceusb_gen2_init(ir);
  899. mceusb_get_parameters(ir);
  900. mceusb_set_tx_mask(ir, MCE_DEFAULT_TX_MASK);
  901. usb_set_intfdata(intf, ir);
  902. dev_info(&intf->dev, "Registered %s on usb%d:%d\n", name,
  903. dev->bus->busnum, dev->devnum);
  904. return 0;
  905. /* Error-handling path */
  906. input_dev_fail:
  907. usb_free_urb(ir->urb_in);
  908. urb_in_alloc_fail:
  909. usb_free_coherent(dev, maxp, ir->buf_in, ir->dma_in);
  910. buf_in_alloc_fail:
  911. kfree(ir);
  912. mem_alloc_fail:
  913. dev_err(&intf->dev, "%s: device setup failed!\n", __func__);
  914. return -ENOMEM;
  915. }
  916. static void __devexit mceusb_dev_disconnect(struct usb_interface *intf)
  917. {
  918. struct usb_device *dev = interface_to_usbdev(intf);
  919. struct mceusb_dev *ir = usb_get_intfdata(intf);
  920. usb_set_intfdata(intf, NULL);
  921. if (!ir)
  922. return;
  923. ir->usbdev = NULL;
  924. ir_input_unregister(ir->idev);
  925. usb_kill_urb(ir->urb_in);
  926. usb_free_urb(ir->urb_in);
  927. usb_free_coherent(dev, ir->len_in, ir->buf_in, ir->dma_in);
  928. kfree(ir);
  929. }
  930. static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message)
  931. {
  932. struct mceusb_dev *ir = usb_get_intfdata(intf);
  933. dev_info(ir->dev, "suspend\n");
  934. usb_kill_urb(ir->urb_in);
  935. return 0;
  936. }
  937. static int mceusb_dev_resume(struct usb_interface *intf)
  938. {
  939. struct mceusb_dev *ir = usb_get_intfdata(intf);
  940. dev_info(ir->dev, "resume\n");
  941. if (usb_submit_urb(ir->urb_in, GFP_ATOMIC))
  942. return -EIO;
  943. return 0;
  944. }
  945. static struct usb_driver mceusb_dev_driver = {
  946. .name = DRIVER_NAME,
  947. .probe = mceusb_dev_probe,
  948. .disconnect = mceusb_dev_disconnect,
  949. .suspend = mceusb_dev_suspend,
  950. .resume = mceusb_dev_resume,
  951. .reset_resume = mceusb_dev_resume,
  952. .id_table = mceusb_dev_table
  953. };
  954. static int __init mceusb_dev_init(void)
  955. {
  956. int ret;
  957. ret = usb_register(&mceusb_dev_driver);
  958. if (ret < 0)
  959. printk(KERN_ERR DRIVER_NAME
  960. ": usb register failed, result = %d\n", ret);
  961. return ret;
  962. }
  963. static void __exit mceusb_dev_exit(void)
  964. {
  965. usb_deregister(&mceusb_dev_driver);
  966. }
  967. module_init(mceusb_dev_init);
  968. module_exit(mceusb_dev_exit);
  969. MODULE_DESCRIPTION(DRIVER_DESC);
  970. MODULE_AUTHOR(DRIVER_AUTHOR);
  971. MODULE_LICENSE("GPL");
  972. MODULE_DEVICE_TABLE(usb, mceusb_dev_table);
  973. module_param(debug, bool, S_IRUGO | S_IWUSR);
  974. MODULE_PARM_DESC(debug, "Debug enabled or not");