mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/6] drivers/bus: move to drivers/base
@ 2011-07-22 15:38 Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 2/6] drivers: move resource generic management to driver/base/resource.c Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/Makefile                     |    1 +
 drivers/base/Makefile                |    2 ++
 {lib => drivers/base}/driver.c       |    0
 lib/bus.c => drivers/base/platform.c |    0
 lib/Makefile                         |    2 --
 5 files changed, 3 insertions(+), 2 deletions(-)
 create mode 100644 drivers/base/Makefile
 rename {lib => drivers/base}/driver.c (100%)
 rename lib/bus.c => drivers/base/platform.c (100%)

diff --git a/drivers/Makefile b/drivers/Makefile
index 92b22bd..16b3bb1 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -1,3 +1,4 @@
+obj-y	+= base/
 obj-y	+= net/
 obj-y	+= serial/
 obj-y	+= mtd/
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
new file mode 100644
index 0000000..2d94723
--- /dev/null
+++ b/drivers/base/Makefile
@@ -0,0 +1,2 @@
+obj-y	+= driver.o
+obj-y	+= platform.o
diff --git a/lib/driver.c b/drivers/base/driver.c
similarity index 100%
rename from lib/driver.c
rename to drivers/base/driver.c
diff --git a/lib/bus.c b/drivers/base/platform.c
similarity index 100%
rename from lib/bus.c
rename to drivers/base/platform.c
diff --git a/lib/Makefile b/lib/Makefile
index 8b986d2..d96cfe7 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -5,8 +5,6 @@ obj-y			+= string.o
 obj-y			+= vsprintf.o
 obj-y			+= div64.o
 obj-y			+= misc.o
-obj-y			+= driver.o
-obj-y			+= bus.o
 obj-y			+= parameter.o
 obj-y			+= xfuncs.o
 obj-y			+= getopt.o
-- 
1.7.5.4


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

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

* [PATCH 2/6] drivers: move resource generic management to driver/base/resource.c
  2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-22 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 3/6] resource: introduce add_generic_device to register simple device Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/Makefile                         |    1 -
 drivers/base/Makefile                   |    1 +
 common/mem.c => drivers/base/resource.c |    0
 3 files changed, 1 insertions(+), 1 deletions(-)
 rename common/mem.c => drivers/base/resource.c (100%)

diff --git a/common/Makefile b/common/Makefile
index 27aebae..9fed2ae 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -9,7 +9,6 @@ obj-$(CONFIG_POLLER)		+= poller.o
 obj-$(CONFIG_BLOCK)		+= block.o
 
 obj-y += memory.o
-obj-y += mem.o
 obj-$(CONFIG_MALLOC_DLMALLOC) += dlmalloc.o
 obj-$(CONFIG_MALLOC_DUMMY) += dummy_malloc.o
 obj-y += clock.o
diff --git a/drivers/base/Makefile b/drivers/base/Makefile
index 2d94723..957ca5a 100644
--- a/drivers/base/Makefile
+++ b/drivers/base/Makefile
@@ -1,2 +1,3 @@
 obj-y	+= driver.o
 obj-y	+= platform.o
+obj-y	+= resource.o
diff --git a/common/mem.c b/drivers/base/resource.c
similarity index 100%
rename from common/mem.c
rename to drivers/base/resource.c
-- 
1.7.5.4


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

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

* [PATCH 3/6] resource: introduce add_generic_device to register simple device
  2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 2/6] drivers: move resource generic management to driver/base/resource.c Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-22 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 4/6] at91: switch to add_generic_device Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/base/resource.c |   16 ++++++++++------
 include/driver.h        |   16 ++++++++++++++--
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/base/resource.c b/drivers/base/resource.c
index 7b0020b..f0450d3 100644
--- a/drivers/base/resource.c
+++ b/drivers/base/resource.c
@@ -25,22 +25,26 @@
 #include <driver.h>
 #include <xfuncs.h>
 
-struct device_d *add_mem_device(const char *name, resource_size_t start,
-		resource_size_t size, unsigned int flags)
+struct device_d *add_generic_device(const char* devname, int id, const char *resname,
+		resource_size_t start, resource_size_t size, unsigned int flags,
+		void *pdata)
 {
 	struct device_d *dev;
 
 	dev = xzalloc(sizeof(*dev));
-	strcpy(dev->name, "mem");
-	dev->id = -1;
+	strcpy(dev->name, devname);
+	dev->id = id;
 	dev->resource = xzalloc(sizeof(struct resource));
 	dev->num_resources = 1;
-	dev->resource[0].name = xstrdup(name);
+	if (resname)
+		dev->resource[0].name = xstrdup(resname);
 	dev->resource[0].start = start;
 	dev->resource[0].size = size;
-	dev->resource[0].flags = IORESOURCE_MEM | flags;
+	dev->resource[0].flags = flags;
+	dev->platform_data = pdata;
 
 	register_device(dev);
 
 	return dev;
 }
+EXPORT_SYMBOL(add_generic_device);
diff --git a/include/driver.h b/include/driver.h
index 11c42fe..738cfae 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -203,10 +203,22 @@ static inline void __iomem *dev_request_mem_region(struct device_d *dev, int num
 }
 
 /*
+ * register a generic device
+ * with only one resource
+ */
+struct device_d *add_generic_device(const char* devname, int id, const char *resname,
+		resource_size_t start, resource_size_t size, unsigned int flags,
+		void *pdata);
+
+/*
  * register a memory device
  */
-struct device_d *add_mem_device(const char *name, resource_size_t start,
-		resource_size_t size, unsigned int flags);
+static inline struct device_d *add_mem_device(const char *name, resource_size_t start,
+		resource_size_t size, unsigned int flags)
+{
+	return add_generic_device("mem", -1, name, start, size,
+				  IORESOURCE_MEM | flags, NULL);
+}
 
 /* linear list over all available devices
  */
-- 
1.7.5.4


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

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

* [PATCH 4/6] at91: switch to add_generic_device
  2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 2/6] drivers: move resource generic management to driver/base/resource.c Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 3/6] resource: introduce add_generic_device to register simple device Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-22 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 5/6] imx/devices: " Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 6/6] resource: introduce add_cfi_device to register simple cfi device Jean-Christophe PLAGNIOL-VILLARD
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/at91rm9200ek/init.c      |   18 +--
 arch/arm/boards/at91sam9263ek/init.c     |   18 +---
 arch/arm/boards/mmccpu/init.c            |   17 +--
 arch/arm/boards/pm9261/init.c            |   11 +--
 arch/arm/boards/pm9263/init.c            |   18 +---
 arch/arm/mach-at91/at91rm9200_devices.c  |  144 ++++-----------------
 arch/arm/mach-at91/at91sam9260_devices.c |  209 ++++++------------------------
 arch/arm/mach-at91/at91sam9261_devices.c |  130 ++++---------------
 arch/arm/mach-at91/at91sam9263_devices.c |  177 +++++--------------------
 arch/arm/mach-at91/at91sam9g45_devices.c |  199 ++++++-----------------------
 10 files changed, 178 insertions(+), 763 deletions(-)

diff --git a/arch/arm/boards/at91rm9200ek/init.c b/arch/arm/boards/at91rm9200ek/init.c
index 2b16980..3ef41a2 100644
--- a/arch/arm/boards/at91rm9200ek/init.c
+++ b/arch/arm/boards/at91rm9200ek/init.c
@@ -34,20 +34,6 @@
 #include <mach/gpio.h>
 #include <mach/io.h>
 
-static struct resource cfi_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_0,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d cfi_dev = {
-	.id		= 0,
-	.name		= "cfi_flash",
-	.num_resources	= ARRAY_SIZE(cfi_resources),
-	.resource	= cfi_resources,
-};
-
 static struct at91_ether_platform_data ether_pdata = {
 	.flags = AT91SAM_ETHER_RMII,
 	.phy_addr = 0,
@@ -63,7 +49,9 @@ static int at91rm9200ek_devices_init(void)
 
 	at91_add_device_sdram(64 * 1024 * 1024);
 	at91_add_device_eth(&ether_pdata);
-	register_device(&cfi_dev);
+
+	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 0,
+			   IORESOURCE_MEM, NULL);
 
 #if defined(CONFIG_DRIVER_CFI) || defined(CONFIG_DRIVER_CFI_OLD)
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
diff --git a/arch/arm/boards/at91sam9263ek/init.c b/arch/arm/boards/at91sam9263ek/init.c
index af8a1e1..655d46a 100644
--- a/arch/arm/boards/at91sam9263ek/init.c
+++ b/arch/arm/boards/at91sam9263ek/init.c
@@ -87,21 +87,6 @@ static void ek_add_device_nand(void)
 	at91_add_device_nand(&nand_pdata);
 }
 
-static struct resource cfi_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_0,
-		.size	= 8 * 1024 * 1024,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d cfi_dev = {
-	.id		= -1,
-	.name		= "cfi_flash",
-	.num_resources	= ARRAY_SIZE(cfi_resources),
-	.resource	= cfi_resources,
-};
-
 static struct at91_ether_platform_data macb_pdata = {
 	.flags = AT91SAM_ETHER_RMII,
 	.phy_addr = 0,
@@ -135,7 +120,8 @@ static int at91sam9263ek_devices_init(void)
 	at91_add_device_sdram(64 * 1024 * 1024);
 	ek_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
-	register_device(&cfi_dev);
+	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 8 * 1024 * 1024,
+			   IORESOURCE_MEM, NULL);
 	ek_add_device_mci();
 
 #if defined(CONFIG_DRIVER_CFI) || defined(CONFIG_DRIVER_CFI_OLD)
