History log of /linux-master/drivers/usb/serial/xr_serial.c
Revision Date Author Comments
# 974e2f6a 08-Jul-2023 Jarkko Sonninen <kasper@iki.fi>

USB: serial: xr: add TIOCGRS485 and TIOCSRS485 ioctls

Exar devices like XR21B1411 can control an RS485 transceiver by
automatically asserting the RTS#/RS485 pin before sending data
and deasserting it when the last stop bit has been transmitted.
The polarity of the RST#/RS485 signal is configurable and the
hardware also supports half-duplex turn-around delay and
address matching mode.

Add support for enabling and disabling RS-485 mode and
configuring the RST#/RS485 signal polarity using the TIOCGRS485
and TIOCSRS485 ioctls. Support for half-duplex turn-around delay
and address matching mode are left unimplemented for now.

User enables RS-485 mode by setting SER_RS485_ENABLED flag in
struct serial_rs485 flags. User should also set either
SER_RS485_RTS_ON_SEND or SER_RS485_RTS_AFTER_SEND to select the
behaviour of the RTS#/RS485 pin. Setting SER_RS485_RTS_ON_SEND
will drive RTS#/RS485 low during transmission.

Signed-off-by: Jarkko Sonninen <kasper@iki.fi>
[ johan: let SER_RS485_RTS_ON_SEND determine SER_RS485_RTS_AFTER_SEND ]
Signed-off-by: Johan Hovold <johan@kernel.org>


# 6ff58ae1 04-Jun-2023 Johan Hovold <johan@kernel.org>

USB: serial: return errors from break handling

Start propagating errors to user space when setting the break state
fails.

This will be used by follow-on changes to also report when a driver or
device does not support break control.

Tested-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Johan Hovold <johan@kernel.org>


# 63b8ed26 29-Nov-2022 Johan Hovold <johan@kernel.org>

USB: serial: xr: avoid requesting zero DTE rate

When the requested line speed is B0 (hangup) there is no need to use the
current speed in the line-coding request. This specifically avoids
requesting a zero DTE rate when the current speed is B0, which could
potentially confuse buggy firmware.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>


# f6d47fe5 16-Aug-2022 Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

usb: serial: Make ->set_termios() old ktermios const

There should be no reason to adjust old ktermios which is going to get
discarded anyway.

Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20220816115739.10928-8-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>


# d801c8d4 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add copyright notice

Add another copyright notice for the work done in 2021.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 06f79d57 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: reset FIFOs on open

Reset the transmit and receive FIFOs before enabling the UARTs as part
of open() in order to flush any stale data.

Note that the XR21V141X needs a type-specific implementation due to its
UART Manager registers.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 6da99f9d 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add support for XR22801, XR22802, XR22804

The XR22801, XR22802 and XR22804 are compound devices with an embedded
hub and up to seven downstream USB devices including one, two or four
UARTs respectively.

The UART function is similar to XR21B142X but most registers are offset
by 0x40, the register requests are different and are directed at the
device rather than interface, and 5 and 6-bit words are not supported.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 4099d4ba 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add support for XR21B1411

The single-port XR21B1411 is similar to the XR21B142X type but uses
12-bit registers and 16-bit register addresses, the register requests
are different and are directed at the device rather than interface, and
5 and 6-bit words are not supported.

The register layout is very similar to XR21B142X except that most
registers are offset by 0xc00 (corresponding to a channel index of 12 in
the MSB of wIndex). As the device is single-port so that the derived
channel index is 0, the current register accessors can be reused after
simply changing the address width.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 607f6718 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add support for XR21B1421, XR21B1422 and XR21B1424

The XR21B1421, XR21B1422 and XR21B1424 are the one-, two- and four-port
models of a second XR21B142X type of the Maxlinear/Exar USB UARTs.

The XR21B142X type differs from XR21V141X in several ways, including:

