Skip to content

Commit 4563376

Browse files
committed
OPP: Migrate set-supported-hw API to use set-config helpers
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2122311 commit 89f0398 Author: Viresh Kumar <viresh.kumar@linaro.org> Date: Thu, 26 May 2022 09:36:27 +0530 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> Signed-off-by: Mark Langsdorf <mlangsdo@redhat.com>
1 parent 2b3bcdb commit 4563376

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
@@ -1832,7 +1832,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
18321832
}
18331833

18341834
/**
1835-
* dev_pm_opp_set_supported_hw() - Set supported platforms
1835+
* _opp_set_supported_hw() - Set supported platforms
18361836
* @dev: Device for which supported-hw has to be set.
18371837
* @versions: Array of hierarchy of versions to match.
18381838
* @count: Number of elements in the array.
@@ -1842,84 +1842,39 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
18421842
* OPPs, which are available for those versions, based on its 'opp-supported-hw'
18431843
* property.
18441844
*/
1845-
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
1846-
const u32 *versions, unsigned int count)
1845+
static int _opp_set_supported_hw(struct opp_table *opp_table,
1846+
const u32 *versions, unsigned int count)
18471847
{
1848-
struct opp_table *opp_table;
1849-
1850-
opp_table = _add_opp_table(dev, false);
1851-
if (IS_ERR(opp_table))
1852-
return opp_table;
1853-
1854-
/* Make sure there are no concurrent readers while updating opp_table */
1855-
WARN_ON(!list_empty(&opp_table->opp_list));
1856-
18571848
/* Another CPU that shares the OPP table has set the property ? */
18581849
if (opp_table->supported_hw)
1859-
return opp_table;
1850+
return 0;
18601851

18611852
opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
18621853
GFP_KERNEL);
1863-
if (!opp_table->supported_hw) {
1864-
dev_pm_opp_put_opp_table(opp_table);
1865-
return ERR_PTR(-ENOMEM);
1866-
}
1854+
if (!opp_table->supported_hw)
1855+
return -ENOMEM;
18671856

18681857
opp_table->supported_hw_count = count;
18691858

1870-
return opp_table;
1859+
return 0;
18711860
}
1872-
EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
18731861

18741862
/**
1875-
* dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw
1876-
* @opp_table: OPP table returned by dev_pm_opp_set_supported_hw().
1863+
* _opp_put_supported_hw() - Releases resources blocked for supported hw
1864+
* @opp_table: OPP table returned by _opp_set_supported_hw().
18771865
*
18781866
* This is required only for the V2 bindings, and is called for a matching
1879-
* dev_pm_opp_set_supported_hw(). Until this is called, the opp_table structure
1867+
* _opp_set_supported_hw(). Until this is called, the opp_table structure
18801868
* will not be freed.
18811869
*/
1882-
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
1870+
static void _opp_put_supported_hw(struct opp_table *opp_table)
18831871
{
1884-
if (unlikely(!opp_table))
1885-
return;
1886-
1887-
kfree(opp_table->supported_hw);
1888-
opp_table->supported_hw = NULL;
1889-
opp_table->supported_hw_count = 0;
1890-
1891-
dev_pm_opp_put_opp_table(opp_table);
1892-
}
1893-
EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
1894-
1895-
static void devm_pm_opp_supported_hw_release(void *data)
1896-
{
1897-
dev_pm_opp_put_supported_hw(data);
1898-
}
1899-
1900-
/**
1901-
* devm_pm_opp_set_supported_hw() - Set supported platforms
1902-
* @dev: Device for which supported-hw has to be set.
1903-
* @versions: Array of hierarchy of versions to match.
1904-
* @count: Number of elements in the array.
1905-
*
1906-
* This is a resource-managed variant of dev_pm_opp_set_supported_hw().
1907-
*
1908-
* Return: 0 on success and errorno otherwise.
1909-
*/
1910-
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
1911-
unsigned int count)
1912-
{
1913-
struct opp_table *opp_table;
1914-
1915-
opp_table = dev_pm_opp_set_supported_hw(dev, versions, count);
1916-
if (IS_ERR(opp_table))
1917-
return PTR_ERR(opp_table);
1918-
1919-
return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release,
1920-
opp_table);
1872+
if (opp_table->supported_hw) {
1873+
kfree(opp_table->supported_hw);
1874+
opp_table->supported_hw = NULL;
1875+
opp_table->supported_hw_count = 0;
1876+
}
19211877
}
1922-
EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw);
19231878

19241879
/**
19251880
* dev_pm_opp_set_prop_name() - Set prop-extn name
@@ -2456,7 +2411,7 @@ static void _opp_clear_config(struct opp_config_data *data)
24562411
if (data->flags & OPP_CONFIG_REGULATOR)
24572412
_opp_put_regulators(data->opp_table);
24582413
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
2459-
dev_pm_opp_put_supported_hw(data->opp_table);
2414+
_opp_put_supported_hw(data->opp_table);
24602415
if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
24612416
dev_pm_opp_unregister_set_opp_helper(data->opp_table);
24622417
if (data->flags & OPP_CONFIG_PROP_NAME)
@@ -2567,12 +2522,10 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
25672522

25682523
/* Configure supported hardware */
25692524
if (config->supported_hw) {
2570-
err = dev_pm_opp_set_supported_hw(dev, config->supported_hw,
2571-
config->supported_hw_count);
2572-
if (IS_ERR(err)) {
2573-
ret = PTR_ERR(err);
2525+
ret = _opp_set_supported_hw(opp_table, config->supported_hw,
2526+
config->supported_hw_count);
2527+
if (ret)
25742528
goto err;
2575-
}
25762529

25772530
data->flags |= OPP_CONFIG_SUPPORTED_HW;
25782531
}

include/linux/pm_opp.h

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

180-
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
181-
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
182-
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
183180
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
184181
void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
185182
struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
@@ -350,22 +347,6 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti
350347
return -EOPNOTSUPP;
351348
}
352349

353-
static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
354-
const u32 *versions,
355-
unsigned int count)
356-
{
357-
return ERR_PTR(-EOPNOTSUPP);
358-
}
359-
360-
static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
361-
362-
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
363-
const u32 *versions,
364-
unsigned int count)
365-
{
366-
return -EOPNOTSUPP;
367-
}
368-
369350
static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
370351
int (*set_opp)(struct dev_pm_set_opp_data *data))
371352
{
@@ -599,4 +580,34 @@ static inline int devm_pm_opp_set_regulators(struct device *dev,
599580
return devm_pm_opp_set_config(dev, &config);
600581
}
601582

583+
/* Supported-hw helpers */
584+
static inline int dev_pm_opp_set_supported_hw(struct device *dev,
585+
const u32 *versions,
586+
unsigned int count)
587+
{
588+
struct dev_pm_opp_config config = {
589+
.supported_hw = versions,
590+
.supported_hw_count = count,
591+
};
592+
593+
return dev_pm_opp_set_config(dev, &config);
594+
}
595+
596+
static inline void dev_pm_opp_put_supported_hw(int token)
597+
{
598+
dev_pm_opp_clear_config(token);
599+
}
600+
601+
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
602+
const u32 *versions,
603+
unsigned int count)
604+
{
605+
struct dev_pm_opp_config config = {
606+
.supported_hw = versions,
607+
.supported_hw_count = count,
608+
};
609+
610+
return devm_pm_opp_set_config(dev, &config);
611+
}
612+
602613
#endif /* __LINUX_OPP_H__ */

0 commit comments

Comments
 (0)