public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
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 3/4] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
Date: Mon, 2 Oct 2023 09:14:32 +0200	[thread overview]
Message-ID: <73a6b0ae-d94e-4a9e-9964-0484c95c8226@kernel.org> (raw)
In-Reply-To: <20231002015702.30509-4-crescentcy.hsieh@moxa.com>

On 02. 10. 23, 3:57, 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 | 39 +++++++++++++++++++++++++++++-
>   1 file changed, 38 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index a70546ac361e..31bfe5381000 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1890,17 +1890,54 @@ pci_sunix_setup(struct serial_private *priv,
>   #define MOXA_PUART_GPIO_EN	0x09
>   #define MOXA_PUART_GPIO_OUT	0x0A
>   
> +#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_GPIO_SET_ALL_OUTPUT	0x0F
>   
> +static int pci_moxa_set_interface(struct pci_dev *dev,

can it be const?

> +				  unsigned int port_idx,
> +				  unsigned char mode)

u8

> +{
> +	unsigned long iobar_addr = pci_resource_start(dev, 2);

resource_size_t

> +	unsigned long UIR_addr = iobar_addr + MOXA_UIR_OFFSET + (port_idx / 2);

resource_size_t. Why the parentheses?

> +	unsigned char val, intf;

u8

> +	val = inb(UIR_addr);
> +
> +	if (port_idx % 2) {
> +		intf = mode << 4;
> +		val &= 0x0F;
> +	} else {
> +		intf = mode;
> +		val &= 0xF0;
> +	}
> +	val |= intf;

May be better:
   if (port_idx % 2) {
     val &= 0x0F;
     val |= mode << 4;
   } else {
     val &= 0xF0;
     val |= mode;
   }
(no need for intf)?


> +	outb(val, UIR_addr);
> +
> +	return 0;
> +}
> +
>   static int pci_moxa_init(struct pci_dev *dev)
>   {
>   	unsigned short device = dev->device;
>   	unsigned long iobar_addr = pci_resource_start(dev, 2);
> +	int i;

unsigned

>   	int num_ports = (device & 0x00F0) >> 4;

And this one too (in the previous patch).

>   	unsigned char val;
>   
>   	outb(MOXA_GPIO_SET_ALL_OUTPUT, iobar_addr + MOXA_PUART_GPIO_EN);
> -
> +	/*
> +	 * 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 ((device & 0x0F00) == 0x0300) {
> +		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 boot up.
>   	 * This hardware buffer is only supported on Mini PCIe series.

-- 
js
suse labs


  reply	other threads:[~2023-10-02  7:14 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02  1:56 [PATCH 0/4] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
2023-10-02  1:56 ` [PATCH 1/4] tty: serial: 8250: Cleanup MOXA configurations " Crescent CY Hsieh
2023-10-02  6:51   ` Jiri Slaby
2023-10-03  7:17     ` Crescent CY Hsieh
2023-10-03  7:30       ` Greg KH
2023-10-03  9:49         ` Jiri Slaby
2023-10-02  1:57 ` [PATCH 2/4] tty: serial: 8250: Add support for MOXA Mini PCIe boards Crescent CY Hsieh
2023-10-02  7:05   ` Jiri Slaby
2023-10-03  8:17     ` Crescent CY Hsieh
2023-10-02  1:57 ` [PATCH 3/4] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
2023-10-02  7:14   ` Jiri Slaby [this message]
2023-10-03  8:22     ` Crescent CY Hsieh
2023-10-02  1:57 ` [PATCH 4/4] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485 Crescent CY Hsieh
2023-10-02  4:13   ` kernel test robot
2023-10-02  5:47   ` kernel test robot
2023-10-02  7:19   ` Jiri Slaby
2023-10-03  9:57     ` Crescent CY Hsieh

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=73a6b0ae-d94e-4a9e-9964-0484c95c8226@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