cp210x.c (e88906b169ebcb8046e8f0ad76edd09ab41cfdfe) cp210x.c (d03a6d4e2beaa358b6c4e16fe106e813a57e927a)
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

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

1044static void cp210x_change_speed(struct tty_struct *tty,
1045 struct usb_serial_port *port,
1046 const struct ktermios *old_termios)
1047{
1048 struct usb_serial *serial = port->serial;
1049 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1050 u32 baud;
1051
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

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

1044static void cp210x_change_speed(struct tty_struct *tty,
1045 struct usb_serial_port *port,
1046 const struct ktermios *old_termios)
1047{
1048 struct usb_serial *serial = port->serial;
1049 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1050 u32 baud;
1051
1052 if (tty->termios.c_ospeed == 0)
1053 return;
1054
1052 /*
1053 * This maps the requested rate to the actual rate, a valid rate on
1054 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
1055 /*
1056 * This maps the requested rate to the actual rate, a valid rate on
1057 * cp2102 or cp2103, or to an arbitrary rate in [1M, max_speed].
1055 *
1056 * NOTE: B0 is not implemented.
1057 */
1058 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
1059
1060 if (priv->use_actual_rate)
1061 baud = cp210x_get_actual_rate(baud);
1062 else if (baud < 1000000)
1063 baud = cp210x_get_an205_rate(baud);
1064

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

1141 * Some CP2102N interpret ulXonLimit as ulFlowReplace (erratum
1142 * CP2102N_E104). Report back that flow control is not supported.
1143 */
1144 if (priv->no_flow_control) {
1145 tty->termios.c_cflag &= ~CRTSCTS;
1146 tty->termios.c_iflag &= ~(IXON | IXOFF);
1147 }
1148
1058 */
1059 baud = clamp(tty->termios.c_ospeed, priv->min_speed, priv->max_speed);
1060
1061 if (priv->use_actual_rate)
1062 baud = cp210x_get_actual_rate(baud);
1063 else if (baud < 1000000)
1064 baud = cp210x_get_an205_rate(baud);
1065

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

1142 * Some CP2102N interpret ulXonLimit as ulFlowReplace (erratum
1143 * CP2102N_E104). Report back that flow control is not supported.
1144 */
1145 if (priv->no_flow_control) {
1146 tty->termios.c_cflag &= ~CRTSCTS;
1147 tty->termios.c_iflag &= ~(IXON | IXOFF);
1148 }
1149
1149 if (old_termios &&
1150 if (tty->termios.c_ospeed != 0 &&
1151 old_termios && old_termios->c_ospeed != 0 &&
1150 C_CRTSCTS(tty) == (old_termios->c_cflag & CRTSCTS) &&
1151 I_IXON(tty) == (old_termios->c_iflag & IXON) &&
1152 I_IXOFF(tty) == (old_termios->c_iflag & IXOFF) &&
1153 START_CHAR(tty) == old_termios->c_cc[VSTART] &&
1154 STOP_CHAR(tty) == old_termios->c_cc[VSTOP]) {
1155 return;
1156 }
1157

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

1166 if (ret) {
1167 dev_err(&port->dev, "failed to set special chars: %d\n",
1168 ret);
1169 }
1170 }
1171
1172 mutex_lock(&port_priv->mutex);
1173
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 }
1159

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

1168 if (ret) {
1169 dev_err(&port->dev, "failed to set special chars: %d\n",
1170 ret);
1171 }
1172 }
1173
1174 mutex_lock(&port_priv->mutex);
1175
1176 if (tty->termios.c_ospeed == 0) {
1177 port_priv->dtr = false;
1178 port_priv->rts = false;
1179 } else if (old_termios && old_termios->c_ospeed == 0) {
1180 port_priv->dtr = true;
1181 port_priv->rts = true;
1182 }
1183
1174 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
1175 sizeof(flow_ctl));
1176 if (ret)
1177 goto out_unlock;
1178
1179 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
1180 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
1181

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

1238static void cp210x_set_termios(struct tty_struct *tty,
1239 struct usb_serial_port *port,
1240 const struct ktermios *old_termios)
1241{
1242 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
1243 u16 bits;
1244 int ret;
1245
1184 ret = cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
1185 sizeof(flow_ctl));
1186 if (ret)
1187 goto out_unlock;
1188
1189 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
1190 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
1191

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

1248static void cp210x_set_termios(struct tty_struct *tty,
1249 struct usb_serial_port *port,
1250 const struct ktermios *old_termios)
1251{
1252 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
1253 u16 bits;
1254 int ret;
1255
1246 if (old_termios && !cp210x_termios_change(&tty->termios, old_termios))
1256 if (old_termios && !cp210x_termios_change(&tty->termios, old_termios) &&
1257 tty->termios.c_ospeed != 0)
1247 return;
1248
1249 if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed)
1250 cp210x_change_speed(tty, port, old_termios);
1251
1252 /* CP2101 only supports CS8, 1 stop bit and non-stick parity. */
1253 if (priv->partnum == CP210X_PARTNUM_CP2101) {
1254 tty->termios.c_cflag &= ~(CSIZE | CSTOPB | CMSPAR);

--- 919 unchanged lines hidden ---
1258 return;
1259
1260 if (!old_termios || tty->termios.c_ospeed != old_termios->c_ospeed)
1261 cp210x_change_speed(tty, port, old_termios);
1262
1263 /* CP2101 only supports CS8, 1 stop bit and non-stick parity. */
1264 if (priv->partnum == CP210X_PARTNUM_CP2101) {
1265 tty->termios.c_cflag &= ~(CSIZE | CSTOPB | CMSPAR);

--- 919 unchanged lines hidden ---