From d5a3dee65f4ee9d320128bbf79df80d51aec7687 Mon Sep 17 00:00:00 2001 From: Andrey Gusakov Date: Mon, 24 Jul 2017 20:22:03 +0300 Subject: [PATCH] pci: pcie-rcar: add regulators support Add PCIE regulators Signed-off-by: Andrey Gusakov --- drivers/pci/host/pcie-rcar.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/pci/host/pcie-rcar.c b/drivers/pci/host/pcie-rcar.c index 8e24d5f88415..6994ea2ac936 100644 --- a/drivers/pci/host/pcie-rcar.c +++ b/drivers/pci/host/pcie-rcar.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -155,6 +156,8 @@ struct rcar_pcie { int root_bus_nr; struct clk *clk; struct clk *bus_clk; + struct regulator *pcie3v3; /* 3.3V power supply */ + struct regulator *pcie1v8; /* 1.8V power supply */ struct rcar_msi msi; }; @@ -1193,6 +1196,36 @@ static int rcar_pcie_parse_request_of_pci_ranges(struct rcar_pcie *pci) return err; } +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; @@ -1209,6 +1242,26 @@ 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) + 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) + 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"); + goto err_set_pcie; + } + INIT_LIST_HEAD(&pcie->resources); rcar_pcie_parse_request_of_pci_ranges(pcie); @@ -1267,6 +1320,7 @@ static int rcar_pcie_probe(struct platform_device *pdev) err_pm_disable: pm_runtime_disable(dev); +err_set_pcie: return err; } -- 2.13.0