Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 50f4f40a authored by Subbaraman Narayanamurthy's avatar Subbaraman Narayanamurthy Committed by Gerrit - the friendly Code Review server
Browse files

power: qpnp-smbcharger: handle the regulator probe deferral properly



Currently, if regulator_register() of smbcharger-external-otg
regulator returns an error (e.g. -EPROBE_DEFER),
regulator_unregister() is not called for smbcharger-boost-otg
regulator which got registered before that.

This causes problems during bootup later because of an invalid
regulator device being left registered indefinitely.

Fix this by changing the driver to use devm_regulator_register()
for registering the regulators. This fixes the issue by taking
care of unregistering the regulators automatically. Since this
eliminates the need for smbchg_regulator_deinit() in charger
driver, remove it.

CRs-Fixed: 895622
Change-Id: I363693888f357555dbb82ef2566ed855cea9fe94
Signed-off-by: default avatarSubbaraman Narayanamurthy <subbaram@codeaurora.org>
parent de1cb946
Loading
Loading
Loading
Loading
+8 −17
Original line number Diff line number Diff line
@@ -3357,7 +3357,7 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
		init_data->constraints.valid_ops_mask
			|= REGULATOR_CHANGE_STATUS;

		chip->otg_vreg.rdev = regulator_register(
		chip->otg_vreg.rdev = devm_regulator_register(chip->dev,
						&chip->otg_vreg.rdesc, &cfg);
		if (IS_ERR(chip->otg_vreg.rdev)) {
			rc = PTR_ERR(chip->otg_vreg.rdev);
@@ -3400,8 +3400,9 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
		init_data->constraints.valid_ops_mask
			|= REGULATOR_CHANGE_STATUS;

		chip->ext_otg_vreg.rdev = regulator_register(
					&chip->ext_otg_vreg.rdesc, &cfg);
		chip->ext_otg_vreg.rdev = devm_regulator_register(chip->dev,
						&chip->ext_otg_vreg.rdesc,
						&cfg);
		if (IS_ERR(chip->ext_otg_vreg.rdev)) {
			rc = PTR_ERR(chip->ext_otg_vreg.rdev);
			chip->ext_otg_vreg.rdev = NULL;
@@ -3414,14 +3415,6 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
	return rc;
}

static void smbchg_regulator_deinit(struct smbchg_chip *chip)
{
	if (chip->otg_vreg.rdev)
		regulator_unregister(chip->otg_vreg.rdev);
	if (chip->ext_otg_vreg.rdev)
		regulator_unregister(chip->ext_otg_vreg.rdev);
}

#define CMD_CHG_LED_REG		0x43
#define CHG_LED_CTRL_BIT		BIT(0)
#define LED_SW_CTRL_BIT		0x1
@@ -6801,14 +6794,14 @@ static int smbchg_probe(struct spmi_device *spmi)
	if (rc < 0) {
		dev_err(&spmi->dev,
			"Unable to intialize hardware rc = %d\n", rc);
		goto free_regulator;
		goto out;
	}

	rc = determine_initial_status(chip);
	if (rc < 0) {
		dev_err(&spmi->dev,
			"Unable to determine init status rc = %d\n", rc);
		goto free_regulator;
		goto out;
	}

	chip->previous_soc = -EINVAL;
@@ -6825,7 +6818,7 @@ static int smbchg_probe(struct spmi_device *spmi)
	if (rc < 0) {
		dev_err(&spmi->dev,
			"Unable to register batt_psy rc = %d\n", rc);
		goto free_regulator;
		goto out;
	}
	if (chip->dc_psy_type != -EINVAL) {
		chip->dc_psy.name		= "dc";
@@ -6896,8 +6889,7 @@ unregister_dc_psy:
	power_supply_unregister(&chip->dc_psy);
unregister_batt_psy:
	power_supply_unregister(&chip->batt_psy);
free_regulator:
	smbchg_regulator_deinit(chip);
out:
	handle_usb_removal(chip);
	return rc;
}
@@ -6912,7 +6904,6 @@ static int smbchg_remove(struct spmi_device *spmi)
		power_supply_unregister(&chip->dc_psy);

	power_supply_unregister(&chip->batt_psy);
	smbchg_regulator_deinit(chip);

	return 0;
}