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

Commit 89b8a21c authored by Abhijeet Dharmapurikar's avatar Abhijeet Dharmapurikar Committed by Rohit Vaswani
Browse files

power: qpnp-smbcharger: avail of simpler regulator registration api



Change,
a0c7b164 regulator: of: Provide simplified DT parsing method
enables to register a regulator without constructing an regulator_init_data
structure. The regulator_init_data is instantiated within the
registration api and is filled with information by parsing the regualtor
device node.

Avail of this convenience while registering OTG regulators in the
qpnp-smbcharger driver.

Change-Id: I2ba14d3bea7d839f8055401d69d7461d2f54aa8e
Signed-off-by: default avatarAbhijeet Dharmapurikar <adharmap@codeaurora.org>
parent 8b5cc3d7
Loading
Loading
Loading
Loading
+34 −64
Original line number Diff line number Diff line
@@ -3769,32 +3769,17 @@ struct regulator_ops smbchg_external_otg_reg_ops = {
static int smbchg_regulator_init(struct smbchg_chip *chip)
{
	int rc = 0;
	struct regulator_init_data *init_data;
	struct regulator_config cfg = {};
	struct device_node *regulator_node;

	regulator_node = of_get_child_by_name(chip->dev->of_node,
			"qcom,smbcharger-boost-otg");

	init_data = of_get_regulator_init_data(chip->dev, regulator_node);
	if (!init_data) {
		dev_err(chip->dev, "Unable to allocate memory\n");
		return -ENOMEM;
	}
	cfg.dev = chip->dev;
	cfg.driver_data = chip;

	if (init_data->constraints.name) {
	chip->otg_vreg.rdesc.owner = THIS_MODULE;
	chip->otg_vreg.rdesc.type = REGULATOR_VOLTAGE;
	chip->otg_vreg.rdesc.ops = &smbchg_otg_reg_ops;
		chip->otg_vreg.rdesc.name = init_data->constraints.name;

		cfg.dev = chip->dev;
		cfg.init_data = init_data;
		cfg.driver_data = chip;
		cfg.of_node = regulator_node;

		init_data->constraints.valid_ops_mask
			|= REGULATOR_CHANGE_STATUS;
	chip->otg_vreg.rdesc.of_match = "qcom,smbcharger-boost-otg";
	chip->otg_vreg.rdesc.name = "qcom,smbcharger-boost-otg";

	chip->otg_vreg.rdev = devm_regulator_register(chip->dev,
					&chip->otg_vreg.rdesc, &cfg);
@@ -3805,8 +3790,6 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
			dev_err(chip->dev,
				"OTG reg failed, rc=%d\n", rc);
	}
	}

	if (rc)
		return rc;

@@ -3816,28 +3799,16 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
		dev_dbg(chip->dev, "external-otg node absent\n");
		return 0;
	}
	init_data = of_get_regulator_init_data(chip->dev, regulator_node);
	if (!init_data) {
		dev_err(chip->dev, "Unable to allocate memory\n");
		return -ENOMEM;
	}

	if (init_data->constraints.name) {
		if (of_get_property(chip->dev->of_node,
					"otg-parent-supply", NULL))
			init_data->supply_regulator = "otg-parent";
	chip->ext_otg_vreg.rdesc.owner = THIS_MODULE;
	chip->ext_otg_vreg.rdesc.type = REGULATOR_VOLTAGE;
	chip->ext_otg_vreg.rdesc.ops = &smbchg_external_otg_reg_ops;
		chip->ext_otg_vreg.rdesc.name = init_data->constraints.name;

	chip->ext_otg_vreg.rdesc.of_match =  "qcom,smbcharger-external-otg";
	chip->ext_otg_vreg.rdesc.name = "qcom,smbcharger-external-otg";
	if (of_get_property(chip->dev->of_node, "otg-parent-supply", NULL))
		chip->ext_otg_vreg.rdesc.supply_name = "otg-parent";
	cfg.dev = chip->dev;
		cfg.init_data = init_data;
	cfg.driver_data = chip;
		cfg.of_node = regulator_node;

		init_data->constraints.valid_ops_mask
			|= REGULATOR_CHANGE_STATUS;

	chip->ext_otg_vreg.rdev = devm_regulator_register(chip->dev,
					&chip->ext_otg_vreg.rdesc,
@@ -3849,7 +3820,6 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
			dev_err(chip->dev,
				"external OTG reg failed, rc=%d\n", rc);
	}
	}

	return rc;
}