cp210x.c (95168d624f3a8dee466525767200391a0fb006b9) cp210x.c (d42976296c3389b556913d249f7c5626b754ec26)
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 *
7 * Support to set flow control line levels using TIOCMGET and TIOCMSET
8 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow

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

1359 iflag_change = ((a->c_iflag ^ b->c_iflag) & INPCK);
1360
1361 return tty_termios_hw_change(a, b) || iflag_change;
1362}
1363
1364static void cp210x_set_termios(struct tty_struct *tty,
1365 struct usb_serial_port *port, struct ktermios *old_termios)
1366{
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 *
7 * Support to set flow control line levels using TIOCMGET and TIOCMSET
8 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow

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

1359 iflag_change = ((a->c_iflag ^ b->c_iflag) & INPCK);
1360
1361 return tty_termios_hw_change(a, b) || iflag_change;
1362}
1363
1364static void cp210x_set_termios(struct tty_struct *tty,
1365 struct usb_serial_port *port, struct ktermios *old_termios)
1366{
1367 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
1367 struct device *dev = &port->dev;
1368 unsigned int cflag, old_cflag;
1369 u16 bits;
1368 struct device *dev = &port->dev;
1369 unsigned int cflag, old_cflag;
1370 u16 bits;
1371 int ret;
1370
1371 if (!cp210x_termios_change(&tty->termios, old_termios))
1372 return;
1373
1374 cflag = tty->termios.c_cflag;
1375 old_cflag = old_termios->c_cflag;
1376
1377 if (tty->termios.c_ospeed != old_termios->c_ospeed)
1378 cp210x_change_speed(tty, port, old_termios);
1379
1372
1373 if (!cp210x_termios_change(&tty->termios, old_termios))
1374 return;
1375
1376 cflag = tty->termios.c_cflag;
1377 old_cflag = old_termios->c_cflag;
1378
1379 if (tty->termios.c_ospeed != old_termios->c_ospeed)
1380 cp210x_change_speed(tty, port, old_termios);
1381
1380 /* If the number of data bits is to be updated */
1381 if ((cflag & CSIZE) != (old_cflag & CSIZE)) {
1382 cp210x_get_line_ctl(port, &bits);
1383 bits &= ~BITS_DATA_MASK;
1384 switch (cflag & CSIZE) {
1385 case CS5:
1386 bits |= BITS_DATA_5;
1387 dev_dbg(dev, "%s - data bits = 5\n", __func__);
1388 break;
1389 case CS6:
1390 bits |= BITS_DATA_6;
1391 dev_dbg(dev, "%s - data bits = 6\n", __func__);
1392 break;
1393 case CS7:
1394 bits |= BITS_DATA_7;
1395 dev_dbg(dev, "%s - data bits = 7\n", __func__);
1396 break;
1397 case CS8:
1398 default:
1399 bits |= BITS_DATA_8;
1400 dev_dbg(dev, "%s - data bits = 8\n", __func__);
1401 break;
1402 }
1403 if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
1404 dev_dbg(dev, "Number of data bits requested not supported by device\n");
1382 /* CP2101 only supports CS8, 1 stop bit and non-stick parity. */
1383 if (priv->partnum == CP210X_PARTNUM_CP2101) {
1384 tty->termios.c_cflag &= ~(CSIZE | CSTOPB | CMSPAR);
1385 tty->termios.c_cflag |= CS8;
1405 }
1406
1386 }
1387
1407 if ((cflag & (PARENB|PARODD|CMSPAR)) !=
1408 (old_cflag & (PARENB|PARODD|CMSPAR))) {
1409 cp210x_get_line_ctl(port, &bits);
1410 bits &= ~BITS_PARITY_MASK;
1411 if (cflag & PARENB) {
1412 if (cflag & CMSPAR) {
1413 if (cflag & PARODD) {
1414 bits |= BITS_PARITY_MARK;
1415 dev_dbg(dev, "%s - parity = MARK\n", __func__);
1416 } else {
1417 bits |= BITS_PARITY_SPACE;
1418 dev_dbg(dev, "%s - parity = SPACE\n", __func__);
1419 }
1420 } else {
1421 if (cflag & PARODD) {
1422 bits |= BITS_PARITY_ODD;
1423 dev_dbg(dev, "%s - parity = ODD\n", __func__);
1424 } else {
1425 bits |= BITS_PARITY_EVEN;
1426 dev_dbg(dev, "%s - parity = EVEN\n", __func__);
1427 }
1428 }
1429 }
1430 if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
1431 dev_dbg(dev, "Parity mode not supported by device\n");
1388 bits = 0;
1389
1390 switch (C_CSIZE(tty)) {
1391 case CS5:
1392 bits |= BITS_DATA_5;
1393 break;
1394 case CS6:
1395 bits |= BITS_DATA_6;
1396 break;
1397 case CS7:
1398 bits |= BITS_DATA_7;
1399 break;
1400 case CS8:
1401 default:
1402 bits |= BITS_DATA_8;
1403 break;
1432 }
1433
1404 }
1405
1434 if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) {
1435 cp210x_get_line_ctl(port, &bits);
1436 bits &= ~BITS_STOP_MASK;
1437 if (cflag & CSTOPB) {
1438 bits |= BITS_STOP_2;
1439 dev_dbg(dev, "%s - stop bits = 2\n", __func__);
1406 if (C_PARENB(tty)) {
1407 if (C_CMSPAR(tty)) {
1408 if (C_PARODD(tty))
1409 bits |= BITS_PARITY_MARK;
1410 else
1411 bits |= BITS_PARITY_SPACE;
1440 } else {
1412 } else {
1441 bits |= BITS_STOP_1;
1442 dev_dbg(dev, "%s - stop bits = 1\n", __func__);
1413 if (C_PARODD(tty))
1414 bits |= BITS_PARITY_ODD;
1415 else
1416 bits |= BITS_PARITY_EVEN;
1443 }
1417 }
1444 if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
1445 dev_dbg(dev, "Number of stop bits requested not supported by device\n");
1446 }
1447
1418 }
1419
1420 if (C_CSTOPB(tty))
1421 bits |= BITS_STOP_2;
1422 else
1423 bits |= BITS_STOP_1;
1424
1425 ret = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
1426 if (ret)
1427 dev_err(&port->dev, "failed to set line control: %d\n", ret);
1428
1448 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
1449 struct cp210x_flow_ctl flow_ctl;
1450 u32 ctl_hs;
1451 u32 flow_repl;
1452
1453 cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
1454 sizeof(flow_ctl));
1455 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);

--- 670 unchanged lines hidden ---
1429 if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
1430 struct cp210x_flow_ctl flow_ctl;
1431 u32 ctl_hs;
1432 u32 flow_repl;
1433
1434 cp210x_read_reg_block(port, CP210X_GET_FLOW, &flow_ctl,
1435 sizeof(flow_ctl));
1436 ctl_hs = le32_to_cpu(flow_ctl.ulControlHandshake);

--- 670 unchanged lines hidden ---