linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c
@ 2023-10-18  9:17 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
                   ` (6 more replies)
  0 siblings, 7 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

These patch series do some changes to MOXA PCIe boards in 8250_pci.c,
including:

- Modify MOXA enum name within 8250_pci.c
- Cleanup MOXA configurations within 8250_pci.c
- Relocate macros within 8250_pci.c
- Add support for MOXA Mini PCIe boards
- Fix MOXA RS422/RS485 boards not function by default
- Add support for MOXA PCIe boards to switch between different serial
  interfaces

Each patch depends on previous one.

---
Changes in v3:
- Add reviewer tag in first 4 patches.
- [PATCH v3 2/6]:
	- Make commit message clearer.
- [PATCH v3 5/6]:
	- Delete pci_moxa_match_x3xx() function.
	- Introduce pci_moxa_match_second_digit() function.
- [PATCH v3 6/6]:
	- Delete pci_moxa_match_x1xx() function.
	- Replace pci_moxa_match_x1xx() and pci_moxa_match_x3xx() with
	  pci_moxa_match_second_digit().
	- Add comment at pci_moxa_rs485_config().
	- Revise comment and return value where device not support RS232
	  interface.

Changes in v2:
- Split cleanup patch into first 2 patches of this patch series.
- Reposition macro list to the top of the code.
- Use PCI_VDEVICE() instead of PCI_DEVICE() in serial_pci_tbl[].
- Replace some C99 types with kernel types.
- Introduce functions for checking device ID pattern.
- Replace magic constant with BIT().
- Sort macros into pre-existing macro list.
- Rewrite set_interface condition architecture.
- Utilize unused flag to represent RS422 interface instead of adding a
  new one.

v2: https://lore.kernel.org/all/20231016033705.20669-1-crescentcy.hsieh@moxa.com/
v1: https://lore.kernel.org/all/20231002015702.30509-1-crescentcy.hsieh@moxa.com/

Crescent CY Hsieh (6):
  tty: serial: 8250: Modify MOXA enum name within 8250_pci.c
  tty: serial: 8250: Cleanup MOXA configurations within 8250_pci.c
  tty: serial: 8250: Relocate macros within 8250_pci.c
  tty: serial: 8250: Add support for MOXA Mini PCIe boards
  tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by
    default
  tty: serial: 8250: Add support for MOXA PCIe boards to switch
    interface between RS422/RS485

 drivers/tty/serial/8250/8250_pci.c | 370 ++++++++++++++++++++---------
 1 file changed, 256 insertions(+), 114 deletions(-)

-- 
2.34.1


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

* [PATCH v3 1/6] tty: serial: 8250: Modify MOXA enum name within 8250_pci.c
  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 ` Crescent CY Hsieh
  2023-10-18  9:17 ` [PATCH v3 2/6] tty: serial: 8250: Cleanup MOXA configurations Crescent CY Hsieh
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

To improve clarity, modify the MOXA enum name within pci_board_num_t.

Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_pci.c | 36 +++++++++++++++---------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index d2d547b5d..b052b286d 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -2852,9 +2852,9 @@ enum pci_board_num_t {
 	pbn_titan_2_4000000,
 	pbn_titan_4_4000000,
 	pbn_titan_8_4000000,
-	pbn_moxa8250_2p,
-	pbn_moxa8250_4p,
-	pbn_moxa8250_8p,
+	pbn_moxa_2,
+	pbn_moxa_4,
+	pbn_moxa_8,
 };
 
 /*
@@ -3626,19 +3626,19 @@ static struct pciserial_board pci_boards[] = {
 		.uart_offset	= 0x200,
 		.first_offset	= 0x1000,
 	},
-	[pbn_moxa8250_2p] = {
+	[pbn_moxa_2] = {
 		.flags		= FL_BASE1,
 		.num_ports      = 2,
 		.base_baud      = 921600,
 		.uart_offset	= 0x200,
 	},
-	[pbn_moxa8250_4p] = {
+	[pbn_moxa_4] = {
 		.flags		= FL_BASE1,
 		.num_ports      = 4,
 		.base_baud      = 921600,
 		.uart_offset	= 0x200,
 	},
-	[pbn_moxa8250_8p] = {
+	[pbn_moxa_8] = {
 		.flags		= FL_BASE1,
 		.num_ports      = 8,
 		.base_baud      = 921600,
@@ -5349,40 +5349,40 @@ static const struct pci_device_id serial_pci_tbl[] = {
 	 */
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102E,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
+		pbn_moxa_2 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102EL,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
+		pbn_moxa_2 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
+		pbn_moxa_4 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114EL,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
+		pbn_moxa_4 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132EL,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
+		pbn_moxa_2 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
+		pbn_moxa_4 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP138E_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A,
 		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+		pbn_moxa_8 },
 
 	/*
 	* ADDI-DATA GmbH communication cards <info@addi-data.com>
-- 
2.34.1


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

* [PATCH v3 2/6] tty: serial: 8250: Cleanup MOXA configurations
  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 ` Crescent CY Hsieh
  2023-10-18  9:17 ` [PATCH v3 3/6] tty: serial: 8250: Relocate macros within 8250_pci.c Crescent CY Hsieh
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

To improve clarity, clean up the MOXA configurations within
serial_pci_tbl using PCI_VDEVICE().

Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_pci.c | 48 ++++++++----------------------
 1 file changed, 12 insertions(+), 36 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index b052b286d..14e2e3433 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -5347,42 +5347,18 @@ static const struct pci_device_id serial_pci_tbl[] = {
 	/*
 	 * MOXA
 	 */
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102E,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_2 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_2 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_4 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_4 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_2 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_4 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP138E_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102E),	    pbn_moxa_2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102EL),    pbn_moxa_2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A),  pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114EL),    pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A), pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B), pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A),  pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I), pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132EL),    pbn_moxa_2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A),  pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP138E_A),   pbn_moxa_8 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A),  pbn_moxa_8 },
 
 	/*
 	* ADDI-DATA GmbH communication cards <info@addi-data.com>
-- 
2.34.1


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

* [PATCH v3 3/6] tty: serial: 8250: Relocate macros within 8250_pci.c
  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 ` 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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

