All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] RFC: 16550A pci serial board support
@ 2011-01-04 15:57 Stefan Kisdaroczi
  2011-01-04 19:49 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Kisdaroczi @ 2011-01-04 15:57 UTC (permalink / raw)
  To: xenomai@xenomai.org


[-- Attachment #1.1: Type: text/plain, Size: 323 bytes --]

Hi,

the attached patch adds pci support to the 16550A serial driver. I have
a Moxa CP-132 board and the first tests are looking good. If there is a
chance to get the patch applied I kindly request you to review it. I'll
add support for more Moxa boards if there is a interest to apply the patch.

thanks
Stefan


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: xeno_16550A_pci.patch --]
[-- Type: text/x-patch; name="xeno_16550A_pci.patch", Size: 5433 bytes --]

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index 4c46d86..73665f0 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -140,6 +140,7 @@ MODULE_AUTHOR("jan.kiszka@domain.hid");
 
 #include "16550A_io.h"
 #include "16550A_pnp.h"
+#include "16550A_pci.h"
 
 static inline int rt_16550_rx_interrupt(struct rt_16550_context *ctx,
 					uint64_t * timestamp)
@@ -1119,6 +1120,7 @@ int __init rt_16550_init(void)
 	int i;
 
 	rt_16550_pnp_init();
+	rt_16550_pci_init();
 
 	for (i = 0; i < MAX_DEVICES; i++) {
 		if (!rt_16550_addr_param(i))
@@ -1192,6 +1194,7 @@ void rt_16550_exit(void)
 			kfree(device[i]);
 		}
 
+	rt_16550_pci_cleanup();
 	rt_16550_pnp_cleanup();
 }
 
diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
new file mode 100644
index 0000000..b766888
--- /dev/null
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2006-2007 Jan Kiszka <jan.kiszka@domain.hid>.
+ * Copyright (C) 2011 Stefan Kisdaroczi <kisda@domain.hid>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && defined(CONFIG_PCI) && \
+	defined(CONFIG_XENO_DRIVERS_16550A_PCI)
+
+#include <linux/pci.h>
+
+struct rt_16550_pci_board {
+	char *name;
+	resource_size_t resource_base_addr;
+	unsigned int nports;
+	unsigned int port_ofs;
+	unsigned int baud_base;
+	int tx_fifo;
+};
+
+static const struct rt_16550_pci_board rt_16550_pci_boards[] = {
+/*  0 */ { 0 },
+/*  1 */ { "Moxa C104H/PCI",	2, 4, 8, 921600, 16 },
+/*  2 */ { "Moxa C168H/PCI",	2, 8, 8, 921600, 16 },
+/*  3 */ { "Moxa CP-114",	2, 4, 8, 921600, 16 },
+/*  4 */ { "Moxa CP-132",	2, 2, 8, 921600, 16 },
+};
+
+/* driver_data correspond to the line in the structure above */
+DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_tbl ) = {
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),  .driver_data = 1 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),  .driver_data = 2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114), .driver_data = 3 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132), .driver_data = 4 },
+#endif
+	{ 0 }
+};
+
+static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
+					 const struct pci_device_id *ent )
+{
+	struct rt_16550_pci_board *board;
+	int err;
+	int i;
+	int port = 0;
+	int base_addr;
+	int max_devices = 0;
+
+	if (!ent->driver_data)
+		return -ENODEV;
+
+	board = &rt_16550_pci_boards[ent->driver_data];
+
+	for (i = 0; i < MAX_DEVICES; i++)
+		if (!rt_16550_addr_param(i))
+			max_devices++;
+
+	if (board->nports > max_devices)
+		return -ENODEV;
+
+	if (err = pci_enable_device(pdev))
+		return err;
+
+	base_addr = pci_resource_start(pdev, board->resource_base_addr);
+
+	for (i = 0; i < MAX_DEVICES; i++) {
+		if ((port < board->nports) && (!rt_16550_addr_param(i))) {
+			io[i] = base_addr + port * board->port_ofs;
+			irq[i] = pdev->irq;
+			baud_base[i] = board->baud_base;
+			tx_fifo[i] = board->tx_fifo;
+			port++;
+		}
+	}
+
+	return 0;
+}
+
+static void __devexit rt_16550_pci_remove( struct pci_dev *pdev ) {
+	pci_disable_device( pdev );
+};
+
+static struct pci_driver rt_16550_pci_driver = {
+	.name     = RT_16550_DRIVER_NAME,
+	.id_table = rt_16550_pci_tbl,
+	.probe    = rt_16550_pci_probe,
+	.remove   = __devexit_p(rt_16550_pci_remove)
+};
+
+static int pci_registered;
+
+static inline void rt_16550_pci_init(void)
+{
+	if (pci_register_driver(&rt_16550_pci_driver) == 0)
+		pci_registered = 1;
+}
+
+static inline void rt_16550_pci_cleanup(void)
+{
+	if (pci_registered)
+		pci_unregister_driver(&rt_16550_pci_driver);
+}
+
+#else /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
+
+#define rt_16550_pci_init()	do { } while (0)
+#define rt_16550_pci_cleanup()	do { } while (0)
+
+#endif /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index afbaabf..4964f05 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -39,4 +39,24 @@ config XENO_DRIVERS_16550A_ANY
 
 endchoice
 
+config XENO_DRIVERS_16550A_PCI
+	depends on XENO_DRIVERS_16550A_PIO || XENO_DRIVERS_16550A_ANY
+	bool "PCI board support"
+	default n
+	help
+
+	This option activates support for PCI serial boards.
+
+config XENO_DRIVERS_16550A_PCI_MOXA
+	depends on XENO_DRIVERS_16550A_PCI
+	bool "Moxa multiport PCI boards"
+	default n
+	help
+
+	This option activates support for the following Moxa PCI serial boards:
+	- C104H/PCI
+	- C168H/PCI
+	- CP-114
+	- CP-132
+
 endmenu

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-04 15:57 [Xenomai-help] RFC: 16550A pci serial board support Stefan Kisdaroczi
@ 2011-01-04 19:49 ` Gilles Chanteperdrix
  2011-01-05 19:40   ` Stefan Kisdaroczi
  0 siblings, 1 reply; 10+ messages in thread
From: Gilles Chanteperdrix @ 2011-01-04 19:49 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai@xenomai.org

