mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 17/18] ARM: rockchip: rk3588: add memsize detection
Date: Thu,  4 May 2023 10:17:44 +0200	[thread overview]
Message-ID: <20230504081745.305841-18-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20230504081745.305841-1-s.hauer@pengutronix.de>

Extend the DMC driver for rk3588

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-rockchip/dmc.c | 52 +++++++++++++++++++++++++++++++-----
 include/mach/rockchip/dmc.h  |  1 +
 2 files changed, 47 insertions(+), 6 deletions(-)

diff --git a/arch/arm/mach-rockchip/dmc.c b/arch/arm/mach-rockchip/dmc.c
index dd60db5830..85fa8acd19 100644
--- a/arch/arm/mach-rockchip/dmc.c
+++ b/arch/arm/mach-rockchip/dmc.c
@@ -29,6 +29,8 @@
 struct rockchip_dmc_drvdata {
 	unsigned int os_reg2;
 	unsigned int os_reg3;
+	unsigned int os_reg4;
+	unsigned int os_reg5;
 	resource_size_t internal_registers_start;
 };
 
@@ -151,12 +153,39 @@ resource_size_t rk3568_ram0_size(void)
 	return size;
 }
 
+#define RK3588_PMUGRF_BASE 0xfd58a000
+#define RK3588_PMUGRF_OS_REG2           0x208
+#define RK3588_PMUGRF_OS_REG3           0x20c
+#define RK3588_PMUGRF_OS_REG4           0x210
+#define RK3588_PMUGRF_OS_REG5           0x214
+
+resource_size_t rk3588_ram0_size(void)
+{
+	void __iomem *pmugrf = IOMEM(RK3588_PMUGRF_BASE);
+	u32 sys_reg2, sys_reg3, sys_reg4, sys_reg5;
+	resource_size_t size, size1, size2;
+
+	sys_reg2 = readl(pmugrf + RK3588_PMUGRF_OS_REG2);
+	sys_reg3 = readl(pmugrf + RK3588_PMUGRF_OS_REG3);
+	sys_reg4 = readl(pmugrf + RK3588_PMUGRF_OS_REG4);
+	sys_reg5 = readl(pmugrf + RK3588_PMUGRF_OS_REG5);
+
+	size1 = rockchip_sdram_size(sys_reg2, sys_reg3);
+	size2 = rockchip_sdram_size(sys_reg4, sys_reg5);
+
+	pr_info("%s() size1 = %llu, size2 = %llu\n", __func__, (u64)size1, (u64)size2);
+
+	size = min_t(resource_size_t, RK3568_INT_REG_START, size1 + size2);
+
+	return size;
+}
+
 static int rockchip_dmc_probe(struct device *dev)
 {
 	const struct rockchip_dmc_drvdata *drvdata;
 	resource_size_t membase, memsize;
 	struct regmap *regmap;
-	u32 sys_reg2, sys_reg3;
+	u32 sys_rega, sys_regb;
 
 	regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "rockchip,pmu");
 	if (IS_ERR(regmap))
@@ -166,10 +195,15 @@ static int rockchip_dmc_probe(struct device *dev)
 	if (!drvdata)
 		return -ENOENT;
 
-	regmap_read(regmap, drvdata->os_reg2, &sys_reg2);
-	regmap_read(regmap, drvdata->os_reg3, &sys_reg3);
+	regmap_read(regmap, drvdata->os_reg2, &sys_rega);
+	regmap_read(regmap, drvdata->os_reg3, &sys_regb);
+	memsize = rockchip_sdram_size(sys_rega, sys_regb);
 
-	memsize = rockchip_sdram_size(sys_reg2, sys_reg3);
+	if (drvdata->os_reg4) {
+		regmap_read(regmap, drvdata->os_reg4, &sys_rega);
+		regmap_read(regmap, drvdata->os_reg5, &sys_regb);
+		memsize += rockchip_sdram_size(sys_rega, sys_regb);
+	}
 
 	dev_info(dev, "Detected memory size: %pa\n", &memsize);
 