Move PCI_DEVICE_ID macros to the top so that these macros can be used
throughout 8250_pci.c

Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
Reviewed-by: Jiri Slaby <jirislaby@kernel.org>
---
 drivers/tty/serial/8250/8250_pci.c | 144 ++++++++++++++---------------
 1 file changed, 72 insertions(+), 72 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 14e2e3433..ef23f1c6d 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -26,6 +26,78 @@
 #include "8250.h"
 #include "8250_pcilib.h"
 
+#define PCI_VENDOR_ID_SBSMODULARIO	0x124B
+#define PCI_SUBVENDOR_ID_SBSMODULARIO	0x124B
+#define PCI_DEVICE_ID_OCTPRO		0x0001
+#define PCI_SUBDEVICE_ID_OCTPRO232	0x0108
+#define PCI_SUBDEVICE_ID_OCTPRO422	0x0208
+#define PCI_SUBDEVICE_ID_POCTAL232	0x0308
+#define PCI_SUBDEVICE_ID_POCTAL422	0x0408
+#define PCI_SUBDEVICE_ID_SIIG_DUAL_00	0x2500
+#define PCI_SUBDEVICE_ID_SIIG_DUAL_30	0x2530
+#define PCI_VENDOR_ID_ADVANTECH		0x13fe
+#define PCI_DEVICE_ID_INTEL_CE4100_UART 0x2e66
+#define PCI_DEVICE_ID_ADVANTECH_PCI1600	0x1600
+#define PCI_DEVICE_ID_ADVANTECH_PCI1600_1611	0x1611
+#define PCI_DEVICE_ID_ADVANTECH_PCI3620	0x3620
+#define PCI_DEVICE_ID_ADVANTECH_PCI3618	0x3618
+#define PCI_DEVICE_ID_ADVANTECH_PCIf618	0xf618
+#define PCI_DEVICE_ID_TITAN_200I	0x8028
+#define PCI_DEVICE_ID_TITAN_400I	0x8048
+#define PCI_DEVICE_ID_TITAN_800I	0x8088
+#define PCI_DEVICE_ID_TITAN_800EH	0xA007
+#define PCI_DEVICE_ID_TITAN_800EHB	0xA008
+#define PCI_DEVICE_ID_TITAN_400EH	0xA009
+#define PCI_DEVICE_ID_TITAN_100E	0xA010
+#define PCI_DEVICE_ID_TITAN_200E	0xA012
+#define PCI_DEVICE_ID_TITAN_400E	0xA013
+#define PCI_DEVICE_ID_TITAN_800E	0xA014
+#define PCI_DEVICE_ID_TITAN_200EI	0xA016
+#define PCI_DEVICE_ID_TITAN_200EISI	0xA017
+#define PCI_DEVICE_ID_TITAN_200V3	0xA306
+#define PCI_DEVICE_ID_TITAN_400V3	0xA310
+#define PCI_DEVICE_ID_TITAN_410V3	0xA312
+#define PCI_DEVICE_ID_TITAN_800V3	0xA314
+#define PCI_DEVICE_ID_TITAN_800V3B	0xA315
+#define PCI_DEVICE_ID_OXSEMI_16PCI958	0x9538
+#define PCIE_DEVICE_ID_NEO_2_OX_IBM	0x00F6
+#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA	0xc001
+#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
+#define PCI_VENDOR_ID_WCH		0x4348
+#define PCI_DEVICE_ID_WCH_CH352_2S	0x3253
+#define PCI_DEVICE_ID_WCH_CH353_4S	0x3453
+#define PCI_DEVICE_ID_WCH_CH353_2S1PF	0x5046
+#define PCI_DEVICE_ID_WCH_CH353_1S1P	0x5053
+#define PCI_DEVICE_ID_WCH_CH353_2S1P	0x7053
+#define PCI_DEVICE_ID_WCH_CH355_4S	0x7173
+#define PCI_VENDOR_ID_AGESTAR		0x5372
+#define PCI_DEVICE_ID_AGESTAR_9375	0x6872
+#define PCI_DEVICE_ID_BROADCOM_TRUMANAGE 0x160a
+#define PCI_DEVICE_ID_AMCC_ADDIDATA_APCI7800 0x818e
+
+#define PCIE_VENDOR_ID_WCH		0x1c00
+#define PCIE_DEVICE_ID_WCH_CH382_2S1P	0x3250
+#define PCIE_DEVICE_ID_WCH_CH384_4S	0x3470
+#define PCIE_DEVICE_ID_WCH_CH384_8S	0x3853
+#define PCIE_DEVICE_ID_WCH_CH382_2S	0x3253
+
+#define PCI_DEVICE_ID_MOXA_CP102E	0x1024
+#define PCI_DEVICE_ID_MOXA_CP102EL	0x1025
+#define PCI_DEVICE_ID_MOXA_CP104EL_A	0x1045
+#define PCI_DEVICE_ID_MOXA_CP114EL	0x1144
+#define PCI_DEVICE_ID_MOXA_CP116E_A_A	0x1160
+#define PCI_DEVICE_ID_MOXA_CP116E_A_B	0x1161
+#define PCI_DEVICE_ID_MOXA_CP118EL_A	0x1182
+#define PCI_DEVICE_ID_MOXA_CP118E_A_I	0x1183
+#define PCI_DEVICE_ID_MOXA_CP132EL	0x1322
+#define PCI_DEVICE_ID_MOXA_CP134EL_A	0x1342
+#define PCI_DEVICE_ID_MOXA_CP138E_A	0x1381
+#define PCI_DEVICE_ID_MOXA_CP168EL_A	0x1683
+
+/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
+#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584	0x1584
+#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588	0x1588
+
 /*
  * init function returns:
  *  > 0 - number of ports
@@ -1901,78 +1973,6 @@ pci_moxa_setup(struct serial_private *priv,
 	return setup_port(priv, port, bar, offset, 0);
 }
 
-#define PCI_VENDOR_ID_SBSMODULARIO	0x124B
-#define PCI_SUBVENDOR_ID_SBSMODULARIO	0x124B
-#define PCI_DEVICE_ID_OCTPRO		0x0001
-#define PCI_SUBDEVICE_ID_OCTPRO232	0x0108
-#define PCI_SUBDEVICE_ID_OCTPRO422	0x0208
-#define PCI_SUBDEVICE_ID_POCTAL232	0x0308
-#define PCI_SUBDEVICE_ID_POCTAL422	0x0408
-#define PCI_SUBDEVICE_ID_SIIG_DUAL_00	0x2500
-#define PCI_SUBDEVICE_ID_SIIG_DUAL_30	0x2530
-#define PCI_VENDOR_ID_ADVANTECH		0x13fe
-#define PCI_DEVICE_ID_INTEL_CE4100_UART 0x2e66
-#define PCI_DEVICE_ID_ADVANTECH_PCI1600	0x1600
-#define PCI_DEVICE_ID_ADVANTECH_PCI1600_1611	0x1611
-#define PCI_DEVICE_ID_ADVANTECH_PCI3620	0x3620
-#define PCI_DEVICE_ID_ADVANTECH_PCI3618	0x3618
-#define PCI_DEVICE_ID_ADVANTECH_PCIf618	0xf618
-#define PCI_DEVICE_ID_TITAN_200I	0x8028
-#define PCI_DEVICE_ID_TITAN_400I	0x8048
-#define PCI_DEVICE_ID_TITAN_800I	0x8088
-#define PCI_DEVICE_ID_TITAN_800EH	0xA007
-#define PCI_DEVICE_ID_TITAN_800EHB	0xA008
-#define PCI_DEVICE_ID_TITAN_400EH	0xA009
-#define PCI_DEVICE_ID_TITAN_100E	0xA010
-#define PCI_DEVICE_ID_TITAN_200E	0xA012
-#define PCI_DEVICE_ID_TITAN_400E	0xA013
-#define PCI_DEVICE_ID_TITAN_800E	0xA014
-#define PCI_DEVICE_ID_TITAN_200EI	0xA016
-#define PCI_DEVICE_ID_TITAN_200EISI	0xA017
-#define PCI_DEVICE_ID_TITAN_200V3	0xA306
-#define PCI_DEVICE_ID_TITAN_400V3	0xA310
-#define PCI_DEVICE_ID_TITAN_410V3	0xA312
-#define PCI_DEVICE_ID_TITAN_800V3	0xA314
-#define PCI_DEVICE_ID_TITAN_800V3B	0xA315
-#define PCI_DEVICE_ID_OXSEMI_16PCI958	0x9538
-#define PCIE_DEVICE_ID_NEO_2_OX_IBM	0x00F6
-#define PCI_DEVICE_ID_PLX_CRONYX_OMEGA	0xc001
-#define PCI_DEVICE_ID_INTEL_PATSBURG_KT 0x1d3d
-#define PCI_VENDOR_ID_WCH		0x4348
-#define PCI_DEVICE_ID_WCH_CH352_2S	0x3253
-#define PCI_DEVICE_ID_WCH_CH353_4S	0x3453
-#define PCI_DEVICE_ID_WCH_CH353_2S1PF	0x5046
-#define PCI_DEVICE_ID_WCH_CH353_1S1P	0x5053
-#define PCI_DEVICE_ID_WCH_CH353_2S1P	0x7053
-#define PCI_DEVICE_ID_WCH_CH355_4S	0x7173
-#define PCI_VENDOR_ID_AGESTAR		0x5372
-#define PCI_DEVICE_ID_AGESTAR_9375	0x6872
-#define PCI_DEVICE_ID_BROADCOM_TRUMANAGE 0x160a
-#define PCI_DEVICE_ID_AMCC_ADDIDATA_APCI7800 0x818e
-
-#define PCIE_VENDOR_ID_WCH		0x1c00
-#define PCIE_DEVICE_ID_WCH_CH382_2S1P	0x3250
-#define PCIE_DEVICE_ID_WCH_CH384_4S	0x3470
-#define PCIE_DEVICE_ID_WCH_CH384_8S	0x3853
-#define PCIE_DEVICE_ID_WCH_CH382_2S	0x3253
-
-#define	PCI_DEVICE_ID_MOXA_CP102E	0x1024
-#define	PCI_DEVICE_ID_MOXA_CP102EL	0x1025
-#define	PCI_DEVICE_ID_MOXA_CP104EL_A	0x1045
-#define	PCI_DEVICE_ID_MOXA_CP114EL	0x1144
-#define	PCI_DEVICE_ID_MOXA_CP116E_A_A	0x1160
-#define	PCI_DEVICE_ID_MOXA_CP116E_A_B	0x1161
-#define	PCI_DEVICE_ID_MOXA_CP118EL_A	0x1182
-#define	PCI_DEVICE_ID_MOXA_CP118E_A_I	0x1183
-#define	PCI_DEVICE_ID_MOXA_CP132EL	0x1322
-#define	PCI_DEVICE_ID_MOXA_CP134EL_A	0x1342
-#define	PCI_DEVICE_ID_MOXA_CP138E_A	0x1381
-#define	PCI_DEVICE_ID_MOXA_CP168EL_A	0x1683
-
-/* Unknown vendors/cards - this should not be in linux/pci_ids.h */
-#define PCI_SUBDEVICE_ID_UNKNOWN_0x1584	0x1584
-#define PCI_SUBDEVICE_ID_UNKNOWN_0x1588	0x1588
-
 /*
  * Master list of serial port init/setup/exit quirks.
  * This does not describe the general nature of the port.
-- 
2.34.1


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

* [PATCH v3 4/6] tty: serial: 8250: Add support for MOXA Mini PCIe boards
  2023-10-18  9:17 [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

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

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index ef23f1c6d..b2be3783f 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -83,14 +83,20 @@
 
 #define PCI_DEVICE_ID_MOXA_CP102E	0x1024
 #define PCI_DEVICE_ID_MOXA_CP102EL	0x1025
+#define PCI_DEVICE_ID_MOXA_CP102N	0x1027
 #define PCI_DEVICE_ID_MOXA_CP104EL_A	0x1045
+#define PCI_DEVICE_ID_MOXA_CP104N	0x1046
+#define PCI_DEVICE_ID_MOXA_CP112N	0x1121
 #define PCI_DEVICE_ID_MOXA_CP114EL	0x1144
+#define PCI_DEVICE_ID_MOXA_CP114N	0x1145
 #define PCI_DEVICE_ID_MOXA_CP116E_A_A	0x1160
 #define PCI_DEVICE_ID_MOXA_CP116E_A_B	0x1161
 #define PCI_DEVICE_ID_MOXA_CP118EL_A	0x1182
 #define PCI_DEVICE_ID_MOXA_CP118E_A_I	0x1183
 #define PCI_DEVICE_ID_MOXA_CP132EL	0x1322
+#define PCI_DEVICE_ID_MOXA_CP132N	0x1323
 #define PCI_DEVICE_ID_MOXA_CP134EL_A	0x1342
+#define PCI_DEVICE_ID_MOXA_CP134N	0x1343
 #define PCI_DEVICE_ID_MOXA_CP138E_A	0x1381
 #define PCI_DEVICE_ID_MOXA_CP168EL_A	0x1683
 
@@ -1957,6 +1963,49 @@ 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_PIN2	BIT(2)
+
+static bool pci_moxa_is_mini_pcie(unsigned short device)
+{
+	if (device == PCI_DEVICE_ID_MOXA_CP102N	||
+	    device == PCI_DEVICE_ID_MOXA_CP104N	||
+	    device == PCI_DEVICE_ID_MOXA_CP112N	||
+	    device == PCI_DEVICE_ID_MOXA_CP114N ||
+	    device == PCI_DEVICE_ID_MOXA_CP132N ||
+	    device == PCI_DEVICE_ID_MOXA_CP134N)
+		return true;
+
+	return false;
+}
+
+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;
+	u8 val;
+
+	/*
+	 * Enable hardware buffer to prevent break signal output when system boots up.
+	 * This hardware buffer is only supported on Mini PCIe series.
+	 */
+	if (pci_moxa_is_mini_pcie(device)) {
+		/* Set GPIO direction */
+		val = inb(iobar_addr + MOXA_PUART_GPIO_EN);
+		val |= MOXA_GPIO_PIN2;
+		outb(val, iobar_addr + MOXA_PUART_GPIO_EN);
+		/* Enable low GPIO */
+		val = inb(iobar_addr + MOXA_PUART_GPIO_OUT);
+		val &= ~MOXA_GPIO_PIN2;
+		outb(val, iobar_addr + MOXA_PUART_GPIO_OUT);
+	}
+
+	return num_ports;
+}
+
 static int
 pci_moxa_setup(struct serial_private *priv,
 		const struct pciserial_board *board,
@@ -2633,6 +2682,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,
 	},
 	{
@@ -5349,14 +5399,20 @@ static const struct pci_device_id serial_pci_tbl[] = {
 	 */
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102E),	    pbn_moxa_2 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102EL),    pbn_moxa_2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102N),	    pbn_moxa_2 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A),  pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104N),	    pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP112N),	    pbn_moxa_2 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114EL),    pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114N),	    pbn_moxa_4 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A), pbn_moxa_8 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B), pbn_moxa_8 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A),  pbn_moxa_8 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I), pbn_moxa_8 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132EL),    pbn_moxa_2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132N),     pbn_moxa_2 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A),  pbn_moxa_4 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134N),	    pbn_moxa_4 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP138E_A),   pbn_moxa_8 },
 	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A),  pbn_moxa_8 },
 
