All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] arm/dt: register devices from device tree
@ 2011-01-26  4:44 ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

Hi all,

For right now this is only an early implementation and there are
several bugs that prevent all devices from getting registered
correctly, and not all of the dts data is accurate.  However, it
starts to show what a device-tree enabled machine_desc looks like
using the versatile platform as an example, and I wanted to get it out
for people to see.

A significant change in this series compared with the previous version
is that the devicetree clock lookup code has been decoupled from the
common struct clk patches that Jeremy is currently working on.  This
means that there is more machine-specific code than there needs to be
for handling clocks, but it can be removed after a common struct clk
is merged.

This series is based on:

    git://git.secretlab.ca/git/linux-2.6  devicetree/arm

g.

---

Grant Likely (2):
      arm/dt: Add dt machine definition
      arm/versatile: add a device tree versatile platform

Jeremy Kerr (3):
      drivers/amba: probe via device tree
      of: add clock providers
      arm/clkdev: lookup clocks from OF clock providers


 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/mach/arch.h       |    9 ++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/amba/bus.c                     |   67 ++++++++++++++++
 drivers/clk/clkdev.c                   |    7 ++
 drivers/of/Kconfig                     |    5 +
 drivers/of/Makefile                    |    1 
 drivers/of/clock.c                     |  133 +++++++++++++++++++++++++++++++
 include/linux/amba/bus.h               |    5 +
 include/linux/of_clk.h                 |   36 ++++++++
 15 files changed, 520 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

-- 
Signature

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

* [RFC PATCH 0/5] arm/dt: register devices from device tree
@ 2011-01-26  4:44 ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

Hi all,

For right now this is only an early implementation and there are
several bugs that prevent all devices from getting registered
correctly, and not all of the dts data is accurate.  However, it
starts to show what a device-tree enabled machine_desc looks like
using the versatile platform as an example, and I wanted to get it out
for people to see.

A significant change in this series compared with the previous version
is that the devicetree clock lookup code has been decoupled from the
common struct clk patches that Jeremy is currently working on.  This
means that there is more machine-specific code than there needs to be
for handling clocks, but it can be removed after a common struct clk
is merged.

This series is based on:

    git://git.secretlab.ca/git/linux-2.6  devicetree/arm

g.

---

Grant Likely (2):
      arm/dt: Add dt machine definition
      arm/versatile: add a device tree versatile platform

Jeremy Kerr (3):
      drivers/amba: probe via device tree
      of: add clock providers
      arm/clkdev: lookup clocks from OF clock providers


 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/mach/arch.h       |    9 ++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/amba/bus.c                     |   67 ++++++++++++++++
 drivers/clk/clkdev.c                   |    7 ++
 drivers/of/Kconfig                     |    5 +
 drivers/of/Makefile                    |    1 
 drivers/of/clock.c                     |  133 +++++++++++++++++++++++++++++++
 include/linux/amba/bus.h               |    5 +
 include/linux/of_clk.h                 |   36 ++++++++
 15 files changed, 520 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

-- 
Signature

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

* [RFC PATCH 0/5] arm/dt: register devices from device tree
@ 2011-01-26  4:44 ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

Hi all,

For right now this is only an early implementation and there are
several bugs that prevent all devices from getting registered
correctly, and not all of the dts data is accurate.  However, it
starts to show what a device-tree enabled machine_desc looks like
using the versatile platform as an example, and I wanted to get it out
for people to see.

A significant change in this series compared with the previous version
is that the devicetree clock lookup code has been decoupled from the
common struct clk patches that Jeremy is currently working on.  This
means that there is more machine-specific code than there needs to be
for handling clocks, but it can be removed after a common struct clk
is merged.

This series is based on:

    git://git.secretlab.ca/git/linux-2.6  devicetree/arm

g.

---

Grant Likely (2):
      arm/dt: Add dt machine definition
      arm/versatile: add a device tree versatile platform

Jeremy Kerr (3):
      drivers/amba: probe via device tree
      of: add clock providers
      arm/clkdev: lookup clocks from OF clock providers


 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/include/asm/mach/arch.h       |    9 ++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/amba/bus.c                     |   67 ++++++++++++++++
 drivers/clk/clkdev.c                   |    7 ++
 drivers/of/Kconfig                     |    5 +
 drivers/of/Makefile                    |    1 
 drivers/of/clock.c                     |  133 +++++++++++++++++++++++++++++++
 include/linux/amba/bus.h               |    5 +
 include/linux/of_clk.h                 |   36 ++++++++
 15 files changed, 520 insertions(+), 12 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

-- 
Signature

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

* [RFC PATCH 1/5] arm/dt: Add dt machine definition
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 arch/arm/include/asm/mach/arch.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/mach/arch.h b/arch/arm/include/asm/mach/arch.h
index 2ed24e7..13c0e69 100644
--- a/arch/arm/include/asm/mach/arch.h
+++ b/arch/arm/include/asm/mach/arch.h
@@ -67,4 +67,13 @@ static const struct machine_desc __mach_desc_##_type	\
 #define MACHINE_END				\
 };
 
+#define MACH_TYPE_DT	0xffffffff
+
+#define DT_MACHINE_START(_name, _namestr)		\
+static const struct machine_desc __mach_desc_##_name	\
+ __used							\
+ __attribute__((__section__(".arch.info.init"))) = {	\
+	.nr		= MACH_TYPE_DT,			\
+	.name		= _namestr,
+
 #endif


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

* [RFC PATCH 1/5] arm/dt: Add dt machine definition
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 arch/arm/include/asm/mach/arch.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/mach/arch.h b/arch/arm/include/asm/mach/arch.h
index 2ed24e7..13c0e69 100644
--- a/arch/arm/include/asm/mach/arch.h
+++ b/arch/arm/include/asm/mach/arch.h
@@ -67,4 +67,13 @@ static const struct machine_desc __mach_desc_##_type	\
 #define MACHINE_END				\
 };
 
+#define MACH_TYPE_DT	0xffffffff
+
+#define DT_MACHINE_START(_name, _namestr)		\
+static const struct machine_desc __mach_desc_##_name	\
+ __used							\
+ __attribute__((__section__(".arch.info.init"))) = {	\
+	.nr		= MACH_TYPE_DT,			\
+	.name		= _namestr,
+
 #endif

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

* [RFC PATCH 1/5] arm/dt: Add dt machine definition
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 arch/arm/include/asm/mach/arch.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/mach/arch.h b/arch/arm/include/asm/mach/arch.h
index 2ed24e7..13c0e69 100644
--- a/arch/arm/include/asm/mach/arch.h
+++ b/arch/arm/include/asm/mach/arch.h
@@ -67,4 +67,13 @@ static const struct machine_desc __mach_desc_##_type	\
 #define MACHINE_END				\
 };
 
+#define MACH_TYPE_DT	0xffffffff
+
+#define DT_MACHINE_START(_name, _namestr)		\
+static const struct machine_desc __mach_desc_##_name	\
+ __used							\
+ __attribute__((__section__(".arch.info.init"))) = {	\
+	.nr		= MACH_TYPE_DT,			\
+	.name		= _namestr,
+
 #endif

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

* [RFC PATCH 2/5] drivers/amba: probe via device tree
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Add functions to parse the AMBA bus through the device tree.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/amba/bus.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/amba/bus.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index e7df019..e753fa9 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -13,6 +13,10 @@
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
 #include <linux/amba/bus.h>
 
 #include <asm/irq.h>
@@ -486,3 +490,66 @@ EXPORT_SYMBOL(amba_device_unregister);
 EXPORT_SYMBOL(amba_find_device);
 EXPORT_SYMBOL(amba_request_regions);
 EXPORT_SYMBOL(amba_release_regions);
+
+#ifdef CONFIG_OF
+static int of_amba_device_create(struct device_node *node,struct device *parent)
+{
+	struct amba_device *dev;
+	const void *prop;
+	int i, ret;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	/* setup generic device info */
+	dev->dev.coherent_dma_mask = ~0;
+	dev->dev.of_node = node;
+	dev->dev.parent = parent;
+	of_device_make_bus_id(&dev->dev);
+
+	/* setup amba-specific device info */
+	dev->dma_mask = ~0;
+
+	/* Decode the IRQs and address ranges */
+	for (i = 0; i < AMBA_NR_IRQS; i++)
+		dev->irq[i] = irq_of_parse_and_map(node, i);
+
+	ret = of_address_to_resource(node, 0, &dev->res);
+	if (ret)
+		goto err_free;
+
+	ret = amba_device_register(dev, &iomem_resource);
+	if (ret)
+		goto err_free;
+
+	/* Sanity check the arm,amba-deviceid value */
+	prop = of_get_property(node, "arm,amba-deviceid", NULL);
+	if (!prop)
+		dev_warn(&dev->dev, "arm,amba-deviceid property missing; "
+				    "probe gives 0x%08x.\n", dev->periphid);
+
+	if (prop && (dev->periphid != of_read_ulong(prop, 1)))
+		dev_warn(&dev->dev, "arm,amba-deviceid value (0x%08lx) and "
+				    "probed value (0x%08x) don't agree.",
+				    of_read_ulong(prop, 1), dev->periphid);
+
+	return 0;
+
+err_free:
+	kfree(dev);
+	return ret;
+}
+
+void of_amba_bus_populate(struct device_node *node, struct device *parent)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child) {
+		if (of_device_is_compatible(child, "arm,amba-device"))
+			of_amba_device_create(child, parent);
+	}
+}
+EXPORT_SYMBOL(of_amba_bus_populate);
+
+#endif /* CONFIG_OF */
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 9e7f259..4baa4cf 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -90,4 +90,9 @@ void amba_release_regions(struct amba_device *);
 #define amba_manf(d)	AMBA_MANF_BITS((d)->periphid)
 #define amba_part(d)	AMBA_PART_BITS((d)->periphid)
 
