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 v2 06/33] ARM: K3: add am62lx base support
Date: Thu, 05 Jun 2025 14:42:31 +0200	[thread overview]
Message-ID: <20250605-arm-k3-am62l-v2-6-53257d4b2dd2@pengutronix.de> (raw)
In-Reply-To: <20250605-arm-k3-am62l-v2-0-53257d4b2dd2@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-06-05 12:45 UTC|newest]

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