- register layout
- register width (16-bit instead of 8-bit)
- vendor register requests
- UART enable/disable sequence
- custom-driver mode flag
- three additional GPIOs (9 instead of 6)

As for XR21V141X, the XR21B142X vendor requests encode the channel index
in the MSB of wIndex, but it lacks the UART Manager registers which
have been replaced by regular UART registers. The new type also uses the
interface number of the control interface (0, 2, 4, 6) as channel index
instead of the channel number (0, 1, 2, 3).

The XR21B142X lacks the divisor and format registers used by XR21V141X
and instead uses the CDC SET_LINE_CONTROL request to configure the line
settings.

Note that the currently supported XR21V141X type lacks the custom-driver
mode flag that prevents the device from entering CDC-ACM mode when a CDC
requests is received. This specifically means that the SET_LINE_CONTROL
request cannot be used with XR21V141X even though it is otherwise
supported.

The UART enable sequence for XR21B142X does not involve explicitly
enabling the FIFOs, but according to datasheet the UART must be disabled
when writing any register but GPIO_SET, GPIO_CLEAR, TX_BREAK and
ERROR_STATUS.

Signed-off-by: Johan Hovold <johan@kernel.org>


# f865e614 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add type abstraction

There are at least four types of Maxlinear/Exar USB UARTs which differ
in various ways such as in their register layouts:

XR21V141X
XR21B142X
XR21B1411
XR22804

It is not clear whether the device type can be inferred from the
descriptors so encode it in the device-id table for now.

Add a type structure that can be used to abstract the register layout
and other features, and use it when accessing the XR21V141X UART
registers that are shared by all types.

Note that the currently supported XR21V141X type is the only type that
has a set of UART Manager registers and that these will need to be
handled specifically.

Similarly, XR21V141X is the only type which has the divisor registers
and that needs to use the format register when configuring the line
settings.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 958d6b95 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: drop type prefix from shared defines

In preparation for adding support for further types, drop the type
prefix from defines that are not specific to XR21V141X.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 49036fd0 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: move pin configuration to probe

There's no need to configure the pins on every open and judging from the
vendor driver and datasheet it can be done before enabling the UART.

Move pin configuration from open() to port probe and make sure to
deassert DTR and RTS after configuring all pins as GPIO.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 5f70fe32 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: rename GPIO-pin defines

Rename the GPIO-pin defines so that they reflect how they are used.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 3c369a85 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: rename GPIO-mode defines

Rename the GPIO mode defines so that they reflect the datasheet and how
they are used.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 23b7998e 12-Apr-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: add support for XR21V1412 and XR21V1414

Add support for the two- and four-port variants of XR21V1410.

Use the interface number of each control interface (e.g. 0, 2, 4, 6) to
derive the zero-based channel index:

XR21V1410 0
XR21V1412 0, 1
XR21V1414 0, 1, 2, 3

Note that the UART registers reside in separate blocks per channel,
while the UART Manager functionality is implemented using per-channel
registers.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 5fec21e7 30-Mar-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: claim both interfaces

Use the new multi-interface support in USB serial core to properly claim
also the control interface during probe. This prevents having another
driver claim the control interface and makes core allocate resources
also for the interrupt endpoint (currently unused).

Switch to probing only Communication Class interfaces and use the Union
functional descriptor to determine the corresponding data interface.

Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Johan Hovold <johan@kernel.org>


# ea7ada4d 30-Mar-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix CSIZE handling

The XR21V141X does not have a 5- or 6-bit mode, but the current
implementation failed to properly restore the old setting when CS5 or
CS6 was requested. Instead an invalid request would be sent to the
device.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Cc: stable@vger.kernel.org # 5.12
Signed-off-by: Johan Hovold <johan@kernel.org>


# f164f5d8 26-Feb-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix NULL-deref on disconnect

Claiming the sibling control interface is a bit more involved and
specifically requires adding support to USB-serial core for managing
either interface being unbound first, something which could otherwise
lead to a NULL-pointer dereference.