+#ifdef CONFIG_OF
+struct device_node;
+void of_amba_bus_populate(struct device_node *node, struct device *parent);
+#endif
+
 #endif


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

* [RFC PATCH 2/5] drivers/amba: probe via device tree
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

From: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

Add functions to parse the AMBA bus through the device tree.

Signed-off-by: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 drivers/amba/bus.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/amba/bus.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index e7df019..e753fa9 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -13,6 +13,10 @@
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
 #include <linux/amba/bus.h>
 
 #include <asm/irq.h>
@@ -486,3 +490,66 @@ EXPORT_SYMBOL(amba_device_unregister);
 EXPORT_SYMBOL(amba_find_device);
 EXPORT_SYMBOL(amba_request_regions);
 EXPORT_SYMBOL(amba_release_regions);
+
+#ifdef CONFIG_OF
+static int of_amba_device_create(struct device_node *node,struct device *parent)
+{
+	struct amba_device *dev;
+	const void *prop;
+	int i, ret;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	/* setup generic device info */
+	dev->dev.coherent_dma_mask = ~0;
+	dev->dev.of_node = node;
+	dev->dev.parent = parent;
+	of_device_make_bus_id(&dev->dev);
+
+	/* setup amba-specific device info */
+	dev->dma_mask = ~0;
+
+	/* Decode the IRQs and address ranges */
+	for (i = 0; i < AMBA_NR_IRQS; i++)
+		dev->irq[i] = irq_of_parse_and_map(node, i);
+
+	ret = of_address_to_resource(node, 0, &dev->res);
+	if (ret)
+		goto err_free;
+
+	ret = amba_device_register(dev, &iomem_resource);
+	if (ret)
+		goto err_free;
+
+	/* Sanity check the arm,amba-deviceid value */
+	prop = of_get_property(node, "arm,amba-deviceid", NULL);
+	if (!prop)
+		dev_warn(&dev->dev, "arm,amba-deviceid property missing; "
+				    "probe gives 0x%08x.\n", dev->periphid);
+
+	if (prop && (dev->periphid != of_read_ulong(prop, 1)))
+		dev_warn(&dev->dev, "arm,amba-deviceid value (0x%08lx) and "
+				    "probed value (0x%08x) don't agree.",
+				    of_read_ulong(prop, 1), dev->periphid);
+
+	return 0;
+
+err_free:
+	kfree(dev);
+	return ret;
+}
+
+void of_amba_bus_populate(struct device_node *node, struct device *parent)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child) {
+		if (of_device_is_compatible(child, "arm,amba-device"))
+			of_amba_device_create(child, parent);
+	}
+}
+EXPORT_SYMBOL(of_amba_bus_populate);
+
+#endif /* CONFIG_OF */
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 9e7f259..4baa4cf 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -90,4 +90,9 @@ void amba_release_regions(struct amba_device *);
 #define amba_manf(d)	AMBA_MANF_BITS((d)->periphid)
 #define amba_part(d)	AMBA_PART_BITS((d)->periphid)
 
+#ifdef CONFIG_OF
+struct device_node;
+void of_amba_bus_populate(struct device_node *node, struct device *parent);
+#endif
+
 #endif

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

* [RFC PATCH 2/5] drivers/amba: probe via device tree
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Add functions to parse the AMBA bus through the device tree.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/amba/bus.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/amba/bus.h |    5 +++
 2 files changed, 72 insertions(+), 0 deletions(-)

diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index e7df019..e753fa9 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -13,6 +13,10 @@
 #include <linux/string.h>
 #include <linux/slab.h>
 #include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_irq.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
 #include <linux/amba/bus.h>
 
 #include <asm/irq.h>
@@ -486,3 +490,66 @@ EXPORT_SYMBOL(amba_device_unregister);
 EXPORT_SYMBOL(amba_find_device);
 EXPORT_SYMBOL(amba_request_regions);
 EXPORT_SYMBOL(amba_release_regions);
+
+#ifdef CONFIG_OF
+static int of_amba_device_create(struct device_node *node,struct device *parent)
+{
+	struct amba_device *dev;
+	const void *prop;
+	int i, ret;
+
+	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
+	if (!dev)
+		return -ENOMEM;
+
+	/* setup generic device info */
+	dev->dev.coherent_dma_mask = ~0;
+	dev->dev.of_node = node;
+	dev->dev.parent = parent;
+	of_device_make_bus_id(&dev->dev);
+
+	/* setup amba-specific device info */
+	dev->dma_mask = ~0;
+
+	/* Decode the IRQs and address ranges */
+	for (i = 0; i < AMBA_NR_IRQS; i++)
+		dev->irq[i] = irq_of_parse_and_map(node, i);
+
+	ret = of_address_to_resource(node, 0, &dev->res);
+	if (ret)
+		goto err_free;
+
+	ret = amba_device_register(dev, &iomem_resource);
+	if (ret)
+		goto err_free;
+
+	/* Sanity check the arm,amba-deviceid value */
+	prop = of_get_property(node, "arm,amba-deviceid", NULL);
+	if (!prop)
+		dev_warn(&dev->dev, "arm,amba-deviceid property missing; "
+				    "probe gives 0x%08x.\n", dev->periphid);
+
+	if (prop && (dev->periphid != of_read_ulong(prop, 1)))
+		dev_warn(&dev->dev, "arm,amba-deviceid value (0x%08lx) and "
+				    "probed value (0x%08x) don't agree.",
+				    of_read_ulong(prop, 1), dev->periphid);
+
+	return 0;
+
+err_free:
+	kfree(dev);
+	return ret;
+}
+
+void of_amba_bus_populate(struct device_node *node, struct device *parent)
+{
+	struct device_node *child;
+
+	for_each_child_of_node(node, child) {
+		if (of_device_is_compatible(child, "arm,amba-device"))
+			of_amba_device_create(child, parent);
+	}
+}
+EXPORT_SYMBOL(of_amba_bus_populate);
+
+#endif /* CONFIG_OF */
diff --git a/include/linux/amba/bus.h b/include/linux/amba/bus.h
index 9e7f259..4baa4cf 100644
--- a/include/linux/amba/bus.h
+++ b/include/linux/amba/bus.h
@@ -90,4 +90,9 @@ void amba_release_regions(struct amba_device *);
 #define amba_manf(d)	AMBA_MANF_BITS((d)->periphid)
 #define amba_part(d)	AMBA_PART_BITS((d)->periphid)
 
+#ifdef CONFIG_OF
+struct device_node;
+void of_amba_bus_populate(struct device_node *node, struct device *parent);
+#endif
+
 #endif

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

* [RFC PATCH 3/5] of: add clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Based on work by Ben Herrenschmidt, this patch adds an of_clk_get
function to allow platforms to retrieve clock data from the device tree.

Platform register a provider through of_clk_add_provider, which will be
called when a device references the provider's OF node for a clock
reference.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
[grant.likely@secretlab.ca: fix Kconfig conflict]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/of/Kconfig     |    5 ++
 drivers/of/Makefile    |    1 
 drivers/of/clock.c     |  134 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_clk.h |   36 +++++++++++++
 4 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 3c6e100..6650583 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -69,4 +69,9 @@ config OF_MDIO
 	help
 	  OpenFirmware MDIO bus (Ethernet PHY) accessors
 
+config OF_CLOCK
+	def_bool y
+	depends on HAVE_CLK
+	help
+	  OpenFirmware clock accessors
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 3ab21a0..c378c7b 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
+obj-$(CONFIG_OF_CLOCK)	+= clock.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
new file mode 100644
index 0000000..3e2b221
--- /dev/null
+++ b/drivers/of/clock.c
@@ -0,0 +1,134 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+
+struct of_clk_provider {
+	struct list_head	link;
+	struct device_node	*node;
+
+	/* Return NULL if no such clock output */
+	struct clk		*(*get)(struct device_node *np,
+					const char *output_id, void *data);
+	void			*data;
+};
+
+static LIST_HEAD(of_clk_providers);
+static DEFINE_MUTEX(of_clk_lock);
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp;
+
+	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->get = clk_src_get;
+
+	mutex_lock(&of_clk_lock);
+	list_add(&cp->link, &of_clk_providers);
+	mutex_unlock(&of_clk_lock);
+	pr_debug("Added clock from %s\n", np->full_name);
+
+	return 0;
+}
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp, *tmp;
+
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry_safe(cp, tmp, &of_clk_providers, link) {
+		if (cp->node == np && cp->get == clk_src_get &&
+				cp->data == data) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_clk_lock);
+}
+
+static struct clk *__of_clk_get_from_provider(struct device_node *np, const char *clk_output)
+{
+	struct of_clk_provider *provider;
+	struct clk *clk = NULL;
+
+	/* Check if we have such a provider in our array */
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry(provider, &of_clk_providers, link) {
+		if (provider->node == np)
+			clk = provider->get(np, clk_output, provider->data);
+		if (clk)
+			break;
+	}
+	mutex_unlock(&of_clk_lock);
+
+	return clk;
+}
+
+struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	struct device_node *provnode;
+	u32 provhandle;
+	int sz;
+	struct clk *clk;
+	char prop_name[32]; /* 32 is max size of property name */
+	const void *prop;
+
+	dev_dbg(dev, "Looking up %s-clock from device tree\n", id);
+
+	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
+
+	/* Extract the phandle from the start of the property value */
+	provhandle = be32_to_cpup(prop);
+	prop += 4;
+	sz -= 4;
+
+	/* Make sure the clock name is properly terminated and within the
+	 * size of the property. */
+	if (strlen(prop) + 1 > sz)
+		return NULL;
+
+	/* Find the clock provider node; check if it is registered as a
+	 * provider, and ask it for the relevant clk structure */
+	provnode = of_find_node_by_phandle(provhandle);
+	if (!provnode) {
+		pr_warn("%s: %s property in node %s references invalid phandle",
+			__func__, prop_name, dev->of_node->full_name);
+		return NULL;
+	}
+	clk = __of_clk_get_from_provider(provnode, prop);
+	if (clk)
+		dev_dbg(dev, "Using clock from %s\n", provnode->full_name);
+
+	of_node_put(provnode);
+
+	return clk;
+}
+
diff --git a/include/linux/of_clk.h b/include/linux/of_clk.h
new file mode 100644
index 0000000..c2f6b5a
--- /dev/null
+++ b/include/linux/of_clk.h
@@ -0,0 +1,36 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+#ifndef __OF_CLK_H
+#define __OF_CLK_H
+
+struct device;
+struct clk;
+
+#ifdef CONFIG_OF_CLOCK
+
+struct device_node;
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+struct clk *of_clk_get(struct device *dev, const char *id);
+
+#else
+static inline struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	return NULL;
+}
+#endif
+
+#endif /* __OF_CLK_H */
+


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

