linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: f.fainelli@gmail.com, Saenz Julienne <nsaenzjulienne@suse.de>,
	bcm-kernel-feedback-list@broadcom.com,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	Lee Jones <lee.jones@linaro.org>, Ray Jui <rjui@broadcom.com>,
	Scott Branden <sbranden@broadcom.com>
Cc: phil@raspberrypi.com, wahrenst@gmx.net, linux-kernel@vger.kernel.org
Subject: [RFC/PATCH 04/11] mfd: bcm2835-pm: Add support for BCM2711
Date: Fri,  5 Feb 2021 14:52:40 +0100	[thread overview]
Message-ID: <20210205135249.2924-5-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20210205135249.2924-1-nsaenzjulienne@suse.de>

In BCM2711 the new ARGON ASB took over V3D. The old ASB is still present
with the ISP and H264 bits, and V3D is in the same place in the new ASB
as the old one.

As per the devicetree bindings, BCM2711 will provide both the old and
new ASB registers, so get both of them and pass them into
'bcm2835-power,' which will take care of selecting which one to use
accordingly.

We're being extra careful when dealing with older firmware. We can't
assume all V3D users will use the new "brcm,bcm2711-pm" compatible
string, so use the fact that a 3rd resource is present in firmware as a
hint we're running on BCM2711.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/mfd/bcm2835-pm.c       | 55 ++++++++++++++++++++++++++--------
 include/linux/mfd/bcm2835-pm.h |  1 +
 2 files changed, 43 insertions(+), 13 deletions(-)

diff --git a/drivers/mfd/bcm2835-pm.c b/drivers/mfd/bcm2835-pm.c
index 42fe67f1538e..98c6943d3cd0 100644
--- a/drivers/mfd/bcm2835-pm.c
+++ b/drivers/mfd/bcm2835-pm.c
@@ -6,6 +6,7 @@
  * the WDT and power drivers.
  */
 
+#include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/mfd/bcm2835-pm.h>
@@ -17,6 +18,9 @@
 #include <linux/types.h>
 #include <linux/watchdog.h>
 
+#define BCM2835		BIT(1)
+#define BCM2711		BIT(2)
+
 static const struct mfd_cell bcm2835_pm_devs[] = {
 	{ .name = "bcm2835-wdt" },
 };
@@ -30,6 +34,7 @@ static int bcm2835_pm_probe(struct platform_device *pdev)
 	struct resource *res;
 	struct device *dev = &pdev->dev;
 	struct bcm2835_pm *pm;
+	bool is_bcm2711;
 	int ret;
 
 	pm = devm_kzalloc(dev, sizeof(*pm), GFP_KERNEL);
@@ -38,6 +43,7 @@ static int bcm2835_pm_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, pm);
 
 	pm->dev = dev;
+	is_bcm2711 = (uintptr_t)device_get_match_data(&pdev->dev) & BCM2711;
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	pm->base = devm_ioremap_resource(dev, res);
@@ -50,30 +56,53 @@ static int bcm2835_pm_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	/* We'll use the presence of the AXI ASB regs in the
-	 * bcm2835-pm binding as the key for whether we can reference
-	 * the full PM register range and support power domains.
+	/* To support old firmware, check if a third resource was defined and
+	 * use that as a hint that we're on bcm2711.
 	 */
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
+	if (res) {
+		pm->arsan_asb = devm_ioremap_resource(dev, res);
+		if (IS_ERR(pm->arsan_asb)) {
+			dev_err(dev, "Failed to map Arsan ASB: %ld\n",
+				PTR_ERR(pm->arsan_asb));
+			return PTR_ERR(pm->arsan_asb);
+		}
+
+		if (!is_bcm2711) {
+			dev_warn(dev, "Using an outdated DT, please update it\n");
+			is_bcm2711 = true;
+		}
+	}
+
+	if (is_bcm2711 && !pm->arsan_asb) {
+		dev_err(dev, "Arsan ASB resource missing\n");
+		return -EINVAL;
+	}
+
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (res) {
 		pm->asb = devm_ioremap_resource(dev, res);
-		if (IS_ERR(pm->asb))
+		if (IS_ERR(pm->asb)) {
+			dev_err(dev, "Failed to map ASB: %ld\n", PTR_ERR(pm->asb));
 			return PTR_ERR(pm->asb);
-
-		ret = devm_mfd_add_devices(dev, -1,
-					   bcm2835_power_devs,
-					   ARRAY_SIZE(bcm2835_power_devs),
-					   NULL, 0, NULL);
-		if (ret)
-			return ret;
+		}
 	}
 
