spcp8x5.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  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. /* desc : when device plug in,this function would be called.
  138. * thanks to usb_serial subsystem,then do almost every things for us. And what
  139. * we should do just alloc the buffer */
  140. static int spcp8x5_startup(struct usb_serial *serial)
  141. {
  142. struct spcp8x5_private *priv;
  143. int i;
  144. enum spcp8x5_type type = SPCP825_007_TYPE;
  145. u16 product = le16_to_cpu(serial->dev->descriptor.idProduct);
  146. if (product == 0x0201)
  147. type = SPCP825_007_TYPE;
  148. else if (product == 0x0231)
  149. type = SPCP835_TYPE;
  150. else if (product == 0x0235)
  151. type = SPCP825_008_TYPE;
  152. else if (product == 0x0204)
  153. type = SPCP825_INTERMATIC_TYPE;
  154. else if (product == 0x0471 &&
  155. serial->dev->descriptor.idVendor == cpu_to_le16(0x081e))
  156. type = SPCP825_PHILIP_TYPE;
  157. dev_dbg(&serial->dev->dev, "device type = %d\n", (int)type);
  158. for (i = 0; i < serial->num_ports; ++i) {
  159. priv = kzalloc(sizeof(struct spcp8x5_private), GFP_KERNEL);
  160. if (!priv)
  161. goto cleanup;
  162. spin_lock_init(&priv->lock);
  163. init_waitqueue_head(&priv->delta_msr_wait);
  164. priv->type = type;
  165. usb_set_serial_port_data(serial->port[i] , priv);
  166. }
  167. return 0;
  168. cleanup:
  169. for (--i; i >= 0; --i) {
  170. priv = usb_get_serial_port_data(serial->port[i]);
  171. kfree(priv);
  172. usb_set_serial_port_data(serial->port[i] , NULL);
  173. }
  174. return -ENOMEM;
  175. }
  176. /* call when the device plug out. free all the memory alloced by probe */
  177. static void spcp8x5_release(struct usb_serial *serial)
  178. {
  179. int i;
  180. for (i = 0; i < serial->num_ports; i++)
  181. kfree(usb_get_serial_port_data(serial->port[i]));
  182. }
  183. /* set the modem control line of the device.
  184. * NOTE spcp825-007 not supported this */
  185. static int spcp8x5_set_ctrlLine(struct usb_device *dev, u8 value,
  186. enum spcp8x5_type type)
  187. {
  188. int retval;
  189. u8 mcr = 0 ;
  190. if (type == SPCP825_007_TYPE)
  191. return -EPERM;
  192. mcr = (unsigned short)value;
  193. retval = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  194. SET_UART_STATUS_TYPE, SET_UART_STATUS,
  195. mcr, 0x04, NULL, 0, 100);
  196. if (retval != 0)
  197. dev_dbg(&dev->dev, "usb_control_msg return %#x\n", retval);
  198. return retval;
  199. }
  200. /* get the modem status register of the device
  201. * NOTE spcp825-007 not supported this */
  202. static int spcp8x5_get_msr(struct usb_device *dev, u8 *status,
  203. enum spcp8x5_type type)
  204. {
  205. u8 *status_buffer;
  206. int ret;
  207. /* I return Permited not support here but seem inval device
  208. * is more fix */
  209. if (type == SPCP825_007_TYPE)
  210. return -EPERM;
  211. if (status == NULL)
  212. return -EINVAL;
  213. status_buffer = kmalloc(1, GFP_KERNEL);
  214. if (!status_buffer)
  215. return -ENOMEM;
  216. status_buffer[0] = status[0];
  217. ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
  218. GET_UART_STATUS, GET_UART_STATUS_TYPE,
  219. 0, GET_UART_STATUS_MSR, status_buffer, 1, 100);
  220. if (ret < 0)
  221. dev_dbg(&dev->dev, "Get MSR = 0x%p failed (error = %d)",
  222. status_buffer, ret);
  223. dev_dbg(&dev->dev, "0xc0:0x22:0:6 %d - 0x%p ", ret, status_buffer);
  224. status[0] = status_buffer[0];
  225. kfree(status_buffer);
  226. return ret;
  227. }
  228. /* select the work mode.
  229. * NOTE this function not supported by spcp825-007 */
  230. static void spcp8x5_set_workMode(struct usb_device *dev, u16 value,
  231. u16 index, enum spcp8x5_type type)
  232. {
  233. int ret;
  234. /* I return Permited not support here but seem inval device
  235. * is more fix */
  236. if (type == SPCP825_007_TYPE)
  237. return;
  238. ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
  239. SET_WORKING_MODE_TYPE, SET_WORKING_MODE,
  240. value, index, NULL, 0, 100);
  241. dev_dbg(&dev->dev, "value = %#x , index = %#x\n", value, index);
  242. if (ret < 0)
  243. dev_dbg(&dev->dev,
  244. "RTSCTS usb_control_msg(enable flowctrl) = %d\n", ret);
  245. }
  246. static int spcp8x5_carrier_raised(struct usb_serial_port *port)
  247. {
  248. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  249. if (priv->line_status & MSR_STATUS_LINE_DCD)
  250. return 1;
  251. return 0;
  252. }
  253. static void spcp8x5_dtr_rts(struct usb_serial_port *port, int on)
  254. {
  255. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  256. unsigned long flags;
  257. u8 control;
  258. spin_lock_irqsave(&priv->lock, flags);
  259. if (on)
  260. priv->line_control = MCR_CONTROL_LINE_DTR
  261. | MCR_CONTROL_LINE_RTS;
  262. else
  263. priv->line_control &= ~ (MCR_CONTROL_LINE_DTR
  264. | MCR_CONTROL_LINE_RTS);
  265. control = priv->line_control;
  266. spin_unlock_irqrestore(&priv->lock, flags);
  267. spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
  268. }
  269. static void spcp8x5_init_termios(struct tty_struct *tty)
  270. {
  271. /* for the 1st time call this function */
  272. *(tty->termios) = tty_std_termios;
  273. tty->termios->c_cflag = B115200 | CS8 | CREAD | HUPCL | CLOCAL;
  274. tty->termios->c_ispeed = 115200;
  275. tty->termios->c_ospeed = 115200;
  276. }
  277. /* set the serial param for transfer. we should check if we really need to
  278. * transfer. if we set flow control we should do this too. */
  279. static void spcp8x5_set_termios(struct tty_struct *tty,
  280. struct usb_serial_port *port, struct ktermios *old_termios)
  281. {
  282. struct usb_serial *serial = port->serial;
  283. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  284. unsigned long flags;
  285. unsigned int cflag = tty->termios->c_cflag;
  286. unsigned int old_cflag = old_termios->c_cflag;
  287. unsigned short uartdata;
  288. unsigned char buf[2] = {0, 0};
  289. int baud;
  290. int i;
  291. u8 control;
  292. /* check that they really want us to change something */
  293. if (!tty_termios_hw_change(tty->termios, old_termios))
  294. return;
  295. /* set DTR/RTS active */
  296. spin_lock_irqsave(&priv->lock, flags);
  297. control = priv->line_control;
  298. if ((old_cflag & CBAUD) == B0) {
  299. priv->line_control |= MCR_DTR;
  300. if (!(old_cflag & CRTSCTS))
  301. priv->line_control |= MCR_RTS;
  302. }
  303. if (control != priv->line_control) {
  304. control = priv->line_control;
  305. spin_unlock_irqrestore(&priv->lock, flags);
  306. spcp8x5_set_ctrlLine(serial->dev, control , priv->type);
  307. } else {
  308. spin_unlock_irqrestore(&priv->lock, flags);
  309. }
  310. /* Set Baud Rate */
  311. baud = tty_get_baud_rate(tty);
  312. switch (baud) {
  313. case 300: buf[0] = 0x00; break;
  314. case 600: buf[0] = 0x01; break;
  315. case 1200: buf[0] = 0x02; break;
  316. case 2400: buf[0] = 0x03; break;
  317. case 4800: buf[0] = 0x04; break;
  318. case 9600: buf[0] = 0x05; break;
  319. case 19200: buf[0] = 0x07; break;
  320. case 38400: buf[0] = 0x09; break;
  321. case 57600: buf[0] = 0x0a; break;
  322. case 115200: buf[0] = 0x0b; break;
  323. case 230400: buf[0] = 0x0c; break;
  324. case 460800: buf[0] = 0x0d; break;
  325. case 921600: buf[0] = 0x0e; break;
  326. /* case 1200000: buf[0] = 0x0f; break; */
  327. /* case 2400000: buf[0] = 0x10; break; */
  328. case 3000000: buf[0] = 0x11; break;
  329. /* case 6000000: buf[0] = 0x12; break; */
  330. case 0:
  331. case 1000000:
  332. buf[0] = 0x0b; break;
  333. default:
  334. dev_err(&port->dev, "spcp825 driver does not support the "
  335. "baudrate requested, using default of 9600.\n");
  336. }
  337. /* Set Data Length : 00:5bit, 01:6bit, 10:7bit, 11:8bit */
  338. if (cflag & CSIZE) {
  339. switch (cflag & CSIZE) {
  340. case CS5:
  341. buf[1] |= SET_UART_FORMAT_SIZE_5;
  342. break;
  343. case CS6:
  344. buf[1] |= SET_UART_FORMAT_SIZE_6;
  345. break;
  346. case CS7:
  347. buf[1] |= SET_UART_FORMAT_SIZE_7;
  348. break;
  349. default:
  350. case CS8:
  351. buf[1] |= SET_UART_FORMAT_SIZE_8;
  352. break;
  353. }
  354. }
  355. /* Set Stop bit2 : 0:1bit 1:2bit */
  356. buf[1] |= (cflag & CSTOPB) ? SET_UART_FORMAT_STOP_2 :
  357. SET_UART_FORMAT_STOP_1;
  358. /* Set Parity bit3-4 01:Odd 11:Even */
  359. if (cflag & PARENB) {
  360. buf[1] |= (cflag & PARODD) ?
  361. SET_UART_FORMAT_PAR_ODD : SET_UART_FORMAT_PAR_EVEN ;
  362. } else
  363. buf[1] |= SET_UART_FORMAT_PAR_NONE;
  364. uartdata = buf[0] | buf[1]<<8;
  365. i = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  366. SET_UART_FORMAT_TYPE, SET_UART_FORMAT,
  367. uartdata, 0, NULL, 0, 100);
  368. if (i < 0)
  369. dev_err(&port->dev, "Set UART format %#x failed (error = %d)\n",
  370. uartdata, i);
  371. dev_dbg(&port->dev, "0x21:0x40:0:0 %d\n", i);
  372. if (cflag & CRTSCTS) {
  373. /* enable hardware flow control */
  374. spcp8x5_set_workMode(serial->dev, 0x000a,
  375. SET_WORKING_MODE_U2C, priv->type);
  376. }
  377. }
  378. /* open the serial port. do some usb system call. set termios and get the line
  379. * status of the device. */
  380. static int spcp8x5_open(struct tty_struct *tty, struct usb_serial_port *port)
  381. {
  382. struct ktermios tmp_termios;
  383. struct usb_serial *serial = port->serial;
  384. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  385. int ret;
  386. unsigned long flags;
  387. u8 status = 0x30;
  388. /* status 0x30 means DSR and CTS = 1 other CDC RI and delta = 0 */
  389. usb_clear_halt(serial->dev, port->write_urb->pipe);
  390. usb_clear_halt(serial->dev, port->read_urb->pipe);
  391. ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
  392. 0x09, 0x00,
  393. 0x01, 0x00, NULL, 0x00, 100);
  394. if (ret)
  395. return ret;
  396. spcp8x5_set_ctrlLine(serial->dev, priv->line_control , priv->type);
  397. /* Setup termios */
  398. if (tty)
  399. spcp8x5_set_termios(tty, port, &tmp_termios);
  400. spcp8x5_get_msr(serial->dev, &status, priv->type);
  401. /* may be we should update uart status here but now we did not do */
  402. spin_lock_irqsave(&priv->lock, flags);
  403. priv->line_status = status & 0xf0 ;
  404. spin_unlock_irqrestore(&priv->lock, flags);
  405. port->port.drain_delay = 256;
  406. return usb_serial_generic_open(tty, port);
  407. }
  408. static void spcp8x5_process_read_urb(struct urb *urb)
  409. {
  410. struct usb_serial_port *port = urb->context;
  411. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  412. struct tty_struct *tty;
  413. unsigned char *data = urb->transfer_buffer;
  414. unsigned long flags;
  415. u8 status;
  416. char tty_flag;
  417. /* get tty_flag from status */
  418. tty_flag = TTY_NORMAL;
  419. spin_lock_irqsave(&priv->lock, flags);
  420. status = priv->line_status;
  421. priv->line_status &= ~UART_STATE_TRANSIENT_MASK;
  422. spin_unlock_irqrestore(&priv->lock, flags);
  423. /* wake up the wait for termios */
  424. wake_up_interruptible(&priv->delta_msr_wait);
  425. if (!urb->actual_length)
  426. return;
  427. tty = tty_port_tty_get(&port->port);
  428. if (!tty)
  429. return;
  430. if (status & UART_STATE_TRANSIENT_MASK) {
  431. /* break takes precedence over parity, which takes precedence
  432. * over framing errors */
  433. if (status & UART_BREAK_ERROR)
  434. tty_flag = TTY_BREAK;
  435. else if (status & UART_PARITY_ERROR)
  436. tty_flag = TTY_PARITY;
  437. else if (status & UART_FRAME_ERROR)
  438. tty_flag = TTY_FRAME;
  439. dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
  440. /* overrun is special, not associated with a char */
  441. if (status & UART_OVERRUN_ERROR)
  442. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  443. if (status & UART_DCD)
  444. usb_serial_handle_dcd_change(port, tty,
  445. priv->line_status & MSR_STATUS_LINE_DCD);
  446. }
  447. tty_insert_flip_string_fixed_flag(tty, data, tty_flag,
  448. urb->actual_length);
  449. tty_flip_buffer_push(tty);
  450. tty_kref_put(tty);
  451. }
  452. static int spcp8x5_wait_modem_info(struct usb_serial_port *port,
  453. unsigned int arg)
  454. {
  455. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  456. unsigned long flags;
  457. unsigned int prevstatus;
  458. unsigned int status;
  459. unsigned int changed;
  460. spin_lock_irqsave(&priv->lock, flags);
  461. prevstatus = priv->line_status;
  462. spin_unlock_irqrestore(&priv->lock, flags);
  463. while (1) {
  464. /* wake up in bulk read */
  465. interruptible_sleep_on(&priv->delta_msr_wait);
  466. /* see if a signal did it */
  467. if (signal_pending(current))
  468. return -ERESTARTSYS;
  469. spin_lock_irqsave(&priv->lock, flags);
  470. status = priv->line_status;
  471. spin_unlock_irqrestore(&priv->lock, flags);
  472. changed = prevstatus^status;
  473. if (((arg & TIOCM_RNG) && (changed & MSR_STATUS_LINE_RI)) ||
  474. ((arg & TIOCM_DSR) && (changed & MSR_STATUS_LINE_DSR)) ||
  475. ((arg & TIOCM_CD) && (changed & MSR_STATUS_LINE_DCD)) ||
  476. ((arg & TIOCM_CTS) && (changed & MSR_STATUS_LINE_CTS)))
  477. return 0;
  478. prevstatus = status;
  479. }
  480. /* NOTREACHED */
  481. return 0;
  482. }
  483. static int spcp8x5_ioctl(struct tty_struct *tty,
  484. unsigned int cmd, unsigned long arg)
  485. {
  486. struct usb_serial_port *port = tty->driver_data;
  487. dev_dbg(&port->dev, "%s (%d) cmd = 0x%04x\n", __func__,
  488. port->number, cmd);
  489. switch (cmd) {
  490. case TIOCMIWAIT:
  491. dev_dbg(&port->dev, "%s (%d) TIOCMIWAIT\n", __func__,
  492. port->number);
  493. return spcp8x5_wait_modem_info(port, arg);
  494. default:
  495. dev_dbg(&port->dev, "%s not supported = 0x%04x", __func__,
  496. cmd);
  497. break;
  498. }
  499. return -ENOIOCTLCMD;
  500. }
  501. static int spcp8x5_tiocmset(struct tty_struct *tty,
  502. unsigned int set, unsigned int clear)
  503. {
  504. struct usb_serial_port *port = tty->driver_data;
  505. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  506. unsigned long flags;
  507. u8 control;
  508. spin_lock_irqsave(&priv->lock, flags);
  509. if (set & TIOCM_RTS)
  510. priv->line_control |= MCR_RTS;
  511. if (set & TIOCM_DTR)
  512. priv->line_control |= MCR_DTR;
  513. if (clear & TIOCM_RTS)
  514. priv->line_control &= ~MCR_RTS;
  515. if (clear & TIOCM_DTR)
  516. priv->line_control &= ~MCR_DTR;
  517. control = priv->line_control;
  518. spin_unlock_irqrestore(&priv->lock, flags);
  519. return spcp8x5_set_ctrlLine(port->serial->dev, control , priv->type);
  520. }
  521. static int spcp8x5_tiocmget(struct tty_struct *tty)
  522. {
  523. struct usb_serial_port *port = tty->driver_data;
  524. struct spcp8x5_private *priv = usb_get_serial_port_data(port);
  525. unsigned long flags;
  526. unsigned int mcr;
  527. unsigned int status;
  528. unsigned int result;
  529. spin_lock_irqsave(&priv->lock, flags);
  530. mcr = priv->line_control;
  531. status = priv->line_status;
  532. spin_unlock_irqrestore(&priv->lock, flags);
  533. result = ((mcr & MCR_DTR) ? TIOCM_DTR : 0)
  534. | ((mcr & MCR_RTS) ? TIOCM_RTS : 0)
  535. | ((status & MSR_STATUS_LINE_CTS) ? TIOCM_CTS : 0)
  536. | ((status & MSR_STATUS_LINE_DSR) ? TIOCM_DSR : 0)
  537. | ((status & MSR_STATUS_LINE_RI) ? TIOCM_RI : 0)
  538. | ((status & MSR_STATUS_LINE_DCD) ? TIOCM_CD : 0);
  539. return result;
  540. }
  541. /* All of the device info needed for the spcp8x5 SIO serial converter */
  542. static struct usb_serial_driver spcp8x5_device = {
  543. .driver = {
  544. .owner = THIS_MODULE,
  545. .name = "SPCP8x5",
  546. },
  547. .id_table = id_table,
  548. .num_ports = 1,
  549. .open = spcp8x5_open,
  550. .dtr_rts = spcp8x5_dtr_rts,
  551. .carrier_raised = spcp8x5_carrier_raised,
  552. .set_termios = spcp8x5_set_termios,
  553. .init_termios = spcp8x5_init_termios,
  554. .ioctl = spcp8x5_ioctl,
  555. .tiocmget = spcp8x5_tiocmget,
  556. .tiocmset = spcp8x5_tiocmset,
  557. .attach = spcp8x5_startup,
  558. .release = spcp8x5_release,
  559. .process_read_urb = spcp8x5_process_read_urb,
  560. };
  561. static struct usb_serial_driver * const serial_drivers[] = {
  562. &spcp8x5_device, NULL
  563. };
  564. module_usb_serial_driver(serial_drivers, id_table);
  565. MODULE_DESCRIPTION(DRIVER_DESC);
  566. MODULE_VERSION(DRIVER_VERSION);
  567. MODULE_LICENSE("GPL");