Re: [PATCH v1 21/31] serial: 8250_mxpcie: implement rx_trig_bytes callbacks and persist per-port level

From: Andy Shevchenko

Date: Sun Nov 30 2025 - 21:03:31 EST


On Sun, Nov 30, 2025 at 12:45 PM Crescent Hsieh
<crescentcy.hsieh@xxxxxxxx> wrote:
>
> This patch implements device-specific RX trigger handling for the
> rx_trig_bytes sysfs attribute by programming MOXA_PUART_RTL directly.
>
> Changes:
> - Add a per-port structure to persist both the registered line and the
> RX trigger level, allowing the level to be restored on startup.
> - Implement uart_port callbacks:
> - set_rxtrig(port, bytes): program MOXA_PUART_RTL and cache the value
> - get_rxtrig(port): read back MOXA_PUART_RTL
> - Use the cached RX trigger level during startup instead of a fixed
> default, while keeping the initial default at 96 for backward
> compatibility.
>
> With these callbacks in place, writes to rx_trig_bytes update the
> hardware-specific register immediately, and the selected threshold is
> preserved across open/close cycles.
>
> No functional change for other 8250 drivers.

...

> static int mxpcie8250_startup(struct uart_port *port)
> {
> + struct pci_dev *pdev = to_pci_dev(port->dev);
> + struct mxpcie8250 *priv = pci_get_drvdata(pdev);

It's a bit of a detour to simply use dev_get_drvdata() in an agnostic
way. With the above the code will need a change once the device uses
another bus.

> struct uart_8250_port *up = up_to_u8250p(port);
> int i, ret;

> }

...

> +static int mxpcie8250_set_rxtrig(struct uart_port *port, unsigned char bytes)
> +{
> + struct uart_8250_port *up = up_to_u8250p(port);

> + struct pci_dev *pdev = to_pci_dev(port->dev);
> + struct mxpcie8250 *priv = pci_get_drvdata(pdev);

Ditto. Aslo locate the lines consistently with the other function
(usually in reversed xmas tree order).

> + 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);

> + int rx_trig_byte;

Seems a useless variable. Is there something in the next changes that
justifies its presence?

> + rx_trig_byte = serial_in(up, MOXA_PUART_RTL);
> +
> + return rx_trig_byte;
> +}

...

Also it seems that this change can be split to two:
- preparatory that moves just a line member to a new data structure
- this one which adds required features

--
With Best Regards,
Andy Shevchenko