mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/3] common: Allow for I/O mapped I/O
@ 2014-04-04 13:41 michel
  2014-04-04 13:41 ` [PATCH 2/3] x86: Add support for IDE on the legacy I/O ports michel
  2014-04-04 13:41 ` [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space michel
  0 siblings, 2 replies; 8+ messages in thread
From: michel @ 2014-04-04 13:41 UTC (permalink / raw)
  To: barebox

From: Michel Stam <m.stam@fugro.nl>

Rework the current framework so that I/O mapped I/O resources are
also possible.
---
 arch/arm/include/asm/io.h     |    2 +
 arch/mips/include/asm/io.h    |    2 +
 arch/nios2/include/asm/io.h   |    2 +
 arch/sandbox/include/asm/io.h |    1 +
 arch/x86/include/asm/io.h     |    2 +
 commands/Kconfig              |    8 ++--
 commands/Makefile             |    2 +-
 commands/iomem.c              |   52 ---------------------------------
 commands/iomemport.c          |   64 +++++++++++++++++++++++++++++++++++++++++
 common/memory.c               |    2 +-
 common/resource.c             |   30 +++++++++++++++----
 drivers/base/driver.c         |   15 +++++----
 drivers/gpio/gpio-generic.c   |    4 +-
 drivers/mfd/syscon.c          |    2 +-
 drivers/misc/sram.c           |    2 +-
 include/driver.h              |    3 +-
 include/linux/ioport.h        |    5 ++-
 17 files changed, 121 insertions(+), 77 deletions(-)
 delete mode 100644 commands/iomem.c
 create mode 100644 commands/iomemport.c

diff --git a/arch/arm/include/asm/io.h b/arch/arm/include/asm/io.h
index e0630eb..ccf1f59 100644
--- a/arch/arm/include/asm/io.h
+++ b/arch/arm/include/asm/io.h
@@ -3,6 +3,8 @@
 
 #include <asm-generic/io.h>
 
+#define	IO_SPACE_LIMIT	0
+
 /*
  * String version of IO memory access ops:
  */
diff --git a/arch/mips/include/asm/io.h b/arch/mips/include/asm/io.h
index 4100e1e..1cc8a51 100644
--- a/arch/mips/include/asm/io.h
+++ b/arch/mips/include/asm/io.h
@@ -14,6 +14,8 @@
 #include <asm/types.h>
 #include <asm/byteorder.h>
 
+#define	IO_SPACE_LIMIT	0
+
 /*****************************************************************************/
 /*
  * readX/writeX() are used to access memory mapped devices. On some
diff --git a/arch/nios2/include/asm/io.h b/arch/nios2/include/asm/io.h
index 8ee48e0..59eea73 100644
--- a/arch/nios2/include/asm/io.h
+++ b/arch/nios2/include/asm/io.h
@@ -22,6 +22,8 @@
 
 #include <asm/byteorder.h>
 
+#define	IO_SPACE_LIMIT	0
+
 #define __raw_writeb(v, a)       (*(volatile unsigned char  *)(a) = (v))
 #define __raw_writew(v, a)       (*(volatile unsigned short *)(a) = (v))
 #define __raw_writel(v, a)       (*(volatile unsigned int   *)(a) = (v))
diff --git a/arch/sandbox/include/asm/io.h b/arch/sandbox/include/asm/io.h
index 8ca164f..35b5784 100644
--- a/arch/sandbox/include/asm/io.h
+++ b/arch/sandbox/include/asm/io.h
@@ -2,5 +2,6 @@
 #define __ASM_SANDBOX_IO_H
 
 #include <asm-generic/io.h>
+#define	IO_SPACE_LIMIT 0
 
 #endif /* __ASM_SANDBOX_IO_H */
diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
index 9cb78e4..f020510 100644
--- a/arch/x86/include/asm/io.h
+++ b/arch/x86/include/asm/io.h
@@ -12,6 +12,8 @@
 
 #include <asm/byteorder.h>
 
+#define	IO_SPACE_LIMIT	0xffff
+
 static inline void outb(unsigned char value, int port)
 {
 	asm volatile("outb %b0, %w1" : : "a"(value), "Nd"(port));
diff --git a/commands/Kconfig b/commands/Kconfig
index cc014f3..33bd353 100644
--- a/commands/Kconfig
+++ b/commands/Kconfig
@@ -307,12 +307,12 @@ config CMD_MEMINFO
 	tristate
 	prompt "meminfo"
 
-config CMD_IOMEM
+config CMD_IOMEMPORT
 	tristate
-	prompt "iomem"
+	prompt "iomem/ioport"
 	help
-	  Show information about iomem usage. Pendant to 'cat /proc/iomem'
-	  under Linux.
+	  Show information about iomem/ioport usage. Pendant to
+	  'cat /proc/iomem' and 'cat /proc/ioports' under Linux.
 
 config CMD_MEMORY
 	bool
diff --git a/commands/Makefile b/commands/Makefile
index e463031..0da1173 100644
--- a/commands/Makefile
+++ b/commands/Makefile
@@ -76,7 +76,7 @@ obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
 obj-$(CONFIG_CMD_OF_PROPERTY)	+= of_property.o
 obj-$(CONFIG_CMD_OF_NODE)	+= of_node.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
-obj-$(CONFIG_CMD_IOMEM)		+= iomem.o
+obj-$(CONFIG_CMD_IOMEMPORT)	+= iomemport.o
 obj-$(CONFIG_CMD_LINUX_EXEC)	+= linux_exec.o
 obj-$(CONFIG_CMD_AUTOMOUNT)	+= automount.o
 obj-$(CONFIG_CMD_GLOBAL)	+= global.o
diff --git a/commands/iomem.c b/commands/iomem.c
deleted file mode 100644
index e117c2a..0000000
--- a/commands/iomem.c
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * iomem.c - barebox iomem command
- *
- * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
- *
- * See file CREDITS for list of people who contributed to this
- * project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2
- * as published by the Free Software Foundation.
- *
- * This program 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.
- */
-#include <common.h>
-#include <command.h>
-
-static void __print_resources(struct resource *res, int indent)
-{
-	struct resource *r;
-	int i;
-
-	for (i = 0; i < indent; i++)
-		printf("  ");
-
-	printf(PRINTF_CONVERSION_RESOURCE " - " PRINTF_CONVERSION_RESOURCE
-			" (size " PRINTF_CONVERSION_RESOURCE ") %s\n", res->start,
-			res->end, resource_size(res), res->name);
-
-	list_for_each_entry(r, &res->children, sibling)
-		__print_resources(r, indent + 1);
-}
-
-static void print_resources(struct resource *res)
-{
-	__print_resources(res, 0);
-}
-
-static int do_iomem(int argc, char *argv[])
-{
-	print_resources(&iomem_resource);
-
-	return 0;
-}
-
-BAREBOX_CMD_START(iomem)
-	.cmd		= do_iomem,
-	.usage		= "show iomem usage",
-BAREBOX_CMD_END
diff --git a/commands/iomemport.c b/commands/iomemport.c
new file mode 100644
index 0000000..5ae48ac
--- /dev/null
+++ b/commands/iomemport.c
@@ -0,0 +1,64 @@
+/*
+ * iomem.c - barebox iomem command
+ *
+ * Copyright (c) 2011 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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.
+ */
+#include <common.h>
+#include <command.h>
+
+static void __print_resources(struct resource *res, int indent)
+{
+	struct resource *r;
+	int i;
+
+	for (i = 0; i < indent; i++)
+		printf("  ");
+
+	printf(PRINTF_CONVERSION_RESOURCE " - " PRINTF_CONVERSION_RESOURCE
+			" (size " PRINTF_CONVERSION_RESOURCE ") %s\n", res->start,
+			res->end, resource_size(res), res->name);
+
+	list_for_each_entry(r, &res->children, sibling)
+		__print_resources(r, indent + 1);
+}
+
+static void print_resources(struct resource *res)
+{
+	__print_resources(res, 0);
+}
+
+static int do_iomem(int argc, char *argv[])
+{
+	print_resources(&iomem_resource);
+
+	return 0;
+}
+
+static int do_ioport(int argc, char *argv[])
+{
+	print_resources(&ioport_resource);
+
+	return 0;
+}
+
+BAREBOX_CMD_START(iomem)
+	.cmd		= do_iomem,
+	.usage		= "show iomem usage",
+BAREBOX_CMD_END
+
+BAREBOX_CMD_START(ioport)
+	.cmd		= do_ioport,
+	.usage		= "show ioport usage",
+BAREBOX_CMD_END
diff --git a/common/memory.c b/common/memory.c
index c82bbaa..1ccf1eb 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -148,7 +148,7 @@ struct resource *request_sdram_region(const char *name, resource_size_t start,
 	for_each_memory_bank(bank) {
 		struct resource *res;
 
-		res = request_region(bank->res, name, start, start + size - 1);
+		res = __request_region(bank->res, name, start, start + size - 1);
 		if (res)
 			return res;
 	}
diff --git a/common/resource.c b/common/resource.c
index 5795e79..f05e12f 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 #include <init.h>
 #include <linux/ioport.h>
+#include <asm/io.h>
 
 static int init_resource(struct resource *res, const char *name)
 {
@@ -36,7 +37,7 @@ static int init_resource(struct resource *res, const char *name)
  * the parent resource and does not conflict with any of the child
  * resources.
  */
-struct resource *request_region(struct resource *parent,
+struct resource *__request_region(struct resource *parent,
 		const char *name, resource_size_t start,
 		resource_size_t end)
 {
@@ -95,7 +96,7 @@ ok:
 }
 
 /*
- * release a region previously requested with request_region
+ * release a region previously requested with request_*_region
  */
 int release_region(struct resource *res)
 {
@@ -109,7 +110,7 @@ int release_region(struct resource *res)
 	return 0;
 }
 
-/* The root resource for the whole io space */
+/* The root resource for the whole memory-mapped io space */
 struct resource iomem_resource = {
 	.start = 0,
 	.end = 0xffffffff,
@@ -118,10 +119,27 @@ struct resource iomem_resource = {
 };
 
 /*
- * request a region inside the io space
+ * request a region inside the io space (memory)
  */
-struct resource *request_iomem_region(const char *name,
+inline struct resource *request_iomem_region(const char *name,
 		resource_size_t start, resource_size_t end)
 {
-	return request_region(&iomem_resource, name, start, end);
+	return __request_region(&iomem_resource, name, start, end);
+}
+
+/* The root resource for the whole io-mapped io space */
+struct resource ioport_resource = {
+	.start = 0,
+	.end = IO_SPACE_LIMIT,
+	.name = "ioport",
+	.children = LIST_HEAD_INIT(ioport_resource.children),
+};
+
+/*
+ * request a region inside the io space (i/o port)
+ */
+inline struct resource *request_ioport_region(const char *name,
+		resource_size_t start, resource_size_t end)
+{
+	return __request_region(&ioport_resource, name, start, end);
 }
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 37560fd..1d1d04e 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -241,13 +241,13 @@ int register_driver(struct driver_d *drv)
 }
 EXPORT_SYMBOL(register_driver);
 
-struct resource *dev_get_resource(struct device_d *dev, int num)
+struct resource *dev_get_resource(struct device_d *dev, unsigned long type, int num)
 {
 	int i, n = 0;
 
 	for (i = 0; i < dev->num_resources; i++) {
 		struct resource *res = &dev->resource[i];
-		if (resource_type(res) == IORESOURCE_MEM) {
+		if (resource_type(res) == type) {
 			if (n == num)
 				return res;
 			n++;
@@ -261,7 +261,7 @@ void *dev_get_mem_region(struct device_d *dev, int num)
 {
 	struct resource *res;
 
-	res = dev_get_resource(dev, num);
+	res = dev_get_resource(dev, IORESOURCE_MEM, num);
 	if (!res)
 		return NULL;
 
@@ -270,13 +270,14 @@ void *dev_get_mem_region(struct device_d *dev, int num)
 EXPORT_SYMBOL(dev_get_mem_region);
 
 struct resource *dev_get_resource_by_name(struct device_d *dev,
+					  unsigned long type,
 					  const char *name)
 {
 	int i;
 
 	for (i = 0; i < dev->num_resources; i++) {
 		struct resource *res = &dev->resource[i];
-		if (resource_type(res) != IORESOURCE_MEM)
+		if (resource_type(res) != type)
 			continue;
 		if (!res->name)
 			continue;
@@ -291,7 +292,7 @@ void *dev_get_mem_region_by_name(struct device_d *dev, const char *name)
 {
 	struct resource *res;
 
-	res = dev_get_resource_by_name(dev, name);
+	res = dev_get_resource_by_name(dev, IORESOURCE_MEM, name);
 	if (!res)
 		return NULL;
 
@@ -303,7 +304,7 @@ void __iomem *dev_request_mem_region_by_name(struct device_d *dev, const char *n
 {
 	struct resource *res;
 
-	res = dev_get_resource_by_name(dev, name);
+	res = dev_get_resource_by_name(dev, IORESOURCE_MEM, name);
 	if (!res)
 		return NULL;
 
@@ -319,7 +320,7 @@ void __iomem *dev_request_mem_region(struct device_d *dev, int num)
 {
 	struct resource *res;
 
-	res = dev_get_resource(dev, num);
+	res = dev_get_resource(dev, IORESOURCE_MEM, num);
 	if (!res)
 		return NULL;
 
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index a2fc400..5c46282 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -310,7 +310,7 @@ static void __iomem *bgpio_map(struct device_d *dev, const char *name,
 
 	*err = 0;
 
-	r = dev_get_resource_by_name(dev, name);
+	r = dev_get_resource_by_name(dev, IORESOURCE_MEM, name);
 	if (!r)
 		return NULL;
 
@@ -342,7 +342,7 @@ static int bgpio_dev_probe(struct device_d *dev)
 	struct bgpio_chip *bgc;
 	struct bgpio_pdata *pdata = dev->platform_data;
 
-	r = dev_get_resource_by_name(dev, "dat");
+	r = dev_get_resource_by_name(dev, IORESOURCE_MEM, "dat");
 	if (!r)
 		return -EINVAL;
 
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 8fc84c3..e6722e1 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -70,7 +70,7 @@ static int syscon_probe(struct device_d *dev)
 	if (!syscon)
 		return -ENOMEM;
 
-	res = dev_get_resource(dev, 0);
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
 	if (!res) {
 		free(syscon);
 		return -ENOENT;
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
index 7ea23b7..0466a15 100644
--- a/drivers/misc/sram.c
+++ b/drivers/misc/sram.c
@@ -47,7 +47,7 @@ static int sram_probe(struct device_d *dev)
 	sram->cdev.name = asprintf("sram%d",
 			cdev_find_free_index("sram"));
 
-	res = dev_get_resource(dev, 0);
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
 
 	sram->cdev.size = (unsigned long)resource_size(res);
 	sram->cdev.ops = &memops;
diff --git a/include/driver.h b/include/driver.h
index 01b181d..37797c7 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -203,11 +203,12 @@ static inline const char *dev_name(const struct device_d *dev)
 /*
  * get resource 'num' for a device
  */
-struct resource *dev_get_resource(struct device_d *dev, int num);
+struct resource *dev_get_resource(struct device_d *dev, unsigned long type, int num);
 /*
  * get resource base 'name' for a device
  */
 struct resource *dev_get_resource_by_name(struct device_d *dev,
+					  unsigned long type,
 					  const char *name);
 /*
  * get register base 'name' for a device
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index ff0cba0..d1b2f55 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -137,14 +137,17 @@ static inline unsigned long resource_type(const struct resource *res)
 
 struct resource *request_iomem_region(const char *name,
 		resource_size_t start, resource_size_t end);
+struct resource *request_ioport_region(const char *name,
+		resource_size_t start, resource_size_t end);
 
-struct resource *request_region(struct resource *parent,
+struct resource *__request_region(struct resource *parent,
 		const char *name, resource_size_t end,
 		resource_size_t size);
 
 int release_region(struct resource *res);
 
 extern struct resource iomem_resource;
+extern struct resource ioport_resource;
 
 #endif /* __ASSEMBLY__ */
 #endif	/* _LINUX_IOPORT_H */
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/3] x86: Add support for IDE on the legacy I/O ports
  2014-04-04 13:41 [PATCH 1/3] common: Allow for I/O mapped I/O michel
@ 2014-04-04 13:41 ` michel
  2014-04-04 13:41 ` [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space michel
  1 sibling, 0 replies; 8+ messages in thread
From: michel @ 2014-04-04 13:41 UTC (permalink / raw)
  To: barebox

From: Michel Stam <m.stam@fugro.nl>

---
 arch/x86/boards/x86_generic/generic_pc.c |   73 +++++++++++++++++++++++
 drivers/ata/ide-sff.c                    |   94 ++++++++++++++++++++++++-----
 drivers/ata/intf_platform_ide.c          |   33 +++++++++-
 include/ata_drive.h                      |    1 +
 4 files changed, 180 insertions(+), 21 deletions(-)

diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
index 74a7224..895b88d 100644
--- a/arch/x86/boards/x86_generic/generic_pc.c
+++ b/arch/x86/boards/x86_generic/generic_pc.c
@@ -27,6 +27,10 @@
 #include <ns16550.h>
 #include <linux/err.h>
 
+#ifdef CONFIG_DISK_INTF_PLATFORM_IDE
+#include <platform_ide.h>
+#endif
+
 /*
  * These datas are from the MBR, created by the linker and filled by the
  * setup tool while installing barebox on the disk drive
@@ -41,17 +45,85 @@ extern uint8_t pers_env_drive;
  */
 #define PATCH_AREA_PERS_SIZE_UNUSED 0x000
 
+#ifdef CONFIG_DISK_INTF_PLATFORM_IDE
+
+static struct ide_port_info ide_plat = {
+	.ioport_shift = 0,
+	.dataif_be = 0,
+};
+
+static struct resource primary_ide_resources[] = {
+	{
+		.name = "base",
+		.start = 0x1f0,
+		.end =  0x1f7,
+		.flags = IORESOURCE_IO
+	},
+	{
+		.name = "alt",
+		.start = 0x3f6,
+		.end =  0x3f7,
+		.flags = IORESOURCE_IO
+	}
+};
+
+static struct resource secondary_ide_resources[] = {
+	{
+		.name = "base",
+		.start = 0x170,
+		.end =  0x177,
+		.flags = IORESOURCE_IO
+	},
+};
+
+static struct device_d primary_ide_device = {
+	.name = "ide_intf",
+	.id = 0,
+	.platform_data = &ide_plat,
+	.resource = primary_ide_resources,
+	.num_resources = ARRAY_SIZE( primary_ide_resources ),
+};
+
+static struct device_d secondary_ide_device = {
+	.name = "ide_intf",
+	.id = 1,
+	.platform_data = &ide_plat,
+	.resource = secondary_ide_resources,
+	.num_resources = ARRAY_SIZE( secondary_ide_resources ),
+};
+
+#endif /* CONFIG_DISK_INTF_PLATFORM_IDE */
+
 static int devices_init(void)
 {
+#ifdef CONFIG_DISK_INTF_PLATFORM_IDE
 	struct cdev *cdev;
+#endif
 
 	/* extended memory only */
 	add_mem_device("ram0", 0x0, bios_get_memsize() << 10,
 		       IORESOURCE_MEM_WRITEABLE);
+#ifdef CONFIG_DISK_BIOS
 	add_generic_device("biosdrive", DEVICE_ID_DYNAMIC, NULL, 0, 0, IORESOURCE_MEM,
 			NULL);
+#endif
+
+#ifdef CONFIG_DISK_INTF_PLATFORM_IDE
+	platform_device_register( &primary_ide_device );
+	platform_device_register( &secondary_ide_device );
 
 	if (pers_env_size != PATCH_AREA_PERS_SIZE_UNUSED) {
+		cdev = devfs_add_partition("ata0",
+				pers_env_storage * 512,
+				(unsigned)pers_env_size * 512,
+				DEVFS_PARTITION_FIXED, "env0");
+		printf("Partition: %ld\n", IS_ERR(cdev) ? PTR_ERR(cdev) : 0);
+	} else
+		printf("No persistent storage defined\n");
+#endif /* CONFIG_DISK_INTF_PLATFORM_IDE */
+
+#ifdef CONFIG_DISK_BIOS
+	if (pers_env_size != PATCH_AREA_PERS_SIZE_UNUSED) {
 		cdev = devfs_add_partition("biosdisk0",
 				pers_env_storage * 512,
 				(unsigned)pers_env_size * 512,
@@ -59,6 +131,7 @@ static int devices_init(void)
 		printf("Partition: %ld\n", IS_ERR(cdev) ? PTR_ERR(cdev) : 0);
 	} else
 		printf("No persistent storage defined\n");
+#endif
 
         return 0;
 }
diff --git a/drivers/ata/ide-sff.c b/drivers/ata/ide-sff.c
index 3d5932e..f3a5cbd 100644
--- a/drivers/ata/ide-sff.c
+++ b/drivers/ata/ide-sff.c
@@ -15,13 +15,71 @@
 #define DISK_SLAVE 1
 
 /**
+ * Read a byte from the ATA controller
+ * @param ide IDE port structure
+ * @param addr Register adress
+ * @return Register's content
+ */
+static inline uint8_t ata_rd_byte(struct ide_port *ide, void __iomem *addr )
+{
+	if (ide->io.mmio)
+		return readb(addr);
+	else
+		return (uint8_t) inb((int) addr);
+}
+
+/**
+ * Write a byte to the ATA controller
+ * @param ide IDE port structure
+ * @param value Value to write
+ * @param addr Register adress
+ * @return Register's content
+ */
+static inline void ata_wr_byte(struct ide_port *ide, uint8_t value, void __iomem *addr )
+{
+	if (ide->io.mmio)
+		writeb(value, addr);
+	else
+		outb(value, (int) addr);
+}
+
+/**
+ * Read a word from the ATA controller
+ * @param ide IDE port structure
+ * @param addr Register adress
+ * @return Register's content
+ */
+static inline uint16_t ata_rd_word(struct ide_port *ide, void __iomem *addr )
+{
+	if (ide->io.mmio)
+		return readw(addr);
+	else
+		return (uint16_t) inw((int) addr);
+}
+
+/**
+ * Write a word to the ATA controller
+ * @param ide IDE port structure
+ * @param value Value to write
+ * @param addr Register adress
+ * @return Register's content
+ */
+static inline void ata_wr_word(struct ide_port *ide, uint16_t value, void __iomem *addr )
+{
+	if (ide->io.mmio)
+		writew(value, addr);
+	else
+		outw(value, (int) addr);
+}
+
+/**
  * Read the status register of the ATA drive
  * @param io Register file
  * @return Register's content
  */
 static uint8_t ata_rd_status(struct ide_port *ide)
 {
-	return readb(ide->io.status_addr);
+	return ata_rd_byte(ide,ide->io.status_addr);
 }
 
 /**
@@ -83,12 +141,12 @@ static int ata_set_lba_sector(struct ide_port *ide, unsigned drive, uint64_t num
 	if (num > 0x0FFFFFFF || drive > 1)
 		return -EINVAL;
 
-	writeb(0xA0 | LBA_FLAG | drive << 4 | num >> 24, ide->io.device_addr);
-	writeb(0x00, ide->io.error_addr);
-	writeb(0x01, ide->io.nsect_addr);
-	writeb(num, ide->io.lbal_addr);	/* 0 ... 7 */
-	writeb(num >> 8, ide->io.lbam_addr); /* 8 ... 15 */
-	writeb(num >> 16, ide->io.lbah_addr); /* 16 ... 23 */
+	ata_wr_byte(ide, 0xA0 | LBA_FLAG | drive << 4 | num >> 24, ide->io.device_addr);
+	ata_wr_byte(ide, 0x00, ide->io.error_addr);
+	ata_wr_byte(ide, 0x01, ide->io.nsect_addr);
+	ata_wr_byte(ide, num, ide->io.lbal_addr);	/* 0 ... 7 */
+	ata_wr_byte(ide, num >> 8, ide->io.lbam_addr); /* 8 ... 15 */
+	ata_wr_byte(ide, num >> 16, ide->io.lbah_addr); /* 16 ... 23 */
 
 	return 0;
 }
@@ -107,7 +165,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd)
 	if (rc != 0)
 		return rc;
 
-	writeb(cmd, ide->io.command_addr);
+	ata_wr_byte(ide, cmd, ide->io.command_addr);
 	return 0;
 }
 
@@ -118,7 +176,7 @@ static int ata_wr_cmd(struct ide_port *ide, uint8_t cmd)
  */
 static void ata_wr_dev_ctrl(struct ide_port *ide, uint8_t val)
 {
-	writeb(val, ide->io.ctl_addr);
+	ata_wr_byte(ide, val, ide->io.ctl_addr);
 }
 
 /**
@@ -133,10 +191,10 @@ static void ata_rd_sector(struct ide_port *ide, void *buf)
 
 	if (ide->io.dataif_be) {
 		for (; u > 0; u--)
-			*b++ = be16_to_cpu(readw(ide->io.data_addr));
+			*b++ = be16_to_cpu(ata_rd_word(ide, ide->io.data_addr));
 	} else {
 		for (; u > 0; u--)
-			*b++ = le16_to_cpu(readw(ide->io.data_addr));
+			*b++ = le16_to_cpu(ata_rd_word(ide, ide->io.data_addr));
 	}
 }
 
@@ -152,10 +210,10 @@ static void ata_wr_sector(struct ide_port *ide, const void *buf)
 
 	if (ide->io.dataif_be) {
 		for (; u > 0; u--)
-			writew(cpu_to_be16(*b++), ide->io.data_addr);
+			ata_wr_word(ide, cpu_to_be16(*b++), ide->io.data_addr);
 	} else {
 		for (; u > 0; u--)
-			writew(cpu_to_le16(*b++), ide->io.data_addr);
+			ata_wr_word(ide, cpu_to_le16(*b++), ide->io.data_addr);
 	}
 }
 
@@ -169,10 +227,10 @@ static int ide_read_id(struct ata_port *port, void *buf)
 	struct ide_port *ide = to_ata_drive_access(port);
 	int rc;
 
-	writeb(0xA0, ide->io.device_addr);	/* FIXME drive */
-	writeb(0x00, ide->io.lbal_addr);
-	writeb(0x00, ide->io.lbam_addr);
-	writeb(0x00, ide->io.lbah_addr);
+	ata_wr_byte(ide, 0xA0, ide->io.device_addr);	/* FIXME drive */
+	ata_wr_byte(ide, 0x00, ide->io.lbal_addr);
+	ata_wr_byte(ide, 0x00, ide->io.lbam_addr);
+	ata_wr_byte(ide, 0x00, ide->io.lbah_addr);
 
 	rc = ata_wr_cmd(ide, ATA_CMD_ID_ATA);
 	if (rc != 0)
@@ -327,6 +385,8 @@ int ide_port_register(struct ide_port *ide)
 	ide->port.ops = &ide_ops;
 
 	ret = ata_port_register(&ide->port);
+	if ( !ret )
+		ata_port_detect(&ide->port);
 
 	if (ret)
 		free(ide);
diff --git a/drivers/ata/intf_platform_ide.c b/drivers/ata/intf_platform_ide.c
index 8ae0f05..5ad4c3d 100644
--- a/drivers/ata/intf_platform_ide.c
+++ b/drivers/ata/intf_platform_ide.c
@@ -81,16 +81,43 @@ static int platform_ide_probe(struct device_d *dev)
 	int rc;
 	struct ide_port_info *pdata = dev->platform_data;
 	struct ide_port *ide;
+	struct resource *res;
 	void *reg_base, *alt_base;
+	int mmio;
 
 	if (pdata == NULL) {
 		dev_err(dev, "No platform data. Cannot continue\n");
 		return -EINVAL;
 	}
 
+	reg_base = NULL;
+	alt_base = NULL;
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+	mmio = (res != NULL);
+	if (res && (res = request_iomem_region(dev_name(dev),res->start,res->end)))
+	{
+		reg_base = (void __force __iomem*) res->start;
+		res = dev_get_resource(dev, IORESOURCE_MEM, 1);
+		if (res && (res = request_iomem_region(dev_name(dev),res->start,res->end)))
+			alt_base = (void __force __iomem*) res->start;
+	}
+	else
+	{
+		res = dev_get_resource(dev, IORESOURCE_IO, 0);
+		if (res && (res = request_ioport_region(dev_name(dev),res->start,res->end)))
+		{
+			reg_base = (void __force *) res->start;
+			res = dev_get_resource(dev, IORESOURCE_IO, 1);
+			if (res && (res = request_ioport_region(dev_name(dev),res->start,res->end)))
+				alt_base = (void __force *) res->start;
+		}
+        }
+        if (!reg_base)
+		return -ENODEV;
+
 	ide = xzalloc(sizeof(*ide));
-	reg_base = dev_request_mem_region(dev, 0);
-	alt_base = dev_request_mem_region(dev, 1);
+	ide->io.mmio = mmio;
+
 	platform_ide_setup_port(reg_base, alt_base, &ide->io, pdata->ioport_shift);
 	ide->io.reset = pdata->reset;
 	ide->io.dataif_be = pdata->dataif_be;
@@ -125,6 +152,4 @@ device_platform_driver(platform_ide_driver);
  *
  * This driver does not change any access timings due to the fact it has no idea
  * how to do so. So, do not expect an impressive data throughput.
- *
- * @todo Support also the IO port access method, the x86 architecture is using
  */
diff --git a/include/ata_drive.h b/include/ata_drive.h
index 6d6cca4..44073cb 100644
--- a/include/ata_drive.h
+++ b/include/ata_drive.h
@@ -119,6 +119,7 @@ struct ata_ioports {
 	/* hard reset line handling */
 	void (*reset)(int);	/* true: assert reset, false: de-assert reset */
 	int dataif_be;	/* true if 16 bit data register is big endian */
+	int mmio; /* true if memory-mapped io */
 };
 
 struct ata_port;
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 13:41 [PATCH 1/3] common: Allow for I/O mapped I/O michel
  2014-04-04 13:41 ` [PATCH 2/3] x86: Add support for IDE on the legacy I/O ports michel
@ 2014-04-04 13:41 ` michel
  2014-04-04 15:56   ` Antony Pavlov
  1 sibling, 1 reply; 8+ messages in thread
From: michel @ 2014-04-04 13:41 UTC (permalink / raw)
  To: barebox

From: Michel Stam <m.stam@fugro.nl>

The current implementation fakes a memory-mapped I/O device
at 0x3f8 and 0x2f8, then uses platform read/write functions
to do the actual reading and writing. These platform functions
only exist for the x86 platform; better to move the I/O
routines into the driver and have the driver request I/O ports
using request_ioport_region.
---
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    2 +-
 arch/arm/mach-mvebu/armada-370-xp.c               |    3 +-
 arch/arm/mach-mvebu/kirkwood.c                    |    3 +-
 arch/arm/mach-socfpga/xload.c                     |    4 +-
 arch/arm/mach-tegra/tegra20.c                     |    2 +-
 arch/mips/boards/dlink-dir-320/serial.c           |    2 +-
 arch/mips/boards/loongson-ls1b/serial.c           |    2 +-
 arch/mips/mach-ar231x/ar231x.c                    |    2 +-
 arch/mips/mach-xburst/serial.c                    |   60 ++++++++++
 arch/openrisc/boards/generic/generic.c            |    2 +-
 arch/ppc/boards/freescale-p1022ds/p1022ds.c       |    2 +-
 arch/ppc/boards/freescale-p2020rdb/p2020rdb.c     |    3 +-
 arch/ppc/boards/geip-da923rc/da923rc.c            |    3 +-
 arch/x86/boards/x86_generic/generic_pc.c          |    5 +-
 arch/x86/mach-i386/Makefile                       |    1 -
 arch/x86/mach-i386/generic.c                      |   34 ------
 drivers/serial/serial_ns16550.c                   |  122 ++++++++++++++++++---
 include/driver.h                                  |    2 +-
 include/ns16550.h                                 |   11 +--
 19 files changed, 187 insertions(+), 78 deletions(-)
 create mode 100644 arch/mips/mach-xburst/serial.c
 delete mode 100644 arch/x86/mach-i386/generic.c

diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
index e2ad1c8..69967c5 100644
--- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -223,7 +223,7 @@ static int eukrea_cpuimx27_console_init(void)
 	imx27_setup_weimcs(3, 0x0000D603, 0x0D1D0D01, 0x00D20000);
 #ifdef CONFIG_DRIVER_SERIAL_NS16550
 	add_ns16550_device(DEVICE_ID_DYNAMIC, MX27_CS3_BASE_ADDR + QUART_OFFSET, 0xf,
-			 IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
+			 IORESOURCE_MEM | IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
 #endif
 	return 0;
 }
diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
index 776b4c0..209be0b 100644
--- a/arch/arm/mach-mvebu/armada-370-xp.c
+++ b/arch/arm/mach-mvebu/armada-370-xp.c
@@ -60,7 +60,8 @@ static int armada_370_xp_add_uart(void)
 	uart_plat.clock = clk_get_rate(tclk);
 	if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
 				(unsigned int)CONSOLE_UART_BASE, 32,
-				IORESOURCE_MEM_32BIT, &uart_plat))
+				IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+				&uart_plat))
 	    return -ENODEV;
 	return 0;
 }
diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
index 1284220..c79d130 100644
--- a/arch/arm/mach-mvebu/kirkwood.c
+++ b/arch/arm/mach-mvebu/kirkwood.c
@@ -58,7 +58,8 @@ static int kirkwood_add_uart(void)
 	uart_plat.clock = clk_get_rate(tclk);
 	if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
 				(unsigned int)CONSOLE_UART_BASE, 32,
-				IORESOURCE_MEM_32BIT, &uart_plat))
+				IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
+				&uart_plat))
 		return -ENODEV;
 	return 0;
 }
diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
index 0b99db0..6586ada 100644
--- a/arch/arm/mach-socfpga/xload.c
+++ b/arch/arm/mach-socfpga/xload.c
@@ -45,8 +45,8 @@ static void socfpga_uart_init(void)
 	clks[uart] = clk_fixed("uart", 100000000);
 	clkdev_add_physbase(clks[uart], CYCLONE5_UART0_ADDRESS, NULL);
 	clkdev_add_physbase(clks[uart], CYCLONE5_UART1_ADDRESS, NULL);
-	add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM_8BIT,
-			&uart_pdata);
+	add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM |
+			IORESOURCE_MEM_8BIT, &uart_pdata);
 }
 
 static void socfpga_timer_init(void)
diff --git a/arch/arm/mach-tegra/tegra20.c b/arch/arm/mach-tegra/tegra20.c
index cc2d748..bdd7960 100644
--- a/arch/arm/mach-tegra/tegra20.c
+++ b/arch/arm/mach-tegra/tegra20.c
@@ -50,7 +50,7 @@ static int tegra20_add_debug_console(void)
 		return -ENODEV;
 
 	add_ns16550_device(DEVICE_ID_DYNAMIC, base, 8 << debug_uart.shift,
-			   IORESOURCE_MEM_8BIT, &debug_uart);
+			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &debug_uart);
 
 	return 0;
 }
diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
index bddb683..eb87379 100644
--- a/arch/mips/boards/dlink-dir-320/serial.c
+++ b/arch/mips/boards/dlink-dir-320/serial.c
@@ -36,7 +36,7 @@ static int dir320_console_init(void)
 
 	/* Register the serial port */
 	add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
-			IORESOURCE_MEM_8BIT, &serial_plat);
+			IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
 
 	return 0;
 }
diff --git a/arch/mips/boards/loongson-ls1b/serial.c b/arch/mips/boards/loongson-ls1b/serial.c
index d8e0f7c..7159ab7 100644
--- a/arch/mips/boards/loongson-ls1b/serial.c
+++ b/arch/mips/boards/loongson-ls1b/serial.c
@@ -15,7 +15,7 @@ static int console_init(void)
 	barebox_set_hostname("ls1b");
 
 	add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(LS1X_UART2_BASE),
-		8, IORESOURCE_MEM_8BIT, &serial_plat);
+		8, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
 
 	return 0;
 }
diff --git a/arch/mips/mach-ar231x/ar231x.c b/arch/mips/mach-ar231x/ar231x.c
index ca912bf..06d2edb 100644
--- a/arch/mips/mach-ar231x/ar231x.c
+++ b/arch/mips/mach-ar231x/ar231x.c
@@ -189,7 +189,7 @@ static int ar2312_console_init(void)
 	/* Register the serial port */
 	serial_plat.clock = ar2312_sys_frequency();
 	add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(AR2312_UART0),
-		8 << AR2312_UART_SHIFT, IORESOURCE_MEM_8BIT, &serial_plat);
+		8 << AR2312_UART_SHIFT, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
 	return 0;
 }
 console_initcall(ar2312_console_init);
diff --git a/arch/mips/mach-xburst/serial.c b/arch/mips/mach-xburst/serial.c
new file mode 100644
index 0000000..4365d19
--- /dev/null
+++ b/arch/mips/mach-xburst/serial.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
+ *
+ * Based on the linux kernel JZ4740 serial support:
+ * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * This file is part of barebox.
+ * See file CREDITS for list of people who contributed to this project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program 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.
+ *
+ */
+
+#include <common.h>
+#include <ns16550.h>
+#include <io.h>
+#include <mach/devices.h>
+
+#define JZ_UART_SHIFT	2
+
+#define ier		(1 << JZ_UART_SHIFT)
+#define fcr		(2 << JZ_UART_SHIFT)
+
+static void jz_serial_reg_write(unsigned int val, unsigned long base,
+	unsigned char reg_offset)
+{
+	switch (reg_offset) {
+	case fcr:
+		val |= 0x10; /* Enable uart module */
+		break;
+	case ier:
+		val |= (val & 0x4) << 2;
+		break;
+	default:
+		break;
+	}
+
+	writeb(val & 0xff, (void *)(base + reg_offset));
+}
+
+struct device_d *jz_add_uart(int id, unsigned long base, unsigned int clock)
+{
+	struct NS16550_plat *serial_plat;
+
+	serial_plat = xzalloc(sizeof(*serial_plat));
+
+	serial_plat->shift = JZ_UART_SHIFT;
+	serial_plat->reg_write = &jz_serial_reg_write;
+	serial_plat->clock = clock;
+
+	return add_ns16550_device(id, base, 8 << JZ_UART_SHIFT,
+			IORESOURCE_MEM | IORESOURCE_MEM_8BIT, serial_plat);
+}
diff --git a/arch/openrisc/boards/generic/generic.c b/arch/openrisc/boards/generic/generic.c
index 290e05c..1d6ac8a 100644
--- a/arch/openrisc/boards/generic/generic.c
+++ b/arch/openrisc/boards/generic/generic.c
@@ -15,7 +15,7 @@ static int openrisc_console_init(void)
 	barebox_set_hostname("or1k");
 
 	/* Register the serial port */
-	add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM_8BIT, &serial_plat);
+	add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
 
 #ifdef CONFIG_DRIVER_NET_ETHOC
 	add_generic_device("ethoc", DEVICE_ID_DYNAMIC, NULL,
diff --git a/arch/ppc/boards/freescale-p1022ds/p1022ds.c b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
index c800064..57e7953 100644
--- a/arch/ppc/boards/freescale-p1022ds/p1022ds.c
+++ b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
@@ -130,7 +130,7 @@ static int p1022ds_console_init(void)
 
 	serial_plat.clock = fsl_get_bus_freq(0);
 	add_ns16550_device(DEVICE_ID_DYNAMIC, CFG_IMMR + 0x4500, 16,
-			   IORESOURCE_MEM_8BIT, &serial_plat);
+			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
 	return 0;
 }
 
diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
index 229ae41..385a436 100644
--- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
+++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
@@ -112,7 +112,8 @@ static int p2020_console_init(void)
 
 	serial_plat.clock = fsl_get_bus_freq(0);
 
-	add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16, IORESOURCE_MEM_8BIT,
+	add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16,
+			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
 			   &serial_plat);
 	return 0;
 }
diff --git a/arch/ppc/boards/geip-da923rc/da923rc.c b/arch/ppc/boards/geip-da923rc/da923rc.c
index 976aa8d..3d77349 100644
--- a/arch/ppc/boards/geip-da923rc/da923rc.c
+++ b/arch/ppc/boards/geip-da923rc/da923rc.c
@@ -115,7 +115,8 @@ static int da923rc_console_init(void)
 		barebox_set_model("unknown");
 
 	serial_plat.clock = fsl_get_bus_freq(0);
-	add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16, IORESOURCE_MEM_8BIT,
+	add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16,
+			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
 			   &serial_plat);
 	return 0;
 }
diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
index 895b88d..69c6f58 100644
--- a/arch/x86/boards/x86_generic/generic_pc.c
+++ b/arch/x86/boards/x86_generic/generic_pc.c
@@ -141,8 +141,6 @@ device_initcall(devices_init);
 
 static struct NS16550_plat serial_plat = {
        .clock = 1843200,
-       .reg_read = x86_uart_read,
-       .reg_write = x86_uart_write,
 };
 
 static int pc_console_init(void)
@@ -151,7 +149,8 @@ static int pc_console_init(void)
 	barebox_set_hostname("x86");
 
 	/* Register the serial port */
-	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, 0, &serial_plat);
+	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, IORESOURCE_IO, &serial_plat);
+	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x2f8, 8, IORESOURCE_IO, &serial_plat);
 
 	return 0;
 }
diff --git a/arch/x86/mach-i386/Makefile b/arch/x86/mach-i386/Makefile
index 10712e6..e46aa5b 100644
--- a/arch/x86/mach-i386/Makefile
+++ b/arch/x86/mach-i386/Makefile
@@ -1,4 +1,3 @@
-obj-y += generic.o
 obj-y += reset.o
 
 # reference clocksource
diff --git a/arch/x86/mach-i386/generic.c b/arch/x86/mach-i386/generic.c
deleted file mode 100644
index 69cf53c..0000000
--- a/arch/x86/mach-i386/generic.c
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2009 Juergen Beisert, Pengutronix
- *
- * This program 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.
- *
- * This program 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.
- *
- *
- */
-
-/**
- * @file
- * @brief x86 Architecture Initialization routines
- */
-
-#include <io.h>
-
-/** to work with the 8250 UART driver implementation we need this function */
-unsigned int x86_uart_read(unsigned long base, unsigned char reg_idx)
-{
-	return inb(base + reg_idx);
-}
-
-/** to work with the 8250 UART driver implementation we need this function */
-void x86_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
-{
-	outb(val, base + reg_idx);
-}
diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
index 0c00eb1..dfe572d 100644
--- a/drivers/serial/serial_ns16550.c
+++ b/drivers/serial/serial_ns16550.c
@@ -47,6 +47,7 @@ struct ns16550_priv {
 	struct console_device cdev;
 	struct NS16550_plat plat;
 	int access_width;
+	int mmio;
 	struct clk *clk;
 	uint32_t fcrval;
 };
@@ -62,6 +63,87 @@ struct ns16550_drvdata {
 };
 
 /**
+ * @brief read system i/o (byte)
+ * @param[in] addr address to read
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio)
+{
+	if (mmio)
+		return readb(addr);
+        else
+		return (uint8_t) inb((int) addr);
+}
+
+/**
+ * @brief read system i/o (word)
+ * @param[in] addr address to read
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio)
+{
+	if (mmio)
+		return readw(addr);
+        else
+		return (uint16_t) inw((int) addr);
+}
+
+/**
+ * @brief read system i/o (dword)
+ * @param[in] addr address to read
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio)
+{
+	if (mmio)
+		return readl(addr);
+        else
+		return (uint32_t) inl((int) addr);
+}
+
+/**
+ * @brief write system i/o (byte)
+ * @param[in] val data to write
+ * @param[in] addr address to write to
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, int mmio)
+{
+	if (mmio)
+		writeb(val, addr);
+        else
+		outb(val, (int) addr);
+}
+
+/**
+ * @brief read system i/o (word)
+ * @param[in] val data to write
+ * @param[in] addr address to write to
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, int mmio)
+{
+	if (mmio)
+		writew(val, addr);
+        else
+		outw(val, (int) addr);
+}
+
+/**
+ * @brief read system i/o (dword)
+ * @param[in] val data to write
+ * @param[in] addr address to write to
+ * @param[in] mmio memory i/o space or i/o port space
+ */
+static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, int mmio)
+{
+	if (mmio)
+		writel(val, addr);
+        else
+		outl(val, (int) addr);
+}
+
+/**
  * @brief read register
  *
  * @param[in] cdev pointer to console device
@@ -78,16 +160,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
 
 	off <<= plat->shift;
 
-	if (plat->reg_read)
-		return plat->reg_read((unsigned long)dev->priv, off);
-
 	switch (width) {
 	case IORESOURCE_MEM_8BIT:
-		return readb(dev->priv + off);
+		return ns16550_sys_readb(dev->priv + off, priv->mmio);
 	case IORESOURCE_MEM_16BIT:
-		return readw(dev->priv + off);
+		return ns16550_sys_readw(dev->priv + off, priv->mmio);
 	case IORESOURCE_MEM_32BIT:
-		return readl(dev->priv + off);
+		return ns16550_sys_readl(dev->priv + off, priv->mmio);
 	}
 	return -1;
 }
@@ -109,20 +188,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
 
 	off <<= plat->shift;
 
-	if (plat->reg_write) {
-		plat->reg_write(val, (unsigned long)dev->priv, off);
-		return;
-	}
-
 	switch (width) {
 	case IORESOURCE_MEM_8BIT:
-		writeb(val & 0xff, dev->priv + off);
+		ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio);
 		break;
 	case IORESOURCE_MEM_16BIT:
-		writew(val & 0xffff, dev->priv + off);
+		ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio);
 		break;
 	case IORESOURCE_MEM_32BIT:
-		writel(val, dev->priv + off);
+		ns16550_sys_writel(val, dev->priv + off, priv->mmio);
 		break;
 	}
 }
@@ -293,16 +367,32 @@ static int ns16550_probe(struct device_d *dev)
 	struct console_device *cdev;
 	struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
 	struct ns16550_drvdata *devtype;
+	struct resource *res;
 	int ret;
 
 	ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
 	if (ret)
 		devtype = &ns16550_drvdata;
 
-	dev->priv = dev_request_mem_region(dev, 0);
-
 	priv = xzalloc(sizeof(*priv));
 
+	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
+	priv->mmio = (res != NULL);
+	if (res)
+	{
+		res = request_iomem_region(dev_name(dev),res->start,res->end);
+	}
+	else
+	{
+		res = dev_get_resource(dev, IORESOURCE_IO, 0);
+		if (res)
+			res = request_ioport_region(dev_name(dev),res->start,res->end);
+	}
+	if (!res)
+		goto err;
+	dev->priv = (void __force __iomem *) res->start;
+
+
 	if (plat)
 		priv->plat = *plat;
 	else
diff --git a/include/driver.h b/include/driver.h
index 37797c7..ff4a5a1 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -276,7 +276,7 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
 		resource_size_t size, int flags, struct NS16550_plat *pdata)
 {
 	return add_generic_device("ns16550_serial", id, NULL, start, size,
-				  IORESOURCE_MEM | flags, pdata);
+				  flags, pdata);
 }
 
 #ifdef CONFIG_DRIVER_NET_DM9K
diff --git a/include/ns16550.h b/include/ns16550.h
index 36aa5ff..876bb04 100644
--- a/include/ns16550.h
+++ b/include/ns16550.h
@@ -33,18 +33,9 @@
 struct NS16550_plat {
 	/** Clock speed */
 	unsigned int clock;
-	/**
-	 * register read access capability
-	 */
-	unsigned int (*reg_read) (unsigned long base, unsigned char reg_offset);
-	/**
-	 * register write access capability
-	 */
-	void (*reg_write) (unsigned int val, unsigned long base,
-				    unsigned char reg_offset);
-
 	int shift;
 	unsigned int flags;
+	int mmio;
 #define NS16650_FLAG_DISABLE_FIFO	1
 };
 
-- 
1.7.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 13:41 ` [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space michel
@ 2014-04-04 15:56   ` Antony Pavlov
  2014-04-04 16:52     ` Michel Stam
  0 siblings, 1 reply; 8+ messages in thread
From: Antony Pavlov @ 2014-04-04 15:56 UTC (permalink / raw)
  To: michel; +Cc: barebox

On Fri,  4 Apr 2014 15:41:39 +0200
michel@reverze.net wrote:

> From: Michel Stam <m.stam@fugro.nl>
> 
> The current implementation fakes a memory-mapped I/O device
> at 0x3f8 and 0x2f8, then uses platform read/write functions
> to do the actual reading and writing. These platform functions
> only exist for the x86 platform; better to move the I/O
> routines into the driver and have the driver request I/O ports
> using request_ioport_region.
> ---
>  arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    2 +-
>  arch/arm/mach-mvebu/armada-370-xp.c               |    3 +-
>  arch/arm/mach-mvebu/kirkwood.c                    |    3 +-
>  arch/arm/mach-socfpga/xload.c                     |    4 +-
>  arch/arm/mach-tegra/tegra20.c                     |    2 +-
>  arch/mips/boards/dlink-dir-320/serial.c           |    2 +-
>  arch/mips/boards/loongson-ls1b/serial.c           |    2 +-
>  arch/mips/mach-ar231x/ar231x.c                    |    2 +-
>  arch/mips/mach-xburst/serial.c                    |   60 ++++++++++
hmmm
this partly revert my recent commit in the 'next' branch:

 commit 8f5d37835d44d07460d92307f0b6489048a18fba
 Author: Antony Pavlov <antonynpavlov@gmail.com>
 Date:   Tue Mar 25 20:50:58 2014 +0400

    MIPS: mach-xburst: drop serial.c
    
    We use dts for serial port initialization,
    so we have no need in mach-xburst/serial.c anymore.
    
    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
    Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

 arch/mips/mach-xburst/Makefile |  1 -
 arch/mips/mach-xburst/serial.c | 60 -----------------------------------------------------
 2 files changed, 61 deletions(-)

>  arch/openrisc/boards/generic/generic.c            |    2 +-
>  arch/ppc/boards/freescale-p1022ds/p1022ds.c       |    2 +-
>  arch/ppc/boards/freescale-p2020rdb/p2020rdb.c     |    3 +-
>  arch/ppc/boards/geip-da923rc/da923rc.c            |    3 +-
>  arch/x86/boards/x86_generic/generic_pc.c          |    5 +-
>  arch/x86/mach-i386/Makefile                       |    1 -
>  arch/x86/mach-i386/generic.c                      |   34 ------
>  drivers/serial/serial_ns16550.c                   |  122 ++++++++++++++++++---
>  include/driver.h                                  |    2 +-
>  include/ns16550.h                                 |   11 +--
>  19 files changed, 187 insertions(+), 78 deletions(-)
>  create mode 100644 arch/mips/mach-xburst/serial.c
>  delete mode 100644 arch/x86/mach-i386/generic.c
> 
> diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> index e2ad1c8..69967c5 100644
> --- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> +++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> @@ -223,7 +223,7 @@ static int eukrea_cpuimx27_console_init(void)
>  	imx27_setup_weimcs(3, 0x0000D603, 0x0D1D0D01, 0x00D20000);
>  #ifdef CONFIG_DRIVER_SERIAL_NS16550
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, MX27_CS3_BASE_ADDR + QUART_OFFSET, 0xf,
> -			 IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
> +			 IORESOURCE_MEM | IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
>  #endif
>  	return 0;
>  }
> diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
> index 776b4c0..209be0b 100644
> --- a/arch/arm/mach-mvebu/armada-370-xp.c
> +++ b/arch/arm/mach-mvebu/armada-370-xp.c
> @@ -60,7 +60,8 @@ static int armada_370_xp_add_uart(void)
>  	uart_plat.clock = clk_get_rate(tclk);
>  	if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>  				(unsigned int)CONSOLE_UART_BASE, 32,
> -				IORESOURCE_MEM_32BIT, &uart_plat))
> +				IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +				&uart_plat))
>  	    return -ENODEV;
>  	return 0;
>  }
> diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
> index 1284220..c79d130 100644
> --- a/arch/arm/mach-mvebu/kirkwood.c
> +++ b/arch/arm/mach-mvebu/kirkwood.c
> @@ -58,7 +58,8 @@ static int kirkwood_add_uart(void)
>  	uart_plat.clock = clk_get_rate(tclk);
>  	if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>  				(unsigned int)CONSOLE_UART_BASE, 32,
> -				IORESOURCE_MEM_32BIT, &uart_plat))
> +				IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> +				&uart_plat))
>  		return -ENODEV;
>  	return 0;
>  }
> diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
> index 0b99db0..6586ada 100644
> --- a/arch/arm/mach-socfpga/xload.c
> +++ b/arch/arm/mach-socfpga/xload.c
> @@ -45,8 +45,8 @@ static void socfpga_uart_init(void)
>  	clks[uart] = clk_fixed("uart", 100000000);
>  	clkdev_add_physbase(clks[uart], CYCLONE5_UART0_ADDRESS, NULL);
>  	clkdev_add_physbase(clks[uart], CYCLONE5_UART1_ADDRESS, NULL);
> -	add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM_8BIT,
> -			&uart_pdata);
> +	add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM |
> +			IORESOURCE_MEM_8BIT, &uart_pdata);
>  }
>  
>  static void socfpga_timer_init(void)
> diff --git a/arch/arm/mach-tegra/tegra20.c b/arch/arm/mach-tegra/tegra20.c
> index cc2d748..bdd7960 100644
> --- a/arch/arm/mach-tegra/tegra20.c
> +++ b/arch/arm/mach-tegra/tegra20.c
> @@ -50,7 +50,7 @@ static int tegra20_add_debug_console(void)
>  		return -ENODEV;
>  
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, base, 8 << debug_uart.shift,
> -			   IORESOURCE_MEM_8BIT, &debug_uart);
> +			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &debug_uart);
>  
>  	return 0;
>  }
> diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
> index bddb683..eb87379 100644
> --- a/arch/mips/boards/dlink-dir-320/serial.c
> +++ b/arch/mips/boards/dlink-dir-320/serial.c
> @@ -36,7 +36,7 @@ static int dir320_console_init(void)
>  
>  	/* Register the serial port */
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
> -			IORESOURCE_MEM_8BIT, &serial_plat);
> +			IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>  
>  	return 0;
>  }
> diff --git a/arch/mips/boards/loongson-ls1b/serial.c b/arch/mips/boards/loongson-ls1b/serial.c
> index d8e0f7c..7159ab7 100644
> --- a/arch/mips/boards/loongson-ls1b/serial.c
> +++ b/arch/mips/boards/loongson-ls1b/serial.c
> @@ -15,7 +15,7 @@ static int console_init(void)
>  	barebox_set_hostname("ls1b");
>  
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(LS1X_UART2_BASE),
> -		8, IORESOURCE_MEM_8BIT, &serial_plat);
> +		8, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>  
>  	return 0;
>  }
> diff --git a/arch/mips/mach-ar231x/ar231x.c b/arch/mips/mach-ar231x/ar231x.c
> index ca912bf..06d2edb 100644
> --- a/arch/mips/mach-ar231x/ar231x.c
> +++ b/arch/mips/mach-ar231x/ar231x.c
> @@ -189,7 +189,7 @@ static int ar2312_console_init(void)
>  	/* Register the serial port */
>  	serial_plat.clock = ar2312_sys_frequency();
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(AR2312_UART0),
> -		8 << AR2312_UART_SHIFT, IORESOURCE_MEM_8BIT, &serial_plat);
> +		8 << AR2312_UART_SHIFT, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>  	return 0;
>  }
>  console_initcall(ar2312_console_init);
> diff --git a/arch/mips/mach-xburst/serial.c b/arch/mips/mach-xburst/serial.c
> new file mode 100644
> index 0000000..4365d19
> --- /dev/null
> +++ b/arch/mips/mach-xburst/serial.c
> @@ -0,0 +1,60 @@
> +/*
> + * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
> + *
> + * Based on the linux kernel JZ4740 serial support:
> + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
> + *
> + * This file is part of barebox.
> + * See file CREDITS for list of people who contributed to this project.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2
> + * as published by the Free Software Foundation.
> + *
> + * This program 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.
> + *
> + */
> +
> +#include <common.h>
> +#include <ns16550.h>
> +#include <io.h>
> +#include <mach/devices.h>
> +
> +#define JZ_UART_SHIFT	2
> +
> +#define ier		(1 << JZ_UART_SHIFT)
> +#define fcr		(2 << JZ_UART_SHIFT)
> +
> +static void jz_serial_reg_write(unsigned int val, unsigned long base,
> +	unsigned char reg_offset)
> +{
> +	switch (reg_offset) {
> +	case fcr:
> +		val |= 0x10; /* Enable uart module */
> +		break;
> +	case ier:
> +		val |= (val & 0x4) << 2;
> +		break;
> +	default:
> +		break;
> +	}
> +
> +	writeb(val & 0xff, (void *)(base + reg_offset));
> +}
> +
> +struct device_d *jz_add_uart(int id, unsigned long base, unsigned int clock)
> +{
> +	struct NS16550_plat *serial_plat;
> +
> +	serial_plat = xzalloc(sizeof(*serial_plat));
> +
> +	serial_plat->shift = JZ_UART_SHIFT;
> +	serial_plat->reg_write = &jz_serial_reg_write;
> +	serial_plat->clock = clock;
> +
> +	return add_ns16550_device(id, base, 8 << JZ_UART_SHIFT,
> +			IORESOURCE_MEM | IORESOURCE_MEM_8BIT, serial_plat);
> +}
> diff --git a/arch/openrisc/boards/generic/generic.c b/arch/openrisc/boards/generic/generic.c
> index 290e05c..1d6ac8a 100644
> --- a/arch/openrisc/boards/generic/generic.c
> +++ b/arch/openrisc/boards/generic/generic.c
> @@ -15,7 +15,7 @@ static int openrisc_console_init(void)
>  	barebox_set_hostname("or1k");
>  
>  	/* Register the serial port */
> -	add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM_8BIT, &serial_plat);
> +	add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>  
>  #ifdef CONFIG_DRIVER_NET_ETHOC
>  	add_generic_device("ethoc", DEVICE_ID_DYNAMIC, NULL,
> diff --git a/arch/ppc/boards/freescale-p1022ds/p1022ds.c b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> index c800064..57e7953 100644
> --- a/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> +++ b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> @@ -130,7 +130,7 @@ static int p1022ds_console_init(void)
>  
>  	serial_plat.clock = fsl_get_bus_freq(0);
>  	add_ns16550_device(DEVICE_ID_DYNAMIC, CFG_IMMR + 0x4500, 16,
> -			   IORESOURCE_MEM_8BIT, &serial_plat);
> +			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>  	return 0;
>  }
>  
> diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> index 229ae41..385a436 100644
> --- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> +++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> @@ -112,7 +112,8 @@ static int p2020_console_init(void)
>  
>  	serial_plat.clock = fsl_get_bus_freq(0);
>  
> -	add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16, IORESOURCE_MEM_8BIT,
> +	add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16,
> +			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>  			   &serial_plat);
>  	return 0;
>  }
> diff --git a/arch/ppc/boards/geip-da923rc/da923rc.c b/arch/ppc/boards/geip-da923rc/da923rc.c
> index 976aa8d..3d77349 100644
> --- a/arch/ppc/boards/geip-da923rc/da923rc.c
> +++ b/arch/ppc/boards/geip-da923rc/da923rc.c
> @@ -115,7 +115,8 @@ static int da923rc_console_init(void)
>  		barebox_set_model("unknown");
>  
>  	serial_plat.clock = fsl_get_bus_freq(0);
> -	add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16, IORESOURCE_MEM_8BIT,
> +	add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16,
> +			   IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>  			   &serial_plat);
>  	return 0;
>  }
> diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
> index 895b88d..69c6f58 100644
> --- a/arch/x86/boards/x86_generic/generic_pc.c
> +++ b/arch/x86/boards/x86_generic/generic_pc.c
> @@ -141,8 +141,6 @@ device_initcall(devices_init);
>  
>  static struct NS16550_plat serial_plat = {
>         .clock = 1843200,
> -       .reg_read = x86_uart_read,
> -       .reg_write = x86_uart_write,
>  };
>  
>  static int pc_console_init(void)
> @@ -151,7 +149,8 @@ static int pc_console_init(void)
>  	barebox_set_hostname("x86");
>  
>  	/* Register the serial port */
> -	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, 0, &serial_plat);
> +	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, IORESOURCE_IO, &serial_plat);
> +	add_ns16550_device(DEVICE_ID_DYNAMIC, 0x2f8, 8, IORESOURCE_IO, &serial_plat);
>  
>  	return 0;
>  }
> diff --git a/arch/x86/mach-i386/Makefile b/arch/x86/mach-i386/Makefile
> index 10712e6..e46aa5b 100644
> --- a/arch/x86/mach-i386/Makefile
> +++ b/arch/x86/mach-i386/Makefile
> @@ -1,4 +1,3 @@
> -obj-y += generic.o
>  obj-y += reset.o
>  
>  # reference clocksource
> diff --git a/arch/x86/mach-i386/generic.c b/arch/x86/mach-i386/generic.c
> deleted file mode 100644
> index 69cf53c..0000000
> --- a/arch/x86/mach-i386/generic.c
> +++ /dev/null
> @@ -1,34 +0,0 @@
> -/*
> - * Copyright (C) 2009 Juergen Beisert, Pengutronix
> - *
> - * This program 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.
> - *
> - * This program 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.
> - *
> - *
> - */
> -
> -/**
> - * @file
> - * @brief x86 Architecture Initialization routines
> - */
> -
> -#include <io.h>
> -
> -/** to work with the 8250 UART driver implementation we need this function */
> -unsigned int x86_uart_read(unsigned long base, unsigned char reg_idx)
> -{
> -	return inb(base + reg_idx);
> -}
> -
> -/** to work with the 8250 UART driver implementation we need this function */
> -void x86_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
> -{
> -	outb(val, base + reg_idx);
> -}
> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
> index 0c00eb1..dfe572d 100644
> --- a/drivers/serial/serial_ns16550.c
> +++ b/drivers/serial/serial_ns16550.c
> @@ -47,6 +47,7 @@ struct ns16550_priv {
>  	struct console_device cdev;
>  	struct NS16550_plat plat;
>  	int access_width;
> +	int mmio;
>  	struct clk *clk;
>  	uint32_t fcrval;
>  };
> @@ -62,6 +63,87 @@ struct ns16550_drvdata {
>  };
>  
>  /**
> + * @brief read system i/o (byte)
> + * @param[in] addr address to read
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		return readb(addr);
> +        else
> +		return (uint8_t) inb((int) addr);
> +}
> +
> +/**
> + * @brief read system i/o (word)
> + * @param[in] addr address to read
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		return readw(addr);
> +        else
> +		return (uint16_t) inw((int) addr);
> +}
> +
> +/**
> + * @brief read system i/o (dword)
> + * @param[in] addr address to read
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		return readl(addr);
> +        else
> +		return (uint32_t) inl((int) addr);
> +}
> +
> +/**
> + * @brief write system i/o (byte)
> + * @param[in] val data to write
> + * @param[in] addr address to write to
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		writeb(val, addr);
> +        else
> +		outb(val, (int) addr);
> +}
> +
> +/**
> + * @brief read system i/o (word)
> + * @param[in] val data to write
> + * @param[in] addr address to write to
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		writew(val, addr);
> +        else
> +		outw(val, (int) addr);
> +}
> +
> +/**
> + * @brief read system i/o (dword)
> + * @param[in] val data to write
> + * @param[in] addr address to write to
> + * @param[in] mmio memory i/o space or i/o port space
> + */
> +static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, int mmio)
> +{
> +	if (mmio)
> +		writel(val, addr);
> +        else
> +		outl(val, (int) addr);
> +}
> +
> +/**
>   * @brief read register
>   *
>   * @param[in] cdev pointer to console device
> @@ -78,16 +160,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
>  
>  	off <<= plat->shift;
>  
> -	if (plat->reg_read)
> -		return plat->reg_read((unsigned long)dev->priv, off);
> -
>  	switch (width) {
>  	case IORESOURCE_MEM_8BIT:
> -		return readb(dev->priv + off);
> +		return ns16550_sys_readb(dev->priv + off, priv->mmio);
>  	case IORESOURCE_MEM_16BIT:
> -		return readw(dev->priv + off);
> +		return ns16550_sys_readw(dev->priv + off, priv->mmio);
>  	case IORESOURCE_MEM_32BIT:
> -		return readl(dev->priv + off);
> +		return ns16550_sys_readl(dev->priv + off, priv->mmio);
>  	}
>  	return -1;
>  }
> @@ -109,20 +188,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
>  
>  	off <<= plat->shift;
>  
> -	if (plat->reg_write) {
> -		plat->reg_write(val, (unsigned long)dev->priv, off);
> -		return;
> -	}
> -
>  	switch (width) {
>  	case IORESOURCE_MEM_8BIT:
> -		writeb(val & 0xff, dev->priv + off);
> +		ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio);
>  		break;
>  	case IORESOURCE_MEM_16BIT:
> -		writew(val & 0xffff, dev->priv + off);
> +		ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio);
>  		break;
>  	case IORESOURCE_MEM_32BIT:
> -		writel(val, dev->priv + off);
> +		ns16550_sys_writel(val, dev->priv + off, priv->mmio);
>  		break;
>  	}
>  }
> @@ -293,16 +367,32 @@ static int ns16550_probe(struct device_d *dev)
>  	struct console_device *cdev;
>  	struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
>  	struct ns16550_drvdata *devtype;
> +	struct resource *res;
>  	int ret;
>  
>  	ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
>  	if (ret)
>  		devtype = &ns16550_drvdata;
>  
> -	dev->priv = dev_request_mem_region(dev, 0);
> -
>  	priv = xzalloc(sizeof(*priv));
>  
> +	res = dev_get_resource(dev, IORESOURCE_MEM, 0);
> +	priv->mmio = (res != NULL);
> +	if (res)
> +	{
> +		res = request_iomem_region(dev_name(dev),res->start,res->end);
> +	}
> +	else
> +	{



Have you checked your patches with checkpatch.pl script?


> +		res = dev_get_resource(dev, IORESOURCE_IO, 0);
> +		if (res)
> +			res = request_ioport_region(dev_name(dev),res->start,res->end);
> +	}
> +	if (!res)
> +		goto err;
> +	dev->priv = (void __force __iomem *) res->start;
> +
> +
>  	if (plat)
>  		priv->plat = *plat;
>  	else
> diff --git a/include/driver.h b/include/driver.h
> index 37797c7..ff4a5a1 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -276,7 +276,7 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
>  		resource_size_t size, int flags, struct NS16550_plat *pdata)
>  {
>  	return add_generic_device("ns16550_serial", id, NULL, start, size,
> -				  IORESOURCE_MEM | flags, pdata);
> +				  flags, pdata);
>  }
>  
>  #ifdef CONFIG_DRIVER_NET_DM9K
> diff --git a/include/ns16550.h b/include/ns16550.h
> index 36aa5ff..876bb04 100644
> --- a/include/ns16550.h
> +++ b/include/ns16550.h
> @@ -33,18 +33,9 @@
>  struct NS16550_plat {
>  	/** Clock speed */
>  	unsigned int clock;
> -	/**
> -	 * register read access capability
> -	 */
> -	unsigned int (*reg_read) (unsigned long base, unsigned char reg_offset);
> -	/**
> -	 * register write access capability
> -	 */
> -	void (*reg_write) (unsigned int val, unsigned long base,
> -				    unsigned char reg_offset);
> -
>  	int shift;
>  	unsigned int flags;
> +	int mmio;

