Skip to contentSkip to conversation

serial: add KEBA UART driver

PATCH In review Gerhard Engleder 4 participants 16 messages Oct 23, 2025 – Nov 27, 2025 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

v4 cover serial: add KEBA UART driver

First the serial subsystem is prepared to keep rs485 settings from the driver if no firmware node exists. This enables drivers to configure a default rs485 mode, which is set by the serial subsystem.

Second the driver for the KEBA UART is added. This driver supports multiple rs485 modes and selects RS485 as default mode. This UART is found in KEBA PLC devices. The auxiliary devices for this driver are created by the cp500 driver.

v4:
- fix spelling, exist -> exists (Lukas Wunner)
- remove duplicate include (Lukas Wunner)
- order includes alphabetically (Lukas Wunner)

v3:
- add info to commit why device tree / ACPI is not possible (Lukas Wunner)
- separate if and comment for change in uart_get_rs485_mode() (Lukas Wunner)

v2:
- use BIT() for flag definition (Jiri Slaby)
- use enum for UART mode definition (Jiri Slaby)
- use BIT() for capability flag definition (Jiri Slaby)
- use GENMASK() for capability mask (Jiri Slaby)
- use unsigned int for serial line number (Jiri Slaby)
- use unsigned int for flags (Jiri Slaby)

Gerhard Engleder (2):
serial: Keep rs485 settings for devices without firmware node
serial: 8250: add driver for KEBA UART

 drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig     |  13 ++
 drivers/tty/serial/8250/Makefile    |   1 +
 drivers/tty/serial/serial_core.c    |   8 +
 4 files changed, 302 insertions(+)
 create mode 100644 drivers/tty/serial/8250/8250_keba.c
Signature · 1 line
2.39.5
#1 lore raw

PATCH v4 1/2 serial: Keep rs485 settings for devices without firmware node

From: Gerhard Engleder <[email protected]>

Commit fe7f0fa43cef ("serial: 8250: Support rs485 devicetree properties") retrieves rs485 properties for 8250 drivers. These properties are read from the firmware node of the device within uart_get_rs485_mode(). If the firmware node does not exist, then the rs485 flags are still reset. Thus, 8250 driver cannot set rs485 flags to enable a defined rs485 mode during driver loading. This is no problem so far, as no 8250 driver sets the rs485 flags.

The default rs485 mode can also be set by firmware nodes. But for some devices a firmware node does not exist. E.g., for a PCIe based serial interface on x86 no device tree is available and the ACPI information of the BIOS often cannot by modified. In this case it shall be possible, that a driver works out of the box by setting a reasonable default rs485 mode.

If no firmware node exists, then it should be possible for the driver to set a reasonable default rs485 mode. Therefore, reset rs485 flags only if a firmware node exists.

---
 drivers/tty/serial/serial_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/tty/serial/serial_core.c +8 -0
index 4757293ece8c..70cac77cac61 100644
@@ -3536,6 +3536,14 @@ int uart_get_rs485_mode(struct uart_port *port)
 	if (!(port->rs485_supported.flags & SER_RS485_ENABLED))
 		return 0;
 
+	/*
+	 * Retrieve properties only if a firmware node exists. If no firmware
+	 * node exists, then don't touch rs485 config and keep initial rs485
+	 * properties set by driver.
+	 */
+	if (!dev_fwnode(dev))
+		return 0;
+
 	ret = device_property_read_u32_array(dev, "rs485-rts-delay",
 					     rs485_delay, 2);
 	if (!ret) {
Signature · 1 line
2.39.5
Reviewed-by on v4 1/2
#2 lore raw

Re: [PATCH v4 1/2] serial: Keep rs485 settings for devices without firmware node

Quoted 15 lines · Gerhard Engleder

Commit fe7f0fa43cef ("serial: 8250: Support rs485 devicetree properties") retrieves rs485 properties for 8250 drivers. These properties are read from the firmware node of the device within uart_get_rs485_mode(). If the firmware node does not exist, then the rs485 flags are still reset. Thus, 8250 driver cannot set rs485 flags to enable a defined rs485 mode during driver loading. This is no problem so far, as no 8250 driver sets the rs485 flags.

The default rs485 mode can also be set by firmware nodes. But for some devices a firmware node does not exist. E.g., for a PCIe based serial interface on x86 no device tree is available and the ACPI information of the BIOS often cannot by modified. In this case it shall be possible, that a driver works out of the box by setting a reasonable default rs485 mode.

Quoted 5 lines

If no firmware node exists, then it should be possible for the driver to set a reasonable default rs485 mode. Therefore, reset rs485 flags only if a firmware node exists.

#3 lore raw

Re: [PATCH v4 1/2] serial: Keep rs485 settings for devices without firmware node

In reply to Gerhard Engleder
Quoted 9 lines · Gerhard Engleder

Commit fe7f0fa43cef ("serial: 8250: Support rs485 devicetree properties") retrieves rs485 properties for 8250 drivers. These properties are read from the firmware node of the device within uart_get_rs485_mode(). If the firmware node does not exist, then the rs485 flags are still reset. Thus, 8250 driver cannot set rs485 flags to enable a defined rs485 mode during driver loading. This is no problem so far, as no 8250 driver sets the rs485 flags.

Quoted 4 lines

The default rs485 mode can also be set by firmware nodes. But for some devices a firmware node does not exist. E.g., for a PCIe based serial interface on x86 no device tree is available and the ACPI information of the BIOS often cannot by modified.

While the code is okay per se, the above statement is not fully true. We specifically have device properties and software nodes to provide the missing bits.

Quoted 7 lines

In this case it shall be possible,
that a driver works out of the box by setting a reasonable default rs485 mode.

If no firmware node exists, then it should be possible for the driver to set a reasonable default rs485 mode. Therefore, reset rs485 flags only if a firmware node exists.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH v4 1/2] serial: Keep rs485 settings for devices without firmware node

Quoted 10 lines · Andy Shevchenko
Quoted 9 lines · Gerhard Engleder

Commit fe7f0fa43cef ("serial: 8250: Support rs485 devicetree properties") retrieves rs485 properties for 8250 drivers. These properties are read from the firmware node of the device within uart_get_rs485_mode(). If the firmware node does not exist, then the rs485 flags are still reset. Thus, 8250 driver cannot set rs485 flags to enable a defined rs485 mode during driver loading. This is no problem so far, as no 8250 driver sets the rs485 flags.

Quoted 8 lines
Quoted 4 lines

The default rs485 mode can also be set by firmware nodes. But for some devices a firmware node does not exist. E.g., for a PCIe based serial interface on x86 no device tree is available and the ACPI information of the BIOS often cannot by modified.

While the code is okay per se, the above statement is not fully true. We specifically have device properties and software nodes to provide the missing bits.

Yes, Lukas Wunner teached me that possibility. I did not mention this alternative solution in the commit, because I did not use it.

Gerhard

#5 lore raw

PATCH v4 2/2 serial: 8250: add driver for KEBA UART

In reply to Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

---
 drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig     |  13 ++
 drivers/tty/serial/8250/Makefile    |   1 +
 3 files changed, 294 insertions(+)
 create mode 100644 drivers/tty/serial/8250/8250_keba.c
