mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] resources work
@ 2011-07-19  8:39 Sascha Hauer
  2011-07-19  8:39 ` [PATCH 01/19] register_device: Add IORESOURCE_MEM flag Sascha Hauer
                   ` (18 more replies)
  0 siblings, 19 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Hi all,

Some resources related work in this series:

- add missing IORESOURCE_MEM flag to resources created by the
  wrapper in register_device
- add helper to register memory devices
- get rid of some map_base in the core
- convert the majority of i.MX devices to struct resource

The following changes since commit 7530c82c3d295c2e93f440dc2ee6440a72e41c3a:

  startup.c: make DEBUG_LL output more useful (2011-07-18 23:04:18 +0200)

are available in the git repository at:
  git://git.pengutronix.de/git/barebox.git resources

Sascha Hauer (19):
      register_device: Add IORESOURCE_MEM flag
      device: Add a dev_request_mem_region function
      add a add_mem_device function
      generic memmap: use resources
      mem_read/write: use resources
      nand i.MX: convert to struct resource
      video i.MX: convert to struct resource
      serial i.MX: convert to struct resource
      i2c i.MX: convert to struct resource
      mci i.MX: convert to struct resource
      net i.MX fec: convert to struct resource
      mci i.MX esdhc: convert to struct resource
      spi i.MX: convert to struct resource
      video i.MX ipu: convert to struct resource
      i.MX devices: convert to struct resource
      cfi: convert to struct resource
      ARM pcm038: use add_mem_device helper
      ARM pcm037: use add_mem_device helper
      ARM i.MX51 babbage: use add_mem_device helper

 arch/arm/boards/freescale-mx51-pdk/board.c |   20 ++-------
 arch/arm/boards/pcm037/pcm037.c            |   56 ++++-----------------------
 arch/arm/boards/pcm038/pcm038.c            |   34 ++--------------
 arch/arm/mach-imx/devices.c                |    7 ++-
 commands/mem.c                             |   25 ++++++++++++
 drivers/i2c/busses/i2c-imx.c               |   28 ++++++++-----
 drivers/mci/imx-esdhc.c                    |    2 +-
 drivers/mci/imx.c                          |    2 +-
 drivers/mtd/nand/nand_imx.c                |    2 +-
 drivers/net/fec_imx.c                      |    2 +-
 drivers/nor/cfi_flash.c                    |   36 ++++++++---------
 drivers/serial/serial_imx.c                |    2 +-
 drivers/spi/imx_spi.c                      |    2 +-
 drivers/video/imx-ipu-fb.c                 |    2 +-
 drivers/video/imx.c                        |    2 +-
 fs/fs.c                                    |    5 +-
 include/driver.h                           |   20 ++++++++++
 lib/driver.c                               |   21 +++++++++-
 18 files changed, 132 insertions(+), 136 deletions(-)

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

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

* [PATCH 01/19] register_device: Add IORESOURCE_MEM flag
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 02/19] device: Add a dev_request_mem_region function Sascha Hauer
                   ` (17 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/driver.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/lib/driver.c b/lib/driver.c
index 7b381ab..95e42d5 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -116,6 +116,7 @@ int register_device(struct device_d *new_device)
 		new_device->resource = xzalloc(sizeof(struct resource));
 		new_device->resource[0].start = new_device->map_base;
 		new_device->resource[0].size = new_device->size;
+		new_device->resource[0].flags = IORESOURCE_MEM;
 		new_device->num_resources = 1;
 	} else if (new_device->resource) {
 		new_device->map_base = new_device->resource[0].start;
-- 
1.7.5.4


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

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

* [PATCH 02/19] device: Add a dev_request_mem_region function
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
  2011-07-19  8:39 ` [PATCH 01/19] register_device: Add IORESOURCE_MEM flag Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19 10:11   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-19  8:39 ` [PATCH 03/19] add a add_mem_device function Sascha Hauer
                   ` (16 subsequent siblings)
  18 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

We might want to add real resource tracking later. Also
The first resource may not be a IORESOURCE_MEM at all.
For these reasons introduce a wrapper function for
driver so that they do not have to fiddle with resources
directly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/driver.h |   14 ++++++++++++++
 lib/driver.c     |   16 ++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/include/driver.h b/include/driver.h
index ed3df16..0fc254d 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -188,6 +188,20 @@ static inline const char *dev_name(const struct device_d *dev)
 	return dev_id(dev);
 }
 
+/*
+ * get register base 'num' for a device
+ */
+void __iomem *dev_get_mem_region(struct device_d *dev, int num);
+
+/*
+ * exlusively request register base 'num' for a device
+ */
+static inline void __iomem *dev_request_mem_region(struct device_d *dev, int num)
+{
+	/* no resource tracking yet */
+	return dev_get_mem_region(dev, num);
+}
+
 /* linear list over all available devices
  */
 extern struct list_head device_list;
diff --git a/lib/driver.c b/lib/driver.c
index 95e42d5..50f065a 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -233,6 +233,22 @@ int register_driver(struct driver_d *drv)
 }
 EXPORT_SYMBOL(register_driver);
 
