* [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver
[not found] <1454348370-3816-1-git-send-email-andre.przywara@arm.com>
@ 2016-02-01 17:39 ` Andre Przywara
2016-02-01 18:40 ` Jean-Francois Moine
2016-02-01 17:39 ` [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name Andre Przywara
` (2 subsequent siblings)
3 siblings, 1 reply; 10+ messages in thread
From: Andre Przywara @ 2016-02-01 17:39 UTC (permalink / raw)
To: Maxime Ripard, Chen-Yu Tsai, linux-sunxi
Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk, Jens Kuske
The Allwinner H3 SoC introduced bus clock gates with potentially
different parents per clock gate. The H3 driver chose to hardcode the
actual parent clock relation in the code.
Add a new driver (which has the potential to drive the H3 and also
the simple clock gates as well) which uses the power of DT to describe
this relationship in an elegant and flexible way.
Using one subnode for every parent clock we get away with a single
DT compatible match, which can be used as a fallback value in the
actual DTs without the need to add specific compatible strings to the
code. This avoids adding a new driver or function for every new SoC.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Changelog RFC .. v1:
- fix IRQ muxes to cover the three banks of the SoC
- amend naming of PCM pins
drivers/clk/sunxi/Makefile | 1 +
drivers/clk/sunxi/clk-multi-gates.c | 105 ++++++++++++++++++++++++++++++++++++
2 files changed, 106 insertions(+)
create mode 100644 drivers/clk/sunxi/clk-multi-gates.c
diff --git a/drivers/clk/sunxi/Makefile b/drivers/clk/sunxi/Makefile
index 3fd7901..3a9dc31 100644
--- a/drivers/clk/sunxi/Makefile
+++ b/drivers/clk/sunxi/Makefile
@@ -11,6 +11,7 @@ obj-y += clk-a10-ve.o
obj-y += clk-a20-gmac.o
obj-y += clk-mod0.o
obj-y += clk-simple-gates.o
+obj-y += clk-multi-gates.o
obj-y += clk-sun8i-bus-gates.o
obj-y += clk-sun8i-mbus.o
obj-y += clk-sun9i-core.o
diff --git a/drivers/clk/sunxi/clk-multi-gates.c b/drivers/clk/sunxi/clk-multi-gates.c
new file mode 100644
index 0000000..76e715a
--- /dev/null
+++ b/drivers/clk/sunxi/clk-multi-gates.c
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2016 ARM Ltd.
+ *
+ * Based on clk-sun8i-bus-gates.c, which is:
+ * Copyright (C) 2015 Jens Kuske <jenskuske@gmail.com>
+ * Based on clk-simple-gates.c, which is:
+ * Copyright 2015 Maxime Ripard <maxime.ripard@free-electrons.com>
+ *
+ * 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.
+ */
+
+#include <linux/clk-provider.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+
+static DEFINE_SPINLOCK(gates_lock);
+
+static void __init sunxi_parse_parent(struct device_node *node,
+ struct clk_onecell_data *clk_data,
+ void __iomem *reg)
+{
+ const char *parent = of_clk_get_parent_name(node, 0);
+ const char *clk_name;
+ struct property *prop;
+ struct clk *clk;
+ const __be32 *p;
+ int index, i = 0;
+
+ of_property_for_each_u32(node, "clock-indices", prop, p, index) {
+ of_property_read_string_index(node, "clock-output-names",
+ i, &clk_name);
+
+ clk = clk_register_gate(NULL, clk_name, parent, 0,
+ reg + 4 * (index / 32), index % 32,
+ 0, &gates_lock);
+ i++;
+ if (IS_ERR(clk)) {
+ pr_warn("could not register gate clock \"%s\"\n",
+ clk_name);
+ continue;
+ }
+ if (clk_data->clks[index])
+ pr_warn("bus-gate clock %s: index #%d already registered as %s\n",
+ clk_name, index, "?");
+ else
+ clk_data->clks[index] = clk;
+ }
+}
+
+static void __init sunxi_multi_bus_gates_init(struct device_node *node)
+{
+ struct clk_onecell_data *clk_data;
+ struct device_node *child;
+ struct property *prop;
+ struct resource res;
+ void __iomem *reg;
+ const __be32 *p;
+ int number = 0;
+ int index;
+
+ reg = of_io_request_and_map(node, 0, of_node_full_name(node));
+ if (IS_ERR(reg))
+ return;
+
+ clk_data = kmalloc(sizeof(struct clk_onecell_data), GFP_KERNEL);
+ if (!clk_data)
+ goto err_unmap;
+
+ for_each_child_of_node(node, child)
+ of_property_for_each_u32(child, "clock-indices", prop, p, index)
+ number = max(number, index);
+
+ clk_data->clks = kcalloc(number + 1, sizeof(struct clk *), GFP_KERNEL);
+ if (!clk_data->clks)
+ goto err_free_data;
+
+ for_each_child_of_node(node, child)
+ sunxi_parse_parent(child, clk_data, reg);
+
+ clk_data->clk_num = number + 1;
+ if (of_clk_add_provider(node, of_clk_src_onecell_get, clk_data))
+ pr_err("registering bus-gate clock %s failed\n", node->name);
+
+ return;
+
+err_free_data:
+ kfree(clk_data);
+err_unmap:
+ iounmap(reg);
+ of_address_to_resource(node, 0, &res);
+ release_mem_region(res.start, resource_size(&res));
+}
+
+CLK_OF_DECLARE(sunxi_multi_bus_gates, "allwinner,sunxi-multi-bus-gates-clk",
+ sunxi_multi_bus_gates_init);
--
2.6.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver
2016-02-01 17:39 ` [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver Andre Przywara
@ 2016-02-01 18:40 ` Jean-Francois Moine
2016-02-01 23:01 ` André Przywara
0 siblings, 1 reply; 10+ messages in thread
From: Jean-Francois Moine @ 2016-02-01 18:40 UTC (permalink / raw)
To: Andre Przywara
Cc: Maxime Ripard, Chen-Yu Tsai, linux-sunxi, Arnd Bergmann,
Emilio López, Michael Turquette, Stephen Boyd, linux-kernel,
Jens Kuske, linux-clk, linux-arm-kernel
On Mon, 1 Feb 2016 17:39:25 +0000
Andre Przywara <andre.przywara@arm.com> wrote:
> The Allwinner H3 SoC introduced bus clock gates with potentially
> different parents per clock gate. The H3 driver chose to hardcode the
> actual parent clock relation in the code.
> Add a new driver (which has the potential to drive the H3 and also
> the simple clock gates as well) which uses the power of DT to describe
> this relationship in an elegant and flexible way.
> Using one subnode for every parent clock we get away with a single
> DT compatible match, which can be used as a fallback value in the
> actual DTs without the need to add specific compatible strings to the
> code. This avoids adding a new driver or function for every new SoC.
>=20
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Changelog RFC .. v1:
> - fix IRQ muxes to cover the three banks of the SoC
> - amend naming of PCM pins
>=20
> drivers/clk/sunxi/Makefile | 1 +
> drivers/clk/sunxi/clk-multi-gates.c | 105 ++++++++++++++++++++++++++++++=
++++++
> 2 files changed, 106 insertions(+)
> create mode 100644 drivers/clk/sunxi/clk-multi-gates.c
[snip]
Glad to see that things are moving to the right way. Thanks.
Acked-by: Jean-Francois Moine <moinejf@free.fr>
--=20
Ken ar c'henta=F1 | ** Breizh ha Linux atav! **
Jef | http://moinejf.free.fr/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver
2016-02-01 18:40 ` Jean-Francois Moine
@ 2016-02-01 23:01 ` André Przywara
0 siblings, 0 replies; 10+ messages in thread
From: André Przywara @ 2016-02-01 23:01 UTC (permalink / raw)
To: Jean-Francois Moine
Cc: Maxime Ripard, Chen-Yu Tsai, linux-sunxi, Arnd Bergmann,
Emilio López, Michael Turquette, Stephen Boyd, linux-kernel,
Jens Kuske, linux-clk, linux-arm-kernel
On 01/02/16 18:40, Jean-Francois Moine wrote:
> On Mon, 1 Feb 2016 17:39:25 +0000
> Andre Przywara <andre.przywara@arm.com> wrote:
>
>> The Allwinner H3 SoC introduced bus clock gates with potentially
>> different parents per clock gate. The H3 driver chose to hardcode the
>> actual parent clock relation in the code.
>> Add a new driver (which has the potential to drive the H3 and also
>> the simple clock gates as well) which uses the power of DT to describe
>> this relationship in an elegant and flexible way.
>> Using one subnode for every parent clock we get away with a single
>> DT compatible match, which can be used as a fallback value in the
>> actual DTs without the need to add specific compatible strings to the
>> code. This avoids adding a new driver or function for every new SoC.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>> ---
>> Changelog RFC .. v1:
>> - fix IRQ muxes to cover the three banks of the SoC
>> - amend naming of PCM pins
Just got embarrassed with seeing that this changelog here actually
belongs into the previous patch :$
>>
>> drivers/clk/sunxi/Makefile | 1 +
>> drivers/clk/sunxi/clk-multi-gates.c | 105 ++++++++++++++++++++++++++++++++++++
>> 2 files changed, 106 insertions(+)
>> create mode 100644 drivers/clk/sunxi/clk-multi-gates.c
> [snip]
>
> Glad to see that things are moving to the right way. Thanks.
> Acked-by: Jean-Francois Moine <moinejf@free.fr>
Thanks! I am relived to hear that (and hope that others agree as well
;-) If people are Ok with that approach I can do patches to move all
existing clock gates into one driver, but I guess this would be part of
a later series.
Cheers,
Andre.
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name
[not found] <1454348370-3816-1-git-send-email-andre.przywara@arm.com>
2016-02-01 17:39 ` [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver Andre Przywara
@ 2016-02-01 17:39 ` Andre Przywara
2016-02-08 15:57 ` Rob Herring
2016-02-01 17:39 ` [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock Andre Przywara
2016-02-01 17:39 ` [PATCH 09/11] clk: sunxi: add critical-clocks property to mux clocks Andre Przywara
3 siblings, 1 reply; 10+ messages in thread
From: Andre Przywara @ 2016-02-01 17:39 UTC (permalink / raw)
To: Maxime Ripard, Chen-Yu Tsai, linux-sunxi
Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk, Jens Kuske,
Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
devicetree
The only difference between the different compatible matches at the
end of clk-sunxi.c are the critical clocks. Two SoCs get away so far
without any, so there is no reason to enumerate those SoCs in here
explicitly, though we have to keep them in for compatibility reasons.
Rename the init function to highlight this generic feature and add a
new, generic DT compatible string which can be used as a fallback value
in the future should a particular SoC don't need any special treatment.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
Documentation/devicetree/bindings/arm/sunxi.txt | 4 ++++
drivers/clk/sunxi/clk-sunxi.c | 14 ++++++--------
2 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/Documentation/devicetree/bindings/arm/sunxi.txt b/Documentation/devicetree/bindings/arm/sunxi.txt
index 7e79fcc..980e065 100644
--- a/Documentation/devicetree/bindings/arm/sunxi.txt
+++ b/Documentation/devicetree/bindings/arm/sunxi.txt
@@ -14,3 +14,7 @@ using one of the following compatible strings:
allwinner,sun8i-a83t
allwinner,sun8i-h3
allwinner,sun9i-a80
+
+For Allwinner SoCs without any specific needs the generic fallback value of:
+ allwinner,sunxi
+can be used.
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index e460a6b..efcce85 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -1052,14 +1052,12 @@ CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);
CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks);
CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks);
-static void __init sun8i_a83t_init_clocks(struct device_node *node)
+static void __init sunxi_generic_init_clocks(struct device_node *node)
{
sunxi_init_clocks(NULL, 0);
}
-CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t", sun8i_a83t_init_clocks);
-
-static void __init sun9i_init_clocks(struct device_node *node)
-{
- sunxi_init_clocks(NULL, 0);
-}
-CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80", sun9i_init_clocks);
+CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t",
+ sunxi_generic_init_clocks);
+CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80",
+ sunxi_generic_init_clocks);
+CLK_OF_DECLARE(sunxi_clk_init, "allwinner,sunxi", sunxi_generic_init_clocks);
--
2.6.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name
2016-02-01 17:39 ` [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name Andre Przywara
@ 2016-02-08 15:57 ` Rob Herring
2016-02-08 16:06 ` Andre Przywara
0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring @ 2016-02-08 15:57 UTC (permalink / raw)
To: Andre Przywara
Cc: Maxime Ripard, Chen-Yu Tsai, linux-sunxi, Arnd Bergmann,
linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk, Jens Kuske,
Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree
On Mon, Feb 01, 2016 at 05:39:26PM +0000, Andre Przywara wrote:
> The only difference between the different compatible matches at the
> end of clk-sunxi.c are the critical clocks. Two SoCs get away so far
> without any, so there is no reason to enumerate those SoCs in here
> explicitly, though we have to keep them in for compatibility reasons.
>
> Rename the init function to highlight this generic feature and add a
> new, generic DT compatible string which can be used as a fallback value
> in the future should a particular SoC don't need any special treatment.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> Documentation/devicetree/bindings/arm/sunxi.txt | 4 ++++
> drivers/clk/sunxi/clk-sunxi.c | 14 ++++++--------
> 2 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/Documentation/devicetree/bindings/arm/sunxi.txt b/Documentation/devicetree/bindings/arm/sunxi.txt
> index 7e79fcc..980e065 100644
> --- a/Documentation/devicetree/bindings/arm/sunxi.txt
> +++ b/Documentation/devicetree/bindings/arm/sunxi.txt
> @@ -14,3 +14,7 @@ using one of the following compatible strings:
> allwinner,sun8i-a83t
> allwinner,sun8i-h3
> allwinner,sun9i-a80
> +
> +For Allwinner SoCs without any specific needs the generic fallback value of:
> + allwinner,sunxi
> +can be used.
Perhaps "fallback" implies this, but be more specific that it can be
used in addition to a specific string.
> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
> index e460a6b..efcce85 100644
> --- a/drivers/clk/sunxi/clk-sunxi.c
> +++ b/drivers/clk/sunxi/clk-sunxi.c
> @@ -1052,14 +1052,12 @@ CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);
> CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks);
> CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks);
>
> -static void __init sun8i_a83t_init_clocks(struct device_node *node)
> +static void __init sunxi_generic_init_clocks(struct device_node *node)
> {
> sunxi_init_clocks(NULL, 0);
> }
> -CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t", sun8i_a83t_init_clocks);
> -
> -static void __init sun9i_init_clocks(struct device_node *node)
> -{
> - sunxi_init_clocks(NULL, 0);
> -}
> -CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80", sun9i_init_clocks);
> +CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t",
> + sunxi_generic_init_clocks);
> +CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80",
> + sunxi_generic_init_clocks);
> +CLK_OF_DECLARE(sunxi_clk_init, "allwinner,sunxi", sunxi_generic_init_clocks);
> --
> 2.6.4
>
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name
2016-02-08 15:57 ` Rob Herring
@ 2016-02-08 16:06 ` Andre Przywara
0 siblings, 0 replies; 10+ messages in thread
From: Andre Przywara @ 2016-02-08 16:06 UTC (permalink / raw)
To: Rob Herring
Cc: Maxime Ripard, Chen-Yu Tsai, linux-sunxi, Arnd Bergmann,
linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk, Jens Kuske,
Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala, devicetree
Hi,
On 08/02/16 15:57, Rob Herring wrote:
> On Mon, Feb 01, 2016 at 05:39:26PM +0000, Andre Przywara wrote:
>> The only difference between the different compatible matches at the
>> end of clk-sunxi.c are the critical clocks. Two SoCs get away so far
>> without any, so there is no reason to enumerate those SoCs in here
>> explicitly, though we have to keep them in for compatibility reasons.
>>
>> Rename the init function to highlight this generic feature and add a
>> new, generic DT compatible string which can be used as a fallback value
>> in the future should a particular SoC don't need any special treatment.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>> ---
>> Documentation/devicetree/bindings/arm/sunxi.txt | 4 ++++
>> drivers/clk/sunxi/clk-sunxi.c | 14 ++++++--------
>> 2 files changed, 10 insertions(+), 8 deletions(-)
>>
>> diff --git a/Documentation/devicetree/bindings/arm/sunxi.txt b/Documentation/devicetree/bindings/arm/sunxi.txt
>> index 7e79fcc..980e065 100644
>> --- a/Documentation/devicetree/bindings/arm/sunxi.txt
>> +++ b/Documentation/devicetree/bindings/arm/sunxi.txt
>> @@ -14,3 +14,7 @@ using one of the following compatible strings:
>> allwinner,sun8i-a83t
>> allwinner,sun8i-h3
>> allwinner,sun9i-a80
>> +
>> +For Allwinner SoCs without any specific needs the generic fallback value of:
>> + allwinner,sunxi
>> +can be used.
>
> Perhaps "fallback" implies this, but be more specific that it can be
> used in addition to a specific string.
Yeah, good point.
But Maxime's latest rework [1] made this patch here actually obsolete,
so we don't match on a root compatible string anymore to register the
sunxi clock drivers. Instead each clock is registered and matched on
it's own compatible string. Much nicer now, IMHO.
Thanks for having a look!
Andre.
[1]
https://git.kernel.org/cgit/linux/kernel/git/mripard/linux.git/commit/?h=sunxi/for-next&id=78e3fb4c745114b16a12458036d48aa96ea5b36d
>> diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
>> index e460a6b..efcce85 100644
>> --- a/drivers/clk/sunxi/clk-sunxi.c
>> +++ b/drivers/clk/sunxi/clk-sunxi.c
>> @@ -1052,14 +1052,12 @@ CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);
>> CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks);
>> CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks);
>>
>> -static void __init sun8i_a83t_init_clocks(struct device_node *node)
>> +static void __init sunxi_generic_init_clocks(struct device_node *node)
>> {
>> sunxi_init_clocks(NULL, 0);
>> }
>> -CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t", sun8i_a83t_init_clocks);
>> -
>> -static void __init sun9i_init_clocks(struct device_node *node)
>> -{
>> - sunxi_init_clocks(NULL, 0);
>> -}
>> -CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80", sun9i_init_clocks);
>> +CLK_OF_DECLARE(sun8i_a83t_clk_init, "allwinner,sun8i-a83t",
>> + sunxi_generic_init_clocks);
>> +CLK_OF_DECLARE(sun9i_a80_clk_init, "allwinner,sun9i-a80",
>> + sunxi_generic_init_clocks);
>> +CLK_OF_DECLARE(sunxi_clk_init, "allwinner,sunxi", sunxi_generic_init_clocks);
>> --
>> 2.6.4
>>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock
[not found] <1454348370-3816-1-git-send-email-andre.przywara@arm.com>
2016-02-01 17:39 ` [PATCH 06/11] clk: sunxi: add generic multi-parent bus clock gates driver Andre Przywara
2016-02-01 17:39 ` [PATCH 07/11] clk: sunxi: add generic allwinner,sunxi name Andre Przywara
@ 2016-02-01 17:39 ` Andre Przywara
2016-02-02 18:02 ` Maxime Ripard
2016-02-01 17:39 ` [PATCH 09/11] clk: sunxi: add critical-clocks property to mux clocks Andre Przywara
3 siblings, 1 reply; 10+ messages in thread
From: Andre Przywara @ 2016-02-01 17:39 UTC (permalink / raw)
To: Maxime Ripard, Chen-Yu Tsai, linux-sunxi
Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk
clk_register_mux returns a pointer wrapped error value in case of
failure, so a simple NULL check is not sufficient to catch errors.
Fix that and elaborate on the failure reason on the way. The whole
function does not return any error value, so silently failing may
leave users scratching their heads because the kernel does not
provide any clues on what's wrong.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
drivers/clk/sunxi/clk-sunxi.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index efcce85..9416e0f3 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -627,17 +627,29 @@ static void __init sunxi_mux_clk_setup(struct device_node *node,
reg = of_iomap(node, 0);
i = of_clk_parent_fill(node, parents, SUNXI_MAX_PARENTS);
- of_property_read_string(node, "clock-output-names", &clk_name);
+ if (of_property_read_string(node, "clock-output-names", &clk_name)) {
+ pr_warn("%s: could not read clock-output-names for \"%s\"\n",
+ __func__, clk_name);
+ goto out_unmap;
+ }
clk = clk_register_mux(NULL, clk_name, parents, i,
CLK_SET_RATE_PARENT, reg,
data->shift, SUNXI_MUX_GATE_WIDTH,
0, &clk_lock);
- if (clk) {
- of_clk_add_provider(node, of_clk_src_simple_get, clk);
- clk_register_clkdev(clk, clk_name, NULL);
+ if (IS_ERR(clk)) {
+ pr_warn("%s: failed to register mux clock %s: %ld\n", __func__,
+ clk_name, PTR_ERR(clk));
+ goto out_unmap;
}
+
+ of_clk_add_provider(node, of_clk_src_simple_get, clk);
+ clk_register_clkdev(clk, clk_name, NULL);
+ return;
+
+out_unmap:
+ iounmap(reg);
}
--
2.6.4
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock
2016-02-01 17:39 ` [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock Andre Przywara
@ 2016-02-02 18:02 ` Maxime Ripard
2016-02-02 18:05 ` Andre Przywara
0 siblings, 1 reply; 10+ messages in thread
From: Maxime Ripard @ 2016-02-02 18:02 UTC (permalink / raw)
To: Andre Przywara
Cc: Chen-Yu Tsai, linux-sunxi, Arnd Bergmann, linux-arm-kernel,
linux-kernel, Emilio López, Michael Turquette, Stephen Boyd,
linux-clk
[-- Attachment #1: Type: text/plain, Size: 715 bytes --]
On Mon, Feb 01, 2016 at 05:39:27PM +0000, Andre Przywara wrote:
> clk_register_mux returns a pointer wrapped error value in case of
> failure, so a simple NULL check is not sufficient to catch errors.
> Fix that and elaborate on the failure reason on the way. The whole
> function does not return any error value, so silently failing may
> leave users scratching their heads because the kernel does not
> provide any clues on what's wrong.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
Applied, thanks.
Any chance you do that for the other functions? :)
Thanks!
Maxime
--
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock
2016-02-02 18:02 ` Maxime Ripard
@ 2016-02-02 18:05 ` Andre Przywara
0 siblings, 0 replies; 10+ messages in thread
From: Andre Przywara @ 2016-02-02 18:05 UTC (permalink / raw)
To: Maxime Ripard
Cc: Chen-Yu Tsai, linux-sunxi, Arnd Bergmann, linux-arm-kernel,
linux-kernel, Emilio López, Michael Turquette, Stephen Boyd,
linux-clk
Salut,
On 02/02/16 18:02, Maxime Ripard wrote:
> On Mon, Feb 01, 2016 at 05:39:27PM +0000, Andre Przywara wrote:
>> clk_register_mux returns a pointer wrapped error value in case of
>> failure, so a simple NULL check is not sufficient to catch errors.
>> Fix that and elaborate on the failure reason on the way. The whole
>> function does not return any error value, so silently failing may
>> leave users scratching their heads because the kernel does not
>> provide any clues on what's wrong.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
>
> Applied, thanks.
>
> Any chance you do that for the other functions? :)
Sure, that was actually a test balloon ;-)
Cheers,
Andre
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 09/11] clk: sunxi: add critical-clocks property to mux clocks
[not found] <1454348370-3816-1-git-send-email-andre.przywara@arm.com>
` (2 preceding siblings ...)
2016-02-01 17:39 ` [PATCH 08/11] clk: sunxi: improve error reporting for the mux clock Andre Przywara
@ 2016-02-01 17:39 ` Andre Przywara
3 siblings, 0 replies; 10+ messages in thread
From: Andre Przywara @ 2016-02-01 17:39 UTC (permalink / raw)
To: Maxime Ripard, Chen-Yu Tsai, linux-sunxi
Cc: Arnd Bergmann, linux-arm-kernel, linux-kernel, Emilio López,
Michael Turquette, Stephen Boyd, linux-clk
The only reason we match the different root compatible strings when
registering the different sunxi clock types is to provide a list of
critical clocks.
Tell the mux clock (for a start) to get this property from the
device tree, allowing new SoCs to refer to the generic fallback
compatible string when the DT provides the critical clock information.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
---
drivers/clk/sunxi/clk-sunxi.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/clk/sunxi/clk-sunxi.c b/drivers/clk/sunxi/clk-sunxi.c
index 9416e0f3..e1e5a8f 100644
--- a/drivers/clk/sunxi/clk-sunxi.c
+++ b/drivers/clk/sunxi/clk-sunxi.c
@@ -644,6 +644,11 @@ static void __init sunxi_mux_clk_setup(struct device_node *node,
goto out_unmap;
}
+ if (of_property_read_bool(node, "critical-clocks")) {
+ pr_debug("marked clock %s as critical\n", clk_name);
+ clk_prepare_enable(clk);
+ }
+
of_clk_add_provider(node, of_clk_src_simple_get, clk);
clk_register_clkdev(clk, clk_name, NULL);
return;
@@ -1064,6 +1069,10 @@ CLK_OF_DECLARE(sun8i_a23_clk_init, "allwinner,sun8i-a23", sun6i_init_clocks);
CLK_OF_DECLARE(sun8i_a33_clk_init, "allwinner,sun8i-a33", sun6i_init_clocks);
CLK_OF_DECLARE(sun8i_h3_clk_init, "allwinner,sun8i-h3", sun6i_init_clocks);
+/*
+ * Those SoCs here either don't have a specific critical clock to
+ * protect or they mark the critical clocks as such in their DT.
+ */
static void __init sunxi_generic_init_clocks(struct device_node *node)
{
sunxi_init_clocks(NULL, 0);
--
2.6.4
^ permalink raw reply related [flat|nested] 10+ messages in thread