clk: Add get/enable/disable/release for a bulk of clocks
Subsystems (2)
PATCH 1/1 clk: Add get/enable/disable/release for a bulk of clocks
This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.
This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.
---
This serie and the "reset bulk" serie is necessary and suggested by Marek Vasut for the "Add USB Support for Amlogic Meson GXL SoCs" to avoid adding the same code to manage a bulk of clocks and resets in another driver.
I will push a RFC code to update the other drivers having a similar code pattern when these patches are merged.
drivers/clk/clk-uclass.c | 59 +++++++++++++++++++++++++++++++++++++++ include/clk.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-)
drivers/clk/clk-uclass.c +59 -0
@@ -104,6 +104,39 @@ int clk_get_by_index(struct udevice *dev, int index, struct clk *clk)return clk_get_by_indexed_prop (dev,"clocks" , index, clk); } +int clk_get_bulk (struct udevice *dev,struct clk_bulk *bulk) +{ +int i, ret, err, count; + + bulk->count =0 ; + + count =dev_count_phandle_with_args (dev,"clocks" ,"#clock-cells" ); +if (!count) +return 0 ; + + bulk->clks =devm_kcalloc (dev, count,sizeof (struct clk ),GFP_KERNEL ); +if (!bulk->clks) +return -ENOMEM ; + +for (i =0 ; i < count; i++) { + ret =clk_get_by_index (dev, i, &bulk->clks[i]); +if (ret <0 ) + goto bulk_get_err; + + ++bulk->count; + } + +return 0 ; + +bulk_get_err: + err =clk_release_all (bulk->clks, bulk->count); +if (err) +debug ("%s: could release all clocks for %p\n" , + __func__, dev); + +return ret; +} +static int clk_set_default_parents (struct udevice *dev) {struct clk clk, parent_clk;
@@ -336,6 +369,19 @@ int clk_enable(struct clk *clk)return ops->enable (clk); } +int clk_enable_bulk (struct clk_bulk *bulk) +{ +int i, ret; + +for (i =0 ; i < bulk->count; i++) { + ret =clk_enable (&bulk->clks[i]); +if (ret <0 && ret != -ENOSYS ) +return ret; + } + +return 0 ; +} +int clk_disable (struct clk *clk) {const struct clk_ops *ops =clk_dev_ops (clk->dev);
@@ -348,6 +394,19 @@ int clk_disable(struct clk *clk)return ops->disable (clk); } +int clk_disable_bulk (struct clk_bulk *bulk) +{ +int i, ret; + +for (i =0 ; i < bulk->count; i++) { + ret =clk_disable (&bulk->clks[i]); +if (ret <0 && ret != -ENOSYS ) +return ret; + } + +return 0 ; +} +UCLASS_DRIVER (clk) = { .id =UCLASS_CLK , .name ="clk" ,
include/clk.h +71 -1
114 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH 1/1 clk: Add get/enable/disable/release for a bulk of clocks
Quoted 14 lines · Neil Armstrong
This patch adds a "bulk" API to the clock API in order to get/enable/disable /release a group of clocks associated with a device.
This bulk API will avoid adding a copy of the same code to manage a group of clocks in drivers.
Signed-off-by Neil Armstrong <[email protected]>---
This serie and the "reset bulk" serie is necessary and suggested by Marek Vasut for the "Add USB Support for Amlogic Meson GXL SoCs" to avoid adding the same code to manage a bulk of clocks and resets in another driver.
I will push a RFC code to update the other drivers having a similar code pattern when these patches are merged.
Quoted 4 lines
drivers/clk/clk-uclass.c | 59 +++++++++++++++++++++++++++++++++++++++ include/clk.h | 72 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 130 insertions(+), 1 deletion(-)
This looks good. Please can you add a sandbox test?
Regards,
Simon