Lines Matching +full:rs485 +full:- +full:rts +full:- +full:active +full:- +full:high

1 // SPDX-License-Identifier: GPL-2.0+
10 * https://lore.kernel.org/r/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop
240 u8 channel; /* zero-based index or interface number */
241 struct serial_rs485 rs485; member
247 const struct xr_type *type = data->type; in xr_set_reg()
248 struct usb_serial *serial = port->serial; in xr_set_reg()
251 ret = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), in xr_set_reg()
252 type->set_reg, in xr_set_reg()
253 USB_DIR_OUT | USB_TYPE_VENDOR | type->reg_recipient, in xr_set_reg()
257 dev_err(&port->dev, "Failed to set reg 0x%02x: %d\n", reg, ret); in xr_set_reg()
267 const struct xr_type *type = data->type; in xr_get_reg()
268 struct usb_serial *serial = port->serial; in xr_get_reg()
272 if (type->reg_width == 8) in xr_get_reg()
279 return -ENOMEM; in xr_get_reg()
281 ret = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), in xr_get_reg()
282 type->get_reg, in xr_get_reg()
283 USB_DIR_IN | USB_TYPE_VENDOR | type->reg_recipient, in xr_get_reg()
293 dev_err(&port->dev, "Failed to get reg 0x%02x: %d\n", reg, ret); in xr_get_reg()
295 ret = -EIO; in xr_get_reg()
307 return xr_set_reg(port, data->channel, reg, val); in xr_set_reg_uart()
314 return xr_get_reg(port, data->channel, reg, val); in xr_get_reg_uart()
322 reg = reg_base + data->channel; in xr_set_reg_um()
331 return xr_set_reg_uart(port, data->type->uart_enable, in __xr_uart_enable()
339 return xr_set_reg_uart(port, data->type->uart_enable, 0); in __xr_uart_disable()
388 if (data->type->enable) in xr_uart_enable()
389 return data->type->enable(port); in xr_uart_enable()
398 if (data->type->disable) in xr_uart_disable()
399 return data->type->disable(port); in xr_uart_disable()
424 if (data->type->fifo_reset) in xr_fifo_reset()
425 return data->type->fifo_reset(port); in xr_fifo_reset()
427 ret = xr_set_reg_uart(port, data->type->tx_fifo_reset, XR_FIFO_RESET); in xr_fifo_reset()
431 ret = xr_set_reg_uart(port, data->type->rx_fifo_reset, XR_FIFO_RESET); in xr_fifo_reset()
440 struct usb_serial_port *port = tty->driver_data; in xr_tiocmget()
445 ret = xr_get_reg_uart(port, data->type->gpio_status, &status); in xr_tiocmget()
450 * Modem control pins are active low, so reading '0' means it is active in xr_tiocmget()
451 * and '1' means not active. in xr_tiocmget()
467 const struct xr_type *type = data->type; in xr_tiocmset_port()
472 /* Modem control pins are active low, so set & clr are swapped */ in xr_tiocmset_port()
484 ret = xr_set_reg_uart(port, type->gpio_clear, gpio_clr); in xr_tiocmset_port()
487 ret = xr_set_reg_uart(port, type->gpio_set, gpio_set); in xr_tiocmset_port()
495 struct usb_serial_port *port = tty->driver_data; in xr_tiocmset()
510 struct usb_serial_port *port = tty->driver_data; in xr_break_ctl()
512 const struct xr_type *type = data->type; in xr_break_ctl()
518 state = GENMASK(type->reg_width - 1, 0); in xr_break_ctl()
520 dev_dbg(&port->dev, "Turning break %s\n", state == 0 ? "off" : "on"); in xr_break_ctl()
522 return xr_set_reg_uart(port, type->tx_break, state); in xr_break_ctl()
567 baud = tty->termios.c_ospeed; in xr21v141x_set_baudrate()
581 dev_dbg(&port->dev, "Setting baud rate: %u\n", baud); in xr21v141x_set_baudrate()
584 * oscillator and 19-bit programmable divisor. So theoretically it can in xr21v141x_set_baudrate()
585 * generate most commonly used baud rates with high accuracy. in xr21v141x_set_baudrate()
632 const struct xr_type *type = data->type; in xr_set_flow_mode()
637 ret = xr_get_reg_uart(port, type->gpio_mode, &gpio_mode); in xr_set_flow_mode()
651 rs485_enabled = !!(data->rs485.flags & SER_RS485_ENABLED); in xr_set_flow_mode()
653 dev_dbg(&port->dev, "Enabling RS-485\n"); in xr_set_flow_mode()
655 if (data->rs485.flags & SER_RS485_RTS_ON_SEND) in xr_set_flow_mode()
662 dev_dbg(&port->dev, "Enabling hardware flow ctrl\n"); in xr_set_flow_mode()
669 dev_dbg(&port->dev, "Enabling sw flow ctrl\n"); in xr_set_flow_mode()
672 xr_set_reg_uart(port, type->xon_char, start_char); in xr_set_flow_mode()
673 xr_set_reg_uart(port, type->xoff_char, stop_char); in xr_set_flow_mode()
675 dev_dbg(&port->dev, "Disabling flow ctrl\n"); in xr_set_flow_mode()
679 xr_set_reg_uart(port, type->flow_control, flow); in xr_set_flow_mode()
680 xr_set_reg_uart(port, type->gpio_mode, gpio_mode); in xr_set_flow_mode()
686 else if (old_termios && (old_termios->c_cflag & CBAUD) == B0) in xr_set_flow_mode()
694 struct ktermios *termios = &tty->termios; in xr21v141x_set_line_settings()
698 if (!old_termios || (tty->termios.c_ospeed != old_termios->c_ospeed)) in xr21v141x_set_line_settings()
705 termios->c_cflag &= ~CSIZE; in xr21v141x_set_line_settings()
707 termios->c_cflag |= old_termios->c_cflag & CSIZE; in xr21v141x_set_line_settings()
709 termios->c_cflag |= CS8; in xr21v141x_set_line_settings()
754 struct usb_host_interface *alt = port->serial->interface->cur_altsetting; in xr_cdc_set_line_coding()
755 struct usb_device *udev = port->serial->dev; in xr_cdc_set_line_coding()
763 if (tty->termios.c_ospeed) in xr_cdc_set_line_coding()
764 lc->dwDTERate = cpu_to_le32(tty->termios.c_ospeed); in xr_cdc_set_line_coding()
766 lc->dwDTERate = cpu_to_le32(9600); in xr_cdc_set_line_coding()
769 lc->bCharFormat = USB_CDC_2_STOP_BITS; in xr_cdc_set_line_coding()
771 lc->bCharFormat = USB_CDC_1_STOP_BITS; in xr_cdc_set_line_coding()
776 lc->bParityType = USB_CDC_MARK_PARITY; in xr_cdc_set_line_coding()
778 lc->bParityType = USB_CDC_SPACE_PARITY; in xr_cdc_set_line_coding()
781 lc->bParityType = USB_CDC_ODD_PARITY; in xr_cdc_set_line_coding()
783 lc->bParityType = USB_CDC_EVEN_PARITY; in xr_cdc_set_line_coding()
786 lc->bParityType = USB_CDC_NO_PARITY; in xr_cdc_set_line_coding()
789 if (!data->type->have_5_6_bit_mode && in xr_cdc_set_line_coding()
791 tty->termios.c_cflag &= ~CSIZE; in xr_cdc_set_line_coding()
793 tty->termios.c_cflag |= old_termios->c_cflag & CSIZE; in xr_cdc_set_line_coding()
795 tty->termios.c_cflag |= CS8; in xr_cdc_set_line_coding()
800 lc->bDataBits = 5; in xr_cdc_set_line_coding()
803 lc->bDataBits = 6; in xr_cdc_set_line_coding()
806 lc->bDataBits = 7; in xr_cdc_set_line_coding()
810 lc->bDataBits = 8; in xr_cdc_set_line_coding()
817 0, alt->desc.bInterfaceNumber, in xr_cdc_set_line_coding()
820 dev_err(&port->dev, "Failed to set line coding: %d\n", ret); in xr_cdc_set_line_coding()
825 static void xr_sanitize_serial_rs485(struct serial_rs485 *rs485) in xr_sanitize_serial_rs485() argument
827 if (!(rs485->flags & SER_RS485_ENABLED)) { in xr_sanitize_serial_rs485()
828 memset(rs485, 0, sizeof(*rs485)); in xr_sanitize_serial_rs485()
832 /* RTS always toggles after TX */ in xr_sanitize_serial_rs485()
833 if (rs485->flags & SER_RS485_RTS_ON_SEND) in xr_sanitize_serial_rs485()
834 rs485->flags &= ~SER_RS485_RTS_AFTER_SEND; in xr_sanitize_serial_rs485()
836 rs485->flags |= SER_RS485_RTS_AFTER_SEND; in xr_sanitize_serial_rs485()
839 rs485->flags &= SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | in xr_sanitize_serial_rs485()
841 rs485->delay_rts_before_send = 0; in xr_sanitize_serial_rs485()
842 rs485->delay_rts_after_send = 0; in xr_sanitize_serial_rs485()
843 memset(rs485->padding, 0, sizeof(rs485->padding)); in xr_sanitize_serial_rs485()
849 struct usb_serial_port *port = tty->driver_data; in xr_get_rs485_config()
852 down_read(&tty->termios_rwsem); in xr_get_rs485_config()
853 if (copy_to_user(argp, &data->rs485, sizeof(data->rs485))) { in xr_get_rs485_config()
854 up_read(&tty->termios_rwsem); in xr_get_rs485_config()
855 return -EFAULT; in xr_get_rs485_config()
857 up_read(&tty->termios_rwsem); in xr_get_rs485_config()
865 struct usb_serial_port *port = tty->driver_data; in xr_set_rs485_config()
867 struct serial_rs485 rs485; in xr_set_rs485_config() local
869 if (copy_from_user(&rs485, argp, sizeof(rs485))) in xr_set_rs485_config()
870 return -EFAULT; in xr_set_rs485_config()
871 xr_sanitize_serial_rs485(&rs485); in xr_set_rs485_config()
873 down_write(&tty->termios_rwsem); in xr_set_rs485_config()
874 data->rs485 = rs485; in xr_set_rs485_config()
876 up_write(&tty->termios_rwsem); in xr_set_rs485_config()
878 if (copy_to_user(argp, &rs485, sizeof(rs485))) in xr_set_rs485_config()
879 return -EFAULT; in xr_set_rs485_config()
895 return -ENOIOCTLCMD; in xr_ioctl()
908 if (data->type->set_line_settings) in xr_set_termios()
909 data->type->set_line_settings(tty, port, old_termios); in xr_set_termios()
926 dev_err(&port->dev, "Failed to enable UART\n"); in xr_open()
952 struct usb_interface *control = serial->interface; in xr_probe()
953 struct usb_host_interface *alt = control->cur_altsetting; in xr_probe()
959 ret = cdc_parse_cdc_header(&hdrs, control, alt->extra, alt->extralen); in xr_probe()
961 return -ENODEV; in xr_probe()
965 return -ENODEV; in xr_probe()
967 data = usb_ifnum_to_if(serial->dev, desc->bSlaveInterface0); in xr_probe()
969 return -ENODEV; in xr_probe()
975 usb_set_serial_data(serial, (void *)id->driver_info); in xr_probe()
989 if (type->have_xmit_toggle) in xr_gpio_init()
992 ret = xr_set_reg_uart(port, type->gpio_mode, mode); in xr_gpio_init()
997 * Configure DTR and RTS as outputs and make sure they are deasserted in xr_gpio_init()
998 * (active low), and configure RI, CD, DSR and CTS as inputs. in xr_gpio_init()
1001 ret = xr_set_reg_uart(port, type->gpio_direction, mask); in xr_gpio_init()
1005 ret = xr_set_reg_uart(port, type->gpio_set, mask); in xr_gpio_init()
1020 type_id = (int)(unsigned long)usb_get_serial_data(port->serial); in xr_port_probe()
1025 return -ENOMEM; in xr_port_probe()
1027 data->type = type; in xr_port_probe()
1029 desc = &port->serial->interface->cur_altsetting->desc; in xr_port_probe()
1031 data->channel = desc->bInterfaceNumber / 2; in xr_port_probe()
1033 data->channel = desc->bInterfaceNumber; in xr_port_probe()
1037 if (type->custom_driver) { in xr_port_probe()
1038 ret = xr_set_reg_uart(port, type->custom_driver, in xr_port_probe()