Skip to contentSkip to conversation

Add fdt-fixups for AM62P variants

PATCH Superseded Aparna Patra 2 participants 6 messages Dec 18, 2024 – Jan 6, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add fdt-fixups for AM62P variants

This series implements fdt fixups, by reading hardware information from registers and accordingly delete/modify the DT nodes, at run-time.

Logs for AM62P boot:
https://gist.github.com/itsme-aparna/b889fe59882c1acf0ef25a644bd325c4

Aparna Patra (3):
arm: mach-k3: am62p: Fixup CPU core, CAN-FD and Video-codec nodes in
fdt
arm: mach-k3: am62p: Fixup thermal zone critical points
arm: mach-k3: am62p: Fixup a53 max cpu frequency by speed-grade

 arch/arm/mach-k3/am62px/am62p5_fdt.c          | 83 +++++++++++++++++++
 .../arm/mach-k3/include/mach/am62p_hardware.h | 65 +++++++++++++++
 2 files changed, 148 insertions(+)

base-commit: 56accc56b9aab87ef4809ccc588e1257969cd271

Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/3 arm: mach-k3: am62p: Fixup CPU core, CAN-FD and Video-codec nodes in fdt

AM62P SOC is available in multiple variants:
-CPU cores (Cortex-A) AM62Px1 (1 core),
AM62Px2 (2 cores), AM62Px4 (4 cores)
-With and without CAN-FD & Video-codec support

Remove the relevant FDT nodes by reading the actual configuration from the SoC registers, with that change it is possible to have a single dts/dtb file handling the different variant at runtime.

---
 arch/arm/mach-k3/am62px/am62p5_fdt.c          | 34 +++++++++++++++++++
 .../arm/mach-k3/include/mach/am62p_hardware.h | 29 ++++++++++++++++
 2 files changed, 63 insertions(+)
arch/arm/mach-k3/am62px/am62p5_fdt.c +34 -0
index 29c832d28a..e88760ea51 100644
@@ -7,8 +7,42 @@
 #include "../common_fdt.h"
 #include <fdt_support.h>
 
+static void fdt_fixup_cores_wdt_nodes_am62p(void *blob, int core_nr)
+{
+	char node_path[32];
+
+	if (core_nr < 1)
+		return;
+
+	for (; core_nr < 4; core_nr++) {
+		snprintf(node_path, sizeof(node_path), "/cpus/cpu@%d", core_nr);
+		fdt_del_node_path(blob, node_path);
+		snprintf(node_path, sizeof(node_path), "/cpus/cpu-map/cluster0/core%d", core_nr);
+		fdt_del_node_path(blob, node_path);
+		snprintf(node_path, sizeof(node_path), "/bus@f0000/watchdog@e0%d0000", core_nr);
+		fdt_del_node_path(blob, node_path);
+	}
+}
+
+static void fdt_fixup_video_codec_nodes_am62p(void *blob, bool has_video_codec)
+{
+	if (!has_video_codec)
+		fdt_del_node_path(blob, "/bus@f0000/video-codec@30210000");
+}
+
+static void fdt_fixup_canfd_nodes_am62p(void *blob, bool has_canfd)
+{
+	if (!has_canfd) {
+		fdt_del_node_path(blob, "/bus@f0000/can@20701000");
+		fdt_del_node_path(blob, "/bus@f0000/can@20711000");
+	}
+}
+
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
+	fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
+	fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
+	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
 	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
 	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
arch/arm/mach-k3/include/mach/am62p_hardware.h +29 -0
index 923466c41f..339562722d 100644
@@ -19,6 +19,14 @@
 #define MCU_CTRL_MMR0_BASE			0x04500000
 #define WKUP_CTRL_MMR0_BASE			0x43000000
 
