Skip to content

Commit ba305e3

Browse files
Tero Kristobroonie
authored andcommitted
regulator: twl: fix twl4030 support for smps regulators
SMPS regulator voltage control differs from the one of the LDO ones. Current TWL code was using LDO regulator ops for controlling the SMPS regulators, which fails. This was fixed fixed by adding separate regulator type which uses correct logic and calculations for the voltage levels. Signed-off-by: Tero Kristo <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected]
1 parent 58fb5cf commit ba305e3

File tree

1 file changed

+44
-2
lines changed

1 file changed

+44
-2
lines changed

drivers/regulator/twl-regulator.c

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct twlreg_info {
7171
#define VREG_TYPE 1
7272
#define VREG_REMAP 2
7373
#define VREG_DEDICATED 3 /* LDO control */
74+
#define VREG_VOLTAGE_SMPS_4030 9
7475
/* TWL6030 register offsets */
7576
#define VREG_TRANS 1
7677
#define VREG_STATE 2
@@ -514,6 +515,32 @@ static struct regulator_ops twl4030ldo_ops = {
514515
.get_status = twl4030reg_get_status,
515516
};
516517

518+
static int
519+
twl4030smps_set_voltage(struct regulator_dev *rdev, int min_uV, int max_uV,
520+
unsigned *selector)
521+
{
522+
struct twlreg_info *info = rdev_get_drvdata(rdev);
523+
int vsel = DIV_ROUND_UP(min_uV - 600000, 12500);
524+
525+
twlreg_write(info, TWL_MODULE_PM_RECEIVER, VREG_VOLTAGE_SMPS_4030,
526+
vsel);
527+
return 0;
528+
}
529+
530+
static int twl4030smps_get_voltage(struct regulator_dev *rdev)
531+
{
532+
struct twlreg_info *info = rdev_get_drvdata(rdev);
533+
int vsel = twlreg_read(info, TWL_MODULE_PM_RECEIVER,
534+
VREG_VOLTAGE_SMPS_4030);
535+
536+
return vsel * 12500 + 600000;
537+
}
538+
539+
static struct regulator_ops twl4030smps_ops = {
540+
.set_voltage = twl4030smps_set_voltage,
541+
.get_voltage = twl4030smps_get_voltage,
542+
};
543+
517544
static int twl6030ldo_list_voltage(struct regulator_dev *rdev, unsigned index)
518545
{
519546
struct twlreg_info *info = rdev_get_drvdata(rdev);
@@ -856,6 +883,21 @@ static struct regulator_ops twlsmps_ops = {
856883
}, \
857884
}
858885

886+
#define TWL4030_ADJUSTABLE_SMPS(label, offset, num, turnon_delay, remap_conf) \
887+
{ \
888+
.base = offset, \
889+
.id = num, \
890+
.delay = turnon_delay, \
891+
.remap = remap_conf, \
892+
.desc = { \
893+
.name = #label, \
894+
.id = TWL4030_REG_##label, \
895+
.ops = &twl4030smps_ops, \
896+
.type = REGULATOR_VOLTAGE, \
897+
.owner = THIS_MODULE, \
898+
}, \
899+
}
900+
859901
#define TWL6030_ADJUSTABLE_LDO(label, offset, min_mVolts, max_mVolts) { \
860902
.base = offset, \
861903
.min_mV = min_mVolts, \
@@ -947,8 +989,8 @@ static struct twlreg_info twl_regs[] = {
947989
TWL4030_ADJUSTABLE_LDO(VINTANA2, 0x43, 12, 100, 0x08),
948990
TWL4030_FIXED_LDO(VINTDIG, 0x47, 1500, 13, 100, 0x08),
949991
TWL4030_ADJUSTABLE_LDO(VIO, 0x4b, 14, 1000, 0x08),
950-
TWL4030_ADJUSTABLE_LDO(VDD1, 0x55, 15, 1000, 0x08),
951-
TWL4030_ADJUSTABLE_LDO(VDD2, 0x63, 16, 1000, 0x08),
992+
TWL4030_ADJUSTABLE_SMPS(VDD1, 0x55, 15, 1000, 0x08),
993+
TWL4030_ADJUSTABLE_SMPS(VDD2, 0x63, 16, 1000, 0x08),
952994
TWL4030_FIXED_LDO(VUSB1V5, 0x71, 1500, 17, 100, 0x08),
953995
TWL4030_FIXED_LDO(VUSB1V8, 0x74, 1800, 18, 100, 0x08),
954996
TWL4030_FIXED_LDO(VUSB3V1, 0x77, 3100, 19, 150, 0x08),

0 commit comments

Comments
 (0)