cp210x.c (95fd4f47c857cf887ec0f6718ffb6a6ec3b62bd6) cp210x.c (d4706c05c59d7afdadd8e7cfc1bf470356938c89)
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

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

224struct cp210x_serial_private {
225#ifdef CONFIG_GPIOLIB
226 struct gpio_chip gc;
227 u8 config;
228 u8 gpio_mode;
229 bool gpio_registered;
230#endif
231 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 *
7 * Support to set flow control line levels using TIOCMGET and TIOCMSET
8 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow

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

224struct cp210x_serial_private {
225#ifdef CONFIG_GPIOLIB
226 struct gpio_chip gc;
227 u8 config;
228 u8 gpio_mode;
229 bool gpio_registered;
230#endif
231 u8 partnum;
232 speed_t max_speed;
232};
233
234struct cp210x_port_private {
235 __u8 bInterfaceNumber;
236 bool has_swapped_line_ctl;
237};
238
239static struct usb_serial_driver cp210x_device = {

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

1047 * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps
1048 * or 1 otherwise.
1049 * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1
1050 * otherwise.
1051 */
1052static void cp210x_change_speed(struct tty_struct *tty,
1053 struct usb_serial_port *port, struct ktermios *old_termios)
1054{
233};
234
235struct cp210x_port_private {
236 __u8 bInterfaceNumber;
237 bool has_swapped_line_ctl;
238};
239
240static struct usb_serial_driver cp210x_device = {

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

1048 * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps
1049 * or 1 otherwise.
1050 * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1
1051 * otherwise.
1052 */
1053static void cp210x_change_speed(struct tty_struct *tty,
1054 struct usb_serial_port *port, struct ktermios *old_termios)
1055{
1056 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial);
1055 u32 baud;
1056
1057 baud = tty->termios.c_ospeed;
1058
1059 /* This maps the requested rate to a rate valid on cp2102 or cp2103,
1057 u32 baud;
1058
1059 baud = tty->termios.c_ospeed;
1060
1061 /* This maps the requested rate to a rate valid on cp2102 or cp2103,
1060 * or to an arbitrary rate in [1M,2M].
1062 * or to an arbitrary rate in [1M, max_speed]
1061 *
1062 * NOTE: B0 is not implemented.
1063 */
1064 if (baud < 1000000)
1065 baud = cp210x_get_an205_rate(baud);
1063 *
1064 * NOTE: B0 is not implemented.
1065 */
1066 if (baud < 1000000)
1067 baud = cp210x_get_an205_rate(baud);
1066 else if (baud > 2000000)
1067 baud = 2000000;
1068 else if (baud > priv->max_speed)
1069 baud = priv->max_speed;
1068
1069 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);
1070 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
1071 dev_warn(&port->dev, "failed to set baud rate to %u\n", baud);
1072 if (old_termios)
1073 baud = old_termios->c_ospeed;
1074 else
1075 baud = 9600;

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

1490 struct cp210x_port_private *port_priv;
1491
1492 port_priv = usb_get_serial_port_data(port);
1493 kfree(port_priv);
1494
1495 return 0;
1496}
1497
1070
1071 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);
1072 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
1073 dev_warn(&port->dev, "failed to set baud rate to %u\n", baud);
1074 if (old_termios)
1075 baud = old_termios->c_ospeed;
1076 else
1077 baud = 9600;

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

1492 struct cp210x_port_private *port_priv;
1493
1494 port_priv = usb_get_serial_port_data(port);
1495 kfree(port_priv);
1496
1497 return 0;
1498}
1499
1500static void cp210x_init_max_speed(struct usb_serial *serial)
1501{
1502 struct cp210x_serial_private *priv = usb_get_serial_data(serial);
1503 speed_t max;
1504
1505 switch (priv->partnum) {
1506 case CP210X_PARTNUM_CP2101:
1507 max = 921600;
1508 break;
1509 case CP210X_PARTNUM_CP2102:
1510 case CP210X_PARTNUM_CP2103:
1511 max = 1000000;
1512 break;
1513 case CP210X_PARTNUM_CP2104:
1514 case CP210X_PARTNUM_CP2108:
1515 max = 2000000;
1516 break;
1517 case CP210X_PARTNUM_CP2105:
1518 if (cp210x_interface_num(serial) == 0)
1519 max = 2000000; /* ECI */
1520 else
1521 max = 921600; /* SCI */
1522 break;
1523 default:
1524 max = 2000000;
1525 break;
1526 }
1527
1528 priv->max_speed = max;
1529}
1530
1498static int cp210x_attach(struct usb_serial *serial)
1499{
1500 int result;
1501 struct cp210x_serial_private *priv;
1502
1503 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1504 if (!priv)
1505 return -ENOMEM;

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

1510 if (result < 0) {
1511 dev_warn(&serial->interface->dev,
1512 "querying part number failed\n");
1513 priv->partnum = CP210X_PARTNUM_UNKNOWN;
1514 }
1515
1516 usb_set_serial_data(serial, priv);
1517
1531static int cp210x_attach(struct usb_serial *serial)
1532{
1533 int result;
1534 struct cp210x_serial_private *priv;
1535
1536 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1537 if (!priv)
1538 return -ENOMEM;

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

1543 if (result < 0) {
1544 dev_warn(&serial->interface->dev,
1545 "querying part number failed\n");
1546 priv->partnum = CP210X_PARTNUM_UNKNOWN;
1547 }
1548
1549 usb_set_serial_data(serial, priv);
1550
1551 cp210x_init_max_speed(serial);
1552
1518 if (priv->partnum == CP210X_PARTNUM_CP2105) {
1519 result = cp2105_shared_gpio_init(serial);
1520 if (result < 0) {
1521 dev_err(&serial->interface->dev,
1522 "GPIO initialisation failed, continuing without GPIO support\n");
1523 }
1524 }
1525

--- 21 unchanged lines hidden ---
1553 if (priv->partnum == CP210X_PARTNUM_CP2105) {
1554 result = cp2105_shared_gpio_init(serial);
1555 if (result < 0) {
1556 dev_err(&serial->interface->dev,
1557 "GPIO initialisation failed, continuing without GPIO support\n");
1558 }
1559 }
1560

--- 21 unchanged lines hidden ---