Commit 6baee034 authored by Viresh Kumar's avatar Viresh Kumar

OPP: ti: Migrate to dev_pm_opp_set_config_regulators()

The OPP core now provides dev_pm_opp_set_config_regulators() interface,
which needs the platforms to just set the OPP voltages instead of both
clk and voltage.  The clock is set by the OPP core instead and hence
reduces code redundancy.

Migrate the only user of the custom set_opp() to
dev_pm_opp_set_config_regulators().
Signed-off-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
parent 69b1af17
...@@ -36,11 +36,15 @@ struct ti_opp_supply_optimum_voltage_table { ...@@ -36,11 +36,15 @@ struct ti_opp_supply_optimum_voltage_table {
* @vdd_table: Optimized voltage mapping table * @vdd_table: Optimized voltage mapping table
* @num_vdd_table: number of entries in vdd_table * @num_vdd_table: number of entries in vdd_table
* @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply * @vdd_absolute_max_voltage_uv: absolute maximum voltage in UV for the supply
* @old_supplies: Placeholder for supplies information for old OPP.
* @new_supplies: Placeholder for supplies information for new OPP.
*/ */
struct ti_opp_supply_data { struct ti_opp_supply_data {
struct ti_opp_supply_optimum_voltage_table *vdd_table; struct ti_opp_supply_optimum_voltage_table *vdd_table;
u32 num_vdd_table; u32 num_vdd_table;
u32 vdd_absolute_max_voltage_uv; u32 vdd_absolute_max_voltage_uv;
struct dev_pm_opp_supply old_supplies[2];
struct dev_pm_opp_supply new_supplies[2];
}; };
static struct ti_opp_supply_data opp_data; static struct ti_opp_supply_data opp_data;
...@@ -266,27 +270,32 @@ static int _opp_set_voltage(struct device *dev, ...@@ -266,27 +270,32 @@ static int _opp_set_voltage(struct device *dev,
return 0; return 0;
} }
/** /* Do the opp supply transition */
* ti_opp_supply_set_opp() - do the opp supply transition static int ti_opp_config_regulators(struct device *dev,
* @data: information on regulators and new and old opps provided by struct dev_pm_opp *old_opp, struct dev_pm_opp *new_opp,
* opp core to use in transition struct regulator **regulators, unsigned int count)
*
* Return: If successful, 0, else appropriate error value.
*/
static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data)
{ {
struct dev_pm_opp_supply *old_supply_vdd = &data->old_opp.supplies[0]; struct dev_pm_opp_supply *old_supply_vdd = &opp_data.old_supplies[0];
struct dev_pm_opp_supply *old_supply_vbb = &data->old_opp.supplies[1]; struct dev_pm_opp_supply *old_supply_vbb = &opp_data.old_supplies[1];
struct dev_pm_opp_supply *new_supply_vdd = &data->new_opp.supplies[0]; struct dev_pm_opp_supply *new_supply_vdd = &opp_data.new_supplies[0];
struct dev_pm_opp_supply *new_supply_vbb = &data->new_opp.supplies[1]; struct dev_pm_opp_supply *new_supply_vbb = &opp_data.new_supplies[1];
struct device *dev = data->dev; struct regulator *vdd_reg = regulators[0];
unsigned long old_freq = data->old_opp.rate, freq = data->new_opp.rate; struct regulator *vbb_reg = regulators[1];
struct clk *clk = data->clk; unsigned long old_freq, freq;
struct regulator *vdd_reg = data->regulators[0];
struct regulator *vbb_reg = data->regulators[1];
int vdd_uv; int vdd_uv;
int ret; int ret;
/* We must have two regulators here */
WARN_ON(count != 2);
/* Fetch supplies and freq information from OPP core */
ret = dev_pm_opp_get_supplies(new_opp, opp_data.new_supplies);
WARN_ON(ret);
old_freq = dev_pm_opp_get_freq(old_opp);
freq = dev_pm_opp_get_freq(new_opp);
WARN_ON(!old_freq || !freq);
vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data, vdd_uv = _get_optimal_vdd_voltage(dev, &opp_data,
new_supply_vdd->u_volt); new_supply_vdd->u_volt);
...@@ -303,39 +312,24 @@ static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data) ...@@ -303,39 +312,24 @@ static int ti_opp_supply_set_opp(struct dev_pm_set_opp_data *data)
ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
if (ret) if (ret)
goto restore_voltage; goto restore_voltage;
} } else {
/* Change frequency */
dev_dbg(dev, "%s: switching OPP: %lu Hz --> %lu Hz\n",
__func__, old_freq, freq);
ret = clk_set_rate(clk, freq);
if (ret) {
dev_err(dev, "%s: failed to set clock rate: %d\n", __func__,
ret);
goto restore_voltage;
}
/* Scaling down? Scale voltage after frequency */
if (freq < old_freq) {
ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb"); ret = _opp_set_voltage(dev, new_supply_vbb, 0, vbb_reg, "vbb");
if (ret) if (ret)
goto restore_freq; goto restore_voltage;
ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg, ret = _opp_set_voltage(dev, new_supply_vdd, vdd_uv, vdd_reg,
"vdd"); "vdd");
if (ret) if (ret)
goto restore_freq; goto restore_voltage;
} }
return 0; return 0;
restore_freq:
ret = clk_set_rate(clk, old_freq);
if (ret)
dev_err(dev, "%s: failed to restore old-freq (%lu Hz)\n",
__func__, old_freq);
restore_voltage: restore_voltage:
/* Fetch old supplies information only if required */
ret = dev_pm_opp_get_supplies(old_opp, opp_data.old_supplies);
WARN_ON(ret);
/* This shouldn't harm even if the voltages weren't updated earlier */ /* This shouldn't harm even if the voltages weren't updated earlier */
if (old_supply_vdd->u_volt) { if (old_supply_vdd->u_volt) {
ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb"); ret = _opp_set_voltage(dev, old_supply_vbb, 0, vbb_reg, "vbb");
...@@ -405,8 +399,7 @@ static int ti_opp_supply_probe(struct platform_device *pdev) ...@@ -405,8 +399,7 @@ static int ti_opp_supply_probe(struct platform_device *pdev)
return ret; return ret;
} }
ret = dev_pm_opp_register_set_opp_helper(cpu_dev, ret = dev_pm_opp_set_config_regulators(cpu_dev, ti_opp_config_regulators);
ti_opp_supply_set_opp);
if (ret < 0) if (ret < 0)
_free_optimized_voltages(dev, &opp_data); _free_optimized_voltages(dev, &opp_data);
......
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