Skip to content

Commit 89f0398

Browse files
committed
OPP: Migrate set-supported-hw API to use set-config helpers
Now that we have a central API to handle all OPP table configurations, migrate the set-supported-hw 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. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
1 parent b0ec094 commit 89f0398

File tree

5 files changed

+66
-105
lines changed

5 files changed

+66
-105
lines changed

drivers/cpufreq/imx-cpufreq-dt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131

3232
/* cpufreq-dt device registered by imx-cpufreq-dt */
3333
static struct platform_device *cpufreq_dt_pdev;
34-
static struct opp_table *cpufreq_opp_table;
3534
static struct device *cpu_dev;
35+
static int cpufreq_opp_token;
3636

3737
enum IMX7ULP_CPUFREQ_CLKS {
3838
ARM,
@@ -153,17 +153,17 @@ static int imx_cpufreq_dt_probe(struct platform_device *pdev)
153153
dev_info(&pdev->dev, "cpu speed grade %d mkt segment %d supported-hw %#x %#x\n",
154154
speed_grade, mkt_segment, supported_hw[0], supported_hw[1]);
155155

156-
cpufreq_opp_table = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2);
157-
if (IS_ERR(cpufreq_opp_table)) {
158-
ret = PTR_ERR(cpufreq_opp_table);
156+
cpufreq_opp_token = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2);
157+
if (cpufreq_opp_token < 0) {
158+
ret = cpufreq_opp_token;
159159
dev_err(&pdev->dev, "Failed to set supported opp: %d\n", ret);
160160
return ret;
161161
}
162162

163163
cpufreq_dt_pdev = platform_device_register_data(
164164
&pdev->dev, "cpufreq-dt", -1, NULL, 0);
165165
if (IS_ERR(cpufreq_dt_pdev)) {
166-
dev_pm_opp_put_supported_hw(cpufreq_opp_table);
166+
dev_pm_opp_put_supported_hw(cpufreq_opp_token);
167167
ret = PTR_ERR(cpufreq_dt_pdev);
168168
dev_err(&pdev->dev, "Failed to register cpufreq-dt: %d\n", ret);
169169
return ret;
@@ -176,7 +176,7 @@ static int imx_cpufreq_dt_remove(struct platform_device *pdev)
176176
{
177177
platform_device_unregister(cpufreq_dt_pdev);
178178
if (!of_machine_is_compatible("fsl,imx7ulp"))
179-
dev_pm_opp_put_supported_hw(cpufreq_opp_table);
179+
dev_pm_opp_put_supported_hw(cpufreq_opp_token);
180180
else
181181
clk_bulk_put(ARRAY_SIZE(imx7ulp_clks), imx7ulp_clks);
182182

drivers/cpufreq/tegra20-cpufreq.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ static bool cpu0_node_has_opp_v2_prop(void)
3232
return ret;
3333
}
3434

35-
static void tegra20_cpufreq_put_supported_hw(void *opp_table)
35+
static void tegra20_cpufreq_put_supported_hw(void *opp_token)
3636
{
37-
dev_pm_opp_put_supported_hw(opp_table);
37+
dev_pm_opp_put_supported_hw((unsigned long) opp_token);
3838
}
3939

4040
static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
@@ -45,7 +45,6 @@ static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
4545
static int tegra20_cpufreq_probe(struct platform_device *pdev)
4646
{
4747
struct platform_device *cpufreq_dt;
48-
struct opp_table *opp_table;
4948
struct device *cpu_dev;
5049
u32 versions[2];
5150
int err;
@@ -71,16 +70,15 @@ static int tegra20_cpufreq_probe(struct platform_device *pdev)
7170
if (WARN_ON(!cpu_dev))
7271
return -ENODEV;
7372

74-
opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
75-
err = PTR_ERR_OR_ZERO(opp_table);
76-
if (err) {
73+
err = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
74+
if (err < 0) {
7775
dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
7876
return err;
7977
}
8078

8179
err = devm_add_action_or_reset(&pdev->dev,
8280
tegra20_cpufreq_put_supported_hw,
83-
opp_table);
81+
(void *)((unsigned long) err));
8482
if (err)
8583
return err;
8684

drivers/memory/tegra/tegra124-emc.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,15 +1395,14 @@ static int tegra_emc_interconnect_init(struct tegra_emc *emc)
13951395
static int tegra_emc_opp_table_init(struct tegra_emc *emc)
13961396
{
13971397
u32 hw_version = BIT(tegra_sku_info.soc_speedo_id);
1398-
struct opp_table *hw_opp_table;
1399-
int err;
1398+
int opp_token, err;
14001399

1401-
hw_opp_table = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1);
1402-
err = PTR_ERR_OR_ZERO(hw_opp_table);
1403-
if (err) {
1400+
err = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1);
1401+
if (err < 0) {
14041402
dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err);
14051403
return err;
14061404
}
1405+
opp_token = err;
14071406

14081407
err = dev_pm_opp_of_add_table(emc->dev);
14091408
if (err) {
@@ -1430,7 +1429,7 @@ static int tegra_emc_opp_table_init(struct tegra_emc *emc)
14301429
remove_table:
14311430
dev_pm_opp_of_remove_table(emc->dev);
14321431
put_hw_table:
1433-
dev_pm_opp_put_supported_hw(hw_opp_table);
1432+
dev_pm_opp_put_supported_hw(opp_token);
14341433

14351434
return err;
14361435
}

drivers/opp/core.c

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
19521952
}
19531953

