Skip to content

Commit 1c73dae

Browse files
AxelLinbroonie
authored andcommitted
regulator: hi6421: Fix getting wrong drvdata
Since config.dev = pdev->dev.parent in current code, so dev_get_drvdata(rdev->dev.parent) call in hi6421_regulator_enable returns the drvdata of the mfd device rather than the regulator. Fix it. This was broken while converting to use simplified DT parsing because the config.dev changed from pdev->dev to pdev->dev.parent for parsing the parent's of_node. Fixes: 29dc269 ("regulator: hi6421: Convert to use simplified DT parsing") Signed-off-by: Axel Lin <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ea98690 commit 1c73dae

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

drivers/regulator/hi6421-regulator.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,8 @@ static struct hi6421_regulator_info
366366

367367
static int hi6421_regulator_enable(struct regulator_dev *rdev)
368368
{
369-
struct hi6421_regulator_pdata *pdata;
369+
struct hi6421_regulator_pdata *pdata = rdev_get_drvdata(rdev);
370370

371-
pdata = dev_get_drvdata(rdev->dev.parent);
372371
/* hi6421 spec requires regulator enablement must be serialized:
373372
* - Because when BUCK, LDO switching from off to on, it will have
374373
* a huge instantaneous current; so you can not turn on two or
@@ -385,9 +384,10 @@ static int hi6421_regulator_enable(struct regulator_dev *rdev)
385384

386385
static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)
387386
{
388-
struct hi6421_regulator_info *info = rdev_get_drvdata(rdev);
387+
struct hi6421_regulator_info *info;
389388
unsigned int reg_val;
390389

390+
info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
391391
regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val);
392392
if (reg_val & info->mode_mask)
393393
return REGULATOR_MODE_IDLE;
@@ -397,9 +397,10 @@ static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)
397397

398398
static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
399399
{
400-
struct hi6421_regulator_info *info = rdev_get_drvdata(rdev);
400+
struct hi6421_regulator_info *info;
401401
unsigned int reg_val;
402402

403+
info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
403404
regmap_read(rdev->regmap, rdev->desc->enable_reg, &reg_val);
404405
if (reg_val & info->mode_mask)
405406
return REGULATOR_MODE_STANDBY;
@@ -410,9 +411,10 @@ static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
410411
static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
411412
unsigned int mode)
412413
{
413-
struct hi6421_regulator_info *info = rdev_get_drvdata(rdev);
414+
struct hi6421_regulator_info *info;
414415
unsigned int new_mode;
415416

417+
info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
416418
switch (mode) {
417419
case REGULATOR_MODE_NORMAL:
418420
new_mode = 0;
@@ -434,9 +436,10 @@ static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
434436
static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev,
435437
unsigned int mode)
436438
{
437-
struct hi6421_regulator_info *info = rdev_get_drvdata(rdev);
439+
struct hi6421_regulator_info *info;
438440
unsigned int new_mode;
439441

442+
info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
440443
switch (mode) {
441444
case REGULATOR_MODE_NORMAL:
442445
new_mode = 0;
@@ -459,7 +462,9 @@ static unsigned int
459462
hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev,
460463
int input_uV, int output_uV, int load_uA)
461464
{
462-
struct hi6421_regulator_info *info = rdev_get_drvdata(rdev);
465+
struct hi6421_regulator_info *info;
466+
467+
info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
463468

464469
if (load_uA > info->eco_microamp)
465470
return REGULATOR_MODE_NORMAL;
@@ -543,14 +548,13 @@ static int hi6421_regulator_probe(struct platform_device *pdev)
543548
if (!pdata)
544549
return -ENOMEM;
545550
mutex_init(&pdata->lock);
546-
platform_set_drvdata(pdev, pdata);
547551

548552
for (i = 0; i < ARRAY_SIZE(hi6421_regulator_info); i++) {
549553
/* assign per-regulator data */
550554
info = &hi6421_regulator_info[i];
551555

552556
config.dev = pdev->dev.parent;
553-
config.driver_data = info;
557+
config.driver_data = pdata;
554558
config.regmap = pmic->regmap;
555559

556560
rdev = devm_regulator_register(&pdev->dev, &info->desc,

0 commit comments

Comments
 (0)