drivers/tty/serial/8250/8250_keba.c new file +280 -0
new file mode 100644
index 000000000000..c05b89551b12
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 KEBA Industrial Automation GmbH
+ *
+ * Driver for KEBA UART FPGA IP core
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/misc/keba.h>
+#include <linux/module.h>
+
+#include "8250.h"
+
+#define KUART "kuart"
+
+/* flags */
+#define KUART_RS485		BIT(0)
+#define KUART_USE_CAPABILITY	BIT(1)
+
+/* registers */
+#define KUART_VERSION		0x0000
+#define KUART_REVISION		0x0001
+#define KUART_CAPABILITY	0x0002
+#define KUART_CONTROL		0x0004
+#define KUART_BASE		0x000C
+#define KUART_REGSHIFT		2
+#define KUART_CLK		1843200
+
+/* mode flags */
+enum kuart_mode {
+	KUART_MODE_NONE = 0,
+	KUART_MODE_RS485,
+	KUART_MODE_RS422,
+	KUART_MODE_RS232
+};
+
+/* capability flags */
+#define KUART_CAPABILITY_NONE	BIT(KUART_MODE_NONE)
+#define KUART_CAPABILITY_RS485	BIT(KUART_MODE_RS485)
+#define KUART_CAPABILITY_RS422	BIT(KUART_MODE_RS422)
+#define KUART_CAPABILITY_RS232	BIT(KUART_MODE_RS232)
+#define KUART_CAPABILITY_MASK	GENMASK(3, 0)
+
+/* Additional Control Register DTR line configuration */
+#define UART_ACR_DTRLC_MASK		0x18
+#define UART_ACR_DTRLC_COMPAT		0x00
+#define UART_ACR_DTRLC_ENABLE_LOW	0x10
+
+struct kuart {
+	struct keba_uart_auxdev *auxdev;
+	void __iomem *base;
+	unsigned int line;
+
+	unsigned int flags;
+	u8 capability;
+	enum kuart_mode mode;
+};
+
+static void kuart_set_phy_mode(struct kuart *kuart, enum kuart_mode mode)
+{
+	iowrite8(mode, kuart->base + KUART_CONTROL);
+}
+
+static void kuart_enhanced_mode(struct uart_8250_port *up, bool enable)
+{
+	u8 lcr, efr;
+
+	/* backup LCR register */
+	lcr = serial_in(up, UART_LCR);
+
+	/* enable 650 compatible register set (EFR, ...) */
+	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
+
+	/* enable/disable enhanced mode with indexed control registers */
+	efr = serial_in(up, UART_EFR);
+	if (enable)
+		efr |= UART_EFR_ECB;
+	else
+		efr &= ~UART_EFR_ECB;
+	serial_out(up, UART_EFR, efr);
+
+	/* disable 650 compatible register set, restore LCR */
+	serial_out(up, UART_LCR, lcr);
+}
+
+static void kuart_dtr_line_config(struct uart_8250_port *up, u8 dtrlc)
+{
+	u8 acr;
+
+	/* set index register to 0 to access ACR register */
+	serial_out(up, UART_SCR, UART_ACR);
+
+	/* set value register to 0x10 writing DTR mode (1,0) */
+	acr = serial_in(up, UART_LSR);
+	acr &= ~UART_ACR_DTRLC_MASK;
+	acr |= dtrlc;
+	serial_out(up, UART_LSR, acr);
+}
+
+static int kuart_rs485_config(struct uart_port *port, struct ktermios *termios,
+			      struct serial_rs485 *rs485)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	struct kuart *kuart = port->private_data;
+	enum kuart_mode mode;
+	u8 dtrlc;
+
+	if (rs485->flags & SER_RS485_ENABLED) {
+		if (rs485->flags & SER_RS485_MODE_RS422)
+			mode = KUART_MODE_RS422;
+		else
+			mode = KUART_MODE_RS485;
+	} else {
+		mode = KUART_MODE_RS232;
+	}
+
+	if (mode == kuart->mode)
+		return 0;
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* deactivate physical interface, break before make */
+		kuart_set_phy_mode(kuart, KUART_MODE_NONE);
+	}
+
+	if (mode == KUART_MODE_RS485) {
+		/*
+		 * Set DTR line configuration of 95x UART to DTR mode (1,0).
+		 * In this mode the DTR pin drives the active-low enable pin of
+		 * an external RS485 buffer. The DTR pin will be forced low
+		 * whenever the transmitter is not empty, otherwise DTR pin is
+		 * high.
+		 */
+		dtrlc = UART_ACR_DTRLC_ENABLE_LOW;
+	} else {
+		/*
+		 * Set DTR line configuration of 95x UART to DTR mode (0,0).
+		 * In this mode the DTR pin is compatible with 16C450, 16C550,
+		 * 16C650 and 16c670 (i.e. normal).
+		 */
+		dtrlc = UART_ACR_DTRLC_COMPAT;
+	}
+
+	kuart_enhanced_mode(up, true);
+	kuart_dtr_line_config(up, dtrlc);
+	kuart_enhanced_mode(up, false);
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* activate selected physical interface */
+		kuart_set_phy_mode(kuart, mode);
+	}
+
+	kuart->mode = mode;
+
+	return 0;
+}
+
+static int kuart_probe(struct auxiliary_device *auxdev,
+		       const struct auxiliary_device_id *id)
+{
+	struct device *dev = &auxdev->dev;
+	struct uart_8250_port uart = {};
+	struct resource res;
+	struct kuart *kuart;
+	int retval;
+
+	kuart = devm_kzalloc(dev, sizeof(*kuart), GFP_KERNEL);
+	if (!kuart)
+		return -ENOMEM;
+	kuart->auxdev = container_of(auxdev, struct keba_uart_auxdev, auxdev);
+	kuart->flags = id->driver_data;
+	auxiliary_set_drvdata(auxdev, kuart);
+
+	/*
+	 * map only memory in front of UART registers, UART registers will be
+	 * mapped by serial port
+	 */
+	res = kuart->auxdev->io;
+	res.end = res.start + KUART_BASE - 1;
+	kuart->base = devm_ioremap_resource(dev, &res);
+	if (IS_ERR(kuart->base))
+		return PTR_ERR(kuart->base);
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/*
+		 * supported modes are read from capability register, at least
+		 * one mode other than none must be supported
+		 */
+		kuart->capability = ioread8(kuart->base + KUART_CAPABILITY) &
+				    KUART_CAPABILITY_MASK;
+		if ((kuart->capability & ~KUART_CAPABILITY_NONE) == 0)
+			return -EIO;
+	}
+
+	spin_lock_init(&uart.port.lock);
+	uart.port.dev = dev;
+	uart.port.mapbase = kuart->auxdev->io.start + KUART_BASE;
+	uart.port.irq = kuart->auxdev->irq;
+	uart.port.uartclk = KUART_CLK;
+	uart.port.private_data = kuart;
+
+	/* 8 bit registers are 32 bit aligned => shift register offset */
+	uart.port.iotype = UPIO_MEM32;
+	uart.port.regshift = KUART_REGSHIFT;
+
+	/*
+	 * UART mixes 16550, 16750 and 16C950 (for RS485) standard => auto
+	 * configuration works best
+	 */
+	uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_IOREMAP;
+
+	/*
+	 * UART supports RS485, RS422 and RS232 with switching of physical
+	 * interface
+	 */
+	uart.port.rs485_config = kuart_rs485_config;
+	if (kuart->flags & KUART_RS485) {
+		uart.port.rs485_supported.flags = SER_RS485_ENABLED |
+						  SER_RS485_RTS_ON_SEND;
+		uart.port.rs485.flags = SER_RS485_ENABLED |
+					SER_RS485_RTS_ON_SEND;
+	}
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* default mode priority is RS485 > RS422 > RS232 */
+		if (kuart->capability & KUART_CAPABILITY_RS422) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND |
+							   SER_RS485_MODE_RS422;
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND |
+						SER_RS485_MODE_RS422;
+		}
+		if (kuart->capability & KUART_CAPABILITY_RS485) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND;
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND;
+		}
+	}
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
+		dev_err(&auxdev->dev, "UART registration failed!\n");
+		return retval;
+	}
+	kuart->line = retval;
+
+	return 0;
+}
+
+static void kuart_remove(struct auxiliary_device *auxdev)
+{
+	struct kuart *kuart = auxiliary_get_drvdata(auxdev);
+
+	if (kuart->flags & KUART_USE_CAPABILITY)
+		kuart_set_phy_mode(kuart, KUART_MODE_NONE);
+
+	serial8250_unregister_port(kuart->line);
+}
+
+static const struct auxiliary_device_id kuart_devtype_aux[] = {
+	{ .name = "keba.rs485-uart", .driver_data = KUART_RS485 },
+	{ .name = "keba.rs232-uart", .driver_data = 0 },
+	{ .name = "keba.uart", .driver_data = KUART_USE_CAPABILITY },
+	{}
+};
+MODULE_DEVICE_TABLE(auxiliary, kuart_devtype_aux);
+
+static struct auxiliary_driver kuart_driver_aux = {
+	.name = KUART,
+	.id_table = kuart_devtype_aux,
+	.probe  = kuart_probe,
+	.remove = kuart_remove,
+};
+module_auxiliary_driver(kuart_driver_aux);
+
+MODULE_AUTHOR("Gerhard Engleder <[email protected]>");
+MODULE_DESCRIPTION("KEBA 8250 serial port driver");
+MODULE_LICENSE("GPL");
drivers/tty/serial/8250/Kconfig +13 -0
index f64ef0819cd4..5c3e4bcb3b93 100644
@@ -430,6 +430,19 @@ config SERIAL_8250_IOC3
 	  behind the IOC3 device on those systems.  Maximum baud speed is
 	  38400bps using this driver.
 