19541954
/**
1955-
* dev_pm_opp_set_supported_hw() - Set supported platforms
1955+
* _opp_set_supported_hw() - Set supported platforms
19561956
* @dev: Device for which supported-hw has to be set.
19571957
* @versions: Array of hierarchy of versions to match.
19581958
* @count: Number of elements in the array.
@@ -1962,84 +1962,39 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
19621962
* OPPs, which are available for those versions, based on its 'opp-supported-hw'
19631963
* property.
19641964
*/
1965-
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
1966-
const u32 *versions, unsigned int count)
1965+
static int _opp_set_supported_hw(struct opp_table *opp_table,
1966+
const u32 *versions, unsigned int count)
19671967
{
1968-
struct opp_table *opp_table;
1969-
1970-
opp_table = _add_opp_table(dev, false);
1971-
if (IS_ERR(opp_table))
1972-
return opp_table;
1973-
1974-
/* Make sure there are no concurrent readers while updating opp_table */
1975-
WARN_ON(!list_empty(&opp_table->opp_list));
1976-
19771968
/* Another CPU that shares the OPP table has set the property ? */
19781969
if (opp_table->supported_hw)
1979-
return opp_table;
1970+
return 0;
19801971

19811972
opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
19821973
GFP_KERNEL);
1983-
if (!opp_table->supported_hw) {
1984-
dev_pm_opp_put_opp_table(opp_table);
1985-
return ERR_PTR(-ENOMEM);
1986-
}
1974+
if (!opp_table->supported_hw)
1975+
return -ENOMEM;
19871976

19881977
opp_table->supported_hw_count = count;
19891978

1990-
return opp_table;
1979+
return 0;
19911980
}
1992-
EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
19931981

19941982
/**
1995-
* dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw
1996-
* @opp_table: OPP table returned by dev_pm_opp_set_supported_hw().
1983+
* _opp_put_supported_hw() - Releases resources blocked for supported hw
1984+
* @opp_table: OPP table returned by _opp_set_supported_hw().
19971985
*
19981986
* This is required only for the V2 bindings, and is called for a matching
1999-
* dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure
1987+
* _opp_set_supported_hw(). Until this is called, the opp_table structure
20001988
* will not be freed.
20011989
*/
2002-
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
1990+
static void _opp_put_supported_hw(struct opp_table *opp_table)
20031991
{
2004-
if (unlikely(!opp_table))
2005-
return;
2006-
2007-
kfree(opp_table->supported_hw);
2008-
opp_table->supported_hw = NULL;
2009-
opp_table->supported_hw_count = 0;
2010-
2011-
dev_pm_opp_put_opp_table(opp_table);
2012-
}
2013-
EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
2014-
2015-
static void devm_pm_opp_supported_hw_release(void *data)
2016-
{
2017-
dev_pm_opp_put_supported_hw(data);
2018-
}
2019-
2020-
/**
2021-
* devm_pm_opp_set_supported_hw() - Set supported platforms
2022-
* @dev: Device for which supported-hw has to be set.
2023-
* @versions: Array of hierarchy of versions to match.
2024-
* @count: Number of elements in the array.
2025-
*
2026-
* This is a resource-managed variant of dev_pm_opp_set_supported_hw().
2027-
*
2028-
* Return: 0 on success and errorno otherwise.
2029-
*/
2030-
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
2031-
unsigned int count)
2032-
{
2033-
struct opp_table *opp_table;
2034-
2035-
opp_table = dev_pm_opp_set_supported_hw(dev, versions, count);
2036-
if (IS_ERR(opp_table))
2037-
return PTR_ERR(opp_table);
2038-
2039-
return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release,
2040-
opp_table);
1992+
if (opp_table->supported_hw) {
1993+
kfree(opp_table->supported_hw);
1994+
opp_table->supported_hw = NULL;
1995+
opp_table->supported_hw_count = 0;
1996+
}
20411997
}
2042-
EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw);
20431998

