From: Jaedon Shin <jaedon.shin@gmail.com>
To: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>,
Florian Fainelli <f.fainelli@gmail.com>,
bcm-kernel-feedback-list@broadcom.com
Cc: Bjorn Helgaas <bhelgaas@google.com>,
Rob Herring <robh+dt@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Andrew Murray <amurray@thegoodpenguin.co.uk>,
Gregory Fong <gregory.0xf0@gmail.com>,
Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-pci@vger.kernel.org, Jaedon Shin <jaedon.shin@gmail.com>
Subject: [PATCH 2/3] PCI: brcmstb: Add regulator support
Date: Thu, 13 Feb 2020 11:59:29 +0900 [thread overview]
Message-ID: <20200213025930.27943-3-jaedon.shin@gmail.com> (raw)
In-Reply-To: <20200213025930.27943-1-jaedon.shin@gmail.com>
ARM-based Broadcom STB SoCs have GPIO-based voltage regulator for PCIe
turning off/on power supplies.
Signed-off-by: Jaedon Shin <jaedon.shin@gmail.com>
---
drivers/gpio/gpio-brcmstb.c | 13 ++++-
drivers/pci/controller/pcie-brcmstb.c | 76 +++++++++++++++++++++++++++
2 files changed, 88 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpio-brcmstb.c b/drivers/gpio/gpio-brcmstb.c
index 05e3f99ae59c..0cee5fcd2782 100644
--- a/drivers/gpio/gpio-brcmstb.c
+++ b/drivers/gpio/gpio-brcmstb.c
@@ -777,7 +777,18 @@ static struct platform_driver brcmstb_gpio_driver = {
.remove = brcmstb_gpio_remove,
.shutdown = brcmstb_gpio_shutdown,
};
-module_platform_driver(brcmstb_gpio_driver);
+
+static int __init brcmstb_gpio_init(void)
+{
+ return platform_driver_register(&brcmstb_gpio_driver);
+}
+subsys_initcall(brcmstb_gpio_init);
+
+static void __exit brcmstb_gpio_exit(void)
+{
+ platform_driver_unregister(&brcmstb_gpio_driver);
+}
+module_exit(brcmstb_gpio_exit);
MODULE_AUTHOR("Gregory Fong");
MODULE_DESCRIPTION("Driver for Broadcom BRCMSTB SoC UPG GPIO");
diff --git a/drivers/pci/controller/pcie-brcmstb.c b/drivers/pci/controller/pcie-brcmstb.c
index 34581a6a7313..0e0ca39a680b 100644
--- a/drivers/pci/controller/pcie-brcmstb.c
+++ b/drivers/pci/controller/pcie-brcmstb.c
@@ -23,6 +23,7 @@
#include <linux/of_platform.h>
#include <linux/pci.h>
#include <linux/printk.h>
+#include <linux/regulator/consumer.h>
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/string.h>
@@ -173,8 +174,79 @@ struct brcm_pcie {
int gen;
u64 msi_target_addr;
struct brcm_msi *msi;
+#ifdef CONFIG_REGULATOR
+ int num_regs;
+ struct regulator **regs;
+#endif
};
+#ifdef CONFIG_REGULATOR
+static void brcm_pcie_regulator_enable(struct brcm_pcie *pcie)
+{
+ int i, ret;
+
+ for (i = 0; i < pcie->num_regs; i++) {
+ if (!pcie->regs[i])
+ continue;
+
+ ret = regulator_enable(pcie->regs[i]);
+ if (ret)
+ dev_err(pcie->dev, "Failed to enable regulator\n");
+ }
+}
+
+static void brcm_pcie_regulator_disable(struct brcm_pcie *pcie)
+{
+ int i, ret;
+
+ for (i = 0; i < pcie->num_regs; i++) {
+ if (!pcie->regs[i])
+ continue;
+
+ ret = regulator_disable(pcie->regs[i]);
+ if (ret)
+ dev_err(pcie->dev, "Failed to disable regulator\n");
+ }
+}
+
+static void brcm_pcie_regulator_init(struct brcm_pcie *pcie)
+{
+ struct device_node *np = pcie->dev->of_node;
+ struct device *dev = pcie->dev;
+ const char *name;
+ struct regulator *reg;
+ int i;
+
+ pcie->num_regs = of_property_count_strings(np, "supply-names");
+ if (pcie->num_regs <= 0) {
+ pcie->num_regs = 0;
+ return;
+ }
+
+ pcie->regs = devm_kcalloc(dev, pcie->num_regs, sizeof(pcie->regs[0]),
+ GFP_KERNEL);
+ if (!pcie->regs) {
+ pcie->num_regs = 0;
+ return;
+ }
+
+ for (i = 0; i < pcie->num_regs; i++) {
+ if (of_property_read_string_index(np, "supply-names", i, &name))
+ continue;
+
+ reg = devm_regulator_get_optional(dev, name);
+ if (IS_ERR(reg))
+ continue;
+
+ pcie->regs[i] = reg;
+ }
+}
+#else
+static inline void brcm_pcie_regulator_enable(struct brcm_pcie *pcie) { }
+static inline void brcm_pcie_regulator_disable(struct brcm_pcie *pcie) { }
+static inline void brcm_pcie_regulator_init(struct brcm_pcie *pcie) { }
+#endif
+
/*
* This is to convert the size of the inbound "BAR" region to the
* non-linear values of PCIE_X_MISC_RC_BAR[123]_CONFIG_LO.SIZE
@@ -898,6 +970,7 @@ static void __brcm_pcie_remove(struct brcm_pcie *pcie)
{
brcm_msi_remove(pcie);
brcm_pcie_turn_off(pcie);
+ brcm_pcie_regulator_disable(pcie);
clk_disable_unprepare(pcie->clk);
clk_put(pcie->clk);
}
@@ -955,6 +1028,9 @@ static int brcm_pcie_probe(struct platform_device *pdev)
return ret;
}
+ brcm_pcie_regulator_init(pcie);
+ brcm_pcie_regulator_enable(pcie);
+
ret = brcm_pcie_setup(pcie);
if (ret)
goto fail;
--
2.21.0
next prev parent reply other threads:[~2020-02-13 2:59 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-13 2:59 [PATCH 0/3] PCI: brcmstb: Add Broadcom STB support Jaedon Shin
2020-02-13 2:59 ` [PATCH 1/3] PCI: brcmstb: Enable ARCH_BRCMSTB Jaedon Shin
2020-02-13 3:58 ` Florian Fainelli
2020-02-13 2:59 ` Jaedon Shin [this message]
2020-02-13 3:58 ` [PATCH 2/3] PCI: brcmstb: Add regulator support Florian Fainelli
2020-02-20 11:07 ` Gregory Fong
2020-02-13 15:25 ` Jim Quinlan
2020-02-14 10:06 ` Linus Walleij
2020-02-14 11:52 ` Mark Brown
2020-02-14 11:01 ` Nicolas Saenz Julienne
2020-02-13 2:59 ` [PATCH 3/3] PCI: brcmstb: Drop clk_put when probe fails and remove Jaedon Shin
2020-02-13 4:01 ` Florian Fainelli
2020-02-14 10:55 ` Nicolas Saenz Julienne
2020-02-13 3:54 ` [PATCH 0/3] PCI: brcmstb: Add Broadcom STB support Florian Fainelli
2020-02-13 5:15 ` Jaedon Shin
2020-02-13 15:54 ` Jim Quinlan
2020-02-14 2:16 ` Jaedon Shin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200213025930.27943-3-jaedon.shin@gmail.com \
--to=jaedon.shin@gmail.com \
--cc=amurray@thegoodpenguin.co.uk \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=bgolaszewski@baylibre.com \
--cc=bhelgaas@google.com \
--cc=f.fainelli@gmail.com \
--cc=gregory.0xf0@gmail.com \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=mark.rutland@arm.com \
--cc=nsaenzjulienne@suse.de \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).