+config SERIAL_8250_KEBA
+	tristate "Support for KEBA 8250 UART"
+	depends on SERIAL_8250
+	depends on KEBA_CP500
+	help
+	  Selecting this option will add support for KEBA UARTs. These UARTs
+	  are used for the serial interfaces of KEBA PLCs.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called 8250_keba.
+
+	  If unsure, say N.
+
 config SERIAL_8250_RT288X
 	bool "Ralink RT288x/RT305x/RT3662/RT3883 serial port support"
 	depends on SERIAL_8250
drivers/tty/serial/8250/Makefile +1 -0
index 513a0941c284..f7a463c9860a 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_SERIAL_8250_HP300)		+= 8250_hp300.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
 obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_IOC3)		+= 8250_ioc3.o
+obj-$(CONFIG_SERIAL_8250_KEBA)		+= 8250_keba.o
 obj-$(CONFIG_SERIAL_8250_LPC18XX)	+= 8250_lpc18xx.o
 obj-$(CONFIG_SERIAL_8250_LPSS)		+= 8250_lpss.o
 obj-$(CONFIG_SERIAL_8250_MEN_MCB)	+= 8250_men_mcb.o
Signature · 1 line
2.39.5
Reviewed-by on v4 2/2
#6 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 10 lines · Gerhard Engleder

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

Quoted 2 lines
#7 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

In reply to Gerhard Engleder
Quoted 10 lines · Gerhard Engleder

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

...

Quoted 1 line

+#include <linux/auxiliary_bus.h>

+ bits.h
+ container_of.h

Quoted 1 line

+#include <linux/device.h>

I don't see how it's being used.
What I see are

+ dev_printk.h
+ device/devres.h

+ err.h

drivers/tty/serial/8250/8250_keba.c line 11

Quoted 2 lines
drivers/tty/serial/8250/8250_keba.c new file +2 -0
+#include <linux/io.h>
+#include <linux/misc/keba.h>

+ mod_devicetable.h

Quoted 1 line

+#include <linux/module.h>

+ spinlock.h
+ types.h

...

Quoted 37 lines
drivers/tty/serial/8250/8250_keba.c new file +37 -0
+static int kuart_probe(struct auxiliary_device *auxdev,
+		       const struct auxiliary_device_id *id)
+{
+	struct device *dev = &auxdev->dev;
+	struct uart_8250_port uart = {};
+	struct resource res;
+	struct kuart *kuart;
+	int retval;
+
+	kuart = devm_kzalloc(dev, sizeof(*kuart), GFP_KERNEL);
+	if (!kuart)
+		return -ENOMEM;
+	kuart->auxdev = container_of(auxdev, struct keba_uart_auxdev, auxdev);
+	kuart->flags = id->driver_data;
+	auxiliary_set_drvdata(auxdev, kuart);
+
+	/*
+	 * map only memory in front of UART registers, UART registers will be
+	 * mapped by serial port
+	 */
+	res = kuart->auxdev->io;
+	res.end = res.start + KUART_BASE - 1;
+	kuart->base = devm_ioremap_resource(dev, &res);
+	if (IS_ERR(kuart->base))
+		return PTR_ERR(kuart->base);
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/*
+		 * supported modes are read from capability register, at least
+		 * one mode other than none must be supported
+		 */
+		kuart->capability = ioread8(kuart->base + KUART_CAPABILITY) &
+				    KUART_CAPABILITY_MASK;
+		if ((kuart->capability & ~KUART_CAPABILITY_NONE) == 0)
+			return -EIO;
+	}
+

drivers/tty/serial/8250/8250_keba.c line 205

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+	spin_lock_init(&uart.port.lock);
+	uart.port.dev = dev;
+	uart.port.mapbase = kuart->auxdev->io.start + KUART_BASE;
+	uart.port.irq = kuart->auxdev->irq;
+	uart.port.uartclk = KUART_CLK;
+	uart.port.private_data = kuart;
+
+	/* 8 bit registers are 32 bit aligned => shift register offset */
+	uart.port.iotype = UPIO_MEM32;
+	uart.port.regshift = KUART_REGSHIFT;

Can't you call uart_read_port_properties()?

If ever you gain some properties either via FW description or via software nodes, they will be automatically used without need to update the driver!

Quoted 30 lines
drivers/tty/serial/8250/8250_keba.c new file +30 -0
+	/*
+	 * UART mixes 16550, 16750 and 16C950 (for RS485) standard => auto
+	 * configuration works best
+	 */
+	uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_IOREMAP;
+
+	/*
+	 * UART supports RS485, RS422 and RS232 with switching of physical
+	 * interface
+	 */
+	uart.port.rs485_config = kuart_rs485_config;
+	if (kuart->flags & KUART_RS485) {
+		uart.port.rs485_supported.flags = SER_RS485_ENABLED |
+						  SER_RS485_RTS_ON_SEND;
+		uart.port.rs485.flags = SER_RS485_ENABLED |
+					SER_RS485_RTS_ON_SEND;
+	}
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* default mode priority is RS485 > RS422 > RS232 */
+		if (kuart->capability & KUART_CAPABILITY_RS422) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND |
+							   SER_RS485_MODE_RS422;
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND |
+						SER_RS485_MODE_RS422;
+		}
+		if (kuart->capability & KUART_CAPABILITY_RS485) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND;

