From: Jiri Slaby <jirislaby@kernel.org>
To: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>,
gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [Patch v2 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
Date: Mon, 16 Oct 2023 07:27:26 +0200 [thread overview]
Message-ID: <79a2006b-abca-4e06-b8a3-58411318b9d7@kernel.org> (raw)
In-Reply-To: <20231016033705.20669-7-crescentcy.hsieh@moxa.com>
On 16. 10. 23, 5:37, Crescent CY Hsieh wrote:
> MOXA PCIe boards have 4 serial interfaces and don't require additional
> stuff to switch between interfaces:
>
> - RS232
> - RS422
> - RS485_2W (half-duplex)
> - RS485_4W (full-duplex)
>
> By using ioctl command "TIOCRS485", it can switch between default
> interface and RS485 if supported.
>
> That means, for RS422/RS485 board, it can switch between RS422 and
> RS485 by setting the flags within struct serial_rs485.
>
> However, for the RS232/RS422/RS485 board, it can only switch between
> RS232 and RS485, there's no flag for switching interface into RS422.
>
> This patch uses "SER_RS485_TERMINATE_BUS" to represent RS422 as a
> workaround solution.
>
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> ---
> drivers/tty/serial/8250/8250_pci.c | 52 ++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index 72dd27141801..e2e8a28242bc 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1976,6 +1976,10 @@ pci_sunix_setup(struct serial_private *priv,
> #define MOXA_RS485_2W 0x0F
> #define MOXA_UIR_OFFSET 0x04
>
> +static const struct serial_rs485 pci_moxa_rs485_supported = {
> + .flags = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX | SER_RS485_TERMINATE_BUS,
> +};
> +
> static bool pci_moxa_is_mini_pcie(unsigned short device)
> {
> if (device == PCI_DEVICE_ID_MOXA_CP102N ||
> @@ -1989,6 +1993,11 @@ static bool pci_moxa_is_mini_pcie(unsigned short device)
> return false;
> }
>
> +static bool pci_moxa_match_x1xx(unsigned short device)
> +{
> + return (device & 0x0F00) == 0x0100;
> +}
> +
> static bool pci_moxa_match_x3xx(unsigned short device)
I wonder if it made more sense to have only a single function like:
static bool pci_moxa_match(unsigned short device, unsigned short matching)
{
return (device & 0x0F00) == matching;
}
and call:
pci_moxa_match(device, 0x0100)
pci_moxa_match(device, 0x0300)
?
Perhaps name the function better. According to what the second digit in
the device ID in fact means.
> {
> return (device & 0x0F00) == 0x0300;
> @@ -2016,6 +2025,36 @@ static int pci_moxa_set_interface(const struct pci_dev *dev,
> return 0;
> }
>
> +static int pci_moxa_rs485_config(struct uart_port *port,
> + struct ktermios *termios,
> + struct serial_rs485 *rs485)
> +{
> + struct pci_dev *dev = to_pci_dev(port->dev);
> + unsigned short device = dev->device;
> + u8 mode = MOXA_RS232;
> +
> + if (rs485->flags & SER_RS485_ENABLED) {
> + /* Use SER_RS485_TERMINATE_BUS to represent RS422 as a workaround. */
> + if (rs485->flags & SER_RS485_TERMINATE_BUS) {
> + mode = MOXA_RS422;
> + } else {
> + if (rs485->flags & SER_RS485_RX_DURING_TX)
> + mode = MOXA_RS485_4W;
> + else
> + mode = MOXA_RS485_2W;
> + }
> + } else {
> + /*
> + * RS232 is not supported for those device IDs of
> + * MOXA PCIe boards match the pattern 0x*3**.
I am not native, but I can hardly parse this.
Maybe:
RS232 is not supported on MOXA PCIe boards with device IDs matching the
pattern 0x*3**.
?
> + */
> + if (pci_moxa_match_x3xx(device))
> + return -EINVAL;
Perhaps EOPNOTSUPP?
> + }
> +
> + return pci_moxa_set_interface(dev, port->port_id, mode);
> +}
> +
> static int pci_moxa_init(struct pci_dev *dev)
> {
> unsigned short device = dev->device;
thanks,
--
js
suse labs
prev parent reply other threads:[~2023-10-16 5:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 3:36 [Patch v2 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
2023-10-16 3:37 ` [Patch v2 1/6] tty: serial: 8250: Modify MOXA enum name within 8250_pci.c Crescent CY Hsieh
2023-10-16 5:11 ` Jiri Slaby
2023-10-16 3:37 ` [Patch v2 2/6] tty: serial: 8250: Cleanup MOXA configurations " Crescent CY Hsieh
2023-10-16 5:12 ` Jiri Slaby
2023-10-16 3:37 ` [Patch v2 3/6] tty: serial: 8250: Relocate macros " Crescent CY Hsieh
2023-10-16 5:14 ` Jiri Slaby
2023-10-16 3:37 ` [Patch v2 4/6] tty: serial: 8250: Add support for MOXA Mini PCIe boards Crescent CY Hsieh
2023-10-16 5:16 ` Jiri Slaby
2023-10-16 3:37 ` [Patch v2 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
2023-10-16 5:18 ` Jiri Slaby
2023-10-16 3:37 ` [Patch v2 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485 Crescent CY Hsieh
2023-10-16 5:27 ` Jiri Slaby [this message]
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=79a2006b-abca-4e06-b8a3-58411318b9d7@kernel.org \
--to=jirislaby@kernel.org \
--cc=crescentcy.hsieh@moxa.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).