clk: Add generic sync_state callback for disabling unused clocks
Subsystems (3)
PATCH v2 1/2 clk: Add generic sync_state callback for disabling unused clocks
There are unused clocks that need to remain untouched by clk_disable_unused, and most likely could be disabled later on sync_state. So provide a generic sync_state callback for the clock providers that register such clocks. Then, use the same mechanism as clk_disable_unused from that generic callback, but pass the device to make sure only the clocks belonging to the current clock provider get disabled, if unused. Also, during the default clk_disable_unused, if the driver that registered the clock has the generic clk_sync_state_disable_unused callback set for sync_state, skip disabling its clocks.
---
Changes since v1:
* Dropped the 0 returned by __clk_disable_unused when clk_ignore_unused is set.
* Dropped __initdata for clk_ignore_unused
drivers/clk/clk.c | 59 +++++++++++++++++++++++++++++------- include/linux/clk-provider.h | 1 + 2 files changed, 49 insertions(+), 11 deletions(-)
drivers/clk/clk.c +48 -11
@@ -1302,14 +1302,27 @@ static void clk_core_disable_unprepare(struct clk_core *core)clk_core_unprepare_lock (core); } -static void __init clk_unprepare_unused_subtree (struct clk_core *core) +static void clk_unprepare_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_unprepare_unused_subtree (child); +clk_unprepare_unused_subtree (child, dev); + +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be unprepared on sync_state, +* so leave as is for now +*/ +if (!from_sync_state &&dev_has_sync_state (core->dev) && + core->dev->driver->sync_state == clk_sync_state_disable_unused) +return ;if (core->prepare_count)return ;
@@ -1332,15 +1345,28 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)clk_pm_runtime_put (core); } -static void __init clk_disable_unused_subtree (struct clk_core *core) +static void clk_disable_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;unsigned long flags;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_disable_unused_subtree (child); +clk_disable_unused_subtree (child, dev); + +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be disabled on sync_state, +* so leave as is for now +*/ +if (!from_sync_state && + core->dev->driver->sync_state == clk_sync_state_disable_unused) +return ;if (core->flags &CLK_OPS_PARENT_ENABLE )clk_core_prepare_enable (core->parent);
@@ -1378,7 +1404,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)clk_core_disable_unprepare (core->parent); } -static bool clk_ignore_unused__initdata ; +static bool clk_ignore_unused;static int __init clk_ignore_unused_setup (char *__unused) { clk_ignore_unused = true;
@@ -1386,35 +1412,46 @@ static int __init clk_ignore_unused_setup(char *__unused) }__setup ("clk_ignore_unused" , clk_ignore_unused_setup); -static int __init clk_disable_unused (void ) +static void __clk_disable_unused (struct device *dev) {struct clk_core *core;if (clk_ignore_unused) {pr_warn ("clk: Not disabling unused clocks\n" ); -return 0 ; +return ; }clk_prepare_lock ();hlist_for_each_entry (core, &clk_root_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_root_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);clk_prepare_unlock (); +} + +static int __init clk_disable_unused (void ) +{ +__clk_disable_unused (NULL );return 0 ; }late_initcall_sync (clk_disable_unused); +void clk_sync_state_disable_unused (struct device *dev) +{ +__clk_disable_unused (dev); +} +EXPORT_SYMBOL_GPL (clk_sync_state_disable_unused); +static int clk_core_determine_round_nolock (struct clk_core *core,struct clk_rate_request *req) {
include/linux/clk-provider.h +1 -0
@@ -720,6 +720,7 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name, void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); +void clk_sync_state_disable_unused (struct device *dev);/** * clk_register_divider - register a divider clock with the clock framework * @dev: device registering this clock
Signature · 1 line
2.34.1
PATCH v2 2/2 clk: qcom: sdm845: Use generic clk_sync_state_disable_unused callback
By adding the newly added clk_sync_state_disable_unused as sync_state callback to all sdm845 clock providers, we make sure that no clock belonging to these providers gets disabled on clk_disable_unused, but rather they are disabled on sync_state, when it is safe, since all the consumers build as modules have had their chance of enabling their own clocks.
---
Changes since v1:
* None
drivers/clk/qcom/camcc-sdm845.c | 1 + drivers/clk/qcom/dispcc-sdm845.c | 1 + drivers/clk/qcom/gcc-sdm845.c | 1 + drivers/clk/qcom/gpucc-sdm845.c | 1 + 4 files changed, 4 insertions(+)
drivers/clk/qcom/camcc-sdm845.c +1 -0
@@ -1743,6 +1743,7 @@ static struct platform_driver cam_cc_sdm845_driver = { .driver = { .name = "sdm845-camcc", .of_match_table = cam_cc_sdm845_match_table, + .sync_state = clk_sync_state_disable_unused, }, };
drivers/clk/qcom/dispcc-sdm845.c +1 -0
@@ -869,6 +869,7 @@ static struct platform_driver disp_cc_sdm845_driver = { .driver = { .name = "disp_cc-sdm845", .of_match_table = disp_cc_sdm845_match_table, + .sync_state = clk_sync_state_disable_unused, }, };
drivers/clk/qcom/gcc-sdm845.c +1 -0
@@ -4020,6 +4020,7 @@ static struct platform_driver gcc_sdm845_driver = { .driver = { .name = "gcc-sdm845", .of_match_table = gcc_sdm845_match_table, + .sync_state = clk_sync_state_disable_unused, }, };
drivers/clk/qcom/gpucc-sdm845.c +1 -0
@@ -205,6 +205,7 @@ static struct platform_driver gpu_cc_sdm845_driver = { .driver = { .name = "sdm845-gpucc", .of_match_table = gpu_cc_sdm845_match_table, + .sync_state = clk_sync_state_disable_unused, }, };
Signature · 1 line
2.34.1
Quoted 43 lines · Abel Vesa
There are unused clocks that need to remain untouched by
clk_disable_unused, and most likely could be disabled later onsync_state. So provide a genericsync_statecallback for the clock providers that register such clocks. Then, use the same mechanism asclk_disable_unusedfrom that generic callback, but pass the device to make sure only the clocks belonging to the current clock provider get disabled, if unused. Also, during the defaultclk_disable_unused, if the driver that registered the clock has the genericclk_sync_state_disable_unusedcallback set forsync_state, skip disabling its clocks.Signed-off-by Abel Vesa <[email protected]>---
Changes since v1:
* Dropped the 0 returned by__clk_disable_unusedwhenclk_ignore_unusedis set.
* Dropped__initdataforclk_ignore_unuseddrivers/clk/clk.c | 59 +++++++++++++++++++++++++++++------- include/linux/clk-provider.h | 1 + 2 files changed, 49 insertions(+), 11 deletions(-)drivers/clk/clk.c +4
-2@@ -1302,14 +1302,27 @@ static void clk_core_disable_unprepare(struct clk_core *core)clk_core_unprepare_lock (core); } -static void __init clk_unprepare_unused_subtree (struct clk_core *core) +static void clk_unprepare_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_unprepare_unused_subtree (child); +clk_unprepare_unused_subtree (child, dev);
drivers/clk/clk.c static void clk_core_disable_unprepare(struct clk_core *core) · line 1324
Quoted 10 lines
drivers/clk/clk.c +10
-0+ +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be unprepared on sync_state, +* so leave as is for now +*/ +if (!from_sync_state &&dev_has_sync_state (core->dev) && + core->dev->driver->sync_state == clk_sync_state_disable_unused)
I link the overall approach, but I don't think we should check the sync_state function.
Such a check would disallow a driver to wrap the clk_sync_state_disable_unused() into some driver-specific code.
Quoted 112 lines
drivers/clk/clk.c +34
-9+return ;if (core->prepare_count)return ;@@ -1332,15 +1345,28 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)clk_pm_runtime_put (core); } -static void __init clk_disable_unused_subtree (struct clk_core *core) +static void clk_disable_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;unsigned long flags;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_disable_unused_subtree (child); +clk_disable_unused_subtree (child, dev); + +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be disabled on sync_state, +* so leave as is for now +*/ +if (!from_sync_state && + core->dev->driver->sync_state == clk_sync_state_disable_unused) +return ;if (core->flags &CLK_OPS_PARENT_ENABLE )clk_core_prepare_enable (core->parent);@@ -1378,7 +1404,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)clk_core_disable_unprepare (core->parent); } -static bool clk_ignore_unused__initdata ; +static bool clk_ignore_unused;static int __init clk_ignore_unused_setup (char *__unused) { clk_ignore_unused = true;@@ -1386,35 +1412,46 @@ static int __init clk_ignore_unused_setup(char *__unused) }__setup ("clk_ignore_unused" , clk_ignore_unused_setup); -static int __init clk_disable_unused (void ) +static void __clk_disable_unused (struct device *dev) {struct clk_core *core;if (clk_ignore_unused) {pr_warn ("clk: Not disabling unused clocks\n" ); -return 0 ; +return ; }clk_prepare_lock ();hlist_for_each_entry (core, &clk_root_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_root_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);clk_prepare_unlock (); +} + +static int __init clk_disable_unused (void ) +{ +__clk_disable_unused (NULL );return 0 ; }late_initcall_sync (clk_disable_unused); +void clk_sync_state_disable_unused (struct device *dev) +{ +__clk_disable_unused (dev); +} +EXPORT_SYMBOL_GPL (clk_sync_state_disable_unused); +static int clk_core_determine_round_nolock (struct clk_core *core,struct clk_rate_request *req) {include/linux/clk-provider.h +1
-1@@ -720,6 +720,7 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name, void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); +void clk_sync_state_disable_unused (struct device *dev);/** * clk_register_divider - register a divider clock with the clock framework * @dev: device registering this clock -- 2.34.1
Signature · 2 lines
With best wishes Dmitry
Quoted 51 lines · Dmitry Baryshkov
Quoted 50 lines · Abel Vesa
There are unused clocks that need to remain untouched by
clk_disable_unused, and most likely could be disabled later onsync_state. So provide a genericsync_statecallback for the clock providers that register such clocks. Then, use the same mechanism asclk_disable_unusedfrom that generic callback, but pass the device to make sure only the clocks belonging to the current clock provider get disabled, if unused. Also, during the defaultclk_disable_unused, if the driver that registered the clock has the genericclk_sync_state_disable_unusedcallback set forsync_state, skip disabling its clocks.Signed-off-by Abel Vesa <[email protected]>---
Changes since v1:
* Dropped the 0 returned by__clk_disable_unusedwhenclk_ignore_unusedis set.
* Dropped__initdataforclk_ignore_unuseddrivers/clk/clk.c | 59 +++++++++++++++++++++++++++++------- include/linux/clk-provider.h | 1 + 2 files changed, 49 insertions(+), 11 deletions(-)drivers/clk/clk.c +11
-2@@ -1302,14 +1302,27 @@ static void clk_core_disable_unprepare(struct clk_core *core)clk_core_unprepare_lock (core); } -static void __init clk_unprepare_unused_subtree (struct clk_core *core) +static void clk_unprepare_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_unprepare_unused_subtree (child); +clk_unprepare_unused_subtree (child, dev); + +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be unprepared on sync_state, +* so leave as is for now
Quoted 8 lines
drivers/clk/clk.c static void clk_core_disable_unprepare(struct clk_core *core) · line 1324
Quoted 3 lines
drivers/clk/clk.c +3
-0+*/ +if (!from_sync_state &&dev_has_sync_state (core->dev) && + core->dev->driver->sync_state == clk_sync_state_disable_unused)I link the overall approach, but I don't think we should check the
sync_statefunction.
Such a check would disallow a driver to wrap theclk_sync_state_disable_unused()into some driver-specific code.
OK, will drop it and resend.
Quoted 118 lines
Quoted 113 lines
drivers/clk/clk.c +34
-9+return ;if (core->prepare_count)return ;@@ -1332,15 +1345,28 @@ static void __init clk_unprepare_unused_subtree(struct clk_core *core)clk_pm_runtime_put (core); } -static void __init clk_disable_unused_subtree (struct clk_core *core) +static void clk_disable_unused_subtree (struct clk_core *core, +struct device *dev) { +bool from_sync_state = !!dev;struct clk_core *child;unsigned long flags;lockdep_assert_held (&prepare_lock);hlist_for_each_entry (child, &core->children, child_node) -clk_disable_unused_subtree (child); +clk_disable_unused_subtree (child, dev); + +if (from_sync_state && core->dev != dev) +return ; + +/* +* clock will be disabled on sync_state, +* so leave as is for now +*/ +if (!from_sync_state && + core->dev->driver->sync_state == clk_sync_state_disable_unused) +return ;if (core->flags &CLK_OPS_PARENT_ENABLE )clk_core_prepare_enable (core->parent);@@ -1378,7 +1404,7 @@ static void __init clk_disable_unused_subtree(struct clk_core *core)clk_core_disable_unprepare (core->parent); } -static bool clk_ignore_unused__initdata ; +static bool clk_ignore_unused;static int __init clk_ignore_unused_setup (char *__unused) { clk_ignore_unused = true;@@ -1386,35 +1412,46 @@ static int __init clk_ignore_unused_setup(char *__unused) }__setup ("clk_ignore_unused" , clk_ignore_unused_setup); -static int __init clk_disable_unused (void ) +static void __clk_disable_unused (struct device *dev) {struct clk_core *core;if (clk_ignore_unused) {pr_warn ("clk: Not disabling unused clocks\n" ); -return 0 ; +return ; }clk_prepare_lock ();hlist_for_each_entry (core, &clk_root_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_disable_unused_subtree (core); +clk_disable_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_root_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);hlist_for_each_entry (core, &clk_orphan_list, child_node) -clk_unprepare_unused_subtree (core); +clk_unprepare_unused_subtree (core, dev);clk_prepare_unlock (); +} + +static int __init clk_disable_unused (void ) +{ +__clk_disable_unused (NULL );return 0 ; }late_initcall_sync (clk_disable_unused); +void clk_sync_state_disable_unused (struct device *dev) +{ +__clk_disable_unused (dev); +} +EXPORT_SYMBOL_GPL (clk_sync_state_disable_unused); +static int clk_core_determine_round_nolock (struct clk_core *core,struct clk_rate_request *req) {include/linux/clk-provider.h +1
-1@@ -720,6 +720,7 @@ struct clk *clk_register_divider_table(struct device *dev, const char *name, void __iomem *reg, u8 shift, u8 width, u8 clk_divider_flags, const struct clk_div_table *table, spinlock_t *lock); +void clk_sync_state_disable_unused (struct device *dev);/** * clk_register_divider - register a divider clock with the clock framework * @dev: device registering this clock -- 2.34.1
Signature · 2 lines
With best wishes Dmitry