LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 0/4] clk: st: New clock domain
@ 2015-01-26 11:13 Lee Jones
  2015-01-26 11:13 ` [PATCH 1/4] ARM: sti: stih407-family: Supply defines for CLOCKGEN A0 Lee Jones
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Lee Jones @ 2015-01-26 11:13 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, mturquette, sboyd, devicetree

ST hardware have a bunch of clocks which must not be turned off.
If drivers a) fail to obtain a reference to any of these or b) give
up a previously obtained reference during suspend, the common clk
framework will attempt to turn them off and the hardware will
subsequently die.  The only way to recover from this failure is to
restart.

To avoid either of these two scenarios from catastrophically
disabling the running system we have implemented a clock domain
where clocks are consumed and references are taken, thus preventing
them from being shut down by the framework.

Lee Jones (4):
  ARM: sti: stih407-family: Supply defines for CLOCKGEN A0
  ARM: sti: stih407-family: Provide Clock Domain information
  clk: st: Provide a clock domain
  clk: dt: st: Introduce clock domain documentation

 .../devicetree/bindings/clock/st/st,clk-domain.txt | 34 ++++++++++++
 arch/arm/boot/dts/stih407-family.dtsi              | 13 +++++
 drivers/clk/st/Makefile                            |  2 +-
 drivers/clk/st/clk-domain.c                        | 63 ++++++++++++++++++++++
 include/dt-bindings/clock/stih407-clks.h           |  4 ++
 5 files changed, 115 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
 create mode 100644 drivers/clk/st/clk-domain.c

-- 
1.9.1


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

* [PATCH 1/4] ARM: sti: stih407-family: Supply defines for CLOCKGEN A0
  2015-01-26 11:13 [PATCH 0/4] clk: st: New clock domain Lee Jones
@ 2015-01-26 11:13 ` Lee Jones
  2015-01-26 11:13 ` [PATCH 2/4] ARM: sti: stih407-family: Provide Clock Domain information Lee Jones
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2015-01-26 11:13 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, mturquette, sboyd, devicetree

There are 2 LMI clocks generated by CLOCKGEN A0.  We wish to control
them individually and need to use these indexes to do so.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 include/dt-bindings/clock/stih407-clks.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/include/dt-bindings/clock/stih407-clks.h b/include/dt-bindings/clock/stih407-clks.h
index 7af2b71..082edd9 100644
--- a/include/dt-bindings/clock/stih407-clks.h
+++ b/include/dt-bindings/clock/stih407-clks.h
@@ -5,6 +5,10 @@
 #ifndef _DT_BINDINGS_CLK_STIH407
 #define _DT_BINDINGS_CLK_STIH407
 
+/* CLOCKGEN A0 */
+#define CLK_IC_LMI0		0
+#define CLK_IC_LMI1		1
+
 /* CLOCKGEN C0 */
 #define CLK_ICN_GPU		0
 #define CLK_FDMA		1
-- 
1.9.1


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

* [PATCH 2/4] ARM: sti: stih407-family: Provide Clock Domain information
  2015-01-26 11:13 [PATCH 0/4] clk: st: New clock domain Lee Jones
  2015-01-26 11:13 ` [PATCH 1/4] ARM: sti: stih407-family: Supply defines for CLOCKGEN A0 Lee Jones
