kl5kusb105.c 19 KB

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