drivers/tty/serial/8250/8250_keba.c line 245

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +9 -0
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND;
+		}
+	}
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
 
+		dev_err(&auxdev->dev, "UART registration failed!\n");
+		return retval;
		return dev_err_probe(...);

drivers/tty/serial/8250/8250_keba.c line 250

Quoted 5 lines
drivers/tty/serial/8250/8250_keba.c new file +5 -0
+	}
+	kuart->line = retval;
+
+	return 0;
+}

...

Since driver is about to be applied to serial-next, I suggest to send a followup(s) to address my comments.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#8 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 34 lines · Andy Shevchenko
Quoted 10 lines · Gerhard Engleder

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

...

Quoted 1 line

+#include <linux/auxiliary_bus.h>

+ bits.h
+ container_of.h

Quoted 1 line

+#include <linux/device.h>

I don't see how it's being used.
What I see are

+ dev_printk.h
+ device/devres.h

+ err.h

drivers/tty/serial/8250/8250_keba.c line 11

Quoted 2 lines
drivers/tty/serial/8250/8250_keba.c new file +2 -0
+#include <linux/io.h>
+#include <linux/misc/keba.h>

+ mod_devicetable.h

Quoted 4 lines
Quoted 1 line

+#include <linux/module.h>

+ spinlock.h
+ types.h

Is there any extra tool to check for missing headers? Or do I have to check the header for every used function?

