Skip to content

Commit

Permalink
opp: Add dev_pm_opp_sync_regulators()
Browse files Browse the repository at this point in the history
Extend OPP API with dev_pm_opp_sync_regulators() function, which syncs
voltage state of regulators.

Tested-by: Peter Geis <[email protected]>
Tested-by: Nicolas Chauvet <[email protected]>
Tested-by: Matt Merhar <[email protected]>
Signed-off-by: Dmitry Osipenko <[email protected]>
[ Viresh: Added unlikely() ]
Signed-off-by: Viresh Kumar <[email protected]>
  • Loading branch information
digetx authored and vireshk committed Feb 2, 2021
1 parent 597ff54 commit ce8073d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
41 changes: 41 additions & 0 deletions drivers/opp/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2584,3 +2584,44 @@ void dev_pm_opp_remove_table(struct device *dev)
dev_pm_opp_put_opp_table(opp_table);
}
EXPORT_SYMBOL_GPL(dev_pm_opp_remove_table);

/**
* dev_pm_opp_sync_regulators() - Sync state of voltage regulators
* @dev: device for which we do this operation
*
* Sync voltage state of the OPP table regulators.
*
* Return: 0 on success or a negative error value.
*/
int dev_pm_opp_sync_regulators(struct device *dev)
{
struct opp_table *opp_table;
struct regulator *reg;
int i, ret = 0;

/* Device may not have OPP table */
opp_table = _find_opp_table(dev);
if (IS_ERR(opp_table))
return 0;

/* Regulator may not be required for the device */
if (unlikely(!opp_table->regulators))
goto put_table;

/* Nothing to sync if voltage wasn't changed */
if (!opp_table->enabled)
goto put_table;

for (i = 0; i < opp_table->regulator_count; i++) {
reg = opp_table->regulators[i];
ret = regulator_sync_voltage(reg);
if (ret)
break;
}
put_table:
/* Drop reference taken by _find_opp_table() */
dev_pm_opp_put_opp_table(opp_table);

return ret;
}
EXPORT_SYMBOL_GPL(dev_pm_opp_sync_regulators);
6 changes: 6 additions & 0 deletions include/linux/pm_opp.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ int dev_pm_opp_set_sharing_cpus(struct device *cpu_dev, const struct cpumask *cp
int dev_pm_opp_get_sharing_cpus(struct device *cpu_dev, struct cpumask *cpumask);
void dev_pm_opp_remove_table(struct device *dev);
void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask);
int dev_pm_opp_sync_regulators(struct device *dev);
#else
static inline struct opp_table *dev_pm_opp_get_opp_table(struct device *dev)
{
Expand Down Expand Up @@ -384,6 +385,11 @@ static inline void dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask
{
}

static inline int dev_pm_opp_sync_regulators(struct device *dev)
{
return -ENOTSUPP;
}

#endif /* CONFIG_PM_OPP */

#if defined(CONFIG_PM_OPP) && defined(CONFIG_OF)
Expand Down

0 comments on commit ce8073d

Please sign in to comment.