kl5kusb105.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * KLSI KL5KUSB105 chip RS232 converter driver
  3. *
  4. * Copyright (C) 2010 Johan Hovold <jhovold@gmail.com>
  5. * Copyright (C) 2001 Utz-Uwe Haus <haus@uuhaus.de>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * All information about the device was acquired using SniffUSB ans snoopUSB
  13. * on Windows98.
  14. * It was written out of frustration with the PalmConnect USB Serial adapter
  15. * sold by Palm Inc.
  16. * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided
  17. * information that was not already available.
  18. *
  19. * It seems that KLSI bought some silicon-design information from ScanLogic,
  20. * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI.
  21. * KLSI has firmware available for their devices; it is probable that the
  22. * firmware differs from that used by KLSI in their products. If you have an
  23. * original KLSI device and can provide some information on it, I would be
  24. * most interested in adding support for it here. If you have any information
  25. * on the protocol used (or find errors in my reverse-engineered stuff), please
  26. * let me know.
  27. *
  28. * The code was only tested with a PalmConnect USB adapter; if you
  29. * are adventurous, try it with any KLSI-based device and let me know how it
  30. * breaks so that I can fix it!
  31. */
  32. /* TODO:
  33. * check modem line signals
  34. * implement handshaking or decide that we do not support it
  35. */
  36. #include <linux/kernel.h>
  37. #include <linux/errno.h>
  38. #include <linux/init.h>
  39. #include <linux/slab.h>
  40. #include <linux/tty.h>
  41. #include <linux/tty_driver.h>
  42. #include <linux/tty_flip.h>
  43. #include <linux/module.h>
  44. #include <linux/uaccess.h>
  45. #include <asm/unaligned.h>
  46. #include <linux/usb.h>
  47. #include <linux/usb/serial.h>
  48. #include "kl5kusb105.h"
  49. #define DRIVER_AUTHOR "Utz-Uwe Haus <haus@uuhaus.de>, Johan Hovold <jhovold@gmail.com>"
  50. #define DRIVER_DESC "KLSI KL5KUSB105 chipset USB->Serial Converter driver"
  51. /*
  52. * Function prototypes
  53. */
  54. static int klsi_105_port_probe(struct usb_serial_port *port);
  55. static int klsi_105_port_remove(struct usb_serial_port *port);
  56. static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port);
  57. static void klsi_105_close(struct usb_serial_port *port);
  58. static void klsi_105_set_termios(struct tty_struct *tty,
  59. struct usb_serial_port *port, struct ktermios *old);
  60. static int klsi_105_tiocmget(struct tty_struct *tty);
  61. static int klsi_105_tiocmset(struct tty_struct *tty,
  62. unsigned int set, unsigned int clear);
  63. static void klsi_105_process_read_urb(struct urb *urb);
  64. static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
  65. void *dest, size_t size);
  66. /*
  67. * All of the device info needed for the KLSI converters.
  68. */
  69. static const struct usb_device_id id_table[] = {
  70. { USB_DEVICE(PALMCONNECT_VID, PALMCONNECT_PID) },
  71. { USB_DEVICE(KLSI_VID, KLSI_KL5KUSB105D_PID) },
  72. { } /* Terminating entry */
  73. };
  74. MODULE_DEVICE_TABLE(usb, id_table);
  75. static struct usb_serial_driver kl5kusb105d_device = {
  76. .driver = {
  77. .owner = THIS_MODULE,
  78. .name = "kl5kusb105d",
  79. },
  80. .description = "KL5KUSB105D / PalmConnect",
  81. .id_table = id_table,
  82. .num_ports = 1,
  83. .bulk_out_size = 64,
  84. .open = klsi_105_open,
  85. .close = klsi_105_close,
  86. .set_termios = klsi_105_set_termios,
  87. /*.break_ctl = klsi_105_break_ctl,*/
  88. .tiocmget = klsi_105_tiocmget,
  89. .tiocmset = klsi_105_tiocmset,
  90. .port_probe = klsi_105_port_probe,
  91. .port_remove = klsi_105_port_remove,
  92. .throttle = usb_serial_generic_throttle,
  93. .unthrottle = usb_serial_generic_unthrottle,
  94. .process_read_urb = klsi_105_process_read_urb,
  95. .prepare_write_buffer = klsi_105_prepare_write_buffer,
  96. };
  97. static struct usb_serial_driver * const serial_drivers[] = {
  98. &kl5kusb105d_device, NULL
  99. };
  100. struct klsi_105_port_settings {
  101. __u8 pktlen; /* always 5, it seems */
  102. __u8 baudrate;
  103. __u8 databits;
  104. __u8 unknown1;
  105. __u8 unknown2;
  106. } __attribute__ ((packed));
  107. struct klsi_105_private {
  108. struct klsi_105_port_settings cfg;
  109. struct ktermios termios;
  110. unsigned long line_state; /* modem line settings */
  111. spinlock_t lock;
  112. };
  113. /*
  114. * Handle vendor specific USB requests
  115. */
  116. #define KLSI_TIMEOUT 5000 /* default urb timeout */
  117. static int klsi_105_chg_port_settings(struct usb_serial_port *port,
  118. struct klsi_105_port_settings *settings)
  119. {
  120. int rc;
  121. rc = usb_control_msg(port->serial->dev,
  122. usb_sndctrlpipe(port->serial->dev, 0),
  123. KL5KUSB105A_SIO_SET_DATA,
  124. USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
  125. 0, /* value */
  126. 0, /* index */
  127. settings,
  128. sizeof(struct klsi_105_port_settings),
  129. KLSI_TIMEOUT);
  130. if (rc < 0)
  131. dev_err(&port->dev,
  132. "Change port settings failed (error = %d)\n", rc);
  133. dev_info(&port->serial->dev->dev,
  134. "%d byte block, baudrate %x, databits %d, u1 %d, u2 %d\n",
  135. settings->pktlen, settings->baudrate, settings->databits,
  136. settings->unknown1, settings->unknown2);
  137. return rc;
  138. }
  139. /* translate a 16-bit status value from the device to linux's TIO bits */
  140. static unsigned long klsi_105_status2linestate(const __u16 status)
  141. {
  142. unsigned long res = 0;
  143. res = ((status & KL5KUSB105A_DSR) ? TIOCM_DSR : 0)
  144. | ((status & KL5KUSB105A_CTS) ? TIOCM_CTS : 0)
  145. ;
  146. return res;
  147. }
  148. /*
  149. * Read line control via vendor command and return result through
  150. * *line_state_p
  151. */
  152. /* It seems that the status buffer has always only 2 bytes length */
  153. #define KLSI_STATUSBUF_LEN 2
  154. static int klsi_105_get_line_state(struct usb_serial_port *port,
  155. unsigned long *line_state_p)
  156. {
  157. int rc;
  158. u8 *status_buf;
  159. __u16 status;
  160. dev_info(&port->serial->dev->dev, "sending SIO Poll request\n");
  161. status_buf = kmalloc(KLSI_STATUSBUF_LEN, GFP_KERNEL);
  162. if (!status_buf) {
  163. dev_err(&port->dev, "%s - out of memory for status buffer.\n",
  164. __func__);
  165. return -ENOMEM;
  166. }
  167. status_buf[0] = 0xff;
  168. status_buf[1] = 0xff;
  169. rc = usb_control_msg(port->serial->dev,
  170. usb_rcvctrlpipe(port->serial->dev, 0),
  171. KL5KUSB105A_SIO_POLL,
  172. USB_TYPE_VENDOR | USB_DIR_IN,
  173. 0, /* value */
  174. 0, /* index */
  175. status_buf, KLSI_STATUSBUF_LEN,
  176. 10000
  177. );
  178. if (rc < 0)
  179. dev_err(&port->dev, "Reading line status failed (error = %d)\n",
  180. rc);
  181. else {
  182. status = get_unaligned_le16(status_buf);
  183. dev_info(&port->serial->dev->dev, "read status %x %x",
  184. status_buf[0], status_buf[1]);
  185. *line_state_p = klsi_105_status2linestate(status);
  186. }
  187. kfree(status_buf);
  188. return rc;
  189. }
  190. /*
  191. * Driver's tty interface functions
  192. */
  193. static int klsi_105_port_probe(struct usb_serial_port *port)
  194. {
  195. struct klsi_105_private *priv;
  196. priv = kmalloc(sizeof(*priv), GFP_KERNEL);
  197. if (!priv)
  198. return -ENOMEM;
  199. /* set initial values for control structures */
  200. priv->cfg.pktlen = 5;
  201. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  202. priv->cfg.databits = kl5kusb105a_dtb_8;
  203. priv->cfg.unknown1 = 0;
  204. priv->cfg.unknown2 = 1;
  205. priv->line_state = 0;
  206. spin_lock_init(&priv->lock);
  207. /* priv->termios is left uninitialized until port opening */
  208. usb_set_serial_port_data(port, priv);
  209. return 0;
  210. }
  211. static int klsi_105_port_remove(struct usb_serial_port *port)
  212. {
  213. struct klsi_105_private *priv;
  214. priv = usb_get_serial_port_data(port);
  215. kfree(priv);
  216. return 0;
  217. }
  218. static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
  219. {
  220. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  221. int retval = 0;
  222. int rc;
  223. int i;
  224. unsigned long line_state;
  225. struct klsi_105_port_settings *cfg;
  226. unsigned long flags;
  227. /* Do a defined restart:
  228. * Set up sane default baud rate and send the 'READ_ON'
  229. * vendor command.
  230. * FIXME: set modem line control (how?)
  231. * Then read the modem line control and store values in
  232. * priv->line_state.
  233. */
  234. cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  235. if (!cfg) {
  236. dev_err(&port->dev, "%s - out of memory for config buffer.\n",
  237. __func__);
  238. return -ENOMEM;
  239. }
  240. cfg->pktlen = 5;
  241. cfg->baudrate = kl5kusb105a_sio_b9600;
  242. cfg->databits = kl5kusb105a_dtb_8;
  243. cfg->unknown1 = 0;
  244. cfg->unknown2 = 1;
  245. klsi_105_chg_port_settings(port, cfg);
  246. /* set up termios structure */
  247. spin_lock_irqsave(&priv->lock, flags);
  248. priv->termios.c_iflag = tty->termios.c_iflag;
  249. priv->termios.c_oflag = tty->termios.c_oflag;
  250. priv->termios.c_cflag = tty->termios.c_cflag;
  251. priv->termios.c_lflag = tty->termios.c_lflag;
  252. for (i = 0; i < NCCS; i++)
  253. priv->termios.c_cc[i] = tty->termios.c_cc[i];
  254. priv->cfg.pktlen = cfg->pktlen;
  255. priv->cfg.baudrate = cfg->baudrate;
  256. priv->cfg.databits = cfg->databits;
  257. priv->cfg.unknown1 = cfg->unknown1;
  258. priv->cfg.unknown2 = cfg->unknown2;
  259. spin_unlock_irqrestore(&priv->lock, flags);
  260. /* READ_ON and urb submission */
  261. rc = usb_serial_generic_open(tty, port);
  262. if (rc) {
  263. retval = rc;
  264. goto exit;
  265. }
  266. rc = usb_control_msg(port->serial->dev,
  267. usb_sndctrlpipe(port->serial->dev, 0),
  268. KL5KUSB105A_SIO_CONFIGURE,
  269. USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
  270. KL5KUSB105A_SIO_CONFIGURE_READ_ON,
  271. 0, /* index */
  272. NULL,
  273. 0,
  274. KLSI_TIMEOUT);
  275. if (rc < 0) {
  276. dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc);
  277. retval = rc;
  278. } else
  279. dev_dbg(&port->dev, "%s - enabled reading\n", __func__);
  280. rc = klsi_105_get_line_state(port, &line_state);
  281. if (rc >= 0) {
  282. spin_lock_irqsave(&priv->lock, flags);
  283. priv->line_state = line_state;
  284. spin_unlock_irqrestore(&priv->lock, flags);
  285. dev_dbg(&port->dev, "%s - read line state 0x%lx\n", __func__, line_state);
  286. retval = 0;
  287. } else
  288. retval = rc;
  289. exit:
  290. kfree(cfg);
  291. return retval;
  292. }
  293. static void klsi_105_close(struct usb_serial_port *port)
  294. {
  295. int rc;
  296. mutex_lock(&port->serial->disc_mutex);
  297. if (!port->serial->disconnected) {
  298. /* send READ_OFF */
  299. rc = usb_control_msg(port->serial->dev,
  300. usb_sndctrlpipe(port->serial->dev, 0),
  301. KL5KUSB105A_SIO_CONFIGURE,
  302. USB_TYPE_VENDOR | USB_DIR_OUT,
  303. KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
  304. 0, /* index */
  305. NULL, 0,
  306. KLSI_TIMEOUT);
  307. if (rc < 0)
  308. dev_err(&port->dev,
  309. "Disabling read failed (error = %d)\n", rc);
  310. }
  311. mutex_unlock(&port->serial->disc_mutex);
  312. /* shutdown our bulk reads and writes */
  313. usb_serial_generic_close(port);
  314. /* wgg - do I need this? I think so. */
  315. usb_kill_urb(port->interrupt_in_urb);
  316. }
  317. /* We need to write a complete 64-byte data block and encode the
  318. * number actually sent in the first double-byte, LSB-order. That
  319. * leaves at most 62 bytes of payload.
  320. */
  321. #define KLSI_HDR_LEN 2
  322. static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
  323. void *dest, size_t size)
  324. {
  325. unsigned char *buf = dest;
  326. int count;
  327. count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
  328. &port->lock);
  329. put_unaligned_le16(count, buf);
  330. return count + KLSI_HDR_LEN;
  331. }
  332. /* The data received is preceded by a length double-byte in LSB-first order.
  333. */
  334. static void klsi_105_process_read_urb(struct urb *urb)
  335. {
  336. struct usb_serial_port *port = urb->context;
  337. unsigned char *data = urb->transfer_buffer;
  338. unsigned len;
  339. /* empty urbs seem to happen, we ignore them */
  340. if (!urb->actual_length)
  341. return;
  342. if (urb->actual_length <= KLSI_HDR_LEN) {
  343. dev_dbg(&port->dev, "%s - malformed packet\n", __func__);
  344. return;
  345. }
  346. len = get_unaligned_le16(data);
  347. if (len > urb->actual_length - KLSI_HDR_LEN) {
  348. dev_dbg(&port->dev, "%s - packet length mismatch\n", __func__);
  349. len = urb->actual_length - KLSI_HDR_LEN;
  350. }
  351. tty_insert_flip_string(&port->port, data + KLSI_HDR_LEN, len);
  352. tty_flip_buffer_push(&port->port);
  353. }
  354. static void klsi_105_set_termios(struct tty_struct *tty,
  355. struct usb_serial_port *port,
  356. struct ktermios *old_termios)
  357. {
  358. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  359. struct device *dev = &port->dev;
  360. unsigned int iflag = tty->termios.c_iflag;
  361. unsigned int old_iflag = old_termios->c_iflag;
  362. unsigned int cflag = tty->termios.c_cflag;
  363. unsigned int old_cflag = old_termios->c_cflag;
  364. struct klsi_105_port_settings *cfg;
  365. unsigned long flags;
  366. speed_t baud;
  367. cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  368. if (!cfg) {
  369. dev_err(dev, "%s - out of memory for config buffer.\n", __func__);
  370. return;
  371. }
  372. /* lock while we are modifying the settings */
  373. spin_lock_irqsave(&priv->lock, flags);
  374. /*
  375. * Update baud rate
  376. */
  377. baud = tty_get_baud_rate(tty);
  378. if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
  379. /* reassert DTR and (maybe) RTS on transition from B0 */
  380. if ((old_cflag & CBAUD) == B0) {
  381. dev_dbg(dev, "%s: baud was B0\n", __func__);
  382. #if 0
  383. priv->control_state |= TIOCM_DTR;
  384. /* don't set RTS if using hardware flow control */
  385. if (!(old_cflag & CRTSCTS))
  386. priv->control_state |= TIOCM_RTS;
  387. mct_u232_set_modem_ctrl(serial, priv->control_state);
  388. #endif
  389. }
  390. }
  391. switch (baud) {
  392. case 0: /* handled below */
  393. break;
  394. case 1200:
  395. priv->cfg.baudrate = kl5kusb105a_sio_b1200;
  396. break;
  397. case 2400:
  398. priv->cfg.baudrate = kl5kusb105a_sio_b2400;
  399. break;
  400. case 4800:
  401. priv->cfg.baudrate = kl5kusb105a_sio_b4800;
  402. break;
  403. case 9600:
  404. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  405. break;
  406. case 19200:
  407. priv->cfg.baudrate = kl5kusb105a_sio_b19200;
  408. break;
  409. case 38400:
  410. priv->cfg.baudrate = kl5kusb105a_sio_b38400;
  411. break;
  412. case 57600:
  413. priv->cfg.baudrate = kl5kusb105a_sio_b57600;
  414. break;
  415. case 115200:
  416. priv->cfg.baudrate = kl5kusb105a_sio_b115200;
  417. break;
  418. default:
  419. dev_dbg(dev, "KLSI USB->Serial converter: unsupported baudrate request, using default of 9600");
  420. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  421. baud = 9600;
  422. break;
  423. }
  424. if ((cflag & CBAUD) == B0) {
  425. dev_dbg(dev, "%s: baud is B0\n", __func__);
  426. /* Drop RTS and DTR */
  427. /* maybe this should be simulated by sending read
  428. * disable and read enable messages?
  429. */
  430. ;
  431. #if 0
  432. priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
  433. mct_u232_set_modem_ctrl(serial, priv->control_state);
  434. #endif
  435. }
  436. tty_encode_baud_rate(tty, baud, baud);
  437. if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
  438. /* set the number of data bits */
  439. switch (cflag & CSIZE) {
  440. case CS5:
  441. dev_dbg(dev, "%s - 5 bits/byte not supported\n", __func__);
  442. spin_unlock_irqrestore(&priv->lock, flags);
  443. goto err;
  444. case CS6:
  445. dev_dbg(dev, "%s - 6 bits/byte not supported\n", __func__);
  446. spin_unlock_irqrestore(&priv->lock, flags);
  447. goto err;
  448. case CS7:
  449. priv->cfg.databits = kl5kusb105a_dtb_7;
  450. break;
  451. case CS8:
  452. priv->cfg.databits = kl5kusb105a_dtb_8;
  453. break;
  454. default:
  455. dev_err(dev, "CSIZE was not CS5-CS8, using default of 8\n");
  456. priv->cfg.databits = kl5kusb105a_dtb_8;
  457. break;
  458. }
  459. }
  460. /*
  461. * Update line control register (LCR)
  462. */
  463. if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
  464. || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
  465. /* Not currently supported */
  466. tty->termios.c_cflag &= ~(PARENB|PARODD|CSTOPB);
  467. #if 0
  468. priv->last_lcr = 0;
  469. /* set the parity */
  470. if (cflag & PARENB)
  471. priv->last_lcr |= (cflag & PARODD) ?
  472. MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
  473. else
  474. priv->last_lcr |= MCT_U232_PARITY_NONE;
  475. /* set the number of stop bits */
  476. priv->last_lcr |= (cflag & CSTOPB) ?
  477. MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
  478. mct_u232_set_line_ctrl(serial, priv->last_lcr);
  479. #endif
  480. ;
  481. }
  482. /*
  483. * Set flow control: well, I do not really now how to handle DTR/RTS.
  484. * Just do what we have seen with SniffUSB on Win98.
  485. */
  486. if ((iflag & IXOFF) != (old_iflag & IXOFF)
  487. || (iflag & IXON) != (old_iflag & IXON)
  488. || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
  489. /* Not currently supported */
  490. tty->termios.c_cflag &= ~CRTSCTS;
  491. /* Drop DTR/RTS if no flow control otherwise assert */
  492. #if 0
  493. if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
  494. priv->control_state |= TIOCM_DTR | TIOCM_RTS;
  495. else
  496. priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
  497. mct_u232_set_modem_ctrl(serial, priv->control_state);
  498. #endif
  499. ;
  500. }
  501. memcpy(cfg, &priv->cfg, sizeof(*cfg));
  502. spin_unlock_irqrestore(&priv->lock, flags);
  503. /* now commit changes to device */
  504. klsi_105_chg_port_settings(port, cfg);
  505. err:
  506. kfree(cfg);
  507. }
  508. #if 0
  509. static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
  510. {
  511. struct usb_serial_port *port = tty->driver_data;
  512. struct usb_serial *serial = port->serial;
  513. struct mct_u232_private *priv =
  514. (struct mct_u232_private *)port->private;
  515. unsigned char lcr = priv->last_lcr;
  516. dev_dbg(&port->dev, "%s - state=%d\n", __func__, break_state);
  517. /* LOCKING */
  518. if (break_state)
  519. lcr |= MCT_U232_SET_BREAK;
  520. mct_u232_set_line_ctrl(serial, lcr);
  521. }
  522. #endif
  523. static int klsi_105_tiocmget(struct tty_struct *tty)
  524. {
  525. struct usb_serial_port *port = tty->driver_data;
  526. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  527. unsigned long flags;
  528. int rc;
  529. unsigned long line_state;
  530. rc = klsi_105_get_line_state(port, &line_state);
  531. if (rc < 0) {
  532. dev_err(&port->dev,
  533. "Reading line control failed (error = %d)\n", rc);
  534. /* better return value? EAGAIN? */
  535. return rc;
  536. }
  537. spin_lock_irqsave(&priv->lock, flags);
  538. priv->line_state = line_state;
  539. spin_unlock_irqrestore(&priv->lock, flags);
  540. dev_dbg(&port->dev, "%s - read line state 0x%lx\n", __func__, line_state);
  541. return (int)line_state;
  542. }
  543. static int klsi_105_tiocmset(struct tty_struct *tty,
  544. unsigned int set, unsigned int clear)
  545. {
  546. int retval = -EINVAL;
  547. /* if this ever gets implemented, it should be done something like this:
  548. struct usb_serial *serial = port->serial;
  549. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  550. unsigned long flags;
  551. int control;
  552. spin_lock_irqsave (&priv->lock, flags);
  553. if (set & TIOCM_RTS)
  554. priv->control_state |= TIOCM_RTS;
  555. if (set & TIOCM_DTR)
  556. priv->control_state |= TIOCM_DTR;
  557. if (clear & TIOCM_RTS)
  558. priv->control_state &= ~TIOCM_RTS;
  559. if (clear & TIOCM_DTR)
  560. priv->control_state &= ~TIOCM_DTR;
  561. control = priv->control_state;
  562. spin_unlock_irqrestore (&priv->lock, flags);
  563. retval = mct_u232_set_modem_ctrl(serial, control);
  564. */
  565. return retval;
  566. }
  567. module_usb_serial_driver(serial_drivers, id_table);
  568. MODULE_AUTHOR(DRIVER_AUTHOR);
  569. MODULE_DESCRIPTION(DRIVER_DESC);
  570. MODULE_LICENSE("GPL");