Skip to content

Commit 9a00630

Browse files
ldewanganbroonie
authored andcommitted
regulator: tps62360: support force PWM mode via regulator mode
Change the mechanism of enabling the force PWM mode through regulator set mode. This can be dynamically configured now. In the REGULATOR_MODE_FAST the force PWM is enabled and in REGULATOR_MODE_NORMAL the force PWM is disabled. Signed-off-by: Laxman Dewangan <ldewangan@nvidia.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
1 parent 70e5f64 commit 9a00630

3 files changed

Lines changed: 65 additions & 40 deletions

File tree

‎Documentation/devicetree/bindings/regulator/tps62360-regulator.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ Required properties:
99
- reg: I2C slave address
1010

1111
Optional properties:
12-
- ti,enable-force-pwm: Enable force PWM mode. This is boolean value.
1312
- ti,enable-vout-discharge: Enable output discharge. This is boolean value.
1413
- ti,enable-pull-down: Enable pull down. This is boolean value.
1514
- ti,vsel0-gpio: GPIO for controlling VSEL0 line.

‎drivers/regulator/tps62360-regulator.c‎

Lines changed: 65 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
#define REG_RAMPCTRL 6
5050
#define REG_CHIPID 8
5151

52+
#define FORCE_PWM_ENABLE BIT(7)
53+
5254
enum chips {TPS62360, TPS62361, TPS62362, TPS62363};
5355

5456
#define TPS62360_BASE_VOLTAGE 770000
@@ -69,7 +71,6 @@ struct tps62360_chip {
6971
int voltage_base;
7072
u8 voltage_reg_mask;
7173
bool en_internal_pulldn;
72-
bool en_force_pwm;
7374
bool en_discharge;
7475
bool valid_gpios;
7576
int lru_index[4];
@@ -191,37 +192,81 @@ static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
191192
return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us);
192193
}
193194

195+
static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
196+
{
197+
struct tps62360_chip *tps = rdev_get_drvdata(rdev);
198+
int i;
199+
int val;
200+
int ret;
201+
202+
/* Enable force PWM mode in FAST mode only. */
203+
switch (mode) {
204+
case REGULATOR_MODE_FAST:
205+
val = FORCE_PWM_ENABLE;
206+
break;
207+
208+
case REGULATOR_MODE_NORMAL:
209+
val = 0;
210+
break;
211+
212+
default:
213+
return -EINVAL;
214+
}
215+
216+
if (!tps->valid_gpios) {
217+
ret = regmap_update_bits(tps->regmap,
218+
REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val);
219+
if (ret < 0)
220+
dev_err(tps->dev,
221+
"%s(): register %d update failed with err %d\n",
222+
__func__, REG_VSET0 + tps->curr_vset_id, ret);
223+
return ret;
224+
}
225+
226+
/* If gpios are valid then all register set need to be control */
227+
for (i = 0; i < 4; ++i) {
228+
ret = regmap_update_bits(tps->regmap,
229+
REG_VSET0 + i, FORCE_PWM_ENABLE, val);
230+
if (ret < 0) {
231+
dev_err(tps->dev,
232+
"%s(): register %d update failed with err %d\n",
233+
__func__, REG_VSET0 + i, ret);
234+
return ret;
235+
}
236+
}
237+
return ret;
238+
}
239+
240+
static unsigned int tps62360_get_mode(struct regulator_dev *rdev)
241+
{
242+
struct tps62360_chip *tps = rdev_get_drvdata(rdev);
243+
unsigned int data;
244+
int ret;
245+
246+
ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
247+
if (ret < 0) {
248+
dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
249+
__func__, REG_VSET0 + tps->curr_vset_id, ret);
250+
return ret;
251+
}
252+
return (data & FORCE_PWM_ENABLE) ?
253+
REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
254+
}
255+
194256
static struct regulator_ops tps62360_dcdc_ops = {
195257
.get_voltage_sel = tps62360_dcdc_get_voltage_sel,
196258
.set_voltage_sel = tps62360_dcdc_set_voltage_sel,
197259
.list_voltage = regulator_list_voltage_linear,
198260
.map_voltage = regulator_map_voltage_linear,
199261
.set_voltage_time_sel = tps62360_set_voltage_time_sel,
262+
.set_mode = tps62360_set_mode,
263+
.get_mode = tps62360_get_mode,
200264
};
201265

202-
static int __devinit tps62360_init_force_pwm(struct tps62360_chip *tps,
203-
struct tps62360_regulator_platform_data *pdata,
204-
int vset_id)
205-
{
206-
int ret;
207-
int bit = 0;
208-
209-
if (pdata->en_force_pwm)
210-
bit = BIT(7);
211-
212-
ret = regmap_update_bits(tps->regmap, REG_VSET0 + vset_id, BIT(7), bit);
213-
if (ret < 0)
214-
dev_err(tps->dev,
215-
"%s(): register %d update failed with err %d\n",
216-
__func__, REG_VSET0 + vset_id, ret);
217-
return ret;
218-
}
219-
220266
static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
221267
struct tps62360_regulator_platform_data *pdata)
222268
{
223269
int ret;
224-
int i;
225270
unsigned int ramp_ctrl;
226271

227272
/* Initialize internal pull up/down control */
@@ -236,19 +281,6 @@ static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
236281
return ret;
237282
}
238283

239-
/* Initialize force PWM mode */
240-
if (tps->valid_gpios) {
241-
for (i = 0; i < 4; ++i) {
242-
ret = tps62360_init_force_pwm(tps, pdata, i);
243-
if (ret < 0)
244-
return ret;
245-
}
246-
} else {
247-
ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id);
248-
if (ret < 0)
249-
return ret;
250-
}
251-
252284
/* Reset output discharge path to reduce power consumption */
253285
ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
254286
if (ret < 0) {
@@ -310,9 +342,6 @@ static struct tps62360_regulator_platform_data *
310342
if (of_find_property(np, "ti,enable-pull-down", NULL))
311343
pdata->en_internal_pulldn = true;
312344

313-
if (of_find_property(np, "ti,enable-force-pwm", NULL))
314-
pdata->en_force_pwm = true;
315-
316345
if (of_find_property(np, "ti,enable-vout-discharge", NULL))
317346
pdata->en_discharge = true;
318347

@@ -370,7 +399,6 @@ static int __devinit tps62360_probe(struct i2c_client *client,
370399
return -ENOMEM;
371400
}
372401

373-
tps->en_force_pwm = pdata->en_force_pwm;
374402
tps->en_discharge = pdata->en_discharge;
375403
tps->en_internal_pulldn = pdata->en_internal_pulldn;
376404
tps->vsel0_gpio = pdata->vsel0_gpio;

‎include/linux/regulator/tps62360.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* struct tps62360_regulator_platform_data - tps62360 regulator platform data.
3131
*
3232
* @reg_init_data: The regulator init data.
33-
* @en_force_pwm: Enable force pwm or not.
3433
* @en_discharge: Enable discharge the output capacitor via internal
3534
* register.
3635
* @en_internal_pulldn: internal pull down enable or not.
@@ -43,7 +42,6 @@
4342
*/
4443
struct tps62360_regulator_platform_data {
4544
struct regulator_init_data *reg_init_data;
46-
bool en_force_pwm;
4745
bool en_discharge;
4846
bool en_internal_pulldn;
4947
int vsel0_gpio;

0 commit comments

Comments
 (0)