regulator: core: Fix device link error when registering regulator

The sysfs device link can only be created after regulator device
registered.

Otherwise, the regulator always have some warning logs.
...
[    1.033024] DCDC_REG1: supplied by vcc5v0_sys
[    1.033427] vcc5v0_sys: could not add device link regulator.3 err -2
[    1.034302] vdd_center: 750 <--> 1350 mV at 900 mV
[    1.034862] rk808 0-0020: Looking up vcc2-supply from device tree
[    1.034907] DCDC_REG2: supplied by vcc5v0_sys
[    1.035298] vcc5v0_sys: could not add device link regulator.4 err -2
[    1.036301] vdd_cpu_l: 750 <--> 1350 mV at 900 mV
[    1.036837] rk808 0-0020: Looking up vcc3-supply from device tree
[    1.036880] DCDC_REG3: supplied by vcc5v0_sys
[    1.037271] vcc5v0_sys: could not add device link regulator.5 err -2
[    1.037985] vcc_ddr: at 500 mV
[    1.038508] rk808 0-0020: Looking up vcc4-supply from device tree
[    1.038550] DCDC_REG4: supplied by vcc5v0_sys
[    1.038941] vcc5v0_sys: could not add device link regulator.6 err -2
[    1.039657] vcc3v3_sys: 3300 mV
[    1.040179] rk808 0-0020: Looking up vcc9-supply from device tree
[    1.040223] DCDC_REG5: supplied by vcc5v0_sys

Fixes: c438b9d017 ("regulator: core: Move registration of regulator device")

Change-Id: Ie20421eab45f3f8229a5bedf3fecf99c757160bb
Signed-off-by: Caesar Wang <wxt@rock-chips.com>
This commit is contained in:
Caesar Wang
2019-02-14 10:01:12 +08:00
committed by Tao Huang
parent 5e0baa55b6
commit d8bc92af0a

View File

@@ -1337,12 +1337,15 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
if (regulator->supply_name == NULL)
goto overflow_err;
err = sysfs_create_link_nowarn(&rdev->dev.kobj, &dev->kobj,
buf);
if (err) {
rdev_dbg(rdev, "could not add device link %s err %d\n",
dev->kobj.name, err);
/* non-fatal */
if (device_is_registered(dev)) {
err = sysfs_create_link_nowarn(&rdev->dev.kobj,
&dev->kobj, buf);
if (err) {
rdev_dbg(rdev,
"could not add device link %s err %d\n",
dev->kobj.name, err);
/* non-fatal */
}
}
} else {
regulator->supply_name = kstrdup(supply_name, GFP_KERNEL);
@@ -4411,6 +4414,19 @@ regulator_register(const struct regulator_desc *regulator_desc,
}
dev_set_drvdata(&rdev->dev, rdev);
/* Add a link to the device sysfs entry */
if (rdev->supply && rdev->supply->dev) {
ret = sysfs_create_link_nowarn(&rdev->supply->dev->kobj,
&rdev->dev.kobj,
rdev->supply->supply_name);
if (ret) {
rdev_dbg(rdev, "could not add device link %s err %d\n",
rdev->dev.kobj.name, ret);
/* non-fatal */
}
}
rdev_init_debugfs(rdev);
rdev_init_early_min_volt(rdev);