Similarly, additional infrastructure is also needed to handle suspend
properly.

Since the driver currently isn't actually using the control interface,
we can defer this for now by simply not claiming the control interface.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Reported-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tested-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Manivannan Sadhasivam <mani@kernel.org>
Signed-off-by: Johan Hovold <johan@kernel.org>


# 55317e22 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix B0 handling

Fix up B0 handling which should leave the baud rate unchanged and
specifically not report back a non-B0 rate when B0 is requested; must
temporarily disable hardware flow control so that RTS can be deasserted;
and should reassert DTR/RTS when moving from B0.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>


# 0d05d7d9 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix pin configuration

Make sure that the modem pins are set up correctly when opening the
port to avoid leaving, for example, DTR and RTS configured as inputs,
which is the device default.

This is specifically needed to be able to control DTR and RTS when
hardware flow control is disabled.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>


# 465d3b3a 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix gpio-mode handling

Fix the gpio-mode handling so that all the pins are under driver control
(i.e. in gpio mode) when hardware flow control is disabled.

This is specifically needed to be able to control RTS.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>


# 736c0931 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: simplify line-speed logic

Simplify the changed-line-speed conditional expression.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 35567511 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: clean up line-settings handling

Shift the line-setting values when defining them rather than in
set_termios() for consistency and improved readability.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 72fc7fc7 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: document vendor-request recipient

Add the missing device-recipient define to the vendor control requests
for completeness.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 5c5d9af6 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: use termios flag helpers

Use the termios flag helpers consistently, including for CRTSCTS.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 9ffa6ec5 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: use subsystem usb_device at probe

Use the subsystem struct usb_device pointer at probe instead of
deriving it from the interface pointer.

Signed-off-by: Johan Hovold <johan@kernel.org>


# 54c98d9d 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix interface leak at disconnect

Make sure to release the control interface at disconnect so that the
driver can be unbound without leaking resources (and later rebound).

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>


# a38d2148 21-Jan-2021 Johan Hovold <johan@kernel.org>

USB: serial: xr: fix NULL-deref at probe

Make sure that the probed device has an interface 0 to avoid
dereferencing a NULL pointer in case of a malicious device or during
USB-descriptor fuzzing.

Fixes: c2d405aa86b4 ("USB: serial: add MaxLinear/Exar USB to Serial driver")
Signed-off-by: Johan Hovold <johan@kernel.org>


# c2d405aa 22-Nov-2020 Manivannan Sadhasivam <mani@kernel.org>

USB: serial: add MaxLinear/Exar USB to Serial driver

Add support for MaxLinear/Exar USB to Serial converters. This driver
only supports XR21V141X series but it can be extended to other series
from Exar as well in future.

This driver is inspired from the initial one submitted by Patong Yang:

https://lore.kernel.org/r/20180404070634.nhspvmxcjwfgjkcv@advantechmxl-desktop

While the initial driver was a custom tty USB driver exposing whole
new serial interface ttyXRUSBn, this version is completely based on USB
serial core thus exposing the interfaces as ttyUSBn. This will avoid
the overhead of exposing a new USB serial interface which the userspace
tools are unaware of.

The Exar XR21V141X can be used in either ACM mode using the cdc-acm
driver or in "custom driver" mode in which further features such as
hardware and software flow control, GPIO control and in-band line-status
reporting are available.

In ACM mode the device always enables RTS/CTS flow control, something
which could prevent transmission in case the CTS input isn't wired up
corrently.

A follow-on patch will prevent cdc_acm from binding whenever this driver
is enabled.

Signed-off-by: Manivannan Sadhasivam <mani@kernel.org>
Link: https://lore.kernel.org/r/20201122170822.21715-2-mani@kernel.org
[ johan: fix some style nits, group related functions, drop unused
callbacks, and amend commit message; a few remaining
non-trivial issues will be fixed separately ]
Signed-off-by: Johan Hovold <johan@kernel.org>