@ 2015-01-26 11:13 ` Lee Jones
  2015-01-26 11:13 ` [PATCH 3/4] clk: st: Provide a clock domain Lee Jones
  2015-01-26 11:14 ` [PATCH 4/4] clk: dt: st: Introduce clock domain documentation Lee Jones
  3 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2015-01-26 11:13 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, mturquette, sboyd, devicetree

Certain clocks should not be turned of by clk_disable_unused.  Until
now we have been using the kernel command-line of the same name to
prevent common clk from turning off all clocks without a reference,
as this would ensure hardware lockup.  This patch lists each clock
which need to stay on to prevent the aforementioned issue from
arising.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 arch/arm/boot/dts/stih407-family.dtsi | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/arm/boot/dts/stih407-family.dtsi b/arch/arm/boot/dts/stih407-family.dtsi
index 3e31d32..0478b41 100644
--- a/arch/arm/boot/dts/stih407-family.dtsi
+++ b/arch/arm/boot/dts/stih407-family.dtsi
@@ -34,6 +34,19 @@
 		reg = <0x08761000 0x1000>, <0x08760100 0x100>;
 	};
 
+	clk-domain {
+		compatible = "st,clk-domain";
+		clocks = <&clk_s_c0_flexgen CLK_EXT2F_A9>,
+			 <&clk_s_c0_flexgen CLK_COMPO_DVP>,
+			 <&clk_s_c0_flexgen CLK_MMC_1>,
+			 <&clk_s_c0_flexgen CLK_ICN_SBC>,
+			 <&clk_s_c0_flexgen CLK_ICN_LMI>,
+			 <&clk_s_c0_flexgen CLK_ICN_CPU>,
+			 <&clk_s_c0_flexgen CLK_TX_ICN_DMU>,
+			 <&clk_s_a0_flexgen CLK_IC_LMI0>,
+			 <&clk_m_a9>;
+	};
+
 	scu@08760000 {
 		compatible = "arm,cortex-a9-scu";
 		reg = <0x08760000 0x1000>;
-- 
1.9.1


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

* [PATCH 3/4] clk: st: Provide a clock domain
  2015-01-26 11:13 [PATCH 0/4] clk: st: New clock domain Lee Jones
  2015-01-26 11:13 ` [PATCH 1/4] ARM: sti: stih407-family: Supply defines for CLOCKGEN A0 Lee Jones
  2015-01-26 11:13 ` [PATCH 2/4] ARM: sti: stih407-family: Provide Clock Domain information Lee Jones
@ 2015-01-26 11:13 ` Lee Jones
  2015-01-26 11:14 ` [PATCH 4/4] clk: dt: st: Introduce clock domain documentation Lee Jones
  3 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2015-01-26 11:13 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, mturquette, sboyd, devicetree

ST's h/w contains clocks which if turned off would prove fatal.  The
only way to recover is to restart the board(s).  This driver takes
references to clocks which are required to be always-on in order to
prevent the common clk framework from trying to turn them off during
the clk_disabled_unused() procedure.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/clk/st/Makefile     |  2 +-
 drivers/clk/st/clk-domain.c | 63 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 1 deletion(-)
 create mode 100644 drivers/clk/st/clk-domain.c

diff --git a/drivers/clk/st/Makefile b/drivers/clk/st/Makefile
index ede7b2f..ac09be6 100644
--- a/drivers/clk/st/Makefile
+++ b/drivers/clk/st/Makefile
@@ -1 +1 @@
-obj-y += clkgen-mux.o clkgen-pll.o clkgen-fsyn.o clk-flexgen.o
+obj-y += clkgen-mux.o clkgen-pll.o clkgen-fsyn.o clk-flexgen.o clk-domain.o
diff --git a/drivers/clk/st/clk-domain.c b/drivers/clk/st/clk-domain.c
new file mode 100644
index 0000000..e34049b
--- /dev/null
+++ b/drivers/clk/st/clk-domain.c
@@ -0,0 +1,63 @@
+/*
+ * ST Clock Domain
+ *
+ * Copyright (C) 2015 STMicroelectronics – All Rights Reserved
+ *
+ * Author: Lee Jones <lee.jones@linaro.org>
+ *
+ * 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.
+ */
+
+#include <linux/clk-private.h>
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+
+static void st_clk_domain_hog_clock(struct platform_device *pdev, int index)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct clk *clk;
+	int ret;
+
+	clk = of_clk_get(np, index);
+	if (IS_ERR(clk)) {
+		dev_warn(&pdev->dev, "Failed get clock %s[%d]: %li\n",
+			 np->full_name, index, PTR_ERR(clk));
+		return;
+	}
+
+	ret = clk_prepare_enable(clk);
+	if (ret)
+		dev_warn(&pdev->dev, "Failed to enable clock: %s\n", clk->name);
+}
+
+static int st_clk_domain_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	int nclks, i;
+
+	nclks = of_count_phandle_with_args(np, "clocks", "#clock-cells");
+
+	for (i = 0; i < nclks; i++)
+		st_clk_domain_hog_clock(pdev, i);
+
+	return 0;
+}
+
+static const struct of_device_id st_clk_domain_match[] = {
+	{ .compatible = "st,clk-domain" },
+	{ },
+};
+
+static struct platform_driver st_clk_domain_driver = {
+	.probe = st_clk_domain_probe,
+	.driver = {
+		.name = "st-clk-domain",
+		.of_match_table = st_clk_domain_match,
+	},
+};
+module_platform_driver(st_clk_domain_driver);
-- 
1.9.1


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

* [PATCH 4/4] clk: dt: st: Introduce clock domain documentation
  2015-01-26 11:13 [PATCH 0/4] clk: st: New clock domain Lee Jones
                   ` (2 preceding siblings ...)
  2015-01-26 11:13 ` [PATCH 3/4] clk: st: Provide a clock domain Lee Jones
@ 2015-01-26 11:14 ` Lee Jones
  2015-01-28  1:19   ` Mike Turquette
  3 siblings, 1 reply; 7+ messages in thread
From: Lee Jones @ 2015-01-26 11:14 UTC (permalink / raw)
  To: linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, mturquette, sboyd, devicetree

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 .../devicetree/bindings/clock/st/st,clk-domain.txt | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/clock/st/st,clk-domain.txt

diff --git a/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
new file mode 100644
index 0000000..7309937
--- /dev/null
+++ b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
@@ -0,0 +1,34 @@
+STMicroelectronics Clock Domain
+
+ST hardware have a bunch of clocks which must not be turned off.
+If drivers a) fail to obtain a reference to any of these or b) give
+up a previously obtained reference during suspend, the common clk
+framework will attempt to turn them off and the hardware will
+subsequently die.  The only way to recover from this failure is to
+restart.
+
+To avoid either of these two scenarios from catastrophically
+disabling the running system we have implemented a clock domain
+where clocks are consumed and references are taken, thus preventing
+them from being shut down by the framework.
+
+We use the generic clock bindings found in:
+  Documentation/devicetree/bindings/clock/clock-bindings.txt
+
+Required properties:
+- compatible : Must be "st,clk-domain"
+
+Example:
+
+clk-domain {
+	compatible = "st,clk-domain";
+	clocks = <&clk_s_c0_flexgen CLK_EXT2F_A9>,
+		 <&clk_s_c0_flexgen CLK_COMPO_DVP>,
+		 <&clk_s_c0_flexgen CLK_MMC_1>,
+		 <&clk_s_c0_flexgen CLK_ICN_SBC>,
+		 <&clk_s_c0_flexgen CLK_ICN_LMI>,
+		 <&clk_s_c0_flexgen CLK_ICN_CPU>,
+		 <&clk_s_c0_flexgen CLK_TX_ICN_DMU>,
+		 <&clk_s_a0_flexgen CLK_IC_LMI0>,
+		 <&clk_m_a9>;
+};
-- 
1.9.1


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

* Re: [PATCH 4/4] clk: dt: st: Introduce clock domain documentation
  2015-01-26 11:14 ` [PATCH 4/4] clk: dt: st: Introduce clock domain documentation Lee Jones
