kl5kusb105.c 18 KB

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