+#define CTRLMMR_WKUP_JTAG_DEVICE_ID		(WKUP_CTRL_MMR0_BASE + 0x18)
+#define JTAG_DEV_CORE_NR_MASK			GENMASK(19, 18)
+#define JTAG_DEV_CORE_NR_SHIFT			18
+#define JTAG_DEV_CANFD_MASK			BIT(15)
+#define JTAG_DEV_CANFD_SHIFT			15
+#define JTAG_DEV_VIDEO_CODEC_MASK			BIT(14)
+#define JTAG_DEV_VIDEO_CODEC_SHIFT			14
+
 #define CTRLMMR_MAIN_DEVSTAT			(WKUP_CTRL_MMR0_BASE + 0x30)
 #define MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK	GENMASK(6, 3)
 #define MAIN_DEVSTAT_PRIMARY_BOOTMODE_SHIFT	3
@@ -72,6 +80,27 @@
 
 #define TI_SRAM_SCRATCH_BOARD_EEPROM_START	0x43c30000
 
+static inline int k3_get_core_nr(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+
+	return ((dev_id & JTAG_DEV_CORE_NR_MASK) >> JTAG_DEV_CORE_NR_SHIFT) + 1;
+}
+
+static inline int k3_has_video_codec(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+
+	return !((dev_id & JTAG_DEV_VIDEO_CODEC_MASK) >> JTAG_DEV_VIDEO_CODEC_SHIFT);
+}
+
+static inline int k3_has_canfd(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+
+	return (dev_id & JTAG_DEV_CANFD_MASK) >> JTAG_DEV_CANFD_SHIFT;
+}
+
 #if defined(CONFIG_SYS_K3_SPL_ATF) && !defined(__ASSEMBLY__)
 
 static const u32 put_device_ids[] = {};
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/3 arm: mach-k3: am62p: Fixup thermal zone critical points

In reply to Aparna Patra

Read the max temperature for the SoC temperature grade from the hardware and modify the critical trip nodes on each thermal zone of FDT at runtime so they are correct with the hardware value for its grade.

---
 arch/arm/mach-k3/am62px/am62p5_fdt.c          | 37 +++++++++++++++++++
 .../arm/mach-k3/include/mach/am62p_hardware.h | 17 +++++++++
 2 files changed, 54 insertions(+)
arch/arm/mach-k3/am62px/am62p5_fdt.c +37 -0
index e88760ea51..96194cebcd 100644
@@ -38,11 +38,48 @@ static void fdt_fixup_canfd_nodes_am62p(void *blob, bool has_canfd)
 	}
 }
 
+static int fdt_fixup_trips_node(void *blob, int zoneoffset, int maxc)
+{
+	int node, trip;
+
+	node = fdt_subnode_offset(blob, zoneoffset, "trips");
+	if (node < 0)
+		return -1;
+
+	fdt_for_each_subnode(trip, blob, node) {
+		const char *type = fdt_getprop(blob, trip, "type", NULL);
+
+		if (!type || (strncmp(type, "critical", 8) != 0))
+			continue;
+
+		if (fdt_setprop_u32(blob, trip, "temperature", 1000 * maxc) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc)
+{
+	int node, zone;
+
+	node = fdt_path_offset(blob, "/thermal-zones");
+	if (node < 0)
+		return;
+
+	fdt_for_each_subnode(zone, blob, node) {
+		if (fdt_fixup_trips_node(blob, zone, maxc) < 0)
+			printf("Failed to set temperature in %s critical trips\n",
+			       fdt_get_name(blob, zone, NULL));
+	}
+}
+
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
 	fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
 	fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
 	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
+	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
 	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
 	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
arch/arm/mach-k3/include/mach/am62p_hardware.h +17 -0
index 339562722d..2f1c8517e6 100644
@@ -26,6 +26,12 @@
 #define JTAG_DEV_CANFD_SHIFT			15
 #define JTAG_DEV_VIDEO_CODEC_MASK			BIT(14)
 #define JTAG_DEV_VIDEO_CODEC_SHIFT			14
+#define JTAG_DEV_TEMP_MASK			GENMASK(5, 3)
+#define JTAG_DEV_TEMP_SHIFT			3
+
+#define JTAG_DEV_TEMP_AUTOMOTIVE        0x5
+#define JTAG_DEV_TEMP_EXTENDED_VALUE    105
+#define JTAG_DEV_TEMP_AUTOMOTIVE_VALUE  125
 
 #define CTRLMMR_MAIN_DEVSTAT			(WKUP_CTRL_MMR0_BASE + 0x30)
 #define MAIN_DEVSTAT_PRIMARY_BOOTMODE_MASK	GENMASK(6, 3)
@@ -101,6 +107,17 @@ static inline int k3_has_canfd(void)
 	return (dev_id & JTAG_DEV_CANFD_MASK) >> JTAG_DEV_CANFD_SHIFT;
 }
 
+static inline int k3_get_max_temp(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+	u32 dev_temp = (dev_id & JTAG_DEV_TEMP_MASK) >> JTAG_DEV_TEMP_SHIFT;
+
+	if (dev_temp == JTAG_DEV_TEMP_AUTOMOTIVE)
+		return JTAG_DEV_TEMP_AUTOMOTIVE_VALUE;
+	else
+		return JTAG_DEV_TEMP_EXTENDED_VALUE;
+}
+
 #if defined(CONFIG_SYS_K3_SPL_ATF) && !defined(__ASSEMBLY__)
 
 static const u32 put_device_ids[] = {};
Signature · 1 line
2.34.1
#3 lore raw

PATCH 3/3 arm: mach-k3: am62p: Fixup a53 max cpu frequency by speed-grade

In reply to Aparna Patra

AM62P SoC has multiple speed grades. Add function to delete non-relevant CPU frequency nodes, based on the information retrieved from hardware registers. Fastest grade's maximum frequency also depends on PMIC voltage, hence to simplify implementation use the smaller value.

---
 arch/arm/mach-k3/am62px/am62p5_fdt.c          | 12 ++++++++++++
 .../arm/mach-k3/include/mach/am62p_hardware.h | 19 +++++++++++++++++++
 2 files changed, 31 insertions(+)
arch/arm/mach-k3/am62px/am62p5_fdt.c +12 -0
index 96194cebcd..2c40fa5a59 100644
@@ -74,12 +74,24 @@ static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc)
 	}
 }
 
