This patch adds support for usage of GPIO's by multiple bucks and regulators
of DA9055 for enable-disable and voltage set selection.Without this patch 
regulator
control through GPIO would fail for more than one regulator/buck.

Signed-off-by: Ankur <ankur.ra...@kpitcummins.com>
---
 drivers/regulator/da9055-regulator.c |   73 +++++++++++++++++++++-------------
 1 files changed, 45 insertions(+), 28 deletions(-)

diff --git a/drivers/regulator/da9055-regulator.c 
b/drivers/regulator/da9055-regulator.c
index 3022109..889a2b8 100644
--- a/drivers/regulator/da9055-regulator.c
+++ b/drivers/regulator/da9055-regulator.c
@@ -44,6 +44,10 @@
 #define DA9055_ID_LDO5         6
 #define DA9055_ID_LDO6         7
 
+/* Max Gpio's Controlling Regulators */
+#define MAX_GPIO_LDO           2
+#define GPI_NAME_LENGTH                18
+
 /* DA9055 BUCK current limit */
 static const int da9055_current_limits[] = { 500000, 600000, 700000, 800000 };
 
@@ -445,24 +449,30 @@ static int da9055_gpio_init(struct da9055_regulator 
*regulator,
 {
        struct da9055_regulator_info *info = regulator->info;
        int ret = 0;
+       static int alloc_gpio, req_gpio[MAX_GPIO_LDO];
+       char name[GPI_NAME_LENGTH];
 
-       if (pdata->gpio_ren && pdata->gpio_ren[id]) {
-               char name[18];
-               int gpio_mux = pdata->gpio_ren[id];
-
-               config->ena_gpio = pdata->ena_gpio[id];
-               config->ena_gpio_flags = GPIOF_OUT_INIT_HIGH;
-               config->ena_gpio_invert = 1;
-
+       if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
                /*
-                * GPI pin is muxed with regulator to control the
-                * regulator state.
+                * Verify whether GPIO's to be requested are not
+                * allocated before
                 */
-               sprintf(name, "DA9055 GPI %d", gpio_mux);
-               ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
-                                           name);
-               if (ret < 0)
-                       goto err;
+               if ((pdata->gpio_rsel[id] != req_gpio[0]
+               && pdata->gpio_rsel[id] != req_gpio[1]) &&
+               (alloc_gpio < MAX_GPIO_LDO)) {
+                       /*
+                        * GPI pin is muxed with regulator to control the
+                        * regulator state.
+                        */
+                       sprintf(name, "DA9055 GPI %d", pdata->gpio_rsel[id]);
+                       ret = devm_gpio_request_one(config->dev,
+                                                   pdata->gpio_rsel[id],
+                                                   GPIOF_DIR_IN, name);
+                       if (ret < 0)
+                               goto err;
+                       req_gpio[alloc_gpio] = pdata->gpio_rsel[id];
+                       alloc_gpio++;
+               }
 
                /*
                 * Let the regulator know that its state is controlled
@@ -476,21 +486,28 @@ static int da9055_gpio_init(struct da9055_regulator 
*regulator,
                        goto err;
        }
 
-       if (pdata->gpio_rsel && pdata->gpio_rsel[id]) {
-               char name[18];
-               int gpio_mux = pdata->gpio_rsel[id];
-
-               regulator->reg_rselect = pdata->reg_rsel[id];
-
+       if (pdata->gpio_ren && pdata->gpio_ren[id]) {
                /*
-                * GPI pin is muxed with regulator to select the
-                * regulator register set A/B for voltage ramping.
+                * Verify whether GPIO's to be requested are not
+                * allocated before
                 */
-               sprintf(name, "DA9055 GPI %d", gpio_mux);
-               ret = devm_gpio_request_one(config->dev, gpio_mux, GPIOF_DIR_IN,
-                                           name);
-               if (ret < 0)
-                       goto err;
+               if ((pdata->gpio_ren[id] != req_gpio[0]
+               && pdata->gpio_ren[id] != req_gpio[1]) &&
+               (alloc_gpio < MAX_GPIO_LDO)) {
+                       regulator->reg_rselect = pdata->reg_rsel[id];
+                       /*
+                        * GPI pin is muxed with regulator to select the
+                        * regulator register set A/B for voltage ramping.
+                        */
+                       sprintf(name, "DA9055 GPI %d", pdata->gpio_ren[id]);
+                       ret = devm_gpio_request_one(config->dev,
+                                                   pdata->gpio_ren[id],
+                                                   GPIOF_DIR_IN, name);
+                       if (ret < 0)
+                               goto err;
+                       req_gpio[alloc_gpio] = pdata->gpio_ren[id];
+                       alloc_gpio++;
+               }
 
                /*
                 * Let the regulator know that its register set A/B
-- 
1.7.1




<<attachment: winmail.dat>>

Reply via email to