diff --git a/arch/arm/boards/mmccpu/init.c b/arch/arm/boards/mmccpu/init.c
index 8cc5f2c..85a18e0 100644
--- a/arch/arm/boards/mmccpu/init.c
+++ b/arch/arm/boards/mmccpu/init.c
@@ -37,20 +37,6 @@
 #include <mach/gpio.h>
 #include <mach/io.h>
 
-static struct resource cfi_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_0,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d cfi_dev = {
-	.id		= -1,
-	.name		= "cfi_flash",
-	.num_resources	= ARRAY_SIZE(cfi_resources),
-	.resource	= cfi_resources,
-};
-
 static struct at91_ether_platform_data macb_pdata = {
 	.flags		= AT91SAM_ETHER_MII | AT91SAM_ETHER_FORCE_LINK,
 	.phy_addr	= 4,
@@ -68,7 +54,8 @@ static int mmccpu_devices_init(void)
 
 	at91_add_device_sdram(128 * 1024 * 1024);
 	at91_add_device_eth(&macb_pdata);
-	register_device(&cfi_dev);
+	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 0,
+			   IORESOURCE_MEM, NULL);
 
 	devfs_add_partition("nor0", 0x00000, 256 * 1024, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x40000, 128 * 1024, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/pm9261/init.c b/arch/arm/boards/pm9261/init.c
index ad4fa9d..38e4350 100644
--- a/arch/arm/boards/pm9261/init.c
+++ b/arch/arm/boards/pm9261/init.c
@@ -147,19 +147,12 @@ static void __init pm_add_device_dm9000(void)
 static void __init ek_add_device_dm9000(void) {}
 #endif /* CONFIG_DRIVER_NET_DM9000 */
 
-static struct device_d cfi_dev = {
-	.id		= 0,
-	.name		= "cfi_flash",
-	.map_base	= AT91_CHIPSELECT_0,
-	.size		= 4 * 1024 * 1024,
-};
-
 static int pm9261_devices_init(void)
 {
 	at91_add_device_sdram(64 * 1024 * 1024);
 	pm_add_device_nand();
-	register_device(&cfi_dev);
-	pm_add_device_dm9000();
+	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 4 * 1024 * 1024,
+			   IORESOURCE_MEM, NULL);
 
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
 	devfs_add_partition("nor0", 0x40000, 0x10000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/pm9263/init.c b/arch/arm/boards/pm9263/init.c
index e21e8e3..9f86d67 100644
--- a/arch/arm/boards/pm9263/init.c
+++ b/arch/arm/boards/pm9263/init.c
@@ -86,21 +86,6 @@ static void pm_add_device_nand(void)
 	at91_add_device_nand(&nand_pdata);
 }
 
-static struct resource cfi_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_0,
-		.size	= 4 * 1024 * 1024,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.num_resources	= ARRAY_SIZE(cfi_resources),
-	.resource	= cfi_resources,
-};
-
 static struct at91_ether_platform_data macb_pdata = {
 	.flags = AT91SAM_ETHER_RMII,
 	.phy_addr = 0,
@@ -119,7 +104,8 @@ static int pm9263_devices_init(void)
 	at91_add_device_sdram(64 * 1024 * 1024);
 	pm_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
-	register_device(&cfi_dev);
+	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 4 * 1024 * 1024,
+			   IORESOURCE_MEM, NULL);
 
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x40000, 0x10000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/mach-at91/at91rm9200_devices.c b/arch/arm/mach-at91/at91rm9200_devices.c
index 16c94a6..289f2c3 100644
--- a/arch/arm/mach-at91/at91rm9200_devices.c
+++ b/arch/arm/mach-at91/at91rm9200_devices.c
@@ -34,21 +34,6 @@ void at91_add_device_sdram(u32 size)
  * -------------------------------------------------------------------- */
 
 #if defined(CONFIG_DRIVER_NET_AT91_ETHER)
-static struct resource eth_resources[] = {
-	[0] = {
-		.start	= AT91_VA_BASE_EMAC,
-		.size	= 0x1000,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d at91rm9200_eth_device = {
-	.id		= 0,
-	.name		= "at91_ether",
-	.resource	= eth_resources,
-	.num_resources	= ARRAY_SIZE(eth_resources),
-};
-
 void __init at91_add_device_eth(struct at91_ether_platform_data *data)
 {
 	if (!data)
@@ -77,8 +62,8 @@ void __init at91_add_device_eth(struct at91_ether_platform_data *data)
 		at91_set_B_periph(AT91_PIN_PB12, 0);	/* ETX2 */
 	}
 
-	at91rm9200_eth_device.platform_data = data;
-	register_device(&at91rm9200_eth_device);
+	add_generic_device("at91_ether", 0, NULL, AT91_VA_BASE_EMAC, 0x1000,
+			   IORESOURCE_MEM, data);
 }
 #else
 void __init at91_add_device_eth(struct at91_ether_platform_data *data) {}
@@ -89,21 +74,6 @@ void __init at91_add_device_eth(struct at91_ether_platform_data *data) {}
  * -------------------------------------------------------------------- */
 
 #if defined(CONFIG_NAND_ATMEL)
-static struct resource nand_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_3,
-		.size	= 0x10,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d at91rm9200_nand_device = {
-	.id		= -1,
-	.name		= "atmel_nand",
-	.resource	= nand_resources,
-	.num_resources	= ARRAY_SIZE(nand_resources),
-};
-
 void __init at91_add_device_nand(struct atmel_nand_data *data)
 {
 	unsigned int csa;
@@ -138,8 +108,8 @@ void __init at91_add_device_nand(struct atmel_nand_data *data)
 	at91_set_A_periph(AT91_PIN_PC1, 0);		/* SMOE */
 	at91_set_A_periph(AT91_PIN_PC3, 0);		/* SMWE */
 
-	at91rm9200_nand_device.platform_data = data;
-	platform_device_register(&at91rm9200_nand_device);
+	add_generic_device("atmel_nand", 0, NULL, AT91_CHIPSELECT_3, 0x10,
+			   IORESOURCE_MEM, data);
 }
 #else
 void __init at91_add_device_nand(struct atmel_nand_data *data) {}
@@ -149,42 +119,12 @@ void __init at91_add_device_nand(struct atmel_nand_data *data) {}
  *  UART
  * -------------------------------------------------------------------- */
 
-static struct resource dbgu_resources[] = {
-	[0] = {
-		.start	= AT91_BASE_SYS + AT91_DBGU,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d dbgu_serial_device = {
-	.id		= 0,
-	.name		= "atmel_serial",
-	.resource	= dbgu_resources,
-	.num_resources	= ARRAY_SIZE(dbgu_resources),
-};
-
 static inline void configure_dbgu_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PA30, 0);		/* DRXD */
 	at91_set_A_periph(AT91_PIN_PA31, 1);		/* DTXD */
 }
 
-static struct resource uart0_resources[] = {
-	[0] = {
-		.start	= AT91RM9200_BASE_US0,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart0_serial_device = {
-	.id		= 1,
-	.name		= "atmel_serial",
-	.resource	= uart0_resources,
-	.num_resources	= ARRAY_SIZE(uart0_resources),
-};
-
 static inline void configure_usart0_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PA17, 1);		/* TXD0 */
@@ -202,21 +142,6 @@ static inline void configure_usart0_pins(unsigned pins)
 	}
 }
 
-static struct resource uart1_resources[] = {
-	[0] = {
-		.start	= AT91RM9200_BASE_US1,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart1_serial_device = {
-	.id		= 2,
-	.name		= "atmel_serial",
-	.resource	= uart1_resources,
-	.num_resources	= ARRAY_SIZE(uart1_resources),
-};
-
 static inline void configure_usart1_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB20, 1);		/* TXD1 */
@@ -236,21 +161,6 @@ static inline void configure_usart1_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PB26, 0);	/* RTS1 */
 }
 
-static struct resource uart2_resources[] = {
-	[0] = {
-		.start	= AT91RM9200_BASE_US2,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart2_serial_device = {
-	.id		= 3,
-	.name		= "atmel_serial",
-	.resource	= uart2_resources,
-	.num_resources	= ARRAY_SIZE(uart2_resources),
-};
-
 static inline void configure_usart2_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PA22, 0);		/* RXD2 */
@@ -262,21 +172,6 @@ static inline void configure_usart2_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PA31, 0);	/* RTS2 */
 }
 
