diff mbox series

[1/4] tty: serial: 8250: Cleanup MOXA configurations in 8250_pci.c

Message ID 20231002015702.30509-2-crescentcy.hsieh@moxa.com
State New
Headers show
Series [1/4] tty: serial: 8250: Cleanup MOXA configurations in 8250_pci.c | expand

Commit Message

Crescent CY Hsieh Oct. 2, 2023, 1:56 a.m. UTC
To enhance the maintainability of MOXA configurations in 8250_pci.c,
clean up the code to achieve simplicity, clarity and consistency.

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

Comments

Crescent CY Hsieh Oct. 3, 2023, 7:17 a.m. UTC | #1
On Mon, Oct 02, 2023 at 08:51:03AM +0200, Jiri Slaby wrote:
> On 02. 10. 23, 3:56, Crescent CY Hsieh wrote:
> > @@ -1958,6 +1958,9 @@ pci_moxa_setup(struct serial_private *priv,
> >   #define PCIE_DEVICE_ID_WCH_CH384_8S	0x3853
> >   #define PCIE_DEVICE_ID_WCH_CH382_2S	0x3253
> > +/* MOXA */
> > +#define PCI_VENDOR_ID_MOXA	0x1393
> 
> Isn't this a redefinition of the pci-ids.h one?

At first, I attempt to place DEVICE_ID macros into pci_ids.h to enable
their usage throughout 8250_pci.c and to establish centralized
management. However, I notice the comment in pci_ids.h which is:

'Do not add new entries to this file unless the definitions are shared
between multiple drivers'

So I add this VENDOR_ID just for the clarity, even though it results in
duplication.

Should I put these macros into pci_ids.h? If so, I am willing to help
relocate all other macros.

---
Sincerely,
Crescent CY Hsieh
Greg Kroah-Hartman Oct. 3, 2023, 7:30 a.m. UTC | #2
On Tue, Oct 03, 2023 at 03:17:47PM +0800, Crescent CY Hsieh wrote:
> On Mon, Oct 02, 2023 at 08:51:03AM +0200, Jiri Slaby wrote:
> > On 02. 10. 23, 3:56, Crescent CY Hsieh wrote:
> > > @@ -1958,6 +1958,9 @@ pci_moxa_setup(struct serial_private *priv,
> > >   #define PCIE_DEVICE_ID_WCH_CH384_8S	0x3853
> > >   #define PCIE_DEVICE_ID_WCH_CH382_2S	0x3253
> > > +/* MOXA */
> > > +#define PCI_VENDOR_ID_MOXA	0x1393
> > 
> > Isn't this a redefinition of the pci-ids.h one?
> 
> At first, I attempt to place DEVICE_ID macros into pci_ids.h to enable
> their usage throughout 8250_pci.c and to establish centralized
> management. However, I notice the comment in pci_ids.h which is:
> 
> 'Do not add new entries to this file unless the definitions are shared
> between multiple drivers'
> 
> So I add this VENDOR_ID just for the clarity, even though it results in
> duplication.
> 
> Should I put these macros into pci_ids.h? If so, I am willing to help
> relocate all other macros.

Please do not add new defines to pci_ids.h unless they are needed in
multiple files.

thanks,

greg k-h
Jiri Slaby Oct. 3, 2023, 9:49 a.m. UTC | #3
On 03. 10. 23, 9:30, Greg KH wrote:
>> Should I put these macros into pci_ids.h? If so, I am willing to help
>> relocate all other macros.
> 
> Please do not add new defines to pci_ids.h unless they are needed in
> multiple files.

(Which VENDOR_MOXA is, but DEVICE ids are not.)
diff mbox series

Patch

diff --git a/drivers/tty/serial/8250/8250_pci.c b/drivers/tty/serial/8250/8250_pci.c
index 62a9bd30b4db..a010790ccfcd 100644
--- a/drivers/tty/serial/8250/8250_pci.c
+++ b/drivers/tty/serial/8250/8250_pci.c
@@ -1887,10 +1887,10 @@  pci_sunix_setup(struct serial_private *priv,
 	return setup_port(priv, port, bar, offset, 0);
 }
 
-static int
-pci_moxa_setup(struct serial_private *priv,
-		const struct pciserial_board *board,
-		struct uart_8250_port *port, int idx)
+static int pci_moxa_setup(struct serial_private *priv,
+			  const struct pciserial_board *board,
+			  struct uart_8250_port *port,
+			  int idx)
 {
 	unsigned int bar = FL_GET_BASE(board->flags);
 	int offset;
@@ -1958,6 +1958,9 @@  pci_moxa_setup(struct serial_private *priv,
 #define PCIE_DEVICE_ID_WCH_CH384_8S	0x3853
 #define PCIE_DEVICE_ID_WCH_CH382_2S	0x3253
 
+/* MOXA */
+#define PCI_VENDOR_ID_MOXA	0x1393
+/* MOXA PCIe */
 #define	PCI_DEVICE_ID_MOXA_CP102E	0x1024
 #define	PCI_DEVICE_ID_MOXA_CP102EL	0x1025
 #define	PCI_DEVICE_ID_MOXA_CP104EL_A	0x1045
@@ -2854,9 +2857,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,
 };
 
 /*
@@ -3628,19 +3631,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,
@@ -5347,44 +5350,20 @@  static const struct pci_device_id serial_pci_tbl[] = {
 		pbn_ni8430_4 },
 
 	/*
-	 * MOXA
+	 * MOXA PCIe
 	 */
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102E,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132EL,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_2p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_4p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP138E_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
-	{	PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP168EL_A,
-		PCI_ANY_ID, PCI_ANY_ID, 0, 0,
-		pbn_moxa8250_8p },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102E),	 0, 0, pbn_moxa_2 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP102EL),	 0, 0, pbn_moxa_2 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP104EL_A),	 0, 0, pbn_moxa_4 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP114EL),	 0, 0, pbn_moxa_4 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_A), 0, 0, pbn_moxa_8 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP116E_A_B), 0, 0, pbn_moxa_8 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118EL_A),	 0, 0, pbn_moxa_8 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP118E_A_I), 0, 0, pbn_moxa_8 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP132EL),	 0, 0, pbn_moxa_2 },
+	{ PCI_DEVICE(PCI_VENDOR_ID_MOXA, PCI_DEVICE_ID_MOXA_CP134EL_A),	 0, 0, pbn_moxa_4 },
+	{ 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 },
 
 	/*
 	* ADDI-DATA GmbH communication cards <info@addi-data.com>