* [RFC PATCH 3/5] of: add clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

From: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

Based on work by Ben Herrenschmidt, this patch adds an of_clk_get
function to allow platforms to retrieve clock data from the device tree.

Platform register a provider through of_clk_add_provider, which will be
called when a device references the provider's OF node for a clock
reference.

Signed-off-by: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
[grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org: fix Kconfig conflict]
Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 drivers/of/Kconfig     |    5 ++
 drivers/of/Makefile    |    1 
 drivers/of/clock.c     |  134 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_clk.h |   36 +++++++++++++
 4 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 3c6e100..6650583 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -69,4 +69,9 @@ config OF_MDIO
 	help
 	  OpenFirmware MDIO bus (Ethernet PHY) accessors
 
+config OF_CLOCK
+	def_bool y
+	depends on HAVE_CLK
+	help
+	  OpenFirmware clock accessors
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 3ab21a0..c378c7b 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
+obj-$(CONFIG_OF_CLOCK)	+= clock.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
new file mode 100644
index 0000000..3e2b221
--- /dev/null
+++ b/drivers/of/clock.c
@@ -0,0 +1,134 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+
+struct of_clk_provider {
+	struct list_head	link;
+	struct device_node	*node;
+
+	/* Return NULL if no such clock output */
+	struct clk		*(*get)(struct device_node *np,
+					const char *output_id, void *data);
+	void			*data;
+};
+
+static LIST_HEAD(of_clk_providers);
+static DEFINE_MUTEX(of_clk_lock);
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp;
+
+	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->get = clk_src_get;
+
+	mutex_lock(&of_clk_lock);
+	list_add(&cp->link, &of_clk_providers);
+	mutex_unlock(&of_clk_lock);
+	pr_debug("Added clock from %s\n", np->full_name);
+
+	return 0;
+}
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp, *tmp;
+
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry_safe(cp, tmp, &of_clk_providers, link) {
+		if (cp->node == np && cp->get == clk_src_get &&
+				cp->data == data) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_clk_lock);
+}
+
+static struct clk *__of_clk_get_from_provider(struct device_node *np, const char *clk_output)
+{
+	struct of_clk_provider *provider;
+	struct clk *clk = NULL;
+
+	/* Check if we have such a provider in our array */
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry(provider, &of_clk_providers, link) {
+		if (provider->node == np)
+			clk = provider->get(np, clk_output, provider->data);
+		if (clk)
+			break;
+	}
+	mutex_unlock(&of_clk_lock);
+
+	return clk;
+}
+
+struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	struct device_node *provnode;
+	u32 provhandle;
+	int sz;
+	struct clk *clk;
+	char prop_name[32]; /* 32 is max size of property name */
+	const void *prop;
+
+	dev_dbg(dev, "Looking up %s-clock from device tree\n", id);
+
+	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
+
+	/* Extract the phandle from the start of the property value */
+	provhandle = be32_to_cpup(prop);
+	prop += 4;
+	sz -= 4;
+
+	/* Make sure the clock name is properly terminated and within the
+	 * size of the property. */
+	if (strlen(prop) + 1 > sz)
+		return NULL;
+
+	/* Find the clock provider node; check if it is registered as a
+	 * provider, and ask it for the relevant clk structure */
+	provnode = of_find_node_by_phandle(provhandle);
+	if (!provnode) {
+		pr_warn("%s: %s property in node %s references invalid phandle",
+			__func__, prop_name, dev->of_node->full_name);
+		return NULL;
+	}
+	clk = __of_clk_get_from_provider(provnode, prop);
+	if (clk)
+		dev_dbg(dev, "Using clock from %s\n", provnode->full_name);
+
+	of_node_put(provnode);
+
+	return clk;
+}
+
diff --git a/include/linux/of_clk.h b/include/linux/of_clk.h
new file mode 100644
index 0000000..c2f6b5a
--- /dev/null
+++ b/include/linux/of_clk.h
@@ -0,0 +1,36 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+#ifndef __OF_CLK_H
+#define __OF_CLK_H
+
+struct device;
+struct clk;
+
+#ifdef CONFIG_OF_CLOCK
+
+struct device_node;
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+struct clk *of_clk_get(struct device *dev, const char *id);
+
+#else
+static inline struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	return NULL;
+}
+#endif
+
+#endif /* __OF_CLK_H */
+

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

* [RFC PATCH 3/5] of: add clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Based on work by Ben Herrenschmidt, this patch adds an of_clk_get
function to allow platforms to retrieve clock data from the device tree.

Platform register a provider through of_clk_add_provider, which will be
called when a device references the provider's OF node for a clock
reference.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
[grant.likely at secretlab.ca: fix Kconfig conflict]
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/of/Kconfig     |    5 ++
 drivers/of/Makefile    |    1 
 drivers/of/clock.c     |  134 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_clk.h |   36 +++++++++++++
 4 files changed, 176 insertions(+), 0 deletions(-)
 create mode 100644 drivers/of/clock.c
 create mode 100644 include/linux/of_clk.h

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 3c6e100..6650583 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -69,4 +69,9 @@ config OF_MDIO
 	help
 	  OpenFirmware MDIO bus (Ethernet PHY) accessors
 
+config OF_CLOCK
+	def_bool y
+	depends on HAVE_CLK
+	help
+	  OpenFirmware clock accessors
 endmenu # OF
diff --git a/drivers/of/Makefile b/drivers/of/Makefile
index 3ab21a0..c378c7b 100644
--- a/drivers/of/Makefile
+++ b/drivers/of/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_OF_ADDRESS)  += address.o
 obj-$(CONFIG_OF_IRQ)    += irq.o
 obj-$(CONFIG_OF_DEVICE) += device.o platform.o
 obj-$(CONFIG_OF_GPIO)   += gpio.o
