clk: imx: Refactor entire sccg pll clk
Subsystems (3)
PATCH RESEND 1/1 clk: imx: Refactor entire sccg pll clk
Make the entire combination of plls to be one single clock. The parents used for bypasses are specified each as an index in the parents list. The determine_rate does a lookup throughout all the possible combinations for all the divs and returns the best possible 'setup' which in turn is used by set_rate later to set up all the divs and bypasses.
---
This is basically just a resend of the following:
https://lkml.org/lkml/2019/1/29/874
There are no changes. Just added T-b and A-b tags from Lucas.
Waiting for review.
drivers/clk/imx/clk-imx8mq.c | 58 ++--- drivers/clk/imx/clk-sccg-pll.c | 514 ++++++++++++++++++++++++++++++++--------- drivers/clk/imx/clk.h | 9 +- 3 files changed, 423 insertions(+), 158 deletions(-)
drivers/clk/imx/clk-imx8mq.c +14 -44
@@ -34,15 +34,10 @@ static const char * const audio_pll1_bypass_sels[] = {"audio_pll1", "audio_pll1_static const char *const audio_pll2_bypass_sels[] = {"audio_pll2" ,"audio_pll2_ref_sel" , };static const char *const video_pll1_bypass_sels[] = {"video_pll1" ,"video_pll1_ref_sel" , }; -static const char *const sys1_pll1_out_sels[] = {"sys1_pll1" ,"sys1_pll1_ref_sel" , }; -static const char *const sys2_pll1_out_sels[] = {"sys2_pll1" ,"sys1_pll1_ref_sel" , }; -static const char *const sys3_pll1_out_sels[] = {"sys3_pll1" ,"sys3_pll1_ref_sel" , }; -static const char *const dram_pll1_out_sels[] = {"dram_pll1" ,"dram_pll1_ref_sel" , }; - -static const char *const sys1_pll2_out_sels[] = {"sys1_pll2_div" ,"sys1_pll1_ref_sel" , }; -static const char *const sys2_pll2_out_sels[] = {"sys2_pll2_div" ,"sys2_pll1_ref_sel" , }; -static const char *const sys3_pll2_out_sels[] = {"sys3_pll2_div" ,"sys2_pll1_ref_sel" , }; -static const char *const dram_pll2_out_sels[] = {"dram_pll2_div" ,"dram_pll1_ref_sel" , }; +static const char *const sys1_pll_out_sels[] = {"sys1_pll1_ref_sel" , }; +static const char *const sys2_pll_out_sels[] = {"sys1_pll1_ref_sel" ,"sys2_pll1_ref_sel" , }; +static const char *const sys3_pll_out_sels[] = {"sys3_pll1_ref_sel" ,"sys2_pll1_ref_sel" , }; +static const char *const dram_pll_out_sels[] = {"dram_pll1_ref_sel" , };/* CCM ROOT */ static const char *const imx8mq_a53_sels[] = {"osc_25m" ,"arm_pll_out" ,"sys2_pll_500m" ,"sys2_pll_1000m" ,
@@ -308,10 +303,6 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) clks[IMX8MQ_AUDIO_PLL1_REF_DIV ] =imx_clk_divider ("audio_pll1_ref_div" ,"audio_pll1_ref_sel" , base +0x0 ,5 ,6 ); clks[IMX8MQ_AUDIO_PLL2_REF_DIV ] =imx_clk_divider ("audio_pll2_ref_div" ,"audio_pll2_ref_sel" , base +0x8 ,5 ,6 ); clks[IMX8MQ_VIDEO_PLL1_REF_DIV ] =imx_clk_divider ("video_pll1_ref_div" ,"video_pll1_ref_sel" , base +0x10 ,5 ,6 ); - clks[IMX8MQ_SYS1_PLL1_REF_DIV ] =imx_clk_divider ("sys1_pll1_ref_div" ,"sys1_pll1_ref_sel" , base +0x38 ,25 ,3 ); - clks[IMX8MQ_SYS2_PLL1_REF_DIV ] =imx_clk_divider ("sys2_pll1_ref_div" ,"sys2_pll1_ref_sel" , base +0x44 ,25 ,3 ); - clks[IMX8MQ_SYS3_PLL1_REF_DIV ] =imx_clk_divider ("sys3_pll1_ref_div" ,"sys3_pll1_ref_sel" , base +0x50 ,25 ,3 ); - clks[IMX8MQ_DRAM_PLL1_REF_DIV ] =imx_clk_divider ("dram_pll1_ref_div" ,"dram_pll1_ref_sel" , base +0x68 ,25 ,3 ); clks[IMX8MQ_ARM_PLL ] =imx_clk_frac_pll ("arm_pll" ,"arm_pll_ref_div" , base +0x28 ); clks[IMX8MQ_GPU_PLL ] =imx_clk_frac_pll ("gpu_pll" ,"gpu_pll_ref_div" , base +0x18 );
@@ -319,25 +310,6 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) clks[IMX8MQ_AUDIO_PLL1 ] =imx_clk_frac_pll ("audio_pll1" ,"audio_pll1_ref_div" , base +0x0 ); clks[IMX8MQ_AUDIO_PLL2 ] =imx_clk_frac_pll ("audio_pll2" ,"audio_pll2_ref_div" , base +0x8 ); clks[IMX8MQ_VIDEO_PLL1 ] =imx_clk_frac_pll ("video_pll1" ,"video_pll1_ref_div" , base +0x10 ); - clks[IMX8MQ_SYS1_PLL1 ] =imx_clk_sccg_pll ("sys1_pll1" ,"sys1_pll1_ref_div" , base +0x30 ,SCCG_PLL1 ); - clks[IMX8MQ_SYS2_PLL1 ] =imx_clk_sccg_pll ("sys2_pll1" ,"sys2_pll1_ref_div" , base +0x3c ,SCCG_PLL1 ); - clks[IMX8MQ_SYS3_PLL1 ] =imx_clk_sccg_pll ("sys3_pll1" ,"sys3_pll1_ref_div" , base +0x48 ,SCCG_PLL1 ); - clks[IMX8MQ_DRAM_PLL1 ] =imx_clk_sccg_pll ("dram_pll1" ,"dram_pll1_ref_div" , base +0x60 ,SCCG_PLL1 ); - - clks[IMX8MQ_SYS1_PLL2 ] =imx_clk_sccg_pll ("sys1_pll2" ,"sys1_pll1_out_div" , base +0x30 ,SCCG_PLL2 ); - clks[IMX8MQ_SYS2_PLL2 ] =imx_clk_sccg_pll ("sys2_pll2" ,"sys2_pll1_out_div" , base +0x3c ,SCCG_PLL2 ); - clks[IMX8MQ_SYS3_PLL2 ] =imx_clk_sccg_pll ("sys3_pll2" ,"sys3_pll1_out_div" , base +0x48 ,SCCG_PLL2 ); - clks[IMX8MQ_DRAM_PLL2 ] =imx_clk_sccg_pll ("dram_pll2" ,"dram_pll1_out_div" , base +0x60 ,SCCG_PLL2 ); - -/* PLL divs */ - clks[IMX8MQ_SYS1_PLL1_OUT_DIV ] =imx_clk_divider ("sys1_pll1_out_div" ,"sys1_pll1_out" , base +0x38 ,19 ,6 ); - clks[IMX8MQ_SYS2_PLL1_OUT_DIV ] =imx_clk_divider ("sys2_pll1_out_div" ,"sys2_pll1_out" , base +0x44 ,19 ,6 ); - clks[IMX8MQ_SYS3_PLL1_OUT_DIV ] =imx_clk_divider ("sys3_pll1_out_div" ,"sys3_pll1_out" , base +0x50 ,19 ,6 ); - clks[IMX8MQ_DRAM_PLL1_OUT_DIV ] =imx_clk_divider ("dram_pll1_out_div" ,"dram_pll1_out" , base +0x68 ,19 ,6 ); - clks[IMX8MQ_SYS1_PLL2_DIV ] =imx_clk_divider ("sys1_pll2_div" ,"sys1_pll2" , base +0x38 ,1 ,6 ); - clks[IMX8MQ_SYS2_PLL2_DIV ] =imx_clk_divider ("sys2_pll2_div" ,"sys2_pll2" , base +0x44 ,1 ,6 ); - clks[IMX8MQ_SYS3_PLL2_DIV ] =imx_clk_divider ("sys3_pll2_div" ,"sys3_pll2" , base +0x50 ,1 ,6 ); - clks[IMX8MQ_DRAM_PLL2_DIV ] =imx_clk_divider ("dram_pll2_div" ,"dram_pll2" , base +0x68 ,1 ,6 );/* PLL bypass out */ clks[IMX8MQ_ARM_PLL_BYPASS ] =imx_clk_mux ("arm_pll_bypass" , base +0x28 ,14 ,1 , arm_pll_bypass_sels,ARRAY_SIZE (arm_pll_bypass_sels));
@@ -347,14 +319,12 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) clks[IMX8MQ_AUDIO_PLL2_BYPASS ] =imx_clk_mux ("audio_pll2_bypass" , base +0x8 ,14 ,1 , audio_pll2_bypass_sels,ARRAY_SIZE (audio_pll2_bypass_sels)); clks[IMX8MQ_VIDEO_PLL1_BYPASS ] =imx_clk_mux ("video_pll1_bypass" , base +0x10 ,14 ,1 , video_pll1_bypass_sels,ARRAY_SIZE (video_pll1_bypass_sels)); - clks[IMX8MQ_SYS1_PLL1_OUT ] =imx_clk_mux ("sys1_pll1_out" , base +0x30 ,5 ,1 , sys1_pll1_out_sels,ARRAY_SIZE (sys1_pll1_out_sels)); - clks[IMX8MQ_SYS2_PLL1_OUT ] =imx_clk_mux ("sys2_pll1_out" , base +0x3c ,5 ,1 , sys2_pll1_out_sels,ARRAY_SIZE (sys2_pll1_out_sels)); - clks[IMX8MQ_SYS3_PLL1_OUT ] =imx_clk_mux ("sys3_pll1_out" , base +0x48 ,5 ,1 , sys3_pll1_out_sels,ARRAY_SIZE (sys3_pll1_out_sels)); - clks[IMX8MQ_DRAM_PLL1_OUT ] =imx_clk_mux ("dram_pll1_out" , base +0x60 ,5 ,1 , dram_pll1_out_sels,ARRAY_SIZE (dram_pll1_out_sels)); - clks[IMX8MQ_SYS1_PLL2_OUT ] =imx_clk_mux ("sys1_pll2_out" , base +0x30 ,4 ,1 , sys1_pll2_out_sels,ARRAY_SIZE (sys1_pll2_out_sels)); - clks[IMX8MQ_SYS2_PLL2_OUT ] =imx_clk_mux ("sys2_pll2_out" , base +0x3c ,4 ,1 , sys2_pll2_out_sels,ARRAY_SIZE (sys2_pll2_out_sels)); - clks[IMX8MQ_SYS3_PLL2_OUT ] =imx_clk_mux ("sys3_pll2_out" , base +0x48 ,4 ,1 , sys3_pll2_out_sels,ARRAY_SIZE (sys3_pll2_out_sels)); - clks[IMX8MQ_DRAM_PLL2_OUT ] =imx_clk_mux ("dram_pll2_out" , base +0x60 ,4 ,1 , dram_pll2_out_sels,ARRAY_SIZE (dram_pll2_out_sels)); +/* unbypass all the plls */ +clk_set_parent (clks[IMX8MQ_GPU_PLL_BYPASS ], clks[IMX8MQ_GPU_PLL ]); +clk_set_parent (clks[IMX8MQ_VPU_PLL_BYPASS ], clks[IMX8MQ_VPU_PLL ]); +clk_set_parent (clks[IMX8MQ_AUDIO_PLL1_BYPASS ], clks[IMX8MQ_AUDIO_PLL1 ]); +clk_set_parent (clks[IMX8MQ_AUDIO_PLL2_BYPASS ], clks[IMX8MQ_AUDIO_PLL2 ]); +clk_set_parent (clks[IMX8MQ_VIDEO_PLL1_BYPASS ], clks[IMX8MQ_VIDEO_PLL1 ]);/* PLL OUT GATE */ clks[IMX8MQ_ARM_PLL_OUT ] =imx_clk_gate ("arm_pll_out" ,"arm_pll_bypass" , base +0x28 ,21 );
@@ -363,11 +333,11 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) clks[IMX8MQ_AUDIO_PLL1_OUT ] =imx_clk_gate ("audio_pll1_out" ,"audio_pll1_bypass" , base +0x0 ,21 ); clks[IMX8MQ_AUDIO_PLL2_OUT ] =imx_clk_gate ("audio_pll2_out" ,"audio_pll2_bypass" , base +0x8 ,21 ); clks[IMX8MQ_VIDEO_PLL1_OUT ] =imx_clk_gate ("video_pll1_out" ,"video_pll1_bypass" , base +0x10 ,21 ); - clks[IMX8MQ_SYS1_PLL_OUT ] =imx_clk_gate ("sys1_pll_out" ,"sys1_pll2_out" , base +0x30 ,9 ); - clks[IMX8MQ_SYS2_PLL_OUT ] =imx_clk_gate ("sys2_pll_out" ,"sys2_pll2_out" , base +0x3c ,9 ); - clks[IMX8MQ_SYS3_PLL_OUT ] =imx_clk_gate ("sys3_pll_out" ,"sys3_pll2_out" , base +0x48 ,9 ); - clks[IMX8MQ_DRAM_PLL_OUT ] =imx_clk_gate ("dram_pll_out" ,"dram_pll2_out" , base +0x60 ,9 ); + clks[IMX8MQ_SYS1_PLL_OUT ] =imx_clk_sccg_pll ("sys1_pll_out" , sys1_pll_out_sels,ARRAY_SIZE (sys1_pll_out_sels),0 ,0 ,0 , base +0x30 ,CLK_IS_CRITICAL ); + clks[IMX8MQ_SYS2_PLL_OUT ] =imx_clk_sccg_pll ("sys2_pll_out" , sys2_pll_out_sels,ARRAY_SIZE (sys2_pll_out_sels),0 ,0 ,1 , base +0x3c ,CLK_IS_CRITICAL ); + clks[IMX8MQ_SYS3_PLL_OUT ] =imx_clk_sccg_pll ("sys3_pll_out" , sys3_pll_out_sels,ARRAY_SIZE (sys3_pll_out_sels),0 ,0 ,1 , base +0x48 ,CLK_IS_CRITICAL ); + clks[IMX8MQ_DRAM_PLL_OUT ] =imx_clk_sccg_pll ("dram_pll_out" , dram_pll_out_sels,ARRAY_SIZE (dram_pll_out_sels),0 ,0 ,0 , base +0x60 ,CLK_IS_CRITICAL );/* SYS PLL fixed output */ clks[IMX8MQ_SYS1_PLL_40M ] =imx_clk_fixed_factor ("sys1_pll_40m" ,"sys1_pll_out" ,1 ,20 ); clks[IMX8MQ_SYS1_PLL_80M ] =imx_clk_fixed_factor ("sys1_pll_80m" ,"sys1_pll_out" ,1 ,10 );
drivers/clk/imx/clk-sccg-pll.c +403 -111
621 lines not on this page · raw message
drivers/clk/imx/clk.h +6 -3
@@ -36,9 +36,12 @@ struct clk *imx_clk_pllv2(const char *name, const char *parent,struct clk *imx_clk_frac_pll (const char *name,const char *parent_name,void __iomem *base); -struct clk *imx_clk_sccg_pll (const char *name,const char *parent_name, -void __iomem *base, -enum imx_sccg_pll_type pll_type); +struct clk *imx_clk_sccg_pll (const char *name, +const char *const *parent_names, +u8 num_parents, +u8 parent,u8 bypass1,u8 bypass2, +void __iomem *base, +unsigned long flags);enum imx_pllv3_type {IMX_PLLV3_GENERIC ,
Signature · 7 lines
2.7.4 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoting Abel Vesa (2019-02-18 01:24:33)
Quoted 10 lines
Make the entire combination of plls to be one single clock. The parents used for bypasses are specified each as an index in the parents list. The
determine_ratedoes a lookup throughout all the possible combinations for all the divs and returns the best possible 'setup' which in turn is used byset_ratelater to set up all the divs and bypasses.Signed-off-by Abel Vesa <[email protected]>Tested-by Lucas Stach <[email protected]>Acked-by Lucas Stach <[email protected]>---
Applied to clk-next
Stephen Boyd
maintainerQuoting Abel Vesa (2019-02-18 01:24:33)
Quoted 9 lines
Make the entire combination of plls to be one single clock. The parents used for bypasses are specified each as an index in the parents list. The
determine_ratedoes a lookup throughout all the possible combinations for all the divs and returns the best possible 'setup' which in turn is used byset_ratelater to set up all the divs and bypasses.Signed-off-by Abel Vesa <[email protected]>Tested-by Lucas Stach <[email protected]>Acked-by Lucas Stach <[email protected]>
Quoted 8 lines
---
This is basically just a resend of the following:
https://lkml.org/lkml/2019/1/29/874There are no changes. Just added T-b and A-b tags from Lucas.
Waiting for review.
Spoke too soon. I've kicked this out of the tree. This doesn't compile and spews a bunch of sparse warnings on arm32. Presumably because the use of unsigned long was assuming 64 bits in size? Please write portable code and fix these sparse warnings. Probably all the unsigned long usage should be u64?
drivers/clk/imx/clk-sccg-pll.c:142:53: warning: decimal constant 2400000000 is between LONG_MAX and ULONG_MAX. For C99 that means long long, C90 compilers are very likely to produce unsigned long (and a warning) here drivers/clk/imx/clk-sccg-pll.c:199:48: warning: decimal constant 2400000000 is between LONG_MAX and ULONG_MAX. For C99 that means long long, C90 compilers are very likely to produce unsigned long (and a warning) here drivers/clk/imx/clk-sccg-pll.c:138:17: error: incompatible types in comparison expression (different type sizes)drivers/clk/imx/clk-sccg-pll.c:144:25: error: incompatible types in comparison expression (different type sizes)drivers/clk/imx/clk-sccg-pll.c:180:17: error: incompatible types in comparison expression (different type sizes)drivers/clk/imx/clk-sccg-pll.c:217:17: error: incompatible types in comparison expression (different type sizes)drivers/clk/imx/clk-sccg-pll.c:239:17: error: incompatible types in comparison expression (different type sizes)drivers/clk/imx/clk-sccg-pll.c:138:17: warning: shift too big (32) for type unsigned longdrivers/clk/imx/clk-sccg-pll.c:144:25: warning: shift too big (32) for type unsigned longdrivers/clk/imx/clk-sccg-pll.c:180:17: warning: shift too big (32) for type unsigned longdrivers/clk/imx/clk-sccg-pll.c:217:17: warning: shift too big (32) for type longdrivers/clk/imx/clk-sccg-pll.c:239:17: warning: shift too big (32) for type unsigned long
In file included from arch/arm/include/asm/div64.h:127:0,
from include/linux/kernel.h:207,
from include/asm-generic/bug.h:18,
from arch/arm/include/asm/bug.h:60,
from include/linux/bug.h:5,
from include/linux/io.h:23,
from include/linux/clk-provider.h:9,
from drivers/clk/imx/clk-sccg-pll.c:11:
drivers/clk/imx/clk-sccg-pll.c: In function 'clk_sccg_divq_lookup':
include/asm-generic/div64.h:222:28: warning: comparison of distinct pointer types lacks a cast
(void)(((typeof((n)) *)0) == ((uint64_t *)0)); \
^Quoted 8 lines
drivers/clk/imx/clk-imx8mq.c +0
-4@@ -347,14 +319,12 @@ static int imx8mq_clocks_probe(struct platform_device *pdev) clks[IMX8MQ_AUDIO_PLL2_BYPASS ] =imx_clk_mux ("audio_pll2_bypass" , base +0x8 ,14 ,1 , audio_pll2_bypass_sels,ARRAY_SIZE (audio_pll2_bypass_sels)); clks[IMX8MQ_VIDEO_PLL1_BYPASS ] =imx_clk_mux ("video_pll1_bypass" , base +0x10 ,14 ,1 , video_pll1_bypass_sels,ARRAY_SIZE (video_pll1_bypass_sels)); - clks[IMX8MQ_SYS1_PLL1_OUT ] =imx_clk_mux ("sys1_pll1_out" , base +0x30 ,5 ,1 , sys1_pll1_out_sels,ARRAY_SIZE (sys1_pll1_out_sels)); - clks[IMX8MQ_SYS2_PLL1_OUT ] =imx_clk_mux ("sys2_pll1_out" , base +0x3c ,5 ,1 , sys2_pll1_out_sels,ARRAY_SIZE (sys2_pll1_out_sels)); - clks[IMX8MQ_SYS3_PLL1_OUT ] =imx_clk_mux ("sys3_pll1_out" , base +0x48 ,5 ,1 , sys3_pll1_out_sels,ARRAY_SIZE (sys3_pll1_out_sels)); - clks[IMX8MQ_DRAM_PLL1_OUT ] =imx_clk_mux ("dram_pll1_out" , base +0x60 ,5 ,1 , dram_pll1_out_sels,ARRAY_SIZE (dram_pll1_out_sels));
drivers/clk/imx/clk-imx8mq.c static int imx8mq_clocks_probe(struct platform_device *pdev) · line 327
Quoted 10 lines
drivers/clk/imx/clk-imx8mq.c +6
-4- clks[IMX8MQ_SYS1_PLL2_OUT ] =imx_clk_mux ("sys1_pll2_out" , base +0x30 ,4 ,1 , sys1_pll2_out_sels,ARRAY_SIZE (sys1_pll2_out_sels)); - clks[IMX8MQ_SYS2_PLL2_OUT ] =imx_clk_mux ("sys2_pll2_out" , base +0x3c ,4 ,1 , sys2_pll2_out_sels,ARRAY_SIZE (sys2_pll2_out_sels)); - clks[IMX8MQ_SYS3_PLL2_OUT ] =imx_clk_mux ("sys3_pll2_out" , base +0x48 ,4 ,1 , sys3_pll2_out_sels,ARRAY_SIZE (sys3_pll2_out_sels)); - clks[IMX8MQ_DRAM_PLL2_OUT ] =imx_clk_mux ("dram_pll2_out" , base +0x60 ,4 ,1 , dram_pll2_out_sels,ARRAY_SIZE (dram_pll2_out_sels)); +/* unbypass all the plls */ +clk_set_parent (clks[IMX8MQ_GPU_PLL_BYPASS ], clks[IMX8MQ_GPU_PLL ]); +clk_set_parent (clks[IMX8MQ_VPU_PLL_BYPASS ], clks[IMX8MQ_VPU_PLL ]); +clk_set_parent (clks[IMX8MQ_AUDIO_PLL1_BYPASS ], clks[IMX8MQ_AUDIO_PLL1 ]); +clk_set_parent (clks[IMX8MQ_AUDIO_PLL2_BYPASS ], clks[IMX8MQ_AUDIO_PLL2 ]); +clk_set_parent (clks[IMX8MQ_VIDEO_PLL1_BYPASS ], clks[IMX8MQ_VIDEO_PLL1 ]);
Why? Can you just write the hardware registers directly instead of going through the clk APIs during this clk registration routine? While it's obviously easier to just call consumer APIs, it makes it weird because this is a clk provider driver which 1) shouldn't use the consumer APIs and 2) makes probe ordering and other things complicated to figure out. Plus one more extra, it means that changing this code to use the clk_hw APIs is harder.
Quoted 3 lines
drivers/clk/imx/clk-imx8mq.c +0
-0/* PLL OUT GATE */ clks[IMX8MQ_ARM_PLL_OUT ] =imx_clk_gate ("arm_pll_out" ,"arm_pll_bypass" , base +0x28 ,21 );