+	/* We'll use the presence of the ASB regs in the bcm2835-pm binding as
+	 * the key for whether we can reference the full PM register range and
+	 * support power domains.
+	 */
+	if (pm->asb)
+		return devm_mfd_add_devices(dev, -1, bcm2835_power_devs,
+					    ARRAY_SIZE(bcm2835_power_devs),
+					    NULL, 0, NULL);
 	return 0;
 }
 
 static const struct of_device_id bcm2835_pm_of_match[] = {
-	{ .compatible = "brcm,bcm2835-pm-wdt", },
-	{ .compatible = "brcm,bcm2835-pm", },
+	{ .compatible = "brcm,bcm2835-pm-wdt", .data = (void *)BCM2835},
+	{ .compatible = "brcm,bcm2835-pm", .data = (void *)BCM2835},
+	{ .compatible = "brcm,bcm2711-pm", .data = (void *)BCM2711},
 	{},
 };
 MODULE_DEVICE_TABLE(of, bcm2835_pm_of_match);
diff --git a/include/linux/mfd/bcm2835-pm.h b/include/linux/mfd/bcm2835-pm.h
index ed37dc40e82a..536e3c85347c 100644
--- a/include/linux/mfd/bcm2835-pm.h
+++ b/include/linux/mfd/bcm2835-pm.h
@@ -9,6 +9,7 @@ struct bcm2835_pm {
 	struct device *dev;
 	void __iomem *base;
 	void __iomem *asb;
+	void __iomem *arsan_asb;
 };
 
 #endif /* BCM2835_MFD_PM_H */
-- 
2.30.0


  parent reply	other threads:[~2021-02-05 13:59 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05 13:52 [RFC/PATCH 00/11] Raspberry PI 4 V3D enablement Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 01/11] dt-bindings: soc: bcm: bcm2835-pm: Convert bindings to DT schema Nicolas Saenz Julienne
2021-02-06 11:34   ` Stefan Wahren
2021-02-05 13:52 ` [RFC/PATCH 02/11] dt-bindings: soc: bcm: brcm,bcm2835-pm: Add support for bcm2711 Nicolas Saenz Julienne
2021-02-06 11:36   ` Stefan Wahren
2021-02-05 13:52 ` [RFC/PATCH 03/11] ARM: dts: bcm2711: Use proper compatible in PM/Watchdog node Nicolas Saenz Julienne
2021-02-05 13:52 ` Nicolas Saenz Julienne [this message]
2021-02-05 13:52 ` [RFC/PATCH 05/11] soc: bcm: bcm2835-power: Add support for BCM2711's ARSAN ASB Nicolas Saenz Julienne
2021-02-05 16:56   ` Florian Fainelli
2021-02-05 18:30     ` Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 06/11] soc: bcm: bcm2835-power: Bypass power_on/off() calls Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 07/11] drm/v3d: Get rid of pm code Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 08/11] drm/v3d: Add support for bcm2711 Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 09/11] ARM: dts: bcm2711: Enable V3D Nicolas Saenz Julienne
2021-02-06 11:50   ` Stefan Wahren
2021-02-05 13:52 ` [RFC/PATCH 10/11] ARM: configs: Enable DRM_V3D Nicolas Saenz Julienne
2021-02-05 13:52 ` [RFC/PATCH 11/11] arm64: config: " Nicolas Saenz Julienne

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=20210205135249.2924-5-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=phil@raspberrypi.com \
    --cc=rjui@broadcom.com \
    --cc=sbranden@broadcom.com \
    --cc=wahrenst@gmx.net \
    /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).