+obj-$(CONFIG_OF_CLOCK)	+= clock.o
 obj-$(CONFIG_OF_I2C)	+= of_i2c.o
 obj-$(CONFIG_OF_NET)	+= of_net.o
 obj-$(CONFIG_OF_SPI)	+= of_spi.o
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
new file mode 100644
index 0000000..3e2b221
--- /dev/null
+++ b/drivers/of/clock.c
@@ -0,0 +1,134 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/errno.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
+#include <linux/list.h>
+#include <linux/mutex.h>
+#include <linux/slab.h>
+#include <linux/device.h>
+
+struct of_clk_provider {
+	struct list_head	link;
+	struct device_node	*node;
+
+	/* Return NULL if no such clock output */
+	struct clk		*(*get)(struct device_node *np,
+					const char *output_id, void *data);
+	void			*data;
+};
+
+static LIST_HEAD(of_clk_providers);
+static DEFINE_MUTEX(of_clk_lock);
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp;
+
+	cp = kzalloc(sizeof(struct of_clk_provider), GFP_KERNEL);
+	if (!cp)
+		return -ENOMEM;
+
+	cp->node = of_node_get(np);
+	cp->data = data;
+	cp->get = clk_src_get;
+
+	mutex_lock(&of_clk_lock);
+	list_add(&cp->link, &of_clk_providers);
+	mutex_unlock(&of_clk_lock);
+	pr_debug("Added clock from %s\n", np->full_name);
+
+	return 0;
+}
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data)
+{
+	struct of_clk_provider *cp, *tmp;
+
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry_safe(cp, tmp, &of_clk_providers, link) {
+		if (cp->node == np && cp->get == clk_src_get &&
+				cp->data == data) {
+			list_del(&cp->link);
+			of_node_put(cp->node);
+			kfree(cp);
+			break;
+		}
+	}
+	mutex_unlock(&of_clk_lock);
+}
+
+static struct clk *__of_clk_get_from_provider(struct device_node *np, const char *clk_output)
+{
+	struct of_clk_provider *provider;
+	struct clk *clk = NULL;
+
+	/* Check if we have such a provider in our array */
+	mutex_lock(&of_clk_lock);
+	list_for_each_entry(provider, &of_clk_providers, link) {
+		if (provider->node == np)
+			clk = provider->get(np, clk_output, provider->data);
+		if (clk)
+			break;
+	}
+	mutex_unlock(&of_clk_lock);
+
+	return clk;
+}
+
+struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	struct device_node *provnode;
+	u32 provhandle;
+	int sz;
+	struct clk *clk;
+	char prop_name[32]; /* 32 is max size of property name */
+	const void *prop;
+
+	dev_dbg(dev, "Looking up %s-clock from device tree\n", id);
+
+	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");
+	prop = of_get_property(dev->of_node, prop_name, &sz);
+	if (!prop || sz < 4)
+		return NULL;
+
+	/* Extract the phandle from the start of the property value */
+	provhandle = be32_to_cpup(prop);
+	prop += 4;
+	sz -= 4;
+
+	/* Make sure the clock name is properly terminated and within the
+	 * size of the property. */
+	if (strlen(prop) + 1 > sz)
+		return NULL;
+
+	/* Find the clock provider node; check if it is registered as a
+	 * provider, and ask it for the relevant clk structure */
+	provnode = of_find_node_by_phandle(provhandle);
+	if (!provnode) {
+		pr_warn("%s: %s property in node %s references invalid phandle",
+			__func__, prop_name, dev->of_node->full_name);
+		return NULL;
+	}
+	clk = __of_clk_get_from_provider(provnode, prop);
+	if (clk)
+		dev_dbg(dev, "Using clock from %s\n", provnode->full_name);
+
+	of_node_put(provnode);
+
+	return clk;
+}
+
diff --git a/include/linux/of_clk.h b/include/linux/of_clk.h
new file mode 100644
index 0000000..c2f6b5a
--- /dev/null
+++ b/include/linux/of_clk.h
@@ -0,0 +1,36 @@
+/*
+ * Clock infrastructure for device tree platforms
+ */
+#ifndef __OF_CLK_H
+#define __OF_CLK_H
+
+struct device;
+struct clk;
+
+#ifdef CONFIG_OF_CLOCK
+
+struct device_node;
+
+int of_clk_add_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+void of_clk_del_provider(struct device_node *np,
+		struct clk *(*clk_src_get)(struct device_node *np,
+			const char *output_id,
+			void *data),
+		void *data);
+
+struct clk *of_clk_get(struct device *dev, const char *id);
+
+#else
+static inline struct clk *of_clk_get(struct device *dev, const char *id)
+{
+	return NULL;
+}
+#endif
+
+#endif /* __OF_CLK_H */
+

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

* [RFC PATCH 4/5] arm/clkdev: lookup clocks from OF clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Hook the OF clock provider infrastructure to clk_get.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/clk/clkdev.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 0fc0a79..a546763 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,6 +19,8 @@
 #include <linux/mutex.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
 
 static LIST_HEAD(clocks);
 static DEFINE_MUTEX(clocks_mutex);
@@ -79,6 +81,11 @@ EXPORT_SYMBOL(clk_get_sys);
 struct clk *clk_get(struct device *dev, const char *con_id)
 {
 	const char *dev_id = dev ? dev_name(dev) : NULL;
+	struct clk *clk;
+
+	clk = of_clk_get(dev, con_id);
+	if (clk && __clk_get(clk))
+		return clk;
 
 	return clk_get_sys(dev_id, con_id);
 }


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

* [RFC PATCH 4/5] arm/clkdev: lookup clocks from OF clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

From: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

Hook the OF clock provider infrastructure to clk_get.

Signed-off-by: Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 drivers/clk/clkdev.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 0fc0a79..a546763 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,6 +19,8 @@
 #include <linux/mutex.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
 
 static LIST_HEAD(clocks);
 static DEFINE_MUTEX(clocks_mutex);
@@ -79,6 +81,11 @@ EXPORT_SYMBOL(clk_get_sys);
 struct clk *clk_get(struct device *dev, const char *con_id)
 {
 	const char *dev_id = dev ? dev_name(dev) : NULL;
+	struct clk *clk;
+
+	clk = of_clk_get(dev, con_id);
+	if (clk && __clk_get(clk))
+		return clk;
 
 	return clk_get_sys(dev_id, con_id);
 }

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

* [RFC PATCH 4/5] arm/clkdev: lookup clocks from OF clock providers
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Hook the OF clock provider infrastructure to clk_get.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 drivers/clk/clkdev.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 0fc0a79..a546763 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -19,6 +19,8 @@
 #include <linux/mutex.h>
 #include <linux/clk.h>
 #include <linux/clkdev.h>
+#include <linux/of.h>
+#include <linux/of_clk.h>
 
 static LIST_HEAD(clocks);
 static DEFINE_MUTEX(clocks_mutex);
@@ -79,6 +81,11 @@ EXPORT_SYMBOL(clk_get_sys);
 struct clk *clk_get(struct device *dev, const char *con_id)
 {
 	const char *dev_id = dev ? dev_name(dev) : NULL;
+	struct clk *clk;
+
+	clk = of_clk_get(dev, con_id);
+	if (clk && __clk_get(clk))
+		return clk;
 
 	return clk_get_sys(dev_id, con_id);
 }

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

* [RFC PATCH 5/5] arm/versatile: add a device tree versatile platform
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel
  Cc: nicolas.pitre

For testing the dt work, define a dt-enabled versatile platform.

This patch includes some fixed clk parsing logic that really would be
better as common code, but that depends on the common struct clk
getting merged.  In the mean time it is easy enough to implement it
here.

Based on work originally written by Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/of/clock.c                     |    1 
 8 files changed, 257 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c

diff --git a/arch/arm/boot/dts/versatile.dts b/arch/arm/boot/dts/versatile.dts
new file mode 100644
index 0000000..6ff9ee2
--- /dev/null
+++ b/arch/arm/boot/dts/versatile.dts
@@ -0,0 +1,138 @@
+/dts-v1/;
+
+/ {
+	model = "ARM Versatile-PB";
+	compatible = "arm,versatile-pb";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	interrupt-parent = <&vic>;
+
+	aliases {
+		uart0 = &uart0;
+		uart1 = &uart1;
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x0 0x08000000>;
+	};
+
+	chosen {
+		bootargs = "console=ttyAMA0 debug";
+	};
+
+	clocks {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ref24_clk: clock@0 {
+			compatible = "fixed-clock";
+			clock-frequency = <24000000>;
+			clock-outputs = "ref";
+		};
+
+		osc4_clk: clock@1 {
+			compatible = "ics,icst307";
+			ref = <24000>;
+			vco-max = <200000>;
+			vd-range = <12 519>;
+			rd-range = <3 129>;
+			clock-outputs = "osc4";
+		};
+	};
+
+	vic: intc {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10140000 0x1000>;
+	};
+
+	sic: intc@10003000 {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10003000 0x1000>;
+		interrupts = <31>; /* Cascaded to vic */
+	};
+
+	amba {
+		compatible = "arm,amba-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		fpga {
+			compatible = "arm,versatile-fpga", "simple-bus";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x10000000 0x10000>;
+
+			fpga@5000 {
+				compatible = "arm,amba-device";
+				reg = < 0x5000 0x1000 >;
+			};
+			fpga@6000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x6000 0x1000 >;
+			};
+			fpga@7000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x7000 0x1000 >;
+			};
+			fpga@9000 {
+				compatible = "arm,pl011", "arm,amba-device";
+				reg = < 0x9000 0x1000 >;
+			};
+			fpga@b000 {
+				compatible = "arm,amba-device";
+				reg = < 0xb000 0x1000 >;
+			};
+		};
+
+		uart0: uart@101f1000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f1000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <12>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+
+		uart1: uart@101f2000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f2000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <13>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+	};
+
+	flash@34000000 {
+		compatible = "arm,versatile-flash";
+		reg = <0x34000000 0x4000000>;
+		bank-width = <4>;
+	};
+
+	net@10010000 {
+		compatible = "smsc,smc91c111";
+		reg = <0x10010000 0x10000>;
+		interrupts = <25>;
+	};
+
+	i2c@10002000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "arm,versatile-i2c";
+		reg = <0x10002000 0x1000>;
+
+		rtc@68 {
+			compatible = "dallas,ds1338";
+			reg = <0x68>;
+		};
+	};
+
+	lcd@10008000 {
+		compatible = "arm,versatile-lcd";
+		reg = <0x10008000 0x1000>;
+	};
+};
diff --git a/arch/arm/mach-versatile/Kconfig b/arch/arm/mach-versatile/Kconfig
index 3f7b5e9..3b417f4 100644
--- a/arch/arm/mach-versatile/Kconfig
+++ b/arch/arm/mach-versatile/Kconfig
@@ -15,4 +15,12 @@ config MACH_VERSATILE_AB
 	help
 	  Include support for the ARM(R) Versatile/AP platform.
 
+config MACH_VERSATILE_DT
+	bool "Support Versatile platform from device tree"
+	select USE_OF
+	select CPU_ARM926T
+	help
+	  Include support for the ARM(R) Versatile/PB platform,
+	  using the device tree for discovery
+
 endmenu
diff --git a/arch/arm/mach-versatile/Makefile b/arch/arm/mach-versatile/Makefile
index 97cf4d8..81fa3fe 100644
--- a/arch/arm/mach-versatile/Makefile
+++ b/arch/arm/mach-versatile/Makefile
@@ -5,4 +5,5 @@
 obj-y					:= core.o
 obj-$(CONFIG_ARCH_VERSATILE_PB)		+= versatile_pb.o
 obj-$(CONFIG_MACH_VERSATILE_AB)		+= versatile_ab.o
