mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 06/31] ARM: K3: add am62lx base support
Date: Wed, 28 May 2025 13:45:18 +0200	[thread overview]
Message-ID: <20250528-arm-k3-am62l-v1-6-3f88e6d10d99@pengutronix.de> (raw)
In-Reply-To: <20250528-arm-k3-am62l-v1-0-3f88e6d10d99@pengutronix.de>

This adds the MACH_AM62LX Kconfig symbol to be selected by the boards
and the AM62l bootsource detection.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-k3/Kconfig  |   3 +
 arch/arm/mach-k3/Makefile |   1 +
 arch/arm/mach-k3/am62lx.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-k3/common.c |   5 +-
 include/mach/k3/common.h  |   1 +
 5 files changed, 164 insertions(+), 1 deletion(-)

diff --git a/arch/arm/mach-k3/Kconfig b/arch/arm/mach-k3/Kconfig
index 1c236ef7648869ff3605bfb379298f0e6e6f3305..cda44807e8a1db7c2f701309948c7bd1a863d365 100644
--- a/arch/arm/mach-k3/Kconfig
+++ b/arch/arm/mach-k3/Kconfig
@@ -6,6 +6,9 @@ menu "K3 boards"
 config MACH_AM62X
 	bool
 
+config MACH_AM62LX
+	bool
+
 config MACH_K3_CORTEX_R5
 	bool
 	select CPU_V7
diff --git a/arch/arm/mach-k3/Makefile b/arch/arm/mach-k3/Makefile
index b81088007426a1e2a43d84a0d09b49525370c4bf..050d12a32a6720170a007931fee8a621a0326dd2 100644
--- a/arch/arm/mach-k3/Makefile
+++ b/arch/arm/mach-k3/Makefile
@@ -1,5 +1,6 @@
 obj-y += common.o
 obj-$(CONFIG_MACH_AM62X) += am62x.o
+obj-$(CONFIG_MACH_AM62LX) += am62lx.o
 obj-pbl-$(CONFIG_MACH_K3_CORTEX_R5) += r5.o
 obj-pbl-y += ddrss.o
 obj-$(CONFIG_BAREBOX_UPDATE) += bbu.o
