kl5kusb105.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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_startup(struct usb_serial *serial);
  59. static void klsi_105_release(struct usb_serial *serial);
  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. .attach = klsi_105_startup,
  95. .release = klsi_105_release,
  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_startup(struct usb_serial *serial)
  198. {
  199. struct klsi_105_private *priv;
  200. int i;
  201. /* check if we support the product id (see keyspan.c)
  202. * FIXME
  203. */
  204. /* allocate the private data structure */
  205. for (i = 0; i < serial->num_ports; i++) {
  206. priv = kmalloc(sizeof(struct klsi_105_private),
  207. GFP_KERNEL);
  208. if (!priv) {
  209. dev_dbg(&serial->interface->dev,
  210. "%s - kmalloc for klsi_105_private failed.\n",
  211. __func__);
  212. i--;
  213. goto err_cleanup;
  214. }
  215. /* set initial values for control structures */
  216. priv->cfg.pktlen = 5;
  217. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  218. priv->cfg.databits = kl5kusb105a_dtb_8;
  219. priv->cfg.unknown1 = 0;
  220. priv->cfg.unknown2 = 1;
  221. priv->line_state = 0;
  222. usb_set_serial_port_data(serial->port[i], priv);
  223. spin_lock_init(&priv->lock);
  224. /* priv->termios is left uninitialized until port opening */
  225. init_waitqueue_head(&serial->port[i]->write_wait);
  226. }
  227. return 0;
  228. err_cleanup:
  229. for (; i >= 0; i--) {
  230. priv = usb_get_serial_port_data(serial->port[i]);
  231. kfree(priv);
  232. usb_set_serial_port_data(serial->port[i], NULL);
  233. }
  234. return -ENOMEM;
  235. }
  236. static void klsi_105_release(struct usb_serial *serial)
  237. {
  238. int i;
  239. for (i = 0; i < serial->num_ports; ++i)
  240. kfree(usb_get_serial_port_data(serial->port[i]));
  241. }
  242. static int klsi_105_open(struct tty_struct *tty, struct usb_serial_port *port)
  243. {
  244. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  245. int retval = 0;
  246. int rc;
  247. int i;
  248. unsigned long line_state;
  249. struct klsi_105_port_settings *cfg;
  250. unsigned long flags;
  251. /* Do a defined restart:
  252. * Set up sane default baud rate and send the 'READ_ON'
  253. * vendor command.
  254. * FIXME: set modem line control (how?)
  255. * Then read the modem line control and store values in
  256. * priv->line_state.
  257. */
  258. cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  259. if (!cfg) {
  260. dev_err(&port->dev, "%s - out of memory for config buffer.\n",
  261. __func__);
  262. return -ENOMEM;
  263. }
  264. cfg->pktlen = 5;
  265. cfg->baudrate = kl5kusb105a_sio_b9600;
  266. cfg->databits = kl5kusb105a_dtb_8;
  267. cfg->unknown1 = 0;
  268. cfg->unknown2 = 1;
  269. klsi_105_chg_port_settings(port, cfg);
  270. /* set up termios structure */
  271. spin_lock_irqsave(&priv->lock, flags);
  272. priv->termios.c_iflag = tty->termios.c_iflag;
  273. priv->termios.c_oflag = tty->termios.c_oflag;
  274. priv->termios.c_cflag = tty->termios.c_cflag;
  275. priv->termios.c_lflag = tty->termios.c_lflag;
  276. for (i = 0; i < NCCS; i++)
  277. priv->termios.c_cc[i] = tty->termios.c_cc[i];
  278. priv->cfg.pktlen = cfg->pktlen;
  279. priv->cfg.baudrate = cfg->baudrate;
  280. priv->cfg.databits = cfg->databits;
  281. priv->cfg.unknown1 = cfg->unknown1;
  282. priv->cfg.unknown2 = cfg->unknown2;
  283. spin_unlock_irqrestore(&priv->lock, flags);
  284. /* READ_ON and urb submission */
  285. rc = usb_serial_generic_open(tty, port);
  286. if (rc) {
  287. retval = rc;
  288. goto exit;
  289. }
  290. rc = usb_control_msg(port->serial->dev,
  291. usb_sndctrlpipe(port->serial->dev, 0),
  292. KL5KUSB105A_SIO_CONFIGURE,
  293. USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
  294. KL5KUSB105A_SIO_CONFIGURE_READ_ON,
  295. 0, /* index */
  296. NULL,
  297. 0,
  298. KLSI_TIMEOUT);
  299. if (rc < 0) {
  300. dev_err(&port->dev, "Enabling read failed (error = %d)\n", rc);
  301. retval = rc;
  302. } else
  303. dev_dbg(&port->dev, "%s - enabled reading\n", __func__);
  304. rc = klsi_105_get_line_state(port, &line_state);
  305. if (rc >= 0) {
  306. spin_lock_irqsave(&priv->lock, flags);
  307. priv->line_state = line_state;
  308. spin_unlock_irqrestore(&priv->lock, flags);
  309. dev_dbg(&port->dev, "%s - read line state 0x%lx\n", __func__, line_state);
  310. retval = 0;
  311. } else
  312. retval = rc;
  313. exit:
  314. kfree(cfg);
  315. return retval;
  316. }
  317. static void klsi_105_close(struct usb_serial_port *port)
  318. {
  319. int rc;
  320. mutex_lock(&port->serial->disc_mutex);
  321. if (!port->serial->disconnected) {
  322. /* send READ_OFF */
  323. rc = usb_control_msg(port->serial->dev,
  324. usb_sndctrlpipe(port->serial->dev, 0),
  325. KL5KUSB105A_SIO_CONFIGURE,
  326. USB_TYPE_VENDOR | USB_DIR_OUT,
  327. KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
  328. 0, /* index */
  329. NULL, 0,
  330. KLSI_TIMEOUT);
  331. if (rc < 0)
  332. dev_err(&port->dev,
  333. "Disabling read failed (error = %d)\n", rc);
  334. }
  335. mutex_unlock(&port->serial->disc_mutex);
  336. /* shutdown our bulk reads and writes */
  337. usb_serial_generic_close(port);
  338. /* wgg - do I need this? I think so. */
  339. usb_kill_urb(port->interrupt_in_urb);
  340. }
  341. /* We need to write a complete 64-byte data block and encode the
  342. * number actually sent in the first double-byte, LSB-order. That
  343. * leaves at most 62 bytes of payload.
  344. */
  345. #define KLSI_HDR_LEN 2
  346. static int klsi_105_prepare_write_buffer(struct usb_serial_port *port,
  347. void *dest, size_t size)
  348. {
  349. unsigned char *buf = dest;
  350. int count;
  351. count = kfifo_out_locked(&port->write_fifo, buf + KLSI_HDR_LEN, size,
  352. &port->lock);
  353. put_unaligned_le16(count, buf);
  354. return count + KLSI_HDR_LEN;
  355. }
  356. /* The data received is preceded by a length double-byte in LSB-first order.
  357. */
  358. static void klsi_105_process_read_urb(struct urb *urb)
  359. {
  360. struct usb_serial_port *port = urb->context;
  361. unsigned char *data = urb->transfer_buffer;
  362. struct tty_struct *tty;
  363. unsigned len;
  364. /* empty urbs seem to happen, we ignore them */
  365. if (!urb->actual_length)
  366. return;
  367. if (urb->actual_length <= KLSI_HDR_LEN) {
  368. dev_dbg(&port->dev, "%s - malformed packet\n", __func__);
  369. return;
  370. }
  371. tty = tty_port_tty_get(&port->port);
  372. if (!tty)
  373. return;
  374. len = get_unaligned_le16(data);
  375. if (len > urb->actual_length - KLSI_HDR_LEN) {
  376. dev_dbg(&port->dev, "%s - packet length mismatch\n", __func__);
  377. len = urb->actual_length - KLSI_HDR_LEN;
  378. }
  379. tty_insert_flip_string(tty, data + KLSI_HDR_LEN, len);
  380. tty_flip_buffer_push(tty);
  381. tty_kref_put(tty);
  382. }
  383. static void klsi_105_set_termios(struct tty_struct *tty,
  384. struct usb_serial_port *port,
  385. struct ktermios *old_termios)
  386. {
  387. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  388. struct device *dev = &port->dev;
  389. unsigned int iflag = tty->termios.c_iflag;
  390. unsigned int old_iflag = old_termios->c_iflag;
  391. unsigned int cflag = tty->termios.c_cflag;
  392. unsigned int old_cflag = old_termios->c_cflag;
  393. struct klsi_105_port_settings *cfg;
  394. unsigned long flags;
  395. speed_t baud;
  396. cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  397. if (!cfg) {
  398. dev_err(dev, "%s - out of memory for config buffer.\n", __func__);
  399. return;
  400. }
  401. /* lock while we are modifying the settings */
  402. spin_lock_irqsave(&priv->lock, flags);
  403. /*
  404. * Update baud rate
  405. */
  406. baud = tty_get_baud_rate(tty);
  407. if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
  408. /* reassert DTR and (maybe) RTS on transition from B0 */
  409. if ((old_cflag & CBAUD) == B0) {
  410. dev_dbg(dev, "%s: baud was B0\n", __func__);
  411. #if 0
  412. priv->control_state |= TIOCM_DTR;
  413. /* don't set RTS if using hardware flow control */
  414. if (!(old_cflag & CRTSCTS))
  415. priv->control_state |= TIOCM_RTS;
  416. mct_u232_set_modem_ctrl(serial, priv->control_state);
  417. #endif
  418. }
  419. }
  420. switch (baud) {
  421. case 0: /* handled below */
  422. break;
  423. case 1200:
  424. priv->cfg.baudrate = kl5kusb105a_sio_b1200;
  425. break;
  426. case 2400:
  427. priv->cfg.baudrate = kl5kusb105a_sio_b2400;
  428. break;
  429. case 4800:
  430. priv->cfg.baudrate = kl5kusb105a_sio_b4800;
  431. break;
  432. case 9600:
  433. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  434. break;
  435. case 19200:
  436. priv->cfg.baudrate = kl5kusb105a_sio_b19200;
  437. break;
  438. case 38400:
  439. priv->cfg.baudrate = kl5kusb105a_sio_b38400;
  440. break;
  441. case 57600:
  442. priv->cfg.baudrate = kl5kusb105a_sio_b57600;
  443. break;
  444. case 115200:
  445. priv->cfg.baudrate = kl5kusb105a_sio_b115200;
  446. break;
  447. default:
  448. dev_dbg(dev, "KLSI USB->Serial converter: unsupported baudrate request, using default of 9600");
  449. priv->cfg.baudrate = kl5kusb105a_sio_b9600;
  450. baud = 9600;
  451. break;
  452. }
  453. if ((cflag & CBAUD) == B0) {
  454. dev_dbg(dev, "%s: baud is B0\n", __func__);
  455. /* Drop RTS and DTR */
  456. /* maybe this should be simulated by sending read
  457. * disable and read enable messages?
  458. */
  459. ;
  460. #if 0
  461. priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
  462. mct_u232_set_modem_ctrl(serial, priv->control_state);
  463. #endif
  464. }
  465. tty_encode_baud_rate(tty, baud, baud);
  466. if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
  467. /* set the number of data bits */
  468. switch (cflag & CSIZE) {
  469. case CS5:
  470. dev_dbg(dev, "%s - 5 bits/byte not supported\n", __func__);
  471. spin_unlock_irqrestore(&priv->lock, flags);
  472. goto err;
  473. case CS6:
  474. dev_dbg(dev, "%s - 6 bits/byte not supported\n", __func__);
  475. spin_unlock_irqrestore(&priv->lock, flags);
  476. goto err;
  477. case CS7:
  478. priv->cfg.databits = kl5kusb105a_dtb_7;
  479. break;
  480. case CS8:
  481. priv->cfg.databits = kl5kusb105a_dtb_8;
  482. break;
  483. default:
  484. dev_err(dev, "CSIZE was not CS5-CS8, using default of 8\n");
  485. priv->cfg.databits = kl5kusb105a_dtb_8;
  486. break;
  487. }
  488. }
  489. /*
  490. * Update line control register (LCR)
  491. */
  492. if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
  493. || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
  494. /* Not currently supported */
  495. tty->termios.c_cflag &= ~(PARENB|PARODD|CSTOPB);
  496. #if 0
  497. priv->last_lcr = 0;
  498. /* set the parity */
  499. if (cflag & PARENB)
  500. priv->last_lcr |= (cflag & PARODD) ?
  501. MCT_U232_PARITY_ODD : MCT_U232_PARITY_EVEN;
  502. else
  503. priv->last_lcr |= MCT_U232_PARITY_NONE;
  504. /* set the number of stop bits */
  505. priv->last_lcr |= (cflag & CSTOPB) ?
  506. MCT_U232_STOP_BITS_2 : MCT_U232_STOP_BITS_1;
  507. mct_u232_set_line_ctrl(serial, priv->last_lcr);
  508. #endif
  509. ;
  510. }
  511. /*
  512. * Set flow control: well, I do not really now how to handle DTR/RTS.
  513. * Just do what we have seen with SniffUSB on Win98.
  514. */
  515. if ((iflag & IXOFF) != (old_iflag & IXOFF)
  516. || (iflag & IXON) != (old_iflag & IXON)
  517. || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
  518. /* Not currently supported */
  519. tty->termios.c_cflag &= ~CRTSCTS;
  520. /* Drop DTR/RTS if no flow control otherwise assert */
  521. #if 0
  522. if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
  523. priv->control_state |= TIOCM_DTR | TIOCM_RTS;
  524. else
  525. priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
  526. mct_u232_set_modem_ctrl(serial, priv->control_state);
  527. #endif
  528. ;
  529. }
  530. memcpy(cfg, &priv->cfg, sizeof(*cfg));
  531. spin_unlock_irqrestore(&priv->lock, flags);
  532. /* now commit changes to device */
  533. klsi_105_chg_port_settings(port, cfg);
  534. err:
  535. kfree(cfg);
  536. }
  537. #if 0
  538. static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
  539. {
  540. struct usb_serial_port *port = tty->driver_data;
  541. struct usb_serial *serial = port->serial;
  542. struct mct_u232_private *priv =
  543. (struct mct_u232_private *)port->private;
  544. unsigned char lcr = priv->last_lcr;
  545. dev_dbg(&port->dev, "%s - state=%d\n", __func__, break_state);
  546. /* LOCKING */
  547. if (break_state)
  548. lcr |= MCT_U232_SET_BREAK;
  549. mct_u232_set_line_ctrl(serial, lcr);
  550. }
  551. #endif
  552. static int klsi_105_tiocmget(struct tty_struct *tty)
  553. {
  554. struct usb_serial_port *port = tty->driver_data;
  555. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  556. unsigned long flags;
  557. int rc;
  558. unsigned long line_state;
  559. rc = klsi_105_get_line_state(port, &line_state);
  560. if (rc < 0) {
  561. dev_err(&port->dev,
  562. "Reading line control failed (error = %d)\n", rc);
  563. /* better return value? EAGAIN? */
  564. return rc;
  565. }
  566. spin_lock_irqsave(&priv->lock, flags);
  567. priv->line_state = line_state;
  568. spin_unlock_irqrestore(&priv->lock, flags);
  569. dev_dbg(&port->dev, "%s - read line state 0x%lx\n", __func__, line_state);
  570. return (int)line_state;
  571. }
  572. static int klsi_105_tiocmset(struct tty_struct *tty,
  573. unsigned int set, unsigned int clear)
  574. {
  575. int retval = -EINVAL;
  576. /* if this ever gets implemented, it should be done something like this:
  577. struct usb_serial *serial = port->serial;
  578. struct klsi_105_private *priv = usb_get_serial_port_data(port);
  579. unsigned long flags;
  580. int control;
  581. spin_lock_irqsave (&priv->lock, flags);
  582. if (set & TIOCM_RTS)
  583. priv->control_state |= TIOCM_RTS;
  584. if (set & TIOCM_DTR)
  585. priv->control_state |= TIOCM_DTR;
  586. if (clear & TIOCM_RTS)
  587. priv->control_state &= ~TIOCM_RTS;
  588. if (clear & TIOCM_DTR)
  589. priv->control_state &= ~TIOCM_DTR;
  590. control = priv->control_state;
  591. spin_unlock_irqrestore (&priv->lock, flags);
  592. retval = mct_u232_set_modem_ctrl(serial, control);
  593. */
  594. return retval;
  595. }
  596. module_usb_serial_driver(serial_drivers, id_table);
  597. MODULE_AUTHOR(DRIVER_AUTHOR);
  598. MODULE_DESCRIPTION(DRIVER_DESC);
  599. MODULE_LICENSE("GPL");