1 // SPDX-License-Identifier: GPL-2.0
3 * Fintek F81232 USB to serial adaptor driver
4 * Fintek F81532A/534A/535/536 USB to 2/4/8/12 serial adaptor driver
6 * Copyright (C) 2012 Greg Kroah-Hartman (gregkh@linuxfoundation.org)
7 * Copyright (C) 2012 Linux Foundation
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/slab.h>
13 #include <linux/tty.h>
14 #include <linux/tty_driver.h>
15 #include <linux/tty_flip.h>
16 #include <linux/serial.h>
17 #include <linux/module.h>
18 #include <linux/moduleparam.h>
19 #include <linux/mutex.h>
20 #include <linux/uaccess.h>
21 #include <linux/usb.h>
22 #include <linux/usb/serial.h>
23 #include <linux/serial_reg.h>
26 { USB_DEVICE(0x1934, 0x0706) } /* 1 port UART device */
28 #define F81534A_SERIES_ID \
29 { USB_DEVICE(0x2c42, 0x1602) }, /* In-Box 2 port UART device */ \
30 { USB_DEVICE(0x2c42, 0x1604) }, /* In-Box 4 port UART device */ \
31 { USB_DEVICE(0x2c42, 0x1605) }, /* In-Box 8 port UART device */ \
32 { USB_DEVICE(0x2c42, 0x1606) }, /* In-Box 12 port UART device */ \
33 { USB_DEVICE(0x2c42, 0x1608) }, /* Non-Flash type */ \
34 { USB_DEVICE(0x2c42, 0x1632) }, /* 2 port UART device */ \
35 { USB_DEVICE(0x2c42, 0x1634) }, /* 4 port UART device */ \
36 { USB_DEVICE(0x2c42, 0x1635) }, /* 8 port UART device */ \
37 { USB_DEVICE(0x2c42, 0x1636) } /* 12 port UART device */
39 #define F81534A_CTRL_ID \
40 { USB_DEVICE(0x2c42, 0x16f8) } /* Global control device */
42 static const struct usb_device_id f81232_id_table[] = {
44 { } /* Terminating entry */
47 static const struct usb_device_id f81534a_id_table[] = {
49 { } /* Terminating entry */
52 static const struct usb_device_id f81534a_ctrl_id_table[] = {
54 { } /* Terminating entry */
57 static const struct usb_device_id combined_id_table[] = {
61 { } /* Terminating entry */
63 MODULE_DEVICE_TABLE(usb, combined_id_table);
65 /* Maximum baudrate for F81232 */
66 #define F81232_MAX_BAUDRATE 1500000
67 #define F81232_DEF_BAUDRATE 9600
69 /* USB Control EP parameter */
70 #define F81232_REGISTER_REQUEST 0xa0
71 #define F81232_GET_REGISTER 0xc0
72 #define F81232_SET_REGISTER 0x40
73 #define F81534A_ACCESS_REG_RETRY 2
75 #define SERIAL_BASE_ADDRESS 0x0120
76 #define RECEIVE_BUFFER_REGISTER (0x00 + SERIAL_BASE_ADDRESS)
77 #define INTERRUPT_ENABLE_REGISTER (0x01 + SERIAL_BASE_ADDRESS)
78 #define FIFO_CONTROL_REGISTER (0x02 + SERIAL_BASE_ADDRESS)
79 #define LINE_CONTROL_REGISTER (0x03 + SERIAL_BASE_ADDRESS)
80 #define MODEM_CONTROL_REGISTER (0x04 + SERIAL_BASE_ADDRESS)
81 #define LINE_STATUS_REGISTER (0x05 + SERIAL_BASE_ADDRESS)
82 #define MODEM_STATUS_REGISTER (0x06 + SERIAL_BASE_ADDRESS)
85 * F81232 Clock registers (106h)
87 * Bit1-0: Clock source selector
93 #define F81232_CLK_REGISTER 0x106
94 #define F81232_CLK_1_846_MHZ 0
95 #define F81232_CLK_18_46_MHZ BIT(0)
96 #define F81232_CLK_24_MHZ BIT(1)
97 #define F81232_CLK_14_77_MHZ (BIT(1) | BIT(0))
98 #define F81232_CLK_MASK GENMASK(1, 0)
100 #define F81534A_MODE_REG 0x107
101 #define F81534A_TRIGGER_MASK GENMASK(3, 2)
102 #define F81534A_TRIGGER_MULTIPLE_4X BIT(3)
103 #define F81534A_FIFO_128BYTE (BIT(1) | BIT(0))
105 /* Serial port self GPIO control, 2bytes [control&output data][input data] */
106 #define F81534A_GPIO_REG 0x10e
107 #define F81534A_GPIO_MODE2_DIR BIT(6) /* 1: input, 0: output */
108 #define F81534A_GPIO_MODE1_DIR BIT(5)
109 #define F81534A_GPIO_MODE0_DIR BIT(4)
110 #define F81534A_GPIO_MODE2_OUTPUT BIT(2)
111 #define F81534A_GPIO_MODE1_OUTPUT BIT(1)
112 #define F81534A_GPIO_MODE0_OUTPUT BIT(0)
114 #define F81534A_CTRL_CMD_ENABLE_PORT 0x116
116 struct f81232_private {
122 struct work_struct lsr_work;
123 struct work_struct interrupt_work;
124 struct usb_serial_port *port;
127 static u32 const baudrate_table[] = { 115200, 921600, 1152000, 1500000 };
128 static u8 const clock_table[] = { F81232_CLK_1_846_MHZ, F81232_CLK_14_77_MHZ,
129 F81232_CLK_18_46_MHZ, F81232_CLK_24_MHZ };
131 static int calc_baud_divisor(speed_t baudrate, speed_t clockrate)
133 return DIV_ROUND_CLOSEST(clockrate, baudrate);
136 static int f81232_get_register(struct usb_serial_port *port, u16 reg, u8 *val)
140 struct usb_device *dev = port->serial->dev;
142 tmp = kmalloc(sizeof(*val), GFP_KERNEL);
146 status = usb_control_msg(dev,
147 usb_rcvctrlpipe(dev, 0),
148 F81232_REGISTER_REQUEST,
154 USB_CTRL_GET_TIMEOUT);
155 if (status != sizeof(*val)) {
156 dev_err(&port->dev, "%s failed status: %d\n", __func__, status);
159 status = usb_translate_errors(status);
171 static int f81232_set_register(struct usb_serial_port *port, u16 reg, u8 val)
175 struct usb_device *dev = port->serial->dev;
177 tmp = kmalloc(sizeof(val), GFP_KERNEL);
183 status = usb_control_msg(dev,
184 usb_sndctrlpipe(dev, 0),
185 F81232_REGISTER_REQUEST,
191 USB_CTRL_SET_TIMEOUT);
193 dev_err(&port->dev, "%s failed status: %d\n", __func__, status);
194 status = usb_translate_errors(status);
203 static int f81232_set_mask_register(struct usb_serial_port *port, u16 reg,
209 status = f81232_get_register(port, reg, &tmp);
213 tmp = (tmp & ~mask) | (val & mask);
215 return f81232_set_register(port, reg, tmp);
218 static void f81232_read_msr(struct usb_serial_port *port)
222 struct tty_struct *tty;
223 struct f81232_private *priv = usb_get_serial_port_data(port);
225 mutex_lock(&priv->lock);
226 status = f81232_get_register(port, MODEM_STATUS_REGISTER,
229 dev_err(&port->dev, "%s fail, status: %d\n", __func__, status);
230 mutex_unlock(&priv->lock);
234 if (!(current_msr & UART_MSR_ANY_DELTA)) {
235 mutex_unlock(&priv->lock);
239 priv->modem_status = current_msr;
241 if (current_msr & UART_MSR_DCTS)
243 if (current_msr & UART_MSR_DDSR)
245 if (current_msr & UART_MSR_TERI)
247 if (current_msr & UART_MSR_DDCD) {
249 tty = tty_port_tty_get(&port->port);
251 usb_serial_handle_dcd_change(port, tty,
252 current_msr & UART_MSR_DCD);
258 wake_up_interruptible(&port->port.delta_msr_wait);
259 mutex_unlock(&priv->lock);
262 static int f81232_set_mctrl(struct usb_serial_port *port,
263 unsigned int set, unsigned int clear)
267 struct f81232_private *priv = usb_get_serial_port_data(port);
269 if (((set | clear) & (TIOCM_DTR | TIOCM_RTS)) == 0)
270 return 0; /* no change */
272 /* 'set' takes precedence over 'clear' */
275 /* force enable interrupt with OUT2 */
276 mutex_lock(&priv->lock);
277 val = UART_MCR_OUT2 | priv->modem_control;
279 if (clear & TIOCM_DTR)
280 val &= ~UART_MCR_DTR;
282 if (clear & TIOCM_RTS)
283 val &= ~UART_MCR_RTS;
291 dev_dbg(&port->dev, "%s new:%02x old:%02x\n", __func__,
292 val, priv->modem_control);
294 status = f81232_set_register(port, MODEM_CONTROL_REGISTER, val);
296 dev_err(&port->dev, "%s set MCR status < 0\n", __func__);
297 mutex_unlock(&priv->lock);
301 priv->modem_control = val;
302 mutex_unlock(&priv->lock);
307 static void f81232_update_line_status(struct usb_serial_port *port,
309 size_t actual_length)
311 struct f81232_private *priv = usb_get_serial_port_data(port);
316 switch (data[0] & 0x07) {
317 case 0x00: /* msr change */
318 dev_dbg(&port->dev, "IIR: MSR Change: %02x\n", data[0]);
319 schedule_work(&priv->interrupt_work);
321 case 0x02: /* tx-empty */
323 case 0x04: /* rx data available */
325 case 0x06: /* lsr change */
326 /* we can forget it. the LSR will read from bulk-in */
327 dev_dbg(&port->dev, "IIR: LSR Change: %02x\n", data[0]);
332 static void f81232_read_int_callback(struct urb *urb)
334 struct usb_serial_port *port = urb->context;
335 unsigned char *data = urb->transfer_buffer;
336 unsigned int actual_length = urb->actual_length;
337 int status = urb->status;
347 /* this urb is terminated, clean up */
348 dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
352 dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
357 usb_serial_debug_data(&port->dev, __func__,
358 urb->actual_length, urb->transfer_buffer);
360 f81232_update_line_status(port, data, actual_length);
363 retval = usb_submit_urb(urb, GFP_ATOMIC);
365 dev_err(&urb->dev->dev,
366 "%s - usb_submit_urb failed with result %d\n",
370 static char f81232_handle_lsr(struct usb_serial_port *port, u8 lsr)
372 struct f81232_private *priv = usb_get_serial_port_data(port);
373 char tty_flag = TTY_NORMAL;
375 if (!(lsr & UART_LSR_BRK_ERROR_BITS))
378 if (lsr & UART_LSR_BI) {
379 tty_flag = TTY_BREAK;
381 usb_serial_handle_break(port);
382 } else if (lsr & UART_LSR_PE) {
383 tty_flag = TTY_PARITY;
384 port->icount.parity++;
385 } else if (lsr & UART_LSR_FE) {
386 tty_flag = TTY_FRAME;
387 port->icount.frame++;
390 if (lsr & UART_LSR_OE) {
391 port->icount.overrun++;
392 schedule_work(&priv->lsr_work);
393 tty_insert_flip_char(&port->port, 0, TTY_OVERRUN);
399 static void f81232_process_read_urb(struct urb *urb)
401 struct usb_serial_port *port = urb->context;
402 unsigned char *data = urb->transfer_buffer;
408 * When opening the port we get a 1-byte packet with the current LSR,
411 if ((urb->actual_length < 2) || (urb->actual_length % 2))
414 /* bulk-in data: [LSR(1Byte)+DATA(1Byte)][LSR(1Byte)+DATA(1Byte)]... */
416 for (i = 0; i < urb->actual_length; i += 2) {
418 tty_flag = f81232_handle_lsr(port, lsr);
421 if (usb_serial_handle_sysrq_char(port, data[i + 1]))
425 tty_insert_flip_char(&port->port, data[i + 1], tty_flag);
428 tty_flip_buffer_push(&port->port);
431 static void f81534a_process_read_urb(struct urb *urb)
433 struct usb_serial_port *port = urb->context;
434 unsigned char *data = urb->transfer_buffer;
440 if (urb->actual_length < 3) {
441 dev_err(&port->dev, "short message received: %d\n",
447 if (len != urb->actual_length) {
448 dev_err(&port->dev, "malformed message received: %d (%d)\n",
449 urb->actual_length, len);
453 /* bulk-in data: [LEN][Data.....][LSR] */
455 tty_flag = f81232_handle_lsr(port, lsr);
458 for (i = 1; i < len - 1; ++i) {
459 if (!usb_serial_handle_sysrq_char(port, data[i])) {
460 tty_insert_flip_char(&port->port, data[i],
465 tty_insert_flip_string_fixed_flag(&port->port, &data[1],
469 tty_flip_buffer_push(&port->port);
472 static void f81232_break_ctl(struct tty_struct *tty, int break_state)
474 struct usb_serial_port *port = tty->driver_data;
475 struct f81232_private *priv = usb_get_serial_port_data(port);
478 mutex_lock(&priv->lock);
481 priv->shadow_lcr |= UART_LCR_SBC;
483 priv->shadow_lcr &= ~UART_LCR_SBC;
485 status = f81232_set_register(port, LINE_CONTROL_REGISTER,
488 dev_err(&port->dev, "set break failed: %d\n", status);
490 mutex_unlock(&priv->lock);
493 static int f81232_find_clk(speed_t baudrate)
497 for (idx = 0; idx < ARRAY_SIZE(baudrate_table); ++idx) {
498 if (baudrate <= baudrate_table[idx] &&
499 baudrate_table[idx] % baudrate == 0)
506 static void f81232_set_baudrate(struct tty_struct *tty,
507 struct usb_serial_port *port, speed_t baudrate,
508 speed_t old_baudrate)
510 struct f81232_private *priv = usb_get_serial_port_data(port);
516 speed_t baud_list[] = { baudrate, old_baudrate, F81232_DEF_BAUDRATE };
518 for (i = 0; i < ARRAY_SIZE(baud_list); ++i) {
519 baudrate = baud_list[i];
521 tty_encode_baud_rate(tty, 0, 0);
525 idx = f81232_find_clk(baudrate);
527 tty_encode_baud_rate(tty, baudrate, baudrate);
535 priv->baud_base = baudrate_table[idx];
536 divisor = calc_baud_divisor(baudrate, priv->baud_base);
538 status = f81232_set_mask_register(port, F81232_CLK_REGISTER,
539 F81232_CLK_MASK, clock_table[idx]);
541 dev_err(&port->dev, "%s failed to set CLK_REG: %d\n",
546 status = f81232_get_register(port, LINE_CONTROL_REGISTER,
549 dev_err(&port->dev, "%s failed to get LCR: %d\n",
554 status = f81232_set_register(port, LINE_CONTROL_REGISTER,
555 lcr | UART_LCR_DLAB); /* Enable DLAB */
557 dev_err(&port->dev, "%s failed to set DLAB: %d\n",
562 status = f81232_set_register(port, RECEIVE_BUFFER_REGISTER,
563 divisor & 0x00ff); /* low */
565 dev_err(&port->dev, "%s failed to set baudrate MSB: %d\n",
570 status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER,
571 (divisor & 0xff00) >> 8); /* high */
573 dev_err(&port->dev, "%s failed to set baudrate LSB: %d\n",
578 status = f81232_set_register(port, LINE_CONTROL_REGISTER,
579 lcr & ~UART_LCR_DLAB);
581 dev_err(&port->dev, "%s failed to set DLAB: %d\n",
586 static int f81232_port_enable(struct usb_serial_port *port)
591 /* fifo on, trigger8, clear TX/RX*/
592 val = UART_FCR_TRIGGER_8 | UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR |
595 status = f81232_set_register(port, FIFO_CONTROL_REGISTER, val);
597 dev_err(&port->dev, "%s failed to set FCR: %d\n",
602 /* MSR Interrupt only, LSR will read from Bulk-in odd byte */
603 status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER,
606 dev_err(&port->dev, "%s failed to set IER: %d\n",
614 static int f81232_port_disable(struct usb_serial_port *port)
618 status = f81232_set_register(port, INTERRUPT_ENABLE_REGISTER, 0);
620 dev_err(&port->dev, "%s failed to set IER: %d\n",
628 static void f81232_set_termios(struct tty_struct *tty,
629 struct usb_serial_port *port, struct ktermios *old_termios)
631 struct f81232_private *priv = usb_get_serial_port_data(port);
637 /* Don't change anything if nothing has changed */
638 if (old_termios && !tty_termios_hw_change(&tty->termios, old_termios))
641 if (C_BAUD(tty) == B0)
642 f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS);
643 else if (old_termios && (old_termios->c_cflag & CBAUD) == B0)
644 f81232_set_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0);
646 baudrate = tty_get_baud_rate(tty);
649 old_baud = tty_termios_baud_rate(old_termios);
651 old_baud = F81232_DEF_BAUDRATE;
653 f81232_set_baudrate(tty, port, baudrate, old_baud);
657 new_lcr |= UART_LCR_PARITY;
660 new_lcr |= UART_LCR_EPAR;
663 new_lcr |= UART_LCR_SPAR;
667 new_lcr |= UART_LCR_STOP;
669 switch (C_CSIZE(tty)) {
671 new_lcr |= UART_LCR_WLEN5;
674 new_lcr |= UART_LCR_WLEN6;
677 new_lcr |= UART_LCR_WLEN7;
681 new_lcr |= UART_LCR_WLEN8;
685 mutex_lock(&priv->lock);
687 new_lcr |= (priv->shadow_lcr & UART_LCR_SBC);
688 status = f81232_set_register(port, LINE_CONTROL_REGISTER, new_lcr);
690 dev_err(&port->dev, "%s failed to set LCR: %d\n",
694 priv->shadow_lcr = new_lcr;
696 mutex_unlock(&priv->lock);
699 static int f81232_tiocmget(struct tty_struct *tty)
702 struct usb_serial_port *port = tty->driver_data;
703 struct f81232_private *port_priv = usb_get_serial_port_data(port);
706 /* force get current MSR changed state */
707 f81232_read_msr(port);
709 mutex_lock(&port_priv->lock);
710 mcr = port_priv->modem_control;
711 msr = port_priv->modem_status;
712 mutex_unlock(&port_priv->lock);
714 r = (mcr & UART_MCR_DTR ? TIOCM_DTR : 0) |
715 (mcr & UART_MCR_RTS ? TIOCM_RTS : 0) |
716 (msr & UART_MSR_CTS ? TIOCM_CTS : 0) |
717 (msr & UART_MSR_DCD ? TIOCM_CAR : 0) |
718 (msr & UART_MSR_RI ? TIOCM_RI : 0) |
719 (msr & UART_MSR_DSR ? TIOCM_DSR : 0);
724 static int f81232_tiocmset(struct tty_struct *tty,
725 unsigned int set, unsigned int clear)
727 struct usb_serial_port *port = tty->driver_data;
729 return f81232_set_mctrl(port, set, clear);
732 static int f81232_open(struct tty_struct *tty, struct usb_serial_port *port)
736 result = f81232_port_enable(port);
742 f81232_set_termios(tty, port, NULL);
744 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
746 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
747 " error %d\n", __func__, result);
751 result = usb_serial_generic_open(tty, port);
753 usb_kill_urb(port->interrupt_in_urb);
760 static int f81534a_open(struct tty_struct *tty, struct usb_serial_port *port)
766 val = F81534A_TRIGGER_MULTIPLE_4X | F81534A_FIFO_128BYTE;
767 mask = F81534A_TRIGGER_MASK | F81534A_FIFO_128BYTE;
769 status = f81232_set_mask_register(port, F81534A_MODE_REG, mask, val);
771 dev_err(&port->dev, "failed to set MODE_REG: %d\n", status);
775 return f81232_open(tty, port);
778 static void f81232_close(struct usb_serial_port *port)
780 struct f81232_private *port_priv = usb_get_serial_port_data(port);
782 f81232_port_disable(port);
783 usb_serial_generic_close(port);
784 usb_kill_urb(port->interrupt_in_urb);
785 flush_work(&port_priv->interrupt_work);
786 flush_work(&port_priv->lsr_work);
789 static void f81232_dtr_rts(struct usb_serial_port *port, int on)
792 f81232_set_mctrl(port, TIOCM_DTR | TIOCM_RTS, 0);
794 f81232_set_mctrl(port, 0, TIOCM_DTR | TIOCM_RTS);
797 static bool f81232_tx_empty(struct usb_serial_port *port)
802 status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp);
804 if ((tmp & UART_LSR_TEMT) != UART_LSR_TEMT)
811 static int f81232_carrier_raised(struct usb_serial_port *port)
814 struct f81232_private *priv = usb_get_serial_port_data(port);
816 mutex_lock(&priv->lock);
817 msr = priv->modem_status;
818 mutex_unlock(&priv->lock);
820 if (msr & UART_MSR_DCD)
825 static void f81232_get_serial(struct tty_struct *tty, struct serial_struct *ss)
827 struct usb_serial_port *port = tty->driver_data;
828 struct f81232_private *priv = usb_get_serial_port_data(port);
830 ss->baud_base = priv->baud_base;
833 static void f81232_interrupt_work(struct work_struct *work)
835 struct f81232_private *priv =
836 container_of(work, struct f81232_private, interrupt_work);
838 f81232_read_msr(priv->port);
841 static void f81232_lsr_worker(struct work_struct *work)
843 struct f81232_private *priv;
844 struct usb_serial_port *port;
848 priv = container_of(work, struct f81232_private, lsr_work);
851 status = f81232_get_register(port, LINE_STATUS_REGISTER, &tmp);
853 dev_warn(&port->dev, "read LSR failed: %d\n", status);
856 static int f81534a_ctrl_set_register(struct usb_interface *intf, u16 reg,
859 struct usb_device *dev = interface_to_usbdev(intf);
860 int retry = F81534A_ACCESS_REG_RETRY;
864 tmp = kmemdup(val, size, GFP_KERNEL);
869 status = usb_control_msg(dev,
870 usb_sndctrlpipe(dev, 0),
871 F81232_REGISTER_REQUEST,
877 USB_CTRL_SET_TIMEOUT);
879 status = usb_translate_errors(status);
890 dev_err(&intf->dev, "failed to set register 0x%x: %d\n",
898 static int f81534a_ctrl_enable_all_ports(struct usb_interface *intf, bool en)
900 unsigned char enable[2] = {0};
904 * Enable all available serial ports, define as following:
905 * bit 15 : Reset behavior (when HUB got soft reset)
906 * 0: maintain all serial port enabled state.
907 * 1: disable all serial port.
908 * bit 0~11 : Serial port enable bit.
915 status = f81534a_ctrl_set_register(intf, F81534A_CTRL_CMD_ENABLE_PORT,
916 sizeof(enable), enable);
918 dev_err(&intf->dev, "failed to enable ports: %d\n", status);
923 static int f81534a_ctrl_probe(struct usb_interface *intf,
924 const struct usb_device_id *id)
926 return f81534a_ctrl_enable_all_ports(intf, true);
929 static void f81534a_ctrl_disconnect(struct usb_interface *intf)
931 f81534a_ctrl_enable_all_ports(intf, false);
934 static int f81534a_ctrl_resume(struct usb_interface *intf)
936 return f81534a_ctrl_enable_all_ports(intf, true);
939 static int f81232_port_probe(struct usb_serial_port *port)
941 struct f81232_private *priv;
943 priv = devm_kzalloc(&port->dev, sizeof(*priv), GFP_KERNEL);
947 mutex_init(&priv->lock);
948 INIT_WORK(&priv->interrupt_work, f81232_interrupt_work);
949 INIT_WORK(&priv->lsr_work, f81232_lsr_worker);
951 usb_set_serial_port_data(port, priv);
958 static int f81534a_port_probe(struct usb_serial_port *port)
962 /* tri-state with pull-high, default RS232 Mode */
963 status = f81232_set_register(port, F81534A_GPIO_REG,
964 F81534A_GPIO_MODE2_DIR);
968 return f81232_port_probe(port);
971 static int f81232_suspend(struct usb_serial *serial, pm_message_t message)
973 struct usb_serial_port *port = serial->port[0];
974 struct f81232_private *port_priv = usb_get_serial_port_data(port);
977 for (i = 0; i < ARRAY_SIZE(port->read_urbs); ++i)
978 usb_kill_urb(port->read_urbs[i]);
980 usb_kill_urb(port->interrupt_in_urb);
983 flush_work(&port_priv->interrupt_work);
984 flush_work(&port_priv->lsr_work);
990 static int f81232_resume(struct usb_serial *serial)
992 struct usb_serial_port *port = serial->port[0];
995 if (tty_port_initialized(&port->port)) {
996 result = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
998 dev_err(&port->dev, "submit interrupt urb failed: %d\n",
1004 return usb_serial_generic_resume(serial);
1007 static struct usb_serial_driver f81232_device = {
1009 .owner = THIS_MODULE,
1012 .id_table = f81232_id_table,
1014 .bulk_in_size = 256,
1015 .bulk_out_size = 256,
1016 .open = f81232_open,
1017 .close = f81232_close,
1018 .dtr_rts = f81232_dtr_rts,
1019 .carrier_raised = f81232_carrier_raised,
1020 .get_serial = f81232_get_serial,
1021 .break_ctl = f81232_break_ctl,
1022 .set_termios = f81232_set_termios,
1023 .tiocmget = f81232_tiocmget,
1024 .tiocmset = f81232_tiocmset,
1025 .tiocmiwait = usb_serial_generic_tiocmiwait,
1026 .tx_empty = f81232_tx_empty,
1027 .process_read_urb = f81232_process_read_urb,
1028 .read_int_callback = f81232_read_int_callback,
1029 .port_probe = f81232_port_probe,
1030 .suspend = f81232_suspend,
1031 .resume = f81232_resume,
1034 static struct usb_serial_driver f81534a_device = {
1036 .owner = THIS_MODULE,
1039 .id_table = f81534a_id_table,
1041 .open = f81534a_open,
1042 .close = f81232_close,
1043 .dtr_rts = f81232_dtr_rts,
1044 .carrier_raised = f81232_carrier_raised,
1045 .get_serial = f81232_get_serial,
1046 .break_ctl = f81232_break_ctl,
1047 .set_termios = f81232_set_termios,
1048 .tiocmget = f81232_tiocmget,
1049 .tiocmset = f81232_tiocmset,
1050 .tiocmiwait = usb_serial_generic_tiocmiwait,
1051 .tx_empty = f81232_tx_empty,
1052 .process_read_urb = f81534a_process_read_urb,
1053 .read_int_callback = f81232_read_int_callback,
1054 .port_probe = f81534a_port_probe,
1055 .suspend = f81232_suspend,
1056 .resume = f81232_resume,
1059 static struct usb_serial_driver * const serial_drivers[] = {
1065 static struct usb_driver f81534a_ctrl_driver = {
1066 .name = "f81534a_ctrl",
1067 .id_table = f81534a_ctrl_id_table,
1068 .probe = f81534a_ctrl_probe,
1069 .disconnect = f81534a_ctrl_disconnect,
1070 .resume = f81534a_ctrl_resume,
1073 static int __init f81232_init(void)
1077 status = usb_register_driver(&f81534a_ctrl_driver, THIS_MODULE,
1082 status = usb_serial_register_drivers(serial_drivers, KBUILD_MODNAME,
1085 usb_deregister(&f81534a_ctrl_driver);
1092 static void __exit f81232_exit(void)
1094 usb_serial_deregister_drivers(serial_drivers);
1095 usb_deregister(&f81534a_ctrl_driver);
1098 module_init(f81232_init);
1099 module_exit(f81232_exit);
1101 MODULE_DESCRIPTION("Fintek F81232/532A/534A/535/536 USB to serial driver");
1102 MODULE_AUTHOR("Greg Kroah-Hartman <gregkh@linuxfoundation.org>");
1103 MODULE_AUTHOR("Peter Hong <peter_hong@fintek.com.tw>");
1104 MODULE_LICENSE("GPL v2");