keyspan_pda.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * USB Keyspan PDA / Xircom / Entrega Converter driver
  4. *
  5. * Copyright (C) 1999 - 2001 Greg Kroah-Hartman <greg@kroah.com>
  6. * Copyright (C) 1999, 2000 Brian Warner <warner@lothar.com>
  7. * Copyright (C) 2000 Al Borchers <borchers@steinerpoint.com>
  8. *
  9. * See Documentation/usb/usb-serial.txt for more information on using this
  10. * driver
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/slab.h>
  15. #include <linux/tty.h>
  16. #include <linux/tty_driver.h>
  17. #include <linux/tty_flip.h>
  18. #include <linux/module.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/uaccess.h>
  22. #include <linux/usb.h>
  23. #include <linux/usb/serial.h>
  24. #include <linux/usb/ezusb.h>
  25. /* make a simple define to handle if we are compiling keyspan_pda or xircom support */
  26. #if IS_ENABLED(CONFIG_USB_SERIAL_KEYSPAN_PDA)
  27. #define KEYSPAN
  28. #else
  29. #undef KEYSPAN
  30. #endif
  31. #if IS_ENABLED(CONFIG_USB_SERIAL_XIRCOM)
  32. #define XIRCOM
  33. #else
  34. #undef XIRCOM
  35. #endif
  36. #define DRIVER_AUTHOR "Brian Warner <warner@lothar.com>"
  37. #define DRIVER_DESC "USB Keyspan PDA Converter driver"
  38. struct keyspan_pda_private {
  39. int tx_room;
  40. int tx_throttled;
  41. struct work_struct wakeup_work;
  42. struct work_struct unthrottle_work;
  43. struct usb_serial *serial;
  44. struct usb_serial_port *port;
  45. };
  46. #define KEYSPAN_VENDOR_ID 0x06cd
  47. #define KEYSPAN_PDA_FAKE_ID 0x0103
  48. #define KEYSPAN_PDA_ID 0x0104 /* no clue */
  49. /* For Xircom PGSDB9 and older Entrega version of the same device */
  50. #define XIRCOM_VENDOR_ID 0x085a
  51. #define XIRCOM_FAKE_ID 0x8027
  52. #define XIRCOM_FAKE_ID_2 0x8025 /* "PGMFHUB" serial */
  53. #define ENTREGA_VENDOR_ID 0x1645
  54. #define ENTREGA_FAKE_ID 0x8093
  55. static const struct usb_device_id id_table_combined[] = {
  56. #ifdef KEYSPAN
  57. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
  58. #endif
  59. #ifdef XIRCOM
  60. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
  61. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) },
  62. { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) },
  63. #endif
  64. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
  65. { } /* Terminating entry */
  66. };
  67. MODULE_DEVICE_TABLE(usb, id_table_combined);
  68. static const struct usb_device_id id_table_std[] = {
  69. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
  70. { } /* Terminating entry */
  71. };
  72. #ifdef KEYSPAN
  73. static const struct usb_device_id id_table_fake[] = {
  74. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
  75. { } /* Terminating entry */
  76. };
  77. #endif
  78. #ifdef XIRCOM
  79. static const struct usb_device_id id_table_fake_xircom[] = {
  80. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
  81. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) },
  82. { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) },
  83. { }
  84. };
  85. #endif
  86. static void keyspan_pda_wakeup_write(struct work_struct *work)
  87. {
  88. struct keyspan_pda_private *priv =
  89. container_of(work, struct keyspan_pda_private, wakeup_work);
  90. struct usb_serial_port *port = priv->port;
  91. tty_port_tty_wakeup(&port->port);
  92. }
  93. static void keyspan_pda_request_unthrottle(struct work_struct *work)
  94. {
  95. struct keyspan_pda_private *priv =
  96. container_of(work, struct keyspan_pda_private, unthrottle_work);
  97. struct usb_serial *serial = priv->serial;
  98. int result;
  99. /* ask the device to tell us when the tx buffer becomes
  100. sufficiently empty */
  101. result = usb_control_msg(serial->dev,
  102. usb_sndctrlpipe(serial->dev, 0),
  103. 7, /* request_unthrottle */
  104. USB_TYPE_VENDOR | USB_RECIP_INTERFACE
  105. | USB_DIR_OUT,
  106. 16, /* value: threshold */
  107. 0, /* index */
  108. NULL,
  109. 0,
  110. 2000);
  111. if (result < 0)
  112. dev_dbg(&serial->dev->dev, "%s - error %d from usb_control_msg\n",
  113. __func__, result);
  114. }
  115. static void keyspan_pda_rx_interrupt(struct urb *urb)
  116. {
  117. struct usb_serial_port *port = urb->context;
  118. unsigned char *data = urb->transfer_buffer;
  119. unsigned int len = urb->actual_length;
  120. int retval;
  121. int status = urb->status;
  122. struct keyspan_pda_private *priv;
  123. priv = usb_get_serial_port_data(port);
  124. switch (status) {
  125. case 0:
  126. /* success */
  127. break;
  128. case -ECONNRESET:
  129. case -ENOENT:
  130. case -ESHUTDOWN:
  131. /* this urb is terminated, clean up */
  132. dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
  133. return;
  134. default:
  135. dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status);
  136. goto exit;
  137. }
  138. if (len < 1) {
  139. dev_warn(&port->dev, "short message received\n");
  140. goto exit;
  141. }
  142. /* see if the message is data or a status interrupt */
  143. switch (data[0]) {
  144. case 0:
  145. /* rest of message is rx data */
  146. if (len < 2)
  147. break;
  148. tty_insert_flip_string(&port->port, data + 1, len - 1);
  149. tty_flip_buffer_push(&port->port);
  150. break;
  151. case 1:
  152. /* status interrupt */
  153. if (len < 3) {
  154. dev_warn(&port->dev, "short interrupt message received\n");
  155. break;
  156. }
  157. dev_dbg(&port->dev, "rx int, d1=%d, d2=%d\n", data[1], data[2]);
  158. switch (data[1]) {
  159. case 1: /* modemline change */
  160. break;
  161. case 2: /* tx unthrottle interrupt */
  162. priv->tx_throttled = 0;
  163. /* queue up a wakeup at scheduler time */
  164. schedule_work(&priv->wakeup_work);
  165. break;
  166. default:
  167. break;
  168. }
  169. break;
  170. default:
  171. break;
  172. }
  173. exit:
  174. retval = usb_submit_urb(urb, GFP_ATOMIC);
  175. if (retval)
  176. dev_err(&port->dev,
  177. "%s - usb_submit_urb failed with result %d\n",
  178. __func__, retval);
  179. }
  180. static void keyspan_pda_rx_throttle(struct tty_struct *tty)
  181. {
  182. /* stop receiving characters. We just turn off the URB request, and
  183. let chars pile up in the device. If we're doing hardware
  184. flowcontrol, the device will signal the other end when its buffer
  185. fills up. If we're doing XON/XOFF, this would be a good time to
  186. send an XOFF, although it might make sense to foist that off
  187. upon the device too. */
  188. struct usb_serial_port *port = tty->driver_data;
  189. usb_kill_urb(port->interrupt_in_urb);
  190. }
  191. static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
  192. {
  193. struct usb_serial_port *port = tty->driver_data;
  194. /* just restart the receive interrupt URB */
  195. if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL))
  196. dev_dbg(&port->dev, "usb_submit_urb(read urb) failed\n");
  197. }
  198. static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
  199. {
  200. int rc;
  201. int bindex;
  202. switch (baud) {
  203. case 110:
  204. bindex = 0;
  205. break;
  206. case 300:
  207. bindex = 1;
  208. break;
  209. case 1200:
  210. bindex = 2;
  211. break;
  212. case 2400:
  213. bindex = 3;
  214. break;
  215. case 4800:
  216. bindex = 4;
  217. break;
  218. case 9600:
  219. bindex = 5;
  220. break;
  221. case 19200:
  222. bindex = 6;
  223. break;
  224. case 38400:
  225. bindex = 7;
  226. break;
  227. case 57600:
  228. bindex = 8;
  229. break;
  230. case 115200:
  231. bindex = 9;
  232. break;
  233. default:
  234. bindex = 5; /* Default to 9600 */
  235. baud = 9600;
  236. }
  237. /* rather than figure out how to sleep while waiting for this
  238. to complete, I just use the "legacy" API. */
  239. rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  240. 0, /* set baud */
  241. USB_TYPE_VENDOR
  242. | USB_RECIP_INTERFACE
  243. | USB_DIR_OUT, /* type */
  244. bindex, /* value */
  245. 0, /* index */
  246. NULL, /* &data */
  247. 0, /* size */
  248. 2000); /* timeout */
  249. if (rc < 0)
  250. return 0;
  251. return baud;
  252. }
  253. static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
  254. {
  255. struct usb_serial_port *port = tty->driver_data;
  256. struct usb_serial *serial = port->serial;
  257. int value;
  258. int result;
  259. if (break_state == -1)
  260. value = 1; /* start break */
  261. else
  262. value = 0; /* clear break */
  263. result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  264. 4, /* set break */
  265. USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
  266. value, 0, NULL, 0, 2000);
  267. if (result < 0)
  268. dev_dbg(&port->dev, "%s - error %d from usb_control_msg\n",
  269. __func__, result);
  270. /* there is something funky about this.. the TCSBRK that 'cu' performs
  271. ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
  272. seconds apart, but it feels like the break sent isn't as long as it
  273. is on /dev/ttyS0 */
  274. }
  275. static void keyspan_pda_set_termios(struct tty_struct *tty,
  276. struct usb_serial_port *port, struct ktermios *old_termios)
  277. {
  278. struct usb_serial *serial = port->serial;
  279. speed_t speed;
  280. /* cflag specifies lots of stuff: number of stop bits, parity, number
  281. of data bits, baud. What can the device actually handle?:
  282. CSTOPB (1 stop bit or 2)
  283. PARENB (parity)
  284. CSIZE (5bit .. 8bit)
  285. There is minimal hw support for parity (a PSW bit seems to hold the
  286. parity of whatever is in the accumulator). The UART either deals
  287. with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data,
  288. 1 special, stop). So, with firmware changes, we could do:
  289. 8N1: 10 bit
  290. 8N2: 11 bit, extra bit always (mark?)
  291. 8[EOMS]1: 11 bit, extra bit is parity
  292. 7[EOMS]1: 10 bit, b0/b7 is parity
  293. 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?)
  294. HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS
  295. bit.
  296. For now, just do baud. */
  297. speed = tty_get_baud_rate(tty);
  298. speed = keyspan_pda_setbaud(serial, speed);
  299. if (speed == 0) {
  300. dev_dbg(&port->dev, "can't handle requested baud rate\n");
  301. /* It hasn't changed so.. */
  302. speed = tty_termios_baud_rate(old_termios);
  303. }
  304. /* Only speed can change so copy the old h/w parameters
  305. then encode the new speed */
  306. tty_termios_copy_hw(&tty->termios, old_termios);
  307. tty_encode_baud_rate(tty, speed, speed);
  308. }
  309. /* modem control pins: DTR and RTS are outputs and can be controlled.
  310. DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be
  311. read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused */
  312. static int keyspan_pda_get_modem_info(struct usb_serial *serial,
  313. unsigned char *value)
  314. {
  315. int rc;
  316. u8 *data;
  317. data = kmalloc(1, GFP_KERNEL);
  318. if (!data)
  319. return -ENOMEM;
  320. rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  321. 3, /* get pins */
  322. USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
  323. 0, 0, data, 1, 2000);
  324. if (rc == 1)
  325. *value = *data;
  326. else if (rc >= 0)
  327. rc = -EIO;
  328. kfree(data);
  329. return rc;
  330. }
  331. static int keyspan_pda_set_modem_info(struct usb_serial *serial,
  332. unsigned char value)
  333. {
  334. int rc;
  335. rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  336. 3, /* set pins */
  337. USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_OUT,
  338. value, 0, NULL, 0, 2000);
  339. return rc;
  340. }
  341. static int keyspan_pda_tiocmget(struct tty_struct *tty)
  342. {
  343. struct usb_serial_port *port = tty->driver_data;
  344. struct usb_serial *serial = port->serial;
  345. int rc;
  346. unsigned char status;
  347. int value;
  348. rc = keyspan_pda_get_modem_info(serial, &status);
  349. if (rc < 0)
  350. return rc;
  351. value =
  352. ((status & (1<<7)) ? TIOCM_DTR : 0) |
  353. ((status & (1<<6)) ? TIOCM_CAR : 0) |
  354. ((status & (1<<5)) ? TIOCM_RNG : 0) |
  355. ((status & (1<<4)) ? TIOCM_DSR : 0) |
  356. ((status & (1<<3)) ? TIOCM_CTS : 0) |
  357. ((status & (1<<2)) ? TIOCM_RTS : 0);
  358. return value;
  359. }
  360. static int keyspan_pda_tiocmset(struct tty_struct *tty,
  361. unsigned int set, unsigned int clear)
  362. {
  363. struct usb_serial_port *port = tty->driver_data;
  364. struct usb_serial *serial = port->serial;
  365. int rc;
  366. unsigned char status;
  367. rc = keyspan_pda_get_modem_info(serial, &status);
  368. if (rc < 0)
  369. return rc;
  370. if (set & TIOCM_RTS)
  371. status |= (1<<2);
  372. if (set & TIOCM_DTR)
  373. status |= (1<<7);
  374. if (clear & TIOCM_RTS)
  375. status &= ~(1<<2);
  376. if (clear & TIOCM_DTR)
  377. status &= ~(1<<7);
  378. rc = keyspan_pda_set_modem_info(serial, status);
  379. return rc;
  380. }
  381. static int keyspan_pda_write(struct tty_struct *tty,
  382. struct usb_serial_port *port, const unsigned char *buf, int count)
  383. {
  384. struct usb_serial *serial = port->serial;
  385. int request_unthrottle = 0;
  386. int rc = 0;
  387. struct keyspan_pda_private *priv;
  388. priv = usb_get_serial_port_data(port);
  389. /* guess how much room is left in the device's ring buffer, and if we
  390. want to send more than that, check first, updating our notion of
  391. what is left. If our write will result in no room left, ask the
  392. device to give us an interrupt when the room available rises above
  393. a threshold, and hold off all writers (eventually, those using
  394. select() or poll() too) until we receive that unthrottle interrupt.
  395. Block if we can't write anything at all, otherwise write as much as
  396. we can. */
  397. if (count == 0) {
  398. dev_dbg(&port->dev, "write request of 0 bytes\n");
  399. return 0;
  400. }
  401. /* we might block because of:
  402. the TX urb is in-flight (wait until it completes)
  403. the device is full (wait until it says there is room)
  404. */
  405. spin_lock_bh(&port->lock);
  406. if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) {
  407. spin_unlock_bh(&port->lock);
  408. return 0;
  409. }
  410. clear_bit(0, &port->write_urbs_free);
  411. spin_unlock_bh(&port->lock);
  412. /* At this point the URB is in our control, nobody else can submit it
  413. again (the only sudden transition was the one from EINPROGRESS to
  414. finished). Also, the tx process is not throttled. So we are
  415. ready to write. */
  416. count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
  417. /* Check if we might overrun the Tx buffer. If so, ask the
  418. device how much room it really has. This is done only on
  419. scheduler time, since usb_control_msg() sleeps. */
  420. if (count > priv->tx_room && !in_interrupt()) {
  421. u8 *room;
  422. room = kmalloc(1, GFP_KERNEL);
  423. if (!room) {
  424. rc = -ENOMEM;
  425. goto exit;
  426. }
  427. rc = usb_control_msg(serial->dev,
  428. usb_rcvctrlpipe(serial->dev, 0),
  429. 6, /* write_room */
  430. USB_TYPE_VENDOR | USB_RECIP_INTERFACE
  431. | USB_DIR_IN,
  432. 0, /* value: 0 means "remaining room" */
  433. 0, /* index */
  434. room,
  435. 1,
  436. 2000);
  437. if (rc > 0) {
  438. dev_dbg(&port->dev, "roomquery says %d\n", *room);
  439. priv->tx_room = *room;
  440. }
  441. kfree(room);
  442. if (rc < 0) {
  443. dev_dbg(&port->dev, "roomquery failed\n");
  444. goto exit;
  445. }
  446. if (rc == 0) {
  447. dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
  448. rc = -EIO; /* device didn't return any data */
  449. goto exit;
  450. }
  451. }
  452. if (count > priv->tx_room) {
  453. /* we're about to completely fill the Tx buffer, so
  454. we'll be throttled afterwards. */
  455. count = priv->tx_room;
  456. request_unthrottle = 1;
  457. }
  458. if (count) {
  459. /* now transfer data */
  460. memcpy(port->write_urb->transfer_buffer, buf, count);
  461. /* send the data out the bulk port */
  462. port->write_urb->transfer_buffer_length = count;
  463. priv->tx_room -= count;
  464. rc = usb_submit_urb(port->write_urb, GFP_ATOMIC);
  465. if (rc) {
  466. dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n");
  467. goto exit;
  468. }
  469. } else {
  470. /* There wasn't any room left, so we are throttled until
  471. the buffer empties a bit */
  472. request_unthrottle = 1;
  473. }
  474. if (request_unthrottle) {
  475. priv->tx_throttled = 1; /* block writers */
  476. schedule_work(&priv->unthrottle_work);
  477. }
  478. rc = count;
  479. exit:
  480. if (rc < 0)
  481. set_bit(0, &port->write_urbs_free);
  482. return rc;
  483. }
  484. static void keyspan_pda_write_bulk_callback(struct urb *urb)
  485. {
  486. struct usb_serial_port *port = urb->context;
  487. struct keyspan_pda_private *priv;
  488. set_bit(0, &port->write_urbs_free);
  489. priv = usb_get_serial_port_data(port);
  490. /* queue up a wakeup at scheduler time */
  491. schedule_work(&priv->wakeup_work);
  492. }
  493. static int keyspan_pda_write_room(struct tty_struct *tty)
  494. {
  495. struct usb_serial_port *port = tty->driver_data;
  496. struct keyspan_pda_private *priv;
  497. priv = usb_get_serial_port_data(port);
  498. /* used by n_tty.c for processing of tabs and such. Giving it our
  499. conservative guess is probably good enough, but needs testing by
  500. running a console through the device. */
  501. return priv->tx_room;
  502. }
  503. static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
  504. {
  505. struct usb_serial_port *port = tty->driver_data;
  506. struct keyspan_pda_private *priv;
  507. unsigned long flags;
  508. int ret = 0;
  509. priv = usb_get_serial_port_data(port);
  510. /* when throttled, return at least WAKEUP_CHARS to tell select() (via
  511. n_tty.c:normal_poll() ) that we're not writeable. */
  512. spin_lock_irqsave(&port->lock, flags);
  513. if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled)
  514. ret = 256;
  515. spin_unlock_irqrestore(&port->lock, flags);
  516. return ret;
  517. }
  518. static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
  519. {
  520. struct usb_serial *serial = port->serial;
  521. if (on)
  522. keyspan_pda_set_modem_info(serial, (1 << 7) | (1 << 2));
  523. else
  524. keyspan_pda_set_modem_info(serial, 0);
  525. }
  526. static int keyspan_pda_open(struct tty_struct *tty,
  527. struct usb_serial_port *port)
  528. {
  529. struct usb_serial *serial = port->serial;
  530. u8 *room;
  531. int rc = 0;
  532. struct keyspan_pda_private *priv;
  533. /* find out how much room is in the Tx ring */
  534. room = kmalloc(1, GFP_KERNEL);
  535. if (!room)
  536. return -ENOMEM;
  537. rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
  538. 6, /* write_room */
  539. USB_TYPE_VENDOR | USB_RECIP_INTERFACE
  540. | USB_DIR_IN,
  541. 0, /* value */
  542. 0, /* index */
  543. room,
  544. 1,
  545. 2000);
  546. if (rc < 0) {
  547. dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
  548. goto error;
  549. }
  550. if (rc == 0) {
  551. dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
  552. rc = -EIO;
  553. goto error;
  554. }
  555. priv = usb_get_serial_port_data(port);
  556. priv->tx_room = *room;
  557. priv->tx_throttled = *room ? 0 : 1;
  558. /*Start reading from the device*/
  559. rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  560. if (rc) {
  561. dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
  562. goto error;
  563. }
  564. error:
  565. kfree(room);
  566. return rc;
  567. }
  568. static void keyspan_pda_close(struct usb_serial_port *port)
  569. {
  570. usb_kill_urb(port->write_urb);
  571. usb_kill_urb(port->interrupt_in_urb);
  572. }
  573. /* download the firmware to a "fake" device (pre-renumeration) */
  574. static int keyspan_pda_fake_startup(struct usb_serial *serial)
  575. {
  576. int response;
  577. const char *fw_name;
  578. /* download the firmware here ... */
  579. response = ezusb_fx1_set_reset(serial->dev, 1);
  580. if (0) { ; }
  581. #ifdef KEYSPAN
  582. else if (le16_to_cpu(serial->dev->descriptor.idVendor) == KEYSPAN_VENDOR_ID)
  583. fw_name = "keyspan_pda/keyspan_pda.fw";
  584. #endif
  585. #ifdef XIRCOM
  586. else if ((le16_to_cpu(serial->dev->descriptor.idVendor) == XIRCOM_VENDOR_ID) ||
  587. (le16_to_cpu(serial->dev->descriptor.idVendor) == ENTREGA_VENDOR_ID))
  588. fw_name = "keyspan_pda/xircom_pgs.fw";
  589. #endif
  590. else {
  591. dev_err(&serial->dev->dev, "%s: unknown vendor, aborting.\n",
  592. __func__);
  593. return -ENODEV;
  594. }
  595. if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
  596. dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
  597. fw_name);
  598. return -ENOENT;
  599. }
  600. /* after downloading firmware Renumeration will occur in a
  601. moment and the new device will bind to the real driver */
  602. /* we want this device to fail to have a driver assigned to it. */
  603. return 1;
  604. }
  605. #ifdef KEYSPAN
  606. MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
  607. #endif
  608. #ifdef XIRCOM
  609. MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
  610. #endif
  611. static int keyspan_pda_port_probe(struct usb_serial_port *port)
  612. {
  613. struct keyspan_pda_private *priv;
  614. priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
  615. if (!priv)
  616. return -ENOMEM;
  617. INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
  618. INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
  619. priv->serial = port->serial;
  620. priv->port = port;
  621. usb_set_serial_port_data(port, priv);
  622. return 0;
  623. }
  624. static int keyspan_pda_port_remove(struct usb_serial_port *port)
  625. {
  626. struct keyspan_pda_private *priv;
  627. priv = usb_get_serial_port_data(port);
  628. kfree(priv);
  629. return 0;
  630. }
  631. #ifdef KEYSPAN
  632. static struct usb_serial_driver keyspan_pda_fake_device = {
  633. .driver = {
  634. .owner = THIS_MODULE,
  635. .name = "keyspan_pda_pre",
  636. },
  637. .description = "Keyspan PDA - (prerenumeration)",
  638. .id_table = id_table_fake,
  639. .num_ports = 1,
  640. .attach = keyspan_pda_fake_startup,
  641. };
  642. #endif
  643. #ifdef XIRCOM
  644. static struct usb_serial_driver xircom_pgs_fake_device = {
  645. .driver = {
  646. .owner = THIS_MODULE,
  647. .name = "xircom_no_firm",
  648. },
  649. .description = "Xircom / Entrega PGS - (prerenumeration)",
  650. .id_table = id_table_fake_xircom,
  651. .num_ports = 1,
  652. .attach = keyspan_pda_fake_startup,
  653. };
  654. #endif
  655. static struct usb_serial_driver keyspan_pda_device = {
  656. .driver = {
  657. .owner = THIS_MODULE,
  658. .name = "keyspan_pda",
  659. },
  660. .description = "Keyspan PDA",
  661. .id_table = id_table_std,
  662. .num_ports = 1,
  663. .num_bulk_out = 1,
  664. .num_interrupt_in = 1,
  665. .dtr_rts = keyspan_pda_dtr_rts,
  666. .open = keyspan_pda_open,
  667. .close = keyspan_pda_close,
  668. .write = keyspan_pda_write,
  669. .write_room = keyspan_pda_write_room,
  670. .write_bulk_callback = keyspan_pda_write_bulk_callback,
  671. .read_int_callback = keyspan_pda_rx_interrupt,
  672. .chars_in_buffer = keyspan_pda_chars_in_buffer,
  673. .throttle = keyspan_pda_rx_throttle,
  674. .unthrottle = keyspan_pda_rx_unthrottle,
  675. .set_termios = keyspan_pda_set_termios,
  676. .break_ctl = keyspan_pda_break_ctl,
  677. .tiocmget = keyspan_pda_tiocmget,
  678. .tiocmset = keyspan_pda_tiocmset,
  679. .port_probe = keyspan_pda_port_probe,
  680. .port_remove = keyspan_pda_port_remove,
  681. };
  682. static struct usb_serial_driver * const serial_drivers[] = {
  683. &keyspan_pda_device,
  684. #ifdef KEYSPAN
  685. &keyspan_pda_fake_device,
  686. #endif
  687. #ifdef XIRCOM
  688. &xircom_pgs_fake_device,
  689. #endif
  690. NULL
  691. };
  692. module_usb_serial_driver(serial_drivers, id_table_combined);
  693. MODULE_AUTHOR(DRIVER_AUTHOR);
  694. MODULE_DESCRIPTION(DRIVER_DESC);
  695. MODULE_LICENSE("GPL");