Do you really need this 'int mmio' here?

>  #define NS16650_FLAG_DISABLE_FIFO	1
>  };
>  
> -- 
> 1.7.1
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox


-- 
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 15:56   ` Antony Pavlov
@ 2014-04-04 16:52     ` Michel Stam
  2014-04-04 18:12       ` Antony Pavlov
  0 siblings, 1 reply; 8+ messages in thread
From: Michel Stam @ 2014-04-04 16:52 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox


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

Hello Antony,

Sorry to hear that- the patch was not meant to add new functionality, merely preserve the status quo in master. 

To explain; add_ns16550_device() assumes that all ns16550 chips are mapped into memory. This is not so on the x86 platform. Previously, because no io-mapped resources were available, x86 created a "memory" device with custom IO routines. I rewrote this to use IORESOURCE_IO instead, but to do this, the invocation of the add_ns16550_device() needed to specify the resource type. The patch which conflicts with your patch can be undone as far as I'm concerned; I wasn't adding anything new to the mips/mach-xburst platform. I can redo the patch, leaving the file targeted by your patch unchanged if you like?

Regards,

Michel Stam


> On 4 apr. 2014, at 17:56, Antony Pavlov <antonynpavlov@gmail.com> wrote:
> 
> On Fri,  4 Apr 2014 15:41:39 +0200
> michel@reverze.net wrote:
> 
>> From: Michel Stam <m.stam@fugro.nl>
>> 
>> The current implementation fakes a memory-mapped I/O device
>> at 0x3f8 and 0x2f8, then uses platform read/write functions
>> to do the actual reading and writing. These platform functions
>> only exist for the x86 platform; better to move the I/O
>> routines into the driver and have the driver request I/O ports
>> using request_ioport_region.
>> ---
>> arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    2 +-
>> arch/arm/mach-mvebu/armada-370-xp.c               |    3 +-
>> arch/arm/mach-mvebu/kirkwood.c                    |    3 +-
>> arch/arm/mach-socfpga/xload.c                     |    4 +-
>> arch/arm/mach-tegra/tegra20.c                     |    2 +-
>> arch/mips/boards/dlink-dir-320/serial.c           |    2 +-
>> arch/mips/boards/loongson-ls1b/serial.c           |    2 +-
>> arch/mips/mach-ar231x/ar231x.c                    |    2 +-
>> arch/mips/mach-xburst/serial.c                    |   60 ++++++++++
> hmmm
> this partly revert my recent commit in the 'next' branch:
> 
> commit 8f5d37835d44d07460d92307f0b6489048a18fba
> Author: Antony Pavlov <antonynpavlov@gmail.com>
> Date:   Tue Mar 25 20:50:58 2014 +0400
> 
>    MIPS: mach-xburst: drop serial.c
> 
>    We use dts for serial port initialization,
>    so we have no need in mach-xburst/serial.c anymore.
> 
>    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
>    Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> 
> arch/mips/mach-xburst/Makefile |  1 -
> arch/mips/mach-xburst/serial.c | 60 -----------------------------------------------------
> 2 files changed, 61 deletions(-)
> 
>> arch/openrisc/boards/generic/generic.c            |    2 +-
>> arch/ppc/boards/freescale-p1022ds/p1022ds.c       |    2 +-
>> arch/ppc/boards/freescale-p2020rdb/p2020rdb.c     |    3 +-
>> arch/ppc/boards/geip-da923rc/da923rc.c            |    3 +-
>> arch/x86/boards/x86_generic/generic_pc.c          |    5 +-
>> arch/x86/mach-i386/Makefile                       |    1 -
>> arch/x86/mach-i386/generic.c                      |   34 ------
>> drivers/serial/serial_ns16550.c                   |  122 ++++++++++++++++++---
>> include/driver.h                                  |    2 +-
>> include/ns16550.h                                 |   11 +--
>> 19 files changed, 187 insertions(+), 78 deletions(-)
>> create mode 100644 arch/mips/mach-xburst/serial.c
>> delete mode 100644 arch/x86/mach-i386/generic.c
>> 
>> diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>> index e2ad1c8..69967c5 100644
>> --- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>> +++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>> @@ -223,7 +223,7 @@ static int eukrea_cpuimx27_console_init(void)
>>    imx27_setup_weimcs(3, 0x0000D603, 0x0D1D0D01, 0x00D20000);
>> #ifdef CONFIG_DRIVER_SERIAL_NS16550
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, MX27_CS3_BASE_ADDR + QUART_OFFSET, 0xf,
>> -             IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
>> +             IORESOURCE_MEM | IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
>> #endif
>>    return 0;
>> }
>> diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
>> index 776b4c0..209be0b 100644
>> --- a/arch/arm/mach-mvebu/armada-370-xp.c
>> +++ b/arch/arm/mach-mvebu/armada-370-xp.c
>> @@ -60,7 +60,8 @@ static int armada_370_xp_add_uart(void)
>>    uart_plat.clock = clk_get_rate(tclk);
>>    if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>>                (unsigned int)CONSOLE_UART_BASE, 32,
>> -                IORESOURCE_MEM_32BIT, &uart_plat))
>> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
>> +                &uart_plat))
>>        return -ENODEV;
>>    return 0;
>> }
>> diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
>> index 1284220..c79d130 100644
>> --- a/arch/arm/mach-mvebu/kirkwood.c
>> +++ b/arch/arm/mach-mvebu/kirkwood.c
>> @@ -58,7 +58,8 @@ static int kirkwood_add_uart(void)
>>    uart_plat.clock = clk_get_rate(tclk);
>>    if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>>                (unsigned int)CONSOLE_UART_BASE, 32,
>> -                IORESOURCE_MEM_32BIT, &uart_plat))
>> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
>> +                &uart_plat))
>>        return -ENODEV;
>>    return 0;
>> }
>> diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
>> index 0b99db0..6586ada 100644
>> --- a/arch/arm/mach-socfpga/xload.c
>> +++ b/arch/arm/mach-socfpga/xload.c
>> @@ -45,8 +45,8 @@ static void socfpga_uart_init(void)
>>    clks[uart] = clk_fixed("uart", 100000000);
>>    clkdev_add_physbase(clks[uart], CYCLONE5_UART0_ADDRESS, NULL);
>>    clkdev_add_physbase(clks[uart], CYCLONE5_UART1_ADDRESS, NULL);
>> -    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM_8BIT,
>> -            &uart_pdata);
>> +    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM |
>> +            IORESOURCE_MEM_8BIT, &uart_pdata);
>> }
>> 
>> static void socfpga_timer_init(void)
>> diff --git a/arch/arm/mach-tegra/tegra20.c b/arch/arm/mach-tegra/tegra20.c
>> index cc2d748..bdd7960 100644
>> --- a/arch/arm/mach-tegra/tegra20.c
>> +++ b/arch/arm/mach-tegra/tegra20.c
>> @@ -50,7 +50,7 @@ static int tegra20_add_debug_console(void)
>>        return -ENODEV;
>> 
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, base, 8 << debug_uart.shift,
>> -               IORESOURCE_MEM_8BIT, &debug_uart);
>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &debug_uart);
>> 
>>    return 0;
>> }
>> diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
>> index bddb683..eb87379 100644
>> --- a/arch/mips/boards/dlink-dir-320/serial.c
>> +++ b/arch/mips/boards/dlink-dir-320/serial.c
>> @@ -36,7 +36,7 @@ static int dir320_console_init(void)
>> 
>>    /* Register the serial port */
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
>> -            IORESOURCE_MEM_8BIT, &serial_plat);
>> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>> 
>>    return 0;
>> }
>> diff --git a/arch/mips/boards/loongson-ls1b/serial.c b/arch/mips/boards/loongson-ls1b/serial.c
>> index d8e0f7c..7159ab7 100644
>> --- a/arch/mips/boards/loongson-ls1b/serial.c
>> +++ b/arch/mips/boards/loongson-ls1b/serial.c
>> @@ -15,7 +15,7 @@ static int console_init(void)
>>    barebox_set_hostname("ls1b");
>> 
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(LS1X_UART2_BASE),
>> -        8, IORESOURCE_MEM_8BIT, &serial_plat);
>> +        8, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>> 
>>    return 0;
>> }
>> diff --git a/arch/mips/mach-ar231x/ar231x.c b/arch/mips/mach-ar231x/ar231x.c
>> index ca912bf..06d2edb 100644
>> --- a/arch/mips/mach-ar231x/ar231x.c
>> +++ b/arch/mips/mach-ar231x/ar231x.c
>> @@ -189,7 +189,7 @@ static int ar2312_console_init(void)
>>    /* Register the serial port */
>>    serial_plat.clock = ar2312_sys_frequency();
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(AR2312_UART0),
>> -        8 << AR2312_UART_SHIFT, IORESOURCE_MEM_8BIT, &serial_plat);
>> +        8 << AR2312_UART_SHIFT, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>    return 0;
>> }
>> console_initcall(ar2312_console_init);
>> diff --git a/arch/mips/mach-xburst/serial.c b/arch/mips/mach-xburst/serial.c
>> new file mode 100644
>> index 0000000..4365d19
>> --- /dev/null
>> +++ b/arch/mips/mach-xburst/serial.c
>> @@ -0,0 +1,60 @@
>> +/*
>> + * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
>> + *
>> + * Based on the linux kernel JZ4740 serial support:
>> + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
>> + *
>> + * This file is part of barebox.
>> + * See file CREDITS for list of people who contributed to this project.
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2
>> + * as published by the Free Software Foundation.
>> + *
>> + * This program 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.
>> + *
>> + */
>> +
>> +#include <common.h>
>> +#include <ns16550.h>
>> +#include <io.h>
>> +#include <mach/devices.h>
>> +
>> +#define JZ_UART_SHIFT    2
>> +
>> +#define ier        (1 << JZ_UART_SHIFT)
>> +#define fcr        (2 << JZ_UART_SHIFT)
>> +
>> +static void jz_serial_reg_write(unsigned int val, unsigned long base,
>> +    unsigned char reg_offset)
>> +{
>> +    switch (reg_offset) {
>> +    case fcr:
>> +        val |= 0x10; /* Enable uart module */
>> +        break;
>> +    case ier:
>> +        val |= (val & 0x4) << 2;
>> +        break;
>> +    default:
>> +        break;
>> +    }
>> +
>> +    writeb(val & 0xff, (void *)(base + reg_offset));
>> +}
>> +
>> +struct device_d *jz_add_uart(int id, unsigned long base, unsigned int clock)
>> +{
>> +    struct NS16550_plat *serial_plat;
>> +
>> +    serial_plat = xzalloc(sizeof(*serial_plat));
>> +
>> +    serial_plat->shift = JZ_UART_SHIFT;
>> +    serial_plat->reg_write = &jz_serial_reg_write;
>> +    serial_plat->clock = clock;
>> +
>> +    return add_ns16550_device(id, base, 8 << JZ_UART_SHIFT,
>> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, serial_plat);
>> +}
>> diff --git a/arch/openrisc/boards/generic/generic.c b/arch/openrisc/boards/generic/generic.c
>> index 290e05c..1d6ac8a 100644
>> --- a/arch/openrisc/boards/generic/generic.c
>> +++ b/arch/openrisc/boards/generic/generic.c
>> @@ -15,7 +15,7 @@ static int openrisc_console_init(void)
>>    barebox_set_hostname("or1k");
>> 
>>    /* Register the serial port */
>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM_8BIT, &serial_plat);
>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>> 
>> #ifdef CONFIG_DRIVER_NET_ETHOC
>>    add_generic_device("ethoc", DEVICE_ID_DYNAMIC, NULL,
>> diff --git a/arch/ppc/boards/freescale-p1022ds/p1022ds.c b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>> index c800064..57e7953 100644
>> --- a/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>> +++ b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>> @@ -130,7 +130,7 @@ static int p1022ds_console_init(void)
>> 
>>    serial_plat.clock = fsl_get_bus_freq(0);
>>    add_ns16550_device(DEVICE_ID_DYNAMIC, CFG_IMMR + 0x4500, 16,
>> -               IORESOURCE_MEM_8BIT, &serial_plat);
>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>    return 0;
>> }
>> 
>> diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>> index 229ae41..385a436 100644
>> --- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>> +++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>> @@ -112,7 +112,8 @@ static int p2020_console_init(void)
>> 
>>    serial_plat.clock = fsl_get_bus_freq(0);
>> 
>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16, IORESOURCE_MEM_8BIT,
>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16,
>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>>               &serial_plat);
>>    return 0;
>> }
>> diff --git a/arch/ppc/boards/geip-da923rc/da923rc.c b/arch/ppc/boards/geip-da923rc/da923rc.c
>> index 976aa8d..3d77349 100644
>> --- a/arch/ppc/boards/geip-da923rc/da923rc.c
>> +++ b/arch/ppc/boards/geip-da923rc/da923rc.c
>> @@ -115,7 +115,8 @@ static int da923rc_console_init(void)
>>        barebox_set_model("unknown");
>> 
>>    serial_plat.clock = fsl_get_bus_freq(0);
>> -    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16, IORESOURCE_MEM_8BIT,
>> +    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16,
>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>>               &serial_plat);
>>    return 0;
>> }
>> diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
>> index 895b88d..69c6f58 100644
>> --- a/arch/x86/boards/x86_generic/generic_pc.c
>> +++ b/arch/x86/boards/x86_generic/generic_pc.c
>> @@ -141,8 +141,6 @@ device_initcall(devices_init);
>> 
>> static struct NS16550_plat serial_plat = {
>>        .clock = 1843200,
>> -       .reg_read = x86_uart_read,
>> -       .reg_write = x86_uart_write,
>> };
>> 
>> static int pc_console_init(void)
>> @@ -151,7 +149,8 @@ static int pc_console_init(void)
>>    barebox_set_hostname("x86");
>> 
>>    /* Register the serial port */
>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, 0, &serial_plat);
>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, IORESOURCE_IO, &serial_plat);
>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x2f8, 8, IORESOURCE_IO, &serial_plat);
>> 
>>    return 0;
>> }
>> diff --git a/arch/x86/mach-i386/Makefile b/arch/x86/mach-i386/Makefile
>> index 10712e6..e46aa5b 100644
>> --- a/arch/x86/mach-i386/Makefile
>> +++ b/arch/x86/mach-i386/Makefile
>> @@ -1,4 +1,3 @@
>> -obj-y += generic.o
>> obj-y += reset.o
>> 
>> # reference clocksource
>> diff --git a/arch/x86/mach-i386/generic.c b/arch/x86/mach-i386/generic.c
>> deleted file mode 100644
>> index 69cf53c..0000000
>> --- a/arch/x86/mach-i386/generic.c
>> +++ /dev/null
>> @@ -1,34 +0,0 @@
>> -/*
>> - * Copyright (C) 2009 Juergen Beisert, Pengutronix
>> - *
>> - * This program 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.
>> - *
>> - * This program 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.
>> - *
>> - *
>> - */
>> -
>> -/**
>> - * @file
>> - * @brief x86 Architecture Initialization routines
>> - */
>> -
>> -#include <io.h>
>> -
>> -/** to work with the 8250 UART driver implementation we need this function */
>> -unsigned int x86_uart_read(unsigned long base, unsigned char reg_idx)
>> -{
>> -    return inb(base + reg_idx);
>> -}
>> -
>> -/** to work with the 8250 UART driver implementation we need this function */
>> -void x86_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
>> -{
>> -    outb(val, base + reg_idx);
>> -}
>> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
>> index 0c00eb1..dfe572d 100644
>> --- a/drivers/serial/serial_ns16550.c
>> +++ b/drivers/serial/serial_ns16550.c
>> @@ -47,6 +47,7 @@ struct ns16550_priv {
>>    struct console_device cdev;
>>    struct NS16550_plat plat;
>>    int access_width;
>> +    int mmio;
>>    struct clk *clk;
>>    uint32_t fcrval;
>> };
>> @@ -62,6 +63,87 @@ struct ns16550_drvdata {
>> };
>> 
>> /**
>> + * @brief read system i/o (byte)
>> + * @param[in] addr address to read
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        return readb(addr);
>> +        else
>> +        return (uint8_t) inb((int) addr);
>> +}
>> +
>> +/**
>> + * @brief read system i/o (word)
>> + * @param[in] addr address to read
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        return readw(addr);
>> +        else
>> +        return (uint16_t) inw((int) addr);
>> +}
>> +
>> +/**
>> + * @brief read system i/o (dword)
>> + * @param[in] addr address to read
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        return readl(addr);
>> +        else
>> +        return (uint32_t) inl((int) addr);
>> +}
>> +
>> +/**
>> + * @brief write system i/o (byte)
>> + * @param[in] val data to write
>> + * @param[in] addr address to write to
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        writeb(val, addr);
>> +        else
>> +        outb(val, (int) addr);
>> +}
>> +
>> +/**
>> + * @brief read system i/o (word)
>> + * @param[in] val data to write
>> + * @param[in] addr address to write to
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        writew(val, addr);
>> +        else
>> +        outw(val, (int) addr);
>> +}
>> +
>> +/**
>> + * @brief read system i/o (dword)
>> + * @param[in] val data to write
>> + * @param[in] addr address to write to
>> + * @param[in] mmio memory i/o space or i/o port space
>> + */
>> +static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, int mmio)
>> +{
>> +    if (mmio)
>> +        writel(val, addr);
>> +        else
>> +        outl(val, (int) addr);
>> +}
>> +
>> +/**
>>  * @brief read register
>>  *
>>  * @param[in] cdev pointer to console device
>> @@ -78,16 +160,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
>> 
>>    off <<= plat->shift;
>> 
>> -    if (plat->reg_read)
>> -        return plat->reg_read((unsigned long)dev->priv, off);
>> -
>>    switch (width) {
>>    case IORESOURCE_MEM_8BIT:
>> -        return readb(dev->priv + off);
>> +        return ns16550_sys_readb(dev->priv + off, priv->mmio);
>>    case IORESOURCE_MEM_16BIT:
>> -        return readw(dev->priv + off);
>> +        return ns16550_sys_readw(dev->priv + off, priv->mmio);
>>    case IORESOURCE_MEM_32BIT:
>> -        return readl(dev->priv + off);
>> +        return ns16550_sys_readl(dev->priv + off, priv->mmio);
>>    }
>>    return -1;
>> }
>> @@ -109,20 +188,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
>> 
>>    off <<= plat->shift;
>> 
>> -    if (plat->reg_write) {
>> -        plat->reg_write(val, (unsigned long)dev->priv, off);
>> -        return;
>> -    }
>> -
>>    switch (width) {
>>    case IORESOURCE_MEM_8BIT:
>> -        writeb(val & 0xff, dev->priv + off);
>> +        ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio);
>>        break;
>>    case IORESOURCE_MEM_16BIT:
>> -        writew(val & 0xffff, dev->priv + off);
>> +        ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio);
>>        break;
>>    case IORESOURCE_MEM_32BIT:
>> -        writel(val, dev->priv + off);
>> +        ns16550_sys_writel(val, dev->priv + off, priv->mmio);
>>        break;
>>    }
>> }
>> @@ -293,16 +367,32 @@ static int ns16550_probe(struct device_d *dev)
>>    struct console_device *cdev;
>>    struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
>>    struct ns16550_drvdata *devtype;
>> +    struct resource *res;
>>    int ret;
>> 
>>    ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
>>    if (ret)
>>        devtype = &ns16550_drvdata;
>> 
>> -    dev->priv = dev_request_mem_region(dev, 0);
>> -
>>    priv = xzalloc(sizeof(*priv));
>> 
>> +    res = dev_get_resource(dev, IORESOURCE_MEM, 0);
>> +    priv->mmio = (res != NULL);
>> +    if (res)
>> +    {
>> +        res = request_iomem_region(dev_name(dev),res->start,res->end);
>> +    }
>> +    else
>> +    {
> 
> 
> 
> Have you checked your patches with checkpatch.pl script?
> 
> 
>> +        res = dev_get_resource(dev, IORESOURCE_IO, 0);
>> +        if (res)
>> +            res = request_ioport_region(dev_name(dev),res->start,res->end);
>> +    }
>> +    if (!res)
>> +        goto err;
>> +    dev->priv = (void __force __iomem *) res->start;
>> +
>> +
>>    if (plat)
>>        priv->plat = *plat;
>>    else
>> diff --git a/include/driver.h b/include/driver.h
>> index 37797c7..ff4a5a1 100644
>> --- a/include/driver.h
>> +++ b/include/driver.h
>> @@ -276,7 +276,7 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
>>        resource_size_t size, int flags, struct NS16550_plat *pdata)
>> {
>>    return add_generic_device("ns16550_serial", id, NULL, start, size,
>> -                  IORESOURCE_MEM | flags, pdata);
>> +                  flags, pdata);
>> }
>> 
>> #ifdef CONFIG_DRIVER_NET_DM9K
>> diff --git a/include/ns16550.h b/include/ns16550.h
>> index 36aa5ff..876bb04 100644
>> --- a/include/ns16550.h
>> +++ b/include/ns16550.h
>> @@ -33,18 +33,9 @@
>> struct NS16550_plat {
>>    /** Clock speed */
>>    unsigned int clock;
>> -    /**
>> -     * register read access capability
>> -     */
>> -    unsigned int (*reg_read) (unsigned long base, unsigned char reg_offset);
>> -    /**
>> -     * register write access capability
>> -     */
>> -    void (*reg_write) (unsigned int val, unsigned long base,
>> -                    unsigned char reg_offset);
>> -
>>    int shift;
>>    unsigned int flags;
>> +    int mmio;
> 
> Do you really need this 'int mmio' here?
> 
>> #define NS16650_FLAG_DISABLE_FIFO    1
>> };
>> 
>> -- 
>> 1.7.1
>> 
>> 
>> _______________________________________________
>> barebox mailing list
>> barebox@lists.infradead.org
>> http://lists.infradead.org/mailman/listinfo/barebox
> 
> 
> -- 
> -- 
> Best regards,
>   Antony Pavlov

[-- Attachment #1.2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 6165 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 18:12       ` Antony Pavlov
@ 2014-04-04 18:11         ` Michel Stam
  2014-04-05 16:20         ` Sascha Hauer
  1 sibling, 0 replies; 8+ messages in thread
