Skip to content

Commit 2b3bcdb

Browse files
committed
OPP: Migrate set-regulators API to use set-config helpers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122311 commit b0ec094 Author: Viresh Kumar <viresh.kumar@linaro.org> Date: Mon, 4 Jul 2022 16:36:26 +0530 Now that we have a central API to handle all OPP table configurations, migrate the set-regulators family of helpers to use the new infrastructure. The return type and parameter to the APIs change a bit due to this, update the current users as well in the same commit in order to avoid breaking builds. Reviewed-by: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent 4db9fd3 commit 2b3bcdb

File tree

4 files changed

+60
-106
lines changed

4 files changed

+60
-106
lines changed

drivers/cpufreq/cpufreq-dt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ struct private_data {
2929

3030
cpumask_var_t cpus;
3131
struct device *cpu_dev;
32-
struct opp_table *opp_table;
3332
struct cpufreq_frequency_table *freq_table;
3433
bool have_static_opps;
34+
int opp_token;
3535
};
3636

3737
static LIST_HEAD(priv_list);
@@ -221,9 +221,9 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu)
221221
*/
222222
reg_name[0] = find_supply_name(cpu_dev);
223223
if (reg_name[0]) {
224-
priv->opp_table = dev_pm_opp_set_regulators(cpu_dev, reg_name);
225-
if (IS_ERR(priv->opp_table)) {
226-
ret = PTR_ERR(priv->opp_table);
224+
priv->opp_token = dev_pm_opp_set_regulators(cpu_dev, reg_name);
225+
if (priv->opp_token < 0) {
226+
ret = priv->opp_token;
227227
if (ret != -EPROBE_DEFER)
228228
dev_err(cpu_dev, "failed to set regulators: %d\n",
229229
ret);
@@ -295,7 +295,7 @@ static int dt_cpufreq_early_init(struct device *dev, int cpu)
295295
out:
296296
if (priv->have_static_opps)
297297
dev_pm_opp_of_cpumask_remove_table(priv->cpus);
298-
dev_pm_opp_put_regulators(priv->opp_table);
298+
dev_pm_opp_put_regulators(priv->opp_token);
299299
free_cpumask:
300300
free_cpumask_var(priv->cpus);
301301
return ret;
@@ -309,7 +309,7 @@ static void dt_cpufreq_release(void)
309309
dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &priv->freq_table);
310310
if (priv->have_static_opps)
311311
dev_pm_opp_of_cpumask_remove_table(priv->cpus);
312-
dev_pm_opp_put_regulators(priv->opp_table);
312+
dev_pm_opp_put_regulators(priv->opp_token);
313313
free_cpumask_var(priv->cpus);
314314
list_del(&priv->node);
315315
}

drivers/devfreq/exynos-bus.c

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct exynos_bus {
3333

3434
unsigned long curr_freq;
3535

36-
struct opp_table *opp_table;
36+
int opp_token;
3737
struct clk *clk;
3838
unsigned int ratio;
3939
};
@@ -161,8 +161,7 @@ static void exynos_bus_exit(struct device *dev)
161161

162162
dev_pm_opp_of_remove_table(dev);
163163
clk_disable_unprepare(bus->clk);
164-
dev_pm_opp_put_regulators(bus->opp_table);
165-
bus->opp_table = NULL;
164+
dev_pm_opp_put_regulators(bus->opp_token);
166165
}
167166

