devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 15/21] tegra: fdt: Add function to return peripheral/clock ID
@ 2012-03-07  3:10 Simon Glass
       [not found] ` <1331089833-25262-16-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-03-07  3:10 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Stephen Warren, Devicetree Discuss, Jerry Van Baren, Tom Warren,
	linux-tegra

A common requirement is to find the clock ID for a peripheral. This is the
second cell of the 'clocks' property (the first being the phandle itself).

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v4:
- Add fdtdec function to return peripheral ID

Changes in v6:
- Move peripheral decode function into Tegra's clock.c

Changes in v7:
- Add belts and braces checking of device tree clock ID

Changes in v8:
- Only include clock_decode_periph_id() when CONFIG_OF_CONTROL defined

 arch/arm/cpu/armv7/tegra2/clock.c        |   58 ++++++++++++++++++++++++++++++
 arch/arm/include/asm/arch-tegra2/clock.h |   13 +++++++
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/arch/arm/cpu/armv7/tegra2/clock.c b/arch/arm/cpu/armv7/tegra2/clock.c
index 11d2346..a94cf81 100644
--- a/arch/arm/cpu/armv7/tegra2/clock.c
+++ b/arch/arm/cpu/armv7/tegra2/clock.c
@@ -28,6 +28,7 @@
 #include <asm/arch/tegra2.h>
 #include <common.h>
 #include <div64.h>
+#include <fdtdec.h>
 
 /*
  * This is our record of the current clock rate of each clock. We don't
@@ -918,6 +919,63 @@ void clock_ll_start_uart(enum periph_id periph_id)
 	reset_set_enable(periph_id, 0);
 }
 
+#ifdef CONFIG_OF_CONTROL
+/*
+ * Convert a device tree clock ID to our peripheral ID. They are mostly
+ * the same but we are very cautious so we check that a valid clock ID is
+ * provided.
+ *
+ * @param clk_id	Clock ID according to tegra2 device tree binding
+ * @return peripheral ID, or PERIPH_ID_NONE if the clock ID is invalid
+ */
+static enum periph_id clk_id_to_periph_id(int clk_id)
+{
+	if (clk_id > 95)
+		return PERIPH_ID_NONE;
+
+	switch (clk_id) {
+	case 1:
+	case 2:
+	case 7:
+	case 10:
+	case 20:
+	case 30:
+	case 35:
+	case 49:
+	case 56:
+	case 74:
+	case 76:
+	case 77:
+	case 78:
+	case 79:
+	case 80:
+	case 81:
+	case 82:
+	case 83:
+	case 91:
+	case 95:
+		return PERIPH_ID_NONE;
+	default:
+		return clk_id;
+	}
+}
+
+int clock_decode_periph_id(const void *blob, int node)
+{
+	enum periph_id id;
+	u32 cell[2];
+	int err;
+
+	err = fdtdec_get_int_array(blob, node, "clocks", cell,
+				   ARRAY_SIZE(cell));
+	if (err)
+		return -1;
+	id = clk_id_to_periph_id(cell[1]);
+	assert(clock_periph_id_isvalid(id));
+	return id;
+}
+#endif /* CONFIG_OF_CONTROL */
+
 int clock_verify(void)
 {
 	struct clk_pll *pll = get_pll(CLOCK_ID_PERIPH);
diff --git a/arch/arm/include/asm/arch-tegra2/clock.h b/arch/arm/include/asm/arch-tegra2/clock.h
index 080ef18..6b12c76 100644
--- a/arch/arm/include/asm/arch-tegra2/clock.h
+++ b/arch/arm/include/asm/arch-tegra2/clock.h
@@ -177,6 +177,7 @@ enum periph_id {
 	PERIPH_ID_CRAM2,
 
 	PERIPH_ID_COUNT,
+	PERIPH_ID_NONE = -1,
 };
 
 /* Converts a clock number to a clock register: 0=L, 1=H, 2=U */
@@ -355,6 +356,18 @@ unsigned clock_get_rate(enum clock_id clkid);
  */
 void clock_ll_start_uart(enum periph_id periph_id);
 
+/**
+ * Decode a peripheral ID from a device tree node.
+ *
+ * This works by looking up the peripheral's 'clocks' node and reading out
+ * the second cell, which is the clock number / peripheral ID.
+ *
+ * @param blob		FDT blob to use
+ * @param node		Node to look at
+ * @return peripheral ID, or PERIPH_ID_NONE if none
+ */
+enum periph_id clock_decode_periph_id(const void *blob, int node);
+
 /*
  * Checks that clocks are valid and prints a warning if not
  *
-- 
1.7.7.3

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

* [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana
       [not found] ` <1331089833-25262-16-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2012-03-07  3:10   ` Simon Glass
       [not found]     ` <1331089833-25262-22-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
  2012-03-07 17:09   ` [PATCH v8 15/21] tegra: fdt: Add function to return peripheral/clock ID Stephen Warren
  1 sibling, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-03-07  3:10 UTC (permalink / raw)
  To: U-Boot Mailing List
  Cc: Tom Warren, Stephen Warren, Simon Glass,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Jerry Van Baren,
	Devicetree Discuss

From: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>

This switches Ventana over to use FDT for run-time config instead of
CONFIG options.

At present Ventana does not have its own device tree file - it just uses
the Seaboard one.

Signed-off-by: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
Acked-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
Changes in v8:
- Add Tom's patch to enable FDT support on Ventana

 include/configs/ventana.h |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/include/configs/ventana.h b/include/configs/ventana.h
index acc9b43..3e55fe5 100644
--- a/include/configs/ventana.h
+++ b/include/configs/ventana.h
@@ -27,6 +27,11 @@
 #include <asm/sizes.h>
 #include "tegra2-common.h"
 
+/* Enable fdt support for Ventana. Flash the image in u-boot-dtb.bin */
+#define CONFIG_DEFAULT_DEVICE_TREE	tegra2-seaboard
+#define CONFIG_OF_CONTROL
+#define CONFIG_OF_SEPARATE
+
 /* High-level configuration options */
 #define TEGRA2_SYSMEM		"mem=384M@0M nvmem=128M@384M mem=512M@512M"
 #define V_PROMPT		"Tegra2 (Ventana) # "
-- 
1.7.7.3

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

* Re: [PATCH v8 15/21] tegra: fdt: Add function to return peripheral/clock ID
       [not found] ` <1331089833-25262-16-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
  2012-03-07  3:10   ` [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana Simon Glass
@ 2012-03-07 17:09   ` Stephen Warren
  1 sibling, 0 replies; 6+ messages in thread
