Skip to content

Commit 248a38d

Browse files
storulfvireshk
authored andcommitted
OPP: Add dev_pm_opp_add_dynamic() to allow more flexibility
The dev_pm_opp_add() API is limited to add dynamic OPPs with a frequency and a voltage level. To enable more flexibility, let's add a new API, dev_pm_opp_add_dynamic() that's takes a struct dev_pm_opp_data* instead of a list of in-parameters. Signed-off-by: Ulf Hansson <[email protected]> Signed-off-by: Viresh Kumar <[email protected]>
1 parent 401e092 commit 248a38d

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed

drivers/opp/core.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,8 +2002,7 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
20022002
* _opp_add_v1() - Allocate a OPP based on v1 bindings.
20032003
* @opp_table: OPP table
20042004
* @dev: device for which we do this operation
2005-
* @freq: Frequency in Hz for this OPP
2006-
* @u_volt: Voltage in uVolts for this OPP
2005+
* @data: The OPP data for the OPP to add
20072006
* @dynamic: Dynamically added OPPs.
20082007
*
20092008
* This function adds an opp definition to the opp table and returns status.
@@ -2021,10 +2020,10 @@ int _opp_add(struct device *dev, struct dev_pm_opp *new_opp,
20212020
* -ENOMEM Memory allocation failure
20222021
*/
20232022
int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
2024-
unsigned long freq, long u_volt, bool dynamic)
2023+
struct dev_pm_opp_data *data, bool dynamic)
20252024
{
20262025
struct dev_pm_opp *new_opp;
2027-
unsigned long tol;
2026+
unsigned long tol, u_volt = data->u_volt;
20282027
int ret;
20292028

20302029
if (!assert_single_clk(opp_table))
@@ -2035,7 +2034,7 @@ int _opp_add_v1(struct opp_table *opp_table, struct device *dev,
20352034
return -ENOMEM;
20362035

20372036
/* populate the opp table */
2038-
new_opp->rates[0] = freq;
2037+
new_opp->rates[0] = data->freq;
20392038
tol = u_volt * opp_table->voltage_tolerance_v1 / 100;
20402039
new_opp->supplies[0].u_volt = u_volt;
20412040
new_opp->supplies[0].u_volt_min = u_volt - tol;
@@ -2825,10 +2824,9 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table,
28252824
}
28262825

28272826
/**
2828-
* dev_pm_opp_add() - Add an OPP table from a table definitions
2829-
* @dev: device for which we do this operation
2830-
* @freq: Frequency in Hz for this OPP
2831-
* @u_volt: Voltage in uVolts for this OPP
2827+
* dev_pm_opp_add_dynamic() - Add an OPP table from a table definitions
2828+
* @dev: The device for which we do this operation
2829+
* @data: The OPP data for the OPP to add
28322830
*
28332831
* This function adds an opp definition to the opp table and returns status.
28342832
* The opp is made available by default and it can be controlled using
@@ -2841,7 +2839,7 @@ int dev_pm_opp_xlate_performance_state(struct opp_table *src_table,
28412839
* Duplicate OPPs (both freq and volt are same) and !opp->available
28422840
* -ENOMEM Memory allocation failure
28432841
*/
2844-
int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
2842+
int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *data)
28452843
{
28462844
struct opp_table *opp_table;
28472845
int ret;
@@ -2853,13 +2851,13 @@ int dev_pm_opp_add(struct device *dev, unsigned long freq, unsigned long u_volt)
28532851
/* Fix regulator count for dynamic OPPs */
28542852
opp_table->regulator_count = 1;
28552853

2856-
ret = _opp_add_v1(opp_table, dev, freq, u_volt, true);
2854+
ret = _opp_add_v1(opp_table, dev, data, true);
28572855
if (ret)
28582856
dev_pm_opp_put_opp_table(opp_table);
28592857

28602858
return ret;
28612859
}
2862-
EXPORT_SYMBOL_GPL(dev_pm_opp_add);
2860+
EXPORT_SYMBOL_GPL(dev_pm_opp_add_dynamic);
28632861

