cp210x.c (5951b8508855799fbb2d6a9553ab3b7af595ea94) cp210x.c (8cce3bbfb4cffce097c823c29ba487d5a7422d37)
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

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

264struct cp210x_port_private {
265 u8 bInterfaceNumber;
266 bool event_mode;
267 enum cp210x_event_state event_state;
268 u8 lsr;
269
270 struct mutex mutex;
271 bool crtscts;
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

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

264struct cp210x_port_private {
265 u8 bInterfaceNumber;
266 bool event_mode;
267 enum cp210x_event_state event_state;
268 u8 lsr;
269
270 struct mutex mutex;
271 bool crtscts;
272 bool dtr;
273 bool rts;
272};
273
274static struct usb_serial_driver cp210x_device = {
275 .driver = {
276 .owner = THIS_MODULE,
277 .name = "cp210x",
278 },
279 .id_table = id_table,

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

1157
1158 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
1159 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
1160
1161 ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE;
1162 ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE;
1163 ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY;
1164 ctl_hs &= ~CP210X_SERIAL_DTR_MASK;
274};
275
276static struct usb_serial_driver cp210x_device = {
277 .driver = {
278 .owner = THIS_MODULE,
279 .name = "cp210x",
280 },
281 .id_table = id_table,

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

1159
1160 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);
1161 flow_repl = le32_to_cpu(flow_ctl.ulFlowReplace);
1162
1163 ctl_hs &= ~CP210X_SERIAL_DSR_HANDSHAKE;
1164 ctl_hs &= ~CP210X_SERIAL_DCD_HANDSHAKE;
1165 ctl_hs &= ~CP210X_SERIAL_DSR_SENSITIVITY;
1166 ctl_hs &= ~CP210X_SERIAL_DTR_MASK;
1165 ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE);
1167 if (port_priv->dtr)
1168 ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_ACTIVE);
1169 else
1170 ctl_hs |= CP210X_SERIAL_DTR_SHIFT(CP210X_SERIAL_DTR_INACTIVE);
1166
1167 if (C_CRTSCTS(tty)) {
1168 ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
1169 flow_repl &= ~CP210X_SERIAL_RTS_MASK;
1170 flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
1171 port_priv->crtscts = true;
1172 } else {
1173 ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE;
1174 flow_repl &= ~CP210X_SERIAL_RTS_MASK;
1171
1172 if (C_CRTSCTS(tty)) {
1173 ctl_hs |= CP210X_SERIAL_CTS_HANDSHAKE;
1174 flow_repl &= ~CP210X_SERIAL_RTS_MASK;
1175 flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_FLOW_CTL);
1176 port_priv->crtscts = true;
1177 } else {
1178 ctl_hs &= ~CP210X_SERIAL_CTS_HANDSHAKE;
1179 flow_repl &= ~CP210X_SERIAL_RTS_MASK;
1175 flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE);
1180 if (port_priv->rts)
1181 flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_ACTIVE);
1182 else
1183 flow_repl |= CP210X_SERIAL_RTS_SHIFT(CP210X_SERIAL_RTS_INACTIVE);
1176 port_priv->crtscts = false;
1177 }
1178
1179 if (I_IXOFF(tty))
1180 flow_repl |= CP210X_SERIAL_AUTO_RECEIVE;
1181 else
1182 flow_repl &= ~CP210X_SERIAL_AUTO_RECEIVE;
1183

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

1282
1283static int cp210x_tiocmset_port(struct usb_serial_port *port,
1284 unsigned int set, unsigned int clear)
1285{
1286 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1287 u16 control = 0;
1288 int ret;
1289
1184 port_priv->crtscts = false;
1185 }
1186
1187 if (I_IXOFF(tty))
1188 flow_repl |= CP210X_SERIAL_AUTO_RECEIVE;
1189 else
1190 flow_repl &= ~CP210X_SERIAL_AUTO_RECEIVE;
1191

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

1290
1291static int cp210x_tiocmset_port(struct usb_serial_port *port,
1292 unsigned int set, unsigned int clear)
1293{
1294 struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
1295 u16 control = 0;
1296 int ret;
1297
1298 mutex_lock(&port_priv->mutex);
1299
1290 if (set & TIOCM_RTS) {
1300 if (set & TIOCM_RTS) {
1301 port_priv->rts = true;
1291 control |= CONTROL_RTS;
1292 control |= CONTROL_WRITE_RTS;
1293 }
1294 if (set & TIOCM_DTR) {
1302 control |= CONTROL_RTS;
1303 control |= CONTROL_WRITE_RTS;
1304 }
1305 if (set & TIOCM_DTR) {
1306 port_priv->dtr = true;
1295 control |= CONTROL_DTR;
1296 control |= CONTROL_WRITE_DTR;
1297 }
1298 if (clear & TIOCM_RTS) {
1307 control |= CONTROL_DTR;
1308 control |= CONTROL_WRITE_DTR;
1309 }
1310 if (clear & TIOCM_RTS) {
1311 port_priv->rts = false;
1299 control &= ~CONTROL_RTS;
1300 control |= CONTROL_WRITE_RTS;
1301 }
1302 if (clear & TIOCM_DTR) {
1312 control &= ~CONTROL_RTS;
1313 control |= CONTROL_WRITE_RTS;
1314 }
1315 if (clear & TIOCM_DTR) {
1316 port_priv->dtr = false;
1303 control &= ~CONTROL_DTR;
1304 control |= CONTROL_WRITE_DTR;
1305 }
1306
1317 control &= ~CONTROL_DTR;
1318 control |= CONTROL_WRITE_DTR;
1319 }
1320
1307 mutex_lock(&port_priv->mutex);
1308
1309 /*
1310 * SET_MHS cannot be used to control RTS when auto-RTS is enabled.
1311 * Note that RTS is still deasserted when disabling the UART on close.
1312 */
1313 if (port_priv->crtscts)
1314 control &= ~CONTROL_WRITE_RTS;
1315
1316 dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control);

--- 595 unchanged lines hidden ---
1321 /*
1322 * SET_MHS cannot be used to control RTS when auto-RTS is enabled.
1323 * Note that RTS is still deasserted when disabling the UART on close.
1324 */
1325 if (port_priv->crtscts)
1326 control &= ~CONTROL_WRITE_RTS;
1327
1328 dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control);

--- 595 unchanged lines hidden ---