From: Michel Stam @ 2014-04-04 18:11 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox


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

Hello Antony,

I was not aware of this. No matter, I've resubmitted the patches, 
they're rebased on top of next now.

Michel
On 04/04/2014 08:12 PM, Antony Pavlov wrote:
> On Fri, 4 Apr 2014 18:52:46 +0200
> Michel Stam <michel@reverze.net> wrote:
>
>> Hello Antony,
>>
>> Sorry to hear that- the patch was not meant to add new functionality, merely preserve the status quo in master.
> Quite the contrary!
>
> Your patchseries introduces new functionality, it adds additional io space.
>
> In barebox maillist all new functionality patches are assumed to be 'next' branch patches.
>
> Only critical bugfixes and trivial changes can go to the 'master' branch directly.
>
>> To explain; add_ns16550_device() assumes that all ns16550 chips are mapped into memory. This is not so on the x86 platform. Previously, because no io-mapped resources were available, x86 created a "memory" device with custom IO routines. I rewrote this to use IORESOURCE_IO instead, but to do this, the invocation of the add_ns16550_device() needed to specify the resource type. The patch which conflicts with your patch can be undone as far as I'm concerned; I wasn't adding anything new to the mips/mach-xburst platform. I can redo the patch, leaving the file targeted by your patch unchanged if you like?
> IMHO you have to rebase your patches over the 'next' branch.
>
> Also please use scripts/checkpatch.pl programm before sending patches to the maillist.
>
>>> On 4 apr. 2014, at 17:56, Antony Pavlov <antonynpavlov@gmail.com> wrote:
>>>
>>> On Fri,  4 Apr 2014 15:41:39 +0200
>>> michel@reverze.net wrote:
>>>
>>>> From: Michel Stam <m.stam@fugro.nl>
>>>>
>>>> The current implementation fakes a memory-mapped I/O device
>>>> at 0x3f8 and 0x2f8, then uses platform read/write functions
>>>> to do the actual reading and writing. These platform functions
>>>> only exist for the x86 platform; better to move the I/O
>>>> routines into the driver and have the driver request I/O ports
>>>> using request_ioport_region.
>>>> ---
>>>> arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    2 +-
>>>> arch/arm/mach-mvebu/armada-370-xp.c               |    3 +-
>>>> arch/arm/mach-mvebu/kirkwood.c                    |    3 +-
>>>> arch/arm/mach-socfpga/xload.c                     |    4 +-
>>>> arch/arm/mach-tegra/tegra20.c                     |    2 +-
>>>> arch/mips/boards/dlink-dir-320/serial.c           |    2 +-
>>>> arch/mips/boards/loongson-ls1b/serial.c           |    2 +-
>>>> arch/mips/mach-ar231x/ar231x.c                    |    2 +-
>>>> arch/mips/mach-xburst/serial.c                    |   60 ++++++++++
>>> hmmm
>>> this partly revert my recent commit in the 'next' branch:
>>>
>>> commit 8f5d37835d44d07460d92307f0b6489048a18fba
>>> Author: Antony Pavlov <antonynpavlov@gmail.com>
>>> Date:   Tue Mar 25 20:50:58 2014 +0400
>>>
>>>     MIPS: mach-xburst: drop serial.c
>>>
>>>     We use dts for serial port initialization,
>>>     so we have no need in mach-xburst/serial.c anymore.
>>>
>>>     Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
>>>     Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
>>>
>>> arch/mips/mach-xburst/Makefile |  1 -
>>> arch/mips/mach-xburst/serial.c | 60 -----------------------------------------------------
>>> 2 files changed, 61 deletions(-)
>>>
>>>> arch/openrisc/boards/generic/generic.c            |    2 +-
>>>> arch/ppc/boards/freescale-p1022ds/p1022ds.c       |    2 +-
>>>> arch/ppc/boards/freescale-p2020rdb/p2020rdb.c     |    3 +-
>>>> arch/ppc/boards/geip-da923rc/da923rc.c            |    3 +-
>>>> arch/x86/boards/x86_generic/generic_pc.c          |    5 +-
>>>> arch/x86/mach-i386/Makefile                       |    1 -
>>>> arch/x86/mach-i386/generic.c                      |   34 ------
>>>> drivers/serial/serial_ns16550.c                   |  122 ++++++++++++++++++---
>>>> include/driver.h                                  |    2 +-
>>>> include/ns16550.h                                 |   11 +--
>>>> 19 files changed, 187 insertions(+), 78 deletions(-)
>>>> create mode 100644 arch/mips/mach-xburst/serial.c
>>>> delete mode 100644 arch/x86/mach-i386/generic.c
>>>>
>>>> diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>>>> index e2ad1c8..69967c5 100644
>>>> --- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>>>> +++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
>>>> @@ -223,7 +223,7 @@ static int eukrea_cpuimx27_console_init(void)
>>>>     imx27_setup_weimcs(3, 0x0000D603, 0x0D1D0D01, 0x00D20000);
>>>> #ifdef CONFIG_DRIVER_SERIAL_NS16550
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, MX27_CS3_BASE_ADDR + QUART_OFFSET, 0xf,
>>>> -             IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
>>>> +             IORESOURCE_MEM | IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
>>>> #endif
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
>>>> index 776b4c0..209be0b 100644
>>>> --- a/arch/arm/mach-mvebu/armada-370-xp.c
>>>> +++ b/arch/arm/mach-mvebu/armada-370-xp.c
>>>> @@ -60,7 +60,8 @@ static int armada_370_xp_add_uart(void)
>>>>     uart_plat.clock = clk_get_rate(tclk);
>>>>     if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>>>>                 (unsigned int)CONSOLE_UART_BASE, 32,
>>>> -                IORESOURCE_MEM_32BIT, &uart_plat))
>>>> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
>>>> +                &uart_plat))
>>>>         return -ENODEV;
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
>>>> index 1284220..c79d130 100644
>>>> --- a/arch/arm/mach-mvebu/kirkwood.c
>>>> +++ b/arch/arm/mach-mvebu/kirkwood.c
>>>> @@ -58,7 +58,8 @@ static int kirkwood_add_uart(void)
>>>>     uart_plat.clock = clk_get_rate(tclk);
>>>>     if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
>>>>                 (unsigned int)CONSOLE_UART_BASE, 32,
>>>> -                IORESOURCE_MEM_32BIT, &uart_plat))
>>>> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
>>>> +                &uart_plat))
>>>>         return -ENODEV;
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
>>>> index 0b99db0..6586ada 100644
>>>> --- a/arch/arm/mach-socfpga/xload.c
>>>> +++ b/arch/arm/mach-socfpga/xload.c
>>>> @@ -45,8 +45,8 @@ static void socfpga_uart_init(void)
>>>>     clks[uart] = clk_fixed("uart", 100000000);
>>>>     clkdev_add_physbase(clks[uart], CYCLONE5_UART0_ADDRESS, NULL);
>>>>     clkdev_add_physbase(clks[uart], CYCLONE5_UART1_ADDRESS, NULL);
>>>> -    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM_8BIT,
>>>> -            &uart_pdata);
>>>> +    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM |
>>>> +            IORESOURCE_MEM_8BIT, &uart_pdata);
>>>> }
>>>>
>>>> static void socfpga_timer_init(void)
>>>> diff --git a/arch/arm/mach-tegra/tegra20.c b/arch/arm/mach-tegra/tegra20.c
>>>> index cc2d748..bdd7960 100644
>>>> --- a/arch/arm/mach-tegra/tegra20.c
>>>> +++ b/arch/arm/mach-tegra/tegra20.c
>>>> @@ -50,7 +50,7 @@ static int tegra20_add_debug_console(void)
>>>>         return -ENODEV;
>>>>
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, base, 8 << debug_uart.shift,
>>>> -               IORESOURCE_MEM_8BIT, &debug_uart);
>>>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &debug_uart);
>>>>
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
>>>> index bddb683..eb87379 100644
>>>> --- a/arch/mips/boards/dlink-dir-320/serial.c
>>>> +++ b/arch/mips/boards/dlink-dir-320/serial.c
>>>> @@ -36,7 +36,7 @@ static int dir320_console_init(void)
>>>>
>>>>     /* Register the serial port */
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
>>>> -            IORESOURCE_MEM_8BIT, &serial_plat);
>>>> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>>>
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/mips/boards/loongson-ls1b/serial.c b/arch/mips/boards/loongson-ls1b/serial.c
>>>> index d8e0f7c..7159ab7 100644
>>>> --- a/arch/mips/boards/loongson-ls1b/serial.c
>>>> +++ b/arch/mips/boards/loongson-ls1b/serial.c
>>>> @@ -15,7 +15,7 @@ static int console_init(void)
>>>>     barebox_set_hostname("ls1b");
>>>>
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(LS1X_UART2_BASE),
>>>> -        8, IORESOURCE_MEM_8BIT, &serial_plat);
>>>> +        8, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>>>
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/mips/mach-ar231x/ar231x.c b/arch/mips/mach-ar231x/ar231x.c
>>>> index ca912bf..06d2edb 100644
>>>> --- a/arch/mips/mach-ar231x/ar231x.c
>>>> +++ b/arch/mips/mach-ar231x/ar231x.c
>>>> @@ -189,7 +189,7 @@ static int ar2312_console_init(void)
>>>>     /* Register the serial port */
>>>>     serial_plat.clock = ar2312_sys_frequency();
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(AR2312_UART0),
>>>> -        8 << AR2312_UART_SHIFT, IORESOURCE_MEM_8BIT, &serial_plat);
>>>> +        8 << AR2312_UART_SHIFT, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>>>     return 0;
>>>> }
>>>> console_initcall(ar2312_console_init);
>>>> diff --git a/arch/mips/mach-xburst/serial.c b/arch/mips/mach-xburst/serial.c
>>>> new file mode 100644
>>>> index 0000000..4365d19
>>>> --- /dev/null
>>>> +++ b/arch/mips/mach-xburst/serial.c
>>>> @@ -0,0 +1,60 @@
>>>> +/*
>>>> + * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
>>>> + *
>>>> + * Based on the linux kernel JZ4740 serial support:
>>>> + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
>>>> + *
>>>> + * This file is part of barebox.
>>>> + * See file CREDITS for list of people who contributed to this project.
>>>> + *
>>>> + * This program is free software; you can redistribute it and/or modify
>>>> + * it under the terms of the GNU General Public License version 2
>>>> + * as published by the Free Software Foundation.
>>>> + *
>>>> + * This program 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.
>>>> + *
>>>> + */
>>>> +
>>>> +#include <common.h>
>>>> +#include <ns16550.h>
>>>> +#include <io.h>
>>>> +#include <mach/devices.h>
>>>> +
>>>> +#define JZ_UART_SHIFT    2
>>>> +
>>>> +#define ier        (1 << JZ_UART_SHIFT)
>>>> +#define fcr        (2 << JZ_UART_SHIFT)
>>>> +
>>>> +static void jz_serial_reg_write(unsigned int val, unsigned long base,
>>>> +    unsigned char reg_offset)
>>>> +{
>>>> +    switch (reg_offset) {
>>>> +    case fcr:
>>>> +        val |= 0x10; /* Enable uart module */
>>>> +        break;
>>>> +    case ier:
>>>> +        val |= (val & 0x4) << 2;
>>>> +        break;
>>>> +    default:
>>>> +        break;
>>>> +    }
>>>> +
>>>> +    writeb(val & 0xff, (void *)(base + reg_offset));
>>>> +}
>>>> +
>>>> +struct device_d *jz_add_uart(int id, unsigned long base, unsigned int clock)
>>>> +{
>>>> +    struct NS16550_plat *serial_plat;
>>>> +
>>>> +    serial_plat = xzalloc(sizeof(*serial_plat));
>>>> +
>>>> +    serial_plat->shift = JZ_UART_SHIFT;
>>>> +    serial_plat->reg_write = &jz_serial_reg_write;
>>>> +    serial_plat->clock = clock;
>>>> +
>>>> +    return add_ns16550_device(id, base, 8 << JZ_UART_SHIFT,
>>>> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, serial_plat);
>>>> +}
>>>> diff --git a/arch/openrisc/boards/generic/generic.c b/arch/openrisc/boards/generic/generic.c
>>>> index 290e05c..1d6ac8a 100644
>>>> --- a/arch/openrisc/boards/generic/generic.c
>>>> +++ b/arch/openrisc/boards/generic/generic.c
>>>> @@ -15,7 +15,7 @@ static int openrisc_console_init(void)
>>>>     barebox_set_hostname("or1k");
>>>>
>>>>     /* Register the serial port */
>>>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM_8BIT, &serial_plat);
>>>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>>>
>>>> #ifdef CONFIG_DRIVER_NET_ETHOC
>>>>     add_generic_device("ethoc", DEVICE_ID_DYNAMIC, NULL,
>>>> diff --git a/arch/ppc/boards/freescale-p1022ds/p1022ds.c b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>>>> index c800064..57e7953 100644
>>>> --- a/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>>>> +++ b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
>>>> @@ -130,7 +130,7 @@ static int p1022ds_console_init(void)
>>>>
>>>>     serial_plat.clock = fsl_get_bus_freq(0);
>>>>     add_ns16550_device(DEVICE_ID_DYNAMIC, CFG_IMMR + 0x4500, 16,
>>>> -               IORESOURCE_MEM_8BIT, &serial_plat);
>>>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
>>>>     return 0;
>>>> }
>>>>
>>>> diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>>>> index 229ae41..385a436 100644
>>>> --- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>>>> +++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
>>>> @@ -112,7 +112,8 @@ static int p2020_console_init(void)
>>>>
>>>>     serial_plat.clock = fsl_get_bus_freq(0);
>>>>
>>>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16, IORESOURCE_MEM_8BIT,
>>>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16,
>>>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>>>>                &serial_plat);
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/ppc/boards/geip-da923rc/da923rc.c b/arch/ppc/boards/geip-da923rc/da923rc.c
>>>> index 976aa8d..3d77349 100644
>>>> --- a/arch/ppc/boards/geip-da923rc/da923rc.c
>>>> +++ b/arch/ppc/boards/geip-da923rc/da923rc.c
>>>> @@ -115,7 +115,8 @@ static int da923rc_console_init(void)
>>>>         barebox_set_model("unknown");
>>>>
>>>>     serial_plat.clock = fsl_get_bus_freq(0);
>>>> -    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16, IORESOURCE_MEM_8BIT,
>>>> +    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16,
>>>> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
>>>>                &serial_plat);
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
>>>> index 895b88d..69c6f58 100644
>>>> --- a/arch/x86/boards/x86_generic/generic_pc.c
>>>> +++ b/arch/x86/boards/x86_generic/generic_pc.c
>>>> @@ -141,8 +141,6 @@ device_initcall(devices_init);
>>>>
>>>> static struct NS16550_plat serial_plat = {
>>>>         .clock = 1843200,
>>>> -       .reg_read = x86_uart_read,
>>>> -       .reg_write = x86_uart_write,
>>>> };
>>>>
>>>> static int pc_console_init(void)
>>>> @@ -151,7 +149,8 @@ static int pc_console_init(void)
>>>>     barebox_set_hostname("x86");
>>>>
>>>>     /* Register the serial port */
>>>> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, 0, &serial_plat);
>>>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, IORESOURCE_IO, &serial_plat);
>>>> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x2f8, 8, IORESOURCE_IO, &serial_plat);
>>>>
>>>>     return 0;
>>>> }
>>>> diff --git a/arch/x86/mach-i386/Makefile b/arch/x86/mach-i386/Makefile
>>>> index 10712e6..e46aa5b 100644
>>>> --- a/arch/x86/mach-i386/Makefile
>>>> +++ b/arch/x86/mach-i386/Makefile
>>>> @@ -1,4 +1,3 @@
>>>> -obj-y += generic.o
>>>> obj-y += reset.o
>>>>
>>>> # reference clocksource
>>>> diff --git a/arch/x86/mach-i386/generic.c b/arch/x86/mach-i386/generic.c
>>>> deleted file mode 100644
>>>> index 69cf53c..0000000
>>>> --- a/arch/x86/mach-i386/generic.c
>>>> +++ /dev/null
>>>> @@ -1,34 +0,0 @@
>>>> -/*
>>>> - * Copyright (C) 2009 Juergen Beisert, Pengutronix
>>>> - *
>>>> - * This program 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.
>>>> - *
>>>> - * This program 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.
>>>> - *
>>>> - *
>>>> - */
>>>> -
>>>> -/**
>>>> - * @file
>>>> - * @brief x86 Architecture Initialization routines
>>>> - */
>>>> -
>>>> -#include <io.h>
>>>> -
>>>> -/** to work with the 8250 UART driver implementation we need this function */
>>>> -unsigned int x86_uart_read(unsigned long base, unsigned char reg_idx)
>>>> -{
>>>> -    return inb(base + reg_idx);
>>>> -}
>>>> -
>>>> -/** to work with the 8250 UART driver implementation we need this function */
>>>> -void x86_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
>>>> -{
>>>> -    outb(val, base + reg_idx);
>>>> -}
>>>> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
>>>> index 0c00eb1..dfe572d 100644
>>>> --- a/drivers/serial/serial_ns16550.c
>>>> +++ b/drivers/serial/serial_ns16550.c
>>>> @@ -47,6 +47,7 @@ struct ns16550_priv {
>>>>     struct console_device cdev;
>>>>     struct NS16550_plat plat;
>>>>     int access_width;
>>>> +    int mmio;
>>>>     struct clk *clk;
>>>>     uint32_t fcrval;
>>>> };
>>>> @@ -62,6 +63,87 @@ struct ns16550_drvdata {
>>>> };
>>>>
>>>> /**
>>>> + * @brief read system i/o (byte)
>>>> + * @param[in] addr address to read
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        return readb(addr);
>>>> +        else
>>>> +        return (uint8_t) inb((int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>> + * @brief read system i/o (word)
>>>> + * @param[in] addr address to read
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        return readw(addr);
>>>> +        else
>>>> +        return (uint16_t) inw((int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>> + * @brief read system i/o (dword)
>>>> + * @param[in] addr address to read
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        return readl(addr);
>>>> +        else
>>>> +        return (uint32_t) inl((int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>> + * @brief write system i/o (byte)
>>>> + * @param[in] val data to write
>>>> + * @param[in] addr address to write to
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        writeb(val, addr);
>>>> +        else
>>>> +        outb(val, (int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>> + * @brief read system i/o (word)
>>>> + * @param[in] val data to write
>>>> + * @param[in] addr address to write to
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        writew(val, addr);
>>>> +        else
>>>> +        outw(val, (int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>> + * @brief read system i/o (dword)
>>>> + * @param[in] val data to write
>>>> + * @param[in] addr address to write to
>>>> + * @param[in] mmio memory i/o space or i/o port space
>>>> + */
>>>> +static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, int mmio)
>>>> +{
>>>> +    if (mmio)
>>>> +        writel(val, addr);
>>>> +        else
>>>> +        outl(val, (int) addr);
>>>> +}
>>>> +
>>>> +/**
>>>>   * @brief read register
>>>>   *
>>>>   * @param[in] cdev pointer to console device
>>>> @@ -78,16 +160,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
>>>>
>>>>     off <<= plat->shift;
>>>>
>>>> -    if (plat->reg_read)
>>>> -        return plat->reg_read((unsigned long)dev->priv, off);
>>>> -
>>>>     switch (width) {
>>>>     case IORESOURCE_MEM_8BIT:
>>>> -        return readb(dev->priv + off);
>>>> +        return ns16550_sys_readb(dev->priv + off, priv->mmio);
>>>>     case IORESOURCE_MEM_16BIT:
>>>> -        return readw(dev->priv + off);
>>>> +        return ns16550_sys_readw(dev->priv + off, priv->mmio);
>>>>     case IORESOURCE_MEM_32BIT:
>>>> -        return readl(dev->priv + off);
>>>> +        return ns16550_sys_readl(dev->priv + off, priv->mmio);
>>>>     }
>>>>     return -1;
>>>> }
>>>> @@ -109,20 +188,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
>>>>
>>>>     off <<= plat->shift;
>>>>
>>>> -    if (plat->reg_write) {
>>>> -        plat->reg_write(val, (unsigned long)dev->priv, off);
>>>> -        return;
>>>> -    }
>>>> -
>>>>     switch (width) {
>>>>     case IORESOURCE_MEM_8BIT:
>>>> -        writeb(val & 0xff, dev->priv + off);
>>>> +        ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio);
>>>>         break;
>>>>     case IORESOURCE_MEM_16BIT:
>>>> -        writew(val & 0xffff, dev->priv + off);
>>>> +        ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio);
>>>>         break;
>>>>     case IORESOURCE_MEM_32BIT:
>>>> -        writel(val, dev->priv + off);
>>>> +        ns16550_sys_writel(val, dev->priv + off, priv->mmio);
>>>>         break;
>>>>     }
>>>> }
>>>> @@ -293,16 +367,32 @@ static int ns16550_probe(struct device_d *dev)
>>>>     struct console_device *cdev;
>>>>     struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
>>>>     struct ns16550_drvdata *devtype;
>>>> +    struct resource *res;
>>>>     int ret;
>>>>
>>>>     ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
>>>>     if (ret)
>>>>         devtype = &ns16550_drvdata;
>>>>
>>>> -    dev->priv = dev_request_mem_region(dev, 0);
>>>> -
>>>>     priv = xzalloc(sizeof(*priv));
>>>>
>>>> +    res = dev_get_resource(dev, IORESOURCE_MEM, 0);
>>>> +    priv->mmio = (res != NULL);
>>>> +    if (res)
>>>> +    {
>>>> +        res = request_iomem_region(dev_name(dev),res->start,res->end);
>>>> +    }
>>>> +    else
>>>> +    {
>>>
>>>
>>> Have you checked your patches with checkpatch.pl script?
>>>
>>>
>>>> +        res = dev_get_resource(dev, IORESOURCE_IO, 0);
>>>> +        if (res)
>>>> +            res = request_ioport_region(dev_name(dev),res->start,res->end);
>>>> +    }
>>>> +    if (!res)
>>>> +        goto err;
>>>> +    dev->priv = (void __force __iomem *) res->start;
>>>> +
>>>> +
>>>>     if (plat)
>>>>         priv->plat = *plat;
>>>>     else
>>>> diff --git a/include/driver.h b/include/driver.h
>>>> index 37797c7..ff4a5a1 100644
>>>> --- a/include/driver.h
>>>> +++ b/include/driver.h
>>>> @@ -276,7 +276,7 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
>>>>         resource_size_t size, int flags, struct NS16550_plat *pdata)
>>>> {
>>>>     return add_generic_device("ns16550_serial", id, NULL, start, size,
>>>> -                  IORESOURCE_MEM | flags, pdata);
>>>> +                  flags, pdata);
>>>> }
>>>>
>>>> #ifdef CONFIG_DRIVER_NET_DM9K
>>>> diff --git a/include/ns16550.h b/include/ns16550.h
>>>> index 36aa5ff..876bb04 100644
>>>> --- a/include/ns16550.h
>>>> +++ b/include/ns16550.h
>>>> @@ -33,18 +33,9 @@
>>>> struct NS16550_plat {
>>>>     /** Clock speed */
>>>>     unsigned int clock;
>>>> -    /**
>>>> -     * register read access capability
>>>> -     */
>>>> -    unsigned int (*reg_read) (unsigned long base, unsigned char reg_offset);
>>>> -    /**
>>>> -     * register write access capability
>>>> -     */
>>>> -    void (*reg_write) (unsigned int val, unsigned long base,
>>>> -                    unsigned char reg_offset);
>>>> -
>>>>     int shift;
>>>>     unsigned int flags;
>>>> +    int mmio;
>>> Do you really need this 'int mmio' here?
>>>
>>>> #define NS16650_FLAG_DISABLE_FIFO    1
>>>> };
>>>>
>>>> -- 
>>>> 1.7.1
>>>>
>>>>
>>>> _______________________________________________
>>>> barebox mailing list
>>>> barebox@lists.infradead.org
>>>> http://lists.infradead.org/mailman/listinfo/barebox
>>>
>>> -- 
>>> -- 
>>> Best regards,
>>>    Antony Pavlov
>



