greybus: arche-apb-ctrl: Re-arrange init sequence
authorVaibhav Hiremath <vaibhav.hiremath@linaro.org>
Fri, 12 Feb 2016 20:34:09 +0000 (02:04 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Mon, 15 Feb 2016 21:18:40 +0000 (13:18 -0800)
In order to allow APB2 disable by default on boot/init, and also
provide interface to user to enable it later on, re-arrange the init_seq
fn.
The idea here is, the apb_ctrl_init_seq() fn will be renamed to
apb_ctrl_coldboot_seq(), and should not try to claim any resources.
All the resource claim should happen in apb_ctrl_get_devtree_data() fn.

And also uses devm_gpio_request_one() fn wherever possible.

Testing Done: Tested on EVT1.2 and DB3.5  platform.

Signed-off-by: Vaibhav Hiremath <vaibhav.hiremath@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/arche-apb-ctrl.c

index 42267fa121f5295ff9c6cbf7d4e38c455afc8922..772015393221f5e4110a1f8858ce05bbc731084d 100644 (file)
@@ -78,29 +78,7 @@ static int apb_ctrl_init_seq(struct platform_device *pdev,
        int ret;
 
        /* Hold APB in reset state */
-       ret = devm_gpio_request(dev, apb->resetn_gpio, "apb-reset");
-       if (ret) {
-               dev_err(dev, "Failed requesting reset gpio %d\n",
-                               apb->resetn_gpio);
-               return ret;
-       }
-       ret = gpio_direction_output(apb->resetn_gpio, 0);
-       if (ret) {
-               dev_err(dev, "failed to set reset gpio dir:%d\n", ret);
-               return ret;
-       }
-
-       ret = devm_gpio_request(dev, apb->pwroff_gpio, "pwroff_n");
-       if (ret) {
-               dev_err(dev, "Failed requesting pwroff_n gpio %d\n",
-                               apb->pwroff_gpio);
-               return ret;
-       }
-       ret = gpio_direction_input(apb->pwroff_gpio);
-       if (ret) {
-               dev_err(dev, "failed to set pwroff gpio dir:%d\n", ret);
-               return ret;
-       }
+       assert_reset(apb->resetn_gpio);
 
        /* Enable power to APB */
        if (!IS_ERR(apb->vcore)) {
@@ -115,45 +93,24 @@ static int apb_ctrl_init_seq(struct platform_device *pdev,
                ret = regulator_enable(apb->vio);
                if (ret) {
                        dev_err(dev, "failed to enable IO regulator\n");
-                       goto out_vcore_disable;
+                       return ret;
                }
        }
 
-       ret = devm_gpio_request_one(dev, apb->boot_ret_gpio,
-                       GPIOF_OUT_INIT_LOW, "boot retention");
-       if (ret) {
-               dev_err(dev, "Failed requesting bootret gpio %d\n",
-                               apb->boot_ret_gpio);
-               goto out_vio_disable;
-       }
        gpio_set_value(apb->boot_ret_gpio, 0);
 
        /* On DB3 clock was not mandatory */
-       if (gpio_is_valid(apb->clk_en_gpio)) {
-               ret = devm_gpio_request(dev, apb->clk_en_gpio, "apb_clk_en");
-               if (ret) {
-                       dev_warn(dev, "Failed requesting APB clock en gpio %d\n",
-                                apb->clk_en_gpio);
-               } else {
-                       ret = gpio_direction_output(apb->clk_en_gpio, 1);
-                       if (ret)
-                               dev_warn(dev, "failed to set APB clock en gpio dir:%d\n",
-                                        ret);
-               }
-       }
+       if (gpio_is_valid(apb->clk_en_gpio))
+               gpio_set_value(apb->clk_en_gpio, 1);
 
        usleep_range(100, 200);
 
-       return 0;
+       /* deassert reset to APB : Active-low signal */
+       deassert_reset(apb->resetn_gpio);
 
-out_vio_disable:
-       if (!IS_ERR(apb->vio))
-               regulator_disable(apb->vio);
-out_vcore_disable:
-       if (!IS_ERR(apb->vcore))
-               regulator_disable(apb->vcore);
+       apb->state = ARCHE_PLATFORM_STATE_ACTIVE;
 
-       return ret;
+       return 0;
 }
 
 static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
@@ -161,18 +118,33 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
 {
        struct device *dev = &pdev->dev;
        struct device_node *np = dev->of_node;
+       int ret;
 
        apb->resetn_gpio = of_get_named_gpio(np, "reset-gpios", 0);
        if (apb->resetn_gpio < 0) {
                dev_err(dev, "failed to get reset gpio\n");
                return apb->resetn_gpio;
        }
+       ret = devm_gpio_request_one(dev, apb->resetn_gpio,
+                       GPIOF_OUT_INIT_LOW, "apb-reset");
+       if (ret) {
+               dev_err(dev, "Failed requesting reset gpio %d\n",
+                               apb->resetn_gpio);
+               return ret;
+       }
 
        apb->boot_ret_gpio = of_get_named_gpio(np, "boot-ret-gpios", 0);
        if (apb->boot_ret_gpio < 0) {
                dev_err(dev, "failed to get boot retention gpio\n");
                return apb->boot_ret_gpio;
        }
+       ret = devm_gpio_request_one(dev, apb->boot_ret_gpio,
+                       GPIOF_OUT_INIT_LOW, "boot retention");
+       if (ret) {
+               dev_err(dev, "Failed requesting bootret gpio %d\n",
+                               apb->boot_ret_gpio);
+               return ret;
+       }
 
        /* It's not mandatory to support power management interface */
        apb->pwroff_gpio = of_get_named_gpio(np, "pwr-off-gpios", 0);
@@ -180,11 +152,27 @@ static int apb_ctrl_get_devtree_data(struct platform_device *pdev,
                dev_err(dev, "failed to get power off gpio\n");
                return apb->pwroff_gpio;
        }
+       ret = devm_gpio_request_one(dev, apb->pwroff_gpio,
+                       GPIOF_IN, "pwroff_n");
+       if (ret) {
+               dev_err(dev, "Failed requesting pwroff_n gpio %d\n",
+                               apb->pwroff_gpio);
+               return ret;
+       }
 
        /* Do not make clock mandatory as of now (for DB3) */
        apb->clk_en_gpio = of_get_named_gpio(np, "clock-en-gpio", 0);
-       if (apb->clk_en_gpio < 0)
+       if (apb->clk_en_gpio < 0) {
                dev_warn(dev, "failed to get clock en gpio\n");
+       } else if (gpio_is_valid(apb->clk_en_gpio)) {
+               ret = devm_gpio_request_one(dev, apb->clk_en_gpio,
+                               GPIOF_OUT_INIT_LOW, "apb_clk_en");
+               if (ret) {
+                       dev_warn(dev, "Failed requesting APB clock en gpio %d\n",
+                                       apb->clk_en_gpio);
+                       return ret;
+               }
+       }
 
        apb->pwrdn_gpio = of_get_named_gpio(np, "pwr-down-gpios", 0);
        if (apb->pwrdn_gpio < 0)
@@ -255,10 +243,6 @@ int arche_apb_ctrl_probe(struct platform_device *pdev)
                return ret;
        }
 
-       /* deassert reset to APB : Active-low signal */
-       deassert_reset(apb->resetn_gpio);
-       apb->state = ARCHE_PLATFORM_STATE_ACTIVE;
-
        platform_set_drvdata(pdev, apb);
 
        export_gpios(apb);