From: Johan Hovold <johan@kernel.org>
To: Crescent Hsieh <crescentcy.hsieh@moxa.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v1 3/4] usb: serial: mxuport: support serial interface mode configuration
Date: Thu, 7 May 2026 17:56:49 +0200 [thread overview]
Message-ID: <afy2QagmwKTapTg6@hovoldconsulting.com> (raw)
In-Reply-To: <20260324035041.352190-4-crescentcy.hsieh@moxa.com>
On Tue, Mar 24, 2026 at 11:50:40AM +0800, Crescent Hsieh wrote:
> Add support for configuring the serial interface mode through
> TIOCSRS485 and TIOCGRS485 using struct serial_rs485.
>
> Sanitize the requested RS-485 settings and map them to the device
> interface modes before issuing the vendor command to the firmware.
>
> This allows userspace to switch between RS232, RS422, 2-wire RS485,
> and 4-wire RS485, and to query the current per-port configuration.
>
> Signed-off-by: Crescent Hsieh <crescentcy.hsieh@moxa.com>
> +static void mxuport_sanitize_serial_rs485(struct serial_rs485 *rs485)
> +{
> + if (!(rs485->flags & SER_RS485_ENABLED)) {
> + memset(rs485, 0, sizeof(*rs485));
> + return;
> + }
> + if (rs485->flags & SER_RS485_MODE_RS422) {
> + rs485->flags &= (SER_RS485_ENABLED | SER_RS485_MODE_RS422);
> + return;
> + }
> + rs485->flags &= (SER_RS485_ENABLED | SER_RS485_RX_DURING_TX);
I think you need to clear the other unsupported fields as well (i.e. the
delays).
> +
> + memset(rs485->padding, 0, sizeof(rs485->padding));
> +}
> +
> +static int mxuport_rs485_config(struct usb_serial_port *port,
> + struct serial_rs485 *rs485)
> +{
> + struct usb_serial *serial = port->serial;
> + u16 mode = MX_INT_RS232;
> +
> + if (rs485->flags & SER_RS485_ENABLED) {
> + if (rs485->flags & SER_RS485_MODE_RS422)
> + mode = MX_INT_RS422;
> + else if (rs485->flags & SER_RS485_RX_DURING_TX)
> + mode = MX_INT_4W_RS485;
> + else
> + mode = MX_INT_2W_RS485;
> + }
> +
> + return mxuport_send_ctrl_urb(serial, RQ_VENDOR_SET_INTERFACE, mode,
> + port->port_number);
> +}
> +
> +static int mxuport_get_rs485_config(struct usb_serial_port *port,
> + struct serial_rs485 __user *rs485)
> +{
> + struct mxuport_port *mxport = usb_get_serial_port_data(port);
> +
> + if (copy_to_user(rs485, &mxport->rs485, sizeof(mxport->rs485)))
> + return -EFAULT;
> +
> + return 0;
> +}
> +
> +static int mxuport_set_rs485_config(struct usb_serial_port *port,
> + struct serial_rs485 __user *rs485_user)
> +{
> + struct mxuport_port *mxport = usb_get_serial_port_data(port);
> + struct serial_rs485 rs485;
> + int ret;
> +
> + if (copy_from_user(&rs485, rs485_user, sizeof(*rs485_user)))
> + return -EFAULT;
> +
> + mxuport_sanitize_serial_rs485(&rs485);
> +
> + ret = mxuport_rs485_config(port, &rs485);
> + if (!ret)
> + mxport->rs485 = rs485;
We need some locking here as these ioctls can execute in parallel.
> +
> + if (copy_to_user(rs485_user, &mxport->rs485, sizeof(mxport->rs485)))
> + return -EFAULT;
> +
> + return 0;
> +}
Johan
next prev parent reply other threads:[~2026-05-07 15:56 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-24 3:50 [PATCH v1 0/4] usb: serial: mxuport: extend MXU50U support and runtime controls Crescent Hsieh
2026-03-24 3:50 ` [PATCH v1 1/4] usb: serial: mxuport: add support for more MXU50U UART devices Crescent Hsieh
2026-05-07 14:13 ` Johan Hovold
2026-03-24 3:50 ` [PATCH v1 2/4] usb: serial: mxuport: handle SEND_NEXT tx flow control Crescent Hsieh
2026-05-07 14:40 ` Johan Hovold
2026-03-24 3:50 ` [PATCH v1 3/4] usb: serial: mxuport: support serial interface mode configuration Crescent Hsieh
2026-05-07 15:56 ` Johan Hovold [this message]
2026-03-24 3:50 ` [PATCH v1 4/4] usb: serial: mxuport: add sysfs control for UART FIFO Crescent Hsieh
2026-05-07 15:59 ` Johan Hovold
2026-05-12 11:28 ` Crescent Hsieh
2026-05-13 8:20 ` Johan Hovold
2026-05-13 8:48 ` Greg Kroah-Hartman
2026-05-15 9:08 ` Crescent Hsieh
2026-05-15 9:17 ` Greg Kroah-Hartman
2026-03-30 7:24 ` [PATCH v1 0/4] usb: serial: mxuport: extend MXU50U support and runtime controls Crescent Hsieh
2026-03-30 7:54 ` Johan Hovold
2026-04-27 3:37 ` Crescent Hsieh
2026-04-27 10:43 ` Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=afy2QagmwKTapTg6@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=crescentcy.hsieh@moxa.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.