cp210x.c (a377f9e906af4df9071ba8ddba60188cb4013d93) cp210x.c (9034389cd81681b4f0123173eb836624199209c7)
1/*
2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
3 *
4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.

--- 313 unchanged lines hidden (view full) ---

322/*
323 * CP210X_PURGE - 16 bits passed in wValue of USB request.
324 * SiLabs app note AN571 gives a strange description of the 4 bits:
325 * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive.
326 * writing 1 to all, however, purges cp2108 well enough to avoid the hang.
327 */
328#define PURGE_ALL 0x000f
329
1/*
2 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver
3 *
4 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.

--- 313 unchanged lines hidden (view full) ---

322/*
323 * CP210X_PURGE - 16 bits passed in wValue of USB request.
324 * SiLabs app note AN571 gives a strange description of the 4 bits:
325 * bit 0 or bit 2 clears the transmit queue and 1 or 3 receive.
326 * writing 1 to all, however, purges cp2108 well enough to avoid the hang.
327 */
328#define PURGE_ALL 0x000f
329
330/* CP210X_GET_FLOW/CP210X_SET_FLOW read/write these 0x10 bytes */
331struct cp210x_flow_ctl {
332 __le32 ulControlHandshake;
333 __le32 ulFlowReplace;
334 __le32 ulXonLimit;
335 __le32 ulXoffLimit;
336} __packed;
337
338/* cp210x_flow_ctl::ulControlHandshake */
339#define CP210X_SERIAL_DTR_MASK GENMASK(1, 0)
340#define CP210X_SERIAL_DTR_SHIFT(_mode) (_mode)
341#define CP210X_SERIAL_CTS_HANDSHAKE BIT(3)
342#define CP210X_SERIAL_DSR_HANDSHAKE BIT(4)
343#define CP210X_SERIAL_DCD_HANDSHAKE BIT(5)
344#define CP210X_SERIAL_DSR_SENSITIVITY BIT(6)
345
346/* values for cp210x_flow_ctl::ulControlHandshake::CP210X_SERIAL_DTR_MASK */
347#define CP210X_SERIAL_DTR_INACTIVE 0
348#define CP210X_SERIAL_DTR_ACTIVE 1
349#define CP210X_SERIAL_DTR_FLOW_CTL 2
350
351/* cp210x_flow_ctl::ulFlowReplace */
352#define CP210X_SERIAL_AUTO_TRANSMIT BIT(0)
353#define CP210X_SERIAL_AUTO_RECEIVE BIT(1)
354#define CP210X_SERIAL_ERROR_CHAR BIT(2)
355#define CP210X_SERIAL_NULL_STRIPPING BIT(3)
356#define CP210X_SERIAL_BREAK_CHAR BIT(4)
357#define CP210X_SERIAL_RTS_MASK GENMASK(7, 6)
358#define CP210X_SERIAL_RTS_SHIFT(_mode) (_mode << 6)
359#define CP210X_SERIAL_XOFF_CONTINUE BIT(31)
360
361/* values for cp210x_flow_ctl::ulFlowReplace::CP210X_SERIAL_RTS_MASK */
362#define CP210X_SERIAL_RTS_INACTIVE 0
363#define CP210X_SERIAL_RTS_ACTIVE 1
364#define CP210X_SERIAL_RTS_FLOW_CTL 2
365
330/*
331 * Reads a variable-sized block of CP210X_ registers, identified by req.
332 * Returns data into buf in native USB byte order.
333 */
334static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
335 void *buf, int bufsize)
336{
337 struct usb_serial *serial = port->serial;

--- 351 unchanged lines hidden (view full) ---

689 * cp210x_get_termios_port
690 * This is the heart of cp210x_get_termios which always uses a &usb_serial_port.
691 */
692static void cp210x_get_termios_port(struct usb_serial_port *port,
693 unsigned int *cflagp, unsigned int *baudp)
694{
695 struct device *dev = &port->dev;
696 unsigned int cflag;
366/*
367 * Reads a variable-sized block of CP210X_ registers, identified by req.
368 * Returns data into buf in native USB byte order.
369 */
370static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
371 void *buf, int bufsize)
372{
373 struct usb_serial *serial = port->serial;

--- 351 unchanged lines hidden (view full) ---

725 * cp210x_get_termios_port
726 * This is the heart of cp210x_get_termios which always uses a &usb_serial_port.
727 */
728static void cp210x_get_termios_port(struct usb_serial_port *port,
729 unsigned int *cflagp, unsigned int *baudp)
730{
731 struct device *dev = &port->dev;
732 unsigned int cflag;
697 u8 modem_ctl[16];
733 struct cp210x_flow_ctl flow_ctl;
698 u32 baud;
699 u16 bits;
734 u32 baud;
735 u16 bits;
736 u32 ctl_hs;
700
701 cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
702
703 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
704 *baudp = baud;
705
706 cflag = *cflagp;
707

--- 79 unchanged lines hidden (view full) ---

787 break;
788 default:
789 dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__);
790 bits &= ~BITS_STOP_MASK;
791 cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
792 break;
793 }
794
737
738 cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
739
740 dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
741 *baudp = baud;
742
743 cflag = *cflagp;
744

--- 79 unchanged lines hidden (view full) ---

824 break;
825 default:
826 dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__);
827 bits &= ~BITS_STOP_MASK;
828 cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
829 break;
830 }
831
795 cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
796 sizeof(modem_ctl));
797 if (modem_ctl[0] & 0x08) {
832 cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
833 sizeof(flow_ctl));
834 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
835 if (ctl_hs & CP210X_SERIAL_CTS_HANDSHAKE) {
798 dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
799 cflag |= CRTSCTS;
800 } else {
801 dev_dbg(dev, "%s - flow control = NONE\n", __func__);
802 cflag &= ~CRTSCTS;
803 }
804
805 *cflagp = cflag;

