power: qpnp-smbcharger: avail of simpler regulator registration api
Change,
a0c7b16
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: Abhijeet Dharmapurikar <adharmap@codeaurora.org>
This commit is contained in:
parent
8b5cc3d711
commit
89b8a21c57
1 changed files with 34 additions and 64 deletions
|
@ -3769,44 +3769,27 @@ struct regulator_ops smbchg_external_otg_reg_ops = {
|
||||||
static int smbchg_regulator_init(struct smbchg_chip *chip)
|
static int smbchg_regulator_init(struct smbchg_chip *chip)
|
||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct regulator_init_data *init_data;
|
|
||||||
struct regulator_config cfg = {};
|
struct regulator_config cfg = {};
|
||||||
struct device_node *regulator_node;
|
struct device_node *regulator_node;
|
||||||
|
|
||||||
regulator_node = of_get_child_by_name(chip->dev->of_node,
|
cfg.dev = chip->dev;
|
||||||
"qcom,smbcharger-boost-otg");
|
cfg.driver_data = chip;
|
||||||
|
|
||||||
init_data = of_get_regulator_init_data(chip->dev, regulator_node);
|
chip->otg_vreg.rdesc.owner = THIS_MODULE;
|
||||||
if (!init_data) {
|
chip->otg_vreg.rdesc.type = REGULATOR_VOLTAGE;
|
||||||
dev_err(chip->dev, "Unable to allocate memory\n");
|
chip->otg_vreg.rdesc.ops = &smbchg_otg_reg_ops;
|
||||||
return -ENOMEM;
|
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);
|
||||||
|
if (IS_ERR(chip->otg_vreg.rdev)) {
|
||||||
|
rc = PTR_ERR(chip->otg_vreg.rdev);
|
||||||
|
chip->otg_vreg.rdev = NULL;
|
||||||
|
if (rc != -EPROBE_DEFER)
|
||||||
|
dev_err(chip->dev,
|
||||||
|
"OTG reg failed, rc=%d\n", rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
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.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);
|
|
||||||
chip->otg_vreg.rdev = NULL;
|
|
||||||
if (rc != -EPROBE_DEFER)
|
|
||||||
dev_err(chip->dev,
|
|
||||||
"OTG reg failed, rc=%d\n", rc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rc)
|
if (rc)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
|
@ -3816,39 +3799,26 @@ static int smbchg_regulator_init(struct smbchg_chip *chip)
|
||||||
dev_dbg(chip->dev, "external-otg node absent\n");
|
dev_dbg(chip->dev, "external-otg node absent\n");
|
||||||
return 0;
|
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) {
|
chip->ext_otg_vreg.rdesc.owner = THIS_MODULE;
|
||||||
if (of_get_property(chip->dev->of_node,
|
chip->ext_otg_vreg.rdesc.type = REGULATOR_VOLTAGE;
|
||||||
"otg-parent-supply", NULL))
|
chip->ext_otg_vreg.rdesc.ops = &smbchg_external_otg_reg_ops;
|
||||||
init_data->supply_regulator = "otg-parent";
|
chip->ext_otg_vreg.rdesc.of_match = "qcom,smbcharger-external-otg";
|
||||||
chip->ext_otg_vreg.rdesc.owner = THIS_MODULE;
|
chip->ext_otg_vreg.rdesc.name = "qcom,smbcharger-external-otg";
|
||||||
chip->ext_otg_vreg.rdesc.type = REGULATOR_VOLTAGE;
|
if (of_get_property(chip->dev->of_node, "otg-parent-supply", NULL))
|
||||||
chip->ext_otg_vreg.rdesc.ops = &smbchg_external_otg_reg_ops;
|
chip->ext_otg_vreg.rdesc.supply_name = "otg-parent";
|
||||||
chip->ext_otg_vreg.rdesc.name = init_data->constraints.name;
|
cfg.dev = chip->dev;
|
||||||
|
cfg.driver_data = chip;
|
||||||
|
|
||||||
cfg.dev = chip->dev;
|
chip->ext_otg_vreg.rdev = devm_regulator_register(chip->dev,
|
||||||
cfg.init_data = init_data;
|
&chip->ext_otg_vreg.rdesc,
|
||||||
cfg.driver_data = chip;
|
&cfg);
|
||||||
cfg.of_node = regulator_node;
|
if (IS_ERR(chip->ext_otg_vreg.rdev)) {
|
||||||
|
rc = PTR_ERR(chip->ext_otg_vreg.rdev);
|
||||||
init_data->constraints.valid_ops_mask
|
chip->ext_otg_vreg.rdev = NULL;
|
||||||
|= REGULATOR_CHANGE_STATUS;
|
if (rc != -EPROBE_DEFER)
|
||||||
|
dev_err(chip->dev,
|
||||||
chip->ext_otg_vreg.rdev = devm_regulator_register(chip->dev,
|
"external OTG reg failed, rc=%d\n", rc);
|
||||||
&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;
|
|
||||||
if (rc != -EPROBE_DEFER)
|
|
||||||
dev_err(chip->dev,
|
|
||||||
"external OTG reg failed, rc=%d\n", rc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Add table
Reference in a new issue