Stefan Kisdaroczi wrote:
> Hi,
> 
> the attached patch adds pci support to the 16550A serial driver. I have
> a Moxa CP-132 board and the first tests are looking good. If there is a
> chance to get the patch applied I kindly request you to review it. I'll
> add support for more Moxa boards if there is a interest to apply the patch.
> 
> thanks
> Stefan

Looks fine to me, however, nit-picking a bit, could we do this differently:

+static const struct rt_16550_pci_board rt_16550_pci_boards[] = {
+/*  0 */ { 0 },
+/*  1 */ { "Moxa C104H/PCI",	2, 4, 8, 921600, 16 },
+/*  2 */ { "Moxa C168H/PCI",	2, 8, 8, 921600, 16 },
+/*  3 */ { "Moxa CP-114",	2, 4, 8, 921600, 16 },
+/*  4 */ { "Moxa CP-132",	2, 2, 8, 921600, 16 },
+};
+
+/* driver_data correspond to the line in the structure above */
+DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_tbl ) = {
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),  .driver_data = 1 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),  .driver_data = 2 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114), .driver_data = 3 },
+	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132), .driver_data = 4 },
+#endif
+	{ 0 }
+};

For instance:

static const struct rt_16550_pci_board rt_16550_moxa_c104 = {
	.name = "Moxa C104H/PCI",
	.resource_base_addr = 2,
	.nports = 4,
	.port_ofs = 8,
	.baud_base = 921600,
	.tx_fifo = 16,
};

/* ... */

DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_tbl ) = {
#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
	{ PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),  .driver_data = &rt_16550_moxa_c104 },

/* ... */
};

