From: Andrey Gusakov <andrey.gusa...@cogentembedded.com>

Add PCIe regulators for KingFisher board.

Signed-off-by: Meng Li <meng...@windriver.com>
---
 arch/arm64/boot/dts/renesas/ulcb-kf.dtsi | 47 +++++++++++++++++
 drivers/pci/controller/pcie-rcar.c       | 64 ++++++++++++++++++++++++
 2 files changed, 111 insertions(+)

diff --git a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi 
b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
index a1e70b52727b..e8d431028fc7 100644
--- a/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
+++ b/arch/arm64/boot/dts/renesas/ulcb-kf.dtsi
@@ -50,6 +50,25 @@
                startup-delay-us = <70000>;
                enable-active-high;
        };
+
+       mpcie_3v3: regulator-mpcie_3v3 {
+               compatible = "regulator-fixed";
+               regulator-name = "mPCIe 3v3";
+               regulator-min-microvolt = <3300000>;
+               regulator-max-microvolt = <3300000>;
+               gpio = <&gpio_exp_77 14 GPIO_ACTIVE_HIGH>;
+               enable-active-high;
+       };
+
+       mpcie_1v8: regulator-mpcie_1v8 {
+               compatible = "regulator-fixed";
+               regulator-name = "mPCIe 1v8";
+               regulator-min-microvolt = <1800000>;
+               regulator-max-microvolt = <1800000>;
+               gpio = <&gpio_exp_77 15 GPIO_ACTIVE_HIGH>;
+               startup-delay-us = <200000>;
+               enable-active-high;
+       };
 };
 
 &can0 {
@@ -233,6 +252,31 @@
                interrupt-controller;
                interrupt-parent = <&gpio5>;
                interrupts = <9 IRQ_TYPE_EDGE_FALLING>;
+
+               mpcie_wake {
+                       gpio-hog;
+                       gpios = <0 GPIO_ACTIVE_HIGH>;
+                       output-low;
+                       line-name = "mPCIe WAKE#";
+               };
+               mpcie_wdisable {
+                       gpio-hog;
+                       gpios = <1 GPIO_ACTIVE_HIGH>;
+                       output-high;
+                       line-name = "mPCIe W_DISABLE";
+               };
+               mpcie_clreq {
+                       gpio-hog;
+                       gpios = <2 GPIO_ACTIVE_HIGH>;
+                       input;
+                       line-name = "mPCIe CLKREQ#";
+               };
+               mpcie_ovc {
+                       gpio-hog;
+                       gpios = <3 GPIO_ACTIVE_HIGH>;
+                       input;
+                       line-name = "mPCIe OVC";
+               };
        };
 
        i2cswitch4: i2c-switch@71 {
@@ -259,6 +303,9 @@
 
 &pciec1 {
        status = "okay";
+
+       pcie3v3-supply = <&mpcie_3v3>;
+       pcie1v8-supply = <&mpcie_1v8>;
 };
 
 &pfc {
diff --git a/drivers/pci/controller/pcie-rcar.c 
b/drivers/pci/controller/pcie-rcar.c
index f6a669a9af41..8e7e714e33fd 100644
--- a/drivers/pci/controller/pcie-rcar.c
+++ b/drivers/pci/controller/pcie-rcar.c
@@ -14,6 +14,7 @@
 #include <linux/bitops.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/regulator/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
@@ -151,6 +152,8 @@ struct rcar_pcie {
        struct list_head        resources;
        int                     root_bus_nr;
        struct clk              *bus_clk;
+       struct regulator        *pcie3v3; /* 3.3V power supply */
+       struct regulator        *pcie1v8; /* 1.8V power supply */
        struct                  rcar_msi msi;
 };
 
@@ -1120,6 +1123,36 @@ static const struct of_device_id rcar_pcie_of_match[] = {
        {},
 };
 
+static int rcar_pcie_set_vpcie(struct rcar_pcie *pcie)
+{
+       struct device *dev = pcie->dev;
+       int err;
+
+       if (!IS_ERR(pcie->pcie3v3)) {
+               err = regulator_enable(pcie->pcie3v3);
+               if (err) {
+                       dev_err(dev, "fail to enable vpcie3v3 regulator\n");
+                       goto err_out;
+               }
+       }
+
+       if (!IS_ERR(pcie->pcie1v8)) {
+               err = regulator_enable(pcie->pcie1v8);
+               if (err) {
+                       dev_err(dev, "fail to enable vpcie1v8 regulator\n");
+                       goto err_disable_3v3;
+               }
+       }
+
+       return 0;
+
+err_disable_3v3:
+       if (!IS_ERR(pcie->pcie3v3))
+               regulator_disable(pcie->pcie3v3);
+err_out:
+       return err;
+}
+
 static int rcar_pcie_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
@@ -1138,6 +1171,31 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        pcie->dev = dev;
        platform_set_drvdata(pdev, pcie);
 
+       pcie->pcie3v3 = devm_regulator_get_optional(dev, "pcie3v3");
+       if (IS_ERR(pcie->pcie3v3)) {
+               if (PTR_ERR(pcie->pcie3v3) == -EPROBE_DEFER) {
+                       pci_free_host_bridge(bridge);
+                       return -EPROBE_DEFER;
+               }
+               dev_info(dev, "no pcie3v3 regulator found\n");
+       }
+
+       pcie->pcie1v8 = devm_regulator_get_optional(dev, "pcie1v8");
+       if (IS_ERR(pcie->pcie1v8)) {
+               if (PTR_ERR(pcie->pcie1v8) == -EPROBE_DEFER) {
+                       pci_free_host_bridge(bridge);
+                       return -EPROBE_DEFER;
+               }
+               dev_info(dev, "no pcie1v8 regulator found\n");
+       }
+
+       err = rcar_pcie_set_vpcie(pcie);
+       if (err) {
+               dev_err(dev, "failed to set pcie regulators\n");
+               pci_free_host_bridge(bridge);
+               return err;
+       }
+
        err = pci_parse_request_of_pci_ranges(dev, &pcie->resources, NULL);
        if (err)
                goto err_free_bridge;
@@ -1223,6 +1281,12 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        pci_free_resource_list(&pcie->resources);
 
 err_free_bridge:
+       if(!IS_ERR(pcie->pcie3v3))
+               if (regulator_is_enabled(pcie->pcie3v3))
+                       regulator_disable(pcie->pcie3v3);
+       if(!IS_ERR(pcie->pcie1v8))
+               if (regulator_is_enabled(pcie->pcie1v8))
+                       regulator_disable(pcie->pcie1v8);
        pci_free_host_bridge(bridge);
 
        return err;
-- 
2.18.1

-- 
_______________________________________________
linux-yocto mailing list
linux-yocto@yoctoproject.org
https://lists.yoctoproject.org/listinfo/linux-yocto

Reply via email to