Quoted 3 lines
Quoted 3 lines
drivers/tty/serial/8250/8250_keba.c new file +3 -0
+static int kuart_probe(struct auxiliary_device *auxdev,
+		       const struct auxiliary_device_id *id)
+{

...

Quoted 13 lines

drivers/tty/serial/8250/8250_keba.c line 205

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+	spin_lock_init(&uart.port.lock);
+	uart.port.dev = dev;
+	uart.port.mapbase = kuart->auxdev->io.start + KUART_BASE;
+	uart.port.irq = kuart->auxdev->irq;
+	uart.port.uartclk = KUART_CLK;
+	uart.port.private_data = kuart;
+
+	/* 8 bit registers are 32 bit aligned => shift register offset */
+	uart.port.iotype = UPIO_MEM32;
+	uart.port.regshift = KUART_REGSHIFT;

Can't you call uart_read_port_properties()?

Quoted 2 lines

If ever you gain some properties either via FW description or via software nodes, they will be automatically used without need to update the driver!

Yes that would be some nice behavior. But __uart_read_properties() sets some defaults even if no firmware node exist (UPF_SHARE_IRQ, 0 as irq number or it fails if not irq number is found). So __uart_read_properties() would need to be changed. IMO it makes no sense to change __uart_read_properties() as this functionality is currently not required.

Quoted 4 lines
Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +3 -0
+	/*
+	 * UART mixes 16550, 16750 and 16C950 (for RS485) standard => auto
+	 * configuration works best

...

Quoted 9 lines

drivers/tty/serial/8250/8250_keba.c line 245

Quoted 7 lines
drivers/tty/serial/8250/8250_keba.c new file +6 -0
+	}
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
 
+		dev_err(&auxdev->dev, "UART registration failed!\n");
+		return retval;
		return dev_err_probe(...);

Yes that's simpler.

Quoted 11 lines

drivers/tty/serial/8250/8250_keba.c line 250

Quoted 6 lines
drivers/tty/serial/8250/8250_keba.c new file +5 -0
+	}
+	kuart->line = retval;
+
+	return 0;
+}

...

Since driver is about to be applied to serial-next, I suggest to send a followup(s) to address my comments.

I will do a follow up.

Gerhard

#9 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 2 lines · Gerhard Engleder
Quoted 1 line · Andy Shevchenko

On Thu, Oct 23, 2025 at 05:12:29PM +0200, Gerhard Engleder wrote:

...

Quoted 20 lines
Quoted 20 lines
Quoted 1 line

+#include <linux/auxiliary_bus.h>

+ bits.h
+ container_of.h

Quoted 1 line

+#include <linux/device.h>

I don't see how it's being used.
What I see are

+ dev_printk.h
+ device/devres.h

+ err.h

drivers/tty/serial/8250/8250_keba.c line 11

Quoted 2 lines
drivers/tty/serial/8250/8250_keba.c new file +2 -0
+#include <linux/io.h>
+#include <linux/misc/keba.h>

+ mod_devicetable.h

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+#include <linux/module.h>

+ spinlock.h
+ types.h

Is there any extra tool to check for missing headers? Or do I have to check the header for every used function?

There is iwyu, which is heavily tweaked by Jonathan Cameron for use in Linux kernel and even though it gives some false positives.

I did this manually by reading the code of the driver and remembering which header provides which API.

...

Quoted 7 lines
Quoted 4 lines

Can't you call uart_read_port_properties()?

If ever you gain some properties either via FW description or via software nodes, they will be automatically used without need to update the driver!

Yes that would be some nice behavior. But __uart_read_properties() sets some defaults even if no firmware node exist (UPF_SHARE_IRQ,

Is it a problem? Even a single IRQ may be marked shared.

Quoted 1 line

0 as irq number

It doesn't do that, it just skips setting it in that case.

Quoted 1 line

or it fails if not irq number is found).

Yeah, this is most "problematic" part in case of this driver. Why is it auxiliary and not platform? With that the __uart_read_properties() needs to be updated to also query IRQ from respective aux device, and aux dev needs implementation of dev_is_auxiliary(). Not that big deal, though.

Quoted 3 lines

So __uart_read_properties() would need to be changed. IMO it makes no sense to change __uart_read_properties() as this functionality is currently not required.

Yes, but as I said it will give you for free the possibility to use those properties without future modifications of the driver. OTOH, driver is in tree and modifications will be needed one way or another :-)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#10 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 54 lines · Andy Shevchenko
Quoted 2 lines · Gerhard Engleder
Quoted 1 line · Andy Shevchenko

On Thu, Oct 23, 2025 at 05:12:29PM +0200, Gerhard Engleder wrote:

...

Quoted 20 lines
Quoted 20 lines
Quoted 1 line

+#include <linux/auxiliary_bus.h>

+ bits.h
+ container_of.h

Quoted 1 line

+#include <linux/device.h>

I don't see how it's being used.
What I see are

+ dev_printk.h
+ device/devres.h

+ err.h

drivers/tty/serial/8250/8250_keba.c line 11

Quoted 2 lines
drivers/tty/serial/8250/8250_keba.c new file +2 -0
+#include <linux/io.h>
+#include <linux/misc/keba.h>

+ mod_devicetable.h

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+#include <linux/module.h>

+ spinlock.h
+ types.h

Is there any extra tool to check for missing headers? Or do I have to check the header for every used function?

There is iwyu, which is heavily tweaked by Jonathan Cameron for use in Linux kernel and even though it gives some false positives.

I did this manually by reading the code of the driver and remembering which header provides which API.

...

Quoted 7 lines
Quoted 4 lines

Can't you call uart_read_port_properties()?

If ever you gain some properties either via FW description or via software nodes, they will be automatically used without need to update the driver!

Yes that would be some nice behavior. But __uart_read_properties() sets some defaults even if no firmware node exist (UPF_SHARE_IRQ,

Is it a problem? Even a single IRQ may be marked shared.

Quoted 1 line

0 as irq number

Quoted 8 lines

It doesn't do that, it just skips setting it in that case.

Quoted 1 line

or it fails if not irq number is found).

Yeah, this is most "problematic" part in case of this driver. Why is it auxiliary and not platform? With that the __uart_read_properties() needs to be updated to also query IRQ from respective aux device, and aux dev needs implementation of dev_is_auxiliary(). Not that big deal, though.

It is auxiliary and not platform, because gregkh suggested to switch from platform to auxiliary. IMO he is right and that is a better fit, because auxiliary devices were introduced to split big devices into sub devices, which results in smaller drivers with one job for the sub device. That's actually what I tried to do with platform devices first.

Quoted 7 lines
Quoted 3 lines

So __uart_read_properties() would need to be changed. IMO it makes no sense to change __uart_read_properties() as this functionality is currently not required.

Yes, but as I said it will give you for free the possibility to use those properties without future modifications of the driver. OTOH, driver is in tree and modifications will be needed one way or another :-)

Yes, if the KEBA UART changes, then modifications would be needed. We kept this UART stable now for over 10 years. As it is FPGA based, we can keep it stable as long as FPGAs are on the market. In industrial automation the products are in the field for 10 years, 20 years or even more. We can only support the devices for that long time by keeping them compatible. So I don't expect changes now and therefore I would not prepare for them.

Gerhard

#11 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 4 lines · Gerhard Engleder
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Gerhard Engleder
Quoted 1 line · Andy Shevchenko

On Thu, Oct 23, 2025 at 05:12:29PM +0200, Gerhard Engleder wrote:

...

Quoted 36 lines
Quoted 12 lines
Quoted 7 lines
Quoted 4 lines

Can't you call uart_read_port_properties()?

If ever you gain some properties either via FW description or via software nodes, they will be automatically used without need to update the driver!

Yes that would be some nice behavior. But __uart_read_properties() sets some defaults even if no firmware node exist (UPF_SHARE_IRQ,

Is it a problem? Even a single IRQ may be marked shared.

Quoted 1 line

0 as irq number

Quoted 8 lines

It doesn't do that, it just skips setting it in that case.

Quoted 1 line

or it fails if not irq number is found).

Yeah, this is most "problematic" part in case of this driver. Why is it auxiliary and not platform? With that the __uart_read_properties() needs to be updated to also query IRQ from respective aux device, and aux dev needs implementation of dev_is_auxiliary(). Not that big deal, though.

It is auxiliary and not platform, because gregkh suggested to switch from platform to auxiliary. IMO he is right and that is a better fit, because auxiliary devices were introduced to split big devices into sub devices, which results in smaller drivers with one job for the sub device. That's actually what I tried to do with platform devices first.

Quoted 7 lines
Quoted 3 lines

So __uart_read_properties() would need to be changed. IMO it makes no sense to change __uart_read_properties() as this functionality is currently not required.

Yes, but as I said it will give you for free the possibility to use those properties without future modifications of the driver. OTOH, driver is in tree and modifications will be needed one way or another :-)

Quoted 7 lines

Yes, if the KEBA UART changes, then modifications would be needed. We kept this UART stable now for over 10 years. As it is FPGA based, we can keep it stable as long as FPGAs are on the market. In industrial automation the products are in the field for 10 years, 20 years or even more. We can only support the devices for that long time by keeping them compatible. So I don't expect changes now and therefore I would not prepare for them.

Fair enough.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#12 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

In reply to Gerhard Engleder
Quoted 29 lines · Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

---
 drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
 drivers/tty/serial/8250/Kconfig     |  13 ++
 drivers/tty/serial/8250/Makefile    |   1 +
 3 files changed, 294 insertions(+)
 create mode 100644 drivers/tty/serial/8250/8250_keba.c
drivers/tty/serial/8250/8250_keba.c new file +2 -0
new file mode 100644
index 000000000000..c05b89551b12
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*

drivers/tty/serial/8250/8250_keba.c line 12

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+ * Copyright (C) 2025 KEBA Industrial Automation GmbH
+ *
+ * Driver for KEBA UART FPGA IP core
+ */
+
+#include <linux/auxiliary_bus.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/misc/keba.h>
+#include <linux/module.h>

+ linux/serial_core.h

Quoted 48 lines
drivers/tty/serial/8250/8250_keba.c new file +48 -0
+
+#include "8250.h"
+
+#define KUART "kuart"
+
+/* flags */
+#define KUART_RS485		BIT(0)
+#define KUART_USE_CAPABILITY	BIT(1)
+
+/* registers */
+#define KUART_VERSION		0x0000
+#define KUART_REVISION		0x0001
+#define KUART_CAPABILITY	0x0002
+#define KUART_CONTROL		0x0004
+#define KUART_BASE		0x000C
+#define KUART_REGSHIFT		2
+#define KUART_CLK		1843200
+
+/* mode flags */
+enum kuart_mode {
+	KUART_MODE_NONE = 0,
+	KUART_MODE_RS485,
+	KUART_MODE_RS422,
+	KUART_MODE_RS232
+};
+
+/* capability flags */
+#define KUART_CAPABILITY_NONE	BIT(KUART_MODE_NONE)
+#define KUART_CAPABILITY_RS485	BIT(KUART_MODE_RS485)
+#define KUART_CAPABILITY_RS422	BIT(KUART_MODE_RS422)
+#define KUART_CAPABILITY_RS232	BIT(KUART_MODE_RS232)
+#define KUART_CAPABILITY_MASK	GENMASK(3, 0)
+
+/* Additional Control Register DTR line configuration */
+#define UART_ACR_DTRLC_MASK		0x18
+#define UART_ACR_DTRLC_COMPAT		0x00
+#define UART_ACR_DTRLC_ENABLE_LOW	0x10
+
+struct kuart {
+	struct keba_uart_auxdev *auxdev;
+	void __iomem *base;
+	unsigned int line;
+
+	unsigned int flags;
+	u8 capability;
+	enum kuart_mode mode;
+};
+

drivers/tty/serial/8250/8250_keba.c line 70

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+static void kuart_set_phy_mode(struct kuart *kuart, enum kuart_mode mode)
+{
+	iowrite8(mode, kuart->base + KUART_CONTROL);
+}
+
+static void kuart_enhanced_mode(struct uart_8250_port *up, bool enable)
+{
+	u8 lcr, efr;
+
+	/* backup LCR register */

Save + restore is quite obvious thing. IMO, no comment is needed about it.

Quoted 13 lines
drivers/tty/serial/8250/8250_keba.c new file +13 -0
+	lcr = serial_in(up, UART_LCR);
+
+	/* enable 650 compatible register set (EFR, ...) */
+	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
+
+	/* enable/disable enhanced mode with indexed control registers */
+	efr = serial_in(up, UART_EFR);
+	if (enable)
+		efr |= UART_EFR_ECB;
+	else
+		efr &= ~UART_EFR_ECB;
+	serial_out(up, UART_EFR, efr);
+

drivers/tty/serial/8250/8250_keba.c line 93

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+	/* disable 650 compatible register set, restore LCR */
+	serial_out(up, UART_LCR, lcr);
+}
+
+static void kuart_dtr_line_config(struct uart_8250_port *up, u8 dtrlc)
+{
+	u8 acr;
+
+	/* set index register to 0 to access ACR register */
+	serial_out(up, UART_SCR, UART_ACR);

So the scratch register has some special use on this UART (register multiplexer?), it would probably better name it with define, if that's the case.

Quoted 137 lines
drivers/tty/serial/8250/8250_keba.c new file +137 -0
+
+	/* set value register to 0x10 writing DTR mode (1,0) */
+	acr = serial_in(up, UART_LSR);
+	acr &= ~UART_ACR_DTRLC_MASK;
+	acr |= dtrlc;
+	serial_out(up, UART_LSR, acr);
+}
+
+static int kuart_rs485_config(struct uart_port *port, struct ktermios *termios,
+			      struct serial_rs485 *rs485)
+{
+	struct uart_8250_port *up = up_to_u8250p(port);
+	struct kuart *kuart = port->private_data;
+	enum kuart_mode mode;
+	u8 dtrlc;
+
+	if (rs485->flags & SER_RS485_ENABLED) {
+		if (rs485->flags & SER_RS485_MODE_RS422)
+			mode = KUART_MODE_RS422;
+		else
+			mode = KUART_MODE_RS485;
+	} else {
+		mode = KUART_MODE_RS232;
+	}
+
+	if (mode == kuart->mode)
+		return 0;
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* deactivate physical interface, break before make */
+		kuart_set_phy_mode(kuart, KUART_MODE_NONE);
+	}
+
+	if (mode == KUART_MODE_RS485) {
+		/*
+		 * Set DTR line configuration of 95x UART to DTR mode (1,0).
+		 * In this mode the DTR pin drives the active-low enable pin of
+		 * an external RS485 buffer. The DTR pin will be forced low
+		 * whenever the transmitter is not empty, otherwise DTR pin is
+		 * high.
+		 */
+		dtrlc = UART_ACR_DTRLC_ENABLE_LOW;
+	} else {
+		/*
+		 * Set DTR line configuration of 95x UART to DTR mode (0,0).
+		 * In this mode the DTR pin is compatible with 16C450, 16C550,
+		 * 16C650 and 16c670 (i.e. normal).
+		 */
+		dtrlc = UART_ACR_DTRLC_COMPAT;
+	}
+
+	kuart_enhanced_mode(up, true);
+	kuart_dtr_line_config(up, dtrlc);
+	kuart_enhanced_mode(up, false);
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* activate selected physical interface */
+		kuart_set_phy_mode(kuart, mode);
+	}
+
+	kuart->mode = mode;
+
+	return 0;
+}
+
+static int kuart_probe(struct auxiliary_device *auxdev,
+		       const struct auxiliary_device_id *id)
+{
+	struct device *dev = &auxdev->dev;
+	struct uart_8250_port uart = {};
+	struct resource res;
+	struct kuart *kuart;
+	int retval;
+
+	kuart = devm_kzalloc(dev, sizeof(*kuart), GFP_KERNEL);
+	if (!kuart)
+		return -ENOMEM;
+	kuart->auxdev = container_of(auxdev, struct keba_uart_auxdev, auxdev);
+	kuart->flags = id->driver_data;
+	auxiliary_set_drvdata(auxdev, kuart);
+
+	/*
+	 * map only memory in front of UART registers, UART registers will be
+	 * mapped by serial port
+	 */
+	res = kuart->auxdev->io;
+	res.end = res.start + KUART_BASE - 1;
+	kuart->base = devm_ioremap_resource(dev, &res);
+	if (IS_ERR(kuart->base))
+		return PTR_ERR(kuart->base);
+
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/*
+		 * supported modes are read from capability register, at least
+		 * one mode other than none must be supported
+		 */
+		kuart->capability = ioread8(kuart->base + KUART_CAPABILITY) &
+				    KUART_CAPABILITY_MASK;
+		if ((kuart->capability & ~KUART_CAPABILITY_NONE) == 0)
+			return -EIO;
+	}
+
+	spin_lock_init(&uart.port.lock);
+	uart.port.dev = dev;
+	uart.port.mapbase = kuart->auxdev->io.start + KUART_BASE;
+	uart.port.irq = kuart->auxdev->irq;
+	uart.port.uartclk = KUART_CLK;
+	uart.port.private_data = kuart;
+
+	/* 8 bit registers are 32 bit aligned => shift register offset */
+	uart.port.iotype = UPIO_MEM32;
+	uart.port.regshift = KUART_REGSHIFT;
+
+	/*
+	 * UART mixes 16550, 16750 and 16C950 (for RS485) standard => auto
+	 * configuration works best
+	 */
+	uart.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_IOREMAP;
+
+	/*
+	 * UART supports RS485, RS422 and RS232 with switching of physical
+	 * interface
+	 */
+	uart.port.rs485_config = kuart_rs485_config;
+	if (kuart->flags & KUART_RS485) {
+		uart.port.rs485_supported.flags = SER_RS485_ENABLED |
+						  SER_RS485_RTS_ON_SEND;
+		uart.port.rs485.flags = SER_RS485_ENABLED |
+					SER_RS485_RTS_ON_SEND;
+	}
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* default mode priority is RS485 > RS422 > RS232 */
+		if (kuart->capability & KUART_CAPABILITY_RS422) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND |
+							   SER_RS485_MODE_RS422;
+			uart.port.rs485.flags = SER_RS485_ENABLED |