static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
					 const struct pci_device_id *ent )
{
	struct rt_16550_pci_board *board;
	int err;
	int i;
	int port = 0;
	int base_addr;
	int max_devices = 0;

	if (!ent->driver_data)
		return -ENODEV;

	board = (struct rt_16550_pci_board *)ent->driver_data;


> 
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Xenomai-help mailing list
> Xenomai-help@domain.hid
> https://mail.gna.org/listinfo/xenomai-help


-- 
                                                                Gilles.


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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-04 19:49 ` Gilles Chanteperdrix
@ 2011-01-05 19:40   ` Stefan Kisdaroczi
  2011-01-05 19:55     ` Jan Kiszka
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Kisdaroczi @ 2011-01-05 19:40 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai

[-- Attachment #1: Type: Text/Plain, Size: 543 bytes --]

Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
> Stefan Kisdaroczi wrote:
> > Hi,
> > 
> > the attached patch adds pci support to the 16550A serial driver. I have
> > a Moxa CP-132 board and the first tests are looking good. If there is a
> > chance to get the patch applied I kindly request you to review it. I'll
> > add support for more Moxa boards if there is a interest to apply the
> > patch.
> > 
> > thanks
> > Stefan
> 
> Looks fine to me, however, nit-picking a bit, could we do this differently:

new patches attached.

Stefan

[-- Attachment #2: 0001-16550A-pci-support.patch --]
[-- Type: text/x-patch, Size: 4964 bytes --]

From eff6d96e62b3bd04569cb2e07e675ae3a31d1710 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Wed, 5 Jan 2011 11:18:55 +0100
Subject: [PATCH 1/2] 16550A: pci support

---
 ksrc/drivers/serial/16550A.c     |    3 +
 ksrc/drivers/serial/16550A_pci.h |  108 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |    8 +++
 3 files changed, 119 insertions(+), 0 deletions(-)
 create mode 100644 ksrc/drivers/serial/16550A_pci.h

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index 4c46d86..73665f0 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -140,6 +140,7 @@ MODULE_AUTHOR("jan.kiszka@domain.hid");
 
 #include "16550A_io.h"
 #include "16550A_pnp.h"
+#include "16550A_pci.h"
 
 static inline int rt_16550_rx_interrupt(struct rt_16550_context *ctx,
 					uint64_t * timestamp)
@@ -1119,6 +1120,7 @@ int __init rt_16550_init(void)
 	int i;
 
 	rt_16550_pnp_init();
+	rt_16550_pci_init();
 
 	for (i = 0; i < MAX_DEVICES; i++) {
 		if (!rt_16550_addr_param(i))
@@ -1192,6 +1194,7 @@ void rt_16550_exit(void)
 			kfree(device[i]);
 		}
 
+	rt_16550_pci_cleanup();
 	rt_16550_pnp_cleanup();
 }
 
diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
new file mode 100644
index 0000000..6aff93e
--- /dev/null
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2006-2007 Jan Kiszka <jan.kiszka@domain.hid>.
+ * Copyright (C) 2011 Stefan Kisdaroczi <kisda@domain.hid>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && defined(CONFIG_PCI) && \
+	defined(CONFIG_XENO_DRIVERS_16550A_PCI)
+
+#include <linux/pci.h>
+
+struct rt_16550_pci_board {
+	char *name;
+	resource_size_t resource_base_addr;
+	unsigned int nports;
+	unsigned int port_ofs;
+	unsigned int baud_base;
+	int tx_fifo;
+};
+
+DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+	{ }
+};
+
+static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
+					 const struct pci_device_id *ent )
+{
+	struct rt_16550_pci_board *board;
+	int err;
+	int i;
+	int port = 0;
+	int base_addr;
+	int max_devices = 0;
+
+	if (!ent->driver_data)
+		return -ENODEV;
+
+	board = (struct rt_16550_pci_board *)ent->driver_data;
+
+	for (i = 0; i < MAX_DEVICES; i++)
+		if (!rt_16550_addr_param(i))
+			max_devices++;
+
+	if (board->nports > max_devices)
+		return -ENODEV;
+
+	if (err = pci_enable_device(pdev))
+		return err;
+
+	base_addr = pci_resource_start(pdev, board->resource_base_addr);
+
+	for (i = 0; i < MAX_DEVICES; i++) {
+		if ((port < board->nports) && (!rt_16550_addr_param(i))) {
+			io[i] = base_addr + port * board->port_ofs;
+			irq[i] = pdev->irq;
+			baud_base[i] = board->baud_base;
+			tx_fifo[i] = board->tx_fifo;
+			port++;
+		}
+	}
+
+	return 0;
+}
+
+static void __devexit rt_16550_pci_remove( struct pci_dev *pdev ) {
+	pci_disable_device( pdev );
+};
+
+static struct pci_driver rt_16550_pci_driver = {
+	.name     = RT_16550_DRIVER_NAME,
+	.id_table = rt_16550_pci_table,
+	.probe    = rt_16550_pci_probe,
+	.remove   = __devexit_p(rt_16550_pci_remove)
+};
+
+static int pci_registered;
+
+static inline void rt_16550_pci_init(void)
+{
+	if (pci_register_driver(&rt_16550_pci_driver) == 0)
+		pci_registered = 1;
+}
+
+static inline void rt_16550_pci_cleanup(void)
+{
+	if (pci_registered)
+		pci_unregister_driver(&rt_16550_pci_driver);
+}
+
+#else /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
+
+#define rt_16550_pci_init()	do { } while (0)
+#define rt_16550_pci_cleanup()	do { } while (0)
+
+#endif /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index afbaabf..b468fbc 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -39,4 +39,12 @@ config XENO_DRIVERS_16550A_ANY
 
 endchoice
 
+config XENO_DRIVERS_16550A_PCI
+	depends on XENO_DRIVERS_16550A_PIO || XENO_DRIVERS_16550A_ANY
+	bool "PCI board support"
+	default n
+	help
+
+	This option activates support for PCI serial boards.
+
 endmenu
-- 
1.7.2.3


[-- Attachment #3: 0002-16550A-Moxa-pci-board-support.patch --]
[-- Type: text/x-patch, Size: 5839 bytes --]

From 73a885e49804d176afbd778eecf4b94582291df2 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Wed, 5 Jan 2011 13:35:01 +0100
Subject: [PATCH 2/2] 16550A: Moxa pci board support

---
 ksrc/drivers/serial/16550A_pci.h |  163 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |   16 ++++
 2 files changed, 179 insertions(+), 0 deletions(-)

diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
index 6aff93e..63ecee8 100644
--- a/ksrc/drivers/serial/16550A_pci.h
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -31,7 +31,170 @@ struct rt_16550_pci_board {
 	int tx_fifo;
 };
 
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+
+#define PCI_DEVICE_ID_CP112UL	0x1120
+#define PCI_DEVICE_ID_CP114UL	0x1143
+#define PCI_DEVICE_ID_CP138U	0x1380
+
+static const struct rt_16550_pci_board rt_16550_moxa_c104 = {
+	.name = "Moxa C104H/PCI",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_c168 = {
+	.name = "Moxa C168H/PCI",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114 = {
+	.name = "Moxa CP-114",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132 = {
+	.name = "Moxa CP-132",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102u = {
+	.name = "Moxa CP-102U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102ul = {
+	.name = "Moxa CP-102UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp104u = {
+	.name = "Moxa CP-104U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp112ul = {
+	.name = "Moxa CP-112UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114ul = {
+	.name = "Moxa CP-114UL",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp118u = {
+	.name = "Moxa CP-118U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132u = {
+	.name = "Moxa CP-132U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp134u = {
+	.name = "Moxa CP-134U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp138u = {
+	.name = "Moxa CP-138U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp168u = {
+	.name = "Moxa CP-168U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+};
+#endif
+
 DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),
+	 .driver_data = &rt_16550_moxa_c104},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),
+	 .driver_data = &rt_16550_moxa_c168},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114),
+	 .driver_data = &rt_16550_moxa_cp114},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132),
+	 .driver_data = &rt_16550_moxa_cp132},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U),
+	 .driver_data = &rt_16550_moxa_cp102u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
+	 .driver_data = &rt_16550_moxa_cp102ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U),
+	 .driver_data = &rt_16550_moxa_cp104u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL),
+	 .driver_data = &rt_16550_moxa_cp112ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL),
+	 .driver_data = &rt_16550_moxa_cp114ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U),
+	 .driver_data = &rt_16550_moxa_cp118u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U),
+	 .driver_data = &rt_16550_moxa_cp132u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U),
+	 .driver_data = &rt_16550_moxa_cp134u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U),
+	 .driver_data = &rt_16550_moxa_cp138u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U),
+	 .driver_data = &rt_16550_moxa_cp168u},
+#endif
 	{ }
 };
 
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index b468fbc..d3c100e 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -47,4 +47,20 @@ config XENO_DRIVERS_16550A_PCI
 
 	This option activates support for PCI serial boards.
 
+config XENO_DRIVERS_16550A_PCI_MOXA
+	depends on XENO_DRIVERS_16550A_PCI
+	bool "Moxa PCI boards"
+	default n
+	help
+
+	This option activates support for the following Moxa boards:
+	PCI Serial Boards:
+	  C104H/PCI, C168H/PCI
+	  CP-114, CP-132
+	Universal PCI Serial Boards:
+	  CP-102U, CP-102UL, CP-104U
+	  CP-112UL, CP-114UL, CP-118U
+	  CP-132U, CP-134U, CP-138U
+	  CP-168U
+
 endmenu
-- 
1.7.2.3


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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-05 19:40   ` Stefan Kisdaroczi
@ 2011-01-05 19:55     ` Jan Kiszka
  2011-01-05 20:07       ` Gilles Chanteperdrix
  2011-01-05 22:03       ` Stefan Kisdaroczi
  0 siblings, 2 replies; 10+ messages in thread
From: Jan Kiszka @ 2011-01-05 19:55 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1031 bytes --]

Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
>> Stefan Kisdaroczi wrote:
>>> Hi,
>>>
>>> the attached patch adds pci support to the 16550A serial driver. I have
>>> a Moxa CP-132 board and the first tests are looking good. If there is a
>>> chance to get the patch applied I kindly request you to review it. I'll
>>> add support for more Moxa boards if there is a interest to apply the
>>> patch.
>>>
>>> thanks
>>> Stefan
>>
>> Looks fine to me, however, nit-picking a bit, could we do this differently:
> 
> new patches attached.
> 

Looks good to me as well except for a minor white space damage:

> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
                                           ^^^^^^^

I have one further suggestion which can be done on top: The RTDM_IRQTYPE
flags should be customized as well. So far we assume edge-type devices,
but PCI is level-triggered. Requesting edge works, but is suboptimal.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-05 19:55     ` Jan Kiszka
@ 2011-01-05 20:07       ` Gilles Chanteperdrix
  2011-01-05 20:18         ` Jan Kiszka
  2011-01-05 22:03       ` Stefan Kisdaroczi
  1 sibling, 1 reply; 10+ messages in thread
From: Gilles Chanteperdrix @ 2011-01-05 20:07 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

Jan Kiszka wrote:
> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
>> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
>>> Stefan Kisdaroczi wrote:
>>>> Hi,
>>>>
>>>> the attached patch adds pci support to the 16550A serial driver. I have
>>>> a Moxa CP-132 board and the first tests are looking good. If there is a
>>>> chance to get the patch applied I kindly request you to review it. I'll
>>>> add support for more Moxa boards if there is a interest to apply the
>>>> patch.
>>>>
>>>> thanks
>>>> Stefan
>>> Looks fine to me, however, nit-picking a bit, could we do this differently:
>> new patches attached.
>>
> 
> Looks good to me as well except for a minor white space damage:
> 
>> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
>                                            ^^^^^^^
> 
> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
> flags should be customized as well. So far we assume edge-type devices,
> but PCI is level-triggered. Requesting edge works, but is suboptimal.

Well, on vanilla linux, the edge handler does not mask the interrupt
line before invoking the handler, so, using the edge handler for level
interrupts should not work and lock-up (except if IRQF_DISABLED is
passed, which should now be the default, OK).

Anyway, is a driver the right place to pass these flags? Since the
interrupt controller pins to which the PCI interrupts are wired really
depends on the board more than on the device driver.

-- 
					    Gilles.


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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-05 20:07       ` Gilles Chanteperdrix
@ 2011-01-05 20:18         ` Jan Kiszka
  0 siblings, 0 replies; 10+ messages in thread
From: Jan Kiszka @ 2011-01-05 20:18 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]

Am 05.01.2011 21:07, Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
>> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
>>> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
>>>> Stefan Kisdaroczi wrote:
>>>>> Hi,
>>>>>
>>>>> the attached patch adds pci support to the 16550A serial driver. I have
>>>>> a Moxa CP-132 board and the first tests are looking good. If there is a
>>>>> chance to get the patch applied I kindly request you to review it. I'll
>>>>> add support for more Moxa boards if there is a interest to apply the
>>>>> patch.
>>>>>
>>>>> thanks
>>>>> Stefan
>>>> Looks fine to me, however, nit-picking a bit, could we do this differently:
>>> new patches attached.
>>>
>>
>> Looks good to me as well except for a minor white space damage:
>>
>>> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
>>                                            ^^^^^^^
>>
>> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
>> flags should be customized as well. So far we assume edge-type devices,
>> but PCI is level-triggered. Requesting edge works, but is suboptimal.
> 
> Well, on vanilla linux, the edge handler does not mask the interrupt
> line before invoking the handler, so, using the edge handler for level
> interrupts should not work and lock-up (except if IRQF_DISABLED is
> passed, which should now be the default, OK).

IRQF_DISABLED is a (soon to be removed) nop these days, all handlers are
called with interrupts disabled.

> 
> Anyway, is a driver the right place to pass these flags? Since the
> interrupt controller pins to which the PCI interrupts are wired really
> depends on the board more than on the device driver.
> 

I know. But can we always obtain the required information from Linux? If
Xenomai could set the right types automatically, that would be much
better of course.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-05 19:55     ` Jan Kiszka
  2011-01-05 20:07       ` Gilles Chanteperdrix
@ 2011-01-05 22:03       ` Stefan Kisdaroczi
  2011-01-07  8:28         ` Jan Kiszka
  1 sibling, 1 reply; 10+ messages in thread
From: Stefan Kisdaroczi @ 2011-01-05 22:03 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

[-- Attachment #1: Type: Text/Plain, Size: 1242 bytes --]

Am Mittwoch 05 Januar 2011, 20:55:29 schrieb Jan Kiszka:
> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
> > Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
> >> Stefan Kisdaroczi wrote:
> >>> Hi,
> >>> 
> >>> the attached patch adds pci support to the 16550A serial driver. I have
> >>> a Moxa CP-132 board and the first tests are looking good. If there is a
> >>> chance to get the patch applied I kindly request you to review it. I'll
> >>> add support for more Moxa boards if there is a interest to apply the
> >>> patch.
> >>> 
> >>> thanks
> >>> Stefan
> >> 
> >> Looks fine to me, however, nit-picking a bit, could we do this differently:
> > new patches attached.
> 
> Looks good to me as well except for a minor white space damage:
> > +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
> 
>                                            ^^^^^^^
> 
> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
> flags should be customized as well. So far we assume edge-type devices,
> but PCI is level-triggered. Requesting edge works, but is suboptimal.
> 
> Jan

thanks for the input. updated patches attached with customizable irqtype. 
better? (not compiled and not tested -> tomorrow)

Stefan

[-- Attachment #2: 0001-16550A-customizable-irqtype.patch --]
[-- Type: text/x-patch, Size: 1478 bytes --]

From b657b7534e2fadbfd95b7f3eda2f6f7753649e5d Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Wed, 5 Jan 2011 22:30:36 +0100
Subject: [PATCH 1/3] 16550A: customizable irqtype

---
 ksrc/drivers/serial/16550A.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index 4c46d86..ba6850f 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -119,6 +119,7 @@ static const struct rtser_config default_config = {
 static struct rtdm_device *device[MAX_DEVICES];
 
 static unsigned int irq[MAX_DEVICES];
+static unsigned long irqtype[MAX_DEVICES];
 static unsigned int baud_base[MAX_DEVICES];
 static int tx_fifo[MAX_DEVICES];
 static unsigned int start_index;
@@ -478,8 +479,7 @@ int rt_16550_open(struct rtdm_dev_context *context,
 	rt_16550_set_config(ctx, &default_config, &dummy);
 
 	err = rtdm_irq_request(&ctx->irq_handle, irq[dev_id],
-			       rt_16550_interrupt,
-			       RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE,
+			       rt_16550_interrupt, irqtype[i],
 			       context->device->proc_name, ctx);
 	if (err) {
 		/* reset DTR and RTS */
@@ -1118,6 +1118,9 @@ int __init rt_16550_init(void)
 	int err;
 	int i;
 
+	for (i = 0; i < MAX_DEVICES; i++)
+		irqtype[i] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE;
+
 	rt_16550_pnp_init();
 
 	for (i = 0; i < MAX_DEVICES; i++) {
-- 
1.7.2.3


[-- Attachment #3: 0002-16550A-pci-support.patch --]
[-- Type: text/x-patch, Size: 5066 bytes --]

From 978c5f5e804801d193855dd047e589570a477984 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Wed, 5 Jan 2011 22:38:15 +0100
Subject: [PATCH 2/3] 16550A: pci support

---
 ksrc/drivers/serial/16550A.c     |    3 +
 ksrc/drivers/serial/16550A_pci.h |  110 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |    8 +++
 3 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 ksrc/drivers/serial/16550A_pci.h

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index ba6850f..4d35f2d 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -141,6 +141,7 @@ MODULE_AUTHOR("jan.kiszka@domain.hid");
 
 #include "16550A_io.h"
 #include "16550A_pnp.h"
+#include "16550A_pci.h"
 
 static inline int rt_16550_rx_interrupt(struct rt_16550_context *ctx,
 					uint64_t * timestamp)
@@ -1122,6 +1123,7 @@ int __init rt_16550_init(void)
 		irqtype[i] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE;
 
 	rt_16550_pnp_init();
+	rt_16550_pci_init();
 
 	for (i = 0; i < MAX_DEVICES; i++) {
 		if (!rt_16550_addr_param(i))
@@ -1195,6 +1197,7 @@ void rt_16550_exit(void)
 			kfree(device[i]);
 		}
 
+	rt_16550_pci_cleanup();
 	rt_16550_pnp_cleanup();
 }
 
diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
new file mode 100644
index 0000000..5fd4e10
--- /dev/null
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2006-2007 Jan Kiszka <jan.kiszka@domain.hid>.
+ * Copyright (C) 2011 Stefan Kisdaroczi <kisda@domain.hid>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && defined(CONFIG_PCI) && \
+	defined(CONFIG_XENO_DRIVERS_16550A_PCI)
+
+#include <linux/pci.h>
+
+struct rt_16550_pci_board {
+	char *name;
+	resource_size_t resource_base_addr;
+	unsigned int nports;
+	unsigned int port_ofs;
+	unsigned long irqtype;
+	unsigned int baud_base;
+	int tx_fifo;
+};
+
+DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+	{ }
+};
+
+static int __devinit rt_16550_pci_probe( struct pci_dev *pdev,
+					 const struct pci_device_id *ent )
+{
+	struct rt_16550_pci_board *board;
+	int err;
+	int i;
+	int port = 0;
+	int base_addr;
+	int max_devices = 0;
+
+	if (!ent->driver_data)
+		return -ENODEV;
+
+	board = (struct rt_16550_pci_board *)ent->driver_data;
+
+	for (i = 0; i < MAX_DEVICES; i++)
+		if (!rt_16550_addr_param(i))
+			max_devices++;
+
+	if (board->nports > max_devices)
+		return -ENODEV;
+
+	if (err = pci_enable_device(pdev))
+		return err;
+
+	base_addr = pci_resource_start(pdev, board->resource_base_addr);
+
+	for (i = 0; i < MAX_DEVICES; i++) {
+		if ((port < board->nports) && (!rt_16550_addr_param(i))) {
+			io[i] = base_addr + port * board->port_ofs;
+			irq[i] = pdev->irq;
+			irqtype[i] = board->irqtype;
+			baud_base[i] = board->baud_base;
+			tx_fifo[i] = board->tx_fifo;
+			port++;
+		}
+	}
+
+	return 0;
+}
+
+static void __devexit rt_16550_pci_remove( struct pci_dev *pdev ) {
+	pci_disable_device( pdev );
+};
+
+static struct pci_driver rt_16550_pci_driver = {
+	.name     = RT_16550_DRIVER_NAME,
+	.id_table = rt_16550_pci_table,
+	.probe    = rt_16550_pci_probe,
+	.remove   = __devexit_p(rt_16550_pci_remove)
+};
+
+static int pci_registered;
+
+static inline void rt_16550_pci_init(void)
+{
+	if (pci_register_driver(&rt_16550_pci_driver) == 0)
+		pci_registered = 1;
+}
+
+static inline void rt_16550_pci_cleanup(void)
+{
+	if (pci_registered)
+		pci_unregister_driver(&rt_16550_pci_driver);
+}
+
+#else /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
+
+#define rt_16550_pci_init()	do { } while (0)
+#define rt_16550_pci_cleanup()	do { } while (0)
+
+#endif /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index afbaabf..b468fbc 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -39,4 +39,12 @@ config XENO_DRIVERS_16550A_ANY
 
 endchoice
 
+config XENO_DRIVERS_16550A_PCI
+	depends on XENO_DRIVERS_16550A_PIO || XENO_DRIVERS_16550A_ANY
+	bool "PCI board support"
+	default n
+	help
+
+	This option activates support for PCI serial boards.
+
 endmenu
-- 
1.7.2.3


[-- Attachment #4: 0003-16550A-Moxa-pci-board-support.patch --]
[-- Type: text/x-patch, Size: 6329 bytes --]

From 44fb442f3f91af9b5558203cd892f843dfce01e2 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Wed, 5 Jan 2011 22:49:25 +0100
Subject: [PATCH 3/3] 16550A: Moxa pci board support

---
 ksrc/drivers/serial/16550A_pci.h |  177 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |   16 ++++
 2 files changed, 193 insertions(+), 0 deletions(-)

diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
index 5fd4e10..17777ff 100644
--- a/ksrc/drivers/serial/16550A_pci.h
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -32,7 +32,184 @@ struct rt_16550_pci_board {
 	int tx_fifo;
 };
 
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+
+#define PCI_DEVICE_ID_CP112UL	0x1120
+#define PCI_DEVICE_ID_CP114UL	0x1143
+#define PCI_DEVICE_ID_CP138U	0x1380
+
+static const struct rt_16550_pci_board rt_16550_moxa_c104 = {
+	.name = "Moxa C104H/PCI",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_c168 = {
+	.name = "Moxa C168H/PCI",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114 = {
+	.name = "Moxa CP-114",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132 = {
+	.name = "Moxa CP-132",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102u = {
+	.name = "Moxa CP-102U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102ul = {
+	.name = "Moxa CP-102UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp104u = {
+	.name = "Moxa CP-104U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp112ul = {
+	.name = "Moxa CP-112UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114ul = {
+	.name = "Moxa CP-114UL",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp118u = {
+	.name = "Moxa CP-118U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132u = {
+	.name = "Moxa CP-132U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp134u = {
+	.name = "Moxa CP-134U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp138u = {
+	.name = "Moxa CP-138U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp168u = {
+	.name = "Moxa CP-168U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+#endif
+
 DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),
+	 .driver_data = &rt_16550_moxa_c104},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),
+	 .driver_data = &rt_16550_moxa_c168},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114),
+	 .driver_data = &rt_16550_moxa_cp114},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132),
+	 .driver_data = &rt_16550_moxa_cp132},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U),
+	 .driver_data = &rt_16550_moxa_cp102u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
+	 .driver_data = &rt_16550_moxa_cp102ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U),
+	 .driver_data = &rt_16550_moxa_cp104u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL),
+	 .driver_data = &rt_16550_moxa_cp112ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL),
+	 .driver_data = &rt_16550_moxa_cp114ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U),
+	 .driver_data = &rt_16550_moxa_cp118u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U),
+	 .driver_data = &rt_16550_moxa_cp132u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U),
+	 .driver_data = &rt_16550_moxa_cp134u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U),
+	 .driver_data = &rt_16550_moxa_cp138u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U),
+	 .driver_data = &rt_16550_moxa_cp168u},
+#endif
 	{ }
 };
 
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index b468fbc..d3c100e 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -47,4 +47,20 @@ config XENO_DRIVERS_16550A_PCI
 
 	This option activates support for PCI serial boards.
 
+config XENO_DRIVERS_16550A_PCI_MOXA
+	depends on XENO_DRIVERS_16550A_PCI
+	bool "Moxa PCI boards"
+	default n
+	help
+
+	This option activates support for the following Moxa boards:
+	PCI Serial Boards:
+	  C104H/PCI, C168H/PCI
+	  CP-114, CP-132
+	Universal PCI Serial Boards:
+	  CP-102U, CP-102UL, CP-104U
+	  CP-112UL, CP-114UL, CP-118U
+	  CP-132U, CP-134U, CP-138U
+	  CP-168U
+
 endmenu
-- 
1.7.2.3


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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-05 22:03       ` Stefan Kisdaroczi
@ 2011-01-07  8:28         ` Jan Kiszka
  2011-01-07 22:21           ` Stefan Kisdaroczi
  0 siblings, 1 reply; 10+ messages in thread
From: Jan Kiszka @ 2011-01-07  8:28 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1562 bytes --]