From: Stephen Warren @ 2012-03-07 17:09 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Warren,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Jerry Van Baren,
	Devicetree Discuss

On 03/06/2012 08:10 PM, Simon Glass wrote:
> A common requirement is to find the clock ID for a peripheral. This is the
> second cell of the 'clocks' property (the first being the phandle itself).
> 
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
...
> Changes in v8:
> - Only include clock_decode_periph_id() when CONFIG_OF_CONTROL defined

Acked-by: Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>

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

* Re: [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana
       [not found]     ` <1331089833-25262-22-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
@ 2012-03-07 17:10       ` Stephen Warren
       [not found]         ` <4F579697.4050108-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Warren @ 2012-03-07 17:10 UTC (permalink / raw)
  To: Simon Glass
  Cc: U-Boot Mailing List, Tom Warren,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Jerry Van Baren,
	Devicetree Discuss

On 03/06/2012 08:10 PM, Simon Glass wrote:
> From: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> 
> This switches Ventana over to use FDT for run-time config instead of
> CONFIG options.
> 
> At present Ventana does not have its own device tree file - it just uses
> the Seaboard one.

But there's a Ventana-specific tegra-ventana.dts in the kernel...

> Signed-off-by: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> Acked-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>

Have you tested this on Ventana in mainline U-Boot?

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

* Re: [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana
       [not found]         ` <4F579697.4050108-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
@ 2012-03-07 17:14           ` Simon Glass
       [not found]             ` <CAPnjgZ0CF2Ytoj35MvdpEJa-g7JozG2U7xtQjPEGM4+p_ehtwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Simon Glass @ 2012-03-07 17:14 UTC (permalink / raw)
  To: Stephen Warren
  Cc: U-Boot Mailing List, Tom Warren,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA, Jerry Van Baren,
	Devicetree Discuss

Hi Stephen,

On Wed, Mar 7, 2012 at 9:10 AM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org> wrote:
> On 03/06/2012 08:10 PM, Simon Glass wrote:
>> From: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>>
>> This switches Ventana over to use FDT for run-time config instead of
>> CONFIG options.
>>
>> At present Ventana does not have its own device tree file - it just uses
>> the Seaboard one.
>
> But there's a Ventana-specific tegra-ventana.dts in the kernel...

Yes, that's right. Perhaps we should drop this patch for now? Ventana
will still build, just not have USB support.

>
>> Signed-off-by: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
>> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>> Acked-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
>
> Have you tested this on Ventana in mainline U-Boot?

I have not, but I think Tom has - maybe Tom you can reply Tested-by here if so?

Regards,
Simon

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

* RE: [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana
       [not found]             ` <CAPnjgZ0CF2Ytoj35MvdpEJa-g7JozG2U7xtQjPEGM4+p_ehtwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2012-03-07 18:18               ` Tom Warren
  0 siblings, 0 replies; 6+ messages in thread
From: Tom Warren @ 2012-03-07 18:18 UTC (permalink / raw)
  To: Simon Glass, Stephen Warren
  Cc: U-Boot Mailing List,
	linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Jerry Van Baren, Devicetree Discuss

Simon/Stephen,

> -----Original Message-----
> From: sjg-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org [mailto:sjg-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org] On Behalf Of Simon Glass
> Sent: Wednesday, March 07, 2012 10:15 AM
> To: Stephen Warren
> Cc: U-Boot Mailing List; Tom Warren; linux-tegra-u79uwXL29TY76Z2rM5mHXA@public.gmane.org; Jerry Van
> Baren; Devicetree Discuss
> Subject: Re: [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana
> 
> Hi Stephen,
> 
> On Wed, Mar 7, 2012 at 9:10 AM, Stephen Warren <swarren-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
> wrote:
> > On 03/06/2012 08:10 PM, Simon Glass wrote:
> >> From: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >>
> >> This switches Ventana over to use FDT for run-time config instead of
> >> CONFIG options.
> >>
> >> At present Ventana does not have its own device tree file - it just
> >> uses the Seaboard one.
> >
> > But there's a Ventana-specific tegra-ventana.dts in the kernel...
> 
> Yes, that's right. Perhaps we should drop this patch for now? Ventana will
> still build, just not have USB support.
> 
> >
> >> Signed-off-by: Tom Warren <twarren-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>
> >> Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> >> Acked-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
> >
> > Have you tested this on Ventana in mainline U-Boot?
> 
> I have not, but I think Tom has - maybe Tom you can reply Tested-by here if
> so?
I haven't tested on Ventana yet (just got my board last week), but I will when I apply these patches and report back. If you want to drop the patch for now until you can get a tegra-ventana.dts prepped, that's fine by me, too.

Tom

-- 
nvpublic
> 
> Regards,
> Simon

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

end of thread, other threads:[~2012-03-07 18:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-07  3:10 [PATCH v8 15/21] tegra: fdt: Add function to return peripheral/clock ID Simon Glass
     [not found] ` <1331089833-25262-16-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-07  3:10   ` [PATCH v8 21/21] tegra: fdt: Enable FDT support for Ventana Simon Glass
     [not found]     ` <1331089833-25262-22-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-03-07 17:10       ` Stephen Warren
     [not found]         ` <4F579697.4050108-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2012-03-07 17:14           ` Simon Glass
     [not found]             ` <CAPnjgZ0CF2Ytoj35MvdpEJa-g7JozG2U7xtQjPEGM4+p_ehtwA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-07 18:18               ` Tom Warren
2012-03-07 17:09   ` [PATCH v8 15/21] tegra: fdt: Add function to return peripheral/clock ID Stephen Warren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).