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>,
	gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: Re: [PATCH 2/4] tty: serial: 8250: Add support for MOXA Mini PCIe boards
Date: Mon, 2 Oct 2023 09:05:31 +0200	[thread overview]
Message-ID: <1e99f3c4-e0b8-4951-80c3-f3c5a1eb5277@kernel.org> (raw)
In-Reply-To: <20231002015702.30509-3-crescentcy.hsieh@moxa.com>

On 02. 10. 23, 3:57, Crescent CY Hsieh wrote:
> Add support for MOXA Mini PCIe serial boards:
> 
> - CP102N: 2 ports | RS232
> - CP104N: 4 ports | RS232
> - CP112N: 2 ports | RS232/RS422/RS485
> - CP114N: 4 ports | RS232/RS422/RS485
> - CP132N: 2 ports | RS422/RS485
> - CP134N: 4 ports | RS422/RS485
> 
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> ---
>   drivers/tty/serial/8250/8250_pci.c | 54 ++++++++++++++++++++++++++++++
>   1 file changed, 54 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index a010790ccfcd..a70546ac361e 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1887,6 +1887,42 @@ pci_sunix_setup(struct serial_private *priv,
>   	return setup_port(priv, port, bar, offset, 0);
>   }
>   
> +#define MOXA_PUART_GPIO_EN	0x09
> +#define MOXA_PUART_GPIO_OUT	0x0A
> +
> +#define MOXA_GPIO_SET_ALL_OUTPUT	0x0F
> +
> +static int pci_moxa_init(struct pci_dev *dev)
> +{
> +	unsigned short device = dev->device;
> +	unsigned long iobar_addr = pci_resource_start(dev, 2);

resource_size_t

> +	int num_ports = (device & 0x00F0) >> 4;
> +	unsigned char val;

u8

> +
> +	outb(MOXA_GPIO_SET_ALL_OUTPUT, iobar_addr + MOXA_PUART_GPIO_EN);

You need to comment in the commit log why this doesn't matter for other 
moxa cards.

> +	/*
> +	 * Enable hardware buffer to prevent break signal output when system boot up.

boots up.

> +	 * This hardware buffer is only supported on Mini PCIe series.
> +	 */
> +	if (device == 0x1027 ||	/* MOXA_CP102N */
> +	    device == 0x1046 ||	/* MOXA_CP104N */
> +	    device == 0x1121 ||	/* MOXA_CP112N */
> +	    device == 0x1145 ||	/* MOXA_CP114N */
> +	    device == 0x1323 ||	/* MOXA_CP132N */
> +	    device == 0x1343) {	/* MOXA_CP134N */

Why not use the definitions below? You should define a function for this 
anyway.

> +		/* Set GPIO direction */
> +		val = inb(iobar_addr + MOXA_PUART_GPIO_EN);
> +		val |= (1 << 2);

Too magic constant. Use BIT() and define that 2 as some constant.

> +		outb(val, iobar_addr + MOXA_PUART_GPIO_EN);
> +		/* Enable low GPIO */
> +		val = inb(iobar_addr + MOXA_PUART_GPIO_OUT);
> +		val &= ~(1 << 2);
> +		outb(val, iobar_addr + MOXA_PUART_GPIO_OUT);
> +	}

One more \n here.

> +	return num_ports;
> +}
> +
>   static int pci_moxa_setup(struct serial_private *priv,
>   			  const struct pciserial_board *board,
>   			  struct uart_8250_port *port,
> @@ -1973,6 +2009,13 @@ static int pci_moxa_setup(struct serial_private *priv,
>   #define	PCI_DEVICE_ID_MOXA_CP134EL_A	0x1342
>   #define	PCI_DEVICE_ID_MOXA_CP138E_A	0x1381
>   #define	PCI_DEVICE_ID_MOXA_CP168EL_A	0x1683
> +/* MOXA Mini PCIe */
> +#define PCI_DEVICE_ID_MOXA_CP102N	0x1027
> +#define PCI_DEVICE_ID_MOXA_CP104N	0x1046
> +#define PCI_DEVICE_ID_MOXA_CP112N	0x1121
> +#define PCI_DEVICE_ID_MOXA_CP114N	0x1145
> +#define PCI_DEVICE_ID_MOXA_CP132N	0x1323
> +#define PCI_DEVICE_ID_MOXA_CP134N	0x1343

I am not sure it matters they are mini PCIe. I would sort them into the 
above preexisting list instead.

>   
>   /* Unknown vendors/cards - this should not be in linux/pci_ids.h */
>   #define PCI_SUBDEVICE_ID_UNKNOWN_0x1584	0x1584
> @@ -2638,6 +2681,7 @@ static struct pci_serial_quirk pci_serial_quirks[] = {
>   		.device		= PCI_ANY_ID,
>   		.subvendor	= PCI_ANY_ID,
>   		.subdevice	= PCI_ANY_ID,
> +		.init		= pci_moxa_init,
>   		.setup		= pci_moxa_setup,
>   	},
>   	{
> @@ -5365,6 +5409,16 @@ static const struct pci_device_id serial_pci_tbl[] = {
>   	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP138E_A),	 0, 0, pbn_moxa_8 },
>   	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A),	 0, 0, pbn_moxa_8 },
>   
> +	/*
> +	 * MOXA Mini PCIe
> +	 */
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102N), 0, 0, pbn_moxa_2 },
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104N), 0, 0, pbn_moxa_4 },
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP112N), 0, 0, pbn_moxa_2 },
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114N), 0, 0, pbn_moxa_4 },
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132N), 0, 0, pbn_moxa_2 },
> +	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134N), 0, 0, pbn_moxa_4 },

PCI_VDEVICE() again?

thanks,
-- 
js
suse labs


  reply	other threads:[~2023-10-02  7:05 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 [this message]
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
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=1e99f3c4-e0b8-4951-80c3-f3c5a1eb5277@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®