-static struct resource uart3_resources[] = {
-	[0] = {
-		.start	= AT91RM9200_BASE_US3,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart3_serial_device = {
-	.id		= 4,
-	.name		= "atmel_serial",
-	.resource	= uart3_resources,
-	.num_resources	= ARRAY_SIZE(uart3_resources),
-};
-
 static inline void configure_usart3_pins(unsigned pins)
 {
 	at91_set_B_periph(AT91_PIN_PA5, 1);		/* TXD3 */
@@ -290,33 +185,46 @@ static inline void configure_usart3_pins(unsigned pins)
 
 void __init at91_register_uart(unsigned id, unsigned pins)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	switch (id) {
 		case 0:		/* DBGU */
 			configure_dbgu_pins();
-			at91_clock_associate("mck", &dbgu_serial_device, "usart");
-			register_device(&dbgu_serial_device);
+			start = AT91_BASE_SYS + AT91_DBGU;
+			clk_name = "mck";
+			id = 0;
 			break;
 		case AT91RM9200_ID_US0:
 			configure_usart0_pins(pins);
-			at91_clock_associate("usart0_clk", &uart0_serial_device, "usart");
+			clk_name = "usart0_clk";
+			start = AT91RM9200_BASE_US0;
+			id = 1;
 			break;
 		case AT91RM9200_ID_US1:
 			configure_usart1_pins(pins);
-			at91_clock_associate("usart1_clk", &uart1_serial_device, "usart");
-			register_device(&uart1_serial_device);
+			clk_name = "usart1_clk";
+			start = AT91RM9200_BASE_US1;
+			id = 2;
 			break;
 		case AT91RM9200_ID_US2:
 			configure_usart2_pins(pins);
-			at91_clock_associate("usart2_clk", &uart2_serial_device, "usart");
-			register_device(&uart2_serial_device);
+			clk_name = "usart2_clk";
+			start = AT91RM9200_BASE_US2;
+			id = 3;
 			break;
 		case AT91RM9200_ID_US3:
 			configure_usart3_pins(pins);
-			at91_clock_associate("usart3_clk", &uart3_serial_device, "usart");
-			register_device(&uart3_serial_device);
+			clk_name = "usart3_clk";
+			start = AT91RM9200_BASE_US3;
+			id = 4;
 			break;
 		default:
 			return;
 	}
 
+	dev = add_generic_device("atmel_serial", id, NULL, start, 4096,
+			   IORESOURCE_MEM, NULL);
+	at91_clock_associate(clk_name, dev, "usart");
 }
diff --git a/arch/arm/mach-at91/at91sam9260_devices.c b/arch/arm/mach-at91/at91sam9260_devices.c
index 3808c66..468f00d 100644
--- a/arch/arm/mach-at91/at91sam9260_devices.c
+++ b/arch/arm/mach-at91/at91sam9260_devices.c
@@ -31,21 +31,6 @@ void at91_add_device_sdram(u32 size)
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
-static struct resource eth_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_EMAC,
-		.size	= 0x1000,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d macb_dev = {
-	.id	  = -1,
-	.name     = "macb",
-	.resource	= eth_resources,
-	.num_resources	= ARRAY_SIZE(eth_resources),
-};
-
 void at91_add_device_eth(struct at91_ether_platform_data *data)
 {
 	if (!data)
@@ -74,29 +59,14 @@ void at91_add_device_eth(struct at91_ether_platform_data *data)
 		at91_set_B_periph(AT91_PIN_PA22, 0);	/* ETXER */
 	}
 
-	macb_dev.platform_data = data;
-	register_device(&macb_dev);
+	add_generic_device("macb", 0, NULL, AT91SAM9260_BASE_EMAC, 0x1000,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_eth(struct at91_ether_platform_data *data) {}
 #endif
 
 #if defined(CONFIG_NAND_ATMEL)
-static struct resource nand_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_3,
-		.size	= 0x10,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d nand_dev = {
-	.id	  = -1,
-	.name     = "atmel_nand",
-	.resource	= nand_resources,
-	.num_resources	= ARRAY_SIZE(nand_resources),
-};
-
 void at91_add_device_nand(struct atmel_nand_data *data)
 {
 	unsigned long csa;
@@ -119,49 +89,19 @@ void at91_add_device_nand(struct atmel_nand_data *data)
 	if (data->det_pin)
 		at91_set_gpio_input(data->det_pin, 1);
 
-	nand_dev.platform_data = data;
-	register_device(&nand_dev);
+	add_generic_device("atmel_nand", 0, NULL, AT91_CHIPSELECT_3, 0x10,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_nand(struct atmel_nand_data *data) {}
 #endif
 
-static struct resource dbgu_resources[] = {
-	[0] = {
-		.start	= AT91_BASE_SYS + AT91_DBGU,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d dbgu_serial_device = {
-	.id	  = 0,
-	.name     = "atmel_serial",
-	.resource	= dbgu_resources,
-	.num_resources	= ARRAY_SIZE(dbgu_resources),
-};
-
 static inline void configure_dbgu_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PB14, 0);		/* DRXD */
 	at91_set_A_periph(AT91_PIN_PB15, 1);		/* DTXD */
 }
 
-static struct resource uart0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US0,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart0_serial_device = {
-	.id	  = 1,
-	.name     = "atmel_serial",
-	.resource	= uart0_resources,
-	.num_resources	= ARRAY_SIZE(uart0_resources),
-};
-
 static inline void configure_usart0_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB4, 1);		/* TXD0 */
@@ -181,21 +121,6 @@ static inline void configure_usart0_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PB25, 0);	/* RI0 */
 }
 
-static struct resource uart1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US1,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart1_serial_device = {
-	.id	  = 2,
-	.name     = "atmel_serial",
-	.resource	= uart1_resources,
-	.num_resources	= ARRAY_SIZE(uart1_resources),
-};
-
 static inline void configure_usart1_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB6, 1);		/* TXD1 */
@@ -207,21 +132,6 @@ static inline void configure_usart1_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PB29, 0);	/* CTS1 */
 }
 
-static struct resource uart2_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US2,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart2_serial_device = {
-	.id	  = 3,
-	.name     = "atmel_serial",
-	.resource	= uart2_resources,
-	.num_resources	= ARRAY_SIZE(uart2_resources),
-};
-
 static inline void configure_usart2_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB8, 1);		/* TXD2 */
@@ -233,21 +143,6 @@ static inline void configure_usart2_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PA5, 0);	/* CTS2 */
 }
 
-static struct resource uart3_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US3,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart3_serial_device = {
-	.id	  = 4,
-	.name     = "atmel_serial",
-	.resource	= uart3_resources,
-	.num_resources	= ARRAY_SIZE(uart3_resources),
-};
-
 static inline void configure_usart3_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB10, 1);		/* TXD3 */
@@ -259,42 +154,12 @@ static inline void configure_usart3_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PC10, 0);	/* CTS3 */
 }
 
-static struct resource uart4_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US4,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart4_serial_device = {
-	.id	  = 5,
-	.name     = "atmel_serial",
-	.resource	= uart4_resources,
-	.num_resources	= ARRAY_SIZE(uart4_resources),
-};
-
 static inline void configure_usart4_pins(void)
 {
 	at91_set_B_periph(AT91_PIN_PA31, 1);		/* TXD4 */
 	at91_set_B_periph(AT91_PIN_PA30, 0);		/* RXD4 */
 }
 
-static struct resource uart5_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_US5,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart5_serial_device = {
-	.id	  = 6,
-	.name     = "atmel_serial",
-	.resource	= uart5_resources,
-	.num_resources	= ARRAY_SIZE(uart5_resources),
-};
-
 static inline void configure_usart5_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PB12, 1);		/* TXD5 */
@@ -303,66 +168,68 @@ static inline void configure_usart5_pins(void)
 
 void at91_register_uart(unsigned id, unsigned pins)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	switch (id) {
 		case 0:		/* DBGU */
 			configure_dbgu_pins();
-			at91_clock_associate("mck", &dbgu_serial_device, "usart");
-			register_device(&dbgu_serial_device);
+			start = AT91_BASE_SYS + AT91_DBGU;
+			clk_name = "mck";
+			id = 0;
 			break;
 		case AT91SAM9260_ID_US0:
 			configure_usart0_pins(pins);
-			at91_clock_associate("usart0_clk", &uart0_serial_device, "usart");
-			register_device(&uart0_serial_device);
+			clk_name = "usart0_clk";
+			start = AT91SAM9260_BASE_US0;
+			id = 1;
 			break;
 		case AT91SAM9260_ID_US1:
 			configure_usart1_pins(pins);
-			at91_clock_associate("usart1_clk", &uart1_serial_device, "usart");
-			register_device(&uart1_serial_device);
+			clk_name = "usart1_clk";
+			start = AT91SAM9260_BASE_US1;
+			id = 2;
 			break;
 		case AT91SAM9260_ID_US2:
 			configure_usart2_pins(pins);
-			at91_clock_associate("usart2_clk", &uart2_serial_device, "usart");
-			register_device(&uart2_serial_device);
+			clk_name = "usart2_clk";
+			start = AT91SAM9260_BASE_US2;
+			id = 3;
 			break;
 		case AT91SAM9260_ID_US3:
 			configure_usart3_pins(pins);
-			at91_clock_associate("usart3_clk", &uart3_serial_device, "usart");
-			register_device(&uart3_serial_device);
+			clk_name = "usart3_clk";
+			start = AT91SAM9260_BASE_US3;
+			id = 4;
 			break;
 		case AT91SAM9260_ID_US4:
 			configure_usart4_pins();
-			at91_clock_associate("usart4_clk", &uart4_serial_device, "usart");
-			register_device(&uart4_serial_device);
+			clk_name = "usart4_clk";
+			start = AT91SAM9260_BASE_US4;
+			id = 5;
 			break;
 		case AT91SAM9260_ID_US5:
 			configure_usart5_pins();
-			at91_clock_associate("usart5_clk", &uart5_serial_device, "usart");
-			register_device(&uart5_serial_device);
+			clk_name = "usart5_clk";
+			start = AT91SAM9260_BASE_US5;
+			id = 6;
 			break;
 		default:
 			return;
 	}
