Skip to content

Commit 477f842

Browse files
committed
Merge tag 'opp-5.4-support-adjust-voltages' of https://git.kernel.org/pub/scm/linux/kernel/git/vireshk/pm into next/drivers
2 parents e386b22 + 771fdcf commit 477f842

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

‎drivers/opp/core.c‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,6 +2112,75 @@ static int _opp_set_availability(struct device *dev, unsigned long freq,
21122112
return r;
21132113
}
21142114

2115+
/**
2116+
* dev_pm_opp_adjust_voltage() - helper to change the voltage of an OPP
2117+
* @dev: device for which we do this operation
2118+
* @freq: OPP frequency to adjust voltage of
2119+
* @u_volt: new OPP target voltage
2120+
* @u_volt_min: new OPP min voltage
2121+
* @u_volt_max: new OPP max voltage
2122+
*
2123+
* Return: -EINVAL for bad pointers, -ENOMEM if no memory available for the
2124+
* copy operation, returns 0 if no modifcation was done OR modification was
2125+
* successful.
2126+
*/
2127+
int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
2128+
unsigned long u_volt, unsigned long u_volt_min,
2129+
unsigned long u_volt_max)
2130+
2131+
{
2132+
struct opp_table *opp_table;
2133+
struct dev_pm_opp *tmp_opp, *opp = ERR_PTR(-ENODEV);
2134+
int r = 0;
2135+
2136+
/* Find the opp_table */
2137+
opp_table = _find_opp_table(dev);
2138+
if (IS_ERR(opp_table)) {
2139+
r = PTR_ERR(opp_table);
2140+
dev_warn(dev, "%s: Device OPP not found (%d)\n", __func__, r);
2141+
return r;
2142+
}
2143+
2144+
mutex_lock(&opp_table->lock);
2145+
2146+
/* Do we have the frequency? */
2147+
list_for_each_entry(tmp_opp, &opp_table->opp_list, node) {
2148+
if (tmp_opp->rate == freq) {
2149+
opp = tmp_opp;
2150+
break;
2151+
}
2152+
}
2153+
2154+
if (IS_ERR(opp)) {
2155+
r = PTR_ERR(opp);
2156+
goto adjust_unlock;
2157+
}
2158+
2159+
/* Is update really needed? */
2160+
if (opp->supplies->u_volt == u_volt)
2161+
goto adjust_unlock;
2162+
2163+
opp->supplies->u_volt = u_volt;
2164+
opp->supplies->u_volt_min = u_volt_min;
2165+
opp->supplies->u_volt_max = u_volt_max;
2166+
2167+
dev_pm_opp_get(opp);
2168+
mutex_unlock(&opp_table->lock);
2169+
2170+
/* Notify the voltage change of the OPP */
2171+
blocking_notifier_call_chain(&opp_table->head, OPP_EVENT_ADJUST_VOLTAGE,
2172+
opp);
2173+
2174+
dev_pm_opp_put(opp);
2175+
goto adjust_put_table;
2176+
2177+
adjust_unlock:
2178+
mutex_unlock(&opp_table->lock);
2179+
adjust_put_table:
2180+
dev_pm_opp_put_opp_table(opp_table);
2181+
return r;
2182+
}
2183+
21152184
/**
21162185
* dev_pm_opp_enable() - Enable a specific OPP
21172186
* @dev: device for which we do this operation

‎include/linux/pm_opp.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ struct opp_table;
2222

2323
enum dev_pm_opp_event {
2424
OPP_EVENT_ADD, OPP_EVENT_REMOVE, OPP_EVENT_ENABLE, OPP_EVENT_DISABLE,
25+
OPP_EVENT_ADJUST_VOLTAGE,
2526
};
2627

2728
/**
@@ -113,6 +114,10 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq,
113114
void dev_pm_opp_remove(struct device *dev, unsigned long freq);
114115
void dev_pm_opp_remove_all_dynamic(struct device *dev);
115116

117+
int dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
118+
unsigned long u_volt, unsigned long u_volt_min,
119+
unsigned long u_volt_max);
120+
116121
int dev_pm_opp_enable(struct device *dev, unsigned long freq);
117122

118123
int dev_pm_opp_disable(struct device *dev, unsigned long freq);
@@ -242,6 +247,14 @@ static inline void dev_pm_opp_remove_all_dynamic(struct device *dev)
242247
{
243248
}
244249

250+
static inline int
251+
dev_pm_opp_adjust_voltage(struct device *dev, unsigned long freq,
252+
unsigned long u_volt, unsigned long u_volt_min,
253+
unsigned long u_volt_max)
254+
{
255+
return 0;
256+
}
257+
245258
static inline int dev_pm_opp_enable(struct device *dev, unsigned long freq)
246259
{
247260
return 0;

0 commit comments

Comments
 (0)