cp210x.c (6f7ec77cc8b64ff5037c1945e4650c65c458037d) | cp210x.c (63a8eef70ccb5199534dec56fed9759d214bfe55) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 4 * 5 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 6 * Copyright (C) 2010-2021 Johan Hovold (johan@kernel.org) 7 * 8 * Support to set flow control line levels using TIOCMGET and TIOCMSET --- 238 unchanged lines hidden (view full) --- 247#ifdef CONFIG_GPIOLIB 248 struct gpio_chip gc; 249 bool gpio_registered; 250 u8 gpio_pushpull; 251 u8 gpio_altfunc; 252 u8 gpio_input; 253#endif 254 u8 partnum; | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Silicon Laboratories CP210x USB to RS232 serial adaptor driver 4 * 5 * Copyright (C) 2005 Craig Shelley (craig@microtron.org.uk) 6 * Copyright (C) 2010-2021 Johan Hovold (johan@kernel.org) 7 * 8 * Support to set flow control line levels using TIOCMGET and TIOCMSET --- 238 unchanged lines hidden (view full) --- 247#ifdef CONFIG_GPIOLIB 248 struct gpio_chip gc; 249 bool gpio_registered; 250 u8 gpio_pushpull; 251 u8 gpio_altfunc; 252 u8 gpio_input; 253#endif 254 u8 partnum; |
255 u32 fw_version; |
|
255 speed_t min_speed; 256 speed_t max_speed; 257 bool use_actual_rate; | 256 speed_t min_speed; 257 speed_t max_speed; 258 bool use_actual_rate; |
259 bool no_flow_control; |
|
258}; 259 260enum cp210x_event_state { 261 ES_DATA, 262 ES_ESCAPE, 263 ES_LSR, 264 ES_LSR_DATA_0, 265 ES_LSR_DATA_1, --- 127 unchanged lines hidden (view full) --- 393 u8 bBreakChar; 394 u8 bEventChar; 395 u8 bXonChar; 396 u8 bXoffChar; 397}; 398 399/* CP210X_VENDOR_SPECIFIC values */ 400#define CP210X_READ_2NCONFIG 0x000E | 260}; 261 262enum cp210x_event_state { 263 ES_DATA, 264 ES_ESCAPE, 265 ES_LSR, 266 ES_LSR_DATA_0, 267 ES_LSR_DATA_1, --- 127 unchanged lines hidden (view full) --- 395 u8 bBreakChar; 396 u8 bEventChar; 397 u8 bXonChar; 398 u8 bXoffChar; 399}; 400 401/* CP210X_VENDOR_SPECIFIC values */ 402#define CP210X_READ_2NCONFIG 0x000E |
403#define CP210X_GET_FW_VER_2N 0x0010 |
|
401#define CP210X_READ_LATCH 0x00C2 402#define CP210X_GET_PARTNUM 0x370B 403#define CP210X_GET_PORTCONFIG 0x370C 404#define CP210X_GET_DEVICEMODE 0x3711 405#define CP210X_WRITE_LATCH 0x37E1 406 407/* Part number definitions */ 408#define CP210X_PARTNUM_CP2101 0x01 --- 714 unchanged lines hidden (view full) --- 1123 a->c_cc[VSTOP] != b->c_cc[VSTOP]; 1124 1125 return tty_termios_hw_change(a, b) || iflag_change || cc_change; 1126} 1127 1128static void cp210x_set_flow_control(struct tty_struct *tty, 1129 struct usb_serial_port *port, struct ktermios *old_termios) 1130{ | 404#define CP210X_READ_LATCH 0x00C2 405#define CP210X_GET_PARTNUM 0x370B 406#define CP210X_GET_PORTCONFIG 0x370C 407#define CP210X_GET_DEVICEMODE 0x3711 408#define CP210X_WRITE_LATCH 0x37E1 409 410/* Part number definitions */ 411#define CP210X_PARTNUM_CP2101 0x01 --- 714 unchanged lines hidden (view full) --- 1126 a->c_cc[VSTOP] != b->c_cc[VSTOP]; 1127 1128 return tty_termios_hw_change(a, b) || iflag_change || cc_change; 1129} 1130 1131static void cp210x_set_flow_control(struct tty_struct *tty, 1132 struct usb_serial_port *port, struct ktermios *old_termios) 1133{ |
1134 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); |
|
1131 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 1132 struct cp210x_special_chars chars; 1133 struct cp210x_flow_ctl flow_ctl; 1134 u32 flow_repl; 1135 u32 ctl_hs; 1136 int ret; 1137 | 1135 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port); 1136 struct cp210x_special_chars chars; 1137 struct cp210x_flow_ctl flow_ctl; 1138 u32 flow_repl; 1139 u32 ctl_hs; 1140 int ret; 1141 |
1142 /* 1143 * Some CP2102N interpret ulXonLimit as ulFlowReplace (erratum 1144 * CP2102N_E104). Report back that flow control is not supported. 1145 */ 1146 if (priv->no_flow_control) { 1147 tty->termios.c_cflag &= ~CRTSCTS; 1148 tty->termios.c_iflag &= ~(IXON | IXOFF); 1149 } 1150 |
|
1138 if (old_termios && 1139 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) && 1140 I_IXON(tty) == (old_termios->c_iflag & IXON) && 1141 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) && 1142 START_CHAR(tty) == old_termios->c_cc[VSTART] && 1143 STOP_CHAR(tty) == old_termios->c_cc[VSTOP]) { 1144 return; 1145 } --- 40 unchanged lines hidden (view full) --- 1186 ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; 1187 if (port_priv->rts) 1188 flow_repl |= CP210X_SERIAL_RTS_ACTIVE; 1189 else 1190 flow_repl |= CP210X_SERIAL_RTS_INACTIVE; 1191 port_priv->crtscts = false; 1192 } 1193 | 1151 if (old_termios && 1152 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) && 1153 I_IXON(tty) == (old_termios->c_iflag & IXON) && 1154 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) && 1155 START_CHAR(tty) == old_termios->c_cc[VSTART] && 1156 STOP_CHAR(tty) == old_termios->c_cc[VSTOP]) { 1157 return; 1158 } --- 40 unchanged lines hidden (view full) --- 1199 ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE; 1200 if (port_priv->rts) 1201 flow_repl |= CP210X_SERIAL_RTS_ACTIVE; 1202 else 1203 flow_repl |= CP210X_SERIAL_RTS_INACTIVE; 1204 port_priv->crtscts = false; 1205 } 1206 |
1194 if (I_IXOFF(tty)) | 1207 if (I_IXOFF(tty)) { |
1195 flow_repl |= CP210X_SERIAL_AUTO_RECEIVE; | 1208 flow_repl |= CP210X_SERIAL_AUTO_RECEIVE; |
1196 else | 1209 1210 flow_ctl.ulXonLimit = cpu_to_le32(128); 1211 flow_ctl.ulXoffLimit = cpu_to_le32(128); 1212 } else { |
1197 flow_repl &= ~CP210X_SERIAL_AUTO_RECEIVE; | 1213 flow_repl &= ~CP210X_SERIAL_AUTO_RECEIVE; |
1214 } |
|
1198 1199 if (I_IXON(tty)) 1200 flow_repl |= CP210X_SERIAL_AUTO_TRANSMIT; 1201 else 1202 flow_repl &= ~CP210X_SERIAL_AUTO_TRANSMIT; 1203 | 1215 1216 if (I_IXON(tty)) 1217 flow_repl |= CP210X_SERIAL_AUTO_TRANSMIT; 1218 else 1219 flow_repl &= ~CP210X_SERIAL_AUTO_TRANSMIT; 1220 |
1204 flow_ctl.ulXonLimit = cpu_to_le32(128); 1205 flow_ctl.ulXoffLimit = cpu_to_le32(128); 1206 | |
1207 dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", __func__, 1208 ctl_hs, flow_repl); 1209 1210 flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); 1211 flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); 1212 1213 cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, 1214 sizeof(flow_ctl)); --- 706 unchanged lines hidden (view full) --- 1921 break; 1922 } 1923 1924 priv->min_speed = min; 1925 priv->max_speed = max; 1926 priv->use_actual_rate = use_actual_rate; 1927} 1928 | 1221 dev_dbg(&port->dev, "%s - ctrl = 0x%02x, flow = 0x%02x\n", __func__, 1222 ctl_hs, flow_repl); 1223 1224 flow_ctl.ulControlHandshake = cpu_to_le32(ctl_hs); 1225 flow_ctl.ulFlowReplace = cpu_to_le32(flow_repl); 1226 1227 cp210x_write_reg_block(port, CP210X_SET_FLOW, &flow_ctl, 1228 sizeof(flow_ctl)); --- 706 unchanged lines hidden (view full) --- 1935 break; 1936 } 1937 1938 priv->min_speed = min; 1939 priv->max_speed = max; 1940 priv->use_actual_rate = use_actual_rate; 1941} 1942 |
1943static int cp210x_get_fw_version(struct usb_serial *serial, u16 value) 1944{ 1945 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1946 u8 ver[3]; 1947 int ret; 1948 1949 ret = cp210x_read_vendor_block(serial, REQTYPE_DEVICE_TO_HOST, value, 1950 ver, sizeof(ver)); 1951 if (ret) 1952 return ret; 1953 1954 dev_dbg(&serial->interface->dev, "%s - %d.%d.%d\n", __func__, 1955 ver[0], ver[1], ver[2]); 1956 1957 priv->fw_version = ver[0] << 16 | ver[1] << 8 | ver[2]; 1958 1959 return 0; 1960} 1961 1962static void cp210x_determine_quirks(struct usb_serial *serial) 1963{ 1964 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 1965 int ret; 1966 1967 switch (priv->partnum) { 1968 case CP210X_PARTNUM_CP2102N_QFN28: 1969 case CP210X_PARTNUM_CP2102N_QFN24: 1970 case CP210X_PARTNUM_CP2102N_QFN20: 1971 ret = cp210x_get_fw_version(serial, CP210X_GET_FW_VER_2N); 1972 if (ret) 1973 break; 1974 if (priv->fw_version <= 0x10004) 1975 priv->no_flow_control = true; 1976 break; 1977 default: 1978 break; 1979 } 1980} 1981 |
|
1929static int cp210x_attach(struct usb_serial *serial) 1930{ 1931 int result; 1932 struct cp210x_serial_private *priv; 1933 1934 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1935 if (!priv) 1936 return -ENOMEM; --- 4 unchanged lines hidden (view full) --- 1941 if (result < 0) { 1942 dev_warn(&serial->interface->dev, 1943 "querying part number failed\n"); 1944 priv->partnum = CP210X_PARTNUM_UNKNOWN; 1945 } 1946 1947 usb_set_serial_data(serial, priv); 1948 | 1982static int cp210x_attach(struct usb_serial *serial) 1983{ 1984 int result; 1985 struct cp210x_serial_private *priv; 1986 1987 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 1988 if (!priv) 1989 return -ENOMEM; --- 4 unchanged lines hidden (view full) --- 1994 if (result < 0) { 1995 dev_warn(&serial->interface->dev, 1996 "querying part number failed\n"); 1997 priv->partnum = CP210X_PARTNUM_UNKNOWN; 1998 } 1999 2000 usb_set_serial_data(serial, priv); 2001 |
2002 cp210x_determine_quirks(serial); |
|
1949 cp210x_init_max_speed(serial); 1950 1951 result = cp210x_gpio_init(serial); 1952 if (result < 0) { 1953 dev_err(&serial->interface->dev, "GPIO initialisation failed: %d\n", 1954 result); 1955 } 1956 --- 21 unchanged lines hidden --- | 2003 cp210x_init_max_speed(serial); 2004 2005 result = cp210x_gpio_init(serial); 2006 if (result < 0) { 2007 dev_err(&serial->interface->dev, "GPIO initialisation failed: %d\n", 2008 result); 2009 } 2010 --- 21 unchanged lines hidden --- |