+obj-$(CONFIG_MACH_VERSATILE_DT)		+= versatile_dt.o
 obj-$(CONFIG_PCI)			+= pci.o
diff --git a/arch/arm/mach-versatile/versatile_ab.c b/arch/arm/mach-versatile/versatile_ab.c
index 62053df..aa9730f 100644
--- a/arch/arm/mach-versatile/versatile_ab.c
+++ b/arch/arm/mach-versatile/versatile_ab.c
@@ -33,11 +33,6 @@
 
 #include "core.h"
 
-static const char *versatile_ab_match[] __initdata = {
-	"arm,versatile-ab",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -45,5 +40,4 @@ MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_init,
-	.dt_compat	= versatile_ab_match,
 MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_dt.c b/arch/arm/mach-versatile/versatile_dt.c
new file mode 100644
index 0000000..7eacc2d
--- /dev/null
+++ b/arch/arm/mach-versatile/versatile_dt.c
@@ -0,0 +1,108 @@
+/*
+ *  linux/arch/arm/mach-versatile/versatile_dt.c
+ *
+ *  Copyright (C) 2009 Jeremy Kerr <jeremy.kerr@canonical.com>
+ *  Copyright (C) 2004 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/sysdev.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/pl061.h>
+#include <linux/amba/mmci.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+#include <linux/of_clk.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+#include <asm/mach-types.h>
+
+#include <asm/mach/arch.h>
+
+#include "core.h"
+
+/* Dummy AMBA bus clock; can be overridden */
+static struct clk versatile_dt_dummy_apb_pclk;
+static struct clk_lookup versatile_dt_dummy_apb_cl = {
+	.con_id = "apb_pclk",
+	.clk = &versatile_dt_dummy_apb_pclk,
+};
+
+/* Scan for fixed clocks */
+static struct clk *versatile_dt_clk_get(struct device_node *np,
+					const char *output_id, void *data)
+{
+	return data;
+}
+
+static __init void versatile_dt_scan_clks(void)
+{
+	struct device_node *node;
+	const __be32 *rate;
+	struct clk *clk;
+	int rc;
+
+	for_each_compatible_node(node, NULL, "fixed-clock") {
+		rate = of_get_property(node, "clock-frequency", NULL);
+		if (!rate)
+			continue;
+
+		clk = kzalloc(sizeof(*clk), GFP_KERNEL);
+		if (!clk)
+			panic("out of memory\n");
+		clk->rate = be32_to_cpup(rate);
+
+		rc = of_clk_add_provider(node, versatile_dt_clk_get, clk);
+		if (rc) {
+			kfree(clk);
+			pr_err("error adding fixed clk %s\n", node->name);
+		}
+	}
+}
+static void __init versatile_dt_init(void)
+{
+	struct device_node *node;
+
+	clkdev_add(&versatile_dt_dummy_apb_cl);
+	versatile_dt_scan_clks();
+
+	node = of_find_node_by_path("/amba");
+	if (node)
+		of_amba_bus_populate(node, NULL);
+}
+
+static const char *versatile_dt_match[] __initdata = {
+	"arm,versatile-ab",
+	"arm,versatile-pb",
+	NULL,
+};
+
+DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
+	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
+	.boot_params	= 0x00000100,
+	.map_io		= versatile_map_io,
+	.init_irq	= versatile_init_irq,
+	.timer		= &versatile_timer,
+	.init_machine	= versatile_dt_init,
+	.dt_compat	= versatile_dt_match,
+MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_pb.c b/arch/arm/mach-versatile/versatile_pb.c
index eba12fa..bf46964 100644
--- a/arch/arm/mach-versatile/versatile_pb.c
+++ b/arch/arm/mach-versatile/versatile_pb.c
@@ -106,11 +106,6 @@ static void __init versatile_pb_init(void)
 	}
 }
 
-static const char *versatile_pb_match[] __initdata = {
-	"arm,versatile-pb",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -118,5 +113,4 @@ MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_pb_init,
-	.dt_compat	= versatile_pb_match,
 MACHINE_END
diff --git a/arch/arm/plat-versatile/clock.c b/arch/arm/plat-versatile/clock.c
index 5c8b656..44545de 100644
--- a/arch/arm/plat-versatile/clock.c
+++ b/arch/arm/plat-versatile/clock.c
@@ -13,6 +13,8 @@
 #include <linux/errno.h>
 #include <linux/clk.h>
 #include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/slab.h>
 
 #include <asm/hardware/icst.h>
 
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
index 3e2b221..7b5ea67 100644
--- a/drivers/of/clock.c
+++ b/drivers/of/clock.c
@@ -131,4 +131,3 @@ struct clk *of_clk_get(struct device *dev, const char *id)
 
 	return clk;
 }
-


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

* [RFC PATCH 5/5] arm/versatile: add a device tree versatile platform
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
	jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r
  Cc: nicolas.pitre-QSEj5FYQhm4dnm+yROfE0A

For testing the dt work, define a dt-enabled versatile platform.

This patch includes some fixed clk parsing logic that really would be
better as common code, but that depends on the common struct clk
getting merged.  In the mean time it is easy enough to implement it
here.

Based on work originally written by Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Signed-off-by: Grant Likely <grant.likely-s3s/WqlpOiPyB63q8FvJNQ@public.gmane.org>
---
 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/of/clock.c                     |    1 
 8 files changed, 257 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c

diff --git a/arch/arm/boot/dts/versatile.dts b/arch/arm/boot/dts/versatile.dts
new file mode 100644
index 0000000..6ff9ee2
--- /dev/null
+++ b/arch/arm/boot/dts/versatile.dts
@@ -0,0 +1,138 @@
+/dts-v1/;
+
+/ {
+	model = "ARM Versatile-PB";
+	compatible = "arm,versatile-pb";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	interrupt-parent = <&vic>;
+
+	aliases {
+		uart0 = &uart0;
+		uart1 = &uart1;
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x0 0x08000000>;
+	};
+
+	chosen {
+		bootargs = "console=ttyAMA0 debug";
+	};
+
+	clocks {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ref24_clk: clock@0 {
+			compatible = "fixed-clock";
+			clock-frequency = <24000000>;
+			clock-outputs = "ref";
+		};
+
+		osc4_clk: clock@1 {
+			compatible = "ics,icst307";
+			ref = <24000>;
+			vco-max = <200000>;
+			vd-range = <12 519>;
+			rd-range = <3 129>;
+			clock-outputs = "osc4";
+		};
+	};
+
+	vic: intc {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10140000 0x1000>;
+	};
+
+	sic: intc@10003000 {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10003000 0x1000>;
+		interrupts = <31>; /* Cascaded to vic */
+	};
+
+	amba {
+		compatible = "arm,amba-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		fpga {
+			compatible = "arm,versatile-fpga", "simple-bus";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x10000000 0x10000>;
+
+			fpga@5000 {
+				compatible = "arm,amba-device";
+				reg = < 0x5000 0x1000 >;
+			};
+			fpga@6000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x6000 0x1000 >;
+			};
+			fpga@7000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x7000 0x1000 >;
+			};
+			fpga@9000 {
+				compatible = "arm,pl011", "arm,amba-device";
+				reg = < 0x9000 0x1000 >;
+			};
+			fpga@b000 {
+				compatible = "arm,amba-device";
+				reg = < 0xb000 0x1000 >;
+			};
+		};
+
+		uart0: uart@101f1000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f1000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <12>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+
+		uart1: uart@101f2000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f2000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <13>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+	};
+
+	flash@34000000 {
+		compatible = "arm,versatile-flash";
+		reg = <0x34000000 0x4000000>;
+		bank-width = <4>;
+	};
+
+	net@10010000 {
+		compatible = "smsc,smc91c111";
+		reg = <0x10010000 0x10000>;
+		interrupts = <25>;
+	};
+
+	i2c@10002000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "arm,versatile-i2c";
+		reg = <0x10002000 0x1000>;
+
+		rtc@68 {
+			compatible = "dallas,ds1338";
+			reg = <0x68>;
+		};
+	};
+
+	lcd@10008000 {
+		compatible = "arm,versatile-lcd";
+		reg = <0x10008000 0x1000>;
+	};
+};
diff --git a/arch/arm/mach-versatile/Kconfig b/arch/arm/mach-versatile/Kconfig
index 3f7b5e9..3b417f4 100644
--- a/arch/arm/mach-versatile/Kconfig
+++ b/arch/arm/mach-versatile/Kconfig
@@ -15,4 +15,12 @@ config MACH_VERSATILE_AB
 	help
 	  Include support for the ARM(R) Versatile/AP platform.
 
+config MACH_VERSATILE_DT
+	bool "Support Versatile platform from device tree"
+	select USE_OF
+	select CPU_ARM926T
+	help
+	  Include support for the ARM(R) Versatile/PB platform,
+	  using the device tree for discovery
+
 endmenu
diff --git a/arch/arm/mach-versatile/Makefile b/arch/arm/mach-versatile/Makefile
index 97cf4d8..81fa3fe 100644
--- a/arch/arm/mach-versatile/Makefile
+++ b/arch/arm/mach-versatile/Makefile
@@ -5,4 +5,5 @@
 obj-y					:= core.o
 obj-$(CONFIG_ARCH_VERSATILE_PB)		+= versatile_pb.o
 obj-$(CONFIG_MACH_VERSATILE_AB)		+= versatile_ab.o
