devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC 0/2] clk: dt: generic DT preset clock frequency bindings
@ 2013-12-20 22:08 James Hogan
  2013-12-20 22:08 ` [RFC 1/2] dt: binding: add clock-N-frequency to common clock bindings James Hogan
  2013-12-20 22:08 ` [RFC 2/2] clk: implement generic DT preset clock frequency James Hogan
  0 siblings, 2 replies; 3+ messages in thread
From: James Hogan @ 2013-12-20 22:08 UTC (permalink / raw)
  To: Mike Turquette, Russell King,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
	devicetree-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, James Hogan

These patches add a property "clock-N-frequency" to the clock consumer
bindings to specify the frequency that a clock should be configured to
when it is made use of. N is the index of a clock specifier in the
clocks property, starting at 0.

It's RFC since there are plenty of ways it could be handled, I've pretty
much just tried the simplest, but I'd like to get some thoughts from
others:
 - Adding such properties to individual device drivers / bindings. The
   bindings could be standardised and handled generically like in this
   patch, although it's not very nicely extensible to more complex
   settings (e.g. setting a particular clock's parent up the hierarchy a
   bit).
 - Adding named phandles like pinctrl clients do for pin configuration
   but to describe clock configuration, the "default" of which is set up
   automatically when a device is probed. This is more extensible, and
   certainly more complex. I suspect it may be overkill.

The point is to avoid the need to add clock-frequency properties to
individual device bindings or modify drivers to set the frequency of
clocks to that requested in device tree. Instead the driver can just
read the rate of the clock as if it was fixed without needing to know
how it has been configured.

This is aimed at devices where it's difficult for drivers to determine
what a clock should be set to, and either there is a recommended
frequency for the particular system or a chosen frequency for the
particular application of the system (which makes it essentially
configuration data).

James Hogan (2):
  dt: binding: add clock-N-frequency to common clock bindings
  clk: implement generic DT preset clock frequency

 .../devicetree/bindings/clock/clock-bindings.txt   |  3 ++
 drivers/clk/clk.c                                  | 34 ++++++++++++++++++++++
 drivers/clk/clkdev.c                               |  3 ++
 include/linux/clk.h                                |  5 ++++
 4 files changed, 45 insertions(+)

-- 
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

* [RFC 1/2] dt: binding: add clock-N-frequency to common clock bindings
  2013-12-20 22:08 [RFC 0/2] clk: dt: generic DT preset clock frequency bindings James Hogan
@ 2013-12-20 22:08 ` James Hogan
  2013-12-20 22:08 ` [RFC 2/2] clk: implement generic DT preset clock frequency James Hogan
  1 sibling, 0 replies; 3+ messages in thread
From: James Hogan @ 2013-12-20 22:08 UTC (permalink / raw)
  To: Mike Turquette, Russell King, linux-arm-kernel, devicetree
  Cc: linux-kernel, James Hogan, Ian Campbell, Mark Rutland, Pawel Moll,
	Rob Herring, Stephen Warren, Rob Landley, linux-doc

Add a property "clock-N-frequency" to the clock consumer bindings to
specify the frequency that a clock should be configured to when it is
made use of. N is the index of a clock specifier in the clocks property,
starting at 0.

This avoids the need to add clock-frequency properties to individual
device bindings or modify drivers to set the frequency of clocks to that
requested in device tree. Instead the driver can just read the rate of
the clock as if it was fixed.

This is aimed at devices where it's difficult for drivers to determine
what a clock should be set to, and either there is a recommended
frequency for the particular system or a chosen frequency for the
particular application of the system (which makes it essentially
configuration data).

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Cc: Ian Campbell <ijc+devicetree@hellion.org.uk>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: devicetree@vger.kernel.org
Cc: Rob Landley <rob@landley.net>
Cc: linux-doc@vger.kernel.org
---
 Documentation/devicetree/bindings/clock/clock-bindings.txt | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/clock/clock-bindings.txt b/Documentation/devicetree/bindings/clock/clock-bindings.txt
index eb65d41..e8bca1a 100644
--- a/Documentation/devicetree/bindings/clock/clock-bindings.txt
+++ b/Documentation/devicetree/bindings/clock/clock-bindings.txt
@@ -60,6 +60,9 @@ clock-names:	List of clock input name strings sorted in the same
 clock-ranges:	Empty property indicating that child nodes can inherit named
 		clocks from this node. Useful for bus nodes to provide a
 		clock to their children.
