PCI: rockchip: Control optional 12v power supply
authorShawn Lin <shawn.lin@rock-chips.com>
Thu, 29 Jun 2017 01:22:23 +0000 (09:22 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Wed, 16 Aug 2017 16:43:59 +0000 (11:43 -0500)
Get vpcie12v from DT and control it if available.

Signed-off-by: Shawn Lin <shawn.lin@rock-chips.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/host/pcie-rockchip.c

index 7bb9870..80b9a88 100644 (file)
@@ -222,6 +222,7 @@ struct rockchip_pcie {
        struct  clk *aclk_perf_pcie;
        struct  clk *hclk_pcie;
        struct  clk *clk_pcie_pm;
+       struct  regulator *vpcie12v; /* 12V power supply */
        struct  regulator *vpcie3v3; /* 3.3V power supply */
        struct  regulator *vpcie1v8; /* 1.8V power supply */
        struct  regulator *vpcie0v9; /* 0.9V power supply */
@@ -1018,6 +1019,13 @@ static int rockchip_pcie_parse_dt(struct rockchip_pcie *rockchip)
                return err;
        }
 
+       rockchip->vpcie12v = devm_regulator_get_optional(dev, "vpcie12v");
+       if (IS_ERR(rockchip->vpcie12v)) {
+               if (PTR_ERR(rockchip->vpcie12v) == -EPROBE_DEFER)
+                       return -EPROBE_DEFER;
+               dev_info(dev, "no vpcie12v regulator found\n");
+       }
+
        rockchip->vpcie3v3 = devm_regulator_get_optional(dev, "vpcie3v3");
        if (IS_ERR(rockchip->vpcie3v3)) {
                if (PTR_ERR(rockchip->vpcie3v3) == -EPROBE_DEFER)
@@ -1047,11 +1055,19 @@ static int rockchip_pcie_set_vpcie(struct rockchip_pcie *rockchip)
        struct device *dev = rockchip->dev;
        int err;
 
+       if (!IS_ERR(rockchip->vpcie12v)) {
+               err = regulator_enable(rockchip->vpcie12v);
+               if (err) {
+                       dev_err(dev, "fail to enable vpcie12v regulator\n");
+                       goto err_out;
+               }
+       }
+
        if (!IS_ERR(rockchip->vpcie3v3)) {
                err = regulator_enable(rockchip->vpcie3v3);
                if (err) {
                        dev_err(dev, "fail to enable vpcie3v3 regulator\n");
-                       goto err_out;
+                       goto err_disable_12v;
                }
        }
 
@@ -1079,6 +1095,9 @@ err_disable_1v8:
 err_disable_3v3:
        if (!IS_ERR(rockchip->vpcie3v3))
                regulator_disable(rockchip->vpcie3v3);
+err_disable_12v:
+       if (!IS_ERR(rockchip->vpcie12v))
+               regulator_disable(rockchip->vpcie12v);
 err_out:
        return err;
 }
@@ -1501,6 +1520,8 @@ static int rockchip_pcie_probe(struct platform_device *pdev)
 err_free_res:
        pci_free_resource_list(&res);
 err_vpcie:
+       if (!IS_ERR(rockchip->vpcie12v))
+               regulator_disable(rockchip->vpcie12v);
        if (!IS_ERR(rockchip->vpcie3v3))
                regulator_disable(rockchip->vpcie3v3);
        if (!IS_ERR(rockchip->vpcie1v8))
@@ -1537,6 +1558,8 @@ static int rockchip_pcie_remove(struct platform_device *pdev)
        clk_disable_unprepare(rockchip->aclk_perf_pcie);
        clk_disable_unprepare(rockchip->aclk_pcie);
 
+       if (!IS_ERR(rockchip->vpcie12v))
+               regulator_disable(rockchip->vpcie12v);
        if (!IS_ERR(rockchip->vpcie3v3))
                regulator_disable(rockchip->vpcie3v3);
        if (!IS_ERR(rockchip->vpcie1v8))