20441999
/**
20452000
* dev_pm_opp_set_prop_name() - Set prop-extn name
@@ -2583,7 +2538,7 @@ static void _opp_clear_config(struct opp_config_data *data)
25832538
if (data->flags & OPP_CONFIG_REGULATOR)
25842539
_opp_put_regulators(data->opp_table);
25852540
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
2586-
dev_pm_opp_put_supported_hw(data->opp_table);
2541+
_opp_put_supported_hw(data->opp_table);
25872542
if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
25882543
dev_pm_opp_unregister_set_opp_helper(data->opp_table);
25892544
if (data->flags & OPP_CONFIG_PROP_NAME)
@@ -2694,12 +2649,10 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
26942649

26952650
/* Configure supported hardware */
26962651
if (config->supported_hw) {
2697-
err = dev_pm_opp_set_supported_hw(dev, config->supported_hw,
2698-
config->supported_hw_count);
2699-
if (IS_ERR(err)) {
2700-
ret = PTR_ERR(err);
2652+
ret = _opp_set_supported_hw(opp_table, config->supported_hw,
2653+
config->supported_hw_count);
2654+
if (ret)
27012655
goto err;
2702-
}
27032656

27042657
data->flags |= OPP_CONFIG_SUPPORTED_HW;
27052658
}

include/linux/pm_opp.h

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
184184
int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
185185
void dev_pm_opp_clear_config(int token);
186186

187-
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
188-
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
189-
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
190187
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
191188
void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
192189
struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
@@ -369,22 +366,6 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti
369366
return -EOPNOTSUPP;
370367
}
371368

372-
static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
373-
const u32 *versions,
374-
unsigned int count)
375-
{
376-
return ERR_PTR(-EOPNOTSUPP);
377-
}
378-
379-
static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
380-
381-
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
382-
const u32 *versions,
383-
unsigned int count)
384-
{
385-
return -EOPNOTSUPP;
386-
}
387-
388369
static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
389370
int (*set_opp)(struct dev_pm_set_opp_data *data))
390371
{
@@ -618,4 +599,34 @@ static inline int devm_pm_opp_set_regulators(struct device *dev,
618599
return devm_pm_opp_set_config(dev, &config);
619600
}
620601

602+
/* Supported-hw helpers */
603+
static inline int dev_pm_opp_set_supported_hw(struct device *dev,
604+
const u32 *versions,
605+
unsigned int count)
606+
{
607+
struct dev_pm_opp_config config = {
608+
.supported_hw = versions,
609+
.supported_hw_count = count,
610+
};
611+
612+
return dev_pm_opp_set_config(dev, &config);
613+
}
614+
615+
static inline void dev_pm_opp_put_supported_hw(int token)
616+
{
617+
dev_pm_opp_clear_config(token);
618+
}
619+
620+
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
621+
const u32 *versions,
622+
unsigned int count)
623+
{
624+
struct dev_pm_opp_config config = {
625+
.supported_hw = versions,
626+
.supported_hw_count = count,
627+
};
628+
629+
return devm_pm_opp_set_config(dev, &config);
630+
}
631+
621632
#endif /* __LINUX_OPP_H__ */

0 commit comments

Comments
 (0)