+
+	dev = add_generic_device("atmel_serial", id, NULL, start, 4096,
+			   IORESOURCE_MEM, NULL);
+	at91_clock_associate(clk_name, dev, "usart");
 }
 
 #if defined(CONFIG_MCI_ATMEL)
-static struct resource mci_resources[] = {
-	[0] = {
-		.start	= AT91SAM9260_BASE_MCI,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci_device = {
-	.id		= -1,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci_resources),
-	.resource	= mci_resources,
-};
-
 /* Consider only one slot : slot 0 */
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 {
+	struct device_d *dev;
+
 	if (!data)
 		return;
 
@@ -393,9 +260,9 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 		at91_set_A_periph(AT91_PIN_PA11, 1);
 	}
 
-	mci_device.platform_data = data;
-	at91_clock_associate("mci_clk", &mci_device, "mci_clk");
-	register_device(&mci_device);
+	dev = add_generic_device("atmel_mci", 0, NULL, AT91SAM9260_BASE_MCI, SZ_16K,
+			   IORESOURCE_MEM, data);
+	at91_clock_associate("mci_clk", dev, "mci_clk");
 }
 #else
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data) {}
diff --git a/arch/arm/mach-at91/at91sam9261_devices.c b/arch/arm/mach-at91/at91sam9261_devices.c
index f2a0664..1e741fd 100644
--- a/arch/arm/mach-at91/at91sam9261_devices.c
+++ b/arch/arm/mach-at91/at91sam9261_devices.c
@@ -31,21 +31,6 @@ void at91_add_device_sdram(u32 size)
 }
 
 #if defined(CONFIG_NAND_ATMEL)
-static struct resource nand_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_3,
-		.size	= 0x10,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d nand_dev = {
-	.id		= 0,
-	.name		= "atmel_nand",
-	.resource	= nand_resources,
-	.num_resources	= ARRAY_SIZE(nand_resources),
-};
-
 void at91_add_device_nand(struct atmel_nand_data *data)
 {
 	unsigned long csa;
@@ -71,49 +56,19 @@ void at91_add_device_nand(struct atmel_nand_data *data)
 	at91_set_A_periph(AT91_PIN_PC0, 0);		/* NANDOE */
 	at91_set_A_periph(AT91_PIN_PC1, 0);		/* NANDWE */
 
-	nand_dev.platform_data = data;
-	register_device(&nand_dev);
+	add_generic_device("atmel_nand", 0, NULL, AT91_CHIPSELECT_3, 0x10,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_nand(struct atmel_nand_data *data) {}
 #endif
 
-static struct resource dbgu_resources[] = {
-	[0] = {
-		.start	= (AT91_BASE_SYS + AT91_DBGU),
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d dbgu_serial_device = {
-	.id		= 0,
-	.name		= "atmel_serial",
-	.resource	= dbgu_resources,
-	.num_resources	= ARRAY_SIZE(dbgu_resources),
-};
-
 static inline void configure_dbgu_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PA9, 0);		/* DRXD */
 	at91_set_A_periph(AT91_PIN_PA10, 1);		/* DTXD */
 }
 
-static struct resource uart0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9261_BASE_US0,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart0_serial_device = {
-	.id		= 1,
-	.name		= "atmel_serial",
-	.resource	= uart0_resources,
-	.num_resources	= ARRAY_SIZE(uart0_resources),
-};
-
 static inline void configure_usart0_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PC8, 1);		/* TXD0 */
@@ -125,21 +80,6 @@ static inline void configure_usart0_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PC11, 0);	/* CTS0 */
 }
 
-static struct resource uart1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9261_BASE_US1,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart1_serial_device = {
-	.id		= 2,
-	.name		= "atmel_serial",
-	.resource	= uart1_resources,
-	.num_resources	= ARRAY_SIZE(uart1_resources),
-};
-
 static inline void configure_usart1_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PC12, 1);		/* TXD1 */
@@ -151,21 +91,6 @@ static inline void configure_usart1_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PA13, 0);	/* CTS1 */
 }
 
-static struct resource uart2_resources[] = {
-	[0] = {
-		.start	= AT91SAM9261_BASE_US2,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart2_serial_device = {
-	.id		= 3,
-	.name		= "atmel_serial",
-	.resource	= uart2_resources,
-	.num_resources	= ARRAY_SIZE(uart2_resources),
-};
-
 static inline void configure_usart2_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PC15, 0);		/* RXD2 */
@@ -179,51 +104,50 @@ static inline void configure_usart2_pins(unsigned pins)
 
 void at91_register_uart(unsigned id, unsigned pins)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	switch (id) {
 		case 0:		/* DBGU */
 			configure_dbgu_pins();
-			at91_clock_associate("mck", &dbgu_serial_device, "usart");
-			register_device(&dbgu_serial_device);
+			start = AT91_BASE_SYS + AT91_DBGU;
+			clk_name = "mck";
+			id = 0;
 			break;
 		case AT91SAM9261_ID_US0:
 			configure_usart0_pins(pins);
-			at91_clock_associate("usart0_clk", &uart0_serial_device, "usart");
-			register_device(&uart0_serial_device);
+			clk_name = "usart0_clk";
+			start = AT91SAM9261_BASE_US0;
+			id = 1;
 			break;
 		case AT91SAM9261_ID_US1:
 			configure_usart1_pins(pins);
-			at91_clock_associate("usart1_clk", &uart1_serial_device, "usart");
-			register_device(&uart1_serial_device);
+			clk_name = "usart1_clk";
+			start = AT91SAM9261_BASE_US1;
+			id = 2;
 			break;
 		case AT91SAM9261_ID_US2:
 			configure_usart2_pins(pins);
-			at91_clock_associate("usart2_clk", &uart2_serial_device, "usart");
-			register_device(&uart2_serial_device);
+			clk_name = "usart3_clk";
+			start = AT91SAM9261_BASE_US2;
+			id = 3;
 			break;
 		default:
 			return;
 	}
+
+	dev = add_generic_device("atmel_serial", id, NULL, start, 4096,
+			   IORESOURCE_MEM, NULL);
+	at91_clock_associate(clk_name, dev, "usart");
 }
 
 #if defined(CONFIG_MCI_ATMEL)
-static struct resource mci_resources[] = {
-	[0] = {
-		.start	= AT91SAM9261_BASE_MCI,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci_device = {
-	.id		= -1,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci_resources),
-	.resource	= mci_resources,
-};
-
 /* Consider only one slot : slot 0 */
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 {
+	struct device_d *dev;
+
 	if (!data)
 		return;
 
@@ -254,9 +178,9 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 		at91_set_B_periph(AT91_PIN_PA6, 1);
 	}
 
-	mci_device.platform_data = data;
-	at91_clock_associate("mci_clk", &mci_device, "mci_clk");
-	register_device(&mci_device);
+	dev = add_generic_device("atmel_mci", 0, NULL, AT91SAM9261_BASE_MCI, SZ_16K,
+			   IORESOURCE_MEM, data);
+	at91_clock_associate("mci_clk", dev, "mci_clk");
 }
 #else
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data) {}
diff --git a/arch/arm/mach-at91/at91sam9263_devices.c b/arch/arm/mach-at91/at91sam9263_devices.c
index c951800..07bd02f 100644
--- a/arch/arm/mach-at91/at91sam9263_devices.c
+++ b/arch/arm/mach-at91/at91sam9263_devices.c
@@ -31,21 +31,6 @@ void at91_add_device_sdram(u32 size)
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
-static struct resource eth_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_EMAC,
-		.size	= 0x1000,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d macb_dev = {
-	.id	  = -1,
-	.name     = "macb",
-	.resource	= eth_resources,
-	.num_resources	= ARRAY_SIZE(eth_resources),
-};
-
 void at91_add_device_eth(struct at91_ether_platform_data *data)
 {
 	if (!data)
@@ -73,29 +58,14 @@ void at91_add_device_eth(struct at91_ether_platform_data *data)
 		at91_set_B_periph(AT91_PIN_PC24, 0);	/* ETXER */
 	}
 
-	macb_dev.platform_data = data;
-	register_device(&macb_dev);
+	add_generic_device("macb", 0, NULL, AT91SAM9263_BASE_EMAC, 0x1000,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_eth(struct at91_ether_platform_data *data) {}
 #endif
 
 #if defined(CONFIG_NAND_ATMEL)
-static struct resource nand_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_3,
-		.size	= 0x10,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d nand_dev = {
-	.id	  = -1,
-	.name     = "atmel_nand",
-	.resource	= nand_resources,
-	.num_resources	= ARRAY_SIZE(nand_resources),
-};
-
 void at91_add_device_nand(struct atmel_nand_data *data)
 {
 	unsigned long csa;
@@ -118,49 +88,19 @@ void at91_add_device_nand(struct atmel_nand_data *data)
 	if (data->det_pin)
 		at91_set_gpio_input(data->det_pin, 1);
 
-	nand_dev.platform_data = data;
-	register_device(&nand_dev);
+	add_generic_device("atmel_nand", -1, NULL, AT91_CHIPSELECT_3, 0x10,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_nand(struct atmel_nand_data *data) {}
 #endif
 
-static struct resource dbgu_resources[] = {
-	[0] = {
-		.start	= (AT91_BASE_SYS + AT91_DBGU),
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d dbgu_serial_device = {
-	.id	  = 0,
-	.name     = "atmel_serial",
-	.resource	= dbgu_resources,
-	.num_resources	= ARRAY_SIZE(dbgu_resources),
-};
-
 static inline void configure_dbgu_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PC30, 0);		/* DRXD */
 	at91_set_A_periph(AT91_PIN_PC31, 1);		/* DTXD */
 }
 
-static struct resource uart0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_US0,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart0_serial_device = {
-	.id	  = 1,
-	.name     = "atmel_serial",
-	.resource	= uart0_resources,
-	.num_resources	= ARRAY_SIZE(uart0_resources),
-};
-
 static inline void configure_usart0_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PA26, 1);		/* TXD0 */
@@ -172,21 +112,6 @@ static inline void configure_usart0_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PA29, 0);	/* CTS0 */
 }
 
