regulator: max1586: Implement get_voltage_sel callback
This is required since commit f7df20ec32
"regulator: core: Use list_voltage() to read single voltage regulators",
otherwise _regulator_get_voltage returns rdev->desc->ops->list_voltage(rdev, 0).
The Maxim 1586 controls V3 and V6 voltages, but offers no way of reading back
the set up value. Thus this patch caches the setting when setting new voltage.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
parent
9489e9dcae
commit
4efd9dfecb
|
@ -44,6 +44,9 @@ struct max1586_data {
|
||||||
unsigned int min_uV;
|
unsigned int min_uV;
|
||||||
unsigned int max_uV;
|
unsigned int max_uV;
|
||||||
|
|
||||||
|
unsigned int v3_curr_sel;
|
||||||
|
unsigned int v6_curr_sel;
|
||||||
|
|
||||||
struct regulator_dev *rdev[0];
|
struct regulator_dev *rdev[0];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -63,31 +66,60 @@ static int v6_voltages_uv[] = { 1, 1800000, 2500000, 3000000 };
|
||||||
* R24 and R25=100kOhm as described in the data sheet.
|
* R24 and R25=100kOhm as described in the data sheet.
|
||||||
* The gain is approximately: 1 + R24/R25 + R24/185.5kOhm
|
* The gain is approximately: 1 + R24/R25 + R24/185.5kOhm
|
||||||
*/
|
*/
|
||||||
|
static int max1586_v3_get_voltage_sel(struct regulator_dev *rdev)
|
||||||
|
{
|
||||||
|
struct max1586_data *max1586 = rdev_get_drvdata(rdev);
|
||||||
|
|
||||||
|
return max1586->v3_curr_sel;
|
||||||
|
}
|
||||||
|
|
||||||
static int max1586_v3_set_voltage_sel(struct regulator_dev *rdev,
|
static int max1586_v3_set_voltage_sel(struct regulator_dev *rdev,
|
||||||
unsigned selector)
|
unsigned selector)
|
||||||
{
|
{
|
||||||
struct max1586_data *max1586 = rdev_get_drvdata(rdev);
|
struct max1586_data *max1586 = rdev_get_drvdata(rdev);
|
||||||
struct i2c_client *client = max1586->client;
|
struct i2c_client *client = max1586->client;
|
||||||
|
int ret;
|
||||||
u8 v3_prog;
|
u8 v3_prog;
|
||||||
|
|
||||||
dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
|
dev_dbg(&client->dev, "changing voltage v3 to %dmv\n",
|
||||||
regulator_list_voltage_linear(rdev, selector) / 1000);
|
regulator_list_voltage_linear(rdev, selector) / 1000);
|
||||||
|
|
||||||
v3_prog = I2C_V3_SELECT | (u8) selector;
|
v3_prog = I2C_V3_SELECT | (u8) selector;
|
||||||
return i2c_smbus_write_byte(client, v3_prog);
|
ret = i2c_smbus_write_byte(client, v3_prog);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
max1586->v3_curr_sel = selector;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int max1586_v6_get_voltage_sel(struct regulator_dev *rdev)
|
||||||
|
{
|
||||||
|
struct max1586_data *max1586 = rdev_get_drvdata(rdev);
|
||||||
|
|
||||||
|
return max1586->v6_curr_sel;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev,
|
static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev,
|
||||||
unsigned int selector)
|
unsigned int selector)
|
||||||
{
|
{
|
||||||
struct i2c_client *client = rdev_get_drvdata(rdev);
|
struct max1586_data *max1586 = rdev_get_drvdata(rdev);
|
||||||
|
struct i2c_client *client = max1586->client;
|
||||||
u8 v6_prog;
|
u8 v6_prog;
|
||||||
|
int ret;
|
||||||
|
|
||||||
dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
|
dev_dbg(&client->dev, "changing voltage v6 to %dmv\n",
|
||||||
rdev->desc->volt_table[selector] / 1000);
|
rdev->desc->volt_table[selector] / 1000);
|
||||||
|
|
||||||
v6_prog = I2C_V6_SELECT | (u8) selector;
|
v6_prog = I2C_V6_SELECT | (u8) selector;
|
||||||
return i2c_smbus_write_byte(client, v6_prog);
|
ret = i2c_smbus_write_byte(client, v6_prog);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
max1586->v6_curr_sel = selector;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -95,12 +127,14 @@ static int max1586_v6_set_voltage_sel(struct regulator_dev *rdev,
|
||||||
* the set up value.
|
* the set up value.
|
||||||
*/
|
*/
|
||||||
static struct regulator_ops max1586_v3_ops = {
|
static struct regulator_ops max1586_v3_ops = {
|
||||||
|
.get_voltage_sel = max1586_v3_get_voltage_sel,
|
||||||
.set_voltage_sel = max1586_v3_set_voltage_sel,
|
.set_voltage_sel = max1586_v3_set_voltage_sel,
|
||||||
.list_voltage = regulator_list_voltage_linear,
|
.list_voltage = regulator_list_voltage_linear,
|
||||||
.map_voltage = regulator_map_voltage_linear,
|
.map_voltage = regulator_map_voltage_linear,
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct regulator_ops max1586_v6_ops = {
|
static struct regulator_ops max1586_v6_ops = {
|
||||||
|
.get_voltage_sel = max1586_v6_get_voltage_sel,
|
||||||
.set_voltage_sel = max1586_v6_set_voltage_sel,
|
.set_voltage_sel = max1586_v6_set_voltage_sel,
|
||||||
.list_voltage = regulator_list_voltage_table,
|
.list_voltage = regulator_list_voltage_table,
|
||||||
};
|
};
|
||||||
|
@ -148,6 +182,10 @@ static int __devinit max1586_pmic_probe(struct i2c_client *client,
|
||||||
max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000;
|
max1586->min_uV = MAX1586_V3_MIN_UV / 1000 * pdata->v3_gain / 1000;
|
||||||
max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000;
|
max1586->max_uV = MAX1586_V3_MAX_UV / 1000 * pdata->v3_gain / 1000;
|
||||||
|
|
||||||
|
/* Set curr_sel to default voltage on power-up */
|
||||||
|
max1586->v3_curr_sel = 24; /* 1.3V */
|
||||||
|
max1586->v6_curr_sel = 0;
|
||||||
|
|
||||||
rdev = max1586->rdev;
|
rdev = max1586->rdev;
|
||||||
for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) {
|
for (i = 0; i < pdata->num_subdevs && i <= MAX1586_V6; i++) {
|
||||||
id = pdata->subdevs[i].id;
|
id = pdata->subdevs[i].id;
|
||||||
|
|
Loading…
Reference in New Issue