@ 2015-01-28  1:19   ` Mike Turquette
  2015-01-28  7:58     ` Lee Jones
  0 siblings, 1 reply; 7+ messages in thread
From: Mike Turquette @ 2015-01-28  1:19 UTC (permalink / raw)
  To: Lee Jones, linux-arm-kernel, linux-kernel
  Cc: lee.jones, kernel, sboyd, devicetree

Quoting Lee Jones (2015-01-26 03:14:00)
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
> ---
>  .../devicetree/bindings/clock/st/st,clk-domain.txt | 34 ++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> 
> diff --git a/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> new file mode 100644
> index 0000000..7309937
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> @@ -0,0 +1,34 @@
> +STMicroelectronics Clock Domain
> +
> +ST hardware have a bunch of clocks which must not be turned off.
> +If drivers a) fail to obtain a reference to any of these or b) give
> +up a previously obtained reference during suspend, the common clk
> +framework will attempt to turn them off and the hardware will
> +subsequently die.  The only way to recover from this failure is to
> +restart.
> +
> +To avoid either of these two scenarios from catastrophically
> +disabling the running system we have implemented a clock domain
> +where clocks are consumed and references are taken, thus preventing
> +them from being shut down by the framework.
> +
> +We use the generic clock bindings found in:
> +  Documentation/devicetree/bindings/clock/clock-bindings.txt
> +
> +Required properties:
> +- compatible : Must be "st,clk-domain"

Seems like a useful feature for any clock provider, not just ST's. Have
you thought about making this solution generic for DT-based clock
providers?

We could amend the common clock binding to include a special "always on"
clock group that is automagically prepared and enabled when the clock
provider/driver is registered, using a common function.

Regards,
Mike

