Commit 298098e5 authored by Viresh Kumar's avatar Viresh Kumar

OPP: Migrate set-prop-name helper API to use set-config helpers

Now that we have a central API to handle all OPP table configurations,
migrate the set-prop-name 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.

Acked-by: Samuel Holland <samuel@sholland.org> # sun50i
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 442e7a17
...@@ -86,20 +86,20 @@ static int sun50i_cpufreq_get_efuse(u32 *versions) ...@@ -86,20 +86,20 @@ static int sun50i_cpufreq_get_efuse(u32 *versions)
static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
{ {
struct opp_table **opp_tables; int *opp_tokens;
char name[MAX_NAME_LEN]; char name[MAX_NAME_LEN];
unsigned int cpu; unsigned int cpu;
u32 speed = 0; u32 speed = 0;
int ret; int ret;
opp_tables = kcalloc(num_possible_cpus(), sizeof(*opp_tables), opp_tokens = kcalloc(num_possible_cpus(), sizeof(*opp_tokens),
GFP_KERNEL); GFP_KERNEL);
if (!opp_tables) if (!opp_tokens)
return -ENOMEM; return -ENOMEM;
ret = sun50i_cpufreq_get_efuse(&speed); ret = sun50i_cpufreq_get_efuse(&speed);
if (ret) { if (ret) {
kfree(opp_tables); kfree(opp_tokens);
return ret; return ret;
} }
...@@ -113,9 +113,9 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) ...@@ -113,9 +113,9 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
goto free_opp; goto free_opp;
} }
opp_tables[cpu] = dev_pm_opp_set_prop_name(cpu_dev, name); opp_tokens[cpu] = dev_pm_opp_set_prop_name(cpu_dev, name);
if (IS_ERR(opp_tables[cpu])) { if (opp_tokens[cpu] < 0) {
ret = PTR_ERR(opp_tables[cpu]); ret = opp_tokens[cpu];
pr_err("Failed to set prop name\n"); pr_err("Failed to set prop name\n");
goto free_opp; goto free_opp;
} }
...@@ -124,7 +124,7 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) ...@@ -124,7 +124,7 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1, cpufreq_dt_pdev = platform_device_register_simple("cpufreq-dt", -1,
NULL, 0); NULL, 0);
if (!IS_ERR(cpufreq_dt_pdev)) { if (!IS_ERR(cpufreq_dt_pdev)) {
platform_set_drvdata(pdev, opp_tables); platform_set_drvdata(pdev, opp_tokens);
return 0; return 0;
} }
...@@ -132,27 +132,24 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev) ...@@ -132,27 +132,24 @@ static int sun50i_cpufreq_nvmem_probe(struct platform_device *pdev)
pr_err("Failed to register platform device\n"); pr_err("Failed to register platform device\n");
free_opp: free_opp:
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu)
if (IS_ERR_OR_NULL(opp_tables[cpu])) dev_pm_opp_put_prop_name(opp_tokens[cpu]);
break; kfree(opp_tokens);
dev_pm_opp_put_prop_name(opp_tables[cpu]);
}
kfree(opp_tables);
return ret; return ret;
} }
static int sun50i_cpufreq_nvmem_remove(struct platform_device *pdev) static int sun50i_cpufreq_nvmem_remove(struct platform_device *pdev)
{ {
struct opp_table **opp_tables = platform_get_drvdata(pdev); int *opp_tokens = platform_get_drvdata(pdev);
unsigned int cpu; unsigned int cpu;
platform_device_unregister(cpufreq_dt_pdev); platform_device_unregister(cpufreq_dt_pdev);
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
dev_pm_opp_put_prop_name(opp_tables[cpu]); dev_pm_opp_put_prop_name(opp_tokens[cpu]);
kfree(opp_tables); kfree(opp_tokens);
return 0; return 0;
} }
......
...@@ -1997,7 +1997,7 @@ static void _opp_put_supported_hw(struct opp_table *opp_table) ...@@ -1997,7 +1997,7 @@ static void _opp_put_supported_hw(struct opp_table *opp_table)
} }
/** /**
* dev_pm_opp_set_prop_name() - Set prop-extn name * _opp_set_prop_name() - Set prop-extn name
* @dev: Device for which the prop-name has to be set. * @dev: Device for which the prop-name has to be set.
* @name: name to postfix to properties. * @name: name to postfix to properties.
* *
...@@ -2006,50 +2006,33 @@ static void _opp_put_supported_hw(struct opp_table *opp_table) ...@@ -2006,50 +2006,33 @@ static void _opp_put_supported_hw(struct opp_table *opp_table)
* which the extension will apply are opp-microvolt and opp-microamp. OPP core * which the extension will apply are opp-microvolt and opp-microamp. OPP core
* should postfix the property name with -<name> while looking for them. * should postfix the property name with -<name> while looking for them.
*/ */
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name) static int _opp_set_prop_name(struct opp_table *opp_table, const char *name)
{ {
struct opp_table *opp_table;
opp_table = _add_opp_table(dev, false);
if (IS_ERR(opp_table))
return opp_table;
/* Make sure there are no concurrent readers while updating opp_table */
WARN_ON(!list_empty(&opp_table->opp_list));
/* Another CPU that shares the OPP table has set the property ? */ /* Another CPU that shares the OPP table has set the property ? */
if (opp_table->prop_name)
return opp_table;
opp_table->prop_name = kstrdup(name, GFP_KERNEL);
if (!opp_table->prop_name) { if (!opp_table->prop_name) {
dev_pm_opp_put_opp_table(opp_table); opp_table->prop_name = kstrdup(name, GFP_KERNEL);
return ERR_PTR(-ENOMEM); if (!opp_table->prop_name)
return -ENOMEM;
} }
return opp_table; return 0;
} }
EXPORT_SYMBOL_GPL(dev_pm_opp_set_prop_name);
/** /**
* dev_pm_opp_put_prop_name() - Releases resources blocked for prop-name * _opp_put_prop_name() - Releases resources blocked for prop-name
* @opp_table: OPP table returned by dev_pm_opp_set_prop_name(). * @opp_table: OPP table returned by _opp_set_prop_name().
* *
* This is required only for the V2 bindings, and is called for a matching * This is required only for the V2 bindings, and is called for a matching
* dev_pm_opp_set_prop_name(). Until this is called, the opp_table structure * _opp_set_prop_name(). Until this is called, the opp_table structure
* will not be freed. * will not be freed.
*/ */
void dev_pm_opp_put_prop_name(struct opp_table *opp_table) static void _opp_put_prop_name(struct opp_table *opp_table)
{ {
if (unlikely(!opp_table)) if (opp_table->prop_name) {
return;
kfree(opp_table->prop_name); kfree(opp_table->prop_name);
opp_table->prop_name = NULL; opp_table->prop_name = NULL;
}
dev_pm_opp_put_opp_table(opp_table);
} }
EXPORT_SYMBOL_GPL(dev_pm_opp_put_prop_name);
/** /**
* _opp_set_regulators() - Set regulator names for the device * _opp_set_regulators() - Set regulator names for the device
...@@ -2414,7 +2397,7 @@ static void _opp_clear_config(struct opp_config_data *data) ...@@ -2414,7 +2397,7 @@ static void _opp_clear_config(struct opp_config_data *data)
if (data->flags & OPP_CONFIG_REGULATOR_HELPER) if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
_opp_unregister_set_opp_helper(data->opp_table); _opp_unregister_set_opp_helper(data->opp_table);
if (data->flags & OPP_CONFIG_PROP_NAME) if (data->flags & OPP_CONFIG_PROP_NAME)
dev_pm_opp_put_prop_name(data->opp_table); _opp_put_prop_name(data->opp_table);
if (data->flags & OPP_CONFIG_CLK) if (data->flags & OPP_CONFIG_CLK)
_opp_put_clknames(data->opp_table); _opp_put_clknames(data->opp_table);
...@@ -2441,7 +2424,7 @@ static void _opp_clear_config(struct opp_config_data *data) ...@@ -2441,7 +2424,7 @@ static void _opp_clear_config(struct opp_config_data *data)
*/ */
int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
{ {
struct opp_table *opp_table, *err; struct opp_table *opp_table;
struct opp_config_data *data; struct opp_config_data *data;
unsigned int id; unsigned int id;
int ret; int ret;
...@@ -2476,11 +2459,9 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) ...@@ -2476,11 +2459,9 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
/* Configure property names */ /* Configure property names */
if (config->prop_name) { if (config->prop_name) {
err = dev_pm_opp_set_prop_name(dev, config->prop_name); ret = _opp_set_prop_name(opp_table, config->prop_name);
if (IS_ERR(err)) { if (ret)
ret = PTR_ERR(err);
goto err; goto err;
}
data->flags |= OPP_CONFIG_PROP_NAME; data->flags |= OPP_CONFIG_PROP_NAME;
} }
......
...@@ -184,8 +184,6 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config); ...@@ -184,8 +184,6 @@ int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config); int devm_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config);
void dev_pm_opp_clear_config(int token); void dev_pm_opp_clear_config(int token);
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
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); 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);
int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate); int dev_pm_opp_xlate_performance_state(struct opp_table *src_table, struct opp_table *dst_table, unsigned int pstate);
int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq); int dev_pm_opp_set_rate(struct device *dev, unsigned long target_freq);
...@@ -357,13 +355,6 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti ...@@ -357,13 +355,6 @@ static inline int dev_pm_opp_unregister_notifier(struct device *dev, struct noti
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
static inline struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name)
{
return ERR_PTR(-EOPNOTSUPP);
}
static inline void dev_pm_opp_put_prop_name(struct opp_table *opp_table) {}
static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config) static inline int dev_pm_opp_set_config(struct device *dev, struct dev_pm_opp_config *config)
{ {
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -652,5 +643,19 @@ static inline int devm_pm_opp_attach_genpd(struct device *dev, ...@@ -652,5 +643,19 @@ static inline int devm_pm_opp_attach_genpd(struct device *dev,
return devm_pm_opp_set_config(dev, &config); return devm_pm_opp_set_config(dev, &config);
} }
/* prop-name helpers */
static inline int dev_pm_opp_set_prop_name(struct device *dev, const char *name)
{
struct dev_pm_opp_config config = {
.prop_name = name,
};
return dev_pm_opp_set_config(dev, &config);
}
static inline void dev_pm_opp_put_prop_name(int token)
{
dev_pm_opp_clear_config(token);
}
#endif /* __LINUX_OPP_H__ */ #endif /* __LINUX_OPP_H__ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment