Skip to content

Commit d6e92d3

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator: regulator: twl: fix twl4030 support for smps regulators regulator: fix use after free bug regulator: aat2870: Fix the logic of checking if no id is matched in aat2870_get_regulator
2 parents cd5b49b + ba305e3 commit d6e92d3

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

drivers/regulator/aat2870-regulator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static struct aat2870_regulator *aat2870_get_regulator(int id)
160160
break;
161161
}
162162

163-
if (!ri)
163+
if (i == ARRAY_SIZE(aat2870_regulators))
164164
return NULL;
165165

166166
ri->enable_addr = AAT2870_LDO_EN;

drivers/regulator/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,8 +2799,8 @@ void regulator_unregister(struct regulator_dev *rdev)
27992799
list_del(&rdev->list);
28002800
if (rdev->supply)
28012801
regulator_put(rdev->supply);
2802-
device_unregister(&rdev->dev);
28032802
kfree(rdev->constraints);
2803+
device_unregister(&rdev->dev);
28042804
mutex_unlock(&regulator_list_mutex);
28052805
}
28062806
EXPORT_SYMBOL_GPL(regulator_unregister);

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)