28642862
/**
28652863
* _opp_set_availability() - helper to set the availability of an opp

drivers/opp/of.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,13 +1077,15 @@ static int _of_add_opp_table_v1(struct device *dev, struct opp_table *opp_table)
10771077

10781078
val = prop->value;
10791079
while (nr) {
1080-
unsigned long freq = be32_to_cpup(val++) * 1000;
1081-
unsigned long volt = be32_to_cpup(val++);
1080+
struct dev_pm_opp_data data = {
1081+
.freq = be32_to_cpup(val++) * 1000,
1082+
.u_volt = be32_to_cpup(val++),
1083+
};
10821084

1083-
ret = _opp_add_v1(opp_table, dev, freq, volt, false);
1085+
ret = _opp_add_v1(opp_table, dev, &data, false);
10841086
if (ret) {
10851087
dev_err(dev, "%s: Failed to add OPP %ld (%d)\n",
1086-
__func__, freq, ret);
1088+
__func__, data.freq, ret);
10871089
goto remove_static_opp;
10881090
}
10891091
nr -= 2;

drivers/opp/opp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ struct dev_pm_opp *_opp_allocate(struct opp_table *opp_table);
251251
void _opp_free(struct dev_pm_opp *opp);
252252
int _opp_compare_key(struct opp_table *opp_table, struct dev_pm_opp *opp1, struct dev_pm_opp *opp2);
253253
int _opp_add(struct device *dev, struct dev_pm_opp *new_opp, struct opp_table *opp_table);
254-
int _opp_add_v1(struct opp_table *opp_table, struct device *dev, unsigned long freq, long u_volt, bool dynamic);
254+
int _opp_add_v1(struct opp_table *opp_table, struct device *dev, struct dev_pm_opp_data *data, bool dynamic);
255255
void _dev_pm_opp_cpumask_remove_table(const struct cpumask *cpumask, int last_cpu);
256256
struct opp_table *_add_opp_table_indexed(struct device *dev, int index, bool getclk);
257257
void _put_opp_list_kref(struct opp_table *opp_table);

include/linux/pm_opp.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@ struct dev_pm_opp_config {
9292
struct device ***virt_devs;
9393
};
9494

95+
/**
96+
* struct dev_pm_opp_data - The data to use to initialize an OPP.
97+
* @freq: The clock rate in Hz for the OPP.
98+
* @u_volt: The voltage in uV for the OPP.
99+
*/
100+
struct dev_pm_opp_data {
101+
unsigned long freq;
102+
unsigned long u_volt;
103+
};
104+
95105
#if defined(CONFIG_PM_OPP)
96106

97107
struct opp_table *dev_pm_opp_get_opp_table(struct device *dev);
@@ -152,8 +162,8 @@ struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
152162

153163
void dev_pm_opp_put(struct dev_pm_opp *opp);
154164

155-
int dev_pm_opp_add(struct device *dev, unsigned long freq,
156-
unsigned long u_volt);
165+
int dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp);
166+
157167
void dev_pm_opp_remove(struct device *dev, unsigned long freq);
158168
void dev_pm_opp_remove_all_dynamic(struct device *dev);
159169

@@ -322,8 +332,8 @@ static inline struct dev_pm_opp *dev_pm_opp_find_bw_floor(struct device *dev,
322332

323333
static inline void dev_pm_opp_put(struct dev_pm_opp *opp) {}
324334

325-
static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
326-
unsigned long u_volt)
335+
static inline int
336+
dev_pm_opp_add_dynamic(struct device *dev, struct dev_pm_opp_data *opp)
327337
{
328338
return -EOPNOTSUPP;
329339
}
@@ -519,6 +529,17 @@ static inline int dev_pm_opp_of_find_icc_paths(struct device *dev, struct opp_ta
519529

520530
/* OPP Configuration helpers */
521531

532+
static inline int dev_pm_opp_add(struct device *dev, unsigned long freq,
533+
unsigned long u_volt)
534+
{
535+
struct dev_pm_opp_data data = {
536+
.freq = freq,
537+
.u_volt = u_volt,
538+
};
539+
540+
return dev_pm_opp_add_dynamic(dev, &data);
541+
}
542+
522543
/* Regulators helpers */
523544
static inline int dev_pm_opp_set_regulators(struct device *dev,
524545
const char * const names[])

0 commit comments

Comments
 (0)