-static struct resource uart1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_US1,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart1_serial_device = {
-	.id	  = 2,
-	.name     = "atmel_serial",
-	.resource	= uart1_resources,
-	.num_resources	= ARRAY_SIZE(uart1_resources),
-};
-
 static inline void configure_usart1_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PD0, 1);		/* TXD1 */
@@ -198,21 +123,6 @@ static inline void configure_usart1_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PD8, 0);	/* CTS1 */
 }
 
-static struct resource uart2_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_US2,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart2_serial_device = {
-	.id	  = 3,
-	.name     = "atmel_serial",
-	.resource	= uart2_resources,
-	.num_resources	= ARRAY_SIZE(uart2_resources),
-};
-
 static inline void configure_usart2_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PD2, 1);		/* TXD2 */
@@ -226,67 +136,53 @@ static inline void configure_usart2_pins(unsigned pins)
 
 void at91_register_uart(unsigned id, unsigned pins)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	switch (id) {
 		case 0:		/* DBGU */
 			configure_dbgu_pins();
-			at91_clock_associate("mck", &dbgu_serial_device, "usart");
-			register_device(&dbgu_serial_device);
+			start = AT91_BASE_SYS + AT91_DBGU;
+			clk_name = "mck";
+			id = 0;
 			break;
 		case AT91SAM9263_ID_US0:
 			configure_usart0_pins(pins);
-			at91_clock_associate("usart0_clk", &uart0_serial_device, "usart");
-			register_device(&uart0_serial_device);
+			clk_name = "usart0_clk";
+			start = AT91SAM9263_BASE_US0;
+			id = 1;
 			break;
 		case AT91SAM9263_ID_US1:
 			configure_usart1_pins(pins);
-			at91_clock_associate("usart1_clk", &uart1_serial_device, "usart");
-			register_device(&uart1_serial_device);
+			clk_name = "usart1_clk";
+			start = AT91SAM9263_BASE_US1;
+			id = 2;
 			break;
 		case AT91SAM9263_ID_US2:
 			configure_usart2_pins(pins);
-			at91_clock_associate("usart2_clk", &uart2_serial_device, "usart");
-			register_device(&uart2_serial_device);
+			clk_name = "usart2_clk";
+			start = AT91SAM9263_BASE_US2;
+			id = 3;
 			break;
 		default:
 			return;
 	}
 
+	dev = add_generic_device("atmel_serial", id, NULL, start, 4096,
+			   IORESOURCE_MEM, NULL);
+	at91_clock_associate(clk_name, dev, "usart");
+
 }
 
 #if defined(CONFIG_MCI_ATMEL)
-static struct resource mci0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_MCI0,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci0_device = {
-	.id		= 0,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci0_resources),
-	.resource	= mci0_resources,
-};
-
-static struct resource mci1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9263_BASE_MCI1,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci1_device = {
-	.id		= 1,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci1_resources),
-	.resource	= mci1_resources,
-};
-
 /* Consider only one slot : slot 0 */
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	if (!data)
 		return;
 
@@ -304,6 +200,8 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 		at91_set_gpio_input(data->wp_pin, 1);
 
 	if (mmc_id == 0) {		/* MCI0 */
+		start = AT91SAM9263_BASE_MCI0;
+		clk_name = "mci0_clk";
 		/* CLK */
 		at91_set_A_periph(AT91_PIN_PA12, 0);
 
@@ -317,12 +215,9 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 			at91_set_A_periph(AT91_PIN_PA4, 1);
 			at91_set_A_periph(AT91_PIN_PA5, 1);
 		}
-
-		mci0_device.platform_data = data;
-		at91_clock_associate("mci0_clk", &mci0_device, "mci_clk");
-		register_device(&mci0_device);
-
 	} else {			/* MCI1 */
+		start = AT91SAM9263_BASE_MCI1;
+		clk_name = "mci1_clk";
 		/* CLK */
 		at91_set_A_periph(AT91_PIN_PA6, 0);
 
@@ -336,11 +231,11 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 			at91_set_A_periph(AT91_PIN_PA10, 1);
 			at91_set_A_periph(AT91_PIN_PA11, 1);
 		}
-
-		mci1_device.platform_data = data;
-		at91_clock_associate("mci1_clk", &mci1_device, "mci_clk");
-		register_device(&mci1_device);
 	}
+
+	dev = add_generic_device("atmel_mci", mmc_id, NULL, start, 4096,
+			   IORESOURCE_MEM, data);
+	at91_clock_associate(clk_name, dev, "mci_clk");
 }
 #else
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data) {}
diff --git a/arch/arm/mach-at91/at91sam9g45_devices.c b/arch/arm/mach-at91/at91sam9g45_devices.c
index 4f5279f..afcc687 100644
--- a/arch/arm/mach-at91/at91sam9g45_devices.c
+++ b/arch/arm/mach-at91/at91sam9g45_devices.c
@@ -31,21 +31,6 @@ void at91_add_device_sdram(u32 size)
 }
 
 #if defined(CONFIG_DRIVER_NET_MACB)
-static struct resource eth_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_EMAC,
-		.size	= 0x1000,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d macb_dev = {
-	.id		= 0,
-	.name		= "macb",
-	.resource	= eth_resources,
-	.num_resources	= ARRAY_SIZE(eth_resources),
-};
-
 void at91_add_device_eth(struct at91_ether_platform_data *data)
 {
 	if (!data)
@@ -74,29 +59,14 @@ void at91_add_device_eth(struct at91_ether_platform_data *data)
 		at91_set_B_periph(AT91_PIN_PA27, 0);	/* ETXER */
 	}
 
-	macb_dev.platform_data = data;
-	register_device(&macb_dev);
+	add_generic_device("macb", 0, NULL, AT91SAM9G45_BASE_EMAC, 0x1000,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_eth(struct at91_ether_platform_data *data) {}
 #endif
 
 #if defined(CONFIG_NAND_ATMEL)
-static struct resource nand_resources[] = {
-	[0] = {
-		.start	= AT91_CHIPSELECT_3,
-		.size	= 0x10,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d nand_dev = {
-	.id		= -1,
-	.name		= "atmel_nand",
-	.resource	= nand_resources,
-	.num_resources	= ARRAY_SIZE(nand_resources),
-};
-
 void at91_add_device_nand(struct atmel_nand_data *data)
 {
 	unsigned long csa;
@@ -122,49 +92,19 @@ void at91_add_device_nand(struct atmel_nand_data *data)
 	if (data->det_pin)
 		at91_set_gpio_input(data->det_pin, 1);
 
-	nand_dev.platform_data = data;
-	register_device(&nand_dev);
+	add_generic_device("atmel_nand", -1, NULL, AT91_CHIPSELECT_3, 0x10,
+			   IORESOURCE_MEM, data);
 }
 #else
 void at91_add_device_nand(struct atmel_nand_data *data) {}
 #endif
 
-static struct resource dbgu_resources[] = {
-	[0] = {
-		.start	= (AT91_BASE_SYS + AT91_DBGU),
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d dbgu_serial_device = {
-	.id	  = -1,
-	.name     = "atmel_serial",
-	.resource	= dbgu_resources,
-	.num_resources	= ARRAY_SIZE(dbgu_resources),
-};
-
 static inline void configure_dbgu_pins(void)
 {
 	at91_set_A_periph(AT91_PIN_PB12, 0);		/* DRXD */
 	at91_set_A_periph(AT91_PIN_PB13, 1);		/* DTXD */
 }
 
-static struct resource uart0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_US0,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart0_serial_device = {
-	.id	  = -1,
-	.name     = "atmel_serial",
-	.resource	= uart0_resources,
-	.num_resources	= ARRAY_SIZE(uart0_resources),
-};
-
 static inline void configure_usart0_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB19, 1);		/* TXD0 */
@@ -176,21 +116,6 @@ static inline void configure_usart0_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PB15, 0);	/* CTS0 */
 }
 
-static struct resource uart1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_US1,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart1_serial_device = {
-	.id	  = -1,
-	.name     = "atmel_serial",
-	.resource	= uart1_resources,
-	.num_resources	= ARRAY_SIZE(uart1_resources),
-};
-
 static inline void configure_usart1_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB4, 1);		/* TXD1 */
@@ -202,21 +127,6 @@ static inline void configure_usart1_pins(unsigned pins)
 		at91_set_A_periph(AT91_PIN_PD17, 0);	/* CTS1 */
 }
 
-static struct resource uart2_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_US2,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart2_serial_device = {
-	.id	  = -1,
-	.name     = "atmel_serial",
-	.resource	= uart2_resources,
-	.num_resources	= ARRAY_SIZE(uart2_resources),
-};
-
 static inline void configure_usart2_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB6, 1);		/* TXD2 */