Am 05.01.2011 23:03, Stefan Kisdaroczi wrote:
> Am Mittwoch 05 Januar 2011, 20:55:29 schrieb Jan Kiszka:
>> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
>>> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
>>>> Stefan Kisdaroczi wrote:
>>>>> Hi,
>>>>>
>>>>> the attached patch adds pci support to the 16550A serial driver. I have
>>>>> a Moxa CP-132 board and the first tests are looking good. If there is a
>>>>> chance to get the patch applied I kindly request you to review it. I'll
>>>>> add support for more Moxa boards if there is a interest to apply the
>>>>> patch.
>>>>>
>>>>> thanks
>>>>> Stefan
>>>>
>>>> Looks fine to me, however, nit-picking a bit, could we do this differently:
>>> new patches attached.
>>
>> Looks good to me as well except for a minor white space damage:
>>> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
>>
>>                                            ^^^^^^^
>>
>> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
>> flags should be customized as well. So far we assume edge-type devices,
>> but PCI is level-triggered. Requesting edge works, but is suboptimal.
>>
>> Jan
> 
> thanks for the input. updated patches attached with customizable irqtype. 
> better? (not compiled and not tested -> tomorrow)
> 

Fine with me (unless an even smarter solution shows up, but I don't see
it ATM). One simplification:

static unsigned long irqtype[MAX_DEVICES] = {
	[0 ... MAX_DEVICES-1] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE;
};

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-07  8:28         ` Jan Kiszka
@ 2011-01-07 22:21           ` Stefan Kisdaroczi
  2011-01-07 23:04             ` Gilles Chanteperdrix
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Kisdaroczi @ 2011-01-07 22:21 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai

[-- Attachment #1: Type: Text/Plain, Size: 1705 bytes --]

Am Freitag 07 Januar 2011, 09:28:46 schrieb Jan Kiszka:
> Am 05.01.2011 23:03, Stefan Kisdaroczi wrote:
> > Am Mittwoch 05 Januar 2011, 20:55:29 schrieb Jan Kiszka:
> >> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
> >>> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
> >>>> Stefan Kisdaroczi wrote:
> >>>>> Hi,
> >>>>> 
> >>>>> the attached patch adds pci support to the 16550A serial driver. I
> >>>>> have a Moxa CP-132 board and the first tests are looking good. If
> >>>>> there is a chance to get the patch applied I kindly request you to
> >>>>> review it. I'll add support for more Moxa boards if there is a
> >>>>> interest to apply the patch.
> >>>>> 
> >>>>> thanks
> >>>>> Stefan
> >>>> 
> >>>> Looks fine to me, however, nit-picking a bit, could we do this 
differently:
> >>> new patches attached.
> >> 
> >> Looks good to me as well except for a minor white space damage:
> >>> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
> >>> 
> >>                                            ^^^^^^^
> >> 
> >> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
> >> flags should be customized as well. So far we assume edge-type devices,
> >> but PCI is level-triggered. Requesting edge works, but is suboptimal.
> >> 
> >> Jan
> > 
> > thanks for the input. updated patches attached with customizable irqtype.
> > better? (not compiled and not tested -> tomorrow)
> 
> Fine with me (unless an even smarter solution shows up, but I don't see
> it ATM). One simplification:
> 
> static unsigned long irqtype[MAX_DEVICES] = {
> 	[0 ... MAX_DEVICES-1] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE;
> };
> 
> Jan

fixed and tested patches attached.

Stefan

[-- Attachment #2: 0001-16550A-customizable-irqtype.patch --]
[-- Type: text/x-patch, Size: 1314 bytes --]

From 69ffa9ea1225382fbad995e22caf8da837322b46 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Fri, 7 Jan 2011 20:21:16 +0100
Subject: [PATCH 1/3] 16550A: customizable irqtype

---
 ksrc/drivers/serial/16550A.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index 4c46d86..f290e43 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -119,6 +119,9 @@ static const struct rtser_config default_config = {
 static struct rtdm_device *device[MAX_DEVICES];
 
 static unsigned int irq[MAX_DEVICES];
+static unsigned long irqtype[MAX_DEVICES] = {
+	[0 ... MAX_DEVICES-1] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE
+};
 static unsigned int baud_base[MAX_DEVICES];
 static int tx_fifo[MAX_DEVICES];
 static unsigned int start_index;
@@ -478,8 +481,7 @@ int rt_16550_open(struct rtdm_dev_context *context,
 	rt_16550_set_config(ctx, &default_config, &dummy);
 
 	err = rtdm_irq_request(&ctx->irq_handle, irq[dev_id],
-			       rt_16550_interrupt,
-			       RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE,
+			       rt_16550_interrupt, irqtype[dev_id],
 			       context->device->proc_name, ctx);
 	if (err) {
 		/* reset DTR and RTS */
-- 
1.7.2.3


[-- Attachment #3: 0002-16550A-pci-support.patch --]
[-- Type: text/x-patch, Size: 5020 bytes --]

From 7008e23c297bf966d79eeca534fa3abe7a589ea5 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Fri, 7 Jan 2011 20:21:48 +0100
Subject: [PATCH 2/3] 16550A: pci support

---
 ksrc/drivers/serial/16550A.c     |    3 +
 ksrc/drivers/serial/16550A_pci.h |  110 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |    8 +++
 3 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100644 ksrc/drivers/serial/16550A_pci.h

diff --git a/ksrc/drivers/serial/16550A.c b/ksrc/drivers/serial/16550A.c
index f290e43..8c8c864 100644
--- a/ksrc/drivers/serial/16550A.c
+++ b/ksrc/drivers/serial/16550A.c
@@ -143,6 +143,7 @@ MODULE_AUTHOR("jan.kiszka@domain.hid");
 
 #include "16550A_io.h"
 #include "16550A_pnp.h"
+#include "16550A_pci.h"
 
 static inline int rt_16550_rx_interrupt(struct rt_16550_context *ctx,
 					uint64_t * timestamp)
@@ -1121,6 +1122,7 @@ int __init rt_16550_init(void)
 	int i;
 
 	rt_16550_pnp_init();
+	rt_16550_pci_init();
 
 	for (i = 0; i < MAX_DEVICES; i++) {
 		if (!rt_16550_addr_param(i))
@@ -1194,6 +1196,7 @@ void rt_16550_exit(void)
 			kfree(device[i]);
 		}
 
+	rt_16550_pci_cleanup();
 	rt_16550_pnp_cleanup();
 }
 
diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
new file mode 100644
index 0000000..442846d
--- /dev/null
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2006-2007 Jan Kiszka <jan.kiszka@domain.hid>.
+ * Copyright (C) 2011 Stefan Kisdaroczi <kisda@domain.hid>.
+ *
+ * Xenomai is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Xenomai is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Xenomai; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && defined(CONFIG_PCI) && \
+	defined(CONFIG_XENO_DRIVERS_16550A_PCI)
+
+#include <linux/pci.h>
+
+struct rt_16550_pci_board {
+	char *name;
+	resource_size_t resource_base_addr;
+	unsigned int nports;
+	unsigned int port_ofs;
+	unsigned long irqtype;
+	unsigned int baud_base;
+	int tx_fifo;
+};
+
+DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+	{ }
+};
+
+static int __devinit rt_16550_pci_probe( struct pci_dev *pdev,
+					 const struct pci_device_id *ent )
+{
+	struct rt_16550_pci_board *board;
+	int err;
+	int i;
+	int port = 0;
+	int base_addr;
+	int max_devices = 0;
+
+	if (!ent->driver_data)
+		return -ENODEV;
+
+	board = (struct rt_16550_pci_board *)ent->driver_data;
+
+	for (i = 0; i < MAX_DEVICES; i++)
+		if (!rt_16550_addr_param(i))
+			max_devices++;
+
+	if (board->nports > max_devices)
+		return -ENODEV;
+
+	if ((err = pci_enable_device(pdev)))
+		return err;
+
+	base_addr = pci_resource_start(pdev, board->resource_base_addr);
+
+	for (i = 0; i < MAX_DEVICES; i++) {
+		if ((port < board->nports) && (!rt_16550_addr_param(i))) {
+			io[i] = base_addr + port * board->port_ofs;
+			irq[i] = pdev->irq;
+			irqtype[i] = board->irqtype;
+			baud_base[i] = board->baud_base;
+			tx_fifo[i] = board->tx_fifo;
+			port++;
+		}
+	}
+
+	return 0;
+}
+
+static void __devexit rt_16550_pci_remove( struct pci_dev *pdev ) {
+	pci_disable_device( pdev );
+};
+
+static struct pci_driver rt_16550_pci_driver = {
+	.name     = RT_16550_DRIVER_NAME,
+	.id_table = rt_16550_pci_table,
+	.probe    = rt_16550_pci_probe,
+	.remove   = __devexit_p(rt_16550_pci_remove)
+};
+
+static int pci_registered;
+
+static inline void rt_16550_pci_init(void)
+{
+	if (pci_register_driver(&rt_16550_pci_driver) == 0)
+		pci_registered = 1;
+}
+
+static inline void rt_16550_pci_cleanup(void)
+{
+	if (pci_registered)
+		pci_unregister_driver(&rt_16550_pci_driver);
+}
+
+#else /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
+
+#define rt_16550_pci_init()	do { } while (0)
+#define rt_16550_pci_cleanup()	do { } while (0)
+
+#endif /* Linux < 2.6.0 || !CONFIG_PCI || !(..._16550A_PCI */
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index afbaabf..b468fbc 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -39,4 +39,12 @@ config XENO_DRIVERS_16550A_ANY
 
 endchoice
 
+config XENO_DRIVERS_16550A_PCI
+	depends on XENO_DRIVERS_16550A_PIO || XENO_DRIVERS_16550A_ANY
+	bool "PCI board support"
+	default n
+	help
+
+	This option activates support for PCI serial boards.
+
 endmenu
-- 
1.7.2.3


[-- Attachment #4: 0003-16550A-Moxa-pci-board-support.patch --]
[-- Type: text/x-patch, Size: 6539 bytes --]

From a5bfbb4368d70707c515fa360926840b1f9af1c6 Mon Sep 17 00:00:00 2001
From: Stefan Kisdaroczi <kisda@domain.hid>
Date: Fri, 7 Jan 2011 20:23:27 +0100
Subject: [PATCH 3/3] 16550A: Moxa pci board support

---
 ksrc/drivers/serial/16550A_pci.h |  177 ++++++++++++++++++++++++++++++++++++++
 ksrc/drivers/serial/Kconfig      |   16 ++++
 2 files changed, 193 insertions(+), 0 deletions(-)

diff --git a/ksrc/drivers/serial/16550A_pci.h b/ksrc/drivers/serial/16550A_pci.h
index 442846d..2c71a5e 100644
--- a/ksrc/drivers/serial/16550A_pci.h
+++ b/ksrc/drivers/serial/16550A_pci.h
@@ -32,7 +32,184 @@ struct rt_16550_pci_board {
 	int tx_fifo;
 };
 
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+
+#define PCI_DEVICE_ID_CP112UL	0x1120
+#define PCI_DEVICE_ID_CP114UL	0x1143
+#define PCI_DEVICE_ID_CP138U	0x1380
+
+static const struct rt_16550_pci_board rt_16550_moxa_c104 = {
+	.name = "Moxa C104H/PCI",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_c168 = {
+	.name = "Moxa C168H/PCI",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114 = {
+	.name = "Moxa CP-114",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132 = {
+	.name = "Moxa CP-132",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102u = {
+	.name = "Moxa CP-102U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp102ul = {
+	.name = "Moxa CP-102UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp104u = {
+	.name = "Moxa CP-104U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp112ul = {
+	.name = "Moxa CP-112UL",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp114ul = {
+	.name = "Moxa CP-114UL",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp118u = {
+	.name = "Moxa CP-118U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp132u = {
+	.name = "Moxa CP-132U",
+	.resource_base_addr = 2,
+	.nports = 2,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp134u = {
+	.name = "Moxa CP-134U",
+	.resource_base_addr = 2,
+	.nports = 4,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp138u = {
+	.name = "Moxa CP-138U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+
+static const struct rt_16550_pci_board rt_16550_moxa_cp168u = {
+	.name = "Moxa CP-168U",
+	.resource_base_addr = 2,
+	.nports = 8,
+	.port_ofs = 8,
+	.baud_base = 921600,
+	.tx_fifo = 16,
+	.irqtype = RTDM_IRQTYPE_SHARED,
+};
+#endif
+
 DEFINE_PCI_DEVICE_TABLE( rt_16550_pci_table ) = {
+#if defined(CONFIG_XENO_DRIVERS_16550A_PCI_MOXA)
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C104),
+	 .driver_data = (unsigned long)&rt_16550_moxa_c104},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_C168),
+	 .driver_data = (unsigned long)&rt_16550_moxa_c168},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP114),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp114},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp132},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp102u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP102UL),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp102ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP104U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp104u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP112UL),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp112ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP114UL),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp114ul},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP118U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp118u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP132U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp132u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP134U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp134u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_CP138U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp138u},
+	{PCI_VDEVICE(MOXA, PCI_DEVICE_ID_MOXA_CP168U),
+	 .driver_data = (unsigned long)&rt_16550_moxa_cp168u},
+#endif
 	{ }
 };
 
diff --git a/ksrc/drivers/serial/Kconfig b/ksrc/drivers/serial/Kconfig
index b468fbc..d3c100e 100644
--- a/ksrc/drivers/serial/Kconfig
+++ b/ksrc/drivers/serial/Kconfig
@@ -47,4 +47,20 @@ config XENO_DRIVERS_16550A_PCI
 
 	This option activates support for PCI serial boards.
 
+config XENO_DRIVERS_16550A_PCI_MOXA
+	depends on XENO_DRIVERS_16550A_PCI
+	bool "Moxa PCI boards"
+	default n
+	help
+
+	This option activates support for the following Moxa boards:
+	PCI Serial Boards:
+	  C104H/PCI, C168H/PCI
+	  CP-114, CP-132
+	Universal PCI Serial Boards:
+	  CP-102U, CP-102UL, CP-104U
+	  CP-112UL, CP-114UL, CP-118U
+	  CP-132U, CP-134U, CP-138U
+	  CP-168U
+
 endmenu
-- 
1.7.2.3


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

* Re: [Xenomai-help] RFC: 16550A pci serial board support
  2011-01-07 22:21           ` Stefan Kisdaroczi
