From 89b8a21c57d57f535f13b584aa6f151dbd9d23fe Mon Sep 17 00:00:00 2001 From: Abhijeet Dharmapurikar Date: Thu, 14 Jan 2016 19:38:40 -0800 Subject: [PATCH] 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 --- drivers/power/qpnp-smbcharger.c | 98 ++++++++++++--------------------- 1 file changed, 34 insertions(+), 64 deletions(-) diff --git a/drivers/power/qpnp-smbcharger.c b/drivers/power/qpnp-smbcharger.c index 2aabfcdf56b1..ef07f1fa1757 100644 --- a/drivers/power/qpnp-smbcharger.c +++ b/drivers/power/qpnp-smbcharger.c @@ -3769,44 +3769,27 @@ 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"); + cfg.dev = chip->dev; + cfg.driver_data = chip; - 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; + 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.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) return rc; @@ -3816,39 +3799,26 @@ 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.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.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.driver_data = chip; - 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, - &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); - } + 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; + if (rc != -EPROBE_DEFER) + dev_err(chip->dev, + "external OTG reg failed, rc=%d\n", rc); } return rc;