@@ -228,21 +138,6 @@ static inline void configure_usart2_pins(unsigned pins)
 		at91_set_B_periph(AT91_PIN_PC11, 0);	/* CTS2 */
 }
 
-static struct resource uart3_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_US3,
-		.size	= 4096,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d uart3_serial_device = {
-	.id	  = -1,
-	.name     = "atmel_serial",
-	.resource	= uart3_resources,
-	.num_resources	= ARRAY_SIZE(uart3_resources),
-};
-
 static inline void configure_usart3_pins(unsigned pins)
 {
 	at91_set_A_periph(AT91_PIN_PB8, 1);		/* TXD3 */
@@ -256,72 +151,59 @@ static inline void configure_usart3_pins(unsigned pins)
 
 void at91_register_uart(unsigned id, unsigned pins)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	switch (id) {
 		case 0:		/* DBGU */
 			configure_dbgu_pins();
-			at91_clock_associate("mck", &dbgu_serial_device, "usart");
-			register_device(&dbgu_serial_device);
+			start = AT91_BASE_SYS + AT91_DBGU;
+			clk_name = "mck";
+			id = 0;
 			break;
 		case AT91SAM9G45_ID_US0:
 			configure_usart0_pins(pins);
-			at91_clock_associate("usart0_clk", &uart0_serial_device, "usart");
-			register_device(&uart0_serial_device);
+			clk_name = "usart0_clk";
+			start = AT91SAM9G45_BASE_US0;
+			id = 1;
 			break;
 		case AT91SAM9G45_ID_US1:
 			configure_usart1_pins(pins);
-			at91_clock_associate("usart1_clk", &uart1_serial_device, "usart");
-			register_device(&uart1_serial_device);
+			clk_name = "usart1_clk";
+			start = AT91SAM9G45_BASE_US1;
+			id = 2;
 			break;
 		case AT91SAM9G45_ID_US2:
 			configure_usart2_pins(pins);
-			at91_clock_associate("usart2_clk", &uart2_serial_device, "usart");
-			register_device(&uart2_serial_device);
+			clk_name = "usart2_clk";
+			start = AT91SAM9G45_BASE_US2;
+			id = 3;
 			break;
 		case AT91SAM9G45_ID_US3:
 			configure_usart3_pins(pins);
-			at91_clock_associate("usart3_clk", &uart2_serial_device, "usart");
-			register_device(&uart3_serial_device);
+			clk_name = "usart3_clk";
+			start = AT91SAM9G45_BASE_US3;
+			id = 4;
 			break;
 		default:
 			return;
 	}
 
+	dev = add_generic_device("atmel_serial", id, NULL, start, 4096,
+			   IORESOURCE_MEM, NULL);
+	at91_clock_associate(clk_name, dev, "usart");
+
 }
 
 #if defined(CONFIG_MCI_ATMEL)
-static struct resource mci0_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_MCI0,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci0_device = {
-	.id		= 0,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci0_resources),
-	.resource	= mci0_resources,
-};
-
-static struct resource mci1_resources[] = {
-	[0] = {
-		.start	= AT91SAM9G45_BASE_MCI1,
-		.size	= SZ_16K,
-		.flags	= IORESOURCE_MEM,
-	},
-};
-
-static struct device_d mci1_device = {
-	.id		= 1,
-	.name		= "atmel_mci",
-	.num_resources	= ARRAY_SIZE(mci1_resources),
-	.resource	= mci1_resources,
-};
-
-/* Consider only one slot : slot 0 */
+* Consider only one slot : slot 0 */
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 {
+	resource_size_t start;
+	struct device_d *dev;
+	char* clk_name;
+
 	if (!data)
 		return;
 
@@ -339,6 +221,8 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 		at91_set_gpio_input(data->wp_pin, 1);
 
 	if (mmc_id == 0) {		/* MCI0 */
+		start = AT91SAM9G45_BASE_MCI0;
+		clk_name = "mci0_clk";
 		/* CLK */
 		at91_set_A_periph(AT91_PIN_PA0, 0);
 
@@ -358,12 +242,9 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 				at91_set_A_periph(AT91_PIN_PA9, 1);
 			}
 		}
-
-		mci0_device.platform_data = data;
-		at91_clock_associate("mci0_clk", &mci0_device, "mci_clk");
-		register_device(&mci0_device);
-
 	} else {			/* MCI1 */
+		start = AT91SAM9G45_BASE_MCI1;
+		clk_name = "mci1_clk";
 		/* CLK */
 		at91_set_A_periph(AT91_PIN_PA31, 0);
 
@@ -383,11 +264,11 @@ void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data)
 				at91_set_A_periph(AT91_PIN_PA30, 1);
 			}
 		}
-
-		mci1_device.platform_data = data;
-		at91_clock_associate("mci1_clk", &mci1_device, "mci_clk");
-		register_device(&mci1_device);
 	}
+
+	dev = add_generic_device("atmel_mci", mmc_id, NULL, start, 4096,
+			   IORESOURCE_MEM, data);
+	at91_clock_associate(clk_name, dev, "mci_clk");
 }
 #else
 void at91_add_device_mci(short mmc_id, struct atmel_mci_platform_data *data) {}
-- 
1.7.5.4


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

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

* [PATCH 5/6] imx/devices: switch to add_generic_device
  2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2011-07-22 15:38 ` [PATCH 4/6] at91: switch to add_generic_device Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-22 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-22 15:38 ` [PATCH 6/6] resource: introduce add_cfi_device to register simple cfi device Jean-Christophe PLAGNIOL-VILLARD
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/mach-imx/devices.c |   19 +++----------------
 1 files changed, 3 insertions(+), 16 deletions(-)

diff --git a/arch/arm/mach-imx/devices.c b/arch/arm/mach-imx/devices.c
index 6503c30..d2cf1e6 100644
--- a/arch/arm/mach-imx/devices.c
+++ b/arch/arm/mach-imx/devices.c
@@ -2,23 +2,10 @@
 #include <driver.h>
 #include <mach/devices.h>
 
-static struct device_d *imx_add_device(char *name, int id, void *base, int size, void *pdata)
+static struct inline device_d *imx_add_device(char *name, int id, void *base, int size, void *pdata)
 {
-	struct device_d *dev;
-
-	dev = xzalloc(sizeof(*dev));
-	strcpy(dev->name,name);
-	dev->id = id;
-	dev->resource = xzalloc(sizeof(struct resource));
-	dev->resource[0].start = (resource_size_t)base;
-	dev->resource[0].size = size;
-	dev->resource[0].flags = IORESOURCE_MEM;
-	dev->num_resources = 1;
-	dev->platform_data = pdata;
-
-	register_device(dev);
-
-	return 0;
+	return add_generic_device(name, id, NULL, (resource_size_t)start, size,
+				  IORESOURCE_MEM, pada);
 }
 
 struct device_d *imx_add_fec(void *base, struct fec_platform_data *pdata)
-- 
1.7.5.4


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

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

