clk: Use of_clk_get_parent_count() instead of open coding
cover clk: Use of_clk_get_parent_count() instead of open coding
Hi all,
In several places, the functionality of of_clk_get_parent_count() is open coded. Replace them by of_clk_get_parent_count() to reduce code size.
The first 3 patches can be applied independently, as the affected clock drivers are used with CONFIG_COMMON_CLK=y and CONFIG_OF=y only.
Patch 4 adds dummy implementations of of_clk_get_parent_count() for the cases where CONFIG_OF or CONFIG_COMMON_CLK are not set.
This is an RFC, as
1. Dummies are needed in two places,
2. We don't have any dummies yet for the !CCF case.
Patch 5 depends on patch 4, since the arm,sp804 timer is also used on platforms where CONFIG_OF or CONFIG_COMMON_CLK are not set.
This was compile-tested using:
- multi_v7_defconfig (CCF, OF)
- realview_defconfig (CCF, no OF)
- versatile_defconfig (no CCF, no OF)
- bcm2835_defconfig (CCF, OF)
- axm55xx_defconfig (CCF, OF)
- at91_dt_defconfig (CCF, OF)
- omap2plus_defconfig (CCF, OF)
Thanks!
Geert Uytterhoeven (5):
clk: at91: Use of_clk_get_parent_count() instead of open coding
clk: st: Use of_clk_get_parent_count() instead of open coding
clk: ti: Use of_clk_get_parent_count() instead of open coding [RFC] clk: Provide dummy of_clk_get_parent_count() for !OF/!CCF [RFC] ARM: timer-sp: Use of_clk_get_parent_count() instead of open
coding
arch/arm/common/timer-sp.c | 3 ++- drivers/clk/at91/clk-main.c | 2 +- drivers/clk/at91/clk-master.c | 2 +- drivers/clk/at91/clk-programmable.c | 2 +- drivers/clk/at91/clk-slow.c | 4 ++-- drivers/clk/at91/clk-smd.c | 2 +- drivers/clk/at91/clk-usb.c | 2 +- drivers/clk/st/clk-flexgen.c | 2 +- drivers/clk/st/clkgen-mux.c | 2 +- drivers/clk/ti/clockdomain.c | 2 +- include/linux/clk-provider.h | 11 ++++++++++- 11 files changed, 22 insertions(+), 12 deletions(-)
Signature · 12 lines
1.9.1
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus TorvaldsPATCH 1/5 clk: at91: Use of_clk_get_parent_count() instead of open coding
--- drivers/clk/at91/clk-main.c | 2 +- drivers/clk/at91/clk-master.c | 2 +- drivers/clk/at91/clk-programmable.c | 2 +- drivers/clk/at91/clk-slow.c | 4 ++-- drivers/clk/at91/clk-smd.c | 2 +- drivers/clk/at91/clk-usb.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
drivers/clk/at91/clk-main.c +1 -1
@@ -614,7 +614,7 @@ void __init of_at91sam9x5_clk_main_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >2 )return ;
drivers/clk/at91/clk-master.c +1 -1
@@ -224,7 +224,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,const char *name = np->name;struct clk_master_characteristics *characteristics; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >MASTER_SOURCE_MAX )return ;
drivers/clk/at91/clk-programmable.c +1 -1
@@ -237,7 +237,7 @@ of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc,const char *name;struct device_node *progclknp; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >PROG_SOURCE_MAX )return ;
drivers/clk/at91/clk-slow.c +2 -2
@@ -373,7 +373,7 @@ void __init of_at91sam9x5_clk_slow_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >2 )return ;
@@ -451,7 +451,7 @@ void __init of_at91sam9260_clk_slow_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents !=2 )return ;
drivers/clk/at91/clk-smd.c +1 -1
@@ -150,7 +150,7 @@ void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,const char *parent_names[SMD_SOURCE_MAX ];const char *name = np->name; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >SMD_SOURCE_MAX )return ;
drivers/clk/at91/clk-usb.c +1 -1
@@ -378,7 +378,7 @@ void __init of_at91sam9x5_clk_usb_setup(struct device_node *np,const char *parent_names[USB_SOURCE_MAX ];const char *name = np->name; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >USB_SOURCE_MAX )return ;
Signature · 1 line
1.9.1
PATCH 1/5 clk: at91: Use of_clk_get_parent_count() instead of open coding
Quoted 1 line · On Fri, 29 May 2015 11:25:45 +0200 Geert Uytterhoeven…
Signed-off-by Geert Uytterhoeven <[email protected]>
Quoted 96 lines
--- drivers/clk/at91/clk-main.c | 2 +- drivers/clk/at91/clk-master.c | 2 +- drivers/clk/at91/clk-programmable.c | 2 +- drivers/clk/at91/clk-slow.c | 4 ++-- drivers/clk/at91/clk-smd.c | 2 +- drivers/clk/at91/clk-usb.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)drivers/clk/at91/clk-main.c +1
-1@@ -614,7 +614,7 @@ void __init of_at91sam9x5_clk_main_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >2 )return ;drivers/clk/at91/clk-master.c +1
-1@@ -224,7 +224,7 @@ of_at91_clk_master_setup(struct device_node *np, struct at91_pmc *pmc,const char *name = np->name;struct clk_master_characteristics *characteristics; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >MASTER_SOURCE_MAX )return ;drivers/clk/at91/clk-programmable.c +1
-1@@ -237,7 +237,7 @@ of_at91_clk_prog_setup(struct device_node *np, struct at91_pmc *pmc,const char *name;struct device_node *progclknp; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >PROG_SOURCE_MAX )return ;drivers/clk/at91/clk-slow.c +2
-2@@ -373,7 +373,7 @@ void __init of_at91sam9x5_clk_slow_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >2 )return ;@@ -451,7 +451,7 @@ void __init of_at91sam9260_clk_slow_setup(struct device_node *np,const char *name = np->name;int i; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents !=2 )return ;drivers/clk/at91/clk-smd.c +1
-1@@ -150,7 +150,7 @@ void __init of_at91sam9x5_clk_smd_setup(struct device_node *np,const char *parent_names[SMD_SOURCE_MAX ];const char *name = np->name; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >SMD_SOURCE_MAX )return ;drivers/clk/at91/clk-usb.c +1
-1@@ -378,7 +378,7 @@ void __init of_at91sam9x5_clk_usb_setup(struct device_node *np,const char *parent_names[USB_SOURCE_MAX ];const char *name = np->name; - num_parents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + num_parents =of_clk_get_parent_count (np);if (num_parents <=0 || num_parents >USB_SOURCE_MAX )return ;
Signature · 3 lines
Boris Brezillon, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
Stephen Boyd
AppliedPATCH 1/5 clk: at91: Use of_clk_get_parent_count() instead of open coding
In reply to Geert UytterhoevenQuoted 2 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 2/5 clk: st: Use of_clk_get_parent_count() instead of open coding
In reply to Geert Uytterhoeven--- drivers/clk/st/clk-flexgen.c | 2 +- drivers/clk/st/clkgen-mux.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/clk/st/clk-flexgen.c +1 -1
@@ -245,7 +245,7 @@ static const char ** __init flexgen_get_parents(struct device_node *np,const char **parents;int nparents, i; - nparents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + nparents =of_clk_get_parent_count (np);if (WARN_ON (nparents <=0 ))return NULL ;
drivers/clk/st/clkgen-mux.c +1 -1
@@ -26,7 +26,7 @@ static const char ** __init clkgen_mux_get_parents(struct device_node *np,const char **parents;int nparents, i; - nparents =of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ); + nparents =of_clk_get_parent_count (np);if (WARN_ON (nparents <=0 ))return ERR_PTR (-EINVAL );
Signature · 1 line
1.9.1
Stephen Boyd
AppliedPATCH 2/5 clk: st: Use of_clk_get_parent_count() instead of open coding
Quoted 2 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH 3/5 clk: ti: Use of_clk_get_parent_count() instead of open coding
In reply to Geert Uytterhoeven--- drivers/clk/ti/clockdomain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/ti/clockdomain.c +1 -1
@@ -32,7 +32,7 @@ static void __init of_ti_clockdomain_setup(struct device_node *node)int i;int num_clks; - num_clks =of_count_phandle_with_args (node,"clocks" ,"#clock-cells" ); + num_clks =of_clk_get_parent_count (node);for (i =0 ; i < num_clks; i++) { clk =of_clk_get (node, i);
Signature · 1 line
1.9.1
Stephen Boyd
AppliedPATCH 3/5 clk: ti: Use of_clk_get_parent_count() instead of open coding
Quoted 2 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>---
Applied to clk-next
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
RFC PATCH 4/5 clk: Provide dummy of_clk_get_parent_count() for !OF/!CCF
In reply to Geert UytterhoevenProvide dummy implementations of of_clk_get_parent_count() for the cases where CONFIG_OF or CONFIG_COMMON_CLK are not set.
---
This is an RFC, as
1. Dummies are needed in two places,
2. We don't have any dummies yet for the !CCF case.
--- include/linux/clk-provider.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
include/linux/clk-provider.h +10 -1
@@ -651,6 +651,10 @@ static inline struct clk *of_clk_src_onecell_get( {return ERR_PTR (-ENOENT ); } +static inline int of_clk_get_parent_count (struct device_node *np) +{ +return -ENOENT ; +}static inline const char *of_clk_get_parent_name (struct device_node *np,int index) {
@@ -696,5 +700,10 @@ struct dentry *clk_debugfs_add_file(struct clk_hw *hw, char *name, umode_t mode, void *data, const struct file_operations *fops);#endif -#endif /* CONFIG_COMMON_CLK */ +#else /* !CONFIG_COMMON_CLK */ +static inline int of_clk_get_parent_count (struct device_node *np) +{ +return -ENOENT ; +} +#endif /* !CONFIG_COMMON_CLK */ #endif /* CLK_PROVIDER_H */
Signature · 1 line
1.9.1
RFC PATCH 5/5 ARM: timer-sp: Use of_clk_get_parent_count() instead of open coding
In reply to Geert Uytterhoeven---
This is an RFC, as it depends on "[RFC] clk: Provide dummy of_clk_get_parent_count() for !OF/!CCF".
--- arch/arm/common/timer-sp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/common/timer-sp.c +2 -1
@@ -21,6 +21,7 @@#include <linux/clk.h> #include <linux/clocksource.h> #include <linux/clockchips.h> +#include <linux/clk-provider.h> #include <linux/err.h> #include <linux/interrupt.h> #include <linux/irq.h>
@@ -234,7 +235,7 @@ static void __init sp804_of_init(struct device_node *np) clk1 =NULL ;/* Get the 2nd clock if the timer has 3 timer clocks */ -if (of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ) ==3 ) { +if (of_clk_get_parent_count (np) ==3 ) { clk2 =of_clk_get (np,1 );if (IS_ERR (clk2)) { pr_err("sp804: %s clock not found: %d\n", np->name,
Signature · 1 line
1.9.1
RFC PATCH 5/5 ARM: timer-sp: Use of_clk_get_parent_count() instead of open coding
Quoted 13 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>---
This is an RFC, as it depends on "[RFC] clk: Provide dummyof_clk_get_parent_count()for !OF/!CCF".--- arch/arm/common/timer-sp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)arch/arm/common/timer-sp.c +0
-0
arch/arm/common/timer-sp.c line 24
Quoted 4 lines
arch/arm/common/timer-sp.c +1
-0@@ -21,6 +21,7 @@#include <linux/clk.h> #include <linux/clocksource.h> #include <linux/clockchips.h> +#include <linux/clk-provider.h>
This looks weird. This is not a clock provider.
arch/arm/common/timer-sp.c static void __init sp804_of_init(struct device_node *np) · line 238
Quoted 9 lines
arch/arm/common/timer-sp.c +1
-1#include <linux/err.h> #include <linux/interrupt.h> #include <linux/irq.h> @@ -234,7 +235,7 @@ static void __init sp804_of_init(struct device_node *np) clk1 =NULL ;/* Get the 2nd clock if the timer has 3 timer clocks */ -if (of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ) ==3 ) { +if (of_clk_get_parent_count (np) ==3 ) {
So maybe it means if we want to expose of_clk_get_parent_count() we should move it to some other header file (of_clk.h?). And then maybe we should always compile said helpers if OF=y and HAVE_CLK=y.
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
RFC PATCH 5/5 ARM: timer-sp: Use of_clk_get_parent_count() instead of open coding
Hi Stephen,
Quoted 9 lines · Stephen Boyd
Quoted 8 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>---
This is an RFC, as it depends on "[RFC] clk: Provide dummyof_clk_get_parent_count()for !OF/!CCF".--- arch/arm/common/timer-sp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 11 lines
arch/arm/common/timer-sp.c line 24
Quoted 9 lines
arch/arm/common/timer-sp.c +1
-0@@ -21,6 +21,7 @@#include <linux/clk.h> #include <linux/clocksource.h> #include <linux/clockchips.h> +#include <linux/clk-provider.h> This looks weird. This is not a clock provider.
But that's where the declaration of of_clk_get_parent_count() lives...
Quoted 6 lines
Quoted 6 lines
arch/arm/common/timer-sp.c +0
-0#include <linux/err.h> #include <linux/interrupt.h> #include <linux/irq.h> @@ -234,7 +235,7 @@ static void __init sp804_of_init(struct device_node *np) clk1 =NULL ;
Quoted 8 lines
arch/arm/common/timer-sp.c static void __init sp804_of_init(struct device_node *np) · line 238
Quoted 3 lines
arch/arm/common/timer-sp.c +1
-1/* Get the 2nd clock if the timer has 3 timer clocks */ -if (of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ) ==3 ) { +if (of_clk_get_parent_count (np) ==3 ) {So maybe it means if we want to expose
of_clk_get_parent_count()we should move it to some other header file (of_clk.h?). And then maybe we should always compile said helpers if OF=y and HAVE_CLK=y.
That makes sense.
Currently we have lots of of_clk_*() in <linux/clk-provider.h>, and a few of_clk_get*() in <inux/clk.h>.
And the mysterious of_clk_set_defaults() in <linux/clk/clk-conf.h>.
All of_clk_get*() could be moved to a new <linux/of_clk.h>.
Alternatively, of_clk_get_parent_count() could just move to <linux/clk.h>?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
RFC PATCH 5/5 ARM: timer-sp: Use of_clk_get_parent_count() instead of open coding
Quoted 22 lines · Geert Uytterhoeven
Hi Stephen,
Quoted 8 lines · Stephen Boyd
Quoted 7 lines · Geert Uytterhoeven
Signed-off-by Geert Uytterhoeven <[email protected]>#include <
linux/err.h>
#include <linux/interrupt.h>
#include <linux/irq.h>arch/arm/common/timer-sp.c +0
-0@@ -234,7 +235,7 @@ static void __init sp804_of_init(struct device_node *np) clk1 =NULL ;Quoted 8 lines
arch/arm/common/timer-sp.c static void __init sp804_of_init(struct device_node *np) · line 238
Quoted 3 lines
arch/arm/common/timer-sp.c +1
-1/* Get the 2nd clock if the timer has 3 timer clocks */ -if (of_count_phandle_with_args (np,"clocks" ,"#clock-cells" ) ==3 ) { +if (of_clk_get_parent_count (np) ==3 ) {So maybe it means if we want to expose
of_clk_get_parent_count()we should move it to some other header file (of_clk.h?). And then maybe we should always compile said helpers if OF=y and HAVE_CLK=y.That makes sense.
Quoted 7 lines
Currently we have lots of of_clk_*() in <
linux/clk-provider.h>, and a few of_clk_get*() in <inux/clk.h>.
And the mysteriousof_clk_set_defaults()in <linux/clk/clk-conf.h>.All of_clk_get*() could be moved to a new <
linux/of_clk.h>.Alternatively,
of_clk_get_parent_count()could just move to <linux/clk.h>?
Hmm... of_clk_*() functions that return a struct clk * or work with a struct clk * should stay within clk.h. But these ones in clk-provider.h should probably move to a new of_clk.h file:
of_clk_get_parent_count
of_clk_get_parent_name
of_clk_init
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project