spcp8x5.c 17 KB

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