-- 
2.34.1


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

* [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  2023-10-18  9:17 [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
                   ` (3 preceding siblings ...)
  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 ` Crescent CY Hsieh
  2023-10-19  5:59   ` Jiri Slaby
                     ` (2 more replies)
  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-21 16:31 ` [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Greg Kroah-Hartman
  6 siblings, 3 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 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>
---
 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
@@ -1968,6 +1968,12 @@ 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
+
 static bool pci_moxa_is_mini_pcie(unsigned short device)
 {
 	if (device == PCI_DEVICE_ID_MOXA_CP102N	||
@@ -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;
+}
+
+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 &= 0x0F;
+		val |= mode << 4;
+	} else {
+		val &= 0xF0;
+		val |= 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 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)) {
+		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] 16+ messages in thread

* [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  2023-10-18  9:17 [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
                   ` (4 preceding siblings ...)
  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-18  9:17 ` Crescent CY Hsieh
  2023-10-19  6:06   ` Jiri Slaby
                     ` (2 more replies)
  2023-10-21 16:31 ` [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Greg Kroah-Hartman
  6 siblings, 3 replies; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-18  9:17 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby
  Cc: linux-kernel, linux-serial, Crescent CY Hsieh

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:

- RS232                   = (no flags are set)
- RS422                   = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
- RS485_2W (half-duplex)  = SER_RS485_ENABLED
- RS485_4W (full-duplex)  = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX

Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
---
 drivers/tty/serial/8250/8250_pci.c | 58 ++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 29a28e72b..098ac466b 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1974,6 +1974,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	||
@@ -2024,6 +2028,46 @@ static int pci_moxa_set_interface(const struct pci_dev *dev,
 	return 0;
 }
 
+/*
+ * MOXA PCIe boards support switching the serial interface using the ioctl
+ * command "TIOCSRS485", but there is currently no dedicated flag for switching
+ * to RS422. As a workaround, we utilize the "SER_RS485_TERMINATE_BUS" flag to
+ * represent RS422.
+ *
+ *	RS232			= (no flags are set)
+ *	RS422			= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
+ *	RS485_2W (half-duplex)	= SER_RS485_ENABLED
+ *	RS485_4W (full-duplex)	= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
+ */
+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) {
+		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 MOXA PCIe boards with device IDs
+		 * matching the pattern 0x*3**.
+		 */
+		if (pci_moxa_match_second_digit(device, 0x0300))
+			return -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;
@@ -2063,9 +2107,23 @@ pci_moxa_setup(struct serial_private *priv,
 		const struct pciserial_board *board,
 		struct uart_8250_port *port, int idx)
 {
+	struct pci_dev *dev = priv->dev;
+	unsigned short device = dev->device;
 	unsigned int bar = FL_GET_BASE(board->flags);
 	int offset;
 
+	/*
+	 * For the device IDs of MOXA PCIe boards match the pattern 0x*1** and 0x*3**,
+	 * these boards support switching interface between RS422/RS485 using TIOCSRS485.
+	 */
+	if (pci_moxa_match_second_digit(device, 0x0100) ||
+	    pci_moxa_match_second_digit(device, 0x0300)) {
+		port->port.rs485_config = pci_moxa_rs485_config;
+		port->port.rs485_supported = pci_moxa_rs485_supported;
+
+		if (pci_moxa_match_second_digit(device, 0x0300))
+			port->port.rs485.flags |= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS;
+	}
 	if (board->num_ports == 4 && idx == 3)
 		offset = 7 * board->uart_offset;
 	else
-- 
2.34.1


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

* Re: [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  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
  2023-10-23  9:21   ` Ilpo Järvinen
  2 siblings, 0 replies; 16+ messages in thread
From: Jiri Slaby @ 2023-10-19  5:59 UTC (permalink / raw)
  To: Crescent CY Hsieh, Greg Kroah-Hartman; +Cc: linux-kernel, linux-serial

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>

Reviewed-by: Jiri Slaby <jirislaby@kernel.org>


-- 
js
suse labs


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

* Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  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
  2 siblings, 0 replies; 16+ messages in thread
From: Jiri Slaby @ 2023-10-19  6:06 UTC (permalink / raw)
  To: Crescent CY Hsieh, Greg Kroah-Hartman; +Cc: linux-kernel, linux-serial

On 18. 10. 23, 11:17, 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:
> 
> - RS232                   = (no flags are set)
> - RS422                   = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
> - RS485_2W (half-duplex)  = SER_RS485_ENABLED
> - RS485_4W (full-duplex)  = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> 
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> ---
>   drivers/tty/serial/8250/8250_pci.c | 58 ++++++++++++++++++++++++++++++
>   1 file changed, 58 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index 29a28e72b..098ac466b 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1974,6 +1974,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	||
> @@ -2024,6 +2028,46 @@ static int pci_moxa_set_interface(const struct pci_dev *dev,
>   	return 0;
>   }
>   
> +/*
> + * MOXA PCIe boards support switching the serial interface using the ioctl
> + * command "TIOCSRS485", but there is currently no dedicated flag for switching
> + * to RS422. As a workaround, we utilize the "SER_RS485_TERMINATE_BUS" flag to
> + * represent RS422.
> + *
> + *	RS232			= (no flags are set)
> + *	RS422			= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS

Oh, I noticed only now. Can we implement this properly? I mean by 
defining e.g. SER_RS422_ENABLED? And add checks to 
uart_check_rs485_flags() that only one of 485/422 is set and whatever 
else makes sense.

> + *	RS485_2W (half-duplex)	= SER_RS485_ENABLED
> + *	RS485_4W (full-duplex)	= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> + */

thanks,
-- 
js
suse labs


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

* Re: [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  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
  2023-10-23  9:21   ` Ilpo Järvinen
  2 siblings, 0 replies; 16+ messages in thread
From: Jiri Slaby @ 2023-10-19  6:16 UTC (permalink / raw)
  To: Crescent CY Hsieh, Greg Kroah-Hartman; +Cc: linux-kernel, linux-serial

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


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

* Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  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
  2 siblings, 0 replies; 16+ messages in thread
From: Jiri Slaby @ 2023-10-19  6:24 UTC (permalink / raw)
  To: Crescent CY Hsieh, Greg Kroah-Hartman; +Cc: linux-kernel, linux-serial

On 18. 10. 23, 11:17, 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:
> 
> - RS232                   = (no flags are set)
> - RS422                   = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
> - RS485_2W (half-duplex)  = SER_RS485_ENABLED
> - RS485_4W (full-duplex)  = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> 
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> ---
>   drivers/tty/serial/8250/8250_pci.c | 58 ++++++++++++++++++++++++++++++
>   1 file changed, 58 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index 29a28e72b..098ac466b 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1974,6 +1974,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	||
> @@ -2024,6 +2028,46 @@ static int pci_moxa_set_interface(const struct pci_dev *dev,
>   	return 0;
>   }
>   
> +/*
> + * MOXA PCIe boards support switching the serial interface using the ioctl
> + * command "TIOCSRS485", but there is currently no dedicated flag for switching
> + * to RS422. As a workaround, we utilize the "SER_RS485_TERMINATE_BUS" flag to
> + * represent RS422.
> + *
> + *	RS232			= (no flags are set)
> + *	RS422			= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
> + *	RS485_2W (half-duplex)	= SER_RS485_ENABLED
> + *	RS485_4W (full-duplex)	= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> + */
> +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) {
> +		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 MOXA PCIe boards with device IDs
> +		 * matching the pattern 0x*3**.
> +		 */
> +		if (pci_moxa_match_second_digit(device, 0x0300))

The same here:
if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232))

> +			return -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;
> @@ -2063,9 +2107,23 @@ pci_moxa_setup(struct serial_private *priv,
>   		const struct pciserial_board *board,
>   		struct uart_8250_port *port, int idx)
>   {
> +	struct pci_dev *dev = priv->dev;
> +	unsigned short device = dev->device;
>   	unsigned int bar = FL_GET_BASE(board->flags);
>   	int offset;
>   
> +	/*
> +	 * For the device IDs of MOXA PCIe boards match the pattern 0x*1** and 0x*3**,
> +	 * these boards support switching interface between RS422/RS485 using TIOCSRS485.
> +	 */
> +	if (pci_moxa_match_second_digit(device, 0x0100) ||
> +	    pci_moxa_match_second_digit(device, 0x0300)) {

if (pci_moxa_supported_rs(dev) & (MOXA_SUPP_RS422 | MOXA_SUPP_RS485) ==
     MOXA_SUPP_RS422 | MOXA_SUPP_RS485)

or maybe even simple:

if (pci_moxa_supported_rs(dev) & MOXA_SUPP_RS485)
?

> +		port->port.rs485_config = pci_moxa_rs485_config;
> +		port->port.rs485_supported = pci_moxa_rs485_supported;
> +
> +		if (pci_moxa_match_second_digit(device, 0x0300))

if (!(pci_moxa_supported_rs(dev) & MOXA_SUPP_RS232))

> +			port->port.rs485.flags |= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS;
> +	}
>   	if (board->num_ports == 4 && idx == 3)
>   		offset = 7 * board->uart_offset;
>   	else

-- 
js
suse labs


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

* Re: [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c
  2023-10-18  9:17 [PATCH v3 0/6] tty: serial: 8250: Changes of MOXA PCIe boards in 8250_pci.c Crescent CY Hsieh
                   ` (5 preceding siblings ...)
  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-21 16:31 ` Greg Kroah-Hartman
  6 siblings, 0 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-21 16:31 UTC (permalink / raw)
  To: Crescent CY Hsieh; +Cc: Jiri Slaby, linux-kernel, linux-serial

On Wed, Oct 18, 2023 at 05:17:33PM +0800, Crescent CY Hsieh wrote:
> These patch series do some changes to MOXA PCIe boards in 8250_pci.c,
> including:
> 
> - Modify MOXA enum name within 8250_pci.c
> - Cleanup MOXA configurations within 8250_pci.c
> - Relocate macros within 8250_pci.c
> - Add support for MOXA Mini PCIe boards
> - Fix MOXA RS422/RS485 boards not function by default
> - Add support for MOXA PCIe boards to switch between different serial
>   interfaces
> 
> Each patch depends on previous one.

I've applied the first 4 to my tree now, plaese fix up the last two and
send them as a new patch series for review.

thanks,

greg k-h

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

* Re: [PATCH v3 5/6] tty: serial: 8250: Fix MOXA RS422/RS485 PCIe boards not work by default
  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
@ 2023-10-23  9:21   ` Ilpo Järvinen
  2 siblings, 0 replies; 16+ messages in thread
From: Ilpo Järvinen @ 2023-10-23  9:21 UTC (permalink / raw)
  To: Crescent CY Hsieh
  Cc: Greg Kroah-Hartman, Jiri Slaby, linux-kernel, linux-serial

On Wed, 18 Oct 2023, 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
> @@ -1968,6 +1968,12 @@ 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
> +
>  static bool pci_moxa_is_mini_pcie(unsigned short device)
>  {
>  	if (device == PCI_DEVICE_ID_MOXA_CP102N	||
> @@ -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;

Define a named field, not literal.

IMO, the function name is not good because it tells what code does, not 
why it does. I think the name should be based on .

> +}
> +
> +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 &= 0x0F;
> +		val |= mode << 4;
> +	} else {
> +		val &= 0xF0;
> +		val |= mode;

These should use the typical pattern instead:

	val &= ~NAMED_DEFINE;
	val |= FIELD_PREP(NAMED_DEFINE, mode);

Also, don't forget to add bitfield.h if it's not there yet among the 
includes.

-- 
 i.



> +	}
> +	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 i;
>  	unsigned int num_ports = (device & 0x00F0) >> 4;

Put declaration of i after num_ports.

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

Name the literal with define, once you have better name for the function 
and no literal, the comment is no longer necessary at all because the code 
will document itself much better!

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

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

* Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  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
  2 siblings, 1 reply; 16+ messages in thread
From: Ilpo Järvinen @ 2023-10-23  9:25 UTC (permalink / raw)
  To: Crescent CY Hsieh; +Cc: Greg Kroah-Hartman, Jiri Slaby, LKML, linux-serial

On Wed, 18 Oct 2023, 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:
> 
> - RS232                   = (no flags are set)
> - RS422                   = SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
> - RS485_2W (half-duplex)  = SER_RS485_ENABLED
> - RS485_4W (full-duplex)  = SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> 
> Signed-off-by: Crescent CY Hsieh <crescentcy.hsieh@moxa.com>
> ---
>  drivers/tty/serial/8250/8250_pci.c | 58 ++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
> 
> diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
> index 29a28e72b..098ac466b 100644
> --- a/drivers/tty/serial/8250/8250_pci.c
> +++ b/drivers/tty/serial/8250/8250_pci.c
> @@ -1974,6 +1974,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,

As recently discussed on linux-serial list, one of the RTS flags should be
enabled (the one the HW uses even if it's not configurable).

> +};
> +
>  static bool pci_moxa_is_mini_pcie(unsigned short device)
>  {
>  	if (device == PCI_DEVICE_ID_MOXA_CP102N	||
> @@ -2024,6 +2028,46 @@ static int pci_moxa_set_interface(const struct pci_dev *dev,
>  	return 0;
>  }
>  
> +/*
> + * MOXA PCIe boards support switching the serial interface using the ioctl
> + * command "TIOCSRS485", but there is currently no dedicated flag for switching
> + * to RS422. As a workaround, we utilize the "SER_RS485_TERMINATE_BUS" flag to
> + * represent RS422.
> + *
> + *	RS232			= (no flags are set)
> + *	RS422			= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS
> + *	RS485_2W (half-duplex)	= SER_RS485_ENABLED
> + *	RS485_4W (full-duplex)	= SER_RS485_ENABLED | SER_RS485_RX_DURING_TX
> + */
> +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) {
> +		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 MOXA PCIe boards with device IDs
> +		 * matching the pattern 0x*3**.
> +		 */
> +		if (pci_moxa_match_second_digit(device, 0x0300))
> +			return -EOPNOTSUPP;

This is not the correct error code I think. Maybe return -ENXIO instead.

> +	}
> +
> +	return pci_moxa_set_interface(dev, port->port_id, mode);
> +}
> +
>  static int pci_moxa_init(struct pci_dev *dev)
>  {
>  	unsigned short device = dev->device;
> @@ -2063,9 +2107,23 @@ pci_moxa_setup(struct serial_private *priv,
>  		const struct pciserial_board *board,
>  		struct uart_8250_port *port, int idx)
>  {
> +	struct pci_dev *dev = priv->dev;
> +	unsigned short device = dev->device;
>  	unsigned int bar = FL_GET_BASE(board->flags);
>  	int offset;
>  
> +	/*
> +	 * For the device IDs of MOXA PCIe boards match the pattern 0x*1** and 0x*3**,
> +	 * these boards support switching interface between RS422/RS485 using TIOCSRS485.
> +	 */
> +	if (pci_moxa_match_second_digit(device, 0x0100) ||
> +	    pci_moxa_match_second_digit(device, 0x0300)) {

As mentioned in the other patch, all these literals must be named.

> +		port->port.rs485_config = pci_moxa_rs485_config;
> +		port->port.rs485_supported = pci_moxa_rs485_supported;
> +
> +		if (pci_moxa_match_second_digit(device, 0x0300))
> +			port->port.rs485.flags |= SER_RS485_ENABLED | SER_RS485_TERMINATE_BUS;
> +	}
>  	if (board->num_ports == 4 && idx == 3)
>  		offset = 7 * board->uart_offset;
>  	else
> 

-- 
 i.


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

* Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  2023-10-23  9:25   ` Ilpo Järvinen
@ 2023-10-24  7:48     ` Crescent CY Hsieh
  2023-10-24  8:10       ` Greg Kroah-Hartman
  0 siblings, 1 reply; 16+ messages in thread
From: Crescent CY Hsieh @ 2023-10-24  7:48 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: Greg Kroah-Hartman, Jiri Slaby, LKML, linux-serial

On Mon, Oct 23, 2023 at 12:25:18PM +0300, Ilpo Järvinen wrote:
> On Wed, 18 Oct 2023, Crescent CY Hsieh wrote:
> > +		/*
> > +		 * RS232 is not supported for MOXA PCIe boards with device IDs
> > +		 * matching the pattern 0x*3**.
> > +		 */
> > +		if (pci_moxa_match_second_digit(device, 0x0300))
> > +			return -EOPNOTSUPP;
> 
> This is not the correct error code I think. Maybe return -ENXIO instead.

I think EOPNOTSUPP or ENOTSUPP would be more reasonable, they directly
indicates "operation is not supported".

However, EOPNOTSUPP is used for network-related and ENOTSUPP is used for
NFSv3 protocol, even though they are already been used throughout the
kernel.

Maybe add a new one stand for serial, or clean them up into a general
one, or use EOPNOTSUPP and ENOTSUPP just for now?

---
Sincerely,
Crescent CY Hsieh

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

* Re: [PATCH v3 6/6] tty: serial: 8250: Add support for MOXA PCIe boards to switch interface between RS422/RS485
  2023-10-24  7:48     ` Crescent CY Hsieh
@ 2023-10-24  8:10       ` Greg Kroah-Hartman
  0 siblings, 0 replies; 16+ messages in thread
From: Greg Kroah-Hartman @ 2023-10-24  8:10 UTC (permalink / raw)
  To: Crescent CY Hsieh; +Cc: Ilpo Järvinen, Jiri Slaby, LKML, linux-serial

On Tue, Oct 24, 2023 at 03:48:07PM +0800, Crescent CY Hsieh wrote:
> On Mon, Oct 23, 2023 at 12:25:18PM +0300, Ilpo Järvinen wrote:
> > On Wed, 18 Oct 2023, Crescent CY Hsieh wrote:
> > > +		/*
> > > +		 * RS232 is not supported for MOXA PCIe boards with device IDs
> > > +		 * matching the pattern 0x*3**.
> > > +		 */
> > > +		if (pci_moxa_match_second_digit(device, 0x0300))
> > > +			return -EOPNOTSUPP;
> > 
> > This is not the correct error code I think. Maybe return -ENXIO instead.
> 
> I think EOPNOTSUPP or ENOTSUPP would be more reasonable, they directly
> indicates "operation is not supported".
> 
> However, EOPNOTSUPP is used for network-related and ENOTSUPP is used for
> NFSv3 protocol, even though they are already been used throughout the
> kernel.
> 
> Maybe add a new one stand for serial, or clean them up into a general
> one, or use EOPNOTSUPP and ENOTSUPP just for now?

-ENODEV should be the proper one here.

thanks,

greg k-h

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

end of thread, other threads:[~2023-10-24  8:10 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

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