[linux-yocto] [PATCH 3/5] pci: pcie-rcar: add regulators support

2019-10-24 Thread Meng.Li
From: Andrey Gusakov 

Add PCIe regulators for KingFisher board.

Signed-off-by: Meng Li 
---
 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 8986a7e6e099..82e463c32a37 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 = <7>;
enable-active-high;
};
+
+   mpcie_3v3: regulator-mpcie_3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "mPCIe 3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   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 = <180>;
+   regulator-max-microvolt = <180>;
+   gpio = <_exp_77 15 GPIO_ACTIVE_HIGH>;
+   startup-delay-us = <20>;
+   enable-active-high;
+   };
 };
 
  {
@@ -241,6 +260,31 @@
interrupt-controller;
interrupt-parent = <>;
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";
+   };
};
 };
 
@@ -259,6 +303,9 @@
 
  {
status = "okay";
+
+   pcie3v3-supply = <_3v3>;
+   pcie1v8-supply = <_1v8>;
 };
 
  {
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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -151,6 +152,8 @@ struct rcar_pcie {
struct list_headresources;
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 = >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;
+  

[linux-yocto] [PATCH 3/5] pci: pcie-rcar: add regulators support

2019-10-24 Thread Meng.Li
From: Andrey Gusakov 

Add PCIe regulators for KingFisher board.

Signed-off-by: Meng Li 
---
 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 8986a7e6e099..82e463c32a37 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 = <7>;
enable-active-high;
};
+
+   mpcie_3v3: regulator-mpcie_3v3 {
+   compatible = "regulator-fixed";
+   regulator-name = "mPCIe 3v3";
+   regulator-min-microvolt = <330>;
+   regulator-max-microvolt = <330>;
+   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 = <180>;
+   regulator-max-microvolt = <180>;
+   gpio = <_exp_77 15 GPIO_ACTIVE_HIGH>;
+   startup-delay-us = <20>;
+   enable-active-high;
+   };
 };
 
  {
@@ -241,6 +260,31 @@
interrupt-controller;
interrupt-parent = <>;
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";
+   };
};
 };
 
@@ -259,6 +303,9 @@
 
  {
status = "okay";
+
+   pcie3v3-supply = <_3v3>;
+   pcie1v8-supply = <_1v8>;
 };
 
  {
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 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -151,6 +152,8 @@ struct rcar_pcie {
struct list_headresources;
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 = >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;
+