drivers/tty/serial/8250/8250_keba.c line 240

Quoted 10 lines
drivers/tty/serial/8250/8250_keba.c new file +10 -0
+						SER_RS485_RTS_ON_SEND |
+						SER_RS485_MODE_RS422;
+		}
+		if (kuart->capability & KUART_CAPABILITY_RS485) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND;
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND;
+		}
+	}

Is it so that only one mode is supported or can that be changes using kuart_rs485_config() in which case you should have all flags listed (you seem to talk about priority so that sounds like all are supported)?

drivers/tty/serial/8250/8250_keba.c line 244

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
+		dev_err(&auxdev->dev, "UART registration failed!\n");

Missing header.

Quoted 73 lines
drivers/tty/serial/8250/8250_keba.c new file +36 -0
+		return retval;
+	}
+	kuart->line = retval;
+
+	return 0;
+}
+
+static void kuart_remove(struct auxiliary_device *auxdev)
+{
+	struct kuart *kuart = auxiliary_get_drvdata(auxdev);
+
+	if (kuart->flags & KUART_USE_CAPABILITY)
+		kuart_set_phy_mode(kuart, KUART_MODE_NONE);
+
+	serial8250_unregister_port(kuart->line);
+}
+
+static const struct auxiliary_device_id kuart_devtype_aux[] = {
+	{ .name = "keba.rs485-uart", .driver_data = KUART_RS485 },
+	{ .name = "keba.rs232-uart", .driver_data = 0 },
+	{ .name = "keba.uart", .driver_data = KUART_USE_CAPABILITY },
+	{}
+};
+MODULE_DEVICE_TABLE(auxiliary, kuart_devtype_aux);
+
+static struct auxiliary_driver kuart_driver_aux = {
+	.name = KUART,
+	.id_table = kuart_devtype_aux,
+	.probe  = kuart_probe,
+	.remove = kuart_remove,
+};
+module_auxiliary_driver(kuart_driver_aux);
+
+MODULE_AUTHOR("Gerhard Engleder <[email protected]>");
+MODULE_DESCRIPTION("KEBA 8250 serial port driver");
+MODULE_LICENSE("GPL");
drivers/tty/serial/8250/Kconfig +13 -0
index f64ef0819cd4..5c3e4bcb3b93 100644
@@ -430,6 +430,19 @@ config SERIAL_8250_IOC3
 	  behind the IOC3 device on those systems.  Maximum baud speed is
 	  38400bps using this driver.
 
+config SERIAL_8250_KEBA
+	tristate "Support for KEBA 8250 UART"
+	depends on SERIAL_8250
+	depends on KEBA_CP500
+	help
+	  Selecting this option will add support for KEBA UARTs. These UARTs
+	  are used for the serial interfaces of KEBA PLCs.
+
+	  This driver can also be built as a module. If so, the module will
+	  be called 8250_keba.
+
+	  If unsure, say N.
+
 config SERIAL_8250_RT288X
 	bool "Ralink RT288x/RT305x/RT3662/RT3883 serial port support"
 	depends on SERIAL_8250
drivers/tty/serial/8250/Makefile +1 -0
index 513a0941c284..f7a463c9860a 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_SERIAL_8250_HP300)		+= 8250_hp300.o
 obj-$(CONFIG_SERIAL_8250_HUB6)		+= 8250_hub6.o
 obj-$(CONFIG_SERIAL_8250_INGENIC)	+= 8250_ingenic.o
 obj-$(CONFIG_SERIAL_8250_IOC3)		+= 8250_ioc3.o
+obj-$(CONFIG_SERIAL_8250_KEBA)		+= 8250_keba.o
 obj-$(CONFIG_SERIAL_8250_LPC18XX)	+= 8250_lpc18xx.o
 obj-$(CONFIG_SERIAL_8250_LPSS)		+= 8250_lpss.o
 obj-$(CONFIG_SERIAL_8250_MEN_MCB)	+= 8250_men_mcb.o
Signature · 1 line
 i.
#13 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 35 lines · Ilpo Järvinen
Quoted 33 lines · Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

---
  drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
  drivers/tty/serial/8250/Kconfig     |  13 ++
  drivers/tty/serial/8250/Makefile    |   1 +
  3 files changed, 294 insertions(+)

create mode 100644 drivers/tty/serial/8250/8250_keba.c

drivers/tty/serial/8250/8250_keba.c new file +6 -0
new file mode 100644
index 000000000000..c05b89551b12
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 KEBA Industrial Automation GmbH
+ *
+ * Driver for KEBA UART FPGA IP core
+ */
Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 12

Quoted 6 lines
drivers/tty/serial/8250/8250_keba.c new file +6 -0
+
+#include <linux/auxiliary_bus.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/misc/keba.h>
+#include <linux/module.h>

+ linux/serial_core.h

Is this really necessary even with the include of 8250.h below?

Quoted 4 lines
Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+#include "8250.h"
+
+#define KUART "kuart"

...

Quoted 7 lines

drivers/tty/serial/8250/8250_keba.c line 70

Quoted 5 lines
drivers/tty/serial/8250/8250_keba.c new file +5 -0
+static void kuart_enhanced_mode(struct uart_8250_port *up, bool enable)
+{
+	u8 lcr, efr;
+
+	/* backup LCR register */

Save + restore is quite obvious thing. IMO, no comment is needed about it.

Yes it could be ommited. The patch is already merged, so I would keep it. Ok?

Quoted 19 lines
Quoted 19 lines
drivers/tty/serial/8250/8250_keba.c new file +19 -0
+	lcr = serial_in(up, UART_LCR);
+
+	/* enable 650 compatible register set (EFR, ...) */
+	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
+
+	/* enable/disable enhanced mode with indexed control registers */
+	efr = serial_in(up, UART_EFR);
+	if (enable)
+		efr |= UART_EFR_ECB;
+	else
+		efr &= ~UART_EFR_ECB;
+	serial_out(up, UART_EFR, efr);
+
+	/* disable 650 compatible register set, restore LCR */
+	serial_out(up, UART_LCR, lcr);
+}
+
+static void kuart_dtr_line_config(struct uart_8250_port *up, u8 dtrlc)
+{
Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 93

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+	u8 acr;
+
+	/* set index register to 0 to access ACR register */
+	serial_out(up, UART_SCR, UART_ACR);

So the scratch register has some special use on this UART (register multiplexer?), it would probably better name it with define, if that's the case.

This UART supports an enhanced mode, which changes the behavior of some registers. But the register still have their normal use with enhanced mode disabled. So I would keep the register name.

Quoted 7 lines
Quoted 7 lines
drivers/tty/serial/8250/8250_keba.c new file +7 -0
+
+	/* set value register to 0x10 writing DTR mode (1,0) */
+	acr = serial_in(up, UART_LSR);
+	acr &= ~UART_ACR_DTRLC_MASK;
+	acr |= dtrlc;
+	serial_out(up, UART_LSR, acr);
+}

...

Quoted 24 lines
Quoted 24 lines
drivers/tty/serial/8250/8250_keba.c new file +24 -0
+	/*
+	 * UART supports RS485, RS422 and RS232 with switching of physical
+	 * interface
+	 */
+	uart.port.rs485_config = kuart_rs485_config;
+	if (kuart->flags & KUART_RS485) {
+		uart.port.rs485_supported.flags = SER_RS485_ENABLED |
+						  SER_RS485_RTS_ON_SEND;
+		uart.port.rs485.flags = SER_RS485_ENABLED |
+					SER_RS485_RTS_ON_SEND;
+	}
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* default mode priority is RS485 > RS422 > RS232 */
+		if (kuart->capability & KUART_CAPABILITY_RS422) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND |
+							   SER_RS485_MODE_RS422;
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND |
+						SER_RS485_MODE_RS422;
+		}
+		if (kuart->capability & KUART_CAPABILITY_RS485) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+							   SER_RS485_RTS_ON_SEND;
Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 233

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND;
+		}
+	}

Is it so that only one mode is supported or can that be changes using kuart_rs485_config() in which case you should have all flags listed (you seem to talk about priority so that sounds like all are supported)?

Both. As written in the commit message, there are 3 variants of the device. 2 variants support only one mode and 1 variant supports up to 3 modes.

Quoted 6 lines

drivers/tty/serial/8250/8250_keba.c line 244

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
+		dev_err(&auxdev->dev, "UART registration failed!\n");

Missing header.

I will check for the header.

As this patch is already merged, I will do a follow up.

regards, gerhard

#14 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 46 lines · Gerhard Engleder
Quoted 36 lines · Ilpo Järvinen
Quoted 34 lines · Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

---
  drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
  drivers/tty/serial/8250/Kconfig     |  13 ++
  drivers/tty/serial/8250/Makefile    |   1 +
  3 files changed, 294 insertions(+)

create mode 100644 drivers/tty/serial/8250/8250_keba.c

drivers/tty/serial/8250/8250_keba.c new file +6 -0
new file mode 100644
index 000000000000..c05b89551b12
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2025 KEBA Industrial Automation GmbH
+ *
+ * Driver for KEBA UART FPGA IP core
+ */
Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 12

Quoted 6 lines
drivers/tty/serial/8250/8250_keba.c new file +6 -0
+
+#include <linux/auxiliary_bus.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/misc/keba.h>
+#include <linux/module.h>

+ linux/serial_core.h

Quoted 1 line

Is this really necessary even with the include of 8250.h below?

Yes. Generally don't rely on indirect includes.

Quoted 15 lines
Quoted 4 lines
Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+#include "8250.h"
+
+#define KUART "kuart"

...

Quoted 7 lines

drivers/tty/serial/8250/8250_keba.c line 70

Quoted 5 lines
drivers/tty/serial/8250/8250_keba.c new file +5 -0
+static void kuart_enhanced_mode(struct uart_8250_port *up, bool enable)
+{
+	u8 lcr, efr;
+
+	/* backup LCR register */

Save + restore is quite obvious thing. IMO, no comment is needed about it.

Quoted 2 lines

Yes it could be ommited. The patch is already merged, so I would keep it. Ok?

Ah, I didn't realize this is already merged. Just leave them then, it's not that big thing.

Quoted 28 lines
Quoted 19 lines
Quoted 19 lines
drivers/tty/serial/8250/8250_keba.c new file +19 -0
+	lcr = serial_in(up, UART_LCR);
+
+	/* enable 650 compatible register set (EFR, ...) */
+	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
+
+	/* enable/disable enhanced mode with indexed control registers */
+	efr = serial_in(up, UART_EFR);
+	if (enable)
+		efr |= UART_EFR_ECB;
+	else
+		efr &= ~UART_EFR_ECB;
+	serial_out(up, UART_EFR, efr);
+
+	/* disable 650 compatible register set, restore LCR */
+	serial_out(up, UART_LCR, lcr);
+}
+
+static void kuart_dtr_line_config(struct uart_8250_port *up, u8 dtrlc)
+{
Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 93

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+	u8 acr;
+
+	/* set index register to 0 to access ACR register */
+	serial_out(up, UART_SCR, UART_ACR);

So the scratch register has some special use on this UART (register multiplexer?), it would probably better name it with define, if that's the case.

Quoted 3 lines

This UART supports an enhanced mode, which changes the behavior of some registers. But the register still have their normal use with enhanced mode disabled. So I would keep the register name.

But this code clearly assume UART is in enhanced mode. Same number can have different names. You could of course reuse the other define in the define:

#define KUART_EMODE_INDEX_REG UART_SCR

Quoted 62 lines
Quoted 6 lines
Quoted 6 lines
drivers/tty/serial/8250/8250_keba.c new file +6 -0
+	/* set value register to 0x10 writing DTR mode (1,0) */
+	acr = serial_in(up, UART_LSR);
+	acr &= ~UART_ACR_DTRLC_MASK;
+	acr |= dtrlc;
+	serial_out(up, UART_LSR, acr);
+}

...

Quoted 27 lines
Quoted 27 lines
drivers/tty/serial/8250/8250_keba.c new file +16 -0
+	/*
+	 * UART supports RS485, RS422 and RS232 with switching of physical
+	 * interface
+	 */
+	uart.port.rs485_config = kuart_rs485_config;
+	if (kuart->flags & KUART_RS485) {
+		uart.port.rs485_supported.flags = SER_RS485_ENABLED |
+						  SER_RS485_RTS_ON_SEND;
+		uart.port.rs485.flags = SER_RS485_ENABLED |
+					SER_RS485_RTS_ON_SEND;
+	}
+	if (kuart->flags & KUART_USE_CAPABILITY) {
+		/* default mode priority is RS485 > RS422 > RS232 */
+		if (kuart->capability & KUART_CAPABILITY_RS422) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+

SER_RS485_RTS_ON_SEND |
+
SER_RS485_MODE_RS422;

drivers/tty/serial/8250/8250_keba.c new file +7 -0
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND |
+						SER_RS485_MODE_RS422;
+		}
+		if (kuart->capability & KUART_CAPABILITY_RS485) {
+			uart.port.rs485_supported.flags |= SER_RS485_ENABLED |
+

SER_RS485_RTS_ON_SEND;

Quoted 8 lines

drivers/tty/serial/8250/8250_keba.c line 233

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+			uart.port.rs485.flags = SER_RS485_ENABLED |
+						SER_RS485_RTS_ON_SEND;
+		}
+	}

Is it so that only one mode is supported or can that be changes using kuart_rs485_config() in which case you should have all flags listed (you seem to talk about priority so that sounds like all are supported)?

Both. As written in the commit message, there are 3 variants of the device. 2 variants support only one mode and 1 variant supports up to 3 modes.

Quoted 6 lines

drivers/tty/serial/8250/8250_keba.c line 244

Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+	retval = serial8250_register_8250_port(&uart);
+	if (retval < 0) {
+		dev_err(&auxdev->dev, "UART registration failed!\n");

Missing header.

I will check for the header.

As this patch is already merged, I will do a follow up.

regards, gerhard

Signature · 1 line
 i.
#15 lore raw

Re: [PATCH v4 2/2] serial: 8250: add driver for KEBA UART

Quoted 25 lines · Ilpo Järvinen
Quoted 23 lines · Gerhard Engleder
Quoted 22 lines · Ilpo Järvinen
Quoted 20 lines · Gerhard Engleder

From: Gerhard Engleder <[email protected]>

The KEBA UART is found in the system FPGA of KEBA PLC devices. It is mostly 8250 compatible with extension for some UART modes.

3 different variants exist. The simpliest variant supports only RS-232 and is used for debug interfaces. The next variant supports only RS-485 and is used mostly for communication with KEBA panel devices. The third variant is able to support RS-232, RS-485 and RS-422. For this variant not only the mode of the UART is configured, also the physics and transceivers are switched according to the mode.

---
   drivers/tty/serial/8250/8250_keba.c | 280 ++++++++++++++++++++++++++++
   drivers/tty/serial/8250/Kconfig     |  13 ++
   drivers/tty/serial/8250/Makefile    |   1 +
   3 files changed, 294 insertions(+)

create mode 100644 drivers/tty/serial/8250/8250_keba.c

...

Quoted 11 lines
Quoted 9 lines
Quoted 7 lines

drivers/tty/serial/8250/8250_keba.c line 12

Quoted 5 lines
drivers/tty/serial/8250/8250_keba.c new file +5 -0
+#include <linux/auxiliary_bus.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/misc/keba.h>
+#include <linux/module.h>

+ linux/serial_core.h

Is this really necessary even with the include of 8250.h below?

Yes. Generally don't rely on indirect includes.

I will add it to the follow up.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/tty/serial/8250/8250_keba.c new file +4 -0
+
+#include "8250.h"
+
+#define KUART "kuart"

...

Quoted 15 lines
Quoted 11 lines
Quoted 10 lines

drivers/tty/serial/8250/8250_keba.c line 93

Quoted 6 lines
drivers/tty/serial/8250/8250_keba.c new file +6 -0
+static void kuart_dtr_line_config(struct uart_8250_port *up, u8 dtrlc)
+{
+	u8 acr;
+
+	/* set index register to 0 to access ACR register */
+	serial_out(up, UART_SCR, UART_ACR);

So the scratch register has some special use on this UART (register multiplexer?), it would probably better name it with define, if that's the case.

Quoted 3 lines

This UART supports an enhanced mode, which changes the behavior of some registers. But the register still have their normal use with enhanced mode disabled. So I would keep the register name.

Quoted 5 lines

But this code clearly assume UART is in enhanced mode. Same number can have different names. You could of course reuse the other define in the define:

#define KUART_EMODE_INDEX_REG UART_SCR

I will consider it for the follow up.

Thank you for your comments!

Gerhard