@ 2011-01-07 23:04             ` Gilles Chanteperdrix
  0 siblings, 0 replies; 10+ messages in thread
From: Gilles Chanteperdrix @ 2011-01-07 23:04 UTC (permalink / raw)
  To: Stefan Kisdaroczi; +Cc: xenomai, Jan Kiszka

Stefan Kisdaroczi wrote:
> Am Freitag 07 Januar 2011, 09:28:46 schrieb Jan Kiszka:
>> Am 05.01.2011 23:03, Stefan Kisdaroczi wrote:
>>> Am Mittwoch 05 Januar 2011, 20:55:29 schrieb Jan Kiszka:
>>>> Am 05.01.2011 20:40, Stefan Kisdaroczi wrote:
>>>>> Am Dienstag 04 Januar 2011, 20:49:59 schrieben Sie:
>>>>>> Stefan Kisdaroczi wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> the attached patch adds pci support to the 16550A serial driver. I
>>>>>>> have a Moxa CP-132 board and the first tests are looking good. If
>>>>>>> there is a chance to get the patch applied I kindly request you to
>>>>>>> review it. I'll add support for more Moxa boards if there is a
>>>>>>> interest to apply the patch.
>>>>>>>
>>>>>>> thanks
>>>>>>> Stefan
>>>>>> Looks fine to me, however, nit-picking a bit, could we do this 
> differently:
>>>>> new patches attached.
>>>> Looks good to me as well except for a minor white space damage:
>>>>> +static int __devinit rt_16550_pci_probe(       struct pci_dev *pdev,
>>>>>
>>>>                                            ^^^^^^^
>>>>
>>>> I have one further suggestion which can be done on top: The RTDM_IRQTYPE
>>>> flags should be customized as well. So far we assume edge-type devices,
>>>> but PCI is level-triggered. Requesting edge works, but is suboptimal.
>>>>
>>>> Jan
>>> thanks for the input. updated patches attached with customizable irqtype.
>>> better? (not compiled and not tested -> tomorrow)
>> Fine with me (unless an even smarter solution shows up, but I don't see
>> it ATM). One simplification:
>>
>> static unsigned long irqtype[MAX_DEVICES] = {
>> 	[0 ... MAX_DEVICES-1] = RTDM_IRQTYPE_SHARED | RTDM_IRQTYPE_EDGE;
>> };
>>
>> Jan
> 
> fixed and tested patches attached.

Merged. Launching the build-test to see if it compiles fine in all cases.

-- 
                                                                Gilles.


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

end of thread, other threads:[~2011-01-07 23:04 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-04 15:57 [Xenomai-help] RFC: 16550A pci serial board support Stefan Kisdaroczi
2011-01-04 19:49 ` Gilles Chanteperdrix
2011-01-05 19:40   ` Stefan Kisdaroczi
2011-01-05 19:55     ` Jan Kiszka
2011-01-05 20:07       ` Gilles Chanteperdrix
2011-01-05 20:18         ` Jan Kiszka
2011-01-05 22:03       ` Stefan Kisdaroczi
2011-01-07  8:28         ` Jan Kiszka
2011-01-07 22:21           ` Stefan Kisdaroczi
2011-01-07 23:04             ` Gilles Chanteperdrix

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.