PCI: rcar-host: Add support for optional regulators
authorWolfram Sang <wsa+renesas@sang-engineering.com>
Sun, 5 Nov 2023 09:29:08 +0000 (10:29 +0100)
committerKrzysztof Wilczyński <kwilczynski@kernel.org>
Thu, 14 Dec 2023 19:10:16 +0000 (19:10 +0000)
The KingFisher board has regulators for miniPCIe, so enable these
optional regulators using devm. devm will automatically disable them
when the driver releases the device. Order variables in reverse-xmas
while we are here.

[kwilczynski: update style to match rest of the code]
Link: https://lore.kernel.org/linux-pci/20231105092908.3792-3-wsa+renesas@sang-engineering.com
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Manivannan Sadhasivam <mani@kernel.org>
drivers/pci/controller/pcie-rcar-host.c

index bf7cc0b6a695736f8b9a27af05fe23c3778369e3..996077ab7cfdb88f2061c82370822b8f3f5776e7 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 
 #include "pcie-rcar.h"
 
@@ -953,14 +954,22 @@ static const struct of_device_id rcar_pcie_of_match[] = {
        {},
 };
 
+/* Design note 346 from Linear Technology says order is not important. */
+static const char * const rcar_pcie_supplies[] = {
+       "vpcie1v5",
+       "vpcie3v3",
+       "vpcie12v",
+};
+
 static int rcar_pcie_probe(struct platform_device *pdev)
 {
        struct device *dev = &pdev->dev;
+       struct pci_host_bridge *bridge;
        struct rcar_pcie_host *host;
        struct rcar_pcie *pcie;
+       unsigned int i;
        u32 data;
        int err;
-       struct pci_host_bridge *bridge;
 
        bridge = devm_pci_alloc_host_bridge(dev, sizeof(*host));
        if (!bridge)
@@ -971,6 +980,13 @@ static int rcar_pcie_probe(struct platform_device *pdev)
        pcie->dev = dev;
        platform_set_drvdata(pdev, host);
 
+       for (i = 0; i < ARRAY_SIZE(rcar_pcie_supplies); i++) {
+               err = devm_regulator_get_enable_optional(dev, rcar_pcie_supplies[i]);
+               if (err < 0 && err != -ENODEV)
+                       return dev_err_probe(dev, err, "failed to enable regulator: %s\n",
+                                            rcar_pcie_supplies[i]);
+       }
+
        pm_runtime_enable(pcie->dev);
        err = pm_runtime_get_sync(pcie->dev);
        if (err < 0) {