@@ -194,8 +228,10 @@ static const struct rockchip_dmc_drvdata rk3399_drvdata = {
 };
 
 static const struct rockchip_dmc_drvdata rk3568_drvdata = {
-	.os_reg2 = RK3568_PMUGRF_OS_REG2,
-	.os_reg3 = RK3568_PMUGRF_OS_REG3,
+	.os_reg2 = RK3588_PMUGRF_OS_REG2,
+	.os_reg3 = RK3588_PMUGRF_OS_REG3,
+	.os_reg4 = RK3588_PMUGRF_OS_REG4,
+	.os_reg5 = RK3588_PMUGRF_OS_REG5,
 	.internal_registers_start = RK3568_INT_REG_START,
 };
 
@@ -208,6 +244,10 @@ static struct of_device_id rockchip_dmc_dt_ids[] = {
 		.compatible = "rockchip,rk3568-dmc",
 		.data = &rk3568_drvdata,
 	},
+	{
+		.compatible = "rockchip,rk3588-dmc",
+		.data = &rk3568_drvdata,
+	},
 	{ /* sentinel */ }
 };
 
diff --git a/include/mach/rockchip/dmc.h b/include/mach/rockchip/dmc.h
index ff197d50a0..ed256f6daf 100644
--- a/include/mach/rockchip/dmc.h
+++ b/include/mach/rockchip/dmc.h
@@ -82,5 +82,6 @@ enum {
 
 resource_size_t rk3399_ram0_size(void);
 resource_size_t rk3568_ram0_size(void);
+resource_size_t rk3588_ram0_size(void);
 
 #endif
-- 
2.39.2




  parent reply	other threads:[~2023-05-04  8:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-04  8:17 [PATCH 00/18] Add Rockchip RK3588 support Sascha Hauer
2023-05-04  8:17 ` [PATCH 01/18] firmware: make drivers/firmware/ obj-y Sascha Hauer
2023-05-04  8:17 ` [PATCH 02/18] stddef: add sizeof_field() Sascha Hauer
2023-05-04  8:17 ` [PATCH 03/18] pci: add pci_select_bars() helper Sascha Hauer
2023-05-04  8:17 ` [PATCH 04/18] pci: set upper word for 64bit base addresses Sascha Hauer
2023-05-04  8:17 ` [PATCH 05/18] ARM: SCMI: Use correct smc/hvc instructions on ARM64 Sascha Hauer
2023-05-04  8:17 ` [PATCH 06/18] clk: rockchip: Add rk3588 support Sascha Hauer
2023-05-04  8:17 ` [PATCH 07/18] pinctrl: rockchip: Move struct definitions to separate header file Sascha Hauer
2023-05-04  8:17 ` [PATCH 08/18] pinctrl/gpio: rockchip: separate gpio from pinctrl driver Sascha Hauer
2023-05-04  8:17 ` [PATCH 09/18] pinctrl: Update pinctrl-rockchip from kernel Sascha Hauer
2023-05-04  8:17 ` [PATCH 10/18] phy: rockchip: naneng-combphy: add rk3588 support Sascha Hauer
2023-05-04  8:17 ` [PATCH 11/18] reset: Implement reset array support Sascha Hauer
2023-05-04  8:17 ` [PATCH 12/18] pci: designware: add rockchip support Sascha Hauer
2023-05-04  8:17 ` [PATCH 13/18] phy: realtek: Add RTL8125 internal phy support Sascha Hauer
2023-05-04  8:17 ` [PATCH 14/18] net: Update Realtek r8169 driver Sascha Hauer
2023-05-04  8:17 ` [PATCH 15/18] ARM: rockchip: Add rk3588 support Sascha Hauer
2023-05-04  8:17 ` [PATCH 16/18] ARM: dts: Add rk3588 device trees Sascha Hauer
2023-05-04  8:17 ` Sascha Hauer [this message]
2023-05-04  8:17 ` [PATCH 18/18] ARM: rockchip: Add Radxa ROCK 5B support Sascha Hauer
2023-05-04  9:36   ` Ahmad Fatoum
2023-05-04 10:08     ` Sascha Hauer

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=20230504081745.305841-18-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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