keyspan_pda.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. * Copyright (C) 2020 Johan Hovold <johan@kernel.org>
  9. *
  10. * See Documentation/usb/usb-serial.rst for more information on using this
  11. * driver
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/slab.h>
  16. #include <linux/tty.h>
  17. #include <linux/tty_driver.h>
  18. #include <linux/tty_flip.h>
  19. #include <linux/module.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/workqueue.h>
  22. #include <linux/uaccess.h>
  23. #include <linux/usb.h>
  24. #include <linux/usb/serial.h>
  25. #include <linux/usb/ezusb.h>
  26. #define DRIVER_AUTHOR "Brian Warner <warner@lothar.com>, Johan Hovold <johan@kernel.org>"
  27. #define DRIVER_DESC "USB Keyspan PDA Converter driver"
  28. #define KEYSPAN_TX_THRESHOLD 128
  29. struct keyspan_pda_private {
  30. int tx_room;
  31. struct work_struct unthrottle_work;
  32. struct usb_serial *serial;
  33. struct usb_serial_port *port;
  34. };
  35. static int keyspan_pda_write_start(struct usb_serial_port *port);
  36. #define KEYSPAN_VENDOR_ID 0x06cd
  37. #define KEYSPAN_PDA_FAKE_ID 0x0103
  38. #define KEYSPAN_PDA_ID 0x0104 /* no clue */
  39. /* For Xircom PGSDB9 and older Entrega version of the same device */
  40. #define XIRCOM_VENDOR_ID 0x085a
  41. #define XIRCOM_FAKE_ID 0x8027
  42. #define XIRCOM_FAKE_ID_2 0x8025 /* "PGMFHUB" serial */
  43. #define ENTREGA_VENDOR_ID 0x1645
  44. #define ENTREGA_FAKE_ID 0x8093
  45. static const struct usb_device_id id_table_combined[] = {
  46. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
  47. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
  48. { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID_2) },
  49. { USB_DEVICE(ENTREGA_VENDOR_ID, ENTREGA_FAKE_ID) },
  50. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
  51. { } /* Terminating entry */
  52. };
  53. MODULE_DEVICE_TABLE(usb, id_table_combined);
  54. static const struct usb_device_id id_table_std[] = {
  55. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
  56. { } /* Terminating entry */
  57. };
  58. static const struct usb_device_id id_table_fake[] = {
  59. { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
  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. { } /* Terminating entry */
  64. };
  65. static int keyspan_pda_get_write_room(struct keyspan_pda_private *priv)
  66. {
  67. struct usb_serial_port *port = priv->port;
  68. struct usb_serial *serial = port->serial;
  69. u8 room;
  70. int rc;
  71. rc = usb_control_msg_recv(serial->dev,
  72. 0,
  73. 6, /* write_room */
  74. USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_IN,
  75. 0, /* value: 0 means "remaining room" */
  76. 0, /* index */
  77. &room,
  78. 1,
  79. 2000,
  80. GFP_KERNEL);
  81. if (rc) {
  82. dev_dbg(&port->dev, "roomquery failed: %d\n", rc);
  83. return rc;
  84. }
  85. dev_dbg(&port->dev, "roomquery says %d\n", room);
  86. return room;
  87. }
  88. static void keyspan_pda_request_unthrottle(struct work_struct *work)
  89. {
  90. struct keyspan_pda_private *priv =
  91. container_of(work, struct keyspan_pda_private, unthrottle_work);
  92. struct usb_serial_port *port = priv->port;
  93. struct usb_serial *serial = port->serial;
  94. unsigned long flags;
  95. int result;
  96. dev_dbg(&port->dev, "%s\n", __func__);
  97. /*
  98. * Ask the device to tell us when the tx buffer becomes
  99. * sufficiently empty.
  100. */
  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. KEYSPAN_TX_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. * Need to check available space after requesting notification in case
  116. * buffer is already empty so that no notification is sent.
  117. */
  118. result = keyspan_pda_get_write_room(priv);
  119. if (result > KEYSPAN_TX_THRESHOLD) {
  120. spin_lock_irqsave(&port->lock, flags);
  121. priv->tx_room = max(priv->tx_room, result);
  122. spin_unlock_irqrestore(&port->lock, flags);
  123. usb_serial_port_softint(port);
  124. }
  125. }
  126. static void keyspan_pda_rx_interrupt(struct urb *urb)
  127. {
  128. struct usb_serial_port *port = urb->context;
  129. unsigned char *data = urb->transfer_buffer;
  130. unsigned int len = urb->actual_length;
  131. int retval;
  132. int status = urb->status;
  133. struct keyspan_pda_private *priv;
  134. unsigned long flags;
  135. priv = usb_get_serial_port_data(port);
  136. switch (status) {
  137. case 0:
  138. /* success */
  139. break;
  140. case -ECONNRESET:
  141. case -ENOENT:
  142. case -ESHUTDOWN:
  143. /* this urb is terminated, clean up */
  144. dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
  145. return;
  146. default:
  147. dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status);
  148. goto exit;
  149. }
  150. if (len < 1) {
  151. dev_warn(&port->dev, "short message received\n");
  152. goto exit;
  153. }
  154. /* see if the message is data or a status interrupt */
  155. switch (data[0]) {
  156. case 0:
  157. /* rest of message is rx data */
  158. if (len < 2)
  159. break;
  160. tty_insert_flip_string(&port->port, data + 1, len - 1);
  161. tty_flip_buffer_push(&port->port);
  162. break;
  163. case 1:
  164. /* status interrupt */
  165. if (len < 2) {
  166. dev_warn(&port->dev, "short interrupt message received\n");
  167. break;
  168. }
  169. dev_dbg(&port->dev, "rx int, d1=%d\n", data[1]);
  170. switch (data[1]) {
  171. case 1: /* modemline change */
  172. break;
  173. case 2: /* tx unthrottle interrupt */
  174. spin_lock_irqsave(&port->lock, flags);
  175. priv->tx_room = max(priv->tx_room, KEYSPAN_TX_THRESHOLD);
  176. spin_unlock_irqrestore(&port->lock, flags);
  177. keyspan_pda_write_start(port);
  178. usb_serial_port_softint(port);
  179. break;
  180. default:
  181. break;
  182. }
  183. break;
  184. default:
  185. break;
  186. }
  187. exit:
  188. retval = usb_submit_urb(urb, GFP_ATOMIC);
  189. if (retval)
  190. dev_err(&port->dev,
  191. "%s - usb_submit_urb failed with result %d\n",
  192. __func__, retval);
  193. }
  194. static void keyspan_pda_rx_throttle(struct tty_struct *tty)
  195. {
  196. struct usb_serial_port *port = tty->driver_data;
  197. /*
  198. * Stop receiving characters. We just turn off the URB request, and
  199. * let chars pile up in the device. If we're doing hardware
  200. * flowcontrol, the device will signal the other end when its buffer
  201. * fills up. If we're doing XON/XOFF, this would be a good time to
  202. * send an XOFF, although it might make sense to foist that off upon
  203. * the device too.
  204. */
  205. usb_kill_urb(port->interrupt_in_urb);
  206. }
  207. static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
  208. {
  209. struct usb_serial_port *port = tty->driver_data;
  210. /* just restart the receive interrupt URB */
  211. if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL))
  212. dev_dbg(&port->dev, "usb_submit_urb(read urb) failed\n");
  213. }
  214. static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
  215. {
  216. int rc;
  217. int bindex;
  218. switch (baud) {
  219. case 110:
  220. bindex = 0;
  221. break;
  222. case 300:
  223. bindex = 1;
  224. break;
  225. case 1200:
  226. bindex = 2;
  227. break;
  228. case 2400:
  229. bindex = 3;
  230. break;
  231. case 4800:
  232. bindex = 4;
  233. break;
  234. case 9600:
  235. bindex = 5;
  236. break;
  237. case 19200:
  238. bindex = 6;
  239. break;
  240. case 38400:
  241. bindex = 7;
  242. break;
  243. case 57600:
  244. bindex = 8;
  245. break;
  246. case 115200:
  247. bindex = 9;
  248. break;
  249. default:
  250. bindex = 5; /* Default to 9600 */
  251. baud = 9600;
  252. }
  253. rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  254. 0, /* set baud */
  255. USB_TYPE_VENDOR
  256. | USB_RECIP_INTERFACE
  257. | USB_DIR_OUT, /* type */
  258. bindex, /* value */
  259. 0, /* index */
  260. NULL, /* &data */
  261. 0, /* size */
  262. 2000); /* timeout */
  263. if (rc < 0)
  264. return 0;
  265. return baud;
  266. }
  267. static int keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
  268. {
  269. struct usb_serial_port *port = tty->driver_data;
  270. struct usb_serial *serial = port->serial;
  271. int value;
  272. int result;
  273. if (break_state == -1)
  274. value = 1; /* start break */
  275. else
  276. value = 0; /* clear break */
  277. result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  278. 4, /* set break */
  279. USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
  280. value, 0, NULL, 0, 2000);
  281. if (result < 0) {
  282. dev_dbg(&port->dev, "%s - error %d from usb_control_msg\n",
  283. __func__, result);
  284. return result;
  285. }
  286. return 0;
  287. }
  288. static void keyspan_pda_set_termios(struct tty_struct *tty,
  289. struct usb_serial_port *port,
  290. const struct ktermios *old_termios)
  291. {
  292. struct usb_serial *serial = port->serial;
  293. speed_t speed;
  294. /*
  295. * cflag specifies lots of stuff: number of stop bits, parity, number
  296. * of data bits, baud. What can the device actually handle?:
  297. * CSTOPB (1 stop bit or 2)
  298. * PARENB (parity)
  299. * CSIZE (5bit .. 8bit)
  300. * There is minimal hw support for parity (a PSW bit seems to hold the
  301. * parity of whatever is in the accumulator). The UART either deals
  302. * with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data,
  303. * 1 special, stop). So, with firmware changes, we could do:
  304. * 8N1: 10 bit
  305. * 8N2: 11 bit, extra bit always (mark?)
  306. * 8[EOMS]1: 11 bit, extra bit is parity
  307. * 7[EOMS]1: 10 bit, b0/b7 is parity
  308. * 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?)
  309. *
  310. * HW flow control is dictated by the tty->termios.c_cflags & CRTSCTS
  311. * bit.
  312. *
  313. * For now, just do baud.
  314. */
  315. speed = tty_get_baud_rate(tty);
  316. speed = keyspan_pda_setbaud(serial, speed);
  317. if (speed == 0) {
  318. dev_dbg(&port->dev, "can't handle requested baud rate\n");
  319. /* It hasn't changed so.. */
  320. speed = tty_termios_baud_rate(old_termios);
  321. }
  322. /*
  323. * Only speed can change so copy the old h/w parameters then encode
  324. * the new speed.
  325. */
  326. tty_termios_copy_hw(&tty->termios, old_termios);
  327. tty_encode_baud_rate(tty, speed, speed);
  328. }
  329. /*
  330. * Modem control pins: DTR and RTS are outputs and can be controlled.
  331. * DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be
  332. * read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused.
  333. */
  334. static int keyspan_pda_get_modem_info(struct usb_serial *serial,
  335. unsigned char *value)
  336. {
  337. int rc;
  338. u8 data;
  339. rc = usb_control_msg_recv(serial->dev, 0,
  340. 3, /* get pins */
  341. USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_IN,
  342. 0,
  343. 0,
  344. &data,
  345. 1,
  346. 2000,
  347. GFP_KERNEL);
  348. if (rc == 0)
  349. *value = data;
  350. return rc;
  351. }
  352. static int keyspan_pda_set_modem_info(struct usb_serial *serial,
  353. unsigned char value)
  354. {
  355. int rc;
  356. rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  357. 3, /* set pins */
  358. USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_OUT,
  359. value, 0, NULL, 0, 2000);
  360. return rc;
  361. }
  362. static int keyspan_pda_tiocmget(struct tty_struct *tty)
  363. {
  364. struct usb_serial_port *port = tty->driver_data;
  365. struct usb_serial *serial = port->serial;
  366. int rc;
  367. unsigned char status;
  368. int value;
  369. rc = keyspan_pda_get_modem_info(serial, &status);
  370. if (rc < 0)
  371. return rc;
  372. value = ((status & BIT(7)) ? TIOCM_DTR : 0) |
  373. ((status & BIT(6)) ? TIOCM_CAR : 0) |
  374. ((status & BIT(5)) ? TIOCM_RNG : 0) |
  375. ((status & BIT(4)) ? TIOCM_DSR : 0) |
  376. ((status & BIT(3)) ? TIOCM_CTS : 0) |
  377. ((status & BIT(2)) ? TIOCM_RTS : 0);
  378. return value;
  379. }
  380. static int keyspan_pda_tiocmset(struct tty_struct *tty,
  381. unsigned int set, unsigned int clear)
  382. {
  383. struct usb_serial_port *port = tty->driver_data;
  384. struct usb_serial *serial = port->serial;
  385. int rc;
  386. unsigned char status;
  387. rc = keyspan_pda_get_modem_info(serial, &status);
  388. if (rc < 0)
  389. return rc;
  390. if (set & TIOCM_RTS)
  391. status |= BIT(2);
  392. if (set & TIOCM_DTR)
  393. status |= BIT(7);
  394. if (clear & TIOCM_RTS)
  395. status &= ~BIT(2);
  396. if (clear & TIOCM_DTR)
  397. status &= ~BIT(7);
  398. rc = keyspan_pda_set_modem_info(serial, status);
  399. return rc;
  400. }
  401. static int keyspan_pda_write_start(struct usb_serial_port *port)
  402. {
  403. struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
  404. unsigned long flags;
  405. struct urb *urb;
  406. int count;
  407. int room;
  408. int rc;
  409. /*
  410. * Guess how much room is left in the device's ring buffer. If our
  411. * write will result in no room left, ask the device to give us an
  412. * interrupt when the room available rises above a threshold but also
  413. * query how much room is currently available (in case our guess was
  414. * too conservative and the buffer is already empty when the
  415. * unthrottle work is scheduled).
  416. */
  417. /*
  418. * We might block because of:
  419. * the TX urb is in-flight (wait until it completes)
  420. * the device is full (wait until it says there is room)
  421. */
  422. spin_lock_irqsave(&port->lock, flags);
  423. room = priv->tx_room;
  424. count = kfifo_len(&port->write_fifo);
  425. if (!test_bit(0, &port->write_urbs_free) || count == 0 || room == 0) {
  426. spin_unlock_irqrestore(&port->lock, flags);
  427. return 0;
  428. }
  429. __clear_bit(0, &port->write_urbs_free);
  430. if (count > room)
  431. count = room;
  432. if (count > port->bulk_out_size)
  433. count = port->bulk_out_size;
  434. urb = port->write_urb;
  435. count = kfifo_out(&port->write_fifo, urb->transfer_buffer, count);
  436. urb->transfer_buffer_length = count;
  437. port->tx_bytes += count;
  438. priv->tx_room -= count;
  439. spin_unlock_irqrestore(&port->lock, flags);
  440. dev_dbg(&port->dev, "%s - count = %d, txroom = %d\n", __func__, count, room);
  441. rc = usb_submit_urb(urb, GFP_ATOMIC);
  442. if (rc) {
  443. dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n");
  444. spin_lock_irqsave(&port->lock, flags);
  445. port->tx_bytes -= count;
  446. priv->tx_room = max(priv->tx_room, room + count);
  447. __set_bit(0, &port->write_urbs_free);
  448. spin_unlock_irqrestore(&port->lock, flags);
  449. return rc;
  450. }
  451. if (count == room)
  452. schedule_work(&priv->unthrottle_work);
  453. return count;
  454. }
  455. static void keyspan_pda_write_bulk_callback(struct urb *urb)
  456. {
  457. struct usb_serial_port *port = urb->context;
  458. unsigned long flags;
  459. spin_lock_irqsave(&port->lock, flags);
  460. port->tx_bytes -= urb->transfer_buffer_length;
  461. __set_bit(0, &port->write_urbs_free);
  462. spin_unlock_irqrestore(&port->lock, flags);
  463. keyspan_pda_write_start(port);
  464. usb_serial_port_softint(port);
  465. }
  466. static int keyspan_pda_write(struct tty_struct *tty, struct usb_serial_port *port,
  467. const unsigned char *buf, int count)
  468. {
  469. int rc;
  470. dev_dbg(&port->dev, "%s - count = %d\n", __func__, count);
  471. if (!count)
  472. return 0;
  473. count = kfifo_in_locked(&port->write_fifo, buf, count, &port->lock);
  474. rc = keyspan_pda_write_start(port);
  475. if (rc)
  476. return rc;
  477. return count;
  478. }
  479. static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
  480. {
  481. struct usb_serial *serial = port->serial;
  482. if (on)
  483. keyspan_pda_set_modem_info(serial, BIT(7) | BIT(2));
  484. else
  485. keyspan_pda_set_modem_info(serial, 0);
  486. }
  487. static int keyspan_pda_open(struct tty_struct *tty,
  488. struct usb_serial_port *port)
  489. {
  490. struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
  491. int rc;
  492. /* find out how much room is in the Tx ring */
  493. rc = keyspan_pda_get_write_room(priv);
  494. if (rc < 0)
  495. return rc;
  496. spin_lock_irq(&port->lock);
  497. priv->tx_room = rc;
  498. spin_unlock_irq(&port->lock);
  499. rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
  500. if (rc) {
  501. dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
  502. return rc;
  503. }
  504. return 0;
  505. }
  506. static void keyspan_pda_close(struct usb_serial_port *port)
  507. {
  508. struct keyspan_pda_private *priv = usb_get_serial_port_data(port);
  509. /*
  510. * Stop the interrupt URB first as its completion handler may submit
  511. * the write URB.
  512. */
  513. usb_kill_urb(port->interrupt_in_urb);
  514. usb_kill_urb(port->write_urb);
  515. cancel_work_sync(&priv->unthrottle_work);
  516. spin_lock_irq(&port->lock);
  517. kfifo_reset(&port->write_fifo);
  518. spin_unlock_irq(&port->lock);
  519. }
  520. /* download the firmware to a "fake" device (pre-renumeration) */
  521. static int keyspan_pda_fake_startup(struct usb_serial *serial)
  522. {
  523. unsigned int vid = le16_to_cpu(serial->dev->descriptor.idVendor);
  524. const char *fw_name;
  525. /* download the firmware here ... */
  526. ezusb_fx1_set_reset(serial->dev, 1);
  527. switch (vid) {
  528. case KEYSPAN_VENDOR_ID:
  529. fw_name = "keyspan_pda/keyspan_pda.fw";
  530. break;
  531. case XIRCOM_VENDOR_ID:
  532. case ENTREGA_VENDOR_ID:
  533. fw_name = "keyspan_pda/xircom_pgs.fw";
  534. break;
  535. default:
  536. dev_err(&serial->dev->dev, "%s: unknown vendor, aborting.\n",
  537. __func__);
  538. return -ENODEV;
  539. }
  540. if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
  541. dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
  542. fw_name);
  543. return -ENOENT;
  544. }
  545. /*
  546. * After downloading firmware renumeration will occur in a moment and
  547. * the new device will bind to the real driver.
  548. */
  549. /* We want this device to fail to have a driver assigned to it. */
  550. return 1;
  551. }
  552. MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
  553. MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
  554. static int keyspan_pda_port_probe(struct usb_serial_port *port)
  555. {
  556. struct keyspan_pda_private *priv;
  557. priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
  558. if (!priv)
  559. return -ENOMEM;
  560. INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
  561. priv->port = port;
  562. usb_set_serial_port_data(port, priv);
  563. return 0;
  564. }
  565. static void keyspan_pda_port_remove(struct usb_serial_port *port)
  566. {
  567. struct keyspan_pda_private *priv;
  568. priv = usb_get_serial_port_data(port);
  569. kfree(priv);
  570. }
  571. static struct usb_serial_driver keyspan_pda_fake_device = {
  572. .driver = {
  573. .name = "keyspan_pda_pre",
  574. },
  575. .description = "Keyspan PDA - (prerenumeration)",
  576. .id_table = id_table_fake,
  577. .num_ports = 1,
  578. .attach = keyspan_pda_fake_startup,
  579. };
  580. static struct usb_serial_driver keyspan_pda_device = {
  581. .driver = {
  582. .name = "keyspan_pda",
  583. },
  584. .description = "Keyspan PDA",
  585. .id_table = id_table_std,
  586. .num_ports = 1,
  587. .num_bulk_out = 1,
  588. .num_interrupt_in = 1,
  589. .dtr_rts = keyspan_pda_dtr_rts,
  590. .open = keyspan_pda_open,
  591. .close = keyspan_pda_close,
  592. .write = keyspan_pda_write,
  593. .write_bulk_callback = keyspan_pda_write_bulk_callback,
  594. .read_int_callback = keyspan_pda_rx_interrupt,
  595. .throttle = keyspan_pda_rx_throttle,
  596. .unthrottle = keyspan_pda_rx_unthrottle,
  597. .set_termios = keyspan_pda_set_termios,
  598. .break_ctl = keyspan_pda_break_ctl,
  599. .tiocmget = keyspan_pda_tiocmget,
  600. .tiocmset = keyspan_pda_tiocmset,
  601. .port_probe = keyspan_pda_port_probe,
  602. .port_remove = keyspan_pda_port_remove,
  603. };
  604. static struct usb_serial_driver * const serial_drivers[] = {
  605. &keyspan_pda_device,
  606. &keyspan_pda_fake_device,
  607. NULL
  608. };
  609. module_usb_serial_driver(serial_drivers, id_table_combined);
  610. MODULE_AUTHOR(DRIVER_AUTHOR);
  611. MODULE_DESCRIPTION(DRIVER_DESC);
  612. MODULE_LICENSE("GPL");