diff --git a/arch/arm/mach-k3/am62lx.c b/arch/arm/mach-k3/am62lx.c
new file mode 100644
index 0000000000000000000000000000000000000000..38a88ea7cf95be110a4125807630db10d402534e
--- /dev/null
+++ b/arch/arm/mach-k3/am62lx.c
@@ -0,0 +1,155 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <io.h>
+#include <of.h>
+#include <init.h>
+#include <linux/bits.h>
+#include <linux/bitfield.h>
+#include <pm_domain.h>
+#include <bootsource.h>
+#include <mach/k3/common.h>
+
+/* Primary BootMode devices */
+#define BOOT_DEVICE_SPI_NAND		0x00
+#define BOOT_DEVICE_RAM			0xFF
+#define BOOT_DEVICE_OSPI		0x01
+#define BOOT_DEVICE_QSPI		0x02
+#define BOOT_DEVICE_SPI			0x03
+#define BOOT_DEVICE_UART		0x07
+#define BOOT_DEVICE_MMC			0x08
+#define BOOT_DEVICE_EMMC		0x09
+#define BOOT_DEVICE_USB			0x0A
+#define BOOT_DEVICE_DFU			0x0A
+#define BOOT_DEVICE_GPMC_NAND		0x0B
+#define BOOT_DEVICE_XSPI_FAST		0x0D
+#define BOOT_DEVICE_XSPI		0x0E
+#define BOOT_DEVICE_NOBOOT		0x0F
+
+/* U-Boot used aliases */
+#define BOOT_DEVICE_SPINAND		0x10
+#define BOOT_DEVICE_MMC2		BOOT_DEVICE_MMC
+#define BOOT_DEVICE_MMC1		BOOT_DEVICE_EMMC
+/* Invalid Choices for the AM62Lx */
+#define BOOT_DEVICE_MMC2_2		0x1F
+#define BOOT_DEVICE_ETHERNET		0x1F
+
+/* Backup BootMode devices */
+#define BACKUP_BOOT_DEVICE_USB		0x01
+#define BACKUP_BOOT_DEVICE_DFU		0x01
+#define BACKUP_BOOT_DEVICE_UART		0x03
+#define BACKUP_BOOT_DEVICE_MMC		0x05
+#define BACKUP_BOOT_DEVICE_SPI		0x06
+
+#define K3_PRIMARY_BOOTMODE		0x0
+
+#define MAIN_DEVSTAT_BACKUP_BOOTMODE		GENMASK(12, 10)
+#define MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG	BIT(13)
+#define MAIN_DEVSTAT_BACKUP_USB_MODE		BIT(0)
+
+static void am62lx_get_backup_bootsource(u32 devstat, enum bootsource *src, int *instance)
+{
+	u32 bkup_bootmode = FIELD_GET(MAIN_DEVSTAT_BACKUP_BOOTMODE, devstat);
+	u32 bkup_bootmode_cfg = FIELD_GET(MAIN_DEVSTAT_BACKUP_BOOTMODE_CFG, devstat);
+
+	*src = BOOTSOURCE_UNKNOWN;
+
+	switch (bkup_bootmode) {
+	case BACKUP_BOOT_DEVICE_UART:
+		*src = BOOTSOURCE_SERIAL;
+		return;
+	case BACKUP_BOOT_DEVICE_MMC:
+		if (bkup_bootmode_cfg) {
+			*src = BOOTSOURCE_MMC;
+			*instance = 1;
+		} else {
+			*src = BOOTSOURCE_MMC;
+			*instance = 0;
+		}
+		return;
+	case BACKUP_BOOT_DEVICE_SPI:
+		*src = BOOTSOURCE_SPI;
+		return;
+	case BACKUP_BOOT_DEVICE_USB:
+		if (bkup_bootmode_cfg & MAIN_DEVSTAT_BACKUP_USB_MODE)
+			*src = BOOTSOURCE_USB;
+		else
+			*src = BOOTSOURCE_SERIAL;
+		return;
+	};
+}
+
+#define MAIN_DEVSTAT_PRIMARY_BOOTMODE		GENMASK(6, 3)
+#define MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG	GENMASK(9, 7)
+#define MAIN_DEVSTAT_PRIMARY_USB_MODE		BIT(1)
+#define MAIN_DEVSTAT_PRIMARY_MMC_PORT		BIT(2)
+
+static void am62lx_get_primary_bootsource(u32 devstat, enum bootsource *src, int *instance)
+{
+	u32 bootmode = FIELD_GET(MAIN_DEVSTAT_PRIMARY_BOOTMODE, devstat);
+	u32 bootmode_cfg = FIELD_GET(MAIN_DEVSTAT_PRIMARY_BOOTMODE_CFG, devstat);
+
+	switch (bootmode) {
+	case BOOT_DEVICE_OSPI:
+	case BOOT_DEVICE_QSPI:
+	case BOOT_DEVICE_XSPI:
+	case BOOT_DEVICE_SPI:
+		*src = BOOTSOURCE_SPI;
+		return;
+	case BOOT_DEVICE_EMMC:
+		*src = BOOTSOURCE_MMC;
+		*instance = 0;
+		return;
+	case BOOT_DEVICE_MMC:
+		if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_MMC_PORT) {
+			*src = BOOTSOURCE_MMC;
+			*instance = 1;
+		} else {
+			*src = BOOTSOURCE_MMC;
+			*instance = 0;
+		}
+		return;
+	case BOOT_DEVICE_USB:
+		if (bootmode_cfg & MAIN_DEVSTAT_PRIMARY_USB_MODE)
+			*src = BOOTSOURCE_USB;
+		else
+			*src = BOOTSOURCE_SERIAL;
+		return;
+	case BOOT_DEVICE_NOBOOT:
+		*src = BOOTSOURCE_UNKNOWN;
+		return;
+	}
+}
+
+#define AM62LX_BOOT_PARAM_TABLE_INDEX_OCRAM		IOMEM(0x70816e70)
+
+#define AM62LX_WKUP_CTRL_MMR0_BASE		IOMEM(0x43010000)
+#define AM62LX_CTRLMMR_MAIN_DEVSTAT		(AM62LX_WKUP_CTRL_MMR0_BASE + 0x30)
+
+void am62lx_get_bootsource(enum bootsource *src, int *instance)
+{
+	u32 bootmode = readl(AM62LX_BOOT_PARAM_TABLE_INDEX_OCRAM);
+	u32 devstat;
+
+	devstat = readl(AM62LX_CTRLMMR_MAIN_DEVSTAT);
+
+	if (bootmode == K3_PRIMARY_BOOTMODE)
+		am62lx_get_primary_bootsource(devstat, src, instance);
+	else
+		am62lx_get_backup_bootsource(devstat, src, instance);
+}
+
+static int am62lx_init(void)
+{
+	enum bootsource src = BOOTSOURCE_UNKNOWN;
+	int instance = 0;
+
+	if (!of_machine_is_compatible("ti,am62l3"))
+		return 0;
+
+	am62lx_get_bootsource(&src, &instance);
+	bootsource_set(src, instance);
+
+	genpd_activate();
+
+	return 0;
+}
+postcore_initcall(am62lx_init);
diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index 7299355eecef1c38e0d53a8feda60d233d74e2cd..aafd22453b9c8393e75fad07a21712a5af6674ef 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -20,8 +20,11 @@
 static const struct of_device_id k3_of_match[] = {
 	{
 		.compatible = "ti,am625",
+	}, {
+		.compatible = "ti,am62l3",
+	}, {
+		/* sentinel */
 	},
-	{ /* sentinel */ },
 };
 BAREBOX_DEEP_PROBE_ENABLE(k3_of_match);
 