+obj-$(CONFIG_MACH_VERSATILE_DT)		+= versatile_dt.o
 obj-$(CONFIG_PCI)			+= pci.o
diff --git a/arch/arm/mach-versatile/versatile_ab.c b/arch/arm/mach-versatile/versatile_ab.c
index 62053df..aa9730f 100644
--- a/arch/arm/mach-versatile/versatile_ab.c
+++ b/arch/arm/mach-versatile/versatile_ab.c
@@ -33,11 +33,6 @@
 
 #include "core.h"
 
-static const char *versatile_ab_match[] __initdata = {
-	"arm,versatile-ab",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -45,5 +40,4 @@ MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_init,
-	.dt_compat	= versatile_ab_match,
 MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_dt.c b/arch/arm/mach-versatile/versatile_dt.c
new file mode 100644
index 0000000..7eacc2d
--- /dev/null
+++ b/arch/arm/mach-versatile/versatile_dt.c
@@ -0,0 +1,108 @@
+/*
+ *  linux/arch/arm/mach-versatile/versatile_dt.c
+ *
+ *  Copyright (C) 2009 Jeremy Kerr <jeremy.kerr-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
+ *  Copyright (C) 2004 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/sysdev.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/pl061.h>
+#include <linux/amba/mmci.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+#include <linux/of_clk.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+#include <asm/mach-types.h>
+
+#include <asm/mach/arch.h>
+
+#include "core.h"
+
+/* Dummy AMBA bus clock; can be overridden */
+static struct clk versatile_dt_dummy_apb_pclk;
+static struct clk_lookup versatile_dt_dummy_apb_cl = {
+	.con_id = "apb_pclk",
+	.clk = &versatile_dt_dummy_apb_pclk,
+};
+
+/* Scan for fixed clocks */
+static struct clk *versatile_dt_clk_get(struct device_node *np,
+					const char *output_id, void *data)
+{
+	return data;
+}
+
+static __init void versatile_dt_scan_clks(void)
+{
+	struct device_node *node;
+	const __be32 *rate;
+	struct clk *clk;
+	int rc;
+
+	for_each_compatible_node(node, NULL, "fixed-clock") {
+		rate = of_get_property(node, "clock-frequency", NULL);
+		if (!rate)
+			continue;
+
+		clk = kzalloc(sizeof(*clk), GFP_KERNEL);
+		if (!clk)
+			panic("out of memory\n");
+		clk->rate = be32_to_cpup(rate);
+
+		rc = of_clk_add_provider(node, versatile_dt_clk_get, clk);
+		if (rc) {
+			kfree(clk);
+			pr_err("error adding fixed clk %s\n", node->name);
+		}
+	}
+}
+static void __init versatile_dt_init(void)
+{
+	struct device_node *node;
+
+	clkdev_add(&versatile_dt_dummy_apb_cl);
+	versatile_dt_scan_clks();
+
+	node = of_find_node_by_path("/amba");
+	if (node)
+		of_amba_bus_populate(node, NULL);
+}
+
+static const char *versatile_dt_match[] __initdata = {
+	"arm,versatile-ab",
+	"arm,versatile-pb",
+	NULL,
+};
+
+DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
+	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
+	.boot_params	= 0x00000100,
+	.map_io		= versatile_map_io,
+	.init_irq	= versatile_init_irq,
+	.timer		= &versatile_timer,
+	.init_machine	= versatile_dt_init,
+	.dt_compat	= versatile_dt_match,
+MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_pb.c b/arch/arm/mach-versatile/versatile_pb.c
index eba12fa..bf46964 100644
--- a/arch/arm/mach-versatile/versatile_pb.c
+++ b/arch/arm/mach-versatile/versatile_pb.c
@@ -106,11 +106,6 @@ static void __init versatile_pb_init(void)
 	}
 }
 
-static const char *versatile_pb_match[] __initdata = {
-	"arm,versatile-pb",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -118,5 +113,4 @@ MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_pb_init,
-	.dt_compat	= versatile_pb_match,
 MACHINE_END
diff --git a/arch/arm/plat-versatile/clock.c b/arch/arm/plat-versatile/clock.c
index 5c8b656..44545de 100644
--- a/arch/arm/plat-versatile/clock.c
+++ b/arch/arm/plat-versatile/clock.c
@@ -13,6 +13,8 @@
 #include <linux/errno.h>
 #include <linux/clk.h>
 #include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/slab.h>
 
 #include <asm/hardware/icst.h>
 
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
index 3e2b221..7b5ea67 100644
--- a/drivers/of/clock.c
+++ b/drivers/of/clock.c
@@ -131,4 +131,3 @@ struct clk *of_clk_get(struct device *dev, const char *id)
 
 	return clk;
 }
-

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