+clock-N-frequency: Single cell specifying the frequency in HZ to set the N'th
+		clock to when it is used. N=0 corresponds to the first clock
+		specifier in the clocks property.
 
 For example:
 
-- 
1.8.3.2

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

* [RFC 2/2] clk: implement generic DT preset clock frequency
  2013-12-20 22:08 [RFC 0/2] clk: dt: generic DT preset clock frequency bindings James Hogan
  2013-12-20 22:08 ` [RFC 1/2] dt: binding: add clock-N-frequency to common clock bindings James Hogan
@ 2013-12-20 22:08 ` James Hogan
  1 sibling, 0 replies; 3+ messages in thread
From: James Hogan @ 2013-12-20 22:08 UTC (permalink / raw)
  To: Mike Turquette, Russell King, linux-arm-kernel, devicetree
  Cc: linux-kernel, James Hogan

Implement the clock-N-frequency clock consumer property to preset a
clock to a particular frequency when it is requested by a driver.

This adds a new of_clk_setup_preset() which is called from the end of
of_clk_get(). It simply looks in the consumer node for a property named
"clock-<index>-frequency" and attempts to set the clock frequency if
found.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Mike Turquette <mturquette@linaro.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
---
 drivers/clk/clk.c    | 34 ++++++++++++++++++++++++++++++++++
 drivers/clk/clkdev.c |  3 +++
 include/linux/clk.h  |  5 +++++
 3 files changed, 42 insertions(+)

diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 2cf2ea6..3f518a2 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -2252,4 +2252,38 @@ void __init of_clk_init(const struct of_device_id *matches)
 		clk_init_cb(np);
 	}
 }
+
+/**
+ * of_clk_setup_preset() - Set up a clock from device tree when it is requested
+ * @np:		pointer to clock consumer node
+ * @index:	consumer index of clock that has been requested
+ * @clk:	struct clk *
+ *
+ * This function is called when a clock is requested by a driver. It scans the
+ * clock consumer node for properties which indicate defaults for how the clock
+ * should be set up.
+ *
+ * Properties looked for are:
+ * - clock-N-frequency
+ */
+void of_clk_setup_preset(struct device_node *np, int index, struct clk *clk)
+{
+	u32 rate;
+	int ret;
+	char prop_name[24];
+
+	/* look for a clock-N-frequency property */
+	snprintf(prop_name, sizeof(prop_name),
+		 "clock-%d-frequency", index);
+	if (!of_property_read_u32(np, prop_name, &rate)) {
+		/* try to set the frequency to that specified in DT */
+		ret = clk_set_rate(clk, rate);
+		if (ret)
+			pr_err("Failed to preset clock %d (%s) of %s to %u Hz\n",
+				 index, clk->name, np->full_name, rate);
+		else
+			pr_debug("Preset clock %d (%s) of %s to %u Hz\n",
+				 index, clk->name, np->full_name, rate);
+	}
+}
 #endif
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index 442a313..edcd67f 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -41,6 +41,9 @@ struct clk *of_clk_get(struct device_node *np, int index)
 
 	clk = of_clk_get_from_provider(&clkspec);
 	of_node_put(clkspec.np);
+
+	if (!IS_ERR(clk))
+		of_clk_setup_preset(np, index, clk);
 	return clk;
 }
 EXPORT_SYMBOL(of_clk_get);
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 9a6d045..3e112ea 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -368,6 +368,7 @@ struct of_phandle_args;
 struct clk *of_clk_get(struct device_node *np, int index);
 struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
 struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
+void of_clk_setup_preset(struct device_node *np, int index, struct clk *clk);
 #else
 static inline struct clk *of_clk_get(struct device_node *np, int index)
 {
@@ -378,6 +379,10 @@ static inline struct clk *of_clk_get_by_name(struct device_node *np,
 {
 	return ERR_PTR(-ENOENT);
 }
+static inline void of_clk_setup_preset(struct device_node *np, int index,
+				       struct clk *clk)
+{
+}
 #endif
 
 #endif
-- 
1.8.3.2

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

end of thread, other threads:[~2013-12-20 22:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-20 22:08 [RFC 0/2] clk: dt: generic DT preset clock frequency bindings James Hogan
2013-12-20 22:08 ` [RFC 1/2] dt: binding: add clock-N-frequency to common clock bindings James Hogan
2013-12-20 22:08 ` [RFC 2/2] clk: implement generic DT preset clock frequency James Hogan

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).