> +
> +Example:
> +
> +clk-domain {
> +       compatible = "st,clk-domain";
> +       clocks = <&clk_s_c0_flexgen CLK_EXT2F_A9>,
> +                <&clk_s_c0_flexgen CLK_COMPO_DVP>,
> +                <&clk_s_c0_flexgen CLK_MMC_1>,
> +                <&clk_s_c0_flexgen CLK_ICN_SBC>,
> +                <&clk_s_c0_flexgen CLK_ICN_LMI>,
> +                <&clk_s_c0_flexgen CLK_ICN_CPU>,
> +                <&clk_s_c0_flexgen CLK_TX_ICN_DMU>,
> +                <&clk_s_a0_flexgen CLK_IC_LMI0>,
> +                <&clk_m_a9>;
> +};
> -- 
> 1.9.1
> 

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

* Re: [PATCH 4/4] clk: dt: st: Introduce clock domain documentation
  2015-01-28  1:19   ` Mike Turquette
@ 2015-01-28  7:58     ` Lee Jones
  0 siblings, 0 replies; 7+ messages in thread
From: Lee Jones @ 2015-01-28  7:58 UTC (permalink / raw)
  To: Mike Turquette; +Cc: linux-arm-kernel, linux-kernel, kernel, sboyd, devicetree

On Tue, 27 Jan 2015, Mike Turquette wrote:

> Quoting Lee Jones (2015-01-26 03:14:00)
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> > ---
> >  .../devicetree/bindings/clock/st/st,clk-domain.txt | 34 ++++++++++++++++++++++
> >  1 file changed, 34 insertions(+)
> >  create mode 100644 Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> > 
> > diff --git a/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> > new file mode 100644
> > index 0000000..7309937
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/clock/st/st,clk-domain.txt
> > @@ -0,0 +1,34 @@
> > +STMicroelectronics Clock Domain
> > +
> > +ST hardware have a bunch of clocks which must not be turned off.
> > +If drivers a) fail to obtain a reference to any of these or b) give
> > +up a previously obtained reference during suspend, the common clk
> > +framework will attempt to turn them off and the hardware will
> > +subsequently die.  The only way to recover from this failure is to
> > +restart.
> > +
> > +To avoid either of these two scenarios from catastrophically
> > +disabling the running system we have implemented a clock domain
> > +where clocks are consumed and references are taken, thus preventing
> > +them from being shut down by the framework.
> > +
> > +We use the generic clock bindings found in:
> > +  Documentation/devicetree/bindings/clock/clock-bindings.txt
> > +
> > +Required properties:
> > +- compatible : Must be "st,clk-domain"
> 
> Seems like a useful feature for any clock provider, not just ST's. Have
> you thought about making this solution generic for DT-based clock
> providers?
> 
> We could amend the common clock binding to include a special "always on"
> clock group that is automagically prepared and enabled when the clock
> provider/driver is registered, using a common function.

OMG, I'm actually going to strangle you!

This is what I've been proposing to you (privately) for weeks.

Does this ring any bells?

  "Just FYI, I am not going to add any method to the kernel that
  permanently enables a clock via some new api. At the worst case your
  clock driver can simply call clk_prepare_enable in its probe
  function (there are some examples of this)."

I will be more than happy to make this a generic driver, if thats what
you want (now). ;)

> > +Example:
> > +
> > +clk-domain {
> > +       compatible = "st,clk-domain";
> > +       clocks = <&clk_s_c0_flexgen CLK_EXT2F_A9>,
> > +                <&clk_s_c0_flexgen CLK_COMPO_DVP>,
> > +                <&clk_s_c0_flexgen CLK_MMC_1>,
> > +                <&clk_s_c0_flexgen CLK_ICN_SBC>,
> > +                <&clk_s_c0_flexgen CLK_ICN_LMI>,
> > +                <&clk_s_c0_flexgen CLK_ICN_CPU>,
> > +                <&clk_s_c0_flexgen CLK_TX_ICN_DMU>,
> > +                <&clk_s_a0_flexgen CLK_IC_LMI0>,
> > +                <&clk_m_a9>;
> > +};

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

end of thread, other threads:[~2015-01-28 20:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-26 11:13 [PATCH 0/4] clk: st: New clock domain Lee Jones
2015-01-26 11:13 ` [PATCH 1/4] ARM: sti: stih407-family: Supply defines for CLOCKGEN A0 Lee Jones
2015-01-26 11:13 ` [PATCH 2/4] ARM: sti: stih407-family: Provide Clock Domain information Lee Jones
2015-01-26 11:13 ` [PATCH 3/4] clk: st: Provide a clock domain Lee Jones
2015-01-26 11:14 ` [PATCH 4/4] clk: dt: st: Introduce clock domain documentation Lee Jones
2015-01-28  1:19   ` Mike Turquette
2015-01-28  7:58     ` Lee Jones

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