[-- Attachment #1.2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4278 bytes --]

[-- Attachment #2: Type: text/plain, Size: 149 bytes --]

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 16:52     ` Michel Stam
@ 2014-04-04 18:12       ` Antony Pavlov
  2014-04-04 18:11         ` Michel Stam
  2014-04-05 16:20         ` Sascha Hauer
  0 siblings, 2 replies; 8+ messages in thread
From: Antony Pavlov @ 2014-04-04 18:12 UTC (permalink / raw)
  To: Michel Stam; +Cc: barebox

On Fri, 4 Apr 2014 18:52:46 +0200
Michel Stam <michel@reverze.net> wrote:

> Hello Antony,
> 
> Sorry to hear that- the patch was not meant to add new functionality, merely preserve the status quo in master. 

Quite the contrary!

Your patchseries introduces new functionality, it adds additional io space.

In barebox maillist all new functionality patches are assumed to be 'next' branch patches.

Only critical bugfixes and trivial changes can go to the 'master' branch directly.

> To explain; add_ns16550_device() assumes that all ns16550 chips are mapped into memory. This is not so on the x86 platform. Previously, because no io-mapped resources were available, x86 created a "memory" device with custom IO routines. I rewrote this to use IORESOURCE_IO instead, but to do this, the invocation of the add_ns16550_device() needed to specify the resource type. The patch which conflicts with your patch can be undone as far as I'm concerned; I wasn't adding anything new to the mips/mach-xburst platform. I can redo the patch, leaving the file targeted by your patch unchanged if you like?

IMHO you have to rebase your patches over the 'next' branch.

Also please use scripts/checkpatch.pl programm before sending patches to the maillist.

> 
> > On 4 apr. 2014, at 17:56, Antony Pavlov <antonynpavlov@gmail.com> wrote:
> > 
> > On Fri,  4 Apr 2014 15:41:39 +0200
> > michel@reverze.net wrote:
> > 
> >> From: Michel Stam <m.stam@fugro.nl>
> >> 
> >> The current implementation fakes a memory-mapped I/O device
> >> at 0x3f8 and 0x2f8, then uses platform read/write functions
> >> to do the actual reading and writing. These platform functions
> >> only exist for the x86 platform; better to move the I/O
> >> routines into the driver and have the driver request I/O ports
> >> using request_ioport_region.
> >> ---
> >> arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |    2 +-
> >> arch/arm/mach-mvebu/armada-370-xp.c               |    3 +-
> >> arch/arm/mach-mvebu/kirkwood.c                    |    3 +-
> >> arch/arm/mach-socfpga/xload.c                     |    4 +-
> >> arch/arm/mach-tegra/tegra20.c                     |    2 +-
> >> arch/mips/boards/dlink-dir-320/serial.c           |    2 +-
> >> arch/mips/boards/loongson-ls1b/serial.c           |    2 +-
> >> arch/mips/mach-ar231x/ar231x.c                    |    2 +-
> >> arch/mips/mach-xburst/serial.c                    |   60 ++++++++++
> > hmmm
> > this partly revert my recent commit in the 'next' branch:
> > 
> > commit 8f5d37835d44d07460d92307f0b6489048a18fba
> > Author: Antony Pavlov <antonynpavlov@gmail.com>
> > Date:   Tue Mar 25 20:50:58 2014 +0400
> > 
> >    MIPS: mach-xburst: drop serial.c
> > 
> >    We use dts for serial port initialization,
> >    so we have no need in mach-xburst/serial.c anymore.
> > 
> >    Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
> >    Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > 
> > arch/mips/mach-xburst/Makefile |  1 -
> > arch/mips/mach-xburst/serial.c | 60 -----------------------------------------------------
> > 2 files changed, 61 deletions(-)
> > 
> >> arch/openrisc/boards/generic/generic.c            |    2 +-
> >> arch/ppc/boards/freescale-p1022ds/p1022ds.c       |    2 +-
> >> arch/ppc/boards/freescale-p2020rdb/p2020rdb.c     |    3 +-
> >> arch/ppc/boards/geip-da923rc/da923rc.c            |    3 +-
> >> arch/x86/boards/x86_generic/generic_pc.c          |    5 +-
> >> arch/x86/mach-i386/Makefile                       |    1 -
> >> arch/x86/mach-i386/generic.c                      |   34 ------
> >> drivers/serial/serial_ns16550.c                   |  122 ++++++++++++++++++---
> >> include/driver.h                                  |    2 +-
> >> include/ns16550.h                                 |   11 +--
> >> 19 files changed, 187 insertions(+), 78 deletions(-)
> >> create mode 100644 arch/mips/mach-xburst/serial.c
> >> delete mode 100644 arch/x86/mach-i386/generic.c
> >> 
> >> diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> >> index e2ad1c8..69967c5 100644
> >> --- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> >> +++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
> >> @@ -223,7 +223,7 @@ static int eukrea_cpuimx27_console_init(void)
> >>    imx27_setup_weimcs(3, 0x0000D603, 0x0D1D0D01, 0x00D20000);
> >> #ifdef CONFIG_DRIVER_SERIAL_NS16550
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, MX27_CS3_BASE_ADDR + QUART_OFFSET, 0xf,
> >> -             IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
> >> +             IORESOURCE_MEM | IORESOURCE_MEM_16BIT, &quad_uart_serial_plat);
> >> #endif
> >>    return 0;
> >> }
> >> diff --git a/arch/arm/mach-mvebu/armada-370-xp.c b/arch/arm/mach-mvebu/armada-370-xp.c
> >> index 776b4c0..209be0b 100644
> >> --- a/arch/arm/mach-mvebu/armada-370-xp.c
> >> +++ b/arch/arm/mach-mvebu/armada-370-xp.c
> >> @@ -60,7 +60,8 @@ static int armada_370_xp_add_uart(void)
> >>    uart_plat.clock = clk_get_rate(tclk);
> >>    if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
> >>                (unsigned int)CONSOLE_UART_BASE, 32,
> >> -                IORESOURCE_MEM_32BIT, &uart_plat))
> >> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> >> +                &uart_plat))
> >>        return -ENODEV;
> >>    return 0;
> >> }
> >> diff --git a/arch/arm/mach-mvebu/kirkwood.c b/arch/arm/mach-mvebu/kirkwood.c
> >> index 1284220..c79d130 100644
> >> --- a/arch/arm/mach-mvebu/kirkwood.c
> >> +++ b/arch/arm/mach-mvebu/kirkwood.c
> >> @@ -58,7 +58,8 @@ static int kirkwood_add_uart(void)
> >>    uart_plat.clock = clk_get_rate(tclk);
> >>    if (!add_ns16550_device(DEVICE_ID_DYNAMIC,
> >>                (unsigned int)CONSOLE_UART_BASE, 32,
> >> -                IORESOURCE_MEM_32BIT, &uart_plat))
> >> +                IORESOURCE_MEM | IORESOURCE_MEM_32BIT,
> >> +                &uart_plat))
> >>        return -ENODEV;
> >>    return 0;
> >> }
> >> diff --git a/arch/arm/mach-socfpga/xload.c b/arch/arm/mach-socfpga/xload.c
> >> index 0b99db0..6586ada 100644
> >> --- a/arch/arm/mach-socfpga/xload.c
> >> +++ b/arch/arm/mach-socfpga/xload.c
> >> @@ -45,8 +45,8 @@ static void socfpga_uart_init(void)
> >>    clks[uart] = clk_fixed("uart", 100000000);
> >>    clkdev_add_physbase(clks[uart], CYCLONE5_UART0_ADDRESS, NULL);
> >>    clkdev_add_physbase(clks[uart], CYCLONE5_UART1_ADDRESS, NULL);
> >> -    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM_8BIT,
> >> -            &uart_pdata);
> >> +    add_ns16550_device(0, 0xffc02000, 1024, IORESOURCE_MEM |
> >> +            IORESOURCE_MEM_8BIT, &uart_pdata);
> >> }
> >> 
> >> static void socfpga_timer_init(void)
> >> diff --git a/arch/arm/mach-tegra/tegra20.c b/arch/arm/mach-tegra/tegra20.c
> >> index cc2d748..bdd7960 100644
> >> --- a/arch/arm/mach-tegra/tegra20.c
> >> +++ b/arch/arm/mach-tegra/tegra20.c
> >> @@ -50,7 +50,7 @@ static int tegra20_add_debug_console(void)
> >>        return -ENODEV;
> >> 
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, base, 8 << debug_uart.shift,
> >> -               IORESOURCE_MEM_8BIT, &debug_uart);
> >> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &debug_uart);
> >> 
> >>    return 0;
> >> }
> >> diff --git a/arch/mips/boards/dlink-dir-320/serial.c b/arch/mips/boards/dlink-dir-320/serial.c
> >> index bddb683..eb87379 100644
> >> --- a/arch/mips/boards/dlink-dir-320/serial.c
> >> +++ b/arch/mips/boards/dlink-dir-320/serial.c
> >> @@ -36,7 +36,7 @@ static int dir320_console_init(void)
> >> 
> >>    /* Register the serial port */
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, DEBUG_LL_UART_ADDR, 8,
> >> -            IORESOURCE_MEM_8BIT, &serial_plat);
> >> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
> >> 
> >>    return 0;
> >> }
> >> diff --git a/arch/mips/boards/loongson-ls1b/serial.c b/arch/mips/boards/loongson-ls1b/serial.c
> >> index d8e0f7c..7159ab7 100644
> >> --- a/arch/mips/boards/loongson-ls1b/serial.c
> >> +++ b/arch/mips/boards/loongson-ls1b/serial.c
> >> @@ -15,7 +15,7 @@ static int console_init(void)
> >>    barebox_set_hostname("ls1b");
> >> 
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(LS1X_UART2_BASE),
> >> -        8, IORESOURCE_MEM_8BIT, &serial_plat);
> >> +        8, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
> >> 
> >>    return 0;
> >> }
> >> diff --git a/arch/mips/mach-ar231x/ar231x.c b/arch/mips/mach-ar231x/ar231x.c
> >> index ca912bf..06d2edb 100644
> >> --- a/arch/mips/mach-ar231x/ar231x.c
> >> +++ b/arch/mips/mach-ar231x/ar231x.c
> >> @@ -189,7 +189,7 @@ static int ar2312_console_init(void)
> >>    /* Register the serial port */
> >>    serial_plat.clock = ar2312_sys_frequency();
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, KSEG1ADDR(AR2312_UART0),
> >> -        8 << AR2312_UART_SHIFT, IORESOURCE_MEM_8BIT, &serial_plat);
> >> +        8 << AR2312_UART_SHIFT, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
> >>    return 0;
> >> }
> >> console_initcall(ar2312_console_init);
> >> diff --git a/arch/mips/mach-xburst/serial.c b/arch/mips/mach-xburst/serial.c
> >> new file mode 100644
> >> index 0000000..4365d19
> >> --- /dev/null
> >> +++ b/arch/mips/mach-xburst/serial.c
> >> @@ -0,0 +1,60 @@
> >> +/*
> >> + * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
> >> + *
> >> + * Based on the linux kernel JZ4740 serial support:
> >> + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
> >> + *
> >> + * This file is part of barebox.
> >> + * See file CREDITS for list of people who contributed to this project.
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License version 2
> >> + * as published by the Free Software Foundation.
> >> + *
> >> + * This program 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.
> >> + *
> >> + */
> >> +
> >> +#include <common.h>
> >> +#include <ns16550.h>
> >> +#include <io.h>
> >> +#include <mach/devices.h>
> >> +
> >> +#define JZ_UART_SHIFT    2
> >> +
> >> +#define ier        (1 << JZ_UART_SHIFT)
> >> +#define fcr        (2 << JZ_UART_SHIFT)
> >> +
> >> +static void jz_serial_reg_write(unsigned int val, unsigned long base,
> >> +    unsigned char reg_offset)
> >> +{
> >> +    switch (reg_offset) {
> >> +    case fcr:
> >> +        val |= 0x10; /* Enable uart module */
> >> +        break;
> >> +    case ier:
> >> +        val |= (val & 0x4) << 2;
> >> +        break;
> >> +    default:
> >> +        break;
> >> +    }
> >> +
> >> +    writeb(val & 0xff, (void *)(base + reg_offset));
> >> +}
> >> +
> >> +struct device_d *jz_add_uart(int id, unsigned long base, unsigned int clock)
> >> +{
> >> +    struct NS16550_plat *serial_plat;
> >> +
> >> +    serial_plat = xzalloc(sizeof(*serial_plat));
> >> +
> >> +    serial_plat->shift = JZ_UART_SHIFT;
> >> +    serial_plat->reg_write = &jz_serial_reg_write;
> >> +    serial_plat->clock = clock;
> >> +
> >> +    return add_ns16550_device(id, base, 8 << JZ_UART_SHIFT,
> >> +            IORESOURCE_MEM | IORESOURCE_MEM_8BIT, serial_plat);
> >> +}
> >> diff --git a/arch/openrisc/boards/generic/generic.c b/arch/openrisc/boards/generic/generic.c
> >> index 290e05c..1d6ac8a 100644
> >> --- a/arch/openrisc/boards/generic/generic.c
> >> +++ b/arch/openrisc/boards/generic/generic.c
> >> @@ -15,7 +15,7 @@ static int openrisc_console_init(void)
> >>    barebox_set_hostname("or1k");
> >> 
> >>    /* Register the serial port */
> >> -    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM_8BIT, &serial_plat);
> >> +    add_ns16550_device(DEVICE_ID_DYNAMIC, OPENRISC_SOPC_UART_BASE, 1024, IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
> >> 
> >> #ifdef CONFIG_DRIVER_NET_ETHOC
> >>    add_generic_device("ethoc", DEVICE_ID_DYNAMIC, NULL,
> >> diff --git a/arch/ppc/boards/freescale-p1022ds/p1022ds.c b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> >> index c800064..57e7953 100644
> >> --- a/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> >> +++ b/arch/ppc/boards/freescale-p1022ds/p1022ds.c
> >> @@ -130,7 +130,7 @@ static int p1022ds_console_init(void)
> >> 
> >>    serial_plat.clock = fsl_get_bus_freq(0);
> >>    add_ns16550_device(DEVICE_ID_DYNAMIC, CFG_IMMR + 0x4500, 16,
> >> -               IORESOURCE_MEM_8BIT, &serial_plat);
> >> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT, &serial_plat);
> >>    return 0;
> >> }
> >> 
> >> diff --git a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> >> index 229ae41..385a436 100644
> >> --- a/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> >> +++ b/arch/ppc/boards/freescale-p2020rdb/p2020rdb.c
> >> @@ -112,7 +112,8 @@ static int p2020_console_init(void)
> >> 
> >>    serial_plat.clock = fsl_get_bus_freq(0);
> >> 
> >> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16, IORESOURCE_MEM_8BIT,
> >> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0xffe04500, 16,
> >> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
> >>               &serial_plat);
> >>    return 0;
> >> }
> >> diff --git a/arch/ppc/boards/geip-da923rc/da923rc.c b/arch/ppc/boards/geip-da923rc/da923rc.c
> >> index 976aa8d..3d77349 100644
> >> --- a/arch/ppc/boards/geip-da923rc/da923rc.c
> >> +++ b/arch/ppc/boards/geip-da923rc/da923rc.c
> >> @@ -115,7 +115,8 @@ static int da923rc_console_init(void)
> >>        barebox_set_model("unknown");
> >> 
> >>    serial_plat.clock = fsl_get_bus_freq(0);
> >> -    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16, IORESOURCE_MEM_8BIT,
> >> +    add_ns16550_device(1, CFG_CCSRBAR + 0x4600, 16,
> >> +               IORESOURCE_MEM | IORESOURCE_MEM_8BIT,
> >>               &serial_plat);
> >>    return 0;
> >> }
> >> diff --git a/arch/x86/boards/x86_generic/generic_pc.c b/arch/x86/boards/x86_generic/generic_pc.c
> >> index 895b88d..69c6f58 100644
> >> --- a/arch/x86/boards/x86_generic/generic_pc.c
> >> +++ b/arch/x86/boards/x86_generic/generic_pc.c
> >> @@ -141,8 +141,6 @@ device_initcall(devices_init);
> >> 
> >> static struct NS16550_plat serial_plat = {
> >>        .clock = 1843200,
> >> -       .reg_read = x86_uart_read,
> >> -       .reg_write = x86_uart_write,
> >> };
> >> 
> >> static int pc_console_init(void)
> >> @@ -151,7 +149,8 @@ static int pc_console_init(void)
> >>    barebox_set_hostname("x86");
> >> 
> >>    /* Register the serial port */
> >> -    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, 0, &serial_plat);
> >> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x3f8, 8, IORESOURCE_IO, &serial_plat);
> >> +    add_ns16550_device(DEVICE_ID_DYNAMIC, 0x2f8, 8, IORESOURCE_IO, &serial_plat);
> >> 
> >>    return 0;
> >> }
> >> diff --git a/arch/x86/mach-i386/Makefile b/arch/x86/mach-i386/Makefile
> >> index 10712e6..e46aa5b 100644
> >> --- a/arch/x86/mach-i386/Makefile
> >> +++ b/arch/x86/mach-i386/Makefile
> >> @@ -1,4 +1,3 @@
> >> -obj-y += generic.o
> >> obj-y += reset.o
> >> 
> >> # reference clocksource
> >> diff --git a/arch/x86/mach-i386/generic.c b/arch/x86/mach-i386/generic.c
> >> deleted file mode 100644
> >> index 69cf53c..0000000
> >> --- a/arch/x86/mach-i386/generic.c
> >> +++ /dev/null
> >> @@ -1,34 +0,0 @@
> >> -/*
> >> - * Copyright (C) 2009 Juergen Beisert, Pengutronix
> >> - *
> >> - * This program 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.
> >> - *
> >> - * This program 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.
> >> - *
> >> - *
> >> - */
> >> -
> >> -/**
> >> - * @file
> >> - * @brief x86 Architecture Initialization routines
> >> - */
> >> -
> >> -#include <io.h>
> >> -
> >> -/** to work with the 8250 UART driver implementation we need this function */
> >> -unsigned int x86_uart_read(unsigned long base, unsigned char reg_idx)
> >> -{
> >> -    return inb(base + reg_idx);
> >> -}
> >> -
> >> -/** to work with the 8250 UART driver implementation we need this function */
> >> -void x86_uart_write(unsigned int val, unsigned long base, unsigned char reg_idx)
> >> -{
> >> -    outb(val, base + reg_idx);
> >> -}
> >> diff --git a/drivers/serial/serial_ns16550.c b/drivers/serial/serial_ns16550.c
> >> index 0c00eb1..dfe572d 100644
> >> --- a/drivers/serial/serial_ns16550.c
> >> +++ b/drivers/serial/serial_ns16550.c
> >> @@ -47,6 +47,7 @@ struct ns16550_priv {
> >>    struct console_device cdev;
> >>    struct NS16550_plat plat;
> >>    int access_width;
> >> +    int mmio;
> >>    struct clk *clk;
> >>    uint32_t fcrval;
> >> };
> >> @@ -62,6 +63,87 @@ struct ns16550_drvdata {
> >> };
> >> 
> >> /**
> >> + * @brief read system i/o (byte)
> >> + * @param[in] addr address to read
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline uint8_t ns16550_sys_readb(void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        return readb(addr);
> >> +        else
> >> +        return (uint8_t) inb((int) addr);
> >> +}
> >> +
> >> +/**
> >> + * @brief read system i/o (word)
> >> + * @param[in] addr address to read
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline uint16_t ns16550_sys_readw(void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        return readw(addr);
> >> +        else
> >> +        return (uint16_t) inw((int) addr);
> >> +}
> >> +
> >> +/**
> >> + * @brief read system i/o (dword)
> >> + * @param[in] addr address to read
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline uint32_t ns16550_sys_readl(void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        return readl(addr);
> >> +        else
> >> +        return (uint32_t) inl((int) addr);
> >> +}
> >> +
> >> +/**
> >> + * @brief write system i/o (byte)
> >> + * @param[in] val data to write
> >> + * @param[in] addr address to write to
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline void ns16550_sys_writeb(uint8_t val, void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        writeb(val, addr);
> >> +        else
> >> +        outb(val, (int) addr);
> >> +}
> >> +
> >> +/**
> >> + * @brief read system i/o (word)
> >> + * @param[in] val data to write
> >> + * @param[in] addr address to write to
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline void ns16550_sys_writew(uint16_t val, void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        writew(val, addr);
> >> +        else
> >> +        outw(val, (int) addr);
> >> +}
> >> +
> >> +/**
> >> + * @brief read system i/o (dword)
> >> + * @param[in] val data to write
> >> + * @param[in] addr address to write to
> >> + * @param[in] mmio memory i/o space or i/o port space
> >> + */
> >> +static inline void ns16550_sys_writel(uint32_t val, void __iomem *addr, int mmio)
> >> +{
> >> +    if (mmio)
> >> +        writel(val, addr);
> >> +        else
> >> +        outl(val, (int) addr);
> >> +}
> >> +
> >> +/**
> >>  * @brief read register
> >>  *
> >>  * @param[in] cdev pointer to console device
> >> @@ -78,16 +160,13 @@ static uint32_t ns16550_read(struct console_device *cdev, uint32_t off)
> >> 
> >>    off <<= plat->shift;
> >> 
> >> -    if (plat->reg_read)
> >> -        return plat->reg_read((unsigned long)dev->priv, off);
> >> -
> >>    switch (width) {
> >>    case IORESOURCE_MEM_8BIT:
> >> -        return readb(dev->priv + off);
> >> +        return ns16550_sys_readb(dev->priv + off, priv->mmio);
> >>    case IORESOURCE_MEM_16BIT:
> >> -        return readw(dev->priv + off);
> >> +        return ns16550_sys_readw(dev->priv + off, priv->mmio);
> >>    case IORESOURCE_MEM_32BIT:
> >> -        return readl(dev->priv + off);
> >> +        return ns16550_sys_readl(dev->priv + off, priv->mmio);
> >>    }
> >>    return -1;
> >> }
> >> @@ -109,20 +188,15 @@ static void ns16550_write(struct console_device *cdev, uint32_t val,
> >> 
> >>    off <<= plat->shift;
> >> 
> >> -    if (plat->reg_write) {
> >> -        plat->reg_write(val, (unsigned long)dev->priv, off);
> >> -        return;
> >> -    }
> >> -
> >>    switch (width) {
> >>    case IORESOURCE_MEM_8BIT:
> >> -        writeb(val & 0xff, dev->priv + off);
> >> +        ns16550_sys_writeb(val & 0xff, dev->priv + off, priv->mmio);
> >>        break;
> >>    case IORESOURCE_MEM_16BIT:
> >> -        writew(val & 0xffff, dev->priv + off);
> >> +        ns16550_sys_writew(val & 0xffff, dev->priv + off, priv->mmio);
> >>        break;
> >>    case IORESOURCE_MEM_32BIT:
> >> -        writel(val, dev->priv + off);
> >> +        ns16550_sys_writel(val, dev->priv + off, priv->mmio);
> >>        break;
> >>    }
> >> }
> >> @@ -293,16 +367,32 @@ static int ns16550_probe(struct device_d *dev)
> >>    struct console_device *cdev;
> >>    struct NS16550_plat *plat = (struct NS16550_plat *)dev->platform_data;
> >>    struct ns16550_drvdata *devtype;
> >> +    struct resource *res;
> >>    int ret;
> >> 
> >>    ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
> >>    if (ret)
> >>        devtype = &ns16550_drvdata;
> >> 
> >> -    dev->priv = dev_request_mem_region(dev, 0);
> >> -
> >>    priv = xzalloc(sizeof(*priv));
> >> 
> >> +    res = dev_get_resource(dev, IORESOURCE_MEM, 0);
> >> +    priv->mmio = (res != NULL);
> >> +    if (res)
> >> +    {
> >> +        res = request_iomem_region(dev_name(dev),res->start,res->end);
> >> +    }
> >> +    else
> >> +    {
> > 
> > 
> > 
> > Have you checked your patches with checkpatch.pl script?
> > 
> > 
> >> +        res = dev_get_resource(dev, IORESOURCE_IO, 0);
> >> +        if (res)
> >> +            res = request_ioport_region(dev_name(dev),res->start,res->end);
> >> +    }
> >> +    if (!res)
> >> +        goto err;
> >> +    dev->priv = (void __force __iomem *) res->start;
> >> +
> >> +
> >>    if (plat)
> >>        priv->plat = *plat;
> >>    else
> >> diff --git a/include/driver.h b/include/driver.h
> >> index 37797c7..ff4a5a1 100644
> >> --- a/include/driver.h
> >> +++ b/include/driver.h
> >> @@ -276,7 +276,7 @@ static inline struct device_d *add_ns16550_device(int id, resource_size_t start,
> >>        resource_size_t size, int flags, struct NS16550_plat *pdata)
> >> {
> >>    return add_generic_device("ns16550_serial", id, NULL, start, size,
> >> -                  IORESOURCE_MEM | flags, pdata);
> >> +                  flags, pdata);
> >> }
> >> 
> >> #ifdef CONFIG_DRIVER_NET_DM9K
> >> diff --git a/include/ns16550.h b/include/ns16550.h
> >> index 36aa5ff..876bb04 100644
> >> --- a/include/ns16550.h
> >> +++ b/include/ns16550.h
> >> @@ -33,18 +33,9 @@
> >> struct NS16550_plat {
> >>    /** Clock speed */
> >>    unsigned int clock;
> >> -    /**
> >> -     * register read access capability
> >> -     */
> >> -    unsigned int (*reg_read) (unsigned long base, unsigned char reg_offset);
> >> -    /**
> >> -     * register write access capability
> >> -     */
> >> -    void (*reg_write) (unsigned int val, unsigned long base,
> >> -                    unsigned char reg_offset);
> >> -
> >>    int shift;
> >>    unsigned int flags;
> >> +    int mmio;
> > 
> > Do you really need this 'int mmio' here?
> > 
> >> #define NS16650_FLAG_DISABLE_FIFO    1
> >> };
> >> 
> >> -- 
> >> 1.7.1
> >> 
> >> 
> >> _______________________________________________
> >> barebox mailing list
> >> barebox@lists.infradead.org
> >> http://lists.infradead.org/mailman/listinfo/barebox
> > 
> > 
> > -- 
> > -- 
> > Best regards,
> >   Antony Pavlov


