spcp8x5.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * spcp8x5 USB to serial adaptor driver
  3. *
  4. * Copyright (C) 2010 Johan Hovold (jhovold@gmail.com)
  5. * Copyright (C) 2006 Linxb (xubin.lin@worldplus.com.cn)
  6. * Copyright (C) 2006 S1 Corp.
  7. *
  8. * Original driver for 2.6.10 pl2303 driver by
  9. * Greg Kroah-Hartman (greg@kroah.com)
  10. * Changes for 2.6.20 by Harald Klein <hari@vt100.at>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. *
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/errno.h>
  21. #include <linux/init.h>
  22. #include <linux/slab.h>
  23. #include <linux/tty.h>
  24. #include <linux/tty_driver.h>
  25. #include <linux/tty_flip.h>
  26. #include <linux/module.h>
  27. #include <linux/spinlock.h>
  28. #include <linux/usb.h>
  29. #include <linux/usb/serial.h>
  30. #define DRIVER_DESC "SPCP8x5 USB to serial adaptor driver"
  31. #define SPCP8x5_007_VID 0x04FC
  32. #define SPCP8x5_007_PID 0x0201
  33. #define SPCP8x5_008_VID 0x04fc
  34. #define SPCP8x5_008_PID 0x0235
  35. #define SPCP8x5_PHILIPS_VID 0x0471
  36. #define SPCP8x5_PHILIPS_PID 0x081e
  37. #define SPCP8x5_INTERMATIC_VID 0x04FC
  38. #define SPCP8x5_INTERMATIC_PID 0x0204
  39. #define SPCP8x5_835_VID 0x04fc
  40. #define SPCP8x5_835_PID 0x0231
  41. static const struct usb_device_id id_table[] = {
  42. { USB_DEVICE(SPCP8x5_PHILIPS_VID , SPCP8x5_PHILIPS_PID)},
  43. { USB_DEVICE(SPCP8x5_INTERMATIC_VID, SPCP8x5_INTERMATIC_PID)},
  44. { USB_DEVICE(SPCP8x5_835_VID, SPCP8x5_835_PID)},
  45. { USB_DEVICE(SPCP8x5_008_VID, SPCP8x5_008_PID)},
  46. { USB_DEVICE(SPCP8x5_007_VID, SPCP8x5_007_PID)},
  47. { } /* Terminating entry */
  48. };
  49. MODULE_DEVICE_TABLE(usb, id_table);
  50. struct spcp8x5_usb_ctrl_arg {
  51. u8 type;
  52. u8 cmd;
  53. u8 cmd_type;
  54. u16 value;
  55. u16 index;
  56. u16 length;
  57. };
  58. /* spcp8x5 spec register define */
  59. #define MCR_CONTROL_LINE_RTS 0x02
  60. #define MCR_CONTROL_LINE_DTR 0x01
  61. #define MCR_DTR 0x01
  62. #define MCR_RTS 0x02
  63. #define MSR_STATUS_LINE_DCD 0x80
  64. #define MSR_STATUS_LINE_RI 0x40
  65. #define MSR_STATUS_LINE_DSR 0x20
  66. #define MSR_STATUS_LINE_CTS 0x10
  67. /* verdor command here , we should define myself */
  68. #define SET_DEFAULT 0x40
  69. #define SET_DEFAULT_TYPE 0x20
  70. #define SET_UART_FORMAT 0x40
  71. #define SET_UART_FORMAT_TYPE 0x21
  72. #define SET_UART_FORMAT_SIZE_5 0x00
  73. #define SET_UART_FORMAT_SIZE_6 0x01
  74. #define SET_UART_FORMAT_SIZE_7 0x02
  75. #define SET_UART_FORMAT_SIZE_8 0x03
  76. #define SET_UART_FORMAT_STOP_1 0x00
  77. #define SET_UART_FORMAT_STOP_2 0x04
  78. #define SET_UART_FORMAT_PAR_NONE 0x00
  79. #define SET_UART_FORMAT_PAR_ODD 0x10
  80. #define SET_UART_FORMAT_PAR_EVEN 0x30
  81. #define SET_UART_FORMAT_PAR_MASK 0xD0
  82. #define SET_UART_FORMAT_PAR_SPACE 0x90
  83. #define GET_UART_STATUS_TYPE 0xc0
  84. #define GET_UART_STATUS 0x22
  85. #define GET_UART_STATUS_MSR 0x06
  86. #define SET_UART_STATUS 0x40
  87. #define SET_UART_STATUS_TYPE 0x23
  88. #define SET_UART_STATUS_MCR 0x0004
  89. #define SET_UART_STATUS_MCR_DTR 0x01
  90. #define SET_UART_STATUS_MCR_RTS 0x02
  91. #define SET_UART_STATUS_MCR_LOOP 0x10
  92. #define SET_WORKING_MODE 0x40
  93. #define SET_WORKING_MODE_TYPE 0x24
  94. #define SET_WORKING_MODE_U2C 0x00
  95. #define SET_WORKING_MODE_RS485 0x01
  96. #define SET_WORKING_MODE_PDMA 0x02
  97. #define SET_WORKING_MODE_SPP 0x03
  98. #define SET_FLOWCTL_CHAR 0x40
  99. #define SET_FLOWCTL_CHAR_TYPE 0x25
  100. #define GET_VERSION 0xc0
  101. #define GET_VERSION_TYPE 0x26
  102. #define SET_REGISTER 0x40
  103. #define SET_REGISTER_TYPE 0x27
  104. #define GET_REGISTER 0xc0
  105. #define GET_REGISTER_TYPE 0x28
  106. #define SET_RAM 0x40
  107. #define SET_RAM_TYPE 0x31
  108. #define GET_RAM 0xc0
  109. #define GET_RAM_TYPE 0x32
  110. /* how come ??? */
  111. #define UART_STATE 0x08
  112. #define UART_STATE_TRANSIENT_MASK 0x75
  113. #define UART_DCD 0x01
  114. #define UART_DSR 0x02
  115. #define UART_BREAK_ERROR 0x04
  116. #define UART_RING 0x08
  117. #define UART_FRAME_ERROR 0x10
  118. #define UART_PARITY_ERROR 0x20
  119. #define UART_OVERRUN_ERROR 0x40
  120. #define UART_CTS 0x80
  121. enum spcp8x5_type {
  122. SPCP825_007_TYPE,
  123. SPCP825_008_TYPE,
  124. SPCP825_PHILIP_TYPE,
  125. SPCP825_INTERMATIC_TYPE,
  126. SPCP835_TYPE,
  127. };
  128. struct spcp8x5_private {
  129. spinlock_t lock;
  130. enum spcp8x5_type type;
  131. u8 line_control;
  132. u8 line_status;
  133. };
  134. static int spcp8x5_port_probe(struct usb_serial_port *port)
  135. {
  136. struct usb_serial *serial = port->serial;
  137. struct spcp8x5_private *priv;
  138. enum spcp8x5_type type = SPCP825_007_TYPE;
  139. u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
  140. if (product == 0x0201)
  141. type = SPCP825_007_TYPE;
  142. else if (product == 0x0231)
  143. type = SPCP835_TYPE;
  144. else if (product == 0x0235)
  145. type = SPCP825_008_TYPE;
  146. else if (product == 0x0204)
  147. type = SPCP825_INTERMATIC_TYPE;
  148. else if (product == 0x0471 &&
  149. serial->dev->descriptor.idVendor == cpu_to_le16(0x081e))
  150. type = SPCP825_PHILIP_TYPE;
  151. dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
  152. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  153. if (!priv)
  154. return -ENOMEM;
  155. spin_lock_init(&priv->lock);
  156. priv->type = type;
  157. usb_set_serial_port_data(port , priv);
  158. return 0;
  159. }
  160. static int spcp8x5_port_remove(struct usb_serial_port *port)
  161. {
  162. struct spcp8x5_private *priv;
  163. priv = usb_get_serial_port_data(port);
  164. kfree(priv);
  165. return 0;
  166. }
  167. /* set the modem control line of the device.
  168. * NOTE spcp825-007 not supported this */
  169. static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
  170. enum spcp8x5_type type)
  171. {
  172. int retval;
  173. u8 mcr = 0 ;
  174. if (type == SPCP825_007_TYPE)
  175. return -EPERM;
  176. mcr = (unsigned short)value;
  177. retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  178. SET_UART_STATUS_TYPE, SET_UART_STATUS,
  179. mcr, 0x04, NULL, 0, 100);
  180. if (retval != 0)
  181. dev_dbg(&dev->dev, "usb_control_msg return %#x\n", retval);
  182. return retval;
  183. }
  184. /* get the modem status register of the device
  185. * NOTE spcp825-007 not supported this */
  186. static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
  187. enum spcp8x5_type type)
  188. {
  189. u8 *status_buffer;
  190. int ret;
  191. /* I return Permited not support here but seem inval device
  192. * is more fix */
  193. if (type == SPCP825_007_TYPE)
  194. return -EPERM;
  195. if (status == NULL)
  196. return -EINVAL;
  197. status_buffer = kmalloc(1, GFP_KERNEL);
  198. if (!status_buffer)
  199. return -ENOMEM;
  200. status_buffer[0] = status[0];
  201. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  202. GET_UART_STATUS, GET_UART_STATUS_TYPE,
  203. 0, GET_UART_STATUS_MSR, status_buffer, 1, 100);
  204. if (ret < 0)
  205. dev_dbg(&dev->dev, "Get MSR = 0x%p failed (error = %d)",
  206. status_buffer, ret);
  207. dev_dbg(&dev->dev, "0xc0:0x22:0:6 %d - 0x%p ", ret, status_buffer);
  208. status[0] = status_buffer[0];
  209. kfree(status_buffer);
  210. return ret;
  211. }
  212. /* select the work mode.
  213. * NOTE this function not supported by spcp825-007 */
  214. static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
  215. u16 index, enum spcp8x5_type type)
  216. {
  217. int ret;
  218. /* I return Permited not support here but seem inval device
  219. * is more fix */
  220. if (type == SPCP825_007_TYPE)
  221. return;
  222. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  223. SET_WORKING_MODE_TYPE, SET_WORKING_MODE,
  224. value, index, NULL, 0, 100);
  225. dev_dbg(&dev->dev, "value = %#x , index = %#x\n", value, index);
  226. if (ret < 0)
  227. dev_dbg(&dev->dev,
  228. "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
  229. }
  230. static int spcp8x5_carrier_raised(struct usb_serial_port *port)
  231. {
  232. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  233. if (priv->line_status & MSR_STATUS_LINE_DCD)
  234. return 1;
  235. return 0;
  236. }
  237. static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
  238. {
  239. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  240. unsigned long flags;
  241. u8 control;
  242. spin_lock_irqsave(&priv->lock, flags);
  243. if (on)
  244. priv->line_control = MCR_CONTROL_LINE_DTR
  245. | MCR_CONTROL_LINE_RTS;
  246. else
  247. priv->line_control &= ~ (MCR_CONTROL_LINE_DTR
  248. | MCR_CONTROL_LINE_RTS);
  249. control = priv->line_control;
  250. spin_unlock_irqrestore(&priv->lock, flags);
  251. spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
  252. }
  253. static void spcp8x5_init_termios(struct tty_struct *tty)
  254. {
  255. /* for the 1st time call this function */
  256. tty->termios = tty_std_termios;
  257. tty->termios.c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
  258. tty->termios.c_ispeed = 115200;
  259. tty->termios.c_ospeed = 115200;
  260. }
  261. /* set the serial param for transfer. we should check if we really need to
  262. * transfer. if we set flow control we should do this too. */
  263. static void spcp8x5_set_termios(struct tty_struct *tty,
  264. struct usb_serial_port *port, struct ktermios *old_termios)
  265. {
  266. struct usb_serial *serial = port->serial;
  267. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  268. unsigned long flags;
  269. unsigned int cflag = tty->termios.c_cflag;
  270. unsigned int old_cflag = old_termios->c_cflag;
  271. unsigned short uartdata;
  272. unsigned char buf[2] = {0, 0};
  273. int baud;
  274. int i;
  275. u8 control;
  276. /* check that they really want us to change something */
  277. if (!tty_termios_hw_change(&tty->termios, old_termios))
  278. return;
  279. /* set DTR/RTS active */
  280. spin_lock_irqsave(&priv->lock, flags);
  281. control = priv->line_control;
  282. if ((old_cflag & CBAUD) == B0) {
  283. priv->line_control |= MCR_DTR;
  284. if (!(old_cflag & CRTSCTS))
  285. priv->line_control |= MCR_RTS;
  286. }
  287. if (control != priv->line_control) {
  288. control = priv->line_control;
  289. spin_unlock_irqrestore(&priv->lock, flags);
  290. spcp8x5_set_ctrlLine(serial->dev, control , priv->type);
  291. } else {
  292. spin_unlock_irqrestore(&priv->lock, flags);
  293. }
  294. /* Set Baud Rate */
  295. baud = tty_get_baud_rate(tty);
  296. switch (baud) {
  297. case 300: buf[0] = 0x00; break;
  298. case 600: buf[0] = 0x01; break;
  299. case 1200: buf[0] = 0x02; break;
  300. case 2400: buf[0] = 0x03; break;
  301. case 4800: buf[0] = 0x04; break;
  302. case 9600: buf[0] = 0x05; break;
  303. case 19200: buf[0] = 0x07; break;
  304. case 38400: buf[0] = 0x09; break;
  305. case 57600: buf[0] = 0x0a; break;
  306. case 115200: buf[0] = 0x0b; break;
  307. case 230400: buf[0] = 0x0c; break;
  308. case 460800: buf[0] = 0x0d; break;
  309. case 921600: buf[0] = 0x0e; break;
  310. /* case 1200000: buf[0] = 0x0f; break; */
  311. /* case 2400000: buf[0] = 0x10; break; */
  312. case 3000000: buf[0] = 0x11; break;
  313. /* case 6000000: buf[0] = 0x12; break; */
  314. case 0:
  315. case 1000000:
  316. buf[0] = 0x0b; break;
  317. default:
  318. dev_err(&port->dev, "spcp825 driver does not support the "
  319. "baudrate requested, using default of 9600.\n");
  320. }
  321. /* Set Data Length : 00:5bit, 01:6bit, 10:7bit, 11:8bit */
  322. if (cflag & CSIZE) {
  323. switch (cflag & CSIZE) {
  324. case CS5:
  325. buf[1] |= SET_UART_FORMAT_SIZE_5;
  326. break;
  327. case CS6:
  328. buf[1] |= SET_UART_FORMAT_SIZE_6;
  329. break;
  330. case CS7:
  331. buf[1] |= SET_UART_FORMAT_SIZE_7;
  332. break;
  333. default:
  334. case CS8:
  335. buf[1] |= SET_UART_FORMAT_SIZE_8;
  336. break;
  337. }
  338. }
  339. /* Set Stop bit2 : 0:1bit 1:2bit */
  340. buf[1] |= (cflag & CSTOPB) ? SET_UART_FORMAT_STOP_2 :
  341. SET_UART_FORMAT_STOP_1;
  342. /* Set Parity bit3-4 01:Odd 11:Even */
  343. if (cflag & PARENB) {
  344. buf[1] |= (cflag & PARODD) ?
  345. SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
  346. } else
  347. buf[1] |= SET_UART_FORMAT_PAR_NONE;
  348. uartdata = buf[0] | buf[1]<<8;
  349. i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  350. SET_UART_FORMAT_TYPE, SET_UART_FORMAT,
  351. uartdata, 0, NULL, 0, 100);
  352. if (i < 0)
  353. dev_err(&port->dev, "Set UART format %#x failed (error = %d)\n",
  354. uartdata, i);
  355. dev_dbg(&port->dev, "0x21:0x40:0:0 %d\n", i);
  356. if (cflag & CRTSCTS) {
  357. /* enable hardware flow control */
  358. spcp8x5_set_workMode(serial->dev, 0x000a,
  359. SET_WORKING_MODE_U2C, priv->type);
  360. }
  361. }
  362. /* open the serial port. do some usb system call. set termios and get the line
  363. * status of the device. */
  364. static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
  365. {
  366. struct ktermios tmp_termios;
  367. struct usb_serial *serial = port->serial;
  368. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  369. int ret;
  370. unsigned long flags;
  371. u8 status = 0x30;
  372. /* status 0x30 means DSR and CTS = 1 other CDC RI and delta = 0 */
  373. usb_clear_halt(serial->dev, port->write_urb->pipe);
  374. usb_clear_halt(serial->dev, port->read_urb->pipe);
  375. ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  376. 0x09, 0x00,
  377. 0x01, 0x00, NULL, 0x00, 100);
  378. if (ret)
  379. return ret;
  380. spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
  381. /* Setup termios */
  382. if (tty)
  383. spcp8x5_set_termios(tty, port, &tmp_termios);
  384. spcp8x5_get_msr(serial->dev, &status, priv->type);
  385. /* may be we should update uart status here but now we did not do */
  386. spin_lock_irqsave(&priv->lock, flags);
  387. priv->line_status = status & 0xf0 ;
  388. spin_unlock_irqrestore(&priv->lock, flags);
  389. port->port.drain_delay = 256;
  390. return usb_serial_generic_open(tty, port);
  391. }
  392. static void spcp8x5_process_read_urb(struct urb *urb)
  393. {
  394. struct usb_serial_port *port = urb->context;
  395. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  396. unsigned char *data = urb->transfer_buffer;
  397. unsigned long flags;
  398. u8 status;
  399. char tty_flag;
  400. /* get tty_flag from status */
  401. tty_flag = TTY_NORMAL;
  402. spin_lock_irqsave(&priv->lock, flags);
  403. status = priv->line_status;
  404. priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
  405. spin_unlock_irqrestore(&priv->lock, flags);
  406. /* wake up the wait for termios */
  407. wake_up_interruptible(&port->delta_msr_wait);
  408. if (!urb->actual_length)
  409. return;
  410. if (status & UART_STATE_TRANSIENT_MASK) {
  411. /* break takes precedence over parity, which takes precedence
  412. * over framing errors */
  413. if (status & UART_BREAK_ERROR)
  414. tty_flag = TTY_BREAK;
  415. else if (status & UART_PARITY_ERROR)
  416. tty_flag = TTY_PARITY;
  417. else if (status & UART_FRAME_ERROR)
  418. tty_flag = TTY_FRAME;
  419. dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
  420. /* overrun is special, not associated with a char */
  421. if (status & UART_OVERRUN_ERROR)
  422. tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
  423. if (status & UART_DCD) {
  424. struct tty_struct *tty = tty_port_tty_get(&port->port);
  425. if (tty) {
  426. usb_serial_handle_dcd_change(port, tty,
  427. priv->line_status & MSR_STATUS_LINE_DCD);
  428. tty_kref_put(tty);
  429. }
  430. }
  431. }
  432. tty_insert_flip_string_fixed_flag(&port->port, data, tty_flag,
  433. urb->actual_length);
  434. tty_flip_buffer_push(&port->port);
  435. }
  436. static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
  437. unsigned int arg)
  438. {
  439. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  440. unsigned long flags;
  441. unsigned int prevstatus;
  442. unsigned int status;
  443. unsigned int changed;
  444. spin_lock_irqsave(&priv->lock, flags);
  445. prevstatus = priv->line_status;
  446. spin_unlock_irqrestore(&priv->lock, flags);
  447. while (1) {
  448. /* wake up in bulk read */
  449. interruptible_sleep_on(&port->delta_msr_wait);
  450. /* see if a signal did it */
  451. if (signal_pending(current))
  452. return -ERESTARTSYS;
  453. if (port->serial->disconnected)
  454. return -EIO;
  455. spin_lock_irqsave(&priv->lock, flags);
  456. status = priv->line_status;
  457. spin_unlock_irqrestore(&priv->lock, flags);
  458. changed = prevstatus^status;
  459. if (((arg & TIOCM_RNG) && (changed & MSR_STATUS_LINE_RI)) ||
  460. ((arg & TIOCM_DSR) && (changed & MSR_STATUS_LINE_DSR)) ||
  461. ((arg & TIOCM_CD) && (changed & MSR_STATUS_LINE_DCD)) ||
  462. ((arg & TIOCM_CTS) && (changed & MSR_STATUS_LINE_CTS)))
  463. return 0;
  464. prevstatus = status;
  465. }
  466. /* NOTREACHED */
  467. return 0;
  468. }
  469. static int spcp8x5_ioctl(struct tty_struct *tty,
  470. unsigned int cmd, unsigned long arg)
  471. {
  472. struct usb_serial_port *port = tty->driver_data;
  473. dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__,
  474. port->number, cmd);
  475. switch (cmd) {
  476. case TIOCMIWAIT:
  477. dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
  478. port->number);
  479. return spcp8x5_wait_modem_info(port, arg);
  480. default:
  481. dev_dbg(&port->dev, "%s not supported = 0x%04x", __func__,
  482. cmd);
  483. break;
  484. }
  485. return -ENOIOCTLCMD;
  486. }
  487. static int spcp8x5_tiocmset(struct tty_struct *tty,
  488. unsigned int set, unsigned int clear)
  489. {
  490. struct usb_serial_port *port = tty->driver_data;
  491. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  492. unsigned long flags;
  493. u8 control;
  494. spin_lock_irqsave(&priv->lock, flags);
  495. if (set & TIOCM_RTS)
  496. priv->line_control |= MCR_RTS;
  497. if (set & TIOCM_DTR)
  498. priv->line_control |= MCR_DTR;
  499. if (clear & TIOCM_RTS)
  500. priv->line_control &= ~MCR_RTS;
  501. if (clear & TIOCM_DTR)
  502. priv->line_control &= ~MCR_DTR;
  503. control = priv->line_control;
  504. spin_unlock_irqrestore(&priv->lock, flags);
  505. return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
  506. }
  507. static int spcp8x5_tiocmget(struct tty_struct *tty)
  508. {
  509. struct usb_serial_port *port = tty->driver_data;
  510. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  511. unsigned long flags;
  512. unsigned int mcr;
  513. unsigned int status;
  514. unsigned int result;
  515. spin_lock_irqsave(&priv->lock, flags);
  516. mcr = priv->line_control;
  517. status = priv->line_status;
  518. spin_unlock_irqrestore(&priv->lock, flags);
  519. result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
  520. | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
  521. | ((status & MSR_STATUS_LINE_CTS) ? TIOCM_CTS : 0)
  522. | ((status & MSR_STATUS_LINE_DSR) ? TIOCM_DSR : 0)
  523. | ((status & MSR_STATUS_LINE_RI) ? TIOCM_RI : 0)
  524. | ((status & MSR_STATUS_LINE_DCD) ? TIOCM_CD : 0);
  525. return result;
  526. }
  527. /* All of the device info needed for the spcp8x5 SIO serial converter */
  528. static struct usb_serial_driver spcp8x5_device = {
  529. .driver = {
  530. .owner = THIS_MODULE,
  531. .name = "SPCP8x5",
  532. },
  533. .id_table = id_table,
  534. .num_ports = 1,
  535. .open = spcp8x5_open,
  536. .dtr_rts = spcp8x5_dtr_rts,
  537. .carrier_raised = spcp8x5_carrier_raised,
  538. .set_termios = spcp8x5_set_termios,
  539. .init_termios = spcp8x5_init_termios,
  540. .ioctl = spcp8x5_ioctl,
  541. .tiocmget = spcp8x5_tiocmget,
  542. .tiocmset = spcp8x5_tiocmset,
  543. .port_probe = spcp8x5_port_probe,
  544. .port_remove = spcp8x5_port_remove,
  545. .process_read_urb = spcp8x5_process_read_urb,
  546. };
  547. static struct usb_serial_driver * const serial_drivers[] = {
  548. &spcp8x5_device, NULL
  549. };
  550. module_usb_serial_driver(serial_drivers, id_table);
  551. MODULE_DESCRIPTION(DRIVER_DESC);
  552. MODULE_LICENSE("GPL");