168167
static void exynos_bus_passive_exit(struct device *dev)
@@ -179,18 +178,16 @@ static int exynos_bus_parent_parse_of(struct device_node *np,
179178
struct exynos_bus *bus)
180179
{
181180
struct device *dev = bus->dev;
182-
struct opp_table *opp_table;
183181
const char *supplies[] = { "vdd", NULL };
184182
int i, ret, count, size;
185183

186-
opp_table = dev_pm_opp_set_regulators(dev, supplies);
187-
if (IS_ERR(opp_table)) {
188-
ret = PTR_ERR(opp_table);
184+
ret = dev_pm_opp_set_regulators(dev, supplies);
185+
if (ret < 0) {
189186
dev_err(dev, "failed to set regulators %d\n", ret);
190187
return ret;
191188
}
192189

193-
bus->opp_table = opp_table;
190+
bus->opp_token = ret;
194191

195192
/*
196193
* Get the devfreq-event devices to get the current utilization of
@@ -236,8 +233,7 @@ static int exynos_bus_parent_parse_of(struct device_node *np,
236233
return 0;
237234

238235
err_regulator:
239-
dev_pm_opp_put_regulators(bus->opp_table);
240-
bus->opp_table = NULL;
236+
dev_pm_opp_put_regulators(bus->opp_token);
241237

242238
return ret;
243239
}
@@ -459,8 +455,7 @@ static int exynos_bus_probe(struct platform_device *pdev)
459455
dev_pm_opp_of_remove_table(dev);
460456
clk_disable_unprepare(bus->clk);
461457
err_reg:
462-
dev_pm_opp_put_regulators(bus->opp_table);
463-
bus->opp_table = NULL;
458+
dev_pm_opp_put_regulators(bus->opp_token);
464459

465460
return ret;
466461
}

drivers/opp/core.c

Lines changed: 19 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,8 @@ static int _set_opp_custom(const struct opp_table *opp_table,
871871
int size;
872872

873873
/*
874-
* We support this only if dev_pm_opp_set_regulators() was called
875-
* earlier.
874+
* We support this only if dev_pm_opp_set_config() was called
875+
* earlier to set regulators.
876876
*/
877877
if (opp_table->sod_supplies) {
878878
size = sizeof(*old_opp->supplies) * opp_table->regulator_count;
@@ -1977,7 +1977,7 @@ void dev_pm_opp_put_prop_name(struct opp_table *opp_table)
19771977
EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
19781978

19791979
/**
1980-
* dev_pm_opp_set_regulators() - Set regulator names for the device
1980+
* _opp_set_regulators() - Set regulator names for the device
19811981
* @dev: Device for which regulator name is being set.
19821982
* @names: Array of pointers to the names of the regulator.
19831983
* @count: Number of regulators.
@@ -1988,12 +1988,11 @@ EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
19881988
*
19891989
* This must be called before any OPPs are initialized for the device.
19901990
*/
1991-
struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
1992-
const char * const names[])
1991+
static int _opp_set_regulators(struct opp_table *opp_table, struct device *dev,
1992+
const char * const names[])
19931993
{
19941994
struct dev_pm_opp_supply *supplies;
19951995
const char * const *temp = names;
1996-
struct opp_table *opp_table;
19971996
struct regulator *reg;
19981997
int count = 0, ret, i;
19991998

@@ -2002,29 +2001,17 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
20022001
count++;
20032002

20042003
if (!count)
2005-
return ERR_PTR(-EINVAL);
2006-
2007-
opp_table = _add_opp_table(dev, false);
2008-
if (IS_ERR(opp_table))
2009-
return opp_table;
2010-
2011-
/* This should be called before OPPs are initialized */
2012-
if (WARN_ON(!list_empty(&opp_table->opp_list))) {
2013-
ret = -EBUSY;
2014-
goto err;
2015-
}
2004+
return -EINVAL;
20162005

20172006
/* Another CPU that shares the OPP table has set the regulators ? */
20182007
if (opp_table->regulators)
2019-
return opp_table;
2008+
return 0;
20202009

20212010
opp_table->regulators = kmalloc_array(count,
20222011
sizeof(*opp_table->regulators),
20232012
GFP_KERNEL);
2024-
if (!opp_table->regulators) {
2025-
ret = -ENOMEM;
2026-
goto err;
2027-
}
2013+
if (!opp_table->regulators)
2014+
return -ENOMEM;
20282015

20292016
for (i = 0; i < count; i++) {
20302017
reg = regulator_get_optional(dev, names[i]);
@@ -2054,7 +2041,7 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
20542041
}
20552042
mutex_unlock(&opp_table->lock);
20562043

2057-
return opp_table;
2044+
return 0;
20582045

20592046
free_regulators:
20602047
while (i != 0)
@@ -2063,26 +2050,20 @@ struct opp_table *dev_pm_opp_set_regulators(struct device *dev,
20632050
kfree(opp_table->regulators);
20642051
opp_table->regulators = NULL;
20652052
opp_table->regulator_count = -1;
2066-
err:
2067-
dev_pm_opp_put_opp_table(opp_table);
20682053

2069-
return ERR_PTR(ret);
2054+
return ret;
20702055
}
2071-
EXPORT_SYMBOL_GPL(dev_pm_opp_set_regulators);
20722056

20732057
/**
2074-
* dev_pm_opp_put_regulators() - Releases resources blocked for regulator
2075-
* @opp_table: OPP table returned from dev_pm_opp_set_regulators().
2058+
* _opp_put_regulators() - Releases resources blocked for regulator
2059+
* @opp_table: OPP table returned from _opp_set_regulators().
20762060
*/
2077-
void dev_pm_opp_put_regulators(struct opp_table *opp_table)
2061+
static void _opp_put_regulators(struct opp_table *opp_table)
20782062
{
20792063
int i;
20802064

2081-
if (unlikely(!opp_table))
2082-
return;
2083-
20842065
if (!opp_table->regulators)
2085-
goto put_opp_table;
2066+
return;
20862067

20872068
if (opp_table->enabled) {
20882069
for (i = opp_table->regulator_count - 1; i >= 0; i--)
@@ -2105,40 +2086,7 @@ void dev_pm_opp_put_regulators(struct opp_table *opp_table)
21052086
kfree(opp_table->regulators);
21062087
opp_table->regulators = NULL;
21072088
opp_table->regulator_count = -1;
2108-
2109-
put_opp_table:
2110-
dev_pm_opp_put_opp_table(opp_table);
2111-
}
2112-
EXPORT_SYMBOL_GPL(dev_pm_opp_put_regulators);
2113-
2114-
static void devm_pm_opp_regulators_release(void *data)
2115-
{
2116-
dev_pm_opp_put_regulators(data);
2117-
}
2118-
2119-
/**
2120-
* devm_pm_opp_set_regulators() - Set regulator names for the device
2121-
* @dev: Device for which regulator name is being set.
2122-
* @names: Array of pointers to the names of the regulator.
2123-
* @count: Number of regulators.
2124-
*
2125-
* This is a resource-managed variant of dev_pm_opp_set_regulators().
2126-
*
2127-
* Return: 0 on success and errorno otherwise.
2128-
*/
2129-
int devm_pm_opp_set_regulators(struct device *dev,
2130-
const char * const names[])
2131-
{
2132-
struct opp_table *opp_table;
2133-
2134-
opp_table = dev_pm_opp_set_regulators(dev, names);
2135-
if (IS_ERR(opp_table))
2136-
return PTR_ERR(opp_table);
2137-
2138-
return devm_add_action_or_reset(dev, devm_pm_opp_regulators_release,
2139-
opp_table);
21402089
}
2141-
EXPORT_SYMBOL_GPL(devm_pm_opp_set_regulators);
21422090

21432091
/**
21442092
* dev_pm_opp_set_clkname() - Set clk name for the device
@@ -2506,7 +2454,7 @@ static void _opp_clear_config(struct opp_config_data *data)
25062454
if (data->flags & OPP_CONFIG_GENPD)
25072455
dev_pm_opp_detach_genpd(data->opp_table);
25082456
if (data->flags & OPP_CONFIG_REGULATOR)
2509-
dev_pm_opp_put_regulators(data->opp_table);
2457+
_opp_put_regulators(data->opp_table);
25102458
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
25112459
dev_pm_opp_put_supported_hw(data->opp_table);
25122460
if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
@@ -2631,11 +2579,10 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
26312579

26322580
/* Configure supplies */
26332581
if (config->regulator_names) {
2634-
err = dev_pm_opp_set_regulators(dev, config->regulator_names);
2635-
if (IS_ERR(err)) {
2636-
ret = PTR_ERR(err);
2582+
ret = _opp_set_regulators(opp_table, dev,
2583+
config->regulator_names);
2584+
if (ret)
26372585
goto err;
2638-
}
26392586

26402587
data->flags |= OPP_CONFIG_REGULATOR;
26412588
}

include/linux/pm_opp.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
182182
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
183183
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
184184
void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
185-
struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[]);
186-
void dev_pm_opp_put_regulators(struct opp_table *opp_table);
187-
int devm_pm_opp_set_regulators(struct device *dev, const char * const names[]);
188185
struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
189186
void dev_pm_opp_put_clkname(struct opp_table *opp_table);
190187
int devm_pm_opp_set_clkname(struct device *dev, const char *name);
@@ -390,19 +387,6 @@ static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, con
390387

391388
static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
392389

393-
static inline struct opp_table *dev_pm_opp_set_regulators(struct device *dev, const char * const names[])
394-
{
395-
return ERR_PTR(-EOPNOTSUPP);
396-
}
397-
398-
static inline void dev_pm_opp_put_regulators(struct opp_table *opp_table) {}
399-
400-
static inline int devm_pm_opp_set_regulators(struct device *dev,
401-
const char * const names[])
402-
{
403-
return -EOPNOTSUPP;
404-
}
405-
406390
static inline struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name)
407391
{
408392
return ERR_PTR(-EOPNOTSUPP);
@@ -587,4 +571,32 @@ static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_ta
587571
}
588572
#endif
589573

574+
/* OPP Configuration helpers */
575+
576+
/* Regulators helpers */
577+
static inline int dev_pm_opp_set_regulators(struct device *dev,
578+
const char * const names[])
579+
{
580+
struct dev_pm_opp_config config = {
581+
.regulator_names = names,
582+
};
583+
584+
return dev_pm_opp_set_config(dev, &config);
585+
}
586+
587+
static inline void dev_pm_opp_put_regulators(int token)
588+
{
589+
dev_pm_opp_clear_config(token);
590+
}
591+
592+
static inline int devm_pm_opp_set_regulators(struct device *dev,
593+
const char * const names[])
594+
{
595+
struct dev_pm_opp_config config = {
596+
.regulator_names = names,
597+
};
598+
599+
return devm_pm_opp_set_config(dev, &config);
600+
}
601+
590602
#endif /* __LINUX_OPP_H__ */

0 commit comments

Comments
 (0)