cp210x.c (d4706c05c59d7afdadd8e7cfc1bf470356938c89) | cp210x.c (6f0bcf720ea81e90e6066d14d5506565049a2eb5) |
---|---|
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 --- 341 unchanged lines hidden (view full) --- 350 351/* Part number definitions */ 352#define CP210X_PARTNUM_CP2101 0x01 353#define CP210X_PARTNUM_CP2102 0x02 354#define CP210X_PARTNUM_CP2103 0x03 355#define CP210X_PARTNUM_CP2104 0x04 356#define CP210X_PARTNUM_CP2105 0x05 357#define CP210X_PARTNUM_CP2108 0x08 | 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 --- 341 unchanged lines hidden (view full) --- 350 351/* Part number definitions */ 352#define CP210X_PARTNUM_CP2101 0x01 353#define CP210X_PARTNUM_CP2102 0x02 354#define CP210X_PARTNUM_CP2103 0x03 355#define CP210X_PARTNUM_CP2104 0x04 356#define CP210X_PARTNUM_CP2105 0x05 357#define CP210X_PARTNUM_CP2108 0x08 |
358#define CP210X_PARTNUM_CP2102N_QFN28 0x20 359#define CP210X_PARTNUM_CP2102N_QFN24 0x21 360#define CP210X_PARTNUM_CP2102N_QFN20 0x22 |
|
358#define CP210X_PARTNUM_UNKNOWN 0xFF 359 360/* CP210X_GET_COMM_STATUS returns these 0x13 bytes */ 361struct cp210x_comm_status { 362 __le32 ulErrors; 363 __le32 ulHoldReasons; 364 __le32 ulAmountInInQueue; 365 __le32 ulAmountInOutQueue; --- 83 unchanged lines hidden (view full) --- 449#define CP2105_GPIO1_RS485_MODE BIT(2) 450 451/* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */ 452struct cp210x_gpio_write { 453 u8 mask; 454 u8 state; 455} __packed; 456 | 361#define CP210X_PARTNUM_UNKNOWN 0xFF 362 363/* CP210X_GET_COMM_STATUS returns these 0x13 bytes */ 364struct cp210x_comm_status { 365 __le32 ulErrors; 366 __le32 ulHoldReasons; 367 __le32 ulAmountInInQueue; 368 __le32 ulAmountInOutQueue; --- 83 unchanged lines hidden (view full) --- 452#define CP2105_GPIO1_RS485_MODE BIT(2) 453 454/* CP210X_VENDOR_SPECIFIC, CP210X_WRITE_LATCH call writes these 0x2 bytes. */ 455struct cp210x_gpio_write { 456 u8 mask; 457 u8 state; 458} __packed; 459 |
460static bool cp210x_is_cp2102n(struct usb_serial *serial) 461{ 462 struct cp210x_serial_private *priv = usb_get_serial_data(serial); 463 464 return (priv->partnum == CP210X_PARTNUM_CP2102N_QFN28) || 465 (priv->partnum == CP210X_PARTNUM_CP2102N_QFN24) || 466 (priv->partnum == CP210X_PARTNUM_CP2102N_QFN20); 467} 468 |
|
457/* 458 * Helper to get interface number when we only have struct usb_serial. 459 */ 460static u8 cp210x_interface_num(struct usb_serial *serial) 461{ 462 struct usb_host_interface *cur_altsetting; 463 464 cur_altsetting = serial->interface->cur_altsetting; --- 583 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{ | 469/* 470 * Helper to get interface number when we only have struct usb_serial. 471 */ 472static u8 cp210x_interface_num(struct usb_serial *serial) 473{ 474 struct usb_host_interface *cur_altsetting; 475 476 cur_altsetting = serial->interface->cur_altsetting; --- 583 unchanged lines hidden (view full) --- 1060 * For CP2104 and CP2105 freq is 48Mhz and prescale is 4 for request <= 365bps 1061 * or 1 otherwise. 1062 * For CP2110 freq is 24Mhz and prescale is 4 for request <= 300bps or 1 1063 * otherwise. 1064 */ 1065static void cp210x_change_speed(struct tty_struct *tty, 1066 struct usb_serial_port *port, struct ktermios *old_termios) 1067{ |
1056 struct cp210x_serial_private *priv = usb_get_serial_data(port->serial); | 1068 struct usb_serial *serial = port->serial; 1069 struct cp210x_serial_private *priv = usb_get_serial_data(serial); |
1057 u32 baud; 1058 1059 baud = tty->termios.c_ospeed; 1060 | 1070 u32 baud; 1071 1072 baud = tty->termios.c_ospeed; 1073 |
1061 /* This maps the requested rate to a rate valid on cp2102 or cp2103, 1062 * or to an arbitrary rate in [1M, max_speed] | 1074 /* 1075 * This maps the requested rate to the actual rate on cp2102n, a valid 1076 * rate on cp2102 or cp2103, or to an arbitrary rate in 1077 * [1M, max_speed]. |
1063 * 1064 * NOTE: B0 is not implemented. 1065 */ | 1078 * 1079 * NOTE: B0 is not implemented. 1080 */ |
1066 if (baud < 1000000) | 1081 if (cp210x_is_cp2102n(serial)) { 1082 int clk_div; 1083 int prescaler; 1084 1085 baud = clamp(baud, 300u, priv->max_speed); 1086 prescaler = (baud <= 365) ? 4 : 1; 1087 clk_div = DIV_ROUND_CLOSEST(48000000, 2 * prescaler * baud); 1088 baud = 48000000 / (2 * prescaler * clk_div); 1089 } else if (baud < 1000000) { |
1067 baud = cp210x_get_an205_rate(baud); | 1090 baud = cp210x_get_an205_rate(baud); |
1068 else if (baud > priv->max_speed) | 1091 } else if (baud > priv->max_speed) { |
1069 baud = priv->max_speed; | 1092 baud = priv->max_speed; |
1093 } |
|
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; --- 437 unchanged lines hidden (view full) --- 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; | 1094 1095 dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud); 1096 if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) { 1097 dev_warn(&port->dev, "failed to set baud rate to %u\n", baud); 1098 if (old_termios) 1099 baud = old_termios->c_ospeed; 1100 else 1101 baud = 9600; --- 437 unchanged lines hidden (view full) --- 1539 max = 2000000; 1540 break; 1541 case CP210X_PARTNUM_CP2105: 1542 if (cp210x_interface_num(serial) == 0) 1543 max = 2000000; /* ECI */ 1544 else 1545 max = 921600; /* SCI */ 1546 break; |
1547 case CP210X_PARTNUM_CP2102N_QFN28: 1548 case CP210X_PARTNUM_CP2102N_QFN24: 1549 case CP210X_PARTNUM_CP2102N_QFN20: 1550 max = 3000000; 1551 break; |
|
1523 default: 1524 max = 2000000; 1525 break; 1526 } 1527 1528 priv->max_speed = max; 1529} 1530 --- 51 unchanged lines hidden --- | 1552 default: 1553 max = 2000000; 1554 break; 1555 } 1556 1557 priv->max_speed = max; 1558} 1559 --- 51 unchanged lines hidden --- |