* [RFC PATCH 5/5] arm/versatile: add a device tree versatile platform
@ 2011-01-26  4:44   ` Grant Likely
  0 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-26  4:44 UTC (permalink / raw)
  To: linux-arm-kernel

For testing the dt work, define a dt-enabled versatile platform.

This patch includes some fixed clk parsing logic that really would be
better as common code, but that depends on the common struct clk
getting merged.  In the mean time it is easy enough to implement it
here.

Based on work originally written by Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---
 arch/arm/boot/dts/versatile.dts        |  138 ++++++++++++++++++++++++++++++++
 arch/arm/mach-versatile/Kconfig        |    8 ++
 arch/arm/mach-versatile/Makefile       |    1 
 arch/arm/mach-versatile/versatile_ab.c |    6 -
 arch/arm/mach-versatile/versatile_dt.c |  108 +++++++++++++++++++++++++
 arch/arm/mach-versatile/versatile_pb.c |    6 -
 arch/arm/plat-versatile/clock.c        |    2 
 drivers/of/clock.c                     |    1 
 8 files changed, 257 insertions(+), 13 deletions(-)
 create mode 100644 arch/arm/boot/dts/versatile.dts
 create mode 100644 arch/arm/mach-versatile/versatile_dt.c

diff --git a/arch/arm/boot/dts/versatile.dts b/arch/arm/boot/dts/versatile.dts
new file mode 100644
index 0000000..6ff9ee2
--- /dev/null
+++ b/arch/arm/boot/dts/versatile.dts
@@ -0,0 +1,138 @@
+/dts-v1/;
+
+/ {
+	model = "ARM Versatile-PB";
+	compatible = "arm,versatile-pb";
+	#address-cells = <1>;
+	#size-cells = <1>;
+	interrupt-parent = <&vic>;
+
+	aliases {
+		uart0 = &uart0;
+		uart1 = &uart1;
+	};
+
+	memory {
+		device_type = "memory";
+		reg = <0x0 0x08000000>;
+	};
+
+	chosen {
+		bootargs = "console=ttyAMA0 debug";
+	};
+
+	clocks {
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		ref24_clk: clock at 0 {
+			compatible = "fixed-clock";
+			clock-frequency = <24000000>;
+			clock-outputs = "ref";
+		};
+
+		osc4_clk: clock at 1 {
+			compatible = "ics,icst307";
+			ref = <24000>;
+			vco-max = <200000>;
+			vd-range = <12 519>;
+			rd-range = <3 129>;
+			clock-outputs = "osc4";
+		};
+	};
+
+	vic: intc {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10140000 0x1000>;
+	};
+
+	sic: intc at 10003000 {
+		compatible = "arm,versatile-vic";
+		interrupt-controller;
+		#interrupt-cells = <1>;
+		reg = <0x10003000 0x1000>;
+		interrupts = <31>; /* Cascaded to vic */
+	};
+
+	amba {
+		compatible = "arm,amba-bus";
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		fpga {
+			compatible = "arm,versatile-fpga", "simple-bus";
+			#address-cells = <1>;
+			#size-cells = <1>;
+			ranges = <0 0x10000000 0x10000>;
+
+			fpga at 5000 {
+				compatible = "arm,amba-device";
+				reg = < 0x5000 0x1000 >;
+			};
+			fpga at 6000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x6000 0x1000 >;
+			};
+			fpga at 7000 {
+				compatible = "arm,pl050", "arm,amba-device";
+				reg = < 0x7000 0x1000 >;
+			};
+			fpga at 9000 {
+				compatible = "arm,pl011", "arm,amba-device";
+				reg = < 0x9000 0x1000 >;
+			};
+			fpga at b000 {
+				compatible = "arm,amba-device";
+				reg = < 0xb000 0x1000 >;
+			};
+		};
+
+		uart0: uart at 101f1000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f1000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <12>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+
+		uart1: uart at 101f2000 {
+			compatible = "arm,pl011", "arm,amba-device";
+			reg = <0x101f2000 0x1000>;
+			arm,amba-deviceid = <0x00141011>;
+			interrupts = <13>;
+			bus-clock = <&ref24_clk>, "ref";
+		};
+	};
+
+	flash at 34000000 {
+		compatible = "arm,versatile-flash";
+		reg = <0x34000000 0x4000000>;
+		bank-width = <4>;
+	};
+
+	net at 10010000 {
+		compatible = "smsc,smc91c111";
+		reg = <0x10010000 0x10000>;
+		interrupts = <25>;
+	};
+
+	i2c at 10002000 {
+		#address-cells = <1>;
+		#size-cells = <0>;
+		compatible = "arm,versatile-i2c";
+		reg = <0x10002000 0x1000>;
+
+		rtc at 68 {
+			compatible = "dallas,ds1338";
+			reg = <0x68>;
+		};
+	};
+
+	lcd at 10008000 {
+		compatible = "arm,versatile-lcd";
+		reg = <0x10008000 0x1000>;
+	};
+};
diff --git a/arch/arm/mach-versatile/Kconfig b/arch/arm/mach-versatile/Kconfig
index 3f7b5e9..3b417f4 100644
--- a/arch/arm/mach-versatile/Kconfig
+++ b/arch/arm/mach-versatile/Kconfig
@@ -15,4 +15,12 @@ config MACH_VERSATILE_AB
 	help
 	  Include support for the ARM(R) Versatile/AP platform.
 
+config MACH_VERSATILE_DT
+	bool "Support Versatile platform from device tree"
+	select USE_OF
+	select CPU_ARM926T
+	help
+	  Include support for the ARM(R) Versatile/PB platform,
+	  using the device tree for discovery
+
 endmenu
diff --git a/arch/arm/mach-versatile/Makefile b/arch/arm/mach-versatile/Makefile
index 97cf4d8..81fa3fe 100644
--- a/arch/arm/mach-versatile/Makefile
+++ b/arch/arm/mach-versatile/Makefile
@@ -5,4 +5,5 @@
 obj-y					:= core.o
 obj-$(CONFIG_ARCH_VERSATILE_PB)		+= versatile_pb.o
 obj-$(CONFIG_MACH_VERSATILE_AB)		+= versatile_ab.o
+obj-$(CONFIG_MACH_VERSATILE_DT)		+= versatile_dt.o
 obj-$(CONFIG_PCI)			+= pci.o
diff --git a/arch/arm/mach-versatile/versatile_ab.c b/arch/arm/mach-versatile/versatile_ab.c
index 62053df..aa9730f 100644
--- a/arch/arm/mach-versatile/versatile_ab.c
+++ b/arch/arm/mach-versatile/versatile_ab.c
@@ -33,11 +33,6 @@
 
 #include "core.h"
 
-static const char *versatile_ab_match[] __initdata = {
-	"arm,versatile-ab",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -45,5 +40,4 @@ MACHINE_START(VERSATILE_AB, "ARM-Versatile AB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_init,
-	.dt_compat	= versatile_ab_match,
 MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_dt.c b/arch/arm/mach-versatile/versatile_dt.c
new file mode 100644
index 0000000..7eacc2d
--- /dev/null
+++ b/arch/arm/mach-versatile/versatile_dt.c
@@ -0,0 +1,108 @@
+/*
+ *  linux/arch/arm/mach-versatile/versatile_dt.c
+ *
+ *  Copyright (C) 2009 Jeremy Kerr <jeremy.kerr@canonical.com>
+ *  Copyright (C) 2004 ARM Limited
+ *  Copyright (C) 2000 Deep Blue Solutions Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/init.h>
+#include <linux/device.h>
+#include <linux/sysdev.h>
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/pl061.h>
+#include <linux/amba/mmci.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+#include <linux/of_clk.h>
+
+#include <mach/hardware.h>
+#include <asm/irq.h>
+#include <asm/mach-types.h>
+
+#include <asm/mach/arch.h>
+
+#include "core.h"
+
+/* Dummy AMBA bus clock; can be overridden */
+static struct clk versatile_dt_dummy_apb_pclk;
+static struct clk_lookup versatile_dt_dummy_apb_cl = {
+	.con_id = "apb_pclk",
+	.clk = &versatile_dt_dummy_apb_pclk,
+};
+
+/* Scan for fixed clocks */
+static struct clk *versatile_dt_clk_get(struct device_node *np,
+					const char *output_id, void *data)
+{
+	return data;
+}
+
+static __init void versatile_dt_scan_clks(void)
+{
+	struct device_node *node;
+	const __be32 *rate;
+	struct clk *clk;
+	int rc;
+
+	for_each_compatible_node(node, NULL, "fixed-clock") {
+		rate = of_get_property(node, "clock-frequency", NULL);
+		if (!rate)
+			continue;
+
+		clk = kzalloc(sizeof(*clk), GFP_KERNEL);
+		if (!clk)
+			panic("out of memory\n");
+		clk->rate = be32_to_cpup(rate);
+
+		rc = of_clk_add_provider(node, versatile_dt_clk_get, clk);
+		if (rc) {
+			kfree(clk);
+			pr_err("error adding fixed clk %s\n", node->name);
+		}
+	}
+}
+static void __init versatile_dt_init(void)
+{
+	struct device_node *node;
+
+	clkdev_add(&versatile_dt_dummy_apb_cl);
+	versatile_dt_scan_clks();
+
+	node = of_find_node_by_path("/amba");
+	if (node)
+		of_amba_bus_populate(node, NULL);
+}
+
+static const char *versatile_dt_match[] __initdata = {
+	"arm,versatile-ab",
+	"arm,versatile-pb",
+	NULL,
+};
+
+DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
+	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
+	.boot_params	= 0x00000100,
+	.map_io		= versatile_map_io,
+	.init_irq	= versatile_init_irq,
+	.timer		= &versatile_timer,
+	.init_machine	= versatile_dt_init,
+	.dt_compat	= versatile_dt_match,
+MACHINE_END
diff --git a/arch/arm/mach-versatile/versatile_pb.c b/arch/arm/mach-versatile/versatile_pb.c
index eba12fa..bf46964 100644
--- a/arch/arm/mach-versatile/versatile_pb.c
+++ b/arch/arm/mach-versatile/versatile_pb.c
@@ -106,11 +106,6 @@ static void __init versatile_pb_init(void)
 	}
 }
 
-static const char *versatile_pb_match[] __initdata = {
-	"arm,versatile-pb",
-	NULL,
-};
-
 MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	/* Maintainer: ARM Ltd/Deep Blue Solutions Ltd */
 	.boot_params	= 0x00000100,
@@ -118,5 +113,4 @@ MACHINE_START(VERSATILE_PB, "ARM-Versatile PB")
 	.init_irq	= versatile_init_irq,
 	.timer		= &versatile_timer,
 	.init_machine	= versatile_pb_init,
-	.dt_compat	= versatile_pb_match,
 MACHINE_END
diff --git a/arch/arm/plat-versatile/clock.c b/arch/arm/plat-versatile/clock.c
index 5c8b656..44545de 100644
--- a/arch/arm/plat-versatile/clock.c
+++ b/arch/arm/plat-versatile/clock.c
@@ -13,6 +13,8 @@
 #include <linux/errno.h>
 #include <linux/clk.h>
 #include <linux/mutex.h>
+#include <linux/err.h>
+#include <linux/slab.h>
 
 #include <asm/hardware/icst.h>
 
diff --git a/drivers/of/clock.c b/drivers/of/clock.c
index 3e2b221..7b5ea67 100644
--- a/drivers/of/clock.c
+++ b/drivers/of/clock.c
@@ -131,4 +131,3 @@ struct clk *of_clk_get(struct device *dev, const char *id)
 
 	return clk;
 }
-

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

* Re: [RFC PATCH 3/5] of: add clock providers
  2011-01-26  4:44   ` Grant Likely
@ 2011-01-26  5:47     ` Paul Mundt
  -1 siblings, 0 replies; 25+ messages in thread
From: Paul Mundt @ 2011-01-26  5:47 UTC (permalink / raw)
  To: Grant Likely
  Cc: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel,
	nicolas.pitre

On Tue, Jan 25, 2011 at 09:44:17PM -0700, Grant Likely wrote:
> +struct clk *of_clk_get(struct device *dev, const char *id)
> +{
...
> +	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");
> +	prop = of_get_property(dev->of_node, prop_name, &sz);
> +	if (!prop || sz < 4)
> +		return NULL;
...
> +	 * size of the property. */
> +	if (strlen(prop) + 1 > sz)
> +		return NULL;
> +
> +	/* Find the clock provider node; check if it is registered as a
> +	 * provider, and ask it for the relevant clk structure */
> +	provnode = of_find_node_by_phandle(provhandle);
> +	if (!provnode) {
> +		pr_warn("%s: %s property in node %s references invalid phandle",
> +			__func__, prop_name, dev->of_node->full_name);
> +		return NULL;
...

> +	return clk;
> +}

On Tue, Jan 25, 2011 at 09:44:22PM -0700, Grant Likely wrote:
> @@ -79,6 +81,11 @@ EXPORT_SYMBOL(clk_get_sys);
>  struct clk *clk_get(struct device *dev, const char *con_id)
>  {
>  	const char *dev_id = dev ? dev_name(dev) : NULL;
> +	struct clk *clk;
> +
> +	clk = of_clk_get(dev, con_id);
> +	if (clk && __clk_get(clk))
> +		return clk;
>  
>  	return clk_get_sys(dev_id, con_id);
>  }
> 

The return value for clk_get() by almost all users is checked for
specifically with IS_ERR() rather than an IS_ERR_OR_NULL(), so you're
going to want to change your of_clk_get() error paths to return
ERR_PTR()'s directly, or wrap it up like clk_get_sys() does.

Given that there are multiple reasons why of_clk_get() can fail however,
it's probably worth handing down the actual error rather than simply
chomping it in to an -ENOENT.

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

* [RFC PATCH 3/5] of: add clock providers
@ 2011-01-26  5:47     ` Paul Mundt
  0 siblings, 0 replies; 25+ messages in thread
From: Paul Mundt @ 2011-01-26  5:47 UTC (permalink / raw)
  To: linux-arm-kernel

