redrat3.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /*
  2. * USB RedRat3 IR Transceiver rc-core driver
  3. *
  4. * Copyright (c) 2011 by Jarod Wilson <jarod@redhat.com>
  5. * based heavily on the work of Stephen Cox, with additional
  6. * help from RedRat Ltd.
  7. *
  8. * This driver began life based an an old version of the first-generation
  9. * lirc_mceusb driver from the lirc 0.7.2 distribution. It was then
  10. * significantly rewritten by Stephen Cox with the aid of RedRat Ltd's
  11. * Chris Dodge.
  12. *
  13. * The driver was then ported to rc-core and significantly rewritten again,
  14. * by Jarod, using the in-kernel mceusb driver as a guide, after an initial
  15. * port effort was started by Stephen.
  16. *
  17. * TODO LIST:
  18. * - fix lirc not showing repeats properly
  19. * --
  20. *
  21. * The RedRat3 is a USB transceiver with both send & receive,
  22. * with 2 separate sensors available for receive to enable
  23. * both good long range reception for general use, and good
  24. * short range reception when required for learning a signal.
  25. *
  26. * http://www.redrat.co.uk/
  27. *
  28. * It uses its own little protocol to communicate, the required
  29. * parts of which are embedded within this driver.
  30. * --
  31. *
  32. * This program is free software; you can redistribute it and/or modify
  33. * it under the terms of the GNU General Public License as published by
  34. * the Free Software Foundation; either version 2 of the License, or
  35. * (at your option) any later version.
  36. *
  37. * This program is distributed in the hope that it will be useful,
  38. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  40. * GNU General Public License for more details.
  41. *
  42. */
  43. #include <asm/unaligned.h>
  44. #include <linux/device.h>
  45. #include <linux/leds.h>
  46. #include <linux/module.h>
  47. #include <linux/slab.h>
  48. #include <linux/usb.h>
  49. #include <linux/usb/input.h>
  50. #include <media/rc-core.h>
  51. /* Driver Information */
  52. #define DRIVER_AUTHOR "Jarod Wilson <jarod@redhat.com>"
  53. #define DRIVER_AUTHOR2 "The Dweller, Stephen Cox"
  54. #define DRIVER_DESC "RedRat3 USB IR Transceiver Driver"
  55. #define DRIVER_NAME "redrat3"
  56. /* bulk data transfer types */
  57. #define RR3_ERROR 0x01
  58. #define RR3_MOD_SIGNAL_IN 0x20
  59. #define RR3_MOD_SIGNAL_OUT 0x21
  60. /* Get the RR firmware version */
  61. #define RR3_FW_VERSION 0xb1
  62. #define RR3_FW_VERSION_LEN 64
  63. /* Send encoded signal bulk-sent earlier*/
  64. #define RR3_TX_SEND_SIGNAL 0xb3
  65. #define RR3_SET_IR_PARAM 0xb7
  66. #define RR3_GET_IR_PARAM 0xb8
  67. /* Blink the red LED on the device */
  68. #define RR3_BLINK_LED 0xb9
  69. /* Read serial number of device */
  70. #define RR3_READ_SER_NO 0xba
  71. #define RR3_SER_NO_LEN 4
  72. /* Start capture with the RC receiver */
  73. #define RR3_RC_DET_ENABLE 0xbb
  74. /* Stop capture with the RC receiver */
  75. #define RR3_RC_DET_DISABLE 0xbc
  76. /* Start capture with the wideband receiver */
  77. #define RR3_MODSIG_CAPTURE 0xb2
  78. /* Return the status of RC detector capture */
  79. #define RR3_RC_DET_STATUS 0xbd
  80. /* Reset redrat */
  81. #define RR3_RESET 0xa0
  82. /* Max number of lengths in the signal. */
  83. #define RR3_IR_IO_MAX_LENGTHS 0x01
  84. /* Periods to measure mod. freq. */
  85. #define RR3_IR_IO_PERIODS_MF 0x02
  86. /* Size of memory for main signal data */
  87. #define RR3_IR_IO_SIG_MEM_SIZE 0x03
  88. /* Delta value when measuring lengths */
  89. #define RR3_IR_IO_LENGTH_FUZZ 0x04
  90. /* Timeout for end of signal detection */
  91. #define RR3_IR_IO_SIG_TIMEOUT 0x05
  92. /* Minimum value for pause recognition. */
  93. #define RR3_IR_IO_MIN_PAUSE 0x06
  94. /* Clock freq. of EZ-USB chip */
  95. #define RR3_CLK 24000000
  96. /* Clock periods per timer count */
  97. #define RR3_CLK_PER_COUNT 12
  98. /* (RR3_CLK / RR3_CLK_PER_COUNT) */
  99. #define RR3_CLK_CONV_FACTOR 2000000
  100. /* USB bulk-in wideband IR data endpoint address */
  101. #define RR3_WIDE_IN_EP_ADDR 0x81
  102. /* USB bulk-in narrowband IR data endpoint address */
  103. #define RR3_NARROW_IN_EP_ADDR 0x82
  104. /* Size of the fixed-length portion of the signal */
  105. #define RR3_DRIVER_MAXLENS 255
  106. #define RR3_MAX_SIG_SIZE 512
  107. #define RR3_TIME_UNIT 50
  108. #define RR3_END_OF_SIGNAL 0x7f
  109. #define RR3_TX_TRAILER_LEN 2
  110. #define RR3_RX_MIN_TIMEOUT 5
  111. #define RR3_RX_MAX_TIMEOUT 2000
  112. /* The 8051's CPUCS Register address */
  113. #define RR3_CPUCS_REG_ADDR 0x7f92
  114. #define USB_RR3USB_VENDOR_ID 0x112a
  115. #define USB_RR3USB_PRODUCT_ID 0x0001
  116. #define USB_RR3IIUSB_PRODUCT_ID 0x0005
  117. /*
  118. * The redrat3 encodes an IR signal as set of different lengths and a set
  119. * of indices into those lengths. This sets how much two lengths must
  120. * differ before they are considered distinct, the value is specified
  121. * in microseconds.
  122. * Default 5, value 0 to 127.
  123. */
  124. static int length_fuzz = 5;
  125. module_param(length_fuzz, uint, 0644);
  126. MODULE_PARM_DESC(length_fuzz, "Length Fuzz (0-127)");
  127. /*
  128. * When receiving a continuous ir stream (for example when a user is
  129. * holding a button down on a remote), this specifies the minimum size
  130. * of a space when the redrat3 sends a irdata packet to the host. Specified
  131. * in miliseconds. Default value 18ms.
  132. * The value can be between 2 and 30 inclusive.
  133. */
  134. static int minimum_pause = 18;
  135. module_param(minimum_pause, uint, 0644);
  136. MODULE_PARM_DESC(minimum_pause, "Minimum Pause in ms (2-30)");
  137. /*
  138. * The carrier frequency is measured during the first pulse of the IR
  139. * signal. The larger the number of periods used To measure, the more
  140. * accurate the result is likely to be, however some signals have short
  141. * initial pulses, so in some case it may be necessary to reduce this value.
  142. * Default 8, value 1 to 255.
  143. */
  144. static int periods_measure_carrier = 8;
  145. module_param(periods_measure_carrier, uint, 0644);
  146. MODULE_PARM_DESC(periods_measure_carrier, "Number of Periods to Measure Carrier (1-255)");
  147. struct redrat3_header {
  148. __be16 length;
  149. __be16 transfer_type;
  150. } __packed;
  151. /* sending and receiving irdata */
  152. struct redrat3_irdata {
  153. struct redrat3_header header;
  154. __be32 pause;
  155. __be16 mod_freq_count;
  156. __be16 num_periods;
  157. __u8 max_lengths;
  158. __u8 no_lengths;
  159. __be16 max_sig_size;
  160. __be16 sig_size;
  161. __u8 no_repeats;
  162. __be16 lens[RR3_DRIVER_MAXLENS]; /* not aligned */
  163. __u8 sigdata[RR3_MAX_SIG_SIZE];
  164. } __packed;
  165. /* firmware errors */
  166. struct redrat3_error {
  167. struct redrat3_header header;
  168. __be16 fw_error;
  169. } __packed;
  170. /* table of devices that work with this driver */
  171. static const struct usb_device_id redrat3_dev_table[] = {
  172. /* Original version of the RedRat3 */
  173. {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3USB_PRODUCT_ID)},
  174. /* Second Version/release of the RedRat3 - RetRat3-II */
  175. {USB_DEVICE(USB_RR3USB_VENDOR_ID, USB_RR3IIUSB_PRODUCT_ID)},
  176. {} /* Terminating entry */
  177. };
  178. /* Structure to hold all of our device specific stuff */
  179. struct redrat3_dev {
  180. /* core device bits */
  181. struct rc_dev *rc;
  182. struct device *dev;
  183. /* led control */
  184. struct led_classdev led;
  185. atomic_t flash;
  186. struct usb_ctrlrequest flash_control;
  187. struct urb *flash_urb;
  188. u8 flash_in_buf;
  189. /* learning */
  190. bool wideband;
  191. struct usb_ctrlrequest learn_control;
  192. struct urb *learn_urb;
  193. u8 learn_buf;
  194. /* save off the usb device pointer */
  195. struct usb_device *udev;
  196. /* the receive endpoint */
  197. struct usb_endpoint_descriptor *ep_narrow;
  198. /* the buffer to receive data */
  199. void *bulk_in_buf;
  200. /* urb used to read ir data */
  201. struct urb *narrow_urb;
  202. struct urb *wide_urb;
  203. /* the send endpoint */
  204. struct usb_endpoint_descriptor *ep_out;
  205. /* usb dma */
  206. dma_addr_t dma_in;
  207. /* Is the device currently transmitting?*/
  208. bool transmitting;
  209. /* store for current packet */
  210. struct redrat3_irdata irdata;
  211. u16 bytes_read;
  212. u32 carrier;
  213. char name[64];
  214. char phys[64];
  215. };
  216. static void redrat3_dump_fw_error(struct redrat3_dev *rr3, int code)
  217. {
  218. if (!rr3->transmitting && (code != 0x40))
  219. dev_info(rr3->dev, "fw error code 0x%02x: ", code);
  220. switch (code) {
  221. case 0x00:
  222. pr_cont("No Error\n");
  223. break;
  224. /* Codes 0x20 through 0x2f are IR Firmware Errors */
  225. case 0x20:
  226. pr_cont("Initial signal pulse not long enough to measure carrier frequency\n");
  227. break;
  228. case 0x21:
  229. pr_cont("Not enough length values allocated for signal\n");
  230. break;
  231. case 0x22:
  232. pr_cont("Not enough memory allocated for signal data\n");
  233. break;
  234. case 0x23:
  235. pr_cont("Too many signal repeats\n");
  236. break;
  237. case 0x28:
  238. pr_cont("Insufficient memory available for IR signal data memory allocation\n");
  239. break;
  240. case 0x29:
  241. pr_cont("Insufficient memory available for IrDa signal data memory allocation\n");
  242. break;
  243. /* Codes 0x30 through 0x3f are USB Firmware Errors */
  244. case 0x30:
  245. pr_cont("Insufficient memory available for bulk transfer structure\n");
  246. break;
  247. /*
  248. * Other error codes... These are primarily errors that can occur in
  249. * the control messages sent to the redrat
  250. */
  251. case 0x40:
  252. if (!rr3->transmitting)
  253. pr_cont("Signal capture has been terminated\n");
  254. break;
  255. case 0x41:
  256. pr_cont("Attempt to set/get and unknown signal I/O algorithm parameter\n");
  257. break;
  258. case 0x42:
  259. pr_cont("Signal capture already started\n");
  260. break;
  261. default:
  262. pr_cont("Unknown Error\n");
  263. break;
  264. }
  265. }
  266. static u32 redrat3_val_to_mod_freq(struct redrat3_irdata *irdata)
  267. {
  268. u32 mod_freq = 0;
  269. u16 mod_freq_count = be16_to_cpu(irdata->mod_freq_count);
  270. if (mod_freq_count != 0)
  271. mod_freq = (RR3_CLK * be16_to_cpu(irdata->num_periods)) /
  272. (mod_freq_count * RR3_CLK_PER_COUNT);
  273. return mod_freq;
  274. }
  275. /* this function scales down the figures for the same result... */
  276. static u32 redrat3_len_to_us(u32 length)
  277. {
  278. u32 biglen = length * 1000;
  279. u32 divisor = (RR3_CLK_CONV_FACTOR) / 1000;
  280. u32 result = (u32) (biglen / divisor);
  281. /* don't allow zero lengths to go back, breaks lirc */
  282. return result ? result : 1;
  283. }
  284. /*
  285. * convert us back into redrat3 lengths
  286. *
  287. * length * 1000 length * 1000000
  288. * ------------- = ---------------- = micro
  289. * rr3clk / 1000 rr3clk
  290. * 6 * 2 4 * 3 micro * rr3clk micro * rr3clk / 1000
  291. * ----- = 4 ----- = 6 -------------- = len ---------------------
  292. * 3 2 1000000 1000
  293. */
  294. static u32 redrat3_us_to_len(u32 microsec)
  295. {
  296. u32 result;
  297. u32 divisor;
  298. microsec = (microsec > IR_MAX_DURATION) ? IR_MAX_DURATION : microsec;
  299. divisor = (RR3_CLK_CONV_FACTOR / 1000);
  300. result = (u32)(microsec * divisor) / 1000;
  301. /* don't allow zero lengths to go back, breaks lirc */
  302. return result ? result : 1;
  303. }
  304. static void redrat3_process_ir_data(struct redrat3_dev *rr3)
  305. {
  306. DEFINE_IR_RAW_EVENT(rawir);
  307. struct device *dev;
  308. unsigned int i, sig_size, single_len, offset, val;
  309. u32 mod_freq;
  310. dev = rr3->dev;
  311. mod_freq = redrat3_val_to_mod_freq(&rr3->irdata);
  312. dev_dbg(dev, "Got mod_freq of %u\n", mod_freq);
  313. if (mod_freq && rr3->wideband) {
  314. DEFINE_IR_RAW_EVENT(ev);
  315. ev.carrier_report = 1;
  316. ev.carrier = mod_freq;
  317. ir_raw_event_store(rr3->rc, &ev);
  318. }
  319. /* process each rr3 encoded byte into an int */
  320. sig_size = be16_to_cpu(rr3->irdata.sig_size);
  321. for (i = 0; i < sig_size; i++) {
  322. offset = rr3->irdata.sigdata[i];
  323. val = get_unaligned_be16(&rr3->irdata.lens[offset]);
  324. single_len = redrat3_len_to_us(val);
  325. /* we should always get pulse/space/pulse/space samples */
  326. if (i % 2)
  327. rawir.pulse = false;
  328. else
  329. rawir.pulse = true;
  330. rawir.duration = US_TO_NS(single_len);
  331. /* cap the value to IR_MAX_DURATION */
  332. rawir.duration = (rawir.duration > IR_MAX_DURATION) ?
  333. IR_MAX_DURATION : rawir.duration;
  334. dev_dbg(dev, "storing %s with duration %d (i: %d)\n",
  335. rawir.pulse ? "pulse" : "space", rawir.duration, i);
  336. ir_raw_event_store_with_filter(rr3->rc, &rawir);
  337. }
  338. /* add a trailing space */
  339. rawir.pulse = false;
  340. rawir.timeout = true;
  341. rawir.duration = rr3->rc->timeout;
  342. dev_dbg(dev, "storing trailing timeout with duration %d\n",
  343. rawir.duration);
  344. ir_raw_event_store_with_filter(rr3->rc, &rawir);
  345. dev_dbg(dev, "calling ir_raw_event_handle\n");
  346. ir_raw_event_handle(rr3->rc);
  347. }
  348. /* Util fn to send rr3 cmds */
  349. static int redrat3_send_cmd(int cmd, struct redrat3_dev *rr3)
  350. {
  351. struct usb_device *udev;
  352. u8 *data;
  353. int res;
  354. data = kzalloc(sizeof(u8), GFP_KERNEL);
  355. if (!data)
  356. return -ENOMEM;
  357. udev = rr3->udev;
  358. res = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0), cmd,
  359. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  360. 0x0000, 0x0000, data, sizeof(u8), HZ * 10);
  361. if (res < 0) {
  362. dev_err(rr3->dev, "%s: Error sending rr3 cmd res %d, data %d",
  363. __func__, res, *data);
  364. res = -EIO;
  365. } else
  366. res = data[0];
  367. kfree(data);
  368. return res;
  369. }
  370. /* Enables the long range detector and starts async receive */
  371. static int redrat3_enable_detector(struct redrat3_dev *rr3)
  372. {
  373. struct device *dev = rr3->dev;
  374. u8 ret;
  375. ret = redrat3_send_cmd(RR3_RC_DET_ENABLE, rr3);
  376. if (ret != 0)
  377. dev_dbg(dev, "%s: unexpected ret of %d\n",
  378. __func__, ret);
  379. ret = redrat3_send_cmd(RR3_RC_DET_STATUS, rr3);
  380. if (ret != 1) {
  381. dev_err(dev, "%s: detector status: %d, should be 1\n",
  382. __func__, ret);
  383. return -EIO;
  384. }
  385. ret = usb_submit_urb(rr3->narrow_urb, GFP_KERNEL);
  386. if (ret) {
  387. dev_err(rr3->dev, "narrow band urb failed: %d", ret);
  388. return ret;
  389. }
  390. ret = usb_submit_urb(rr3->wide_urb, GFP_KERNEL);
  391. if (ret)
  392. dev_err(rr3->dev, "wide band urb failed: %d", ret);
  393. return ret;
  394. }
  395. static inline void redrat3_delete(struct redrat3_dev *rr3,
  396. struct usb_device *udev)
  397. {
  398. usb_kill_urb(rr3->narrow_urb);
  399. usb_kill_urb(rr3->wide_urb);
  400. usb_kill_urb(rr3->flash_urb);
  401. usb_kill_urb(rr3->learn_urb);
  402. usb_free_urb(rr3->narrow_urb);
  403. usb_free_urb(rr3->wide_urb);
  404. usb_free_urb(rr3->flash_urb);
  405. usb_free_urb(rr3->learn_urb);
  406. usb_free_coherent(udev, le16_to_cpu(rr3->ep_narrow->wMaxPacketSize),
  407. rr3->bulk_in_buf, rr3->dma_in);
  408. kfree(rr3);
  409. }
  410. static u32 redrat3_get_timeout(struct redrat3_dev *rr3)
  411. {
  412. __be32 *tmp;
  413. u32 timeout = MS_TO_US(150); /* a sane default, if things go haywire */
  414. int len, ret, pipe;
  415. len = sizeof(*tmp);
  416. tmp = kzalloc(len, GFP_KERNEL);
  417. if (!tmp)
  418. return timeout;
  419. pipe = usb_rcvctrlpipe(rr3->udev, 0);
  420. ret = usb_control_msg(rr3->udev, pipe, RR3_GET_IR_PARAM,
  421. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  422. RR3_IR_IO_SIG_TIMEOUT, 0, tmp, len, HZ * 5);
  423. if (ret != len)
  424. dev_warn(rr3->dev, "Failed to read timeout from hardware\n");
  425. else {
  426. timeout = redrat3_len_to_us(be32_to_cpup(tmp));
  427. dev_dbg(rr3->dev, "Got timeout of %d ms\n", timeout / 1000);
  428. }
  429. kfree(tmp);
  430. return timeout;
  431. }
  432. static int redrat3_set_timeout(struct rc_dev *rc_dev, unsigned int timeoutns)
  433. {
  434. struct redrat3_dev *rr3 = rc_dev->priv;
  435. struct usb_device *udev = rr3->udev;
  436. struct device *dev = rr3->dev;
  437. __be32 *timeout;
  438. int ret;
  439. timeout = kmalloc(sizeof(*timeout), GFP_KERNEL);
  440. if (!timeout)
  441. return -ENOMEM;
  442. *timeout = cpu_to_be32(redrat3_us_to_len(timeoutns / 1000));
  443. ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), RR3_SET_IR_PARAM,
  444. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  445. RR3_IR_IO_SIG_TIMEOUT, 0, timeout, sizeof(*timeout),
  446. HZ * 25);
  447. dev_dbg(dev, "set ir parm timeout %d ret 0x%02x\n",
  448. be32_to_cpu(*timeout), ret);
  449. if (ret == sizeof(*timeout))
  450. ret = 0;
  451. else if (ret >= 0)
  452. ret = -EIO;
  453. kfree(timeout);
  454. return ret;
  455. }
  456. static void redrat3_reset(struct redrat3_dev *rr3)
  457. {
  458. struct usb_device *udev = rr3->udev;
  459. struct device *dev = rr3->dev;
  460. int rc, rxpipe, txpipe;
  461. u8 *val;
  462. size_t const len = sizeof(*val);
  463. rxpipe = usb_rcvctrlpipe(udev, 0);
  464. txpipe = usb_sndctrlpipe(udev, 0);
  465. val = kmalloc(len, GFP_KERNEL);
  466. if (!val)
  467. return;
  468. *val = 0x01;
  469. rc = usb_control_msg(udev, rxpipe, RR3_RESET,
  470. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  471. RR3_CPUCS_REG_ADDR, 0, val, len, HZ * 25);
  472. dev_dbg(dev, "reset returned 0x%02x\n", rc);
  473. *val = length_fuzz;
  474. rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
  475. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  476. RR3_IR_IO_LENGTH_FUZZ, 0, val, len, HZ * 25);
  477. dev_dbg(dev, "set ir parm len fuzz %d rc 0x%02x\n", *val, rc);
  478. *val = (65536 - (minimum_pause * 2000)) / 256;
  479. rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
  480. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  481. RR3_IR_IO_MIN_PAUSE, 0, val, len, HZ * 25);
  482. dev_dbg(dev, "set ir parm min pause %d rc 0x%02x\n", *val, rc);
  483. *val = periods_measure_carrier;
  484. rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
  485. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  486. RR3_IR_IO_PERIODS_MF, 0, val, len, HZ * 25);
  487. dev_dbg(dev, "set ir parm periods measure carrier %d rc 0x%02x", *val,
  488. rc);
  489. *val = RR3_DRIVER_MAXLENS;
  490. rc = usb_control_msg(udev, txpipe, RR3_SET_IR_PARAM,
  491. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_OUT,
  492. RR3_IR_IO_MAX_LENGTHS, 0, val, len, HZ * 25);
  493. dev_dbg(dev, "set ir parm max lens %d rc 0x%02x\n", *val, rc);
  494. kfree(val);
  495. }
  496. static void redrat3_get_firmware_rev(struct redrat3_dev *rr3)
  497. {
  498. int rc;
  499. char *buffer;
  500. buffer = kcalloc(RR3_FW_VERSION_LEN + 1, sizeof(*buffer), GFP_KERNEL);
  501. if (!buffer)
  502. return;
  503. rc = usb_control_msg(rr3->udev, usb_rcvctrlpipe(rr3->udev, 0),
  504. RR3_FW_VERSION,
  505. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  506. 0, 0, buffer, RR3_FW_VERSION_LEN, HZ * 5);
  507. if (rc >= 0)
  508. dev_info(rr3->dev, "Firmware rev: %s", buffer);
  509. else
  510. dev_err(rr3->dev, "Problem fetching firmware ID\n");
  511. kfree(buffer);
  512. }
  513. static void redrat3_read_packet_start(struct redrat3_dev *rr3, unsigned len)
  514. {
  515. struct redrat3_header *header = rr3->bulk_in_buf;
  516. unsigned pktlen, pkttype;
  517. /* grab the Length and type of transfer */
  518. pktlen = be16_to_cpu(header->length);
  519. pkttype = be16_to_cpu(header->transfer_type);
  520. if (pktlen > sizeof(rr3->irdata)) {
  521. dev_warn(rr3->dev, "packet length %u too large\n", pktlen);
  522. return;
  523. }
  524. switch (pkttype) {
  525. case RR3_ERROR:
  526. if (len >= sizeof(struct redrat3_error)) {
  527. struct redrat3_error *error = rr3->bulk_in_buf;
  528. unsigned fw_error = be16_to_cpu(error->fw_error);
  529. redrat3_dump_fw_error(rr3, fw_error);
  530. }
  531. break;
  532. case RR3_MOD_SIGNAL_IN:
  533. memcpy(&rr3->irdata, rr3->bulk_in_buf, len);
  534. rr3->bytes_read = len;
  535. dev_dbg(rr3->dev, "bytes_read %d, pktlen %d\n",
  536. rr3->bytes_read, pktlen);
  537. break;
  538. default:
  539. dev_dbg(rr3->dev, "ignoring packet with type 0x%02x, len of %d, 0x%02x\n",
  540. pkttype, len, pktlen);
  541. break;
  542. }
  543. }
  544. static void redrat3_read_packet_continue(struct redrat3_dev *rr3, unsigned len)
  545. {
  546. void *irdata = &rr3->irdata;
  547. if (len + rr3->bytes_read > sizeof(rr3->irdata)) {
  548. dev_warn(rr3->dev, "too much data for packet\n");
  549. rr3->bytes_read = 0;
  550. return;
  551. }
  552. memcpy(irdata + rr3->bytes_read, rr3->bulk_in_buf, len);
  553. rr3->bytes_read += len;
  554. dev_dbg(rr3->dev, "bytes_read %d, pktlen %d\n", rr3->bytes_read,
  555. be16_to_cpu(rr3->irdata.header.length));
  556. }
  557. /* gather IR data from incoming urb, process it when we have enough */
  558. static int redrat3_get_ir_data(struct redrat3_dev *rr3, unsigned len)
  559. {
  560. struct device *dev = rr3->dev;
  561. unsigned pkttype;
  562. int ret = 0;
  563. if (rr3->bytes_read == 0 && len >= sizeof(struct redrat3_header)) {
  564. redrat3_read_packet_start(rr3, len);
  565. } else if (rr3->bytes_read != 0) {
  566. redrat3_read_packet_continue(rr3, len);
  567. } else if (rr3->bytes_read == 0) {
  568. dev_err(dev, "error: no packet data read\n");
  569. ret = -ENODATA;
  570. goto out;
  571. }
  572. if (rr3->bytes_read < be16_to_cpu(rr3->irdata.header.length) +
  573. sizeof(struct redrat3_header))
  574. /* we're still accumulating data */
  575. return 0;
  576. /* if we get here, we've got IR data to decode */
  577. pkttype = be16_to_cpu(rr3->irdata.header.transfer_type);
  578. if (pkttype == RR3_MOD_SIGNAL_IN)
  579. redrat3_process_ir_data(rr3);
  580. else
  581. dev_dbg(dev, "discarding non-signal data packet (type 0x%02x)\n",
  582. pkttype);
  583. out:
  584. rr3->bytes_read = 0;
  585. return ret;
  586. }
  587. /* callback function from USB when async USB request has completed */
  588. static void redrat3_handle_async(struct urb *urb)
  589. {
  590. struct redrat3_dev *rr3 = urb->context;
  591. int ret;
  592. switch (urb->status) {
  593. case 0:
  594. ret = redrat3_get_ir_data(rr3, urb->actual_length);
  595. if (!ret && rr3->wideband && !rr3->learn_urb->hcpriv) {
  596. ret = usb_submit_urb(rr3->learn_urb, GFP_ATOMIC);
  597. if (ret)
  598. dev_err(rr3->dev, "Failed to submit learning urb: %d",
  599. ret);
  600. }
  601. if (!ret) {
  602. /* no error, prepare to read more */
  603. ret = usb_submit_urb(urb, GFP_ATOMIC);
  604. if (ret)
  605. dev_err(rr3->dev, "Failed to resubmit urb: %d",
  606. ret);
  607. }
  608. break;
  609. case -ECONNRESET:
  610. case -ENOENT:
  611. case -ESHUTDOWN:
  612. usb_unlink_urb(urb);
  613. return;
  614. case -EPIPE:
  615. default:
  616. dev_warn(rr3->dev, "Error: urb status = %d\n", urb->status);
  617. rr3->bytes_read = 0;
  618. break;
  619. }
  620. }
  621. static u16 mod_freq_to_val(unsigned int mod_freq)
  622. {
  623. int mult = 6000000;
  624. /* Clk used in mod. freq. generation is CLK24/4. */
  625. return 65536 - (mult / mod_freq);
  626. }
  627. static int redrat3_set_tx_carrier(struct rc_dev *rcdev, u32 carrier)
  628. {
  629. struct redrat3_dev *rr3 = rcdev->priv;
  630. struct device *dev = rr3->dev;
  631. dev_dbg(dev, "Setting modulation frequency to %u", carrier);
  632. if (carrier == 0)
  633. return -EINVAL;
  634. rr3->carrier = carrier;
  635. return 0;
  636. }
  637. static int redrat3_transmit_ir(struct rc_dev *rcdev, unsigned *txbuf,
  638. unsigned count)
  639. {
  640. struct redrat3_dev *rr3 = rcdev->priv;
  641. struct device *dev = rr3->dev;
  642. struct redrat3_irdata *irdata = NULL;
  643. int ret, ret_len;
  644. int lencheck, cur_sample_len, pipe;
  645. int *sample_lens = NULL;
  646. u8 curlencheck = 0;
  647. unsigned i, sendbuf_len;
  648. if (rr3->transmitting) {
  649. dev_warn(dev, "%s: transmitter already in use\n", __func__);
  650. return -EAGAIN;
  651. }
  652. if (count > RR3_MAX_SIG_SIZE - RR3_TX_TRAILER_LEN)
  653. return -EINVAL;
  654. /* rr3 will disable rc detector on transmit */
  655. rr3->transmitting = true;
  656. sample_lens = kcalloc(RR3_DRIVER_MAXLENS,
  657. sizeof(*sample_lens),
  658. GFP_KERNEL);
  659. if (!sample_lens)
  660. return -ENOMEM;
  661. irdata = kzalloc(sizeof(*irdata), GFP_KERNEL);
  662. if (!irdata) {
  663. ret = -ENOMEM;
  664. goto out;
  665. }
  666. for (i = 0; i < count; i++) {
  667. cur_sample_len = redrat3_us_to_len(txbuf[i]);
  668. if (cur_sample_len > 0xffff) {
  669. dev_warn(dev, "transmit period of %uus truncated to %uus\n",
  670. txbuf[i], redrat3_len_to_us(0xffff));
  671. cur_sample_len = 0xffff;
  672. }
  673. for (lencheck = 0; lencheck < curlencheck; lencheck++) {
  674. if (sample_lens[lencheck] == cur_sample_len)
  675. break;
  676. }
  677. if (lencheck == curlencheck) {
  678. dev_dbg(dev, "txbuf[%d]=%u, pos %d, enc %u\n",
  679. i, txbuf[i], curlencheck, cur_sample_len);
  680. if (curlencheck < RR3_DRIVER_MAXLENS) {
  681. /* now convert the value to a proper
  682. * rr3 value.. */
  683. sample_lens[curlencheck] = cur_sample_len;
  684. put_unaligned_be16(cur_sample_len,
  685. &irdata->lens[curlencheck]);
  686. curlencheck++;
  687. } else {
  688. ret = -EINVAL;
  689. goto out;
  690. }
  691. }
  692. irdata->sigdata[i] = lencheck;
  693. }
  694. irdata->sigdata[count] = RR3_END_OF_SIGNAL;
  695. irdata->sigdata[count + 1] = RR3_END_OF_SIGNAL;
  696. sendbuf_len = offsetof(struct redrat3_irdata,
  697. sigdata[count + RR3_TX_TRAILER_LEN]);
  698. /* fill in our packet header */
  699. irdata->header.length = cpu_to_be16(sendbuf_len -
  700. sizeof(struct redrat3_header));
  701. irdata->header.transfer_type = cpu_to_be16(RR3_MOD_SIGNAL_OUT);
  702. irdata->pause = cpu_to_be32(redrat3_len_to_us(100));
  703. irdata->mod_freq_count = cpu_to_be16(mod_freq_to_val(rr3->carrier));
  704. irdata->no_lengths = curlencheck;
  705. irdata->sig_size = cpu_to_be16(count + RR3_TX_TRAILER_LEN);
  706. pipe = usb_sndbulkpipe(rr3->udev, rr3->ep_out->bEndpointAddress);
  707. ret = usb_bulk_msg(rr3->udev, pipe, irdata,
  708. sendbuf_len, &ret_len, 10 * HZ);
  709. dev_dbg(dev, "sent %d bytes, (ret %d)\n", ret_len, ret);
  710. /* now tell the hardware to transmit what we sent it */
  711. pipe = usb_rcvctrlpipe(rr3->udev, 0);
  712. ret = usb_control_msg(rr3->udev, pipe, RR3_TX_SEND_SIGNAL,
  713. USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
  714. 0, 0, irdata, 2, HZ * 10);
  715. if (ret < 0)
  716. dev_err(dev, "Error: control msg send failed, rc %d\n", ret);
  717. else
  718. ret = count;
  719. out:
  720. kfree(irdata);
  721. kfree(sample_lens);
  722. rr3->transmitting = false;
  723. /* rr3 re-enables rc detector because it was enabled before */
  724. return ret;
  725. }
  726. static void redrat3_brightness_set(struct led_classdev *led_dev, enum
  727. led_brightness brightness)
  728. {
  729. struct redrat3_dev *rr3 = container_of(led_dev, struct redrat3_dev,
  730. led);
  731. if (brightness != LED_OFF && atomic_cmpxchg(&rr3->flash, 0, 1) == 0) {
  732. int ret = usb_submit_urb(rr3->flash_urb, GFP_ATOMIC);
  733. if (ret != 0) {
  734. dev_dbg(rr3->dev, "%s: unexpected ret of %d\n",
  735. __func__, ret);
  736. atomic_set(&rr3->flash, 0);
  737. }
  738. }
  739. }
  740. static int redrat3_wideband_receiver(struct rc_dev *rcdev, int enable)
  741. {
  742. struct redrat3_dev *rr3 = rcdev->priv;
  743. int ret = 0;
  744. rr3->wideband = enable != 0;
  745. if (enable) {
  746. ret = usb_submit_urb(rr3->learn_urb, GFP_KERNEL);
  747. if (ret)
  748. dev_err(rr3->dev, "Failed to submit learning urb: %d",
  749. ret);
  750. }
  751. return ret;
  752. }
  753. static void redrat3_learn_complete(struct urb *urb)
  754. {
  755. struct redrat3_dev *rr3 = urb->context;
  756. switch (urb->status) {
  757. case 0:
  758. break;
  759. case -ECONNRESET:
  760. case -ENOENT:
  761. case -ESHUTDOWN:
  762. usb_unlink_urb(urb);
  763. return;
  764. case -EPIPE:
  765. default:
  766. dev_err(rr3->dev, "Error: learn urb status = %d", urb->status);
  767. break;
  768. }
  769. }
  770. static void redrat3_led_complete(struct urb *urb)
  771. {
  772. struct redrat3_dev *rr3 = urb->context;
  773. switch (urb->status) {
  774. case 0:
  775. break;
  776. case -ECONNRESET:
  777. case -ENOENT:
  778. case -ESHUTDOWN:
  779. usb_unlink_urb(urb);
  780. return;
  781. case -EPIPE:
  782. default:
  783. dev_dbg(rr3->dev, "Error: urb status = %d\n", urb->status);
  784. break;
  785. }
  786. rr3->led.brightness = LED_OFF;
  787. atomic_dec(&rr3->flash);
  788. }
  789. static struct rc_dev *redrat3_init_rc_dev(struct redrat3_dev *rr3)
  790. {
  791. struct device *dev = rr3->dev;
  792. struct rc_dev *rc;
  793. int ret;
  794. u16 prod = le16_to_cpu(rr3->udev->descriptor.idProduct);
  795. rc = rc_allocate_device(RC_DRIVER_IR_RAW);
  796. if (!rc)
  797. return NULL;
  798. snprintf(rr3->name, sizeof(rr3->name),
  799. "RedRat3%s Infrared Remote Transceiver",
  800. prod == USB_RR3IIUSB_PRODUCT_ID ? "-II" : "");
  801. usb_make_path(rr3->udev, rr3->phys, sizeof(rr3->phys));
  802. rc->device_name = rr3->name;
  803. rc->input_phys = rr3->phys;
  804. usb_to_input_id(rr3->udev, &rc->input_id);
  805. rc->dev.parent = dev;
  806. rc->priv = rr3;
  807. rc->allowed_protocols = RC_PROTO_BIT_ALL_IR_DECODER;
  808. rc->min_timeout = MS_TO_NS(RR3_RX_MIN_TIMEOUT);
  809. rc->max_timeout = MS_TO_NS(RR3_RX_MAX_TIMEOUT);
  810. rc->timeout = US_TO_NS(redrat3_get_timeout(rr3));
  811. rc->s_timeout = redrat3_set_timeout;
  812. rc->tx_ir = redrat3_transmit_ir;
  813. rc->s_tx_carrier = redrat3_set_tx_carrier;
  814. rc->s_carrier_report = redrat3_wideband_receiver;
  815. rc->driver_name = DRIVER_NAME;
  816. rc->rx_resolution = US_TO_NS(2);
  817. rc->map_name = RC_MAP_HAUPPAUGE;
  818. ret = rc_register_device(rc);
  819. if (ret < 0) {
  820. dev_err(dev, "remote dev registration failed\n");
  821. goto out;
  822. }
  823. return rc;
  824. out:
  825. rc_free_device(rc);
  826. return NULL;
  827. }
  828. static int redrat3_dev_probe(struct usb_interface *intf,
  829. const struct usb_device_id *id)
  830. {
  831. struct usb_device *udev = interface_to_usbdev(intf);
  832. struct device *dev = &intf->dev;
  833. struct usb_host_interface *uhi;
  834. struct redrat3_dev *rr3;
  835. struct usb_endpoint_descriptor *ep;
  836. struct usb_endpoint_descriptor *ep_narrow = NULL;
  837. struct usb_endpoint_descriptor *ep_wide = NULL;
  838. struct usb_endpoint_descriptor *ep_out = NULL;
  839. u8 addr, attrs;
  840. int pipe, i;
  841. int retval = -ENOMEM;
  842. uhi = intf->cur_altsetting;
  843. /* find our bulk-in and bulk-out endpoints */
  844. for (i = 0; i < uhi->desc.bNumEndpoints; ++i) {
  845. ep = &uhi->endpoint[i].desc;
  846. addr = ep->bEndpointAddress;
  847. attrs = ep->bmAttributes;
  848. if (((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN) &&
  849. ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
  850. USB_ENDPOINT_XFER_BULK)) {
  851. dev_dbg(dev, "found bulk-in endpoint at 0x%02x\n",
  852. ep->bEndpointAddress);
  853. /* data comes in on 0x82, 0x81 is for learning */
  854. if (ep->bEndpointAddress == RR3_NARROW_IN_EP_ADDR)
  855. ep_narrow = ep;
  856. if (ep->bEndpointAddress == RR3_WIDE_IN_EP_ADDR)
  857. ep_wide = ep;
  858. }
  859. if ((ep_out == NULL) &&
  860. ((addr & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) &&
  861. ((attrs & USB_ENDPOINT_XFERTYPE_MASK) ==
  862. USB_ENDPOINT_XFER_BULK)) {
  863. dev_dbg(dev, "found bulk-out endpoint at 0x%02x\n",
  864. ep->bEndpointAddress);
  865. ep_out = ep;
  866. }
  867. }
  868. if (!ep_narrow || !ep_out || !ep_wide) {
  869. dev_err(dev, "Couldn't find all endpoints\n");
  870. retval = -ENODEV;
  871. goto no_endpoints;
  872. }
  873. /* allocate memory for our device state and initialize it */
  874. rr3 = kzalloc(sizeof(*rr3), GFP_KERNEL);
  875. if (!rr3)
  876. goto no_endpoints;
  877. rr3->dev = &intf->dev;
  878. rr3->ep_narrow = ep_narrow;
  879. rr3->ep_out = ep_out;
  880. rr3->udev = udev;
  881. /* set up bulk-in endpoint */
  882. rr3->narrow_urb = usb_alloc_urb(0, GFP_KERNEL);
  883. if (!rr3->narrow_urb)
  884. goto redrat_free;
  885. rr3->wide_urb = usb_alloc_urb(0, GFP_KERNEL);
  886. if (!rr3->wide_urb)
  887. goto redrat_free;
  888. rr3->bulk_in_buf = usb_alloc_coherent(udev,
  889. le16_to_cpu(ep_narrow->wMaxPacketSize),
  890. GFP_KERNEL, &rr3->dma_in);
  891. if (!rr3->bulk_in_buf)
  892. goto redrat_free;
  893. pipe = usb_rcvbulkpipe(udev, ep_narrow->bEndpointAddress);
  894. usb_fill_bulk_urb(rr3->narrow_urb, udev, pipe, rr3->bulk_in_buf,
  895. le16_to_cpu(ep_narrow->wMaxPacketSize),
  896. redrat3_handle_async, rr3);
  897. rr3->narrow_urb->transfer_dma = rr3->dma_in;
  898. rr3->narrow_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  899. pipe = usb_rcvbulkpipe(udev, ep_wide->bEndpointAddress);
  900. usb_fill_bulk_urb(rr3->wide_urb, udev, pipe, rr3->bulk_in_buf,
  901. le16_to_cpu(ep_narrow->wMaxPacketSize),
  902. redrat3_handle_async, rr3);
  903. rr3->wide_urb->transfer_dma = rr3->dma_in;
  904. rr3->wide_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
  905. redrat3_reset(rr3);
  906. redrat3_get_firmware_rev(rr3);
  907. /* default.. will get overridden by any sends with a freq defined */
  908. rr3->carrier = 38000;
  909. atomic_set(&rr3->flash, 0);
  910. rr3->flash_urb = usb_alloc_urb(0, GFP_KERNEL);
  911. if (!rr3->flash_urb)
  912. goto redrat_free;
  913. /* learn urb */
  914. rr3->learn_urb = usb_alloc_urb(0, GFP_KERNEL);
  915. if (!rr3->learn_urb)
  916. goto redrat_free;
  917. /* setup packet is 'c0 b2 0000 0000 0001' */
  918. rr3->learn_control.bRequestType = 0xc0;
  919. rr3->learn_control.bRequest = RR3_MODSIG_CAPTURE;
  920. rr3->learn_control.wLength = cpu_to_le16(1);
  921. usb_fill_control_urb(rr3->learn_urb, udev, usb_rcvctrlpipe(udev, 0),
  922. (unsigned char *)&rr3->learn_control,
  923. &rr3->learn_buf, sizeof(rr3->learn_buf),
  924. redrat3_learn_complete, rr3);
  925. /* setup packet is 'c0 b9 0000 0000 0001' */
  926. rr3->flash_control.bRequestType = 0xc0;
  927. rr3->flash_control.bRequest = RR3_BLINK_LED;
  928. rr3->flash_control.wLength = cpu_to_le16(1);
  929. usb_fill_control_urb(rr3->flash_urb, udev, usb_rcvctrlpipe(udev, 0),
  930. (unsigned char *)&rr3->flash_control,
  931. &rr3->flash_in_buf, sizeof(rr3->flash_in_buf),
  932. redrat3_led_complete, rr3);
  933. /* led control */
  934. rr3->led.name = "redrat3:red:feedback";
  935. rr3->led.default_trigger = "rc-feedback";
  936. rr3->led.brightness_set = redrat3_brightness_set;
  937. retval = led_classdev_register(&intf->dev, &rr3->led);
  938. if (retval)
  939. goto redrat_free;
  940. rr3->rc = redrat3_init_rc_dev(rr3);
  941. if (!rr3->rc) {
  942. retval = -ENOMEM;
  943. goto led_free;
  944. }
  945. /* might be all we need to do? */
  946. retval = redrat3_enable_detector(rr3);
  947. if (retval < 0)
  948. goto led_free;
  949. /* we can register the device now, as it is ready */
  950. usb_set_intfdata(intf, rr3);
  951. return 0;
  952. led_free:
  953. led_classdev_unregister(&rr3->led);
  954. redrat_free:
  955. redrat3_delete(rr3, rr3->udev);
  956. no_endpoints:
  957. return retval;
  958. }
  959. static void redrat3_dev_disconnect(struct usb_interface *intf)
  960. {
  961. struct usb_device *udev = interface_to_usbdev(intf);
  962. struct redrat3_dev *rr3 = usb_get_intfdata(intf);
  963. usb_set_intfdata(intf, NULL);
  964. rc_unregister_device(rr3->rc);
  965. led_classdev_unregister(&rr3->led);
  966. redrat3_delete(rr3, udev);
  967. }
  968. static int redrat3_dev_suspend(struct usb_interface *intf, pm_message_t message)
  969. {
  970. struct redrat3_dev *rr3 = usb_get_intfdata(intf);
  971. led_classdev_suspend(&rr3->led);
  972. usb_kill_urb(rr3->narrow_urb);
  973. usb_kill_urb(rr3->wide_urb);
  974. usb_kill_urb(rr3->flash_urb);
  975. return 0;
  976. }
  977. static int redrat3_dev_resume(struct usb_interface *intf)
  978. {
  979. struct redrat3_dev *rr3 = usb_get_intfdata(intf);
  980. if (usb_submit_urb(rr3->narrow_urb, GFP_ATOMIC))
  981. return -EIO;
  982. if (usb_submit_urb(rr3->wide_urb, GFP_ATOMIC))
  983. return -EIO;
  984. led_classdev_resume(&rr3->led);
  985. return 0;
  986. }
  987. static struct usb_driver redrat3_dev_driver = {
  988. .name = DRIVER_NAME,
  989. .probe = redrat3_dev_probe,
  990. .disconnect = redrat3_dev_disconnect,
  991. .suspend = redrat3_dev_suspend,
  992. .resume = redrat3_dev_resume,
  993. .reset_resume = redrat3_dev_resume,
  994. .id_table = redrat3_dev_table
  995. };
  996. module_usb_driver(redrat3_dev_driver);
  997. MODULE_DESCRIPTION(DRIVER_DESC);
  998. MODULE_AUTHOR(DRIVER_AUTHOR);
  999. MODULE_AUTHOR(DRIVER_AUTHOR2);
  1000. MODULE_LICENSE("GPL");
  1001. MODULE_DEVICE_TABLE(usb, redrat3_dev_table);