提交 7061873f 编写于 作者: A Axel Lin 提交者: Mark Brown

regulator: Convert tps65023 to set_voltage_sel

This patch also changes the define for TPS65023_LDO_CTRL_LDOx_MASK,
because regmap_update_bits actually does:
        (orig & ~mask) | (val & mask)
This change makes the code consists for all regmap_update_bits calls.

Also removes some uninformative comments.
Signed-off-by: NAxel Lin <axel.lin@gmail.com>
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
上级 4533f80e
...@@ -72,7 +72,7 @@ ...@@ -72,7 +72,7 @@
/* LDO_CTRL bitfields */ /* LDO_CTRL bitfields */
#define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4)
#define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0xF0 >> ((ldo_id)*4)) #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0x0F << ((ldo_id)*4))
/* Number of step-down converters available */ /* Number of step-down converters available */
#define TPS65023_NUM_DCDC 3 #define TPS65023_NUM_DCDC 3
...@@ -261,50 +261,28 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) ...@@ -261,50 +261,28 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
return tps->info[dcdc]->min_uV; return tps->info[dcdc]->min_uV;
} }
static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned selector)
unsigned *selector)
{ {
struct tps_pmic *tps = rdev_get_drvdata(dev); struct tps_pmic *tps = rdev_get_drvdata(dev);
int dcdc = rdev_get_id(dev); int dcdc = rdev_get_id(dev);
int vsel;
int ret; int ret;
if (dcdc != tps->core_regulator) if (dcdc != tps->core_regulator)
return -EINVAL; return -EINVAL;
if (min_uV < tps->info[dcdc]->min_uV
|| min_uV > tps->info[dcdc]->max_uV)
return -EINVAL;
if (max_uV < tps->info[dcdc]->min_uV
|| max_uV > tps->info[dcdc]->max_uV)
return -EINVAL;
for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, selector);
int mV = tps->info[dcdc]->table[vsel]; if (ret)
int uV = mV * 1000; goto out;
/* Break at the first in-range value */
if (min_uV <= uV && uV <= max_uV)
break;
}
*selector = vsel;
if (vsel == tps->info[dcdc]->table_len)
goto failed;
ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, vsel);
/* Tell the chip that we have changed the value in DEFCORE /* Tell the chip that we have changed the value in DEFCORE
* and its time to update the core voltage * and its time to update the core voltage
*/ */
regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, ret = regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO); TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO);
out:
return ret; return ret;
failed:
return -EINVAL;
} }
static int tps65023_ldo_get_voltage(struct regulator_dev *dev) static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
...@@ -325,42 +303,15 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev) ...@@ -325,42 +303,15 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
return tps->info[ldo]->table[data] * 1000; return tps->info[ldo]->table[data] * 1000;
} }
static int tps65023_ldo_set_voltage(struct regulator_dev *dev, static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned *selector) unsigned selector)
{ {
struct tps_pmic *tps = rdev_get_drvdata(dev); struct tps_pmic *tps = rdev_get_drvdata(dev);
int data, vsel, ldo = rdev_get_id(dev); int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1;
int ret;
if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL,
return -EINVAL; TPS65023_LDO_CTRL_LDOx_MASK(ldo_index),
selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index));
if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV)
return -EINVAL;
if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV)
return -EINVAL;
for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) {
int mV = tps->info[ldo]->table[vsel];
int uV = mV * 1000;
/* Break at the first in-range value */
if (min_uV <= uV && uV <= max_uV)
break;
}
if (vsel == tps->info[ldo]->table_len)
return -EINVAL;
*selector = vsel;
ret = regmap_read(tps->regmap, TPS65023_REG_LDO_CTRL, &data);
if (ret != 0)
return ret;
data &= TPS65023_LDO_CTRL_LDOx_MASK(ldo - TPS65023_LDO_1);
data |= (vsel << (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)));
return regmap_write(tps->regmap, TPS65023_REG_LDO_CTRL, data);
} }
static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, static int tps65023_dcdc_list_voltage(struct regulator_dev *dev,
...@@ -402,7 +353,7 @@ static struct regulator_ops tps65023_dcdc_ops = { ...@@ -402,7 +353,7 @@ static struct regulator_ops tps65023_dcdc_ops = {
.enable = tps65023_dcdc_enable, .enable = tps65023_dcdc_enable,
.disable = tps65023_dcdc_disable, .disable = tps65023_dcdc_disable,
.get_voltage = tps65023_dcdc_get_voltage, .get_voltage = tps65023_dcdc_get_voltage,
.set_voltage = tps65023_dcdc_set_voltage, .set_voltage_sel = tps65023_dcdc_set_voltage_sel,
.list_voltage = tps65023_dcdc_list_voltage, .list_voltage = tps65023_dcdc_list_voltage,
}; };
...@@ -412,7 +363,7 @@ static struct regulator_ops tps65023_ldo_ops = { ...@@ -412,7 +363,7 @@ static struct regulator_ops tps65023_ldo_ops = {
.enable = tps65023_ldo_enable, .enable = tps65023_ldo_enable,
.disable = tps65023_ldo_disable, .disable = tps65023_ldo_disable,
.get_voltage = tps65023_ldo_get_voltage, .get_voltage = tps65023_ldo_get_voltage,
.set_voltage = tps65023_ldo_set_voltage, .set_voltage_sel = tps65023_ldo_set_voltage_sel,
.list_voltage = tps65023_ldo_list_voltage, .list_voltage = tps65023_ldo_list_voltage,
}; };
...@@ -503,12 +454,6 @@ static int __devinit tps_65023_probe(struct i2c_client *client, ...@@ -503,12 +454,6 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
return error; return error;
} }
/**
* tps_65023_remove - TPS65023 driver i2c remove handler
* @client: i2c driver client device structure
*
* Unregister TPS driver as an i2c client device driver
*/
static int __devexit tps_65023_remove(struct i2c_client *client) static int __devexit tps_65023_remove(struct i2c_client *client)
{ {
struct tps_pmic *tps = i2c_get_clientdata(client); struct tps_pmic *tps = i2c_get_clientdata(client);
...@@ -669,22 +614,12 @@ static struct i2c_driver tps_65023_i2c_driver = { ...@@ -669,22 +614,12 @@ static struct i2c_driver tps_65023_i2c_driver = {
.id_table = tps_65023_id, .id_table = tps_65023_id,
}; };
/**
* tps_65023_init
*
* Module init function
*/
static int __init tps_65023_init(void) static int __init tps_65023_init(void)
{ {
return i2c_add_driver(&tps_65023_i2c_driver); return i2c_add_driver(&tps_65023_i2c_driver);
} }
subsys_initcall(tps_65023_init); subsys_initcall(tps_65023_init);
/**
* tps_65023_cleanup
*
* Module exit function
*/
static void __exit tps_65023_cleanup(void) static void __exit tps_65023_cleanup(void)
{ {
i2c_del_driver(&tps_65023_i2c_driver); i2c_del_driver(&tps_65023_i2c_driver);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册