+static void fdt_fixup_cpu_freq_nodes_am62p(void *blob, int max_freq)
+{
+	if (max_freq >= 1250000000)
+		return;
+
+	if (max_freq <= 1000000000) {
+		fdt_del_node_path(blob, "/opp-table/opp-1250000000");
+		fdt_del_node_path(blob, "/opp-table/opp-1400000000");
+	}
+}
+
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
 	fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
 	fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
 	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
 	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
+	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());
 	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
 	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
arch/arm/mach-k3/include/mach/am62p_hardware.h +19 -0
index 2f1c8517e6..95af5c5c54 100644
@@ -26,6 +26,8 @@
 #define JTAG_DEV_CANFD_SHIFT			15
 #define JTAG_DEV_VIDEO_CODEC_MASK			BIT(14)
 #define JTAG_DEV_VIDEO_CODEC_SHIFT			14
+#define JTAG_DEV_SPEED_MASK			GENMASK(10, 6)
+#define JTAG_DEV_SPEED_SHIFT			6
 #define JTAG_DEV_TEMP_MASK			GENMASK(5, 3)
 #define JTAG_DEV_TEMP_SHIFT			3
 
@@ -118,6 +120,23 @@ static inline int k3_get_max_temp(void)
 		return JTAG_DEV_TEMP_EXTENDED_VALUE;
 }
 
+static inline char k3_get_speed_grade(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+	u32 speed_grade = (dev_id & JTAG_DEV_SPEED_MASK) >>
+			   JTAG_DEV_SPEED_SHIFT;
+
+	return 'A' - 1 + speed_grade;
+}
+
+static inline int k3_get_a53_max_frequency(void)
+{
+	if (k3_get_speed_grade() == 'O')
+		return 1000000000;
+	else
+		return 1250000000;
+}
+
 #if defined(CONFIG_SYS_K3_SPL_ATF) && !defined(__ASSEMBLY__)
 
 static const u32 put_device_ids[] = {};
Signature · 1 line
2.34.1
#4 lore raw

Re: [PATCH 3/3] arm: mach-k3: am62p: Fixup a53 max cpu frequency by speed-grade

Hi Aparna!

On December 18, 2024 thus sayeth Aparna Patra:

Quoted 6 lines

AM62P SoC has multiple speed grades. Add function to delete non-relevant CPU frequency nodes, based on the information retrieved from hardware registers. Fastest grade's maximum frequency also depends on PMIC voltage, hence to simplify implementation use the smaller value.

The R5 SPL will start the A53 at whatever frequency we have specified in the R5 DTB. We'll need to also update that before we start that core.

Quoted 11 lines
---
 arch/arm/mach-k3/am62px/am62p5_fdt.c          | 12 ++++++++++++
 .../arm/mach-k3/include/mach/am62p_hardware.h | 19 +++++++++++++++++++
 2 files changed, 31 insertions(+)
arch/arm/mach-k3/am62px/am62p5_fdt.c +0 -0
index 96194cebcd..2c40fa5a59 100644

arch/arm/mach-k3/am62px/am62p5_fdt.c static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc) · line 81

Quoted 8 lines
arch/arm/mach-k3/am62px/am62p5_fdt.c +5 -0
@@ -74,12 +74,24 @@ static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc)
 	}
 }
 
+static void fdt_fixup_cpu_freq_nodes_am62p(void *blob, int max_freq)
+{
+	if (max_freq >= 1250000000)
+		return;
+

With parts that only support 1.25GHz (18 or R) we'll need to disable the 1.4GHz OPP.

Quoted 56 lines
arch/arm/mach-k3/am62px/am62p5_fdt.c +7 -0
+	if (max_freq <= 1000000000) {
+		fdt_del_node_path(blob, "/opp-table/opp-1250000000");
+		fdt_del_node_path(blob, "/opp-table/opp-1400000000");
+	}
+}
+
 int ft_system_setup(void *blob, struct bd_info *bd)
 {
 	fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
 	fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
 	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
 	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
+	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());
 	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
 	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
arch/arm/mach-k3/include/mach/am62p_hardware.h +19 -0
index 2f1c8517e6..95af5c5c54 100644
@@ -26,6 +26,8 @@
 #define JTAG_DEV_CANFD_SHIFT			15
 #define JTAG_DEV_VIDEO_CODEC_MASK			BIT(14)
 #define JTAG_DEV_VIDEO_CODEC_SHIFT			14
+#define JTAG_DEV_SPEED_MASK			GENMASK(10, 6)
+#define JTAG_DEV_SPEED_SHIFT			6
 #define JTAG_DEV_TEMP_MASK			GENMASK(5, 3)
 #define JTAG_DEV_TEMP_SHIFT			3
 
@@ -118,6 +120,23 @@ static inline int k3_get_max_temp(void)
 		return JTAG_DEV_TEMP_EXTENDED_VALUE;
 }
 
+static inline char k3_get_speed_grade(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+	u32 speed_grade = (dev_id & JTAG_DEV_SPEED_MASK) >>
+			   JTAG_DEV_SPEED_SHIFT;
+
+	return 'A' - 1 + speed_grade;
+}
+
+static inline int k3_get_a53_max_frequency(void)
+{
+	if (k3_get_speed_grade() == 'O')
+		return 1000000000;
+	else
+		return 1250000000;
+}
+
 #if defined(CONFIG_SYS_K3_SPL_ATF) && !defined(__ASSEMBLY__)
 
 static const u32 put_device_ids[] = {};
Signature · 1 line
2.34.1
#5 lore raw

Re: [PATCH 3/3] arm: mach-k3: am62p: Fixup a53 max cpu frequency by speed-grade

Hi Bryan,

Quoted 11 lines · Bryan Brattlof

Hi Aparna!

On December 18, 2024 thus sayeth Aparna Patra:

Quoted 6 lines

AM62P SoC has multiple speed grades. Add function to delete non-relevant CPU frequency nodes, based on the information retrieved from hardware registers. Fastest grade's maximum frequency also depends on PMIC voltage, hence to simplify implementation use the smaller value.

The R5 SPL will start the A53 at whatever frequency we have specified in the R5 DTB. We'll need to also update that before we start that core.

Understood, will add this in the next revision.