* [PATCH 6/6] resource: introduce add_cfi_device to register simple cfi device
  2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2011-07-22 15:38 ` [PATCH 5/6] imx/devices: " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-22 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  4 siblings, 0 replies; 6+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-22 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/boards/at91rm9200ek/init.c               |    3 +--
 arch/arm/boards/at91sam9263ek/init.c              |    3 +--
 arch/arm/boards/edb93xx/edb93xx.c                 |    9 +--------
 arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c |   19 ++-----------------
 arch/arm/boards/freescale-mx35-3-stack/3stack.c   |    9 +--------
 arch/arm/boards/imx21ads/imx21ads.c               |    9 +--------
 arch/arm/boards/imx27ads/imx27ads.c               |    9 +--------
 arch/arm/boards/mmccpu/init.c                     |    3 +--
 arch/arm/boards/netx/netx.c                       |    9 +--------
 arch/arm/boards/pcm037/pcm037.c                   |   17 +++++------------
 arch/arm/boards/pcm038/pcm038.c                   |    9 +--------
 arch/arm/boards/pcm043/pcm043.c                   |   17 +++++------------
 arch/arm/boards/pm9261/init.c                     |    3 +--
 arch/arm/boards/pm9263/init.c                     |    3 +--
 arch/arm/boards/scb9328/scb9328.c                 |   10 +---------
 arch/arm/boards/versatile/versatilepb.c           |    9 +--------
 arch/blackfin/boards/ipe337/ipe337.c              |    9 +--------
 arch/nios2/boards/generic/generic.c               |    9 +--------
 arch/ppc/boards/pcm030/pcm030.c                   |    9 +--------
 include/driver.h                                  |    7 +++++++
 20 files changed, 35 insertions(+), 140 deletions(-)

diff --git a/arch/arm/boards/at91rm9200ek/init.c b/arch/arm/boards/at91rm9200ek/init.c
index 3ef41a2..9b58996 100644
--- a/arch/arm/boards/at91rm9200ek/init.c
+++ b/arch/arm/boards/at91rm9200ek/init.c
@@ -50,8 +50,7 @@ static int at91rm9200ek_devices_init(void)
 	at91_add_device_sdram(64 * 1024 * 1024);
 	at91_add_device_eth(&ether_pdata);
 
-	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 0,
-			   IORESOURCE_MEM, NULL);
+	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 0, 0);
 
 #if defined(CONFIG_DRIVER_CFI) || defined(CONFIG_DRIVER_CFI_OLD)
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
diff --git a/arch/arm/boards/at91sam9263ek/init.c b/arch/arm/boards/at91sam9263ek/init.c
index 655d46a..036a1c4 100644
--- a/arch/arm/boards/at91sam9263ek/init.c
+++ b/arch/arm/boards/at91sam9263ek/init.c
@@ -120,8 +120,7 @@ static int at91sam9263ek_devices_init(void)
 	at91_add_device_sdram(64 * 1024 * 1024);
 	ek_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
-	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 8 * 1024 * 1024,
-			   IORESOURCE_MEM, NULL);
+	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 8 * 1024 * 1024, 0);
 	ek_add_device_mci();
 
 #if defined(CONFIG_DRIVER_CFI) || defined(CONFIG_DRIVER_CFI_OLD)
diff --git a/arch/arm/boards/edb93xx/edb93xx.c b/arch/arm/boards/edb93xx/edb93xx.c
index 49a01d6..b169db6 100644
--- a/arch/arm/boards/edb93xx/edb93xx.c
+++ b/arch/arm/boards/edb93xx/edb93xx.c
@@ -38,13 +38,6 @@
  * Up to 32MiB NOR type flash, connected to
  * CS line 6, data width is 16 bit
  */
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0x60000000,
-	.size     = EDB93XX_CFI_FLASH_SIZE,
-};
-
 static struct device_d eth_dev = {
 	.id	  = -1,
 	.name     = "ep93xx_eth",
@@ -54,7 +47,7 @@ static int ep93xx_devices_init(void)
 {
 	struct device_d *sdram_dev;
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0x60000000, EDB93XX_CFI_FLASH_SIZE, 0);
 
 	/*
 	 * Create partitions that should be
diff --git a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
index 92424e6..4e69bbc 100644
--- a/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
+++ b/arch/arm/boards/eukrea_cpuimx27/eukrea_cpuimx27.c
@@ -48,21 +48,6 @@
 #include <mach/iomux-mx27.h>
 #include <mach/devices-imx27.h>
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC0000000,
-	.size     = 32 * 1024 * 1024,
-};
-#ifdef CONFIG_EUKREA_CPUIMX27_NOR_64MB
-static struct device_d cfi_dev1 = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC2000000,
-	.size     = 32 * 1024 * 1024,
-};
-#endif
-
 #if defined CONFIG_EUKREA_CPUIMX27_SDRAM_256MB
 #define SDRAM0	256
 #elif defined CONFIG_EUKREA_CPUIMX27_SDRAM_128MB
@@ -254,9 +239,9 @@ static int eukrea_cpuimx27_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(mode); i++)
 		imx_gpio_mode(mode[i]);
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 #ifdef CONFIG_EUKREA_CPUIMX27_NOR_64MB
-	register_device(&cfi_dev1);
+	add_cfi_flash_device(-1, 0xC2000000, 32 * 1024 * 1024, 0);
 #endif
 	imx27_add_nand(&nand_info);
 	sdram_dev = add_mem_device("ram0", 0xa0000000, SDRAM0 * 1024 * 1024,
diff --git a/arch/arm/boards/freescale-mx35-3-stack/3stack.c b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
index b3a03cc..9113650 100644
--- a/arch/arm/boards/freescale-mx35-3-stack/3stack.c
+++ b/arch/arm/boards/freescale-mx35-3-stack/3stack.c
@@ -59,13 +59,6 @@
 #define MX35PDK_BOARD_REV_1		0
 #define MX35PDK_BOARD_REV_2		1
 
-static struct device_d cfi_dev = {
-	.id		= -1,
-	.name		= "cfi_flash",
-	.map_base	= IMX_CS0_BASE,
-	.size		= 64 * 1024 * 1024,
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type	= MII100,
 	.phy_addr	= 0x1F,
@@ -170,7 +163,7 @@ static int f3s_devices_init(void)
 	 * This platform supports NOR and NAND
 	 */
 	imx35_add_nand(&nand_info);
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, IMX_CS0_BASE, 64 * 1024 * 1024, 0);
 
 	switch ((reg >> 25) & 0x3) {
 	case 0x01:		/* NAND is the source */
diff --git a/arch/arm/boards/imx21ads/imx21ads.c b/arch/arm/boards/imx21ads/imx21ads.c
index ab47a8d..854f7ab 100644
--- a/arch/arm/boards/imx21ads/imx21ads.c
+++ b/arch/arm/boards/imx21ads/imx21ads.c
@@ -41,13 +41,6 @@
 #define MX21ADS_IO_REG    0xCC800000
 #define MX21ADS_IO_LCDON  (1 << 9)
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC8000000,
-	.size     = 32 * 1024 * 1024,
-};
-
 struct imx_nand_platform_data nand_info = {
 	.width = 1,
 	.hw_ecc = 1,
@@ -171,7 +164,7 @@ static int mx21ads_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(mode); i++)
 		imx_gpio_mode(mode[i]);
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xC8000000, 32 * 1024 * 1024, 0);
 	sdram_dev = add_mem_device("ram0", 0xc0000000, 64 * 1024 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
 	armlinux_add_dram(sdram_dev);
diff --git a/arch/arm/boards/imx27ads/imx27ads.c b/arch/arm/boards/imx27ads/imx27ads.c
index 8aaf3a2..db49aac 100644
--- a/arch/arm/boards/imx27ads/imx27ads.c
+++ b/arch/arm/boards/imx27ads/imx27ads.c
@@ -34,13 +34,6 @@
 #include <mach/iomux-mx27.h>
 #include <mach/devices-imx27.h>
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC0000000,
-	.size     = 32 * 1024 * 1024,
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type = MII100,
 	.phy_addr = 1,
@@ -114,7 +107,7 @@ static int mx27ads_devices_init(void)
 	for (i = 0; i < ARRAY_SIZE(mode); i++)
 		imx_gpio_mode(mode[i]);
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
 	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
diff --git a/arch/arm/boards/mmccpu/init.c b/arch/arm/boards/mmccpu/init.c
index 85a18e0..eb6b490 100644
--- a/arch/arm/boards/mmccpu/init.c
+++ b/arch/arm/boards/mmccpu/init.c
@@ -54,8 +54,7 @@ static int mmccpu_devices_init(void)
 
 	at91_add_device_sdram(128 * 1024 * 1024);
 	at91_add_device_eth(&macb_pdata);
-	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 0,
-			   IORESOURCE_MEM, NULL);
+	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 0, 0);
 
 	devfs_add_partition("nor0", 0x00000, 256 * 1024, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x40000, 128 * 1024, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/netx/netx.c b/arch/arm/boards/netx/netx.c
index 5e25b94..f3be348 100644
--- a/arch/arm/boards/netx/netx.c
+++ b/arch/arm/boards/netx/netx.c
@@ -30,13 +30,6 @@
 #include <generated/mach-types.h>
 #include <mach/netx-eth.h>
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC0000000,
-	.size     = 32 * 1024 * 1024,
-};
-
 struct netx_eth_platform_data eth0_data = {
 	.xcno = 0,
 };
@@ -60,7 +53,7 @@ static struct device_d netx_eth_dev1 = {
 static int netx_devices_init(void) {
 	struct device_d *sdram_dev;
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 
 	sdram_dev = add_mem_device("ram0", 0x80000000, 64 * 1024 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index 7895059..6e20d1d 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -40,17 +40,6 @@
 #include <mach/devices-imx31.h>
 
 /*
- * Up to 32MiB NOR type flash, connected to
- * CS line 0, data width is 16 bit
- */
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = IMX_CS0_BASE,
-	.size     = 32 * 1024 * 1024,	/* area size */
-};
-
-/*
  * SMSC 9217 network controller
  * connected to CS line 1 and interrupt line
  * GPIO3, data width is 16 bit
@@ -227,7 +216,11 @@ static int imx31_devices_init(void)
 	__REG(CSCR_L(5)) = 0x444A0301;
 	__REG(CSCR_A(5)) = 0x44443302;
 
-	register_device(&cfi_dev);
+	/*
+	 * Up to 32MiB NOR type flash, connected to
+	 * CS line 0, data width is 16 bit
+	 */
+	add_cfi_flash_device(-1, IMX_CS0_BASE, 32 * 1024 * 1024, 0);
 
 	/*
 	 * Create partitions that should be
diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 046fbd5..2f87b12 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -47,13 +47,6 @@
 
 #include "pll.h"
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xC0000000,
-	.size     = 32 * 1024 * 1024,
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type = MII100,
 	.phy_addr = 1,
@@ -267,7 +260,7 @@ static int pcm038_devices_init(void)
 	spi_register_board_info(pcm038_spi_board_info, ARRAY_SIZE(pcm038_spi_board_info));
 	imx27_add_spi0(&pcm038_spi_0_data);
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xC0000000, 32 * 1024 * 1024, 0);
 	imx27_add_nand(&nand_info);
 	sdram_dev = add_mem_device("ram0", 0xa0000000, 128 * 1024 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
diff --git a/arch/arm/boards/pcm043/pcm043.c b/arch/arm/boards/pcm043/pcm043.c
index 0cfd675..3bd6402 100644
--- a/arch/arm/boards/pcm043/pcm043.c
+++ b/arch/arm/boards/pcm043/pcm043.c
@@ -46,17 +46,6 @@
 #include <mach/iomux-mx35.h>
 #include <mach/devices-imx35.h>
 
-/*
- * Up to 32MiB NOR type flash, connected to
- * CS line 0, data width is 16 bit
- */
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = IMX_CS0_BASE,
-	.size     = 32 * 1024 * 1024,	/* area size */
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type = MII100,
 };
@@ -158,7 +147,11 @@ static int imx35_devices_init(void)
 	 * This platform supports NOR and NAND
 	 */
 	imx35_add_nand(&nand_info);
-	register_device(&cfi_dev);
+	/*
+	 * Up to 32MiB NOR type flash, connected to
+	 * CS line 0, data width is 16 bit
+	 */
+	add_cfi_flash_device(-1, IMX_CS0_BASE, 32 * 1024 * 1024, 0);
 
 	if ((reg & 0xc00) == 0x800) {   /* reset mode: external boot */
 		switch ( (reg >> 25) & 0x3) {
diff --git a/arch/arm/boards/pm9261/init.c b/arch/arm/boards/pm9261/init.c
index 38e4350..1059aec 100644
--- a/arch/arm/boards/pm9261/init.c
+++ b/arch/arm/boards/pm9261/init.c
@@ -151,8 +151,7 @@ static int pm9261_devices_init(void)
 {
 	at91_add_device_sdram(64 * 1024 * 1024);
 	pm_add_device_nand();
-	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 4 * 1024 * 1024,
-			   IORESOURCE_MEM, NULL);
+	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 4 * 1024 * 1024, 0);
 
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
 	devfs_add_partition("nor0", 0x40000, 0x10000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/pm9263/init.c b/arch/arm/boards/pm9263/init.c
index 9f86d67..418b804 100644
--- a/arch/arm/boards/pm9263/init.c
+++ b/arch/arm/boards/pm9263/init.c
@@ -104,8 +104,7 @@ static int pm9263_devices_init(void)
 	at91_add_device_sdram(64 * 1024 * 1024);
 	pm_add_device_nand();
 	at91_add_device_eth(&macb_pdata);
-	add_generic_device("cfi_flash", 0, NULL, AT91_CHIPSELECT_0, 4 * 1024 * 1024,
-			   IORESOURCE_MEM, NULL);
+	add_cfi_flash_device(0, AT91_CHIPSELECT_0, 4 * 1024 * 1024, 0);
 
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self0");
 	devfs_add_partition("nor0", 0x40000, 0x10000, PARTITION_FIXED, "env0");
diff --git a/arch/arm/boards/scb9328/scb9328.c b/arch/arm/boards/scb9328/scb9328.c
index 2fe8236..d49eaff 100644
--- a/arch/arm/boards/scb9328/scb9328.c
+++ b/arch/arm/boards/scb9328/scb9328.c
@@ -33,14 +33,6 @@
 #include <dm9000.h>
 #include <led.h>
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-
-	.map_base = 0x10000000,
-	.size     = 16 * 1024 * 1024,
-};
-
 static struct dm9000_platform_data dm9000_data = {
 	.buswidth = DM9000_WIDTH_16,
 	.srom     = 1,
@@ -110,7 +102,7 @@ static int scb9328_devices_init(void)
 	CS5U = 0x00008400;
 	CS5L = 0x00000D03;
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0x10000000, 16 * 1024 * 1024, 0);
 	sdram_dev = add_mem_device("ram0", 0x08000000, 16 * 1024 * 1024,
 				   IORESOURCE_MEM_WRITEABLE);
 	armlinux_add_dram(sdram_dev);
diff --git a/arch/arm/boards/versatile/versatilepb.c b/arch/arm/boards/versatile/versatilepb.c
index 5568f21..830be93 100644
--- a/arch/arm/boards/versatile/versatilepb.c
+++ b/arch/arm/boards/versatile/versatilepb.c
@@ -33,13 +33,6 @@
 #include <partition.h>
 #include <sizes.h>
 
-static struct device_d cfi_dev = {
-	.id		= -1,
-	.name		= "cfi_flash",
-	.map_base	= VERSATILE_FLASH_BASE,
-	.size		= VERSATILE_FLASH_SIZE,
-};
-
 static int vpb_console_init(void)
 {
 	versatile_register_uart(0);
@@ -58,7 +51,7 @@ static int vpb_devices_init(void)
 {
 	versatile_add_sdram(64 * 1024 *1024);
 
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, VERSATILE_FLASH_BASE, VERSATILE_FLASH_SIZE, 0);
 	devfs_add_partition("nor0", 0x00000, 0x40000, PARTITION_FIXED, "self");
 	devfs_add_partition("nor0", 0x40000, 0x20000, PARTITION_FIXED, "env0");
 
diff --git a/arch/blackfin/boards/ipe337/ipe337.c b/arch/blackfin/boards/ipe337/ipe337.c
index 81a6a6f..4430f3b 100644
--- a/arch/blackfin/boards/ipe337/ipe337.c
+++ b/arch/blackfin/boards/ipe337/ipe337.c
@@ -5,13 +5,6 @@
 #include <partition.h>
 #include <fs.h>
 
-static struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0x20000000,
-	.size     = 32 * 1024 * 1024,
-};
-
 static struct device_d smc911x_dev = {
 	.id	  = -1,
 	.name     = "smc911x",
@@ -20,7 +13,7 @@ static struct device_d smc911x_dev = {
 };
 
 static int ipe337_devices_init(void) {
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0x20000000, 32 * 1024 * 1024, 0);
 	add_mem_device("ram0", 0x0, 128 * 1024 * 1024,
 		       IORESOURCE_MEM_WRITEABLE);
 
diff --git a/arch/nios2/boards/generic/generic.c b/arch/nios2/boards/generic/generic.c
index 37adfaa..089715b 100644
--- a/arch/nios2/boards/generic/generic.c
+++ b/arch/nios2/boards/generic/generic.c
@@ -4,13 +4,6 @@
 #include <partition.h>
 #include <fs.h>
 
-static struct device_d cfi_dev = {
-	.id       = -1,
-	.name     = "cfi_flash",
-	.map_base = NIOS_SOPC_FLASH_BASE,
-	.size     = NIOS_SOPC_FLASH_SIZE,
-};
-
 static int phy_address = 1;
 
 static struct device_d mac_dev = {
@@ -37,7 +30,7 @@ static struct device_d epcs_flash_device = {
 
 static int generic_devices_init(void)
 {
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, NIOS_SOPC_FLASH_BASE, NIOS_SOPC_FLASH_SIZE, 0);
 	add_mem_device("ram0", NIOS_SOPC_MEMORY_BASE, NIOS_SOPC_MEMORY_SIZE,
 		       IORESOURCE_MEM_WRITEABLE);
 	register_device(&mac_dev);
diff --git a/arch/ppc/boards/pcm030/pcm030.c b/arch/ppc/boards/pcm030/pcm030.c
index 3c23d83..0f09d3e 100644
--- a/arch/ppc/boards/pcm030/pcm030.c
+++ b/arch/ppc/boards/pcm030/pcm030.c
@@ -37,13 +37,6 @@
 #include <mem_malloc.h>
 #include <reloc.h>
 
-struct device_d cfi_dev = {
-	.id	  = -1,
-	.name     = "cfi_flash",
-	.map_base = 0xff000000,
-	.size     = 16 * 1024 * 1024,
-};
-
 static struct mpc5xxx_fec_platform_data fec_info = {
 	.xcv_type = MII100,
 };
@@ -57,7 +50,7 @@ struct device_d eth_dev = {
 
 static int devices_init (void)
 {
-	register_device(&cfi_dev);
+	add_cfi_flash_device(-1, 0xff000000, 16 * 1024 * 1024, 0);
 	add_mem_device("ram0", 0x0, 64 * 1024 * 1024,
 		       IORESOURCE_MEM_WRITEABLE);
 	register_device(&eth_dev);
diff --git a/include/driver.h b/include/driver.h
index 738cfae..af34803 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -220,6 +220,13 @@ static inline struct device_d *add_mem_device(const char *name, resource_size_t
 				  IORESOURCE_MEM | flags, NULL);
 }
 
+static inline struct device_d *add_cfi_flash_device(int id, resource_size_t start,
+		resource_size_t size, unsigned int flags)
+{
+	return add_generic_device("cfi_flash", id, NULL, start, size,
+				  IORESOURCE_MEM | flags, NULL);
+}
+
 /* linear list over all available devices
  */
 extern struct list_head device_list;
-- 
1.7.5.4


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

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

end of thread, other threads:[~2011-07-22 15:55 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-22 15:38 [PATCH 1/6] drivers/bus: move to drivers/base Jean-Christophe PLAGNIOL-VILLARD
2011-07-22 15:38 ` [PATCH 2/6] drivers: move resource generic management to driver/base/resource.c Jean-Christophe PLAGNIOL-VILLARD
2011-07-22 15:38 ` [PATCH 3/6] resource: introduce add_generic_device to register simple device Jean-Christophe PLAGNIOL-VILLARD
2011-07-22 15:38 ` [PATCH 4/6] at91: switch to add_generic_device Jean-Christophe PLAGNIOL-VILLARD
2011-07-22 15:38 ` [PATCH 5/6] imx/devices: " Jean-Christophe PLAGNIOL-VILLARD
2011-07-22 15:38 ` [PATCH 6/6] resource: introduce add_cfi_device to register simple cfi device Jean-Christophe PLAGNIOL-VILLARD

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