kl5kusb105.c 18 KB

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