Quoted 14 lines
Quoted 14 lines
---
  arch/arm/mach-k3/am62px/am62p5_fdt.c          | 12 ++++++++++++
  .../arm/mach-k3/include/mach/am62p_hardware.h | 19 +++++++++++++++++++
  2 files changed, 31 insertions(+)
arch/arm/mach-k3/am62px/am62p5_fdt.c +0 -0
index 96194cebcd..2c40fa5a59 100644
@@ -74,12 +74,24 @@ static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc)
  	}
  }
 
Quoted 7 lines

arch/arm/mach-k3/am62px/am62p5_fdt.c static void fdt_fixup_thermal_zone_nodes_am62p(void *blob, int maxc) · line 81

Quoted 5 lines
arch/arm/mach-k3/am62px/am62p5_fdt.c +5 -0
+static void fdt_fixup_cpu_freq_nodes_am62p(void *blob, int max_freq)
+{
+	if (max_freq >= 1250000000)
+		return;
+

With parts that only support 1.25GHz (18 or R) we'll need to disable the 1.4GHz OPP.

Following the datasheet[1] section 6.6, there are no TI parts that support only 1.25 GHz

[1]: https://www.ti.com/lit/gpn/am62p

Quoted 52 lines
Quoted 52 lines
arch/arm/mach-k3/am62px/am62p5_fdt.c +7 -0
+	if (max_freq <= 1000000000) {
+		fdt_del_node_path(blob, "/opp-table/opp-1250000000");
+		fdt_del_node_path(blob, "/opp-table/opp-1400000000");
+	}
+}
+
  int ft_system_setup(void *blob, struct bd_info *bd)
  {
  	fdt_fixup_cores_wdt_nodes_am62p(blob, k3_get_core_nr());
  	fdt_fixup_video_codec_nodes_am62p(blob, k3_has_video_codec());
  	fdt_fixup_canfd_nodes_am62p(blob, k3_has_canfd());
  	fdt_fixup_thermal_zone_nodes_am62p(blob, k3_get_max_temp());
+	fdt_fixup_cpu_freq_nodes_am62p(blob, k3_get_a53_max_frequency());
  	fdt_fixup_reserved(blob, "tfa", CONFIG_K3_ATF_LOAD_ADDR, 0x80000);
  	fdt_fixup_reserved(blob, "optee", CONFIG_K3_OPTEE_LOAD_ADDR, 0x1800000);
 
arch/arm/mach-k3/include/mach/am62p_hardware.h +19 -0
index 2f1c8517e6..95af5c5c54 100644
@@ -26,6 +26,8 @@
  #define JTAG_DEV_CANFD_SHIFT			15
  #define JTAG_DEV_VIDEO_CODEC_MASK			BIT(14)
  #define JTAG_DEV_VIDEO_CODEC_SHIFT			14
+#define JTAG_DEV_SPEED_MASK			GENMASK(10, 6)
+#define JTAG_DEV_SPEED_SHIFT			6
  #define JTAG_DEV_TEMP_MASK			GENMASK(5, 3)
  #define JTAG_DEV_TEMP_SHIFT			3
 
@@ -118,6 +120,23 @@ static inline int k3_get_max_temp(void)
  		return JTAG_DEV_TEMP_EXTENDED_VALUE;
  }
 
+static inline char k3_get_speed_grade(void)
+{
+	u32 dev_id = readl(CTRLMMR_WKUP_JTAG_DEVICE_ID);
+	u32 speed_grade = (dev_id & JTAG_DEV_SPEED_MASK) >>
+			   JTAG_DEV_SPEED_SHIFT;
+
+	return 'A' - 1 + speed_grade;
+}
+
+static inline int k3_get_a53_max_frequency(void)
+{
+	if (k3_get_speed_grade() == 'O')
+		return 1000000000;
+	else
+		return 1250000000;
+}
+
  #if defined(CONFIG_SYS_K3_SPL_ATF) && !defined(__ASSEMBLY__)
 
Quoted 4 lines
Quoted 4 lines
arch/arm/mach-k3/include/mach/am62p_hardware.h +0 -0
  static const u32 put_device_ids[] = {};
Signature · 1 line
2.34.1

Regards,
Aparna