+void __iomem *dev_get_mem_region(struct device_d *dev, int num)
+{
+	int i, n = 0;
+
+	for (i = 0; i < dev->num_resources; i++) {
+		struct resource *res = &dev->resource[i];
+		if ((res->flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM) {
+			if (n == num)
+				return (void __force __iomem *)res->start;
+			n++;
+		}
+	}
+
+	return NULL;
+}
+
 int dev_protect(struct device_d *dev, size_t count, unsigned long offset, int prot)
 {
 	printf("%s: currently broken\n", __func__);
-- 
1.7.5.4


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

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

* [PATCH 03/19] add a add_mem_device function
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
  2011-07-19  8:39 ` [PATCH 01/19] register_device: Add IORESOURCE_MEM flag Sascha Hauer
  2011-07-19  8:39 ` [PATCH 02/19] device: Add a dev_request_mem_region function Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19 10:13   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-19  8:39 ` [PATCH 04/19] generic memmap: use resources Sascha Hauer
                   ` (15 subsequent siblings)
  18 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Add a helper function for boards to register their memory
devices. This makes the board code smaller and also helps
getting rid of map_base.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/mem.c   |   25 +++++++++++++++++++++++++
 include/driver.h |    6 ++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/commands/mem.c b/commands/mem.c
index 8df5f0a..745eec4 100644
--- a/commands/mem.c
+++ b/commands/mem.c
@@ -587,6 +587,31 @@ static struct file_operations memops = {
 	.lseek = dev_lseek_default,
 };
 
+struct device_d *add_mem_device(const char *name, unsigned long start, size_t size,
+		unsigned int flags)
+{
+	struct device_d *dev;
+	struct memory_platform_data *pdata;
+
+	dev = xzalloc(sizeof(*dev));
+	strcpy(dev->name, "mem");
+	dev->id = -1;
+	dev->resource = xzalloc(sizeof(struct resource));
+	dev->num_resources = 1;
+	dev->resource[0].start = start;
+	dev->resource[0].size = size;
+	dev->resource[0].flags = IORESOURCE_MEM;
+	pdata = xzalloc(sizeof(*pdata));
+	dev->platform_data = pdata;
+
+	pdata->flags = flags;
+	pdata->name = xstrdup(name);
+
+	register_device(dev);
+
+	return dev;
+}
+
 static int mem_probe(struct device_d *dev)
 {
 	struct memory_platform_data *pdata = dev->platform_data;
diff --git a/include/driver.h b/include/driver.h
index 0fc254d..5d5544f 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -202,6 +202,12 @@ static inline void __iomem *dev_request_mem_region(struct device_d *dev, int num
 	return dev_get_mem_region(dev, num);
 }
 
+/*
+ * register a memory device
+ */
+struct device_d *add_mem_device(const char *name, unsigned long start,
+		size_t size, unsigned int flags);
+
 /* 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] 26+ messages in thread

* [PATCH 04/19] generic memmap: use resources
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (2 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 03/19] add a add_mem_device function Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 05/19] mem_read/write: " Sascha Hauer
                   ` (14 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/driver.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/driver.c b/lib/driver.c
index 50f065a..cc900e2 100644
--- a/lib/driver.c
+++ b/lib/driver.c
@@ -262,7 +262,7 @@ int generic_memmap_ro(struct cdev *cdev, void **map, int flags)
 
 	if (flags & PROT_WRITE)
 		return -EACCES;
-	*map = (void *)cdev->dev->map_base;
+	*map = dev_get_mem_region(cdev->dev, 0);
 	return 0;
 }
 
@@ -271,7 +271,7 @@ int generic_memmap_rw(struct cdev *cdev, void **map, int flags)
 	if (!cdev->dev)
 		return -EINVAL;
 
-	*map = (void *)cdev->dev->map_base;
+	*map = dev_get_mem_region(cdev->dev, 0);
 	return 0;
 }
 
-- 
1.7.5.4


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

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

* [PATCH 05/19] mem_read/write: use resources
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (3 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 04/19] generic memmap: use resources Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19 10:14   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-19  8:39 ` [PATCH 06/19] nand i.MX: convert to struct resource Sascha Hauer
                   ` (13 subsequent siblings)
  18 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index e71d5a2..bcc6ff4 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1048,8 +1048,7 @@ ssize_t mem_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong
 	dev = cdev->dev;
 
 	size = min((ulong)count, dev->size - offset);
-	debug("mem_read: dev->map_base: %p size: %d offset: %d\n",dev->map_base, size, offset);
-	memcpy_sz(buf, (void *)(dev->map_base + offset), size, flags & O_RWSIZE_MASK);
+	memcpy_sz(buf, dev_get_mem_region(dev, 0) + offset, size, flags & O_RWSIZE_MASK);
 	return size;
 }
 EXPORT_SYMBOL(mem_read);
@@ -1064,7 +1063,7 @@ ssize_t mem_write(struct cdev *cdev, const void *buf, size_t count, ulong offset
 	dev = cdev->dev;
 
 	size = min((ulong)count, dev->size - offset);
-	memcpy_sz((void *)(dev->map_base + offset), buf, size, flags & O_RWSIZE_MASK);
+	memcpy_sz(dev_get_mem_region(dev, 0) + offset, buf, size, flags & O_RWSIZE_MASK);
 	return size;
 }
 EXPORT_SYMBOL(mem_write);
-- 
1.7.5.4


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

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

* [PATCH 06/19] nand i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (4 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 05/19] mem_read/write: " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 07/19] video " Sascha Hauer
                   ` (12 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand_imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/nand/nand_imx.c b/drivers/mtd/nand/nand_imx.c
index a13f321..e471c8a 100644
--- a/drivers/mtd/nand/nand_imx.c
+++ b/drivers/mtd/nand/nand_imx.c
@@ -1034,7 +1034,7 @@ static int __init imxnd_probe(struct device_d *dev)
 		return -ENOMEM;
 
 	host->data_buf = (uint8_t *)(host + 1);
-	host->base = (void __iomem *)dev->map_base;
+	host->base = dev_request_mem_region(dev, 0);
 
 	host->main_area0 = host->base;
 
-- 
1.7.5.4


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

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

* [PATCH 07/19] video i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (5 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 06/19] nand i.MX: convert to struct resource Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 08/19] serial " Sascha Hauer
                   ` (11 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/video/imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index ac51858..c19e83e 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -547,7 +547,7 @@ static int imxfb_probe(struct device_d *dev)
 	info = &fbi->info;
 
 	fbi->mode = pdata->mode;
-	fbi->regs = (void *)dev->map_base;
+	fbi->regs = dev_request_mem_region(dev, 0);
 	fbi->pcr = pdata->mode->pcr;
 	fbi->pwmr = pdata->pwmr;
 	fbi->lscr1 = pdata->lscr1;
-- 
1.7.5.4


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

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

* [PATCH 08/19] serial i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (6 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 07/19] video " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 09/19] i2c " Sascha Hauer
                   ` (10 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/serial/serial_imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/serial/serial_imx.c b/drivers/serial/serial_imx.c
index 984d7f2..8593efe 100644
--- a/drivers/serial/serial_imx.c
+++ b/drivers/serial/serial_imx.c
@@ -322,7 +322,7 @@ static int imx_serial_probe(struct device_d *dev)
 	priv = xmalloc(sizeof(*priv));
 	cdev = &priv->cdev;
 
-	priv->regs = (void __force __iomem *)dev->map_base;
+	priv->regs = dev_request_mem_region(dev, 0);
 	dev->type_data = cdev;
 	cdev->dev = dev;
 	cdev->f_caps = CONSOLE_STDIN | CONSOLE_STDOUT | CONSOLE_STDERR;
-- 
1.7.5.4


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

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

* [PATCH 09/19] i2c i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (7 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 08/19] serial " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 10/19] mci " Sascha Hauer
                   ` (9 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/i2c/busses/i2c-imx.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 93e978e..aaed8c4 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -102,6 +102,7 @@ static u16 i2c_clk_div[50][2] = {
 };
 
 struct imx_i2c_struct {
+	void __iomem		*base;
 	struct i2c_adapter	adapter;
 	unsigned int 		disable_delay;
 	int			stopped;
@@ -140,7 +141,8 @@ static inline void i2c_imx_dump_reg(struct i2c_adapter *adapter)
 
 static int i2c_imx_bus_busy(struct i2c_adapter *adapter, int for_busy)
 {
-	unsigned long base = adapter->dev->map_base;
+	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
+	void __iomem *base = i2c_imx->base;
 	uint64_t start;
 	unsigned int temp;
 
@@ -164,7 +166,8 @@ static int i2c_imx_bus_busy(struct i2c_adapter *adapter, int for_busy)
 
 static int i2c_imx_trx_complete(struct i2c_adapter *adapter)
 {
-	unsigned long base = adapter->dev->map_base;
+	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
+	void __iomem *base = i2c_imx->base;
 	uint64_t start;
 
 	start = get_time_ns();
@@ -185,7 +188,8 @@ static int i2c_imx_trx_complete(struct i2c_adapter *adapter)
 
 static int i2c_imx_acked(struct i2c_adapter *adapter)
 {
-	unsigned long base = adapter->dev->map_base;
+	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
+	void __iomem *base = i2c_imx->base;
 	uint64_t start;
 
 	start = get_time_ns();
@@ -206,7 +210,7 @@ static int i2c_imx_acked(struct i2c_adapter *adapter)
 static int i2c_imx_start(struct i2c_adapter *adapter)
 {
 	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
-	unsigned long base = adapter->dev->map_base;
+	void __iomem *base = i2c_imx->base;
 	unsigned int temp = 0;
 	int result;
 
@@ -238,7 +242,7 @@ static int i2c_imx_start(struct i2c_adapter *adapter)
 static void i2c_imx_stop(struct i2c_adapter *adapter)
 {
 	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
-	unsigned long base = adapter->dev->map_base;
+	void __iomem *base = i2c_imx->base;
 	unsigned int temp = 0;
 
 	if (!i2c_imx->stopped) {
@@ -306,7 +310,8 @@ static void i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
 
 static int i2c_imx_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
 {
-	unsigned long base = adapter->dev->map_base;
+	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
+	void __iomem *base = i2c_imx->base;
 	int i, result;
 
 	dev_dbg(adapter->dev,
@@ -343,7 +348,7 @@ static int i2c_imx_write(struct i2c_adapter *adapter, struct i2c_msg *msgs)
 static int i2c_imx_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
 {
 	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
-	unsigned long base = adapter->dev->map_base;
+	void __iomem *base = i2c_imx->base;
 	int i, result;
 	unsigned int temp;
 
@@ -411,7 +416,8 @@ static int i2c_imx_read(struct i2c_adapter *adapter, struct i2c_msg *msgs)
 static int i2c_imx_xfer(struct i2c_adapter *adapter,
 			struct i2c_msg *msgs, int num)
 {
-	unsigned long base = adapter->dev->map_base;
+	struct imx_i2c_struct *i2c_imx = to_imx_i2c_struct(adapter);
+	void __iomem *base = i2c_imx->base;
 	unsigned int i, temp;
 	int result;
 
@@ -453,7 +459,6 @@ static int __init i2c_imx_probe(struct device_d *pdev)
 {
 	struct imx_i2c_struct *i2c_imx;
 	struct i2c_platform_data *pdata;
-	unsigned long base = pdev->map_base;
 	int ret;
 
 	pdata = pdev->platform_data;
@@ -464,6 +469,7 @@ static int __init i2c_imx_probe(struct device_d *pdev)
 	i2c_imx->adapter.master_xfer = i2c_imx_xfer;
 	i2c_imx->adapter.nr = pdev->id;
 	i2c_imx->adapter.dev = pdev;
+	i2c_imx->base = dev_request_mem_region(pdev, 0);
 
 	/* Set up clock divider */
 	if (pdata && pdata->bitrate)
@@ -472,8 +478,8 @@ static int __init i2c_imx_probe(struct device_d *pdev)
 		i2c_imx_set_clk(i2c_imx, IMX_I2C_BIT_RATE);
 
 	/* Set up chip registers to defaults */
-	writeb(0, base + IMX_I2C_I2CR);
-	writeb(0, base + IMX_I2C_I2SR);
+	writeb(0, i2c_imx->base + IMX_I2C_I2CR);
+	writeb(0, i2c_imx->base + IMX_I2C_I2SR);
 
 	/* Add I2C adapter */
 	ret = i2c_add_numbered_adapter(&i2c_imx->adapter);
-- 
1.7.5.4


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

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

* [PATCH 10/19] mci i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (8 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 09/19] i2c " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 11/19] net i.MX fec: " Sascha Hauer
                   ` (8 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mci/imx.c b/drivers/mci/imx.c
index 8525692..1f96e96 100644
--- a/drivers/mci/imx.c
+++ b/drivers/mci/imx.c
@@ -493,7 +493,7 @@ static int mxcmci_probe(struct device_d *dev)
 	host->mci.init = mxcmci_init;
 	host->mci.host_caps = MMC_MODE_4BIT;
 
-	host->base = (struct mxcmci_regs *)dev->map_base;
+	host->base = dev_request_mem_region(dev, 0);
 
 	host->mci.voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
 
-- 
1.7.5.4


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

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

* [PATCH 11/19] net i.MX fec: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (9 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 10/19] mci " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 12/19] mci i.MX esdhc: " Sascha Hauer
                   ` (7 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/net/fec_imx.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/net/fec_imx.c b/drivers/net/fec_imx.c
index c1aa594..fcb8cc5 100644
--- a/drivers/net/fec_imx.c
+++ b/drivers/net/fec_imx.c
@@ -613,7 +613,7 @@ static int fec_probe(struct device_d *dev)
 	edev->get_ethaddr = fec_get_hwaddr;
 	edev->set_ethaddr = fec_set_hwaddr;
 
-	fec->regs = (void *)dev->map_base;
+	fec->regs = dev_request_mem_region(dev, 0);
 
 	/* Reset chip. */
 	writel(FEC_ECNTRL_RESET, fec->regs + FEC_ECNTRL);
-- 
1.7.5.4


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

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

* [PATCH 12/19] mci i.MX esdhc: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (10 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 11/19] net i.MX fec: " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 13/19] spi i.MX: " Sascha Hauer
                   ` (6 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mci/imx-esdhc.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/mci/imx-esdhc.c b/drivers/mci/imx-esdhc.c
index 7595a93..5c2a2f4 100644
--- a/drivers/mci/imx-esdhc.c
+++ b/drivers/mci/imx-esdhc.c
@@ -457,7 +457,7 @@ static int fsl_esdhc_probe(struct device_d *dev)
 	mci = &host->mci;
 
 	host->dev = dev;
-	host->regs = (struct fsl_esdhc *)dev->map_base;
+	host->regs = dev_request_mem_region(dev, 0);
 
 	/* First reset the eSDHC controller */
 	ret = esdhc_reset(host->regs);
-- 
1.7.5.4


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

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

* [PATCH 13/19] spi i.MX: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (11 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 12/19] mci i.MX esdhc: " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 14/19] video i.MX ipu: " Sascha Hauer
                   ` (5 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/spi/imx_spi.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 1857d6c..bbe2789 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -379,7 +379,7 @@ static int imx_spi_probe(struct device_d *dev)
 	imx->chipselect = spi_imx_devtype_data[version].chipselect;
 	imx->xchg_single = spi_imx_devtype_data[version].xchg_single;
 	imx->init = spi_imx_devtype_data[version].init;
-	imx->regs = (void __iomem *)dev->map_base;
+	imx->regs = dev_request_mem_region(dev, 0);
 
 	imx->init(imx);
 
-- 
1.7.5.4


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

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

* [PATCH 14/19] video i.MX ipu: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (12 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 13/19] spi i.MX: " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:39 ` [PATCH 15/19] i.MX devices: " Sascha Hauer
                   ` (4 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/video/imx-ipu-fb.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index d9e1e21..5ae8c4b 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -858,7 +858,7 @@ static int imxfb_probe(struct device_d *dev)
 	fbi = xzalloc(sizeof(*fbi));
 	info = &fbi->info;
 
-	fbi->regs = (void *)dev->map_base;
+	fbi->regs = dev_request_mem_region(dev, 0);
 	fbi->dev = dev;
 	info->priv = fbi;
 	info->fbops = &imxfb_ops;
-- 
1.7.5.4


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

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

* [PATCH 15/19] i.MX devices: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (13 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 14/19] video i.MX ipu: " Sascha Hauer
@ 2011-07-19  8:39 ` Sascha Hauer
  2011-07-19  8:40 ` [PATCH 16/19] cfi: " Sascha Hauer
                   ` (3 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:39 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-imx/devices.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-imx/devices.c b/arch/arm/mach-imx/devices.c
index 0395b0e..6503c30 100644
--- a/arch/arm/mach-imx/devices.c
+++ b/arch/arm/mach-imx/devices.c
@@ -9,8 +9,11 @@ static struct device_d *imx_add_device(char *name, int id, void *base, int size,
 	dev = xzalloc(sizeof(*dev));
 	strcpy(dev->name,name);
 	dev->id = id;
-	dev->map_base = (unsigned long)base;
-	dev->size = size;
+	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);
-- 
1.7.5.4


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

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

* [PATCH 16/19] cfi: convert to struct resource
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (14 preceding siblings ...)
  2011-07-19  8:39 ` [PATCH 15/19] i.MX devices: " Sascha Hauer
@ 2011-07-19  8:40 ` Sascha Hauer
  2011-07-19  8:40 ` [PATCH 17/19] ARM pcm038: use add_mem_device helper Sascha Hauer
                   ` (2 subsequent siblings)
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:40 UTC (permalink / raw)
  To: barebox

This is the non invasive approach. All this type casting
shows this driver should be really cleaned up (or retired)

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/nor/cfi_flash.c |   36 +++++++++++++++++-------------------
 1 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
index 39c2bf1..c995962 100644
--- a/drivers/nor/cfi_flash.c
+++ b/drivers/nor/cfi_flash.c
@@ -283,7 +283,7 @@ static int flash_detect_cfi (struct flash_info *info, struct cfi_qry *qry)
 /*
  * The following code cannot be run from FLASH!
  */
-static ulong flash_get_size (struct flash_info *info, ulong base)
+static ulong flash_get_size (struct flash_info *info)
 {
 	int i, j;
 	flash_sect_t sect_cnt;
@@ -295,6 +295,7 @@ static ulong flash_get_size (struct flash_info *info, ulong base)
 	int erase_region_count;
 	int cur_offset = 0;
 	struct cfi_qry qry;
+	unsigned long base = (unsigned long)info->base;
 
 	memset(&qry, 0, sizeof(qry));
 
@@ -464,8 +465,9 @@ static int __cfi_erase(struct cdev *cdev, size_t count, unsigned long offset,
 
 	debug("%s: erase 0x%08lx (size %d)\n", __func__, offset, count);
 
-        start = find_sector(finfo, cdev->dev->map_base + offset);
-        end   = find_sector(finfo, cdev->dev->map_base + offset + count - 1);
+        start = find_sector(finfo, (unsigned long)finfo->base + offset);
+        end   = find_sector(finfo, (unsigned long)finfo->base + offset +
+			count - 1);
 
 	if (verbose)
 		init_progression_bar(end - start);
@@ -633,11 +635,11 @@ static int cfi_protect(struct cdev *cdev, size_t count, unsigned long offset, in
 	int i, ret = 0;
 	const char *action = (prot? "protect" : "unprotect");
 
-	printf("%s: %s 0x%08lx (size %d)\n", __FUNCTION__,
-	       action, cdev->dev->map_base + offset, count);
+	printf("%s: %s 0x%p (size %d)\n", __func__,
+	       action, finfo->base + offset, count);
 
-	start = find_sector(finfo, cdev->dev->map_base + offset);
-	end   = find_sector(finfo, cdev->dev->map_base + offset + count - 1);
+	start = find_sector(finfo, (unsigned long)finfo->base + offset);
+	end   = find_sector(finfo, (unsigned long)finfo->base + offset + count - 1);
 
 	for (i = start; i <= end; i++) {
 		ret = flash_real_protect (finfo, i, prot);
@@ -654,10 +656,10 @@ static ssize_t cfi_write(struct cdev *cdev, const void *buf, size_t count, unsig
         struct flash_info *finfo = (struct flash_info *)cdev->priv;
         int ret;
 
-	debug("cfi_write: buf=0x%p addr=0x%08lx count=0x%08x\n",buf, cdev->dev->map_base + offset, count);
+	debug("cfi_write: buf=0x%p addr=0x%08lx count=0x%08x\n",buf, finfo->base + offset, count);
 
-        ret = write_buff (finfo, buf, cdev->dev->map_base + offset, count);
-        return ret == 0 ? count : -1;
+	ret = write_buff(finfo, buf, (unsigned long)finfo->base + offset, count);
+	return ret == 0 ? count : -1;
 }
 
 static void cfi_info (struct device_d* dev)
@@ -978,18 +980,11 @@ static int cfi_probe (struct device_d *dev)
 
 	dev->priv = (void *)info;
 
-	printf("cfi_probe: %s base: 0x%08x size: 0x%08x\n", dev->name, dev->map_base, dev->size);
-
 	/* Init: no FLASHes known */
 	info->flash_id = FLASH_UNKNOWN;
 	info->cmd_reset = FLASH_CMD_RESET;
-	info->size = flash_get_size(info, dev->map_base);
-	info->base = (void __iomem *)dev->map_base;
-
-	if (dev->size == 0) {
-		printf("cfi_probe: size : 0x%08lx\n", info->size);
-		dev->size = info->size;
-	}
+	info->base = dev_request_mem_region(dev, 0);
+	info->size = flash_get_size(info);
 
 	if (info->flash_id == FLASH_UNKNOWN) {
 		printf ("## Unknown FLASH on Bank at 0x%08x - Size = 0x%08lx = %ld MB\n",
@@ -997,6 +992,9 @@ static int cfi_probe (struct device_d *dev)
 		return -ENODEV;
 	}
 
+	dev_info(dev, "found cfi flash at %p, size %ld\n",
+			info->base, info->size);
+
 	info->cdev.name = asprintf("nor%d", dev->id);
 	info->cdev.size = info->size;
 	info->cdev.dev = dev;
-- 
1.7.5.4


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

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

* [PATCH 17/19] ARM pcm038: use add_mem_device helper
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (15 preceding siblings ...)
  2011-07-19  8:40 ` [PATCH 16/19] cfi: " Sascha Hauer
@ 2011-07-19  8:40 ` Sascha Hauer
  2011-07-19  8:40 ` [PATCH 18/19] ARM pcm037: " Sascha Hauer
  2011-07-19  8:40 ` [PATCH 19/19] ARM i.MX51 babbage: " Sascha Hauer
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:40 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/pcm038/pcm038.c |   34 +++++-----------------------------
 1 files changed, 5 insertions(+), 29 deletions(-)

diff --git a/arch/arm/boards/pcm038/pcm038.c b/arch/arm/boards/pcm038/pcm038.c
index 3ca6650..6cb96f1 100644
--- a/arch/arm/boards/pcm038/pcm038.c
+++ b/arch/arm/boards/pcm038/pcm038.c
@@ -34,6 +34,7 @@
 #include <fcntl.h>
 #include <nand.h>
 #include <command.h>
+#include <sizes.h>
 #include <spi/spi.h>
 #include <asm/io.h>
 #include <mach/imx-nand.h>
@@ -54,32 +55,6 @@ static struct device_d cfi_dev = {
 	.size     = 32 * 1024 * 1024,
 };
 
-static struct memory_platform_data ram_pdata = {
-	.name = "ram0",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sdram_dev = {
-	.id	  = -1,
-	.name     = "mem",
-	.map_base = 0xa0000000,
-	.size     = 128 * 1024 * 1024,
-	.platform_data = &ram_pdata,
-};
-
-static struct memory_platform_data sram_pdata = {
-	.name = "sram0",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sram_dev = {
-	.id	  = -1,
-	.name     = "mem",
-	.map_base = 0xc8000000,
-	.size     = 512 * 1024, /* Can be up to 2MiB */
-	.platform_data = &sram_pdata,
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type = MII100,
 	.phy_addr = 1,
@@ -191,6 +166,7 @@ static int pcm038_devices_init(void)
 {
 	int i;
 	char *envdev;
+	struct device_d *sdramdev;
 
 	unsigned int mode[] = {
 		PD0_AIN_FEC_TXD0,
@@ -294,8 +270,8 @@ static int pcm038_devices_init(void)
 
 	register_device(&cfi_dev);
 	imx27_add_nand(&nand_info);
-	register_device(&sdram_dev);
-	register_device(&sram_dev);
+	sdramdev = add_mem_device("ram0", 0xa0000000, SZ_128M, DEVFS_RDWR);
+	add_mem_device("sram0", 0xc8000000, SZ_512K, DEVFS_RDWR);
 	imx27_add_fb(&pcm038_fb_data);
 
 #ifdef CONFIG_USB
@@ -330,7 +306,7 @@ static int pcm038_devices_init(void)
 
 	printf("Using environment in %s Flash\n", envdev);
 
-	armlinux_add_dram(&sdram_dev);
+	armlinux_add_dram(sdramdev);
 	armlinux_set_bootparams((void *)0xa0000100);
 	armlinux_set_architecture(MACH_TYPE_PCM038);
 
-- 
1.7.5.4


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

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

* [PATCH 18/19] ARM pcm037: use add_mem_device helper
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (16 preceding siblings ...)
  2011-07-19  8:40 ` [PATCH 17/19] ARM pcm038: use add_mem_device helper Sascha Hauer
@ 2011-07-19  8:40 ` Sascha Hauer
  2011-07-19  8:40 ` [PATCH 19/19] ARM i.MX51 babbage: " Sascha Hauer
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:40 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/pcm037/pcm037.c |   56 ++++++--------------------------------
 1 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/arch/arm/boards/pcm037/pcm037.c b/arch/arm/boards/pcm037/pcm037.c
index cb4ffe6..fdf937a 100644
--- a/arch/arm/boards/pcm037/pcm037.c
+++ b/arch/arm/boards/pcm037/pcm037.c
@@ -51,23 +51,6 @@ static struct device_d cfi_dev = {
 };
 
 /*
- * up to 2MiB static RAM type memory, connected
- * to CS4, data width is 16 bit
- */
-static struct memory_platform_data sram_dev_pdata0 = {
-	.name = "sram0",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sram_dev = {
-	.id	  = -1,
-	.name     = "mem",
-	.map_base = IMX_CS4_BASE,
-	.size     = IMX_CS4_RANGE,	/* area size */
-	.platform_data = &sram_dev_pdata0,
-};
-
-/*
  * SMSC 9217 network controller
  * connected to CS line 1 and interrupt line
  * GPIO3, data width is 16 bit
@@ -85,19 +68,6 @@ static struct device_d network_dev = {
 #define SDRAM0	256
 #endif
 
-static struct memory_platform_data ram_dev_pdata0 = {
-	.name = "ram0",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sdram0_dev = {
-	.id	  = -1,
-	.name     = "mem",
-	.map_base = IMX_SDRAM_CS0,
-	.size     = SDRAM0 * 1024 * 1024,	/* fix size */
-	.platform_data = &ram_dev_pdata0,
-};
-
 #ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
 
 #if defined CONFIG_PCM037_SDRAM_BANK1_128MB
@@ -106,18 +76,6 @@ static struct device_d sdram0_dev = {
 #define SDRAM1	256
 #endif
 
-static struct memory_platform_data ram_dev_pdata1 = {
-	.name = "ram1",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sdram1_dev = {
-	.id	  = -1,
-	.name     = "mem",
-	.map_base = IMX_SDRAM_CS1,
-	.size     = SDRAM1 * 1024 * 1024,	/* fix size */
-	.platform_data = &ram_dev_pdata1,
-};
 #endif
 
 struct imx_nand_platform_data nand_info = {
@@ -253,6 +211,10 @@ static void pcm037_mmu_init(void)
 
 static int imx31_devices_init(void)
 {
+	struct device_d *sdram0_dev;
+#ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
+	struct device_d *sdram1_dev;
+#endif
 	pcm037_mmu_init();
 
 	__REG(CSCR_U(0)) = 0x0000cf03; /* CS0: Nor Flash */
@@ -282,13 +244,13 @@ static int imx31_devices_init(void)
 
 	protect_file("/dev/env0", 1);
 
-	register_device(&sram_dev);
+	add_mem_device("sram0", IMX_CS4_BASE, IMX_CS4_RANGE, DEVFS_RDWR);
 	imx31_add_nand(&nand_info);
 	register_device(&network_dev);
 
-	register_device(&sdram0_dev);
+	sdram0_dev = add_mem_device("ram0", IMX_SDRAM_CS0, SDRAM0 * 1024 * 1024, DEVFS_RDWR);
 #ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
-	register_device(&sdram1_dev);
+	sdram1_dev = add_mem_device("ram1", IMX_SDRAM_CS1, SDRAM1 * 1024 * 1024, DEVFS_RDWR);
 #endif
 #ifdef CONFIG_USB
 	pcm037_usb_init();
@@ -296,9 +258,9 @@ static int imx31_devices_init(void)
 	register_device(&usbh2_dev);
 #endif
 
-	armlinux_add_dram(&sdram0_dev);
+	armlinux_add_dram(sdram0_dev);
 #ifndef CONFIG_PCM037_SDRAM_BANK1_NONE
-	armlinux_add_dram(&sdram1_dev);
+	armlinux_add_dram(sdram1_dev);
 #endif
 	armlinux_set_bootparams((void *)0x80000100);
 	armlinux_set_architecture(MACH_TYPE_PCM037);
-- 
1.7.5.4


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

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

* [PATCH 19/19] ARM i.MX51 babbage: use add_mem_device helper
  2011-07-19  8:39 [PATCH] resources work Sascha Hauer
                   ` (17 preceding siblings ...)
  2011-07-19  8:40 ` [PATCH 18/19] ARM pcm037: " Sascha Hauer
@ 2011-07-19  8:40 ` Sascha Hauer
  18 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19  8:40 UTC (permalink / raw)
  To: barebox

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/freescale-mx51-pdk/board.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/arm/boards/freescale-mx51-pdk/board.c b/arch/arm/boards/freescale-mx51-pdk/board.c
index 35d6153..686cb60 100644
--- a/arch/arm/boards/freescale-mx51-pdk/board.c
+++ b/arch/arm/boards/freescale-mx51-pdk/board.c
@@ -30,6 +30,7 @@
 #include <partition.h>
 #include <fs.h>
 #include <fcntl.h>
+#include <sizes.h>
 #include <nand.h>
 #include <spi/spi.h>
 #include <mfd/mc13892.h>
@@ -41,19 +42,6 @@
 #include <mach/iomux-mx51.h>
 #include <mach/devices-imx51.h>
 
-static struct memory_platform_data ram_pdata = {
-	.name = "ram0",
-	.flags = DEVFS_RDWR,
-};
-
-static struct device_d sdram_dev = {
-	.id       = -1,
-	.name     = "mem",
-	.map_base = 0x90000000,
-	.size     = 512 * 1024 * 1024,
-	.platform_data = &ram_pdata,
-};
-
 static struct fec_platform_data fec_info = {
 	.xcv_type = MII100,
 };
@@ -242,9 +230,11 @@ static void babbage_power_init(void)
 
 static int f3s_devices_init(void)
 {
+	struct device_d *sdram_dev;
+
 	babbage_mmu_init();
 
-	register_device(&sdram_dev);
+	sdram_dev = add_mem_device("ram0", 0x90000000, SZ_512M, DEVFS_RDWR);
 	imx51_add_fec(&fec_info);
 	imx51_add_mmc0(NULL);
 
@@ -254,7 +244,7 @@ static int f3s_devices_init(void)
 
 	babbage_power_init();
 
-	armlinux_add_dram(&sdram_dev);
+	armlinux_add_dram(sdram_dev);
 	armlinux_set_bootparams((void *)0x90000100);
 	armlinux_set_architecture(MACH_TYPE_MX51_BABBAGE);
 
-- 
1.7.5.4


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

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

* Re: [PATCH 02/19] device: Add a dev_request_mem_region function
  2011-07-19  8:39 ` [PATCH 02/19] device: Add a dev_request_mem_region function Sascha Hauer
@ 2011-07-19 10:11   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-19 10:58     ` Sascha Hauer
  0 siblings, 1 reply; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-19 10:11 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> We might want to add real resource tracking later. Also
> The first resource may not be a IORESOURCE_MEM at all.
> For these reasons introduce a wrapper function for
> driver so that they do not have to fiddle with resources
> directly.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  include/driver.h |   14 ++++++++++++++
>  lib/driver.c     |   16 ++++++++++++++++
>  2 files changed, 30 insertions(+), 0 deletions(-)
> 
> diff --git a/include/driver.h b/include/driver.h
> index ed3df16..0fc254d 100644
> --- a/include/driver.h
> +++ b/include/driver.h
> @@ -188,6 +188,20 @@ static inline const char *dev_name(const struct device_d *dev)
>  	return dev_id(dev);
>  }
>  
> +/*
> + * get register base 'num' for a device
> + */
> +void __iomem *dev_get_mem_region(struct device_d *dev, int num);
> +
> +/*
> + * exlusively request register base 'num' for a device
> + */
> +static inline void __iomem *dev_request_mem_region(struct device_d *dev, int num)
> +{
> +	/* no resource tracking yet */
> +	return dev_get_mem_region(dev, num);
> +}
> +
>  /* linear list over all available devices
>   */
>  extern struct list_head device_list;
> diff --git a/lib/driver.c b/lib/driver.c
> index 95e42d5..50f065a 100644
> --- a/lib/driver.c
> +++ b/lib/driver.c
> @@ -233,6 +233,22 @@ int register_driver(struct driver_d *drv)
>  }
>  EXPORT_SYMBOL(register_driver);
>  
> +void __iomem *dev_get_mem_region(struct device_d *dev, int num)
> +{
> +	int i, n = 0;
> +
can we check num < dev->num_resources to
> +	for (i = 0; i < dev->num_resources; i++) {
> +		struct resource *res = &dev->resource[i];
> +		if ((res->flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM) {
resource_type here
> +			if (n == num)
> +				return (void __force __iomem *)res->start;
> +			n++;
> +		}
> +	}
> +
> +	return NULL;
> +}
EXPORT_SYMBOL too

Best Regards,
J.

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

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

* Re: [PATCH 03/19] add a add_mem_device function
  2011-07-19  8:39 ` [PATCH 03/19] add a add_mem_device function Sascha Hauer
@ 2011-07-19 10:13   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-07-19 11:00     ` Sascha Hauer
  0 siblings, 1 reply; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-19 10:13 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> Add a helper function for boards to register their memory
> devices. This makes the board code smaller and also helps
> getting rid of map_base.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  commands/mem.c   |   25 +++++++++++++++++++++++++
>  include/driver.h |    6 ++++++
>  2 files changed, 31 insertions(+), 0 deletions(-)
> 
> diff --git a/commands/mem.c b/commands/mem.c
> index 8df5f0a..745eec4 100644
> --- a/commands/mem.c
> +++ b/commands/mem.c
> @@ -587,6 +587,31 @@ static struct file_operations memops = {
>  	.lseek = dev_lseek_default,
>  };
>  
> +struct device_d *add_mem_device(const char *name, unsigned long start, size_t size,
> +		unsigned int flags)
> +{
> +	struct device_d *dev;
> +	struct memory_platform_data *pdata;
> +
> +	dev = xzalloc(sizeof(*dev));
> +	strcpy(dev->name, "mem");
> +	dev->id = -1;
> +	dev->resource = xzalloc(sizeof(struct resource));
> +	dev->num_resources = 1;
> +	dev->resource[0].start = start;
> +	dev->resource[0].size = size;
> +	dev->resource[0].flags = IORESOURCE_MEM;
> +	pdata = xzalloc(sizeof(*pdata));
> +	dev->platform_data = pdata;
> +
> +	pdata->flags = flags;
> +	pdata->name = xstrdup(name);
can we drop the name here and use the resource name instead

I think we can drop the platfrom_data too

Best Regards,
J.

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

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

* Re: [PATCH 05/19] mem_read/write: use resources
  2011-07-19  8:39 ` [PATCH 05/19] mem_read/write: " Sascha Hauer
@ 2011-07-19 10:14   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-19 10:14 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  fs/fs.c |    5 ++---
>  1 files changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index e71d5a2..bcc6ff4 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -1048,8 +1048,7 @@ ssize_t mem_read(struct cdev *cdev, void *buf, size_t count, ulong offset, ulong
>  	dev = cdev->dev;
>  
>  	size = min((ulong)count, dev->size - offset);
> -	debug("mem_read: dev->map_base: %p size: %d offset: %d\n",dev->map_base, size, offset);
in two patch?
> -	memcpy_sz(buf, (void *)(dev->map_base + offset), size, flags & O_RWSIZE_MASK);
> +	memcpy_sz(buf, dev_get_mem_region(dev, 0) + offset, size, flags & O_RWSIZE_MASK);
>  	return size;
>  }
Best Regards,
J.

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

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

* Re: [PATCH 02/19] device: Add a dev_request_mem_region function
  2011-07-19 10:11   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-19 10:58     ` Sascha Hauer
  0 siblings, 0 replies; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19 10:58 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Jul 19, 2011 at 12:11:55PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> > We might want to add real resource tracking later. Also
> > The first resource may not be a IORESOURCE_MEM at all.
> > For these reasons introduce a wrapper function for
> > driver so that they do not have to fiddle with resources
> > directly.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  include/driver.h |   14 ++++++++++++++
> >  lib/driver.c     |   16 ++++++++++++++++
> >  2 files changed, 30 insertions(+), 0 deletions(-)
> > 
> > diff --git a/include/driver.h b/include/driver.h
> > index ed3df16..0fc254d 100644
> > --- a/include/driver.h
> > +++ b/include/driver.h
> > @@ -188,6 +188,20 @@ static inline const char *dev_name(const struct device_d *dev)
> >  	return dev_id(dev);
> >  }
> >  
> > +/*
> > + * get register base 'num' for a device
> > + */
> > +void __iomem *dev_get_mem_region(struct device_d *dev, int num);
> > +
> > +/*
> > + * exlusively request register base 'num' for a device
> > + */
> > +static inline void __iomem *dev_request_mem_region(struct device_d *dev, int num)
> > +{
> > +	/* no resource tracking yet */
> > +	return dev_get_mem_region(dev, num);
> > +}
> > +
> >  /* linear list over all available devices
> >   */
> >  extern struct list_head device_list;
> > diff --git a/lib/driver.c b/lib/driver.c
> > index 95e42d5..50f065a 100644
> > --- a/lib/driver.c
> > +++ b/lib/driver.c
> > @@ -233,6 +233,22 @@ int register_driver(struct driver_d *drv)
> >  }
> >  EXPORT_SYMBOL(register_driver);
> >  
> > +void __iomem *dev_get_mem_region(struct device_d *dev, int num)
> > +{
> > +	int i, n = 0;
> > +
> can we check num < dev->num_resources to

This is done implicitly in the loop below.

> > +	for (i = 0; i < dev->num_resources; i++) {
> > +		struct resource *res = &dev->resource[i];
> > +		if ((res->flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM) {
> resource_type here

ok

> > +			if (n == num)
> > +				return (void __force __iomem *)res->start;
> > +			n++;
> > +		}
> > +	}
> > +
> > +	return NULL;
> > +}
> EXPORT_SYMBOL too

ok

Sascha
> 
> Best Regards,
> J.
> 

-- 
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] 26+ messages in thread

* Re: [PATCH 03/19] add a add_mem_device function
  2011-07-19 10:13   ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-07-19 11:00     ` Sascha Hauer
  2011-07-19 13:06       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 26+ messages in thread
From: Sascha Hauer @ 2011-07-19 11:00 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Tue, Jul 19, 2011 at 12:13:47PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> > Add a helper function for boards to register their memory
> > devices. This makes the board code smaller and also helps
> > getting rid of map_base.
> > 
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > ---
> >  commands/mem.c   |   25 +++++++++++++++++++++++++
> >  include/driver.h |    6 ++++++
> >  2 files changed, 31 insertions(+), 0 deletions(-)
> > 
> > diff --git a/commands/mem.c b/commands/mem.c
> > index 8df5f0a..745eec4 100644
> > --- a/commands/mem.c
> > +++ b/commands/mem.c
> > @@ -587,6 +587,31 @@ static struct file_operations memops = {
> >  	.lseek = dev_lseek_default,
> >  };
> >  
> > +struct device_d *add_mem_device(const char *name, unsigned long start, size_t size,
> > +		unsigned int flags)
> > +{
> > +	struct device_d *dev;
> > +	struct memory_platform_data *pdata;
> > +
> > +	dev = xzalloc(sizeof(*dev));
> > +	strcpy(dev->name, "mem");
> > +	dev->id = -1;
> > +	dev->resource = xzalloc(sizeof(struct resource));
> > +	dev->num_resources = 1;
> > +	dev->resource[0].start = start;
> > +	dev->resource[0].size = size;
> > +	dev->resource[0].flags = IORESOURCE_MEM;
> > +	pdata = xzalloc(sizeof(*pdata));
> > +	dev->platform_data = pdata;
> > +
> > +	pdata->flags = flags;
> > +	pdata->name = xstrdup(name);
> can we drop the name here and use the resource name instead

I think so, yes.

> 
> I think we can drop the platfrom_data too

This is still needed for the rw/ro flag (though it seems this is not
handled)

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] 26+ messages in thread

* Re: [PATCH 03/19] add a add_mem_device function
  2011-07-19 11:00     ` Sascha Hauer
@ 2011-07-19 13:06       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 26+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-07-19 13:06 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 13:00 Tue 19 Jul     , Sascha Hauer wrote:
> On Tue, Jul 19, 2011 at 12:13:47PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > On 10:39 Tue 19 Jul     , Sascha Hauer wrote:
> > > Add a helper function for boards to register their memory
> > > devices. This makes the board code smaller and also helps
> > > getting rid of map_base.
> > > 
> > > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > > ---
> > >  commands/mem.c   |   25 +++++++++++++++++++++++++
> > >  include/driver.h |    6 ++++++
> > >  2 files changed, 31 insertions(+), 0 deletions(-)
> > > 
> > > diff --git a/commands/mem.c b/commands/mem.c
> > > index 8df5f0a..745eec4 100644
> > > --- a/commands/mem.c
> > > +++ b/commands/mem.c
> > > @@ -587,6 +587,31 @@ static struct file_operations memops = {
> > >  	.lseek = dev_lseek_default,
> > >  };
> > >  
> > > +struct device_d *add_mem_device(const char *name, unsigned long start, size_t size,
> > > +		unsigned int flags)
> > > +{
> > > +	struct device_d *dev;
> > > +	struct memory_platform_data *pdata;
> > > +
> > > +	dev = xzalloc(sizeof(*dev));
> > > +	strcpy(dev->name, "mem");
> > > +	dev->id = -1;
> > > +	dev->resource = xzalloc(sizeof(struct resource));
> > > +	dev->num_resources = 1;
> > > +	dev->resource[0].start = start;
> > > +	dev->resource[0].size = size;
> > > +	dev->resource[0].flags = IORESOURCE_MEM;
> > > +	pdata = xzalloc(sizeof(*pdata));
> > > +	dev->platform_data = pdata;
> > > +
> > > +	pdata->flags = flags;
> > > +	pdata->name = xstrdup(name);
> > can we drop the name here and use the resource name instead
> 
> I think so, yes.
> 
> > 
> > I think we can drop the platfrom_data too
> 
> This is still needed for the rw/ro flag (though it seems this is not
> handled)
I agree so we need to pass via flags also and maybe extend it

Best Regards,
J.

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

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

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

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-19  8:39 [PATCH] resources work Sascha Hauer
2011-07-19  8:39 ` [PATCH 01/19] register_device: Add IORESOURCE_MEM flag Sascha Hauer
2011-07-19  8:39 ` [PATCH 02/19] device: Add a dev_request_mem_region function Sascha Hauer
2011-07-19 10:11   ` Jean-Christophe PLAGNIOL-VILLARD
2011-07-19 10:58     ` Sascha Hauer
2011-07-19  8:39 ` [PATCH 03/19] add a add_mem_device function Sascha Hauer
2011-07-19 10:13   ` Jean-Christophe PLAGNIOL-VILLARD
2011-07-19 11:00     ` Sascha Hauer
2011-07-19 13:06       ` Jean-Christophe PLAGNIOL-VILLARD
2011-07-19  8:39 ` [PATCH 04/19] generic memmap: use resources Sascha Hauer
2011-07-19  8:39 ` [PATCH 05/19] mem_read/write: " Sascha Hauer
2011-07-19 10:14   ` Jean-Christophe PLAGNIOL-VILLARD
2011-07-19  8:39 ` [PATCH 06/19] nand i.MX: convert to struct resource Sascha Hauer
2011-07-19  8:39 ` [PATCH 07/19] video " Sascha Hauer
2011-07-19  8:39 ` [PATCH 08/19] serial " Sascha Hauer
2011-07-19  8:39 ` [PATCH 09/19] i2c " Sascha Hauer
2011-07-19  8:39 ` [PATCH 10/19] mci " Sascha Hauer
2011-07-19  8:39 ` [PATCH 11/19] net i.MX fec: " Sascha Hauer
2011-07-19  8:39 ` [PATCH 12/19] mci i.MX esdhc: " Sascha Hauer
2011-07-19  8:39 ` [PATCH 13/19] spi i.MX: " Sascha Hauer
2011-07-19  8:39 ` [PATCH 14/19] video i.MX ipu: " Sascha Hauer
2011-07-19  8:39 ` [PATCH 15/19] i.MX devices: " Sascha Hauer
2011-07-19  8:40 ` [PATCH 16/19] cfi: " Sascha Hauer
2011-07-19  8:40 ` [PATCH 17/19] ARM pcm038: use add_mem_device helper Sascha Hauer
2011-07-19  8:40 ` [PATCH 18/19] ARM pcm037: " Sascha Hauer
2011-07-19  8:40 ` [PATCH 19/19] ARM i.MX51 babbage: " Sascha Hauer

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