* [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 13:27 ` Andy Shevchenko
2026-05-04 8:48 ` [PATCH 02/15] serial: 8250: add Moxa MUEx50 UART port type Crescent Hsieh
` (13 subsequent siblings)
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The Moxa PCIe multiport serial boards are currently handled as part of
8250_pci.c. In preparation for adding Moxa-specific UART features and
optimizations, move the Moxa PCIe implementation into a dedicated
driver.
This introduces drivers/tty/serial/8250/8250_mxpcie.c and wires it up
via Kconfig and Makefile, while preserving the existing probe flow and
device IDs.
This change was suggested during earlier review by Andy Shevchenko.
No functional change intended.
Link: https://lore.kernel.org/all/ZmQovC6TbDpTb3c8@surfacebook.localdomain/
Link: https://lore.kernel.org/all/CAHp75VeDsVt0GQYUFxLM+obfmqXBPa3hM3YMsFbc26uzWZG-SQ@mail.gmail.com/
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 292 ++++++++++++++++++++++++++
drivers/tty/serial/8250/8250_pci.c | 208 +-----------------
drivers/tty/serial/8250/Kconfig | 11 +
drivers/tty/serial/8250/Makefile | 1 +
4 files changed, 307 insertions(+), 205 deletions(-)
create mode 100644 drivers/tty/serial/8250/8250_mxpcie.c
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
new file mode 100644
index 000000000000..aa0afdbed791
--- /dev/null
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -0,0 +1,292 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Moxa PCIe multiport serial device driver
+ *
+ * Copyright (C) 2025 Moxa Inc. (support@moxa.com)
+ * Author: Crescent Hsieh <crescentcy.hsieh@moxa.com>
+ */
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/device.h>
+#include <linux/dev_printk.h>
+#include <linux/types.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/bits.h>
+#include <linux/bitfield.h>
+#include <linux/serial_8250.h>
+#include <linux/serial_core.h>
+#include <linux/serial_reg.h>
+#include <linux/8250_pci.h>
+
+#include "8250.h"
+#include "8250_pcilib.h"
+
+#define PCI_DEVICE_ID_MOXA_CP102E 0x1024
+#define PCI_DEVICE_ID_MOXA_CP102EL 0x1025
+#define PCI_DEVICE_ID_MOXA_CP102N 0x1027
+#define PCI_DEVICE_ID_MOXA_CP104EL_A 0x1045
+#define PCI_DEVICE_ID_MOXA_CP104N 0x1046
+#define PCI_DEVICE_ID_MOXA_CP112N 0x1121
+#define PCI_DEVICE_ID_MOXA_CP114EL 0x1144
+#define PCI_DEVICE_ID_MOXA_CP114N 0x1145
+#define PCI_DEVICE_ID_MOXA_CP116E_A_A 0x1160
+#define PCI_DEVICE_ID_MOXA_CP116E_A_B 0x1161
+#define PCI_DEVICE_ID_MOXA_CP118EL_A 0x1182
+#define PCI_DEVICE_ID_MOXA_CP118E_A_I 0x1183
+#define PCI_DEVICE_ID_MOXA_CP132EL 0x1322
+#define PCI_DEVICE_ID_MOXA_CP132N 0x1323
+#define PCI_DEVICE_ID_MOXA_CP134EL_A 0x1342
+#define PCI_DEVICE_ID_MOXA_CP134N 0x1343
+#define PCI_DEVICE_ID_MOXA_CP138E_A 0x1381
+#define PCI_DEVICE_ID_MOXA_CP168EL_A 0x1683
+
+/* Bits in PCI device ID encoding board capabilities */
+#define MOXA_DEV_ID_IFACE_MASK GENMASK(11, 8) /* Supported serial interface */
+#define MOXA_DEV_ID_NPORTS_MASK GENMASK(7, 4) /* Number of UART ports */
+
+/* UART */
+#define MOXA_PUART_BASE_BAUD 921600
+#define MOXA_PUART_OFFSET 0x200
+
+#define MOXA_GPIO_DIRECTION 0x09
+#define MOXA_GPIO_OUTPUT 0x0A
+
+#define MOXA_GPIO_PIN2 BIT(2)
+
+#define MOXA_UIR_OFFSET 0x04
+#define MOXA_UIR_RS232 0x00
+#define MOXA_UIR_RS422 0x01
+#define MOXA_UIR_RS485_4W 0x0B
+#define MOXA_UIR_RS485_2W 0x0F
+
+#define MOXA_EVEN_RS_MASK GENMASK(3, 0)
+#define MOXA_ODD_RS_MASK GENMASK(7, 4)
+
+struct mxpcie8250 {
+ unsigned int supp_rs;
+ unsigned int num_ports;
+ void __iomem *bar1_base; /* UART registers (MMIO) */
+ void __iomem *bar2_base; /* UIR / GPIO / CPLD (IO) */
+ int line[];
+};
+
+enum {
+ MOXA_SUPP_RS232 = BIT(0),
+ MOXA_SUPP_RS422 = BIT(1),
+ MOXA_SUPP_RS485 = BIT(2),
+};
+
+static bool mxpcie8250_is_mini_pcie(unsigned short device)
+{
+ if (device == PCI_DEVICE_ID_MOXA_CP102N ||
+ device == PCI_DEVICE_ID_MOXA_CP104N ||
+ device == PCI_DEVICE_ID_MOXA_CP112N ||
+ device == PCI_DEVICE_ID_MOXA_CP114N ||
+ device == PCI_DEVICE_ID_MOXA_CP132N ||
+ device == PCI_DEVICE_ID_MOXA_CP134N)
+ return true;
+
+ return false;
+}
+
+static unsigned int mxpcie8250_get_supp_rs(unsigned short device)
+{
+ switch (device & MOXA_DEV_ID_IFACE_MASK) {
+ case 0x0000:
+ case 0x0600:
+ return MOXA_SUPP_RS232;
+ case 0x0100:
+ return MOXA_SUPP_RS232 | MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
+ case 0x0300:
+ return MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
+ }
+
+ return 0;
+}
+
+static unsigned short mxpcie8250_get_nports(unsigned short device)
+{
+ switch (device) {
+ case PCI_DEVICE_ID_MOXA_CP116E_A_A:
+ case PCI_DEVICE_ID_MOXA_CP116E_A_B:
+ return 8;
+ }
+
+ return FIELD_GET(MOXA_DEV_ID_NPORTS_MASK, device);
+}
+
+static void mxpcie8250_set_interface(struct mxpcie8250 *priv,
+ unsigned int port_idx,
+ u8 mode)
+{
+ void __iomem *uir_addr = priv->bar2_base + MOXA_UIR_OFFSET + port_idx / 2;
+ u8 cval;
+
+ cval = ioread8(uir_addr);
+
+ if (port_idx & 1)
+ cval = FIELD_MODIFY(MOXA_ODD_RS_MASK, &cval, mode);
+ else
+ cval = FIELD_MODIFY(MOXA_EVEN_RS_MASK, &cval, mode);
+
+ iowrite8(cval, uir_addr);
+}
+
+static void mxpcie8250_init_board(struct pci_dev *pdev, struct mxpcie8250 *priv)
+{
+ void __iomem *bar2_base = priv->bar2_base;
+ unsigned short device = pdev->device;
+ u8 cval;
+
+ /* Initial terminator */
+ if (device == PCI_DEVICE_ID_MOXA_CP114EL ||
+ device == PCI_DEVICE_ID_MOXA_CP118EL_A) {
+ iowrite8(0xff, bar2_base + MOXA_GPIO_DIRECTION);
+ iowrite8(0x00, bar2_base + MOXA_GPIO_OUTPUT);
+ }
+ /*
+ * Enable hardware buffer to prevent break signal output when system boots up.
+ * This hardware buffer is only supported on Mini PCIe series.
+ */
+ if (mxpcie8250_is_mini_pcie(device)) {
+ /* Set GPIO direction */
+ cval = ioread8(bar2_base + MOXA_GPIO_DIRECTION);
+ cval |= MOXA_GPIO_PIN2;
+ iowrite8(cval, bar2_base + MOXA_GPIO_DIRECTION);
+ /* Enable low GPIO */
+ cval = ioread8(bar2_base + MOXA_GPIO_OUTPUT);
+ cval &= ~MOXA_GPIO_PIN2;
+ iowrite8(cval, bar2_base + MOXA_GPIO_OUTPUT);
+ }
+}
+
+static void mxpcie8250_setup_port(struct pci_dev *pdev,
+ struct mxpcie8250 *priv,
+ struct uart_8250_port *up,
+ int idx)
+{
+ unsigned short device = pdev->device;
+ int offset = idx * MOXA_PUART_OFFSET;
+ u8 init_mode = MOXA_UIR_RS232;
+
+ if (!(priv->supp_rs & MOXA_SUPP_RS232))
+ init_mode = MOXA_UIR_RS422;
+
+ mxpcie8250_set_interface(priv, idx, init_mode);
+
+ if (idx == 3 &&
+ (device == PCI_DEVICE_ID_MOXA_CP104EL_A ||
+ device == PCI_DEVICE_ID_MOXA_CP114EL ||
+ device == PCI_DEVICE_ID_MOXA_CP134EL_A))
+ offset = 7 * MOXA_PUART_OFFSET;
+
+ up->port.mapbase = pci_resource_start(pdev, FL_BASE1) + offset;
+ up->port.membase = pcim_iomap_table(pdev)[FL_BASE1] + offset;
+}
+
+static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+ struct device *dev = &pdev->dev;
+ struct uart_8250_port up = {};
+ struct mxpcie8250 *priv;
+ unsigned short device = pdev->device;
+ unsigned int i, num_ports;
+ int ret;
+
+ ret = pcim_enable_device(pdev);
+ if (ret)
+ return ret;
+
+ num_ports = mxpcie8250_get_nports(device);
+
+ priv = devm_kzalloc(dev, struct_size(priv, line, num_ports), GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+
+ priv->supp_rs = mxpcie8250_get_supp_rs(device);
+ priv->num_ports = num_ports;
+
+ priv->bar1_base = pcim_iomap(pdev, FL_BASE1, 0);
+ if (!priv->bar1_base)
+ return -ENOMEM;
+
+ priv->bar2_base = pcim_iomap(pdev, FL_BASE2, 0);
+ if (!priv->bar2_base)
+ return -ENOMEM;
+
+ mxpcie8250_init_board(pdev, priv);
+
+ up.port.dev = dev;
+ up.port.irq = pdev->irq;
+ up.port.uartclk = MOXA_PUART_BASE_BAUD * 16;
+ up.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
+
+ up.port.iotype = UPIO_MEM;
+ up.port.iobase = 0;
+ up.port.regshift = 0;
+
+ for (i = 0; i < num_ports; i++) {
+ mxpcie8250_setup_port(pdev, priv, &up, i);
+
+ dev_dbg(dev, "Setup PCI port: port %lx, irq %d, type %d\n",
+ up.port.iobase, up.port.irq, up.port.iotype);
+
+ priv->line[i] = serial8250_register_8250_port(&up);
+ if (priv->line[i] < 0) {
+ dev_err(dev,
+ "Couldn't register serial port %lx, irq %d, type %d, error %d\n",
+ up.port.iobase, up.port.irq,
+ up.port.iotype, priv->line[i]);
+ break;
+ }
+ }
+ dev_set_drvdata(dev, priv);
+
+ return 0;
+}
+
+static void mxpcie8250_remove(struct pci_dev *pdev)
+{
+ struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
+ unsigned int i;
+
+ for (i = 0; i < priv->num_ports; i++)
+ serial8250_unregister_port(priv->line[i]);
+}
+
+static const struct pci_device_id mxpcie8250_pci_ids[] = {
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102E) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102EL) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP112N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114EL) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132EL) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134N) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP138E_A) },
+ { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A) },
+ { }
+};
+MODULE_DEVICE_TABLE(pci, mxpcie8250_pci_ids);
+
+static struct pci_driver mxpcie8250_pci_driver = {
+ .name = "8250_mxpcie",
+ .id_table = mxpcie8250_pci_ids,
+ .probe = mxpcie8250_probe,
+ .remove = mxpcie8250_remove,
+};
+module_pci_driver(mxpcie8250_pci_driver);
+
+MODULE_AUTHOR("Moxa Inc.");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Moxa PCIe Multiport Serial Device Driver");
+MODULE_IMPORT_NS("SERIAL_8250_PCI");
diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 152f914c599d..fa172477409a 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -76,25 +76,6 @@
#define PCI_DEVICE_ID_WCHIC_CH384_4S 0x3470
#define PCI_DEVICE_ID_WCHIC_CH384_8S 0x3853
-#define PCI_DEVICE_ID_MOXA_CP102E 0x1024
-#define PCI_DEVICE_ID_MOXA_CP102EL 0x1025
-#define PCI_DEVICE_ID_MOXA_CP102N 0x1027
-#define PCI_DEVICE_ID_MOXA_CP104EL_A 0x1045
-#define PCI_DEVICE_ID_MOXA_CP104N 0x1046
-#define PCI_DEVICE_ID_MOXA_CP112N 0x1121
-#define PCI_DEVICE_ID_MOXA_CP114EL 0x1144
-#define PCI_DEVICE_ID_MOXA_CP114N 0x1145
-#define PCI_DEVICE_ID_MOXA_CP116E_A_A 0x1160
-#define PCI_DEVICE_ID_MOXA_CP116E_A_B 0x1161
-#define PCI_DEVICE_ID_MOXA_CP118EL_A 0x1182
-#define PCI_DEVICE_ID_MOXA_CP118E_A_I 0x1183
-#define PCI_DEVICE_ID_MOXA_CP132EL 0x1322
-#define PCI_DEVICE_ID_MOXA_CP132N 0x1323
-#define PCI_DEVICE_ID_MOXA_CP134EL_A 0x1342
-#define PCI_DEVICE_ID_MOXA_CP134N 0x1343
-#define PCI_DEVICE_ID_MOXA_CP138E_A 0x1381
-#define PCI_DEVICE_ID_MOXA_CP168EL_A 0x1683
-
/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584 0x1584
#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588 0x1588
@@ -1994,138 +1975,6 @@ pci_sunix_setup(struct serial_private *priv,
return setup_port(priv, port, bar, offset, 0);
}
-#define MOXA_PUART_GPIO_EN 0x09
-#define MOXA_PUART_GPIO_OUT 0x0A
-
-#define MOXA_GPIO_PIN2 BIT(2)
-
-#define MOXA_RS232 0x00
-#define MOXA_RS422 0x01
-#define MOXA_RS485_4W 0x0B
-#define MOXA_RS485_2W 0x0F
-#define MOXA_UIR_OFFSET 0x04
-#define MOXA_EVEN_RS_MASK GENMASK(3, 0)
-#define MOXA_ODD_RS_MASK GENMASK(7, 4)
-
-enum {
- MOXA_SUPP_RS232 = BIT(0),
- MOXA_SUPP_RS422 = BIT(1),
- MOXA_SUPP_RS485 = BIT(2),
-};
-
-static unsigned short moxa_get_nports(unsigned short device)
-{
- switch (device) {
- case PCI_DEVICE_ID_MOXA_CP116E_A_A:
- case PCI_DEVICE_ID_MOXA_CP116E_A_B:
- return 8;
- }
-
- return FIELD_GET(0x00F0, device);
-}
-
-static bool pci_moxa_is_mini_pcie(unsigned short device)
-{
- if (device == PCI_DEVICE_ID_MOXA_CP102N ||
- device == PCI_DEVICE_ID_MOXA_CP104N ||
- device == PCI_DEVICE_ID_MOXA_CP112N ||
- device == PCI_DEVICE_ID_MOXA_CP114N ||
- device == PCI_DEVICE_ID_MOXA_CP132N ||
- device == PCI_DEVICE_ID_MOXA_CP134N)
- return true;
-
- return false;
-}
-
-static unsigned int pci_moxa_supported_rs(struct pci_dev *dev)
-{
- switch (dev->device & 0x0F00) {
- case 0x0000:
- case 0x0600:
- return MOXA_SUPP_RS232;
- case 0x0100:
- return MOXA_SUPP_RS232 | MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
- case 0x0300:
- return MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
- }
- return 0;
-}
-
-static int pci_moxa_set_interface(const struct pci_dev *dev,
- unsigned int port_idx,
- u8 mode)
-{
- resource_size_t iobar_addr = pci_resource_start(dev, 2);
- resource_size_t UIR_addr = iobar_addr + MOXA_UIR_OFFSET + port_idx / 2;
- u8 val;
-
- val = inb(UIR_addr);
-
- if (port_idx % 2) {
- val &= ~MOXA_ODD_RS_MASK;
- val |= FIELD_PREP(MOXA_ODD_RS_MASK, mode);
- } else {
- val &= ~MOXA_EVEN_RS_MASK;
- val |= FIELD_PREP(MOXA_EVEN_RS_MASK, mode);
- }
- outb(val, UIR_addr);
-
- return 0;
-}
-
-static int pci_moxa_init(struct pci_dev *dev)
-{
- unsigned short device = dev->device;
- resource_size_t iobar_addr = pci_resource_start(dev, 2);
- unsigned int i, num_ports = moxa_get_nports(device);
- u8 val, init_mode = MOXA_RS232;
-
- if (!IS_ENABLED(CONFIG_HAS_IOPORT))
- return serial_8250_warn_need_ioport(dev);
-
- if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232)) {
- init_mode = MOXA_RS422;
- }
- for (i = 0; i < num_ports; ++i)
- pci_moxa_set_interface(dev, i, init_mode);
-
- /*
- * Enable hardware buffer to prevent break signal output when system boots up.
- * This hardware buffer is only supported on Mini PCIe series.
- */
- if (pci_moxa_is_mini_pcie(device)) {
- /* Set GPIO direction */
- val = inb(iobar_addr + MOXA_PUART_GPIO_EN);
- val |= MOXA_GPIO_PIN2;
- outb(val, iobar_addr + MOXA_PUART_GPIO_EN);
- /* Enable low GPIO */
- val = inb(iobar_addr + MOXA_PUART_GPIO_OUT);
- val &= ~MOXA_GPIO_PIN2;
- outb(val, iobar_addr + MOXA_PUART_GPIO_OUT);
- }
-
- return num_ports;
-}
-
-static int
-pci_moxa_setup(struct serial_private *priv,
- const struct pciserial_board *board,
- struct uart_8250_port *port, int idx)
-{
- unsigned int bar = FL_GET_BASE(board->flags);
- int offset;
-
- if (!IS_ENABLED(CONFIG_HAS_IOPORT))
- return serial_8250_warn_need_ioport(priv->dev);
-
- if (board->num_ports == 4 && idx == 3)
- offset = 7 * board->uart_offset;
- else
- offset = idx * board->uart_offset;
-
- return setup_port(priv, port, bar, offset, 0);
-}
-
/*
* Master list of serial port init/setup/exit quirks.
* This does not describe the general nature of the port.
@@ -2941,17 +2790,6 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
.setup = pci_fintek_setup,
.init = pci_fintek_init,
},
- /*
- * MOXA
- */
- {
- .vendor = PCI_VENDOR_ID_MOXA,
- .device = PCI_ANY_ID,
- .subvendor = PCI_ANY_ID,
- .subdevice = PCI_ANY_ID,
- .init = pci_moxa_init,
- .setup = pci_moxa_setup,
- },
{
.vendor = 0x1c29,
.device = 0x1204,
@@ -3169,9 +3007,6 @@ enum pci_board_num_t {
pbn_titan_2_4000000,
pbn_titan_4_4000000,
pbn_titan_8_4000000,
- pbn_moxa_2,
- pbn_moxa_4,
- pbn_moxa_8,
};
/*
@@ -3943,24 +3778,6 @@ static struct pciserial_board pci_boards[] = {
.uart_offset = 0x200,
.first_offset = 0x1000,
},
- [pbn_moxa_2] = {
- .flags = FL_BASE1,
- .num_ports = 2,
- .base_baud = 921600,
- .uart_offset = 0x200,
- },
- [pbn_moxa_4] = {
- .flags = FL_BASE1,
- .num_ports = 4,
- .base_baud = 921600,
- .uart_offset = 0x200,
- },
- [pbn_moxa_8] = {
- .flags = FL_BASE1,
- .num_ports = 8,
- .base_baud = 921600,
- .uart_offset = 0x200,
- },
};
#define REPORT_CONFIG(option) \
@@ -4014,6 +3831,9 @@ static const struct pci_device_id blacklist[] = {
{ PCI_VDEVICE(PERICOM, PCI_ANY_ID), REPORT_8250_CONFIG(PERICOM), },
{ PCI_VDEVICE(ACCESSIO, PCI_ANY_ID), REPORT_8250_CONFIG(PERICOM), },
+ /* Moxa devices */
+ { PCI_VDEVICE(MOXA, PCI_ANY_ID), REPORT_8250_CONFIG(MOXA), },
+
/* End of the black list */
{ }
};
@@ -5851,28 +5671,6 @@ static const struct pci_device_id serial_pci_tbl[] = {
PCI_ANY_ID, PCI_ANY_ID, 0, 0,
pbn_ni8430_4 },
- /*
- * MOXA
- */
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102E), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102EL), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102N), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104N), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP112N), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114EL), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114N), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A), pbn_moxa_8 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B), pbn_moxa_8 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A), pbn_moxa_8 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I), pbn_moxa_8 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132EL), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132N), pbn_moxa_2 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134N), pbn_moxa_4 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP138E_A), pbn_moxa_8 },
- { PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A), pbn_moxa_8 },
-
/*
* ADDI-DATA GmbH communication cards <info@addi-data.com>
*/
diff --git a/drivers/tty/serial/8250/Kconfig b/drivers/tty/serial/8250/Kconfig
index f64ef0819cd4..7cf8547d18f6 100644
--- a/drivers/tty/serial/8250/Kconfig
+++ b/drivers/tty/serial/8250/Kconfig
@@ -157,6 +157,17 @@ config SERIAL_8250_EXAR
422x PCIe serial cards that are not covered by the more generic
SERIAL_8250_PCI option.
+config SERIAL_8250_MOXA_PCIE
+ tristate "8250/16550 Moxa PCIe device support"
+ depends on SERIAL_8250 && PCI
+ select SERIAL_8250_PCILIB
+ default SERIAL_8250
+ help
+ Say Y here if you have a Moxa PCIe serial card.
+
+ To compile this driver as a module, choose M here: the
+ module will be called 8250_mxpcie.
+
config SERIAL_8250_HP300
tristate
depends on SERIAL_8250 && HP300
diff --git a/drivers/tty/serial/8250/Makefile b/drivers/tty/serial/8250/Makefile
index 9ec4d5fe64de..be78fd6b337a 100644
--- a/drivers/tty/serial/8250/Makefile
+++ b/drivers/tty/serial/8250/Makefile
@@ -42,6 +42,7 @@ 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
obj-$(CONFIG_SERIAL_8250_MID) += 8250_mid.o
+obj-$(CONFIG_SERIAL_8250_MOXA_PCIE) += 8250_mxpcie.o
obj-$(CONFIG_SERIAL_8250_MT6577) += 8250_mtk.o
obj-$(CONFIG_SERIAL_8250_NI) += 8250_ni.o
obj-$(CONFIG_SERIAL_OF_PLATFORM) += 8250_of.o
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci
2026-05-04 8:48 ` [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci Crescent Hsieh
@ 2026-05-04 13:27 ` Andy Shevchenko
2026-05-04 13:29 ` Andy Shevchenko
2026-05-18 12:53 ` Crescent Hsieh
0 siblings, 2 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-04 13:27 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:49 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> The Moxa PCIe multiport serial boards are currently handled as part of
> 8250_pci.c. In preparation for adding Moxa-specific UART features and
> optimizations, move the Moxa PCIe implementation into a dedicated
> driver.
>
> This introduces drivers/tty/serial/8250/8250_mxpcie.c and wires it up
> via Kconfig and Makefile, while preserving the existing probe flow and
> device IDs.
Thanks for doing this!
> This change was suggested during earlier review by Andy Shevchenko.
an earlier
Perhaps you wanted to add a link references here, something like this
This change was suggested during earlier reviews by Andy Shevchenko [1][2].
> No functional change intended.
> Link: https://lore.kernel.org/all/ZmQovC6TbDpTb3c8@surfacebook.localdomain/
> Link: https://lore.kernel.org/all/CAHp75VeDsVt0GQYUFxLM+obfmqXBPa3hM3YMsFbc26uzWZG-SQ@mail.gmail.com/
...and hence
Link: https://lore.kernel.org/all/ZmQovC6TbDpTb3c8@surfacebook.localdomain/
[1]
Link: https://lore.kernel.org/all/CAHp75VeDsVt0GQYUFxLM+obfmqXBPa3hM3YMsFbc26uzWZG-SQ@mail.gmail.com/
[2]
(note [*] references)
> Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
...
> +#include <linux/module.h>
> +#include <linux/pci.h>
> +#include <linux/device.h>
> +#include <linux/dev_printk.h>
> +#include <linux/types.h>
> +#include <linux/io.h>
> +#include <linux/ioport.h>
> +#include <linux/bits.h>
> +#include <linux/bitfield.h>
Keep above sorted alphabetically, it makes it easier to read and
follow and see if anything is missing or a leftover.
+ blank line (i.o.w. keep the below headers in a separate group as
this driver is 8250 driver)
> +#include <linux/serial_8250.h>
> +#include <linux/serial_core.h>
> +#include <linux/serial_reg.h>
Only the first one is needed.
> +#include <linux/8250_pci.h>
...
> +static unsigned int mxpcie8250_get_supp_rs(unsigned short device)
> +{
> + switch (device & MOXA_DEV_ID_IFACE_MASK) {
> + case 0x0000:
> + case 0x0600:
> + return MOXA_SUPP_RS232;
> + case 0x0100:
> + return MOXA_SUPP_RS232 | MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
> + case 0x0300:
> + return MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
> + }
> +
> + return 0;
Simply make it a default case.
> +}
> +
> +static unsigned short mxpcie8250_get_nports(unsigned short device)
> +{
> + switch (device) {
> + case PCI_DEVICE_ID_MOXA_CP116E_A_A:
> + case PCI_DEVICE_ID_MOXA_CP116E_A_B:
> + return 8;
> + }
> +
> + return FIELD_GET(MOXA_DEV_ID_NPORTS_MASK, device);
Ditto.
> +}
> +
> +static void mxpcie8250_set_interface(struct mxpcie8250 *priv,
> + unsigned int port_idx,
> + u8 mode)
> +{
> + void __iomem *uir_addr = priv->bar2_base + MOXA_UIR_OFFSET + port_idx / 2;
> + u8 cval;
> +
> + cval = ioread8(uir_addr);
> +
> + if (port_idx & 1)
% 2
With them (/2, %2) going closer to each other some compilers gain a
few bytes, see this for example
9b3cd5c7099f ("regmap: place foo / 8 and foo % 8 closer to each other").
> + cval = FIELD_MODIFY(MOXA_ODD_RS_MASK, &cval, mode);
> + else
> + cval = FIELD_MODIFY(MOXA_EVEN_RS_MASK, &cval, mode);
> +
> + iowrite8(cval, uir_addr);
> +}
...
> + priv = devm_kzalloc(dev, struct_size(priv, line, num_ports), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->supp_rs = mxpcie8250_get_supp_rs(device);
> + priv->num_ports = num_ports;
Swap these two lines (by the order) and add __counted_by() to the data
structure.
...
> + for (i = 0; i < num_ports; i++) {
Seems i is not used outside the loop, hence just
for (int i = 0; i < num_ports; i++) {
> + }
...
> +static void mxpcie8250_remove(struct pci_dev *pdev)
> +{
> + struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
platform_get_drvdata() IIRC
> + unsigned int i;
> +
> + for (i = 0; i < priv->num_ports; i++)
As per above.
> + serial8250_unregister_port(priv->line[i]);
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread* Re: [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci
2026-05-04 13:27 ` Andy Shevchenko
@ 2026-05-04 13:29 ` Andy Shevchenko
2026-05-18 12:53 ` Crescent Hsieh
1 sibling, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-04 13:29 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 4:27 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
> On Mon, May 4, 2026 at 11:49 AM Crescent Hsieh
> <crescentcy.hsieh@moxa.com> wrote:
...
> > +static void mxpcie8250_remove(struct pci_dev *pdev)
> > +{
> > + struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
>
> platform_get_drvdata() IIRC
Note, for the sake of consistency the probe may use platform_set_drvdata().
> > + unsigned int i;
> > +
> > + for (i = 0; i < priv->num_ports; i++)
>
> As per above.
>
> > + serial8250_unregister_port(priv->line[i]);
> > +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread* Re: [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci
2026-05-04 13:27 ` Andy Shevchenko
2026-05-04 13:29 ` Andy Shevchenko
@ 2026-05-18 12:53 ` Crescent Hsieh
2026-05-19 7:57 ` Andy Shevchenko
1 sibling, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-18 12:53 UTC (permalink / raw)
To: Andy Shevchenko
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 04, 2026 at 04:27:44PM +0300, Andy Shevchenko wrote:
> On Mon, May 4, 2026 at 11:49 AM Crescent Hsieh
> <crescentcy.hsieh@moxa.com> wrote:
> > +static void mxpcie8250_remove(struct pci_dev *pdev)
> > +{
> > + struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
>
> platform_get_drvdata() IIRC
In a previous patchset, dev_get_drvdata() was suggested for similar
cases [1].
Since 8250_mxpcie is a PCI driver, could you clarify what you would
prefer here for retrieving the private data? I was not sure whether the
intention was to use dev_get_drvdata(), pci_get_drvdata(), or something
else, since platform_get_drvdata() does not seem to match this driver
type.
[1]
https://lore.kernel.org/all/CAHp75VcPanVWaLi39Wf-pq8nA+xbeJUs=v1BACz-+Sns0BVyWg@mail.gmail.com/
---
Sincerely,
Crescent Hsieh
^ permalink raw reply [flat|nested] 25+ messages in thread* Re: [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci
2026-05-18 12:53 ` Crescent Hsieh
@ 2026-05-19 7:57 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-19 7:57 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 18, 2026 at 3:53 PM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
> On Mon, May 04, 2026 at 04:27:44PM +0300, Andy Shevchenko wrote:
> > On Mon, May 4, 2026 at 11:49 AM Crescent Hsieh
> > <crescentcy.hsieh@moxa.com> wrote:
> > > +static void mxpcie8250_remove(struct pci_dev *pdev)
> > > +{
> > > + struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
> >
> > platform_get_drvdata() IIRC
>
> In a previous patchset, dev_get_drvdata() was suggested for similar
> cases [1].
The case is not similar, while looking familiar. Here we have a PCI
device already given as a parameter (sorry, I mixed it with platform
in my previous reply), and there the uart_port, from which you take
device, convert to PCI and use pci_get_drvdata(). There it's a detour
as one may use dev_get_drvdata(port->dev) without PCI being involved.
> Since 8250_mxpcie is a PCI driver, could you clarify what you would
> prefer here for retrieving the private data? I was not sure whether the
> intention was to use dev_get_drvdata(), pci_get_drvdata(), or something
> else, since platform_get_drvdata() does not seem to match this driver
> type.
pci_get_drvdata().
> [1]
> https://lore.kernel.org/all/CAHp75VcPanVWaLi39Wf-pq8nA+xbeJUs=v1BACz-+Sns0BVyWg@mail.gmail.com/
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 02/15] serial: 8250: add Moxa MUEx50 UART port type
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
2026-05-04 8:48 ` [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 03/15] serial: 8250_mxpcie: enable enhanced mode and program FIFO trigger levels Crescent Hsieh
` (12 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Add a new 8250 port type for the Moxa MUEx50 UART and describe its basic
FIFO size and trigger characteristics in the 8250 port configuration
table.
The 8250_mxpcie driver sets UPF_FIXED_TYPE and uses PORT_MUEX50 so that
the generic 8250 core applies the correct defaults.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 3 ++-
drivers/tty/serial/8250/8250_port.c | 8 ++++++++
include/uapi/linux/serial_core.h | 3 +++
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index aa0afdbed791..ec91db1a3008 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -220,7 +220,8 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.dev = dev;
up.port.irq = pdev->irq;
up.port.uartclk = MOXA_PUART_BASE_BAUD * 16;
- up.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ;
+ up.port.flags = UPF_SKIP_TEST | UPF_BOOT_AUTOCONF | UPF_SHARE_IRQ | UPF_FIXED_TYPE;
+ up.port.type = PORT_MUEX50;
up.port.iotype = UPIO_MEM;
up.port.iobase = 0;
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 719faf92aa8a..a17fdb5d68d2 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -310,6 +310,14 @@ static const struct serial8250_config uart_config[] = {
.rxtrig_bytes = {1, 8, 16, 30},
.flags = UART_CAP_FIFO | UART_CAP_AFE,
},
+ [PORT_MUEX50] = {
+ .name = "Moxa MUEx50 UART",
+ .fifo_size = 128,
+ .tx_loadsz = 128,
+ .fcr = UART_FCR_ENABLE_FIFO | UART_FCR_R_TRIG_10,
+ .rxtrig_bytes = {15, 31, 63, 111},
+ .flags = UART_CAP_FIFO,
+ },
};
/* Uart divisor latch read */
diff --git a/include/uapi/linux/serial_core.h b/include/uapi/linux/serial_core.h
index 9c007a106330..377884e3856a 100644
--- a/include/uapi/linux/serial_core.h
+++ b/include/uapi/linux/serial_core.h
@@ -100,6 +100,9 @@
/* TXX9 type number */
#define PORT_TXX9 64
+/* Moxa MUEx50 UART */
+#define PORT_MUEX50 65
+
/*Digi jsm */
#define PORT_JSM 69
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 03/15] serial: 8250_mxpcie: enable enhanced mode and program FIFO trigger levels
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
2026-05-04 8:48 ` [PATCH 01/15] serial: 8250: split Moxa PCIe serial board support out of 8250_pci Crescent Hsieh
2026-05-04 8:48 ` [PATCH 02/15] serial: 8250: add Moxa MUEx50 UART port type Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 15:18 ` Andy Shevchenko
2026-05-04 8:48 ` [PATCH 04/15] serial: 8250_mxpcie: enable automatic RTS/CTS flow control Crescent Hsieh
` (11 subsequent siblings)
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART provides an enhanced register set and programmable FIFO
trigger levels for RX, TX, and flow control.
Enable enhanced mode during port startup and program the MUEx50 FIFO
trigger registers according to the configured port settings. Clear the
programmed state again during shutdown to restore the default UART
configuration.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 50 +++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index ec91db1a3008..7ba96a954bb1 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -49,6 +49,19 @@
#define MOXA_PUART_BASE_BAUD 921600
#define MOXA_PUART_OFFSET 0x200
+/* Special Function Register (SFR) */
+#define MOXA_PUART_SFR 0x07
+#define MOXA_PUART_SFR_950 BIT(5)
+
+/* Enhanced Function Register (EFR) */
+#define MOXA_PUART_EFR 0x0A
+#define MOXA_PUART_EFR_ENHANCED BIT(4)
+
+#define MOXA_PUART_TTL 0x10 /* Tx Interrupt Trigger Level */
+#define MOXA_PUART_RTL 0x11 /* Rx Interrupt Trigger Level */
+#define MOXA_PUART_FCL 0x12 /* Flow Control Low Trigger Level */
+#define MOXA_PUART_FCH 0x13 /* Flow Control High Trigger Level */
+
#define MOXA_GPIO_DIRECTION 0x09
#define MOXA_GPIO_OUTPUT 0x0A
@@ -133,6 +146,40 @@ static void mxpcie8250_set_interface(struct mxpcie8250 *priv,
iowrite8(cval, uir_addr);
}
+static int mxpcie8250_startup(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ unsigned int i;
+ int ret;
+
+ ret = serial8250_do_startup(port);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < 5; ++i)
+ serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
+
+ serial_out(up, MOXA_PUART_EFR, MOXA_PUART_EFR_ENHANCED);
+ serial_out(up, MOXA_PUART_SFR, MOXA_PUART_SFR_950);
+
+ serial_out(up, MOXA_PUART_TTL, 0);
+ serial_out(up, MOXA_PUART_RTL, 96);
+ serial_out(up, MOXA_PUART_FCL, 16);
+ serial_out(up, MOXA_PUART_FCH, 110);
+
+ return 0;
+}
+
+static void mxpcie8250_shutdown(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ serial_out(up, MOXA_PUART_EFR, 0);
+ serial_out(up, MOXA_PUART_SFR, 0);
+
+ serial8250_do_shutdown(port);
+}
+
static void mxpcie8250_init_board(struct pci_dev *pdev, struct mxpcie8250 *priv)
{
void __iomem *bar2_base = priv->bar2_base;
@@ -227,6 +274,9 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.iobase = 0;
up.port.regshift = 0;
+ up.port.startup = mxpcie8250_startup;
+ up.port.shutdown = mxpcie8250_shutdown;
+
for (i = 0; i < num_ports; i++) {
mxpcie8250_setup_port(pdev, priv, &up, i);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 03/15] serial: 8250_mxpcie: enable enhanced mode and program FIFO trigger levels
2026-05-04 8:48 ` [PATCH 03/15] serial: 8250_mxpcie: enable enhanced mode and program FIFO trigger levels Crescent Hsieh
@ 2026-05-04 15:18 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-04 15:18 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:49 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> The MUEx50 UART provides an enhanced register set and programmable FIFO
> trigger levels for RX, TX, and flow control.
>
> Enable enhanced mode during port startup and program the MUEx50 FIFO
> trigger registers according to the configured port settings. Clear the
> programmed state again during shutdown to restore the default UART
> configuration.
...
> +static int mxpcie8250_startup(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> + unsigned int i;
> + int ret;
> +
> + ret = serial8250_do_startup(port);
> + if (ret)
> + return ret;
This needs a good comment explaining the retry logic. Why do we even need this?
> + for (i = 0; i < 5; ++i)
for (unsigned int i ...)
> + serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT);
> +
> + serial_out(up, MOXA_PUART_EFR, MOXA_PUART_EFR_ENHANCED);
> + serial_out(up, MOXA_PUART_SFR, MOXA_PUART_SFR_950);
> +
> + serial_out(up, MOXA_PUART_TTL, 0);
> + serial_out(up, MOXA_PUART_RTL, 96);
> + serial_out(up, MOXA_PUART_FCL, 16);
> + serial_out(up, MOXA_PUART_FCH, 110);
> +
> + return 0;
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 04/15] serial: 8250_mxpcie: enable automatic RTS/CTS flow control
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (2 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 03/15] serial: 8250_mxpcie: enable enhanced mode and program FIFO trigger levels Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 05/15] serial: 8250_mxpcie: offload XON/XOFF flow control to MUEx50 hardware Crescent Hsieh
` (10 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART supports automatic RTS/CTS flow control via the enhanced
feature register.
Implement a mxpcie-specific set_termios() callback that enables MUEx50
auto-RTS/auto-CTS when CRTSCTS is requested and disables it otherwise.
Keep the 8250 port status flags in sync with the hardware configuration.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 28 +++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 7ba96a954bb1..89086aa7b228 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -56,6 +56,10 @@
/* Enhanced Function Register (EFR) */
#define MOXA_PUART_EFR 0x0A
#define MOXA_PUART_EFR_ENHANCED BIT(4)
+#define MOXA_PUART_EFR_AUTO_RTS BIT(6)
+#define MOXA_PUART_EFR_AUTO_CTS BIT(7)
+#define MOXA_PUART_EFR_RX_FLOW_MASK GENMASK(1, 0)
+#define MOXA_PUART_EFR_TX_FLOW_MASK GENMASK(3, 2)
#define MOXA_PUART_TTL 0x10 /* Tx Interrupt Trigger Level */
#define MOXA_PUART_RTL 0x11 /* Rx Interrupt Trigger Level */
@@ -146,6 +150,29 @@ static void mxpcie8250_set_interface(struct mxpcie8250 *priv,
iowrite8(cval, uir_addr);
}
+static void mxpcie8250_set_termios(struct uart_port *port,
+ struct ktermios *new,
+ const struct ktermios *old)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ struct tty_struct *tty = port->state->port.tty;
+ unsigned int cflag = tty->termios.c_cflag;
+ u8 efr;
+
+ serial8250_do_set_termios(port, new, old);
+
+ up->port.status &= ~(UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
+
+ efr = serial_in(up, MOXA_PUART_EFR);
+ efr &= ~(MOXA_PUART_EFR_AUTO_RTS | MOXA_PUART_EFR_AUTO_CTS);
+
+ if (cflag & CRTSCTS) {
+ efr |= (MOXA_PUART_EFR_AUTO_RTS | MOXA_PUART_EFR_AUTO_CTS);
+ up->port.status |= (UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
+ }
+ serial_out(up, MOXA_PUART_EFR, efr);
+}
+
static int mxpcie8250_startup(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
@@ -274,6 +301,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.iobase = 0;
up.port.regshift = 0;
+ up.port.set_termios = mxpcie8250_set_termios;
up.port.startup = mxpcie8250_startup;
up.port.shutdown = mxpcie8250_shutdown;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 05/15] serial: 8250_mxpcie: offload XON/XOFF flow control to MUEx50 hardware
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (3 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 04/15] serial: 8250_mxpcie: enable automatic RTS/CTS flow control Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 15:20 ` Andy Shevchenko
2026-05-04 8:48 ` [PATCH 06/15] serial: 8250_mxpcie: add custom handle_irq callback Crescent Hsieh
` (9 subsequent siblings)
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART can handle in-band software flow control (XON/XOFF)
directly in hardware.
Program the on-chip XON/XOFF characters from termios settings and enable
the corresponding MUEx50 flow control modes when IXON or IXOFF is
requested. Provide throttle and unthrottle callbacks so RX can be
stopped and resumed cleanly.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 62 ++++++++++++++++++++++++++-
1 file changed, 61 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 89086aa7b228..99fd789b7665 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -54,13 +54,31 @@
#define MOXA_PUART_SFR_950 BIT(5)
/* Enhanced Function Register (EFR) */
+/*
+ * EFR[1:0] - In-Band Receive Flow Control Mode (Compare XON/XOFF):
+ * 00b (0x00) = Disabled
+ * 01b (0x01) = Recognize XON2 & XOFF2 as XOFF character
+ * 10b (0x02) = Recognize XON1 & XOFF1 as XOFF character
+ * 11b (0x03) = Depends on EFR[3:2]
+ * EFR[3:2] - In-Band Transmit Flow Control Mode (Insert XON/XOFF):
+ * 00b (0x00) = Disabled
+ * 01b (0x04) = Use XON2 & XOFF2 as XOFF character
+ * 10b (0x08) = Use XON1 & XOFF1 as XOFF character
+ * 11b (0x0C) = Reserved
+ */
#define MOXA_PUART_EFR 0x0A
+#define MOXA_PUART_EFR_RX_FLOW 0x02 /* Recognize XON1 & XOFF1 as XOFF character */
+#define MOXA_PUART_EFR_TX_FLOW 0x08 /* Use XON1 & XOFF1 as XOFF character */
#define MOXA_PUART_EFR_ENHANCED BIT(4)
#define MOXA_PUART_EFR_AUTO_RTS BIT(6)
#define MOXA_PUART_EFR_AUTO_CTS BIT(7)
#define MOXA_PUART_EFR_RX_FLOW_MASK GENMASK(1, 0)
#define MOXA_PUART_EFR_TX_FLOW_MASK GENMASK(3, 2)
+#define MOXA_PUART_XON1 0x0B
+#define MOXA_PUART_XON2 0x0C
+#define MOXA_PUART_XOFF1 0x0D
+#define MOXA_PUART_XOFF2 0x0E
#define MOXA_PUART_TTL 0x10 /* Tx Interrupt Trigger Level */
#define MOXA_PUART_RTL 0x11 /* Rx Interrupt Trigger Level */
#define MOXA_PUART_FCL 0x12 /* Flow Control Low Trigger Level */
@@ -161,7 +179,7 @@ static void mxpcie8250_set_termios(struct uart_port *port,
serial8250_do_set_termios(port, new, old);
- up->port.status &= ~(UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
+ up->port.status &= ~(UPSTAT_AUTORTS | UPSTAT_AUTOCTS | UPSTAT_AUTOXOFF);
efr = serial_in(up, MOXA_PUART_EFR);
efr &= ~(MOXA_PUART_EFR_AUTO_RTS | MOXA_PUART_EFR_AUTO_CTS);
@@ -170,6 +188,21 @@ static void mxpcie8250_set_termios(struct uart_port *port,
efr |= (MOXA_PUART_EFR_AUTO_RTS | MOXA_PUART_EFR_AUTO_CTS);
up->port.status |= (UPSTAT_AUTORTS | UPSTAT_AUTOCTS);
}
+ /* Set on-chip software flow control character */
+ serial_out(up, MOXA_PUART_XON1, START_CHAR(tty));
+ serial_out(up, MOXA_PUART_XON2, START_CHAR(tty));
+ serial_out(up, MOXA_PUART_XOFF1, STOP_CHAR(tty));
+ serial_out(up, MOXA_PUART_XOFF2, STOP_CHAR(tty));
+
+ efr &= ~(MOXA_PUART_EFR_RX_FLOW_MASK | MOXA_PUART_EFR_TX_FLOW_MASK);
+
+ if (I_IXON(tty))
+ efr |= MOXA_PUART_EFR_RX_FLOW;
+
+ if (I_IXOFF(tty)) {
+ efr |= MOXA_PUART_EFR_TX_FLOW;
+ up->port.status |= UPSTAT_AUTOXOFF;
+ }
serial_out(up, MOXA_PUART_EFR, efr);
}
@@ -207,6 +240,31 @@ static void mxpcie8250_shutdown(struct uart_port *port)
serial8250_do_shutdown(port);
}
+static void mxpcie8250_throttle(struct uart_port *port)
+{
+ unsigned long flags;
+
+ uart_port_lock_irqsave(port, &flags);
+
+ port->ops->stop_rx(port);
+
+ uart_port_unlock_irqrestore(port, flags);
+}
+
+static void mxpcie8250_unthrottle(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ unsigned long flags;
+
+ uart_port_lock_irqsave(port, &flags);
+
+ up->ier |= UART_IER_RLSI | UART_IER_RDI;
+ port->read_status_mask |= UART_LSR_DR;
+ serial_out(up, UART_IER, up->ier);
+
+ uart_port_unlock_irqrestore(port, flags);
+}
+
static void mxpcie8250_init_board(struct pci_dev *pdev, struct mxpcie8250 *priv)
{
void __iomem *bar2_base = priv->bar2_base;
@@ -304,6 +362,8 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.set_termios = mxpcie8250_set_termios;
up.port.startup = mxpcie8250_startup;
up.port.shutdown = mxpcie8250_shutdown;
+ up.port.throttle = mxpcie8250_throttle;
+ up.port.unthrottle = mxpcie8250_unthrottle;
for (i = 0; i < num_ports; i++) {
mxpcie8250_setup_port(pdev, priv, &up, i);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 05/15] serial: 8250_mxpcie: offload XON/XOFF flow control to MUEx50 hardware
2026-05-04 8:48 ` [PATCH 05/15] serial: 8250_mxpcie: offload XON/XOFF flow control to MUEx50 hardware Crescent Hsieh
@ 2026-05-04 15:20 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-04 15:20 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:50 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> The MUEx50 UART can handle in-band software flow control (XON/XOFF)
> directly in hardware.
>
> Program the on-chip XON/XOFF characters from termios settings and enable
> the corresponding MUEx50 flow control modes when IXON or IXOFF is
> requested. Provide throttle and unthrottle callbacks so RX can be
> stopped and resumed cleanly.
...
> +static void mxpcie8250_throttle(struct uart_port *port)
> +{
> + unsigned long flags;
> + uart_port_lock_irqsave(port, &flags);
You may use guard()() from cleanup.h.
> + port->ops->stop_rx(port);
> +
> + uart_port_unlock_irqrestore(port, flags);
> +}
> +
> +static void mxpcie8250_unthrottle(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> + unsigned long flags;
> +
> + uart_port_lock_irqsave(port, &flags);
> +
> + up->ier |= UART_IER_RLSI | UART_IER_RDI;
> + port->read_status_mask |= UART_LSR_DR;
> + serial_out(up, UART_IER, up->ier);
> +
> + uart_port_unlock_irqrestore(port, flags);
Ditto.
> +}
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 06/15] serial: 8250_mxpcie: add custom handle_irq callback
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (4 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 05/15] serial: 8250_mxpcie: offload XON/XOFF flow control to MUEx50 hardware Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 07/15] serial: 8250_mxpcie: speed up RX using memory-mapped FIFO window Crescent Hsieh
` (8 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Add a mxpcie-specific handle_irq() implementation for Moxa PCIe serial
ports.
This keeps the interrupt handling self-contained in the driver and
provides a hook point for MUEx50-specific RX/TX paths added in subsequent
patches. The handler processes RX, updates modem status, and handles TX
when THRE is asserted.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 48 +++++++++++++++++++++++++++
1 file changed, 48 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 99fd789b7665..9860f2ac2572 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -265,6 +265,53 @@ static void mxpcie8250_unthrottle(struct uart_port *port)
uart_port_unlock_irqrestore(port, flags);
}
+static u16 mxpcie8250_rx_chars(struct uart_8250_port *up, u16 lsr)
+{
+ struct uart_port *port = &up->port;
+
+ if (!(lsr & (UART_LSR_DR | UART_LSR_BI)))
+ return lsr;
+
+ if (!(port->status & (UPSTAT_AUTOCTS | UPSTAT_AUTORTS)))
+ goto do_rx;
+ if (lsr & (UART_LSR_FIFOE | UART_LSR_BRK_ERROR_BITS))
+ goto do_rx;
+ if (port->read_status_mask & UART_LSR_DR)
+ goto do_rx;
+
+ return lsr;
+
+do_rx:
+ return serial8250_rx_chars(up, lsr);
+}
+
+static int mxpcie8250_handle_irq(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ unsigned long flags;
+ u16 lsr;
+ u8 iir;
+
+ iir = serial_in(up, UART_IIR);
+ if (iir & UART_IIR_NO_INT)
+ return 0;
+
+ uart_port_lock_irqsave(port, &flags);
+
+ lsr = serial_lsr_in(up);
+
+ lsr = mxpcie8250_rx_chars(up, lsr);
+
+ serial8250_modem_status(up);
+
+ if ((lsr & UART_LSR_THRE) && (up->ier & UART_IER_THRI))
+ serial8250_tx_chars(up);
+
+ uart_unlock_and_check_sysrq_irqrestore(port, flags);
+
+ return 1;
+}
+
static void mxpcie8250_init_board(struct pci_dev *pdev, struct mxpcie8250 *priv)
{
void __iomem *bar2_base = priv->bar2_base;
@@ -364,6 +411,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.shutdown = mxpcie8250_shutdown;
up.port.throttle = mxpcie8250_throttle;
up.port.unthrottle = mxpcie8250_unthrottle;
+ up.port.handle_irq = mxpcie8250_handle_irq;
for (i = 0; i < num_ports; i++) {
mxpcie8250_setup_port(pdev, priv, &up, i);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 07/15] serial: 8250_mxpcie: speed up RX using memory-mapped FIFO window
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (5 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 06/15] serial: 8250_mxpcie: add custom handle_irq callback Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 08/15] serial: 8250_mxpcie: speed up TX " Crescent Hsieh
` (7 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART provides a memory-mapped RX FIFO data window along with
an RX FIFO byte counter.
When no break or error conditions are present, read received data in
bulk via the MMIO FIFO window and push it to the tty layer in one
operation. Fall back to the generic 8250 RX path for break and error
handling.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 32 +++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 9860f2ac2572..f13fcb090df7 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -17,6 +17,7 @@
#include <linux/serial_8250.h>
#include <linux/serial_core.h>
#include <linux/serial_reg.h>
+#include <linux/tty_flip.h>
#include <linux/8250_pci.h>
#include "8250.h"
@@ -48,6 +49,7 @@
/* UART */
#define MOXA_PUART_BASE_BAUD 921600
#define MOXA_PUART_OFFSET 0x200
+#define MOXA_PUART_FIFO_SIZE 128
/* Special Function Register (SFR) */
#define MOXA_PUART_SFR 0x07
@@ -83,6 +85,9 @@
#define MOXA_PUART_RTL 0x11 /* Rx Interrupt Trigger Level */
#define MOXA_PUART_FCL 0x12 /* Flow Control Low Trigger Level */
#define MOXA_PUART_FCH 0x13 /* Flow Control High Trigger Level */
+#define MOXA_PUART_RX_FIFO_CNT 0x15 /* Rx FIFO Data Counter */
+
+#define MOXA_PUART_RX_FIFO_MEM 0x100 /* Memory Space to Rx FIFO Data Register */
#define MOXA_GPIO_DIRECTION 0x09
#define MOXA_GPIO_OUTPUT 0x0A
@@ -265,6 +270,29 @@ static void mxpcie8250_unthrottle(struct uart_port *port)
uart_port_unlock_irqrestore(port, flags);
}
+static void mxpcie8250_do_rx_chars(struct uart_8250_port *up)
+{
+ struct uart_port *port = &up->port;
+ struct tty_port *tport = &port->state->port;
+ u8 buf[MOXA_PUART_FIFO_SIZE];
+ int recv_room, gdl, i;
+
+ recv_room = tty_buffer_request_room(tport, port->fifosize);
+ if (!recv_room)
+ return;
+
+ gdl = serial_in(up, MOXA_PUART_RX_FIFO_CNT);
+ if (gdl > recv_room)
+ gdl = recv_room;
+
+ for (i = 0; i < gdl; ++i)
+ buf[i] = serial_in(up, MOXA_PUART_RX_FIFO_MEM + i);
+
+ port->icount.rx += gdl;
+ tty_insert_flip_string(tport, buf, gdl);
+ tty_flip_buffer_push(tport);
+}
+
static u16 mxpcie8250_rx_chars(struct uart_8250_port *up, u16 lsr)
{
struct uart_port *port = &up->port;
@@ -282,6 +310,10 @@ static u16 mxpcie8250_rx_chars(struct uart_8250_port *up, u16 lsr)
return lsr;
do_rx:
+ if (!(lsr & UART_LSR_BRK_ERROR_BITS)) {
+ mxpcie8250_do_rx_chars(up);
+ return lsr;
+ }
return serial8250_rx_chars(up, lsr);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 08/15] serial: 8250_mxpcie: speed up TX using memory-mapped FIFO window
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (6 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 07/15] serial: 8250_mxpcie: speed up RX using memory-mapped FIFO window Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 09/15] serial: 8250_mxpcie: introduce per-port private data structure Crescent Hsieh
` (6 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART provides a memory-mapped TX FIFO data window along with
a TX FIFO level counter.
Fill the TX FIFO in bulk via the MMIO FIFO window based on available
FIFO space, and use this path from the mxpcie interrupt handler instead
of the generic serial8250_tx_chars() helper.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 35 ++++++++++++++++++++++++++-
1 file changed, 34 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index f13fcb090df7..5fe07f6947ef 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -86,8 +86,10 @@
#define MOXA_PUART_FCL 0x12 /* Flow Control Low Trigger Level */
#define MOXA_PUART_FCH 0x13 /* Flow Control High Trigger Level */
#define MOXA_PUART_RX_FIFO_CNT 0x15 /* Rx FIFO Data Counter */
+#define MOXA_PUART_TX_FIFO_CNT 0x16 /* Tx FIFO Data Counter */
#define MOXA_PUART_RX_FIFO_MEM 0x100 /* Memory Space to Rx FIFO Data Register */
+#define MOXA_PUART_TX_FIFO_MEM 0x100 /* Memory Space to Tx FIFO Data Register */
#define MOXA_GPIO_DIRECTION 0x09
#define MOXA_GPIO_OUTPUT 0x0A
@@ -317,6 +319,37 @@ static u16 mxpcie8250_rx_chars(struct uart_8250_port *up, u16 lsr)
return serial8250_rx_chars(up, lsr);
}
+static void mxpcie8250_tx_chars(struct uart_8250_port *up)
+{
+ struct uart_port *port = &up->port;
+ struct tty_port *tport = &port->state->port;
+ unsigned int i, count, txsize;
+ unsigned char c;
+
+ if (port->x_char) {
+ uart_xchar_out(port, UART_TX);
+ return;
+ }
+ if (uart_tx_stopped(port) || kfifo_is_empty(&tport->xmit_fifo)) {
+ port->ops->stop_tx(port);
+ return;
+ }
+ txsize = serial_in(up, MOXA_PUART_TX_FIFO_CNT);
+ count = min(kfifo_len(&tport->xmit_fifo), port->fifosize - txsize);
+
+ for (i = 0; i < count; ++i) {
+ if (!uart_fifo_get(port, &c))
+ break;
+
+ serial_out(up, MOXA_PUART_TX_FIFO_MEM + i, c);
+ }
+ if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
+ uart_write_wakeup(port);
+
+ if (kfifo_is_empty(&tport->xmit_fifo) && !(up->capabilities & UART_CAP_RPM))
+ port->ops->stop_tx(port);
+}
+
static int mxpcie8250_handle_irq(struct uart_port *port)
{
struct uart_8250_port *up = up_to_u8250p(port);
@@ -337,7 +370,7 @@ static int mxpcie8250_handle_irq(struct uart_port *port)
serial8250_modem_status(up);
if ((lsr & UART_LSR_THRE) && (up->ier & UART_IER_THRI))
- serial8250_tx_chars(up);
+ mxpcie8250_tx_chars(up);
uart_unlock_and_check_sysrq_irqrestore(port, flags);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 09/15] serial: 8250_mxpcie: introduce per-port private data structure
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (7 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 08/15] serial: 8250_mxpcie: speed up TX " Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 10/15] serial: 8250_mxpcie: defer uart_write_wakeup() to workqueue Crescent Hsieh
` (5 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Introduce a private per-port data structure for the mxpcie driver and
replace the shared flexible array of registered lines with an array of
per-port objects.
This prepares the driver for storing per-port state needed by subsequent
features.
No functional change intended.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 5fe07f6947ef..19233c3c5f1f 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -105,12 +105,16 @@
#define MOXA_EVEN_RS_MASK GENMASK(3, 0)
#define MOXA_ODD_RS_MASK GENMASK(7, 4)
+struct mxpcie8250_port {
+ int line;
+};
+
struct mxpcie8250 {
unsigned int supp_rs;
unsigned int num_ports;
void __iomem *bar1_base; /* UART registers (MMIO) */
void __iomem *bar2_base; /* UIR / GPIO / CPLD (IO) */
- int line[];
+ struct mxpcie8250_port port[];
};
enum {
@@ -444,7 +448,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
num_ports = mxpcie8250_get_nports(device);
- priv = devm_kzalloc(dev, struct_size(priv, line, num_ports), GFP_KERNEL);
+ priv = devm_kzalloc(dev, struct_size(priv, port, num_ports), GFP_KERNEL);
if (!priv)
return -ENOMEM;
@@ -484,12 +488,12 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
dev_dbg(dev, "Setup PCI port: port %lx, irq %d, type %d\n",
up.port.iobase, up.port.irq, up.port.iotype);
- priv->line[i] = serial8250_register_8250_port(&up);
- if (priv->line[i] < 0) {
+ priv->port[i].line = serial8250_register_8250_port(&up);
+ if (priv->port[i].line < 0) {
dev_err(dev,
"Couldn't register serial port %lx, irq %d, type %d, error %d\n",
up.port.iobase, up.port.irq,
- up.port.iotype, priv->line[i]);
+ up.port.iotype, priv->port[i].line);
break;
}
}
@@ -504,7 +508,7 @@ static void mxpcie8250_remove(struct pci_dev *pdev)
unsigned int i;
for (i = 0; i < priv->num_ports; i++)
- serial8250_unregister_port(priv->line[i]);
+ serial8250_unregister_port(priv->port[i].line);
}
static const struct pci_device_id mxpcie8250_pci_ids[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 10/15] serial: 8250_mxpcie: defer uart_write_wakeup() to workqueue
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (8 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 09/15] serial: 8250_mxpcie: introduce per-port private data structure Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 11/15] serial: 8250_mxpcie: support serial interface mode switching Crescent Hsieh
` (4 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Avoid calling uart_write_wakeup() directly from the interrupt-driven TX
path.
Defer the wakeup to a per-port work item and coalesce multiple TX events
using a pending flag, so only one wakeup is scheduled while a previous
one is still outstanding.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 34 +++++++++++++++++++++++----
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 19233c3c5f1f..8dc1b7b0af04 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -18,6 +18,7 @@
#include <linux/serial_core.h>
#include <linux/serial_reg.h>
#include <linux/tty_flip.h>
+#include <linux/workqueue.h>
#include <linux/8250_pci.h>
#include "8250.h"
@@ -105,8 +106,13 @@
#define MOXA_EVEN_RS_MASK GENMASK(3, 0)
#define MOXA_ODD_RS_MASK GENMASK(7, 4)
+#define MOXA_EVENT_TXLOW BIT(0)
+
struct mxpcie8250_port {
int line;
+ unsigned long event_flags;
+ struct uart_port *port;
+ struct work_struct work;
};
struct mxpcie8250 {
@@ -327,6 +333,8 @@ static void mxpcie8250_tx_chars(struct uart_8250_port *up)
{
struct uart_port *port = &up->port;
struct tty_port *tport = &port->state->port;
+ struct device *dev = port->dev;
+ struct mxpcie8250 *priv = dev_get_drvdata(dev);
unsigned int i, count, txsize;
unsigned char c;
@@ -347,9 +355,10 @@ static void mxpcie8250_tx_chars(struct uart_8250_port *up)
serial_out(up, MOXA_PUART_TX_FIFO_MEM + i, c);
}
- if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS)
- uart_write_wakeup(port);
-
+ if (kfifo_len(&tport->xmit_fifo) < WAKEUP_CHARS) {
+ if (!test_and_set_bit(MOXA_EVENT_TXLOW, &priv->port[port->port_id].event_flags))
+ schedule_work(&priv->port[port->port_id].work);
+ }
if (kfifo_is_empty(&tport->xmit_fifo) && !(up->capabilities & UART_CAP_RPM))
port->ops->stop_tx(port);
}
@@ -381,6 +390,14 @@ static int mxpcie8250_handle_irq(struct uart_port *port)
return 1;
}
+static void mxpcie8250_work_handler(struct work_struct *work)
+{
+ struct mxpcie8250_port *priv_port = container_of(work, struct mxpcie8250_port, work);
+
+ if (test_and_clear_bit(MOXA_EVENT_TXLOW, &priv_port->event_flags))
+ uart_write_wakeup(priv_port->port);
+}
+
static void mxpcie8250_init_board(struct pci_dev *pdev, struct mxpcie8250 *priv)
{
void __iomem *bar2_base = priv->bar2_base;
@@ -436,7 +453,7 @@ static void mxpcie8250_setup_port(struct pci_dev *pdev,
static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id)
{
struct device *dev = &pdev->dev;
- struct uart_8250_port up = {};
+ struct uart_8250_port up = {}, *new_port;
struct mxpcie8250 *priv;
unsigned short device = pdev->device;
unsigned int i, num_ports;
@@ -496,6 +513,11 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.iotype, priv->port[i].line);
break;
}
+ new_port = serial8250_get_port(priv->port[i].line);
+
+ priv->port[i].port = &new_port->port;
+
+ INIT_WORK(&priv->port[i].work, mxpcie8250_work_handler);
}
dev_set_drvdata(dev, priv);
@@ -507,8 +529,10 @@ static void mxpcie8250_remove(struct pci_dev *pdev)
struct mxpcie8250 *priv = dev_get_drvdata(&pdev->dev);
unsigned int i;
- for (i = 0; i < priv->num_ports; i++)
+ for (i = 0; i < priv->num_ports; i++) {
+ cancel_work_sync(&priv->port[i].work);
serial8250_unregister_port(priv->port[i].line);
+ }
}
static const struct pci_device_id mxpcie8250_pci_ids[] = {
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 11/15] serial: 8250_mxpcie: support serial interface mode switching
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (9 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 10/15] serial: 8250_mxpcie: defer uart_write_wakeup() to workqueue Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 12/15] serial: 8250: allow low-level drivers to override break control Crescent Hsieh
` (3 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Moxa PCIe multiport serial boards support switching the serial interface
mode between RS232, RS422, RS485-2W, and RS485-4W via on-board control
registers.
Implement an rs485_config() callback and map TIOCSRS485 requests to the
corresponding hardware modes using serial_rs485 flags:
- RS232 = (no flags set)
- RS422 = SER_RS485_ENABLED | SER_RS485_MODE_RS422
- RS485_2W (half-duplex) = SER_RS485_ENABLED
- RS485_4W (full-duplex) = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
This allows users to reconfigure the serial mode at runtime via ioctl().
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 45 +++++++++++++++++++++++++--
1 file changed, 43 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 8dc1b7b0af04..94c3552b9798 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -129,6 +129,10 @@ enum {
MOXA_SUPP_RS485 = BIT(2),
};
+static const struct serial_rs485 mxpcie8250_rs485_supported = {
+ .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX | SER_RS485_MODE_RS422,
+};
+
static bool mxpcie8250_is_mini_pcie(unsigned short device)
{
if (device == PCI_DEVICE_ID_MOXA_CP102N ||
@@ -185,6 +189,38 @@ static void mxpcie8250_set_interface(struct mxpcie8250 *priv,
iowrite8(cval, uir_addr);
}
+/*
+ * Moxa PCIe multiport serial boards support switching serial interfaces
+ * via the ioctl() command "TIOCSRS485". Supported modes and corresponding
+ * flags in "serial_rs485":
+ *
+ * RS232 = (no flags set)
+ * RS422 = SER_RS485_ENABLED | SER_RS485_MODE_RS422
+ * RS485_2W (half-duplex) = SER_RS485_ENABLED
+ * RS485_4W (full-duplex) = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
+ */
+static int mxpcie8250_rs485_config(struct uart_port *port,
+ struct ktermios *termios,
+ struct serial_rs485 *rs485)
+{
+ struct mxpcie8250 *priv = dev_get_drvdata(port->dev);
+ u8 mode = MOXA_UIR_RS232;
+
+ if (rs485->flags & SER_RS485_ENABLED) {
+ if (rs485->flags & SER_RS485_MODE_RS422)
+ mode = MOXA_UIR_RS422;
+ else if (rs485->flags & SER_RS485_RX_DURING_TX)
+ mode = MOXA_UIR_RS485_4W;
+ else
+ mode = MOXA_UIR_RS485_2W;
+ } else if (!(priv->supp_rs & MOXA_SUPP_RS232)) {
+ return -ENODEV;
+ }
+ mxpcie8250_set_interface(priv, port->port_id, mode);
+
+ return 0;
+}
+
static void mxpcie8250_set_termios(struct uart_port *port,
struct ktermios *new,
const struct ktermios *old)
@@ -435,9 +471,14 @@ static void mxpcie8250_setup_port(struct pci_dev *pdev,
int offset = idx * MOXA_PUART_OFFSET;
u8 init_mode = MOXA_UIR_RS232;
- if (!(priv->supp_rs & MOXA_SUPP_RS232))
+ if (priv->supp_rs & MOXA_SUPP_RS485) {
+ up->port.rs485_config = mxpcie8250_rs485_config;
+ up->port.rs485_supported = mxpcie8250_rs485_supported;
+ }
+ if (!(priv->supp_rs & MOXA_SUPP_RS232)) {
init_mode = MOXA_UIR_RS422;
-
+ up->port.rs485.flags = SER_RS485_ENABLED | SER_RS485_MODE_RS422;
+ }
mxpcie8250_set_interface(priv, idx, init_mode);
if (idx == 3 &&
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 12/15] serial: 8250: allow low-level drivers to override break control
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (10 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 11/15] serial: 8250_mxpcie: support serial interface mode switching Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-04 8:48 ` [PATCH 13/15] serial: 8250_mxpcie: add break support for RS485 using MUEx50 features Crescent Hsieh
` (2 subsequent siblings)
14 siblings, 0 replies; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
Some UARTs require driver-specific handling for break signaling, which
cannot be expressed by the generic 8250 break implementation alone.
Add an optional uart_port break_ctl callback and route
serial8250_break_ctl() through it when provided. Rename the existing
8250 implementation to serial8250_do_break_ctl() and export it under the
SERIAL_8250_PCI namespace so low-level drivers can reuse the default
8250 behavior when appropriate.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_core.c | 2 ++
drivers/tty/serial/8250/8250_port.c | 11 ++++++++++-
include/linux/serial_8250.h | 1 +
include/linux/serial_core.h | 1 +
4 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index bfa421ab3253..0a3355eb4bc3 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -796,6 +796,8 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
uart->port.startup = up->port.startup;
if (up->port.shutdown)
uart->port.shutdown = up->port.shutdown;
+ if (up->port.break_ctl)
+ uart->port.break_ctl = up->port.break_ctl;
if (up->port.pm)
uart->port.pm = up->port.pm;
if (up->port.handle_break)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index a17fdb5d68d2..72ecc0112b8a 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -1937,7 +1937,7 @@ static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
serial8250_do_set_mctrl(port, mctrl);
}
-static void serial8250_break_ctl(struct uart_port *port, int break_state)
+void serial8250_do_break_ctl(struct uart_port *port, int break_state)
{
struct uart_8250_port *up = up_to_u8250p(port);
@@ -1950,6 +1950,15 @@ static void serial8250_break_ctl(struct uart_port *port, int break_state)
up->lcr &= ~UART_LCR_SBC;
serial_port_out(port, UART_LCR, up->lcr);
}
+EXPORT_SYMBOL_NS_GPL(serial8250_do_break_ctl, "SERIAL_8250_PCI");
+
+static void serial8250_break_ctl(struct uart_port *port, int break_state)
+{
+ if (port->break_ctl)
+ port->break_ctl(port, break_state);
+ else
+ serial8250_do_break_ctl(port, break_state);
+}
/* Returns true if @bits were set, false on timeout */
static bool wait_for_lsr(struct uart_8250_port *up, int bits)
diff --git a/include/linux/serial_8250.h b/include/linux/serial_8250.h
index 01efdce0fda0..5ae00dede026 100644
--- a/include/linux/serial_8250.h
+++ b/include/linux/serial_8250.h
@@ -192,6 +192,7 @@ void serial8250_do_shutdown(struct uart_port *port);
void serial8250_do_pm(struct uart_port *port, unsigned int state,
unsigned int oldstate);
void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);
+void serial8250_do_break_ctl(struct uart_port *port, int break_state);
void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
unsigned int quot);
int fsl8250_handle_irq(struct uart_port *port);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 666430b47899..d9e5e3d02003 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -463,6 +463,7 @@ struct uart_port {
void (*shutdown)(struct uart_port *port);
void (*throttle)(struct uart_port *port);
void (*unthrottle)(struct uart_port *port);
+ void (*break_ctl)(struct uart_port *port, int break_state);
int (*handle_irq)(struct uart_port *);
void (*pm)(struct uart_port *, unsigned int state,
unsigned int old);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* [PATCH 13/15] serial: 8250_mxpcie: add break support for RS485 using MUEx50 features
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (11 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 12/15] serial: 8250: allow low-level drivers to override break control Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-05 9:25 ` Andy Shevchenko
2026-05-04 8:48 ` [PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling Crescent Hsieh
2026-05-04 8:49 ` [PATCH 15/15] serial: 8250_mxpcie: implement rx_trig_bytes callbacks via MUEx50 RTL Crescent Hsieh
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
On MUEx50, break signaling under RS485 requires a driver-specific
sequence and cannot be handled correctly by the generic 8250 break
implementation alone.
Implement a mxpcie break_ctl callback that performs MUEx50-specific
break handling when RS485 is enabled and fall back to the default 8250
break handling for other modes.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 52 +++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 94c3552b9798..5bf15ca78228 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -54,6 +54,7 @@
/* Special Function Register (SFR) */
#define MOXA_PUART_SFR 0x07
+#define MOXA_PUART_SFR_FORCE_TX BIT(0)
#define MOXA_PUART_SFR_950 BIT(5)
/* Enhanced Function Register (EFR) */
@@ -426,6 +427,56 @@ static int mxpcie8250_handle_irq(struct uart_port *port)
return 1;
}
+static void mxpcie8250_software_break_ctl(struct uart_port *port, int break_state)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+ struct tty_struct *tty = port->state->port.tty;
+ unsigned char tx_byte = 0x01;
+ unsigned int baud, quot;
+ unsigned long flags;
+ u8 sfr;
+
+ uart_port_lock_irqsave(port, &flags);
+
+ if (break_state == -1) {
+ serial_out(up, UART_LCR, up->lcr | UART_LCR_DLAB);
+ serial_out(up, UART_DLL, 0);
+ serial_out(up, UART_DLM, 0);
+ serial_out(up, UART_LCR, up->lcr);
+
+ serial_out(up, MOXA_PUART_TX_FIFO_MEM, tx_byte);
+
+ sfr = serial_in(up, MOXA_PUART_SFR);
+ serial_out(up, MOXA_PUART_SFR, sfr | MOXA_PUART_SFR_FORCE_TX);
+
+ up->lcr |= UART_LCR_SBC;
+ serial_out(up, UART_LCR, up->lcr);
+ } else {
+ up->lcr &= ~UART_LCR_SBC;
+ serial_out(up, UART_LCR, up->lcr);
+
+ sfr = serial_in(up, MOXA_PUART_SFR);
+ serial_out(up, MOXA_PUART_SFR, sfr &= ~MOXA_PUART_SFR_FORCE_TX);
+
+ serial_out(up, UART_FCR, UART_FCR_CLEAR_XMIT);
+
+ baud = tty_get_baud_rate(tty);
+ quot = uart_get_divisor(port, baud);
+ serial8250_do_set_divisor(port, baud, quot);
+ serial_out(up, UART_LCR, up->lcr);
+ }
+ uart_port_unlock_irqrestore(port, flags);
+}
+
+static void mxpcie8250_break_ctl(struct uart_port *port, int break_state)
+{
+ if (port->rs485.flags & SER_RS485_ENABLED &&
+ !(port->rs485.flags & SER_RS485_MODE_RS422))
+ mxpcie8250_software_break_ctl(port, break_state);
+ else
+ serial8250_do_break_ctl(port, break_state);
+}
+
static void mxpcie8250_work_handler(struct work_struct *work)
{
struct mxpcie8250_port *priv_port = container_of(work, struct mxpcie8250_port, work);
@@ -539,6 +590,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.throttle = mxpcie8250_throttle;
up.port.unthrottle = mxpcie8250_unthrottle;
up.port.handle_irq = mxpcie8250_handle_irq;
+ up.port.break_ctl = mxpcie8250_break_ctl;
for (i = 0; i < num_ports; i++) {
mxpcie8250_setup_port(pdev, priv, &up, i);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 13/15] serial: 8250_mxpcie: add break support for RS485 using MUEx50 features
2026-05-04 8:48 ` [PATCH 13/15] serial: 8250_mxpcie: add break support for RS485 using MUEx50 features Crescent Hsieh
@ 2026-05-05 9:25 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-05 9:25 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:51 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> On MUEx50, break signaling under RS485 requires a driver-specific
> sequence and cannot be handled correctly by the generic 8250 break
> implementation alone.
>
> Implement a mxpcie break_ctl callback that performs MUEx50-specific
> break handling when RS485 is enabled and fall back to the default 8250
> break handling for other modes.
...
> + uart_port_lock_irqsave(port, &flags);
guard()() ?
> +
> + if (break_state == -1) {
> + serial_out(up, UART_LCR, up->lcr | UART_LCR_DLAB);
> + serial_out(up, UART_DLL, 0);
> + serial_out(up, UART_DLM, 0);
> + serial_out(up, UART_LCR, up->lcr);
Don't we have a helper doing this?
serial_dl_write()
> + serial_out(up, MOXA_PUART_TX_FIFO_MEM, tx_byte);
> +
> + sfr = serial_in(up, MOXA_PUART_SFR);
> + serial_out(up, MOXA_PUART_SFR, sfr | MOXA_PUART_SFR_FORCE_TX);
> +
> + up->lcr |= UART_LCR_SBC;
> + serial_out(up, UART_LCR, up->lcr);
> + } else {
> + up->lcr &= ~UART_LCR_SBC;
> + serial_out(up, UART_LCR, up->lcr);
> +
> + sfr = serial_in(up, MOXA_PUART_SFR);
> + serial_out(up, MOXA_PUART_SFR, sfr &= ~MOXA_PUART_SFR_FORCE_TX);
> +
> + serial_out(up, UART_FCR, UART_FCR_CLEAR_XMIT);
> +
> + baud = tty_get_baud_rate(tty);
> + quot = uart_get_divisor(port, baud);
> + serial8250_do_set_divisor(port, baud, quot);
> + serial_out(up, UART_LCR, up->lcr);
> + }
> + uart_port_unlock_irqrestore(port, flags);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (12 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 13/15] serial: 8250_mxpcie: add break support for RS485 using MUEx50 features Crescent Hsieh
@ 2026-05-04 8:48 ` Crescent Hsieh
2026-05-05 9:30 ` Andy Shevchenko
2026-05-04 8:49 ` [PATCH 15/15] serial: 8250_mxpcie: implement rx_trig_bytes callbacks via MUEx50 RTL Crescent Hsieh
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:48 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The rx_trig_bytes sysfs attribute currently relies on 8250-internal
helper functions and assumes a fixed mapping between trigger levels and
FIFO behavior.
Some UARTs provide hardware-specific RX trigger mechanisms that do not
fit this model. Add optional uart_port callbacks for setting and getting
the RX trigger level, and use them when provided, while preserving the
existing 8250 helpers as the default fallback.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_core.c | 4 ++++
drivers/tty/serial/8250/8250_port.c | 14 ++++++++++++--
include/linux/serial_core.h | 2 ++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/tty/serial/8250/8250_core.c b/drivers/tty/serial/8250/8250_core.c
index 0a3355eb4bc3..a0a53b642d6c 100644
--- a/drivers/tty/serial/8250/8250_core.c
+++ b/drivers/tty/serial/8250/8250_core.c
@@ -802,6 +802,10 @@ int serial8250_register_8250_port(const struct uart_8250_port *up)
uart->port.pm = up->port.pm;
if (up->port.handle_break)
uart->port.handle_break = up->port.handle_break;
+ if (up->port.set_rxtrig)
+ uart->port.set_rxtrig = up->port.set_rxtrig;
+ if (up->port.get_rxtrig)
+ uart->port.get_rxtrig = up->port.get_rxtrig;
if (up->dl_read)
uart->dl_read = up->dl_read;
if (up->dl_write)
diff --git a/drivers/tty/serial/8250/8250_port.c b/drivers/tty/serial/8250/8250_port.c
index 72ecc0112b8a..2ece8af5d149 100644
--- a/drivers/tty/serial/8250/8250_port.c
+++ b/drivers/tty/serial/8250/8250_port.c
@@ -2999,9 +2999,14 @@ static ssize_t rx_trig_bytes_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct tty_port *port = dev_get_drvdata(dev);
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
int rxtrig_bytes;
- rxtrig_bytes = do_serial8250_get_rxtrig(port);
+ if (uport->get_rxtrig)
+ rxtrig_bytes = uport->get_rxtrig(uport);
+ else
+ rxtrig_bytes = do_serial8250_get_rxtrig(port);
if (rxtrig_bytes < 0)
return rxtrig_bytes;
@@ -3044,6 +3049,8 @@ static ssize_t rx_trig_bytes_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct tty_port *port = dev_get_drvdata(dev);
+ struct uart_state *state = container_of(port, struct uart_state, port);
+ struct uart_port *uport = state->uart_port;
unsigned char bytes;
int ret;
@@ -3054,7 +3061,10 @@ static ssize_t rx_trig_bytes_store(struct device *dev,
if (ret < 0)
return ret;
- ret = do_serial8250_set_rxtrig(port, bytes);
+ if (uport->set_rxtrig)
+ ret = uport->set_rxtrig(uport, bytes);
+ else
+ ret = do_serial8250_set_rxtrig(port, bytes);
if (ret < 0)
return ret;
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index d9e5e3d02003..bba6223d7b12 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -468,6 +468,8 @@ struct uart_port {
void (*pm)(struct uart_port *, unsigned int state,
unsigned int old);
void (*handle_break)(struct uart_port *);
+ int (*set_rxtrig)(struct uart_port *port, unsigned char bytes);
+ int (*get_rxtrig)(struct uart_port *port);
int (*rs485_config)(struct uart_port *,
struct ktermios *termios,
struct serial_rs485 *rs485);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling
2026-05-04 8:48 ` [PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling Crescent Hsieh
@ 2026-05-05 9:30 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-05 9:30 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:51 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> The rx_trig_bytes sysfs attribute currently relies on 8250-internal
> helper functions and assumes a fixed mapping between trigger levels and
> FIFO behavior.
>
> Some UARTs provide hardware-specific RX trigger mechanisms that do not
> fit this model. Add optional uart_port callbacks for setting and getting
> the RX trigger level, and use them when provided, while preserving the
> existing 8250 helpers as the default fallback.
...
> struct uart_port {
> void (*pm)(struct uart_port *, unsigned int state,
> unsigned int old);
> void (*handle_break)(struct uart_port *);
> + int (*set_rxtrig)(struct uart_port *port, unsigned char bytes);
> + int (*get_rxtrig)(struct uart_port *port);
Seems to me a suboptimal location for these. Why not moving up to be
closer to other getter/setter pairs?
> int (*rs485_config)(struct uart_port *,
> struct ktermios *termios,
> struct serial_rs485 *rs485);
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH 15/15] serial: 8250_mxpcie: implement rx_trig_bytes callbacks via MUEx50 RTL
2026-05-04 8:48 [PATCH 00/15] serial: 8250: add MUEx50 support for Moxa PCIe boards Crescent Hsieh
` (13 preceding siblings ...)
2026-05-04 8:48 ` [PATCH 14/15] serial: 8250: allow UART drivers to override rx_trig_bytes handling Crescent Hsieh
@ 2026-05-04 8:49 ` Crescent Hsieh
2026-05-05 9:34 ` Andy Shevchenko
14 siblings, 1 reply; 25+ messages in thread
From: Crescent Hsieh @ 2026-05-04 8:49 UTC (permalink / raw)
To: gregkh, jirislaby, ilpo.jarvinen, andy.shevchenko
Cc: crescentcy.hsieh, fangpingfp.cheng, linux-kernel, linux-serial
The MUEx50 UART exposes a programmable RX trigger level via the RTL
register.
Implement uart_port RX trigger set/get callbacks for the mxpcie driver
and wire them up to the generic rx_trig_bytes sysfs interface. Store the
configured trigger level in the per-port private data.
Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
---
drivers/tty/serial/8250/8250_mxpcie.c | 28 ++++++++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/drivers/tty/serial/8250/8250_mxpcie.c b/drivers/tty/serial/8250/8250_mxpcie.c
index 5bf15ca78228..cc317202b658 100644
--- a/drivers/tty/serial/8250/8250_mxpcie.c
+++ b/drivers/tty/serial/8250/8250_mxpcie.c
@@ -111,6 +111,7 @@
struct mxpcie8250_port {
int line;
+ u8 rx_trig_level;
unsigned long event_flags;
struct uart_port *port;
struct work_struct work;
@@ -262,6 +263,7 @@ static void mxpcie8250_set_termios(struct uart_port *port,
static int mxpcie8250_startup(struct uart_port *port)
{
+ struct mxpcie8250 *priv = dev_get_drvdata(port->dev);
struct uart_8250_port *up = up_to_u8250p(port);
unsigned int i;
int ret;
@@ -277,7 +279,7 @@ static int mxpcie8250_startup(struct uart_port *port)
serial_out(up, MOXA_PUART_SFR, MOXA_PUART_SFR_950);
serial_out(up, MOXA_PUART_TTL, 0);
- serial_out(up, MOXA_PUART_RTL, 96);
+ serial_out(up, MOXA_PUART_RTL, priv->port[port->port_id].rx_trig_level);
serial_out(up, MOXA_PUART_FCL, 16);
serial_out(up, MOXA_PUART_FCH, 110);
@@ -477,6 +479,27 @@ static void mxpcie8250_break_ctl(struct uart_port *port, int break_state)
serial8250_do_break_ctl(port, break_state);
}
+static int mxpcie8250_set_rxtrig(struct uart_port *port, unsigned char bytes)
+{
+ struct mxpcie8250 *priv = dev_get_drvdata(port->dev);
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ if (bytes > 128)
+ return -EINVAL;
+
+ serial_out(up, MOXA_PUART_RTL, bytes);
+ priv->port[port->port_id].rx_trig_level = bytes;
+
+ return 0;
+}
+
+static int mxpcie8250_get_rxtrig(struct uart_port *port)
+{
+ struct uart_8250_port *up = up_to_u8250p(port);
+
+ return serial_in(up, MOXA_PUART_RTL);
+}
+
static void mxpcie8250_work_handler(struct work_struct *work)
{
struct mxpcie8250_port *priv_port = container_of(work, struct mxpcie8250_port, work);
@@ -591,6 +614,8 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
up.port.unthrottle = mxpcie8250_unthrottle;
up.port.handle_irq = mxpcie8250_handle_irq;
up.port.break_ctl = mxpcie8250_break_ctl;
+ up.port.set_rxtrig = mxpcie8250_set_rxtrig;
+ up.port.get_rxtrig = mxpcie8250_get_rxtrig;
for (i = 0; i < num_ports; i++) {
mxpcie8250_setup_port(pdev, priv, &up, i);
@@ -608,6 +633,7 @@ static int mxpcie8250_probe(struct pci_dev *pdev, const struct pci_device_id *id
}
new_port = serial8250_get_port(priv->port[i].line);
+ priv->port[i].rx_trig_level = 96;
priv->port[i].port = &new_port->port;
INIT_WORK(&priv->port[i].work, mxpcie8250_work_handler);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread* Re: [PATCH 15/15] serial: 8250_mxpcie: implement rx_trig_bytes callbacks via MUEx50 RTL
2026-05-04 8:49 ` [PATCH 15/15] serial: 8250_mxpcie: implement rx_trig_bytes callbacks via MUEx50 RTL Crescent Hsieh
@ 2026-05-05 9:34 ` Andy Shevchenko
0 siblings, 0 replies; 25+ messages in thread
From: Andy Shevchenko @ 2026-05-05 9:34 UTC (permalink / raw)
To: Crescent Hsieh
Cc: gregkh, jirislaby, ilpo.jarvinen, fangpingfp.cheng, linux-kernel,
linux-serial
On Mon, May 4, 2026 at 11:51 AM Crescent Hsieh
<crescentcy.hsieh@moxa.com> wrote:
>
> The MUEx50 UART exposes a programmable RX trigger level via the RTL
> register.
>
> Implement uart_port RX trigger set/get callbacks for the mxpcie driver
> and wire them up to the generic rx_trig_bytes sysfs interface. Store the
> configured trigger level in the per-port private data.
...
> struct mxpcie8250_port {
> int line;
> + u8 rx_trig_level;
> unsigned long event_flags;
> struct uart_port *port;
> struct work_struct work;
Whenever you add a member to or modify existing data structure, always
run `pahole` to check if the layout is good enough (or even the best
fit). Same applies to the whole series.
...
> +static int mxpcie8250_set_rxtrig(struct uart_port *port, unsigned char bytes)
> +{
> + struct mxpcie8250 *priv = dev_get_drvdata(port->dev);
> + struct uart_8250_port *up = up_to_u8250p(port);
> +
> + if (bytes > 128)
Magic! Should it be defined or already has been?
> + return -EINVAL;
> +
> + serial_out(up, MOXA_PUART_RTL, bytes);
> + priv->port[port->port_id].rx_trig_level = bytes;
> +
> + return 0;
> +}
...
> +static int mxpcie8250_get_rxtrig(struct uart_port *port)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);
> +
> + return serial_in(up, MOXA_PUART_RTL);
No need to have an intermediate pointer as you can simply use
serial_port_in(). Same applies to other places when the uart_8250_port
is not used otherwise.
> +}
...
> + priv->port[i].rx_trig_level = 96;
As per above, this magic together with the above should be defined
somehow. And together they make more context to the reader.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 25+ messages in thread