mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
Date: Thu, 19 Oct 2023 08:16:32 +0200	[thread overview]
Message-ID: <935b5603-2e86-4d19-af50-d8833f9d8c41@kernel.org> (raw)
In-Reply-To: <20231018091739.10125-6-crescentcy.hsieh@moxa.com>

On 18. 10. 23, 11:17, Crescent CY Hsieh wrote:
> MOXA PCIe RS422/RS485 boards will not function by default because of the
> initial default serial interface of all MOXA PCIe boards is set to RS232.
> 
> This patch fixes the problem above by setting the initial default serial
> interface to RS422 for those MOXA RS422/RS485 PCIe boards.
> 
> 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 b2be3783f..29a28e72b 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
...
> @@ -1981,13 +1987,59 @@ static bool pci_moxa_is_mini_pcie(unsigned short device)
>   	return false;
>   }
>   
> +/*
> + * The second digit of the MOXA PCIe device ID in hexadecimal indicates
> + * which serial interface modes this board supports:
> + *
> + *	0x*0** - RS232
> + *	0x*1** - RS232/RS422/RS485
> + *	0x*3** - RS422/RS485
> + *	0x*6** - RS232
> + */
> +static bool pci_moxa_match_second_digit(unsigned short device,
> +					unsigned short pattern)
> +{
> +	return (device & 0x0F00) == pattern;
> +}

Actually, would it make sense to define the below instead:

enum {
    MOXA_SUPP_RS232 = BIT(0),
    MOXA_SUPP_RS422 = BIT(1),
    MOXA_SUPP_RS485 = BIT(2),
};

u32 pci_moxa_supported_rs(struct pci_dev *dev)
{
    switch (dev->device & 0x0f00) {
    case 0x0000:
    case 0x0600: // or default: ???
      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_init(struct pci_dev *dev)
>   {
>   	unsigned short device = dev->device;
>   	resource_size_t iobar_addr = pci_resource_start(dev, 2);
> +	unsigned int i;
>   	unsigned int num_ports = (device & 0x00F0) >> 4;
>   	u8 val;
>   
> +	/*
> +	 * For the device IDs of MOXA PCIe boards match the pattern 0x*3**,
> +	 * the initial default serial interface mode should be set to RS422.
> +	 */
> +	if (pci_moxa_match_second_digit(device, 0x0300)) {

And here:
if (pci_moxa_supported_rs(dev) == MOXA_SUPP_RS422 | MOXA_SUPP_RS485)

or perhaps:
if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232))
?

> +		for (i = 0; i < num_ports; ++i)
> +			pci_moxa_set_interface(dev, i, MOXA_RS422);
> +	}
>   	/*
>   	 * Enable hardware buffer to prevent break signal output when system boots up.
>   	 * This hardware buffer is only supported on Mini PCIe series.

-- 
js
suse labs


  parent reply	other threads:[~2023-10-19  6:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18  9:17 [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
2023-10-18  9:17 ` [PATCH v3 1/6] tty: serial: 8250: Modify MOXA enum name within 8250_pci.c Crescent CY Hsieh
2023-10-18  9:17 ` [PATCH v3 2/6] tty: serial: 8250: Cleanup MOXA configurations Crescent CY Hsieh
2023-10-18  9:17 ` [PATCH v3 3/6] tty: serial: 8250: Relocate macros within 8250_pci.c Crescent CY Hsieh
2023-10-18  9:17 ` [PATCH v3 4/6] tty: serial: 8250: Add support for MOXA Mini PCIe boards Crescent CY Hsieh
2023-10-18  9:17 ` [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
2023-10-19  5:59   ` Jiri Slaby
2023-10-19  6:16   ` Jiri Slaby [this message]
2023-10-23  9:21   ` Ilpo Järvinen
2023-10-18  9:17 ` [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485 Crescent CY Hsieh
2023-10-19  6:06   ` Jiri Slaby
2023-10-19  6:24   ` Jiri Slaby
2023-10-23  9:25   ` Ilpo Järvinen
2023-10-24  7:48     ` Crescent CY Hsieh
2023-10-24  8:10       ` Greg Kroah-Hartman
2023-10-21 16:31 ` [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Greg Kroah-Hartman

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=935b5603-2e86-4d19-af50-d8833f9d8c41@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

all inboxes | Powered by JetHome®