clk: Add support for rate table based dividers
Subsystems (5)
PATCH v2 1/1 clk: Add support for rate table based dividers
Some divider clks do not have any obvious relationship between the divider and the value programmed in the register. For instance, say a value of 1 could signify divide by 6 and a value of 2 could signify divide by 4 etc. Also there are dividers where not all values possible based on the bitfield width are valid. For instance a 3 bit wide bitfield can be used to program a value from 0 to 7. However its possible that only 0 to 4 are valid values.
All these cases need the platform code to pass a simple table of divider/value tuple, so the framework knows the exact value to be written based on the divider calculation and can also do better error checking.
This patch adds support for such rate table based dividers.
Also since this means adding a new parameter to the clk_register_divider(), update all existing users of it.
--- arch/arm/mach-imx/clk.h | 2 +- drivers/clk/clk-divider.c | 67 ++++++++++++++++++++++++++++++++++-- drivers/clk/spear/spear3xx_clock.c | 4 +- drivers/clk/spear/spear6xx_clock.c | 4 +- include/linux/clk-private.h | 3 +- include/linux/clk-provider.h | 10 +++++- 6 files changed, 80 insertions(+), 10 deletions(-)
arch/arm/mach-imx/clk.h +1 -1
@@ -56,7 +56,7 @@ static inline struct clk *imx_clk_divider(const char *name, const char *parent, void __iomem *reg, u8 shift, u8 width) { return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT, - reg, shift, width, 0, &imx_ccm_lock); + reg, shift, width, 0, , NULL, &imx_ccm_lock); } static inline struct clk *imx_clk_gate(const char *name, const char *parent,
drivers/clk/clk-divider.c +64 -3
126 lines not on this page · raw message
drivers/clk/spear/spear3xx_clock.c +2 -2
@@ -389,7 +389,7 @@ void __init spear3xx_clk_init(void) clk =clk_register_divider (NULL ,"ahb_clk" ,"pll1_clk" ,CLK_SET_RATE_PARENT ,CORE_CLK_CFG ,HCLK_RATIO_SHIFT , -HCLK_RATIO_MASK ,0 , &_lock); +HCLK_RATIO_MASK ,0 ,NULL , &_lock);clk_register_clkdev (clk,"ahb_clk" ,NULL ); clk = clk_register_aux("uart_synth_clk", "uart_synth_gate_clk",
@@ -510,7 +510,7 @@ void __init spear3xx_clk_init(void) clk =clk_register_divider (NULL ,"apb_clk" ,"ahb_clk" ,CLK_SET_RATE_PARENT ,CORE_CLK_CFG ,PCLK_RATIO_SHIFT , -PCLK_RATIO_MASK ,0 , &_lock); +PCLK_RATIO_MASK ,0 ,NULL , &_lock);clk_register_clkdev (clk,"apb_clk" ,NULL ); clk = clk_register_gate(NULL, "amem_clk", "ahb_clk", 0, AMEM_CLK_CFG,
drivers/clk/spear/spear6xx_clock.c +2 -2
@@ -162,7 +162,7 @@ void __init spear6xx_clk_init(void) clk =clk_register_divider (NULL ,"ahb_clk" ,"pll1_clk" ,CLK_SET_RATE_PARENT ,CORE_CLK_CFG ,HCLK_RATIO_SHIFT , -HCLK_RATIO_MASK ,0 , &_lock); +HCLK_RATIO_MASK ,0 ,NULL , &_lock);clk_register_clkdev (clk,"ahb_clk" ,NULL ); clk = clk_register_aux("uart_synth_clk", "uart_synth_gate_clk",
@@ -285,7 +285,7 @@ void __init spear6xx_clk_init(void) clk =clk_register_divider (NULL ,"apb_clk" ,"ahb_clk" ,CLK_SET_RATE_PARENT ,CORE_CLK_CFG ,PCLK_RATIO_SHIFT , -PCLK_RATIO_MASK ,0 , &_lock); +PCLK_RATIO_MASK ,0 ,NULL , &_lock);clk_register_clkdev (clk,"apb_clk" ,NULL ); clk = clk_register_gate(NULL, "dma_clk", "ahb_clk", 0, PERIP1_CLK_ENB,
include/linux/clk-private.h +2 -1
@@ -105,7 +105,7 @@ struct clk {#define DEFINE_CLK_DIVIDER (_name, _parent_name, _parent_ptr, \ _flags, _reg, _shift, _width, \ - _divider_flags, _lock) \ + _divider_flags, _table, _lock) \ static struct clk _name; \ static const char *_name##_parent_names[] = { \ _parent_name, \
@@ -121,6 +121,7 @@ struct clk { .shift = _shift, \ .width = _width, \ .flags = _divider_flags, \ + .table = _table, \ .lock = _lock, \ }; \ DEFINE_CLK(_name, clk_divider_ops, _flags, \
include/linux/clk-provider.h +9 -1
@@ -203,6 +203,11 @@ struct clk *clk_register_gate(struct device *dev, const char *name, void __iomem *reg, u8 bit_idx, u8 clk_gate_flags, spinlock_t *lock); +struct clk_div_table { +unsigned int val; +unsigned int div; +}; +/** * struct clk_divider - adjustable divider clock *
@@ -210,6 +215,7 @@ struct clk *clk_register_gate(struct device *dev, const char *name,* @reg: register containing the divider * @shift: shift to the divider bit field * @width: width of the divider bit field +* @table: array of value/divider pairs, last entry should have div = 0 * @lock: register lock * * Clock with an adjustable divider affecting its output frequency. Implements
@@ -229,6 +235,7 @@ struct clk_divider {u8 shift;u8 width;u8 flags; +const struct clk_div_table *table;spinlock_t *lock; };
@@ -239,7 +246,8 @@ extern const struct clk_ops clk_divider_ops;struct clk *clk_register_divider (struct device *dev,const char *name,const char *parent_name,unsigned long flags,void __iomem *reg,u8 shift,u8 width, -u8 clk_divider_flags,spinlock_t *lock); +u8 clk_divider_flags,const struct clk_div_table *table, +spinlock_t *lock);/** * struct clk_mux - multiplexer clock
Signature · 1 line
1.7.1
Quoted 39 lines · Rajendra Nayak
Some divider clks do not have any obvious relationship between the divider and the value programmed in the register. For instance, say a value of 1 could signify divide by 6 and a value of 2 could signify divide by 4 etc. Also there are dividers where not all values possible based on the bitfield width are valid. For instance a 3 bit wide bitfield can be used to program a value from 0 to 7. However its possible that only 0 to 4 are valid values.
All these cases need the platform code to pass a simple table of divider/value tuple, so the framework knows the exact value to be written based on the divider calculation and can also do better error checking.
This patch adds support for such rate table based dividers.
Also since this means adding a new parameter to the
clk_register_divider(), update all existing users of it.Signed-off-by Rajendra Nayak <[email protected]>Cc Sascha Hauer <[email protected]>Cc Viresh Kumar <[email protected]>--- arch/arm/mach-imx/clk.h | 2 +- drivers/clk/clk-divider.c | 67 ++++++++++++++++++++++++++++++++++-- drivers/clk/spear/spear3xx_clock.c | 4 +- drivers/clk/spear/spear6xx_clock.c | 4 +- include/linux/clk-private.h | 3 +- include/linux/clk-provider.h | 10 +++++- 6 files changed, 80 insertions(+), 10 deletions(-)arch/arm/mach-imx/clk.h +0
-0
arch/arm/mach-imx/clk.h static inline struct clk *imx_clk_divider(const char *name, const char *parent, · line 59
Quoted 5 lines
arch/arm/mach-imx/clk.h +1
-1@@ -56,7 +56,7 @@ static inline struct clk *imx_clk_divider(const char *name, const char *parent, void __iomem *reg, u8 shift, u8 width) { return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT, - reg, shift, width, 0, &imx_ccm_lock); + reg, shift, width, 0, , NULL, &imx_ccm_lock);
^^^^^
Is this valid C-Syntax?
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Quoted 47 lines · Marc Kleine-Budde
Quoted 39 lines · Rajendra Nayak
Some divider clks do not have any obvious relationship between the divider and the value programmed in the register. For instance, say a value of 1 could signify divide by 6 and a value of 2 could signify divide by 4 etc. Also there are dividers where not all values possible based on the bitfield width are valid. For instance a 3 bit wide bitfield can be used to program a value from 0 to 7. However its possible that only 0 to 4 are valid values.
All these cases need the platform code to pass a simple table of divider/value tuple, so the framework knows the exact value to be written based on the divider calculation and can also do better error checking.
This patch adds support for such rate table based dividers.
Also since this means adding a new parameter to the
clk_register_divider(), update all existing users of it.Signed-off-by Rajendra Nayak<[email protected]>Cc Sascha Hauer<[email protected]>Cc Viresh Kumar<[email protected]>--- arch/arm/mach-imx/clk.h | 2 +- drivers/clk/clk-divider.c | 67 ++++++++++++++++++++++++++++++++++-- drivers/clk/spear/spear3xx_clock.c | 4 +- drivers/clk/spear/spear6xx_clock.c | 4 +- include/linux/clk-private.h | 3 +- include/linux/clk-provider.h | 10 +++++- 6 files changed, 80 insertions(+), 10 deletions(-)arch/arm/mach-imx/clk.h +0
-0arch/arm/mach-imx/clk.h static inline struct clk *imx_clk_divider(const char *name, const char *parent, · line 59
Quoted 5 lines
arch/arm/mach-imx/clk.h +1
-1@@ -56,7 +56,7 @@ static inline struct clk *imx_clk_divider(const char *name, const char *parent, void __iomem *reg, u8 shift, u8 width) { return clk_register_divider(NULL, name, parent, CLK_SET_RATE_PARENT, - reg, shift, width, 0,&imx_ccm_lock); + reg, shift, width, 0, , NULL,&imx_ccm_lock);^^^^^
Quoted 1 line
Is this valid C-Syntax?
Nope, its not. Thanks for catching. Will built test with imx and spear configs before the next spin.
Quoted 3 lines
Marc
Sascha Hauer
maintainerQuoted 15 lines · Rajendra Nayak
Some divider clks do not have any obvious relationship between the divider and the value programmed in the register. For instance, say a value of 1 could signify divide by 6 and a value of 2 could signify divide by 4 etc. Also there are dividers where not all values possible based on the bitfield width are valid. For instance a 3 bit wide bitfield can be used to program a value from 0 to 7. However its possible that only 0 to 4 are valid values.
All these cases need the platform code to pass a simple table of divider/value tuple, so the framework knows the exact value to be written based on the divider calculation and can also do better error checking.
Quoted 6 lines
This patch adds support for such rate table based dividers.
Also since this means adding a new parameter to the
clk_register_divider(), update all existing users of it.
I'm not sure whether we should overload the divider code with another type of divider. Maybe it would be better to add a new clk-divider-table.c for this? Just an idea, the result may or may not be better.
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Quoted 19 lines · Sascha Hauer
Quoted 18 lines · Rajendra Nayak
Some divider clks do not have any obvious relationship between the divider and the value programmed in the register. For instance, say a value of 1 could signify divide by 6 and a value of 2 could signify divide by 4 etc. Also there are dividers where not all values possible based on the bitfield width are valid. For instance a 3 bit wide bitfield can be used to program a value from 0 to 7. However its possible that only 0 to 4 are valid values.
All these cases need the platform code to pass a simple table of divider/value tuple, so the framework knows the exact value to be written based on the divider calculation and can also do better error checking.
This patch adds support for such rate table based dividers.
Quoted 9 lines
Quoted 3 lines
Also since this means adding a new parameter to the
clk_register_divider(), update all existing users of it.I'm not sure whether we should overload the divider code with another type of divider. Maybe it would be better to add a new
clk-divider-table.cfor this? Just an idea, the result may or may not be better.
Sascha,
I had the same concerns originally, but the code reuse in clk-divider.c is pretty good. Before this patch I have it about 200 lines, most of which would have to be reproduced for a separate clk-rate-table.c. So I think marginally added complexity is OK compared to code duplication (and duplicate bugfixes, etc).
Rajendra,
After thinking about it a bit more I still think a separate clk_register_divider_table is needed. Primarily this would reduce needless churn in having to update all existing users of clk_register_divider. I also think that clearly separating the two functions will make it a bit easier on folks trying to port their clocks trees over.
Unless there is a technical reason why having two registration functions is a bad idea, can you send a V4 with that new registration function? I'll take it into clk-next.
Thanks,
Mike
Quoted 8 lines
Sascha
Signature · 4 lines
Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Hi Mike,
Quoted 11 lines
After thinking about it a bit more I still think a separate
clk_register_divider_tableis needed. Primarily this would reduce needless churn in having to update all existing users ofclk_register_divider. I also think that clearly separating the two functions will make it a bit easier on folks trying to port their clocks trees over.Unless there is a technical reason why having two registration functions is a bad idea, can you send a V4 with that new registration function? I'll take it into clk-next.
Nope, no technical reason why it can't be done. I'll do what you suggested and post a v4 soon.
thanks,
Rajendra