kl5kusb105.c 18 KB

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