diff mbox series

[2/2] PCI: imx: add another regulator for imx pcie

Message ID 1595317470-9394-2-git-send-email-hongxing.zhu@nxp.com
State New
Headers show
Series [1/2] ARM: dts: imx6qp-sabresd: enable pcie | expand

Commit Message

Richard Zhu July 21, 2020, 7:44 a.m. UTC
One more regulator is required to turn on the external oscillator
populated on the iMX6QP SABRESD board.
Add another regulator to enable PCIe on iMX6QP SABRESD board.

Signed-off-by: Richard Zhu <hongxing.zhu@nxp.com>
---
 drivers/pci/controller/dwc/pci-imx6.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/drivers/pci/controller/dwc/pci-imx6.c b/drivers/pci/controller/dwc/pci-imx6.c
index 8f08ae53f53e..9e1563601835 100644
--- a/drivers/pci/controller/dwc/pci-imx6.c
+++ b/drivers/pci/controller/dwc/pci-imx6.c
@@ -81,6 +81,7 @@  struct imx6_pcie {
 	u32			tx_swing_low;
 	int			link_gen;
 	struct regulator	*vpcie;
+	struct regulator	*vepdev;
 	void __iomem		*phy_base;
 
 	/* power domain for pcie */
@@ -507,6 +508,14 @@  static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 			return;
 		}
 	}
+	if (imx6_pcie->vepdev && !regulator_is_enabled(imx6_pcie->vepdev)) {
+		ret = regulator_enable(imx6_pcie->vepdev);
+		if (ret) {
+			dev_err(dev, "failed to enable vepdev regulator: %d\n",
+				ret);
+			goto err_pcie_vepdev;
+		}
+	}
 
 	ret = clk_prepare_enable(imx6_pcie->pcie_phy);
 	if (ret) {
@@ -595,6 +604,13 @@  static void imx6_pcie_deassert_core_reset(struct imx6_pcie *imx6_pcie)
 err_pcie_bus:
 	clk_disable_unprepare(imx6_pcie->pcie_phy);
 err_pcie_phy:
+	if (imx6_pcie->vepdev && regulator_is_enabled(imx6_pcie->vepdev) > 0) {
+		ret = regulator_disable(imx6_pcie->vepdev);
+		if (ret)
+			dev_err(dev, "failed to disable vepdev regulator: %d\n",
+				ret);
+	}
+err_pcie_vepdev:
 	if (imx6_pcie->vpcie && regulator_is_enabled(imx6_pcie->vpcie) > 0) {
 		ret = regulator_disable(imx6_pcie->vpcie);
 		if (ret)
@@ -1178,6 +1194,12 @@  static int imx6_pcie_probe(struct platform_device *pdev)
 			return PTR_ERR(imx6_pcie->vpcie);
 		imx6_pcie->vpcie = NULL;
 	}
+	imx6_pcie->vepdev = devm_regulator_get_optional(&pdev->dev, "vepdev");
+	if (IS_ERR(imx6_pcie->vepdev)) {
+		if (PTR_ERR(imx6_pcie->vepdev) != -ENODEV)
+			return PTR_ERR(imx6_pcie->vepdev);
+		imx6_pcie->vepdev = NULL;
+	}
 
 	platform_set_drvdata(pdev, imx6_pcie);