--- 52 unchanged lines hidden (view full) ---

858}
859
860static void cp210x_set_termios(struct tty_struct *tty,
861 struct usb_serial_port *port, struct ktermios *old_termios)
862{
863 struct device *dev = &port->dev;
864 unsigned int cflag, old_cflag;
865 u16 bits;
836 dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
837 cflag |= CRTSCTS;
838 } else {
839 dev_dbg(dev, "%s - flow control = NONE\n", __func__);
840 cflag &= ~CRTSCTS;
841 }
842
843 *cflagp = cflag;

--- 52 unchanged lines hidden (view full) ---

896}
897
898static void cp210x_set_termios(struct tty_struct *tty,
899 struct usb_serial_port *port, struct ktermios *old_termios)
900{
901 struct device *dev = &port->dev;
902 unsigned int cflag, old_cflag;
903 u16 bits;
866 u8 modem_ctl[16];
867
868 cflag = tty->termios.c_cflag;
869 old_cflag = old_termios->c_cflag;
870
871 if (tty->termios.c_ospeed != old_termios->c_ospeed)
872 cp210x_change_speed(tty, port, old_termios);
873
874 /* If the number of data bits is to be updated */

--- 67 unchanged lines hidden (view full) ---

942 bits |= BITS_STOP_1;
943 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
944 }
945 if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
946 dev_dbg(dev, "Number of stop bits requested not supported by device\n");
947 }
948
949 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
904
905 cflag = tty->termios.c_cflag;
906 old_cflag = old_termios->c_cflag;
907
908 if (tty->termios.c_ospeed != old_termios->c_ospeed)
909 cp210x_change_speed(tty, port, old_termios);
910
911 /* If the number of data bits is to be updated */

--- 67 unchanged lines hidden (view full) ---