diff --git a/include/mach/k3/common.h b/include/mach/k3/common.h
index d14b8b9cb891dd23dcc3a6277e79aa9f639f412a..5ce129f88cc8522954670d0ae34dda76445fcb75 100644
--- a/include/mach/k3/common.h
+++ b/include/mach/k3/common.h
@@ -9,6 +9,7 @@
         UUID_INIT(0x9e8c2017, 0x8b94, 0x4e2b, 0xa7, 0xb3, 0xa0, 0xf8, 0x8e, 0xab, 0xb8, 0xae)
 
 void am62x_get_bootsource(enum bootsource *src, int *instance);
+void am62lx_get_bootsource(enum bootsource *src, int *instance);
 bool k3_boot_is_emmc(void);
 u64 am62x_sdram_size(void);
 void am62x_register_dram(void);

-- 
2.39.5




  parent reply	other threads:[~2025-05-28 11:46 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-28 11:45 [PATCH 00/31] ARM: K3: add support for AM62L Sascha Hauer
2025-05-28 11:45 ` [PATCH 01/31] scripts: k3img: remove duplicate case value Sascha Hauer
2025-05-28 11:45 ` [PATCH 02/31] ARM: K3: prepare support for other SoCs Sascha Hauer
2025-05-28 11:45 ` [PATCH 03/31] ARM: k3: make k3img destination addresses configurable Sascha Hauer
2025-05-28 11:45 ` [PATCH 04/31] ARM: dts: add k3-am62l dts(i) files Sascha Hauer
2025-05-28 11:45 ` [PATCH 05/31] ARM: dts: am62l: Fix assigned-clock-parents Sascha Hauer
2025-05-28 11:45 ` Sascha Hauer [this message]
2025-05-28 11:45 ` [PATCH 07/31] ARM: Makefile: descend into mach-* for cleaning Sascha Hauer
2025-05-28 11:45 ` [PATCH 08/31] ARM: k3: rename yaml files from am625 to am62x Sascha Hauer
2025-05-28 11:45 ` [PATCH 09/31] scripts/ti-board-config.py: fix length Sascha Hauer
2025-05-28 11:45 ` [PATCH 10/31] ARM: k3: add yaml files for AM62l Sascha Hauer
2025-05-28 11:45 ` [PATCH 11/31] k3: ringacc: pass ringrt address in struct k3_ringacc_init_data Sascha Hauer
2025-05-28 11:45 ` [PATCH 12/31] drivers: soc: ti: k3-ringacc: handle absence of tisci Sascha Hauer
2025-05-28 11:45 ` [PATCH 13/31] drivers: soc: ti: k3-ringacc: fix k3_ringacc_ring_reset_sci Sascha Hauer
2025-05-28 11:45 ` [PATCH 14/31] dma: ti: k3-psil: Add PSIL data for AM62L Sascha Hauer
2025-05-28 11:45 ` [PATCH 15/31] dma: ti: k3-udma: Refactor common bits for AM62L support Sascha Hauer
2025-05-28 11:45 ` [PATCH 16/31] dma: ti: k3-udma-common: Update common code for AM62L DMAs Sascha Hauer
2025-05-28 11:45 ` [PATCH 17/31] dma: ti: k3-udma-am62l: Add AM62L support DMA drivers Sascha Hauer
2025-05-28 11:45 ` [PATCH 18/31] ARM: dts: am62l: Add ethernet ports Sascha Hauer
2025-05-28 11:45 ` [PATCH 19/31] ARM: dts: am62l evm: " Sascha Hauer
2025-05-28 11:45 ` [PATCH 20/31] ARM: k3: am62l: add barebox specific am62l.dtsi Sascha Hauer
2025-05-28 11:45 ` [PATCH 21/31] net: davinci_mdio: Use fallback clock rate Sascha Hauer
2025-05-28 11:45 ` [PATCH 22/31] firmware: arm_scmi: Add support for clock parents Sascha Hauer
2025-05-28 11:45 ` [PATCH 23/31] clk: add struct clk_parent_data Sascha Hauer
2025-05-28 11:45 ` [PATCH 24/31] clk: arm_scmi: implement clock parent setting Sascha Hauer
2025-05-28 11:45 ` [PATCH 25/31] ARM: dts: am62l3-evm: add MMC aliases Sascha Hauer
2025-05-28 11:45 ` [PATCH 26/31] dma: ti: k3-udma: limit asel to am625 Sascha Hauer
2025-05-28 11:45 ` [PATCH 27/31] gpio: increase ARCH_NR_GPIOS to 512 Sascha Hauer
2025-05-28 11:45 ` [PATCH 28/31] ARM: dts: k3-am62l: reserve memory for TF-A Sascha Hauer
2025-05-28 11:45 ` [PATCH 29/31] scripts: k3img: make dmdata optional Sascha Hauer
2025-05-28 11:45 ` [PATCH 30/31] scripts: k3img: handle bootcore_opts Sascha Hauer
2025-05-28 11:45 ` [PATCH 31/31] ARM: k3: add AM62l3 EVM board support 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=20250528-arm-k3-am62l-v1-6-3f88e6d10d99@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