[PATCH v3 0/2] WK2xxx SPI to UART bridge driver

zjzhao posted 2 patches 3 weeks ago
There is a newer version of this series
.../bindings/serial/wkmic,wk2xxx.yaml         |  115 ++
.../devicetree/bindings/vendor-prefixes.yaml  |    2 +
drivers/tty/serial/Kconfig                    |   17 +
drivers/tty/serial/Makefile                   |    1 +
drivers/tty/serial/wk2xxx.c                   | 1401 +++++++++++++++++
include/uapi/linux/serial_core.h              |    3 +
6 files changed, 1539 insertions(+)
create mode 100644 Documentation/devicetree/bindings/serial/wkmic,wk2xxx.yaml
create mode 100644 drivers/tty/serial/wk2xxx.c
[PATCH v3 0/2] WK2xxx SPI to UART bridge driver
Posted by zjzhao 3 weeks ago
Hi,

This series adds a driver for the WK2xxx SPI-to-UART bridge ICs
(WK2124, WK2132, WK2168, WK2202 and WK2204) by WKmic (Chengdu Weikai
Microelectronics), together with a DT binding and the "wkmic" vendor
prefix.

Why a new driver instead of extending an existing one is briefly
explained below the changelog.

Changes in v3 (addresses the Sashiko AI review on [PATCH v2]):

- probe: register all ports before requesting the threaded IRQ, and
  reset the chip / disable every sub-UART first, so an early interrupt
  can never reach a port whose ->state is not set up yet
- remove: unregister the ports (each open port is shut down, disabling
  its sub-UART) before freeing the IRQ, so no late IRQ or queued worker
  can target a port that is being torn down
- handle_tx: do not return right after sending x_char; pending xmit
  FIFO data is drained and the TX trigger is re-armed below, so it
  cannot be stranded until the next start_tx().  x_char is snapshot
  under the port lock
- polling: the shared poll loop is started/stopped under a per-device
  poll_lock and poll_proc stops re-queuing itself once the last port is
  closed, closing a race that could permanently stop polling
- SPI buffers: spi_tx/spi_rx are cache-line aligned and fifo_read()/
  fifo_write() take reg_lock before touching them
- clock-frequency: a zero value is rejected in probe and calc_divisor()
  guards against a zero baud rate
- set_termios: read_status_mask/ignore_status_mask/status are published
  under the port lock

Items that were reported but intentionally kept as-is, because they
mirror the merged sc16is7xx/max310x drivers:

- handle_tx() reads the transmit kfifo without port->lock: the TX path
  is serialized by tx_lock and the kfifo is single-producer/
  single-consumer between the serial core and this driver, exactly like
  sc16is7xx_handle_tx()
- icount updates in the RX/TX paths are done without port->lock, the
  same as sc16is7xx/max310x and the 8250 receive path

The WK2xxx uses a proprietary register map and a custom SPI protocol
(channel number and a page-select bit are encoded in the SPI command
byte, plus dedicated FIFO burst commands).  It has no modem-control
registers and supports 8 data bits only, so it cannot be folded into the
16550-style sc16is7xx/max310x drivers without degrading a more capable
shared layer.  Following the kernel's own precedent (sc16is7xx and
max310x are separate drivers although sc16is7xx is derived from
max310x), a dedicated driver is the appropriate model.

Tested on Raspberry Pi boards (EDATEC IPC1200 with WK2132 on SPI0 and
SBC2300 with WK2204 on SPI1); loopback TX/RX tests pass.  v3 was
re-verified on SBC2300 (SPI1/WK2204, kernel 6.18.39): all four ports
register and open, multi-port termios churn and repeated module
load/unload cycles are clean.  The RX data path is unchanged since the
loopback runs.

zjzhao (2):
  serial: wk2xxx: Add WK2xxx SPI UART driver
  dt-bindings: serial: Document WK2xxx SPI UART bindings

 .../bindings/serial/wkmic,wk2xxx.yaml         |  115 ++
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 drivers/tty/serial/Kconfig                    |   17 +
 drivers/tty/serial/Makefile                   |    1 +
 drivers/tty/serial/wk2xxx.c                   | 1401 +++++++++++++++++
 include/uapi/linux/serial_core.h              |    3 +
 6 files changed, 1539 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/serial/wkmic,wk2xxx.yaml
 create mode 100644 drivers/tty/serial/wk2xxx.c

-- 
2.43.0