979 bits |= BITS_STOP_1;
980 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
981 }
982 if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
983 dev_dbg(dev, "Number of stop bits requested not supported by device\n");
984 }
985
986 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
987 struct cp210x_flow_ctl flow_ctl;
988 u32 ctl_hs;
989 u32 flow_repl;
950
990
951 /* Only bytes 0, 4 and 7 out of first 8 have functional bits */
991 cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
992 sizeof(flow_ctl));
993 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
994 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
995 dev_dbg(dev, "%s - read ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
996 __func__, ctl_hs, flow_repl);
952
997
953 cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
954 sizeof(modem_ctl));
955 dev_dbg(dev, "%s - read modem controls = %02x .. .. .. %02x .. .. %02x\n",
956 __func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
957
958 if (cflag & CRTSCTS) {
998 if (cflag & CRTSCTS) {
959 modem_ctl[0] &= ~0x7B;
960 modem_ctl[0] |= 0x09;
961 modem_ctl[4] = 0x80;
962 /* FIXME - why clear reserved bits just read? */
963 modem_ctl[5] = 0;
964 modem_ctl[6] = 0;
965 modem_ctl[7] = 0;
999 ctl_hs &= ~(CP210X_SERIAL_DTR_MASK |
1000 CP210X_SERIAL_CTS_HANDSHAKE |
1001 CP210X_SERIAL_DSR_HANDSHAKE |
1002 CP210X_SERIAL_DCD_HANDSHAKE |
1003 CP210X_SERIAL_DSR_SENSITIVITY);
1004 ctl_hs |= CP210X_SERIAL_DTR_SHIFT(
1005 CP210X_SERIAL_DTR_ACTIVE);
1006 ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
1007 /*
1008 * FIXME: Why clear bits unrelated to flow control.
1009 * Why clear CP210X_SERIAL_XOFF_CONTINUE which is
1010 * never set
1011 */
1012 flow_repl = 0;
1013 flow_repl |= CP210X_SERIAL_RTS_SHIFT(
1014 CP210X_SERIAL_RTS_FLOW_CTL);
966 dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
967 } else {
1015 dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
1016 } else {
968 modem_ctl[0] &= ~0x7B;
969 modem_ctl[0] |= 0x01;
970 modem_ctl[4] = 0x40;
1017 ctl_hs &= ~(CP210X_SERIAL_DTR_MASK |
1018 CP210X_SERIAL_CTS_HANDSHAKE |
1019 CP210X_SERIAL_DSR_HANDSHAKE |
1020 CP210X_SERIAL_DCD_HANDSHAKE |
1021 CP210X_SERIAL_DSR_SENSITIVITY);
1022 ctl_hs |= CP210X_SERIAL_DTR_SHIFT(
1023 CP210X_SERIAL_DTR_ACTIVE);
1024 /* FIXME: Why clear bits unrelated to flow control */
1025 flow_repl &= 0xffffff00;
1026 flow_repl |= CP210X_SERIAL_RTS_SHIFT(
1027 CP210X_SERIAL_RTS_ACTIVE);
971 dev_dbg(dev, "%s - flow control = NONE\n", __func__);
972 }
973
1028 dev_dbg(dev, "%s - flow control = NONE\n", __func__);
1029 }
1030
974 dev_dbg(dev, "%s - write modem controls = %02x .. .. .. %02x .. .. %02x\n",
975 __func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
976 cp210x_write_reg_block(port, CP210X_SET_FLOW, modem_ctl,
977 sizeof(modem_ctl));
1031 dev_dbg(dev, "%s - write ulControlHandshake=0x%08x, ulFlowReplace=0x%08x\n",
1032 __func__, ctl_hs, flow_repl);
1033 flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs);
1034 flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl);
1035 cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl,
1036 sizeof(flow_ctl));
978 }
979
980}
981
982static int cp210x_tiocmset(struct tty_struct *tty,
983 unsigned int set, unsigned int clear)
984{
985 struct usb_serial_port *port = tty->driver_data;

--- 111 unchanged lines hidden ---
1037 }
1038
1039}
1040
1041static int cp210x_tiocmset(struct tty_struct *tty,
1042 unsigned int set, unsigned int clear)
1043{
1044 struct usb_serial_port *port = tty->driver_data;

--- 111 unchanged lines hidden ---