Skip to content

Commit 8174a3a

Browse files
committed
OPP: Provide a simple implementation to configure multiple clocks
This provides a simple implementation to configure multiple clocks for a device. Tested-by: Dmitry Osipenko <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent f123ea7 commit 8174a3a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/opp/core.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,40 @@ _opp_config_clk_single(struct device *dev, struct opp_table *opp_table,
843843
return ret;
844844
}
845845

846+
/*
847+
* Simple implementation for configuring multiple clocks. Configure clocks in
848+
* the order in which they are present in the array while scaling up.
849+
*/
850+
int dev_pm_opp_config_clks_simple(struct device *dev,
851+
struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
852+
bool scaling_down)
853+
{
854+
int ret, i;
855+
856+
if (scaling_down) {
857+
for (i = opp_table->clk_count - 1; i >= 0; i--) {
858+
ret = clk_set_rate(opp_table->clks[i], opp->rates[i]);
859+
if (ret) {
860+
dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
861+
ret);
862+
return ret;
863+
}
864+
}
865+
} else {
866+
for (i = 0; i < opp_table->clk_count; i++) {
867+
ret = clk_set_rate(opp_table->clks[i], opp->rates[i]);
868+
if (ret) {
869+
dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
870+
ret);
871+
return ret;
872+
}
873+
}
874+
}
875+
876+
return ret;
877+
}
878+
EXPORT_SYMBOL_GPL(dev_pm_opp_config_clks_simple);
879+
846880
static int _opp_config_regulator_single(struct device *dev,
847881
struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
848882
struct regulator **regulators, unsigned int count)

include/linux/pm_opp.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ int dev_pm_opp_unregister_notifier(struct device *dev, struct notifier_block *nb
159159
int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
160160
int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
161161
void dev_pm_opp_clear_config(int token);
162+
int dev_pm_opp_config_clks_simple(struct device *dev,
163+
struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
164+
bool scaling_down);
162165

163166
struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table, struct opp_table *dst_table, struct dev_pm_opp *src_opp);
164167
int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
@@ -342,6 +345,13 @@ static inline int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_c
342345

343346
static inline void dev_pm_opp_clear_config(int token) {}
344347

348+
static inline int dev_pm_opp_config_clks_simple(struct device *dev,
349+
struct opp_table *opp_table, struct dev_pm_opp *opp, void *data,
350+
bool scaling_down)
351+
{
352+
return -EOPNOTSUPP;
353+
}
354+
345355
static inline struct dev_pm_opp *dev_pm_opp_xlate_required_opp(struct opp_table *src_table,
346356
struct opp_table *dst_table, struct dev_pm_opp *src_opp)
347357
{

0 commit comments

Comments
 (0)