On Tue, Jan 25, 2011 at 09:44:17PM -0700, Grant Likely wrote:
> +struct clk *of_clk_get(struct device *dev, const char *id)
> +{
...
> +	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");
> +	prop = of_get_property(dev->of_node, prop_name, &sz);
> +	if (!prop || sz < 4)
> +		return NULL;
...
> +	 * size of the property. */
> +	if (strlen(prop) + 1 > sz)
> +		return NULL;
> +
> +	/* Find the clock provider node; check if it is registered as a
> +	 * provider, and ask it for the relevant clk structure */
> +	provnode = of_find_node_by_phandle(provhandle);
> +	if (!provnode) {
> +		pr_warn("%s: %s property in node %s references invalid phandle",
> +			__func__, prop_name, dev->of_node->full_name);
> +		return NULL;
...

> +	return clk;
> +}

On Tue, Jan 25, 2011 at 09:44:22PM -0700, Grant Likely wrote:
> @@ -79,6 +81,11 @@ EXPORT_SYMBOL(clk_get_sys);
>  struct clk *clk_get(struct device *dev, const char *con_id)
>  {
>  	const char *dev_id = dev ? dev_name(dev) : NULL;
> +	struct clk *clk;
> +
> +	clk = of_clk_get(dev, con_id);
> +	if (clk && __clk_get(clk))
> +		return clk;
>  
>  	return clk_get_sys(dev_id, con_id);
>  }
> 

The return value for clk_get() by almost all users is checked for
specifically with IS_ERR() rather than an IS_ERR_OR_NULL(), so you're
going to want to change your of_clk_get() error paths to return
ERR_PTR()'s directly, or wrap it up like clk_get_sys() does.

Given that there are multiple reasons why of_clk_get() can fail however,
it's probably worth handing down the actual error rather than simply
chomping it in to an -ENOENT.

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

* Re: [RFC,1/5] arm/dt: Add dt machine definition
  2011-01-26  4:44   ` Grant Likely
@ 2011-01-26 18:27     ` Milton Miller
  -1 siblings, 0 replies; 25+ messages in thread
From: Milton Miller @ 2011-01-26 18:27 UTC (permalink / raw)
  To: Grant Likely
  Cc: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel,
	nicolas.pitre

On Wed, 26 Jan 2011 about 04:44:06 -0000, Grant Likely wrote:
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

needs a description ...
> 
> ---
> arch/arm/include/asm/mach/arch.h |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> 
>  
> +#define MACH_TYPE_DT	0xffffffff
> +
> +#define DT_MACHINE_START(_name, _namestr)		\
> +static const struct machine_desc __mach_desc_##_name	\
> + __used							\
> + __attribute__((__section__(".arch.info.init"))) = {	\

linux/compiler.h defines __section for this

> +	.nr		= MACH_TYPE_DT,			\
> +	.name		= _namestr,
> +
>  #endif

milton

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

* [RFC,1/5] arm/dt: Add dt machine definition
@ 2011-01-26 18:27     ` Milton Miller
  0 siblings, 0 replies; 25+ messages in thread
From: Milton Miller @ 2011-01-26 18:27 UTC (permalink / raw)
  To: linux-arm-kernel

On Wed, 26 Jan 2011 about 04:44:06 -0000, Grant Likely wrote:
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

needs a description ...
> 
> ---
> arch/arm/include/asm/mach/arch.h |    9 +++++++++
>  1 files changed, 9 insertions(+), 0 deletions(-)
> 
> 
>  
> +#define MACH_TYPE_DT	0xffffffff
> +
> +#define DT_MACHINE_START(_name, _namestr)		\
> +static const struct machine_desc __mach_desc_##_name	\
> + __used							\
> + __attribute__((__section__(".arch.info.init"))) = {	\

linux/compiler.h defines __section for this

> +	.nr		= MACH_TYPE_DT,			\
> +	.name		= _namestr,
> +
>  #endif

milton

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

* Re: [RFC,1/5] arm/dt: Add dt machine definition
  2011-01-26 18:27     ` Milton Miller
  (?)
@ 2011-01-27  3:31     ` Grant Likely
  -1 siblings, 0 replies; 25+ messages in thread
From: Grant Likely @ 2011-01-27  3:31 UTC (permalink / raw)
  To: Milton Miller
  Cc: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel,
	nicolas.pitre

On Wed, Jan 26, 2011 at 11:27 AM, Milton Miller <miltonm@bga.com> wrote:
> On Wed, 26 Jan 2011 about 04:44:06 -0000, Grant Likely wrote:
>>
>> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
>
> needs a description ...

oops

>>
>> ---
>> arch/arm/include/asm/mach/arch.h |    9 +++++++++
>>  1 files changed, 9 insertions(+), 0 deletions(-)
>>
>>
>>
>> +#define MACH_TYPE_DT 0xffffffff
>> +
>> +#define DT_MACHINE_START(_name, _namestr)            \
>> +static const struct machine_desc __mach_desc_##_name \
>> + __used                                                      \
>> + __attribute__((__section__(".arch.info.init"))) = { \
>
> linux/compiler.h defines __section for this

For commonality, I duplicated what was already done for #define
MACHINE_START in this same file.  However, I'm not even entirely sure
that I'm going to keep this hunk around.  With some of the recent
changes to the arm-dt patches, a special DT machine id of 0xffffffff
is no longer needed.  This patch may get dropped in a future posting
of this series.

g.

>
>> +     .nr             = MACH_TYPE_DT,                 \
>> +     .name           = _namestr,
>> +
>>  #endif
>
> milton
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.

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

* Re: [RFC PATCH 3/5] of: add clock providers
  2011-01-26  4:44   ` Grant Likely
@ 2011-02-01 22:42     ` Rob Herring
  -1 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2011-02-01 22:42 UTC (permalink / raw)
  To: Grant Likely
  Cc: devicetree-discuss, jeremy.kerr, linux-kernel, linux-arm-kernel,
	nicolas.pitre

Grant,

On 01/25/2011 10:44 PM, Grant Likely wrote:
> +struct clk *of_clk_get(struct device *dev, const char *id)

It would help if this took a struct device_node rather than struct 
device. This would allow using of_clk_get directly for cases where you 
don't have a struct device. This is fairly common in core platform core 
which are not full drivers. The case I have run into is the timer init 
code. To make clk_get work, I would have to create a dummy struct device.

Alternatively, an of_clk_get_sys function is needed.

 > +{
> +	struct device_node *provnode;
> +	u32 provhandle;
> +	int sz;
> +	struct clk *clk;
> +	char prop_name[32]; /* 32 is max size of property name */
> +	const void *prop;
> +
> +	dev_dbg(dev, "Looking up %s-clock from device tree\n", id);
> +
> +	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");

Many times a module just has 1 clock and id will be NULL. Is "bus-clock" 
really the best choice of name? A bus clock may exist, but be 
transparent to s/w. How about allowing "clock" or "%s-clock"?

If bus-clock is the default, then you should add this to the clock 
binding wiki page.

Rob

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

* [RFC PATCH 3/5] of: add clock providers
@ 2011-02-01 22:42     ` Rob Herring
  0 siblings, 0 replies; 25+ messages in thread
From: Rob Herring @ 2011-02-01 22:42 UTC (permalink / raw)
  To: linux-arm-kernel

Grant,

On 01/25/2011 10:44 PM, Grant Likely wrote:
> +struct clk *of_clk_get(struct device *dev, const char *id)

It would help if this took a struct device_node rather than struct 
device. This would allow using of_clk_get directly for cases where you 
don't have a struct device. This is fairly common in core platform core 
which are not full drivers. The case I have run into is the timer init 
code. To make clk_get work, I would have to create a dummy struct device.

Alternatively, an of_clk_get_sys function is needed.

 > +{
> +	struct device_node *provnode;
> +	u32 provhandle;
> +	int sz;
> +	struct clk *clk;
> +	char prop_name[32]; /* 32 is max size of property name */
> +	const void *prop;
> +
> +	dev_dbg(dev, "Looking up %s-clock from device tree\n", id);
> +
> +	snprintf(prop_name, 32, "%s-clock", id ? id : "bus");

Many times a module just has 1 clock and id will be NULL. Is "bus-clock" 
really the best choice of name? A bus clock may exist, but be 
transparent to s/w. How about allowing "clock" or "%s-clock"?

If bus-clock is the default, then you should add this to the clock 
binding wiki page.

Rob

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

end of thread, other threads:[~2011-02-01 22:42 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-26  4:44 [RFC PATCH 0/5] arm/dt: register devices from device tree Grant Likely
2011-01-26  4:44 ` Grant Likely
2011-01-26  4:44 ` Grant Likely
2011-01-26  4:44 ` [RFC PATCH 1/5] arm/dt: Add dt machine definition Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26 18:27   ` [RFC,1/5] " Milton Miller
2011-01-26 18:27     ` Milton Miller
2011-01-27  3:31     ` Grant Likely
2011-01-26  4:44 ` [RFC PATCH 2/5] drivers/amba: probe via device tree Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44 ` [RFC PATCH 3/5] of: add clock providers Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  5:47   ` Paul Mundt
2011-01-26  5:47     ` Paul Mundt
2011-02-01 22:42   ` Rob Herring
2011-02-01 22:42     ` Rob Herring
2011-01-26  4:44 ` [RFC PATCH 4/5] arm/clkdev: lookup clocks from OF " Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44 ` [RFC PATCH 5/5] arm/versatile: add a device tree versatile platform Grant Likely
2011-01-26  4:44   ` Grant Likely
2011-01-26  4:44   ` Grant Likely

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