-- 
-- 
Best regards,
  Antony Pavlov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space
  2014-04-04 18:12       ` Antony Pavlov
  2014-04-04 18:11         ` Michel Stam
@ 2014-04-05 16:20         ` Sascha Hauer
  1 sibling, 0 replies; 8+ messages in thread
From: Sascha Hauer @ 2014-04-05 16:20 UTC (permalink / raw)
  To: Antony Pavlov; +Cc: barebox

On Fri, Apr 04, 2014 at 10:12:40PM +0400, Antony Pavlov wrote:
> On Fri, 4 Apr 2014 18:52:46 +0200
> Michel Stam <michel@reverze.net> wrote:
> 
> > Hello Antony,
> > 
> > Sorry to hear that- the patch was not meant to add new functionality, merely preserve the status quo in master. 
> 
> Quite the contrary!
> 
> Your patchseries introduces new functionality, it adds additional io space.
> 
> In barebox maillist all new functionality patches are assumed to be 'next' branch patches.
> 
> Only critical bugfixes and trivial changes can go to the 'master' branch directly.
> 
> > To explain; add_ns16550_device() assumes that all ns16550 chips are mapped into memory. This is not so on the x86 platform. Previously, because no io-mapped resources were available, x86 created a "memory" device with custom IO routines. I rewrote this to use IORESOURCE_IO instead, but to do this, the invocation of the add_ns16550_device() needed to specify the resource type. The patch which conflicts with your patch can be undone as far as I'm concerned; I wasn't adding anything new to the mips/mach-xburst platform. I can redo the patch, leaving the file targeted by your patch unchanged if you like?
> 
> IMHO you have to rebase your patches over the 'next' branch.

No, please base your patches on master. I'll resolve the merge conflicts
if necessary while merging the different for-next branches. Should there
be non-trivial conflicts it may happen that I explicitly ask you to base
your work on -next.

Right now the -next branch is empty, so this doesn't make a difference
at the moment.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2014-04-05 16:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-04 13:41 [PATCH 1/3] common: Allow for I/O mapped I/O michel
2014-04-04 13:41 ` [PATCH 2/3] x86: Add support for IDE on the legacy I/O ports michel
2014-04-04 13:41 ` [PATCH 3/3] x86: ns16550: Rework driver to allow for x86 I/O space michel
2014-04-04 15:56   ` Antony Pavlov
2014-04-04 16:52     ` Michel Stam
2014-04-04 18:12       ` Antony Pavlov
2014-04-04 18:11         ` Michel Stam
2014-04-05 16:20         ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox