mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-06 05:02:31 +00:00
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>
This commit is contained in:
parent
b0ec094286
commit
89f03984fa
@ -31,8 +31,8 @@
|
|||||||
|
|
||||||
/* cpufreq-dt device registered by imx-cpufreq-dt */
|
/* cpufreq-dt device registered by imx-cpufreq-dt */
|
||||||
static struct platform_device *cpufreq_dt_pdev;
|
static struct platform_device *cpufreq_dt_pdev;
|
||||||
static struct opp_table *cpufreq_opp_table;
|
|
||||||
static struct device *cpu_dev;
|
static struct device *cpu_dev;
|
||||||
|
static int cpufreq_opp_token;
|
||||||
|
|
||||||
enum IMX7ULP_CPUFREQ_CLKS {
|
enum IMX7ULP_CPUFREQ_CLKS {
|
||||||
ARM,
|
ARM,
|
||||||
@ -153,9 +153,9 @@ static int imx_cpufreq_dt_probe(struct platform_device *pdev)
|
|||||||
dev_info(&pdev->dev, "cpu speed grade %d mkt segment %d supported-hw %#x %#x\n",
|
dev_info(&pdev->dev, "cpu speed grade %d mkt segment %d supported-hw %#x %#x\n",
|
||||||
speed_grade, mkt_segment, supported_hw[0], supported_hw[1]);
|
speed_grade, mkt_segment, supported_hw[0], supported_hw[1]);
|
||||||
|
|
||||||
cpufreq_opp_table = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2);
|
cpufreq_opp_token = dev_pm_opp_set_supported_hw(cpu_dev, supported_hw, 2);
|
||||||
if (IS_ERR(cpufreq_opp_table)) {
|
if (cpufreq_opp_token < 0) {
|
||||||
ret = PTR_ERR(cpufreq_opp_table);
|
ret = cpufreq_opp_token;
|
||||||
dev_err(&pdev->dev, "Failed to set supported opp: %d\n", ret);
|
dev_err(&pdev->dev, "Failed to set supported opp: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ static int imx_cpufreq_dt_probe(struct platform_device *pdev)
|
|||||||
cpufreq_dt_pdev = platform_device_register_data(
|
cpufreq_dt_pdev = platform_device_register_data(
|
||||||
&pdev->dev, "cpufreq-dt", -1, NULL, 0);
|
&pdev->dev, "cpufreq-dt", -1, NULL, 0);
|
||||||
if (IS_ERR(cpufreq_dt_pdev)) {
|
if (IS_ERR(cpufreq_dt_pdev)) {
|
||||||
dev_pm_opp_put_supported_hw(cpufreq_opp_table);
|
dev_pm_opp_put_supported_hw(cpufreq_opp_token);
|
||||||
ret = PTR_ERR(cpufreq_dt_pdev);
|
ret = PTR_ERR(cpufreq_dt_pdev);
|
||||||
dev_err(&pdev->dev, "Failed to register cpufreq-dt: %d\n", ret);
|
dev_err(&pdev->dev, "Failed to register cpufreq-dt: %d\n", ret);
|
||||||
return ret;
|
return ret;
|
||||||
@ -176,7 +176,7 @@ static int imx_cpufreq_dt_remove(struct platform_device *pdev)
|
|||||||
{
|
{
|
||||||
platform_device_unregister(cpufreq_dt_pdev);
|
platform_device_unregister(cpufreq_dt_pdev);
|
||||||
if (!of_machine_is_compatible("fsl,imx7ulp"))
|
if (!of_machine_is_compatible("fsl,imx7ulp"))
|
||||||
dev_pm_opp_put_supported_hw(cpufreq_opp_table);
|
dev_pm_opp_put_supported_hw(cpufreq_opp_token);
|
||||||
else
|
else
|
||||||
clk_bulk_put(ARRAY_SIZE(imx7ulp_clks), imx7ulp_clks);
|
clk_bulk_put(ARRAY_SIZE(imx7ulp_clks), imx7ulp_clks);
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ static bool cpu0_node_has_opp_v2_prop(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tegra20_cpufreq_put_supported_hw(void *opp_table)
|
static void tegra20_cpufreq_put_supported_hw(void *opp_token)
|
||||||
{
|
{
|
||||||
dev_pm_opp_put_supported_hw(opp_table);
|
dev_pm_opp_put_supported_hw((unsigned long) opp_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
|
static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
|
||||||
@ -45,7 +45,6 @@ static void tegra20_cpufreq_dt_unregister(void *cpufreq_dt)
|
|||||||
static int tegra20_cpufreq_probe(struct platform_device *pdev)
|
static int tegra20_cpufreq_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct platform_device *cpufreq_dt;
|
struct platform_device *cpufreq_dt;
|
||||||
struct opp_table *opp_table;
|
|
||||||
struct device *cpu_dev;
|
struct device *cpu_dev;
|
||||||
u32 versions[2];
|
u32 versions[2];
|
||||||
int err;
|
int err;
|
||||||
@ -71,16 +70,15 @@ static int tegra20_cpufreq_probe(struct platform_device *pdev)
|
|||||||
if (WARN_ON(!cpu_dev))
|
if (WARN_ON(!cpu_dev))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
opp_table = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
|
err = dev_pm_opp_set_supported_hw(cpu_dev, versions, 2);
|
||||||
err = PTR_ERR_OR_ZERO(opp_table);
|
if (err < 0) {
|
||||||
if (err) {
|
|
||||||
dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
|
dev_err(&pdev->dev, "failed to set supported hw: %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = devm_add_action_or_reset(&pdev->dev,
|
err = devm_add_action_or_reset(&pdev->dev,
|
||||||
tegra20_cpufreq_put_supported_hw,
|
tegra20_cpufreq_put_supported_hw,
|
||||||
opp_table);
|
(void *)((unsigned long) err));
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
@ -1395,15 +1395,14 @@ static int tegra_emc_interconnect_init(struct tegra_emc *emc)
|
|||||||
static int tegra_emc_opp_table_init(struct tegra_emc *emc)
|
static int tegra_emc_opp_table_init(struct tegra_emc *emc)
|
||||||
{
|
{
|
||||||
u32 hw_version = BIT(tegra_sku_info.soc_speedo_id);
|
u32 hw_version = BIT(tegra_sku_info.soc_speedo_id);
|
||||||
struct opp_table *hw_opp_table;
|
int opp_token, err;
|
||||||
int err;
|
|
||||||
|
|
||||||
hw_opp_table = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1);
|
err = dev_pm_opp_set_supported_hw(emc->dev, &hw_version, 1);
|
||||||
err = PTR_ERR_OR_ZERO(hw_opp_table);
|
if (err < 0) {
|
||||||
if (err) {
|
|
||||||
dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err);
|
dev_err(emc->dev, "failed to set OPP supported HW: %d\n", err);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
opp_token = err;
|
||||||
|
|
||||||
err = dev_pm_opp_of_add_table(emc->dev);
|
err = dev_pm_opp_of_add_table(emc->dev);
|
||||||
if (err) {
|
if (err) {
|
||||||
@ -1430,7 +1429,7 @@ static int tegra_emc_opp_table_init(struct tegra_emc *emc)
|
|||||||
remove_table:
|
remove_table:
|
||||||
dev_pm_opp_of_remove_table(emc->dev);
|
dev_pm_opp_of_remove_table(emc->dev);
|
||||||
put_hw_table:
|
put_hw_table:
|
||||||
dev_pm_opp_put_supported_hw(hw_opp_table);
|
dev_pm_opp_put_supported_hw(opp_token);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -1952,7 +1952,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_pm_opp_set_supported_hw() - Set supported platforms
|
* _opp_set_supported_hw() - Set supported platforms
|
||||||
* @dev: Device for which supported-hw has to be set.
|
* @dev: Device for which supported-hw has to be set.
|
||||||
* @versions: Array of hierarchy of versions to match.
|
* @versions: Array of hierarchy of versions to match.
|
||||||
* @count: Number of elements in the array.
|
* @count: Number of elements in the array.
|
||||||
@ -1962,85 +1962,40 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
|
|||||||
* OPPs, which are available for those versions, based on its 'opp-supported-hw'
|
* OPPs, which are available for those versions, based on its 'opp-supported-hw'
|
||||||
* property.
|
* property.
|
||||||
*/
|
*/
|
||||||
struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
|
static int _opp_set_supported_hw(struct opp_table *opp_table,
|
||||||
const u32 *versions, unsigned int count)
|
const u32 *versions, unsigned int count)
|
||||||
{
|
{
|
||||||
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->supported_hw)
|
if (opp_table->supported_hw)
|
||||||
return opp_table;
|
return 0;
|
||||||
|
|
||||||
opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
|
opp_table->supported_hw = kmemdup(versions, count * sizeof(*versions),
|
||||||
GFP_KERNEL);
|
GFP_KERNEL);
|
||||||
if (!opp_table->supported_hw) {
|
if (!opp_table->supported_hw)
|
||||||
dev_pm_opp_put_opp_table(opp_table);
|
return -ENOMEM;
|
||||||
return ERR_PTR(-ENOMEM);
|
|
||||||
}
|
|
||||||
|
|
||||||
opp_table->supported_hw_count = count;
|
opp_table->supported_hw_count = count;
|
||||||
|
|
||||||
return opp_table;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dev_pm_opp_set_supported_hw);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_pm_opp_put_supported_hw() - Releases resources blocked for supported hw
|
* _opp_put_supported_hw() - Releases resources blocked for supported hw
|
||||||
* @opp_table: OPP table returned by dev_pm_opp_set_supported_hw().
|
* @opp_table: OPP table returned by _opp_set_supported_hw().
|
||||||
*
|
*
|
||||||
* 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_supported_hw(). Until this is called, the opp_table structure
|
* _opp_set_supported_hw(). Until this is called, the opp_table structure
|
||||||
* will not be freed.
|
* will not be freed.
|
||||||
*/
|
*/
|
||||||
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table)
|
static void _opp_put_supported_hw(struct opp_table *opp_table)
|
||||||
{
|
{
|
||||||
if (unlikely(!opp_table))
|
if (opp_table->supported_hw) {
|
||||||
return;
|
|
||||||
|
|
||||||
kfree(opp_table->supported_hw);
|
kfree(opp_table->supported_hw);
|
||||||
opp_table->supported_hw = NULL;
|
opp_table->supported_hw = NULL;
|
||||||
opp_table->supported_hw_count = 0;
|
opp_table->supported_hw_count = 0;
|
||||||
|
|
||||||
dev_pm_opp_put_opp_table(opp_table);
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(dev_pm_opp_put_supported_hw);
|
|
||||||
|
|
||||||
static void devm_pm_opp_supported_hw_release(void *data)
|
|
||||||
{
|
|
||||||
dev_pm_opp_put_supported_hw(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* devm_pm_opp_set_supported_hw() - Set supported platforms
|
|
||||||
* @dev: Device for which supported-hw has to be set.
|
|
||||||
* @versions: Array of hierarchy of versions to match.
|
|
||||||
* @count: Number of elements in the array.
|
|
||||||
*
|
|
||||||
* This is a resource-managed variant of dev_pm_opp_set_supported_hw().
|
|
||||||
*
|
|
||||||
* Return: 0 on success and errorno otherwise.
|
|
||||||
*/
|
|
||||||
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions,
|
|
||||||
unsigned int count)
|
|
||||||
{
|
|
||||||
struct opp_table *opp_table;
|
|
||||||
|
|
||||||
opp_table = dev_pm_opp_set_supported_hw(dev, versions, count);
|
|
||||||
if (IS_ERR(opp_table))
|
|
||||||
return PTR_ERR(opp_table);
|
|
||||||
|
|
||||||
return devm_add_action_or_reset(dev, devm_pm_opp_supported_hw_release,
|
|
||||||
opp_table);
|
|
||||||
}
|
|
||||||
EXPORT_SYMBOL_GPL(devm_pm_opp_set_supported_hw);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* dev_pm_opp_set_prop_name() - Set prop-extn name
|
* dev_pm_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.
|
||||||
@ -2583,7 +2538,7 @@ static void _opp_clear_config(struct opp_config_data *data)
|
|||||||
if (data->flags & OPP_CONFIG_REGULATOR)
|
if (data->flags & OPP_CONFIG_REGULATOR)
|
||||||
_opp_put_regulators(data->opp_table);
|
_opp_put_regulators(data->opp_table);
|
||||||
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
|
if (data->flags & OPP_CONFIG_SUPPORTED_HW)
|
||||||
dev_pm_opp_put_supported_hw(data->opp_table);
|
_opp_put_supported_hw(data->opp_table);
|
||||||
if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
|
if (data->flags & OPP_CONFIG_REGULATOR_HELPER)
|
||||||
dev_pm_opp_unregister_set_opp_helper(data->opp_table);
|
dev_pm_opp_unregister_set_opp_helper(data->opp_table);
|
||||||
if (data->flags & OPP_CONFIG_PROP_NAME)
|
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)
|
|||||||
|
|
||||||
/* Configure supported hardware */
|
/* Configure supported hardware */
|
||||||
if (config->supported_hw) {
|
if (config->supported_hw) {
|
||||||
err = dev_pm_opp_set_supported_hw(dev, config->supported_hw,
|
ret = _opp_set_supported_hw(opp_table, config->supported_hw,
|
||||||
config->supported_hw_count);
|
config->supported_hw_count);
|
||||||
if (IS_ERR(err)) {
|
if (ret)
|
||||||
ret = PTR_ERR(err);
|
|
||||||
goto err;
|
goto err;
|
||||||
}
|
|
||||||
|
|
||||||
data->flags |= OPP_CONFIG_SUPPORTED_HW;
|
data->flags |= OPP_CONFIG_SUPPORTED_HW;
|
||||||
}
|
}
|
||||||
|
@ -184,9 +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_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
|
|
||||||
void dev_pm_opp_put_supported_hw(struct opp_table *opp_table);
|
|
||||||
int devm_pm_opp_set_supported_hw(struct device *dev, const u32 *versions, unsigned int count);
|
|
||||||
struct opp_table *dev_pm_opp_set_prop_name(struct device *dev, const char *name);
|
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);
|
void dev_pm_opp_put_prop_name(struct opp_table *opp_table);
|
||||||
struct opp_table *dev_pm_opp_set_clkname(struct device *dev, const char *name);
|
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
|
|||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline struct opp_table *dev_pm_opp_set_supported_hw(struct device *dev,
|
|
||||||
const u32 *versions,
|
|
||||||
unsigned int count)
|
|
||||||
{
|
|
||||||
return ERR_PTR(-EOPNOTSUPP);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void dev_pm_opp_put_supported_hw(struct opp_table *opp_table) {}
|
|
||||||
|
|
||||||
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
|
|
||||||
const u32 *versions,
|
|
||||||
unsigned int count)
|
|
||||||
{
|
|
||||||
return -EOPNOTSUPP;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
|
static inline struct opp_table *dev_pm_opp_register_set_opp_helper(struct device *dev,
|
||||||
int (*set_opp)(struct dev_pm_set_opp_data *data))
|
int (*set_opp)(struct dev_pm_set_opp_data *data))
|
||||||
{
|
{
|
||||||
@ -618,4 +599,34 @@ static inline int devm_pm_opp_set_regulators(struct device *dev,
|
|||||||
return devm_pm_opp_set_config(dev, &config);
|
return devm_pm_opp_set_config(dev, &config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Supported-hw helpers */
|
||||||
|
static inline int dev_pm_opp_set_supported_hw(struct device *dev,
|
||||||
|
const u32 *versions,
|
||||||
|
unsigned int count)
|
||||||
|
{
|
||||||
|
struct dev_pm_opp_config config = {
|
||||||
|
.supported_hw = versions,
|
||||||
|
.supported_hw_count = count,
|
||||||
|
};
|
||||||
|
|
||||||
|
return dev_pm_opp_set_config(dev, &config);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void dev_pm_opp_put_supported_hw(int token)
|
||||||
|
{
|
||||||
|
dev_pm_opp_clear_config(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline int devm_pm_opp_set_supported_hw(struct device *dev,
|
||||||
|
const u32 *versions,
|
||||||
|
unsigned int count)
|
||||||
|
{
|
||||||
|
struct dev_pm_opp_config config = {
|
||||||
|
.supported_hw = versions,
|
||||||
|
.supported_hw_count = count,
|
||||||
|
};
|
||||||
|
|
||||||
|
return devm_pm_opp_set_config(dev, &config);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* __LINUX_OPP_H__ */
|
#endif /* __LINUX_OPP_H__ */
|
||||||
|
Loading…
Reference in New Issue
Block a user