linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
@ 2023-12-01  7:40 Crescent CY Hsieh
  2023-12-01  8:27 ` Greg Kroah-Hartman
  2023-12-05 21:35 ` kernel test robot
  0 siblings, 2 replies; 5+ messages in thread
From: Crescent CY Hsieh @ 2023-12-01  7:40 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

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>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_pci.c | 58 +++++++++++++++++++++++++++++-
 1 file changed, 57 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index b2be3783f..66a2450da 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -19,6 +19,7 @@
 #include <linux/serial_core.h>
 #include <linux/8250_pci.h>
 #include <linux/bitops.h>
+#include <linux/bitfield.h>
 
 #include <asm/byteorder.h>
 #include <asm/io.h>
@@ -1968,6 +1969,20 @@ pci_sunix_setup(struct serial_private *priv,
 
 #define MOXA_GPIO_PIN2	BIT(2)
 
+#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_EVEN_RS_MASK	GENMASK(3, 0)
+#define MOXA_ODD_RS_MASK	GENMASK(7, 4)
+
+enum {
+	MOXA_SUPP_RS232 = BIT(0),
+	MOXA_SUPP_RS422 = BIT(1),
+	MOXA_SUPP_RS485 = BIT(2),
+};
+
 static bool pci_moxa_is_mini_pcie(unsigned short device)
 {
 	if (device == PCI_DEVICE_ID_MOXA_CP102N	||
@@ -1981,13 +1996,54 @@ static bool pci_moxa_is_mini_pcie(unsigned short device)
 	return false;
 }
 
+u32 pci_moxa_supported_rs(struct pci_dev *dev)
+{
+	switch (dev->device & 0x0F00) {
+	case 0x0000:
+	case 0x0600:
+		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_set_interface(const struct pci_dev *dev,
+				  unsigned int port_idx,
+				  u8 mode)
+{
+	resource_size_t iobar_addr = pci_resource_start(dev, 2);
+	resource_size_t UIR_addr = iobar_addr + MOXA_UIR_OFFSET + port_idx / 2;
+	u8 val;
+
+	val = inb(UIR_addr);
+
+	if (port_idx % 2) {
+		val &= ~MOXA_ODD_RS_MASK;
+		val |= FIELD_PREP(MOXA_ODD_RS_MASK, mode);
+	} else {
+		val &= ~MOXA_EVEN_RS_MASK;
+		val |= FIELD_PREP(MOXA_EVEN_RS_MASK, mode);
+	}
+	outb(val, UIR_addr);
+
+	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 num_ports = (device & 0x00F0) >> 4;
+	unsigned int num_ports = (device & 0x00F0) >> 4, i;
 	u8 val;
 
+	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.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  2023-12-01  7:40 [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
@ 2023-12-01  8:27 ` Greg Kroah-Hartman
  2023-12-01  9:02   ` Crescent CY Hsieh
  2023-12-05 21:35 ` kernel test robot
  1 sibling, 1 reply; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-12-01  8:27 UTC (permalink / raw)
  To: Crescent CY Hsieh; +Cc: Jiri Slaby, linux-kernel, linux-serial

On Fri, Dec 01, 2023 at 03:40:55PM +0800, 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>
> Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
> ---
>  drivers/tty/serial/8250/8250_pci.c | 58 +++++++++++++++++++++++++++++-
>  1 file changed, 57 insertions(+), 1 deletion(-)

Why is this a RESEND?  What happened to the first attempt, did I miss it
somewhere?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  2023-12-01  8:27 ` Greg Kroah-Hartman
@ 2023-12-01  9:02   ` Crescent CY Hsieh
  2023-12-07  1:33     ` Greg Kroah-Hartman
  0 siblings, 1 reply; 5+ messages in thread
From: Crescent CY Hsieh @ 2023-12-01  9:02 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Jiri Slaby, linux-kernel, linux-serial

On Fri, Dec 01, 2023 at 08:27:05AM +0000, Greg Kroah-Hartman wrote:
> On Fri, Dec 01, 2023 at 03:40:55PM +0800, 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>
> > Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
> > ---
> >  drivers/tty/serial/8250/8250_pci.c | 58 +++++++++++++++++++++++++++++-
> >  1 file changed, 57 insertions(+), 1 deletion(-)
> 
> Why is this a RESEND?  What happened to the first attempt, did I miss it
> somewhere?

This RESEND patch is the first patch of this patch series [1], Jiri
reviewed the first patch and suggested to split the second patch, so I
split the second patch and sent it as a new patch.

However, the first patch seems to be overlooked, so I resend it.

[1] https://lore.kernel.org/all/20231027062440.7749-1-crescentcy.hsieh@moxa.com/

---
Sincerely,
Crescent CY Hsieh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  2023-12-01  7:40 [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
  2023-12-01  8:27 ` Greg Kroah-Hartman
@ 2023-12-05 21:35 ` kernel test robot
  1 sibling, 0 replies; 5+ messages in thread
From: kernel test robot @ 2023-12-05 21:35 UTC (permalink / raw)
  To: Crescent CY Hsieh, Greg Kroah-Hartman, Jiri Slaby
  Cc: oe-kbuild-all, linux-kernel, linux-serial, Crescent CY Hsieh

Hi Crescent,

kernel test robot noticed the following build warnings:

[auto build test WARNING on tty/tty-testing]
[also build test WARNING on tty/tty-next tty/tty-linus usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.7-rc4 next-20231205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Crescent-CY-Hsieh/tty-serial-8250-Fix-MOXA-RS422-RS485-PCIe-boards-not-work-by-default/20231201-154322
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git tty-testing
patch link:    https://lore.kernel.org/r/20231201074055.259207-1-crescentcy.hsieh%40moxa.com
patch subject: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
config: x86_64-randconfig-122-20231202 (https://download.01.org/0day-ci/archive/20231206/202312060523.Kmstf65q-lkp@intel.com/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312060523.Kmstf65q-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312060523.Kmstf65q-lkp@intel.com/

sparse warnings: (new ones prefixed by >>)
>> drivers/tty/serial/8250/8250_pci.c:2001:5: sparse: sparse: symbol 'pci_moxa_supported_rs' was not declared. Should it be static?

vim +/pci_moxa_supported_rs +2001 drivers/tty/serial/8250/8250_pci.c

  2000	
> 2001	u32 pci_moxa_supported_rs(struct pci_dev *dev)
  2002	{
  2003		switch (dev->device & 0x0F00) {
  2004		case 0x0000:
  2005		case 0x0600:
  2006			return MOXA_SUPP_RS232;
  2007		case 0x0100:
  2008			return MOXA_SUPP_RS232 | MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
  2009		case 0x0300:
  2010			return MOXA_SUPP_RS422 | MOXA_SUPP_RS485;
  2011		}
  2012		return 0;
  2013	}
  2014	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  2023-12-01  9:02   ` Crescent CY Hsieh
@ 2023-12-07  1:33     ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2023-12-07  1:33 UTC (permalink / raw)
  To: Crescent CY Hsieh; +Cc: Jiri Slaby, linux-kernel, linux-serial

On Fri, Dec 01, 2023 at 05:02:33PM +0800, Crescent CY Hsieh wrote:
> On Fri, Dec 01, 2023 at 08:27:05AM +0000, Greg Kroah-Hartman wrote:
> > On Fri, Dec 01, 2023 at 03:40:55PM +0800, 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>
> > > Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
> > > ---
> > >  drivers/tty/serial/8250/8250_pci.c | 58 +++++++++++++++++++++++++++++-
> > >  1 file changed, 57 insertions(+), 1 deletion(-)
> > 
> > Why is this a RESEND?  What happened to the first attempt, did I miss it
> > somewhere?
> 
> This RESEND patch is the first patch of this patch series [1], Jiri
> reviewed the first patch and suggested to split the second patch, so I
> split the second patch and sent it as a new patch.
> 
> However, the first patch seems to be overlooked, so I resend it.
> 
> [1] https://lore.kernel.org/all/20231027062440.7749-1-crescentcy.hsieh@moxa.com/

Looks like 0-day had a problem with it, please fix that up and resend a
new version.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-12-07  6:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01  7:40 [RESEND PATCH] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default Crescent CY Hsieh
2023-12-01  8:27 ` Greg Kroah-Hartman
2023-12-01  9:02   ` Crescent CY Hsieh
2023-12-07  1:33     ` Greg Kroah-Hartman
2023-12-05 21:35 ` kernel test robot

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).