Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 302127
b: refs/heads/master
c: 7061873
h: refs/heads/master
i:
  302125: b935032
  302123: 7abdc15
  302119: b2d3f79
  302111: 8ca496a
v: v3
  • Loading branch information
Axel Lin authored and Mark Brown committed Apr 1, 2012
1 parent e81e4ef commit c2cddf6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 87 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 4533f80ef8da866564a29578a1a8b037c51c6fc6
refs/heads/master: 7061873f709bcecc8e079395567e2c314d21f7aa
107 changes: 21 additions & 86 deletions trunk/drivers/regulator/tps65023-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@

/* LDO_CTRL bitfields */
#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 */
#define TPS65023_NUM_DCDC 3
Expand Down Expand Up @@ -261,50 +261,28 @@ static int tps65023_dcdc_get_voltage(struct regulator_dev *dev)
return tps->info[dcdc]->min_uV;
}

static int tps65023_dcdc_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV,
unsigned *selector)
static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
unsigned selector)
{
struct tps_pmic *tps = rdev_get_drvdata(dev);
int dcdc = rdev_get_id(dev);
int vsel;
int ret;

if (dcdc != tps->core_regulator)
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++) {
int mV = tps->info[dcdc]->table[vsel];
int uV = mV * 1000;

/* 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);
ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, selector);
if (ret)
goto out;

/* Tell the chip that we have changed the value in DEFCORE
* and its time to update the core voltage
*/
regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO);
ret = regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO);

out:
return ret;

failed:
return -EINVAL;
}

static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
Expand All @@ -325,42 +303,15 @@ static int tps65023_ldo_get_voltage(struct regulator_dev *dev)
return tps->info[ldo]->table[data] * 1000;
}

static int tps65023_ldo_set_voltage(struct regulator_dev *dev,
int min_uV, int max_uV, unsigned *selector)
static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev,
unsigned selector)
{
struct tps_pmic *tps = rdev_get_drvdata(dev);
int data, vsel, ldo = rdev_get_id(dev);
int ret;

if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2)
return -EINVAL;

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;
int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1;

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);
return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL,
TPS65023_LDO_CTRL_LDOx_MASK(ldo_index),
selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index));
}

static int tps65023_dcdc_list_voltage(struct regulator_dev *dev,
Expand Down Expand Up @@ -402,7 +353,7 @@ static struct regulator_ops tps65023_dcdc_ops = {
.enable = tps65023_dcdc_enable,
.disable = tps65023_dcdc_disable,
.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,
};

Expand All @@ -412,7 +363,7 @@ static struct regulator_ops tps65023_ldo_ops = {
.enable = tps65023_ldo_enable,
.disable = tps65023_ldo_disable,
.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,
};

Expand Down Expand Up @@ -503,12 +454,6 @@ static int __devinit tps_65023_probe(struct i2c_client *client,
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)
{
struct tps_pmic *tps = i2c_get_clientdata(client);
Expand Down Expand Up @@ -638,13 +583,13 @@ static struct tps_driver_data tps65020_drv_data = {
};

static struct tps_driver_data tps65021_drv_data = {
.info = tps65021_regs,
.core_regulator = TPS65023_DCDC_3,
.info = tps65021_regs,
.core_regulator = TPS65023_DCDC_3,
};

static struct tps_driver_data tps65023_drv_data = {
.info = tps65023_regs,
.core_regulator = TPS65023_DCDC_1,
.info = tps65023_regs,
.core_regulator = TPS65023_DCDC_1,
};

static const struct i2c_device_id tps_65023_id[] = {
Expand All @@ -669,22 +614,12 @@ static struct i2c_driver tps_65023_i2c_driver = {
.id_table = tps_65023_id,
};

/**
* tps_65023_init
*
* Module init function
*/
static int __init tps_65023_init(void)
{
return i2c_add_driver(&tps_65023_i2c_driver);
}
subsys_initcall(tps_65023_init);

/**
* tps_65023_cleanup
*
* Module exit function
*/
static void __exit tps_65023_cleanup(void)
{
i2c_del_driver(&tps_65023_i2c_driver);
Expand Down

0 comments on commit c2cddf6

Please sign in to comment.