From: Peng Fan Date: Thu, 19 Sep 2024 04:01:35 +0000 (+0800) Subject: imx9: trdc: cleanup code X-Git-Url: http://git.dujemihanovic.xyz/%22/img/sics.gif/%22/static/git-favicon.png?a=commitdiff_plain;h=5da0629d13eb42597988e472d788a2613a3a0698;p=u-boot.git imx9: trdc: cleanup code Replace magic number with meaningful macros. Signed-off-by: Peng Fan --- diff --git a/arch/arm/include/asm/arch-imx9/imx-regs.h b/arch/arm/include/asm/arch-imx9/imx-regs.h index cb6b8a59ca..ef9538bd42 100644 --- a/arch/arm/include/asm/arch-imx9/imx-regs.h +++ b/arch/arm/include/asm/arch-imx9/imx-regs.h @@ -50,6 +50,11 @@ #define BCTRL_GPR_ENET_QOS_INTF_SEL_RGMII (0x1 << 1) #define BCTRL_GPR_ENET_QOS_CLK_GEN_EN (0x1 << 0) +#define TRDC_AON_BASE (0x44270000UL) +#define TRDC_WAKEUP_BASE (0x42460000UL) +#define TRDC_MEGA_BASE (0x42810000UL) +#define TRDC_NIC_BASE (0x49010000UL) + #define MARKETING_GRADING_MASK GENMASK(5, 4) #define SPEED_GRADING_MASK GENMASK(11, 6) #define NUM_WORDS_PER_BANK 8 diff --git a/arch/arm/mach-imx/imx9/trdc.c b/arch/arm/mach-imx/imx9/trdc.c index 8cdb28459a..ae1a46d133 100644 --- a/arch/arm/mach-imx/imx9/trdc.c +++ b/arch/arm/mach-imx/imx9/trdc.c @@ -4,12 +4,13 @@ */ #include +#include +#include #include #include #include #include #include -#include #include #include @@ -19,6 +20,25 @@ #define MBC_NUM(HWCFG) (((HWCFG) >> 16) & 0xF) #define MRC_NUM(HWCFG) (((HWCFG) >> 24) & 0x1F) +enum { + /* Order following ELE API Spec, not change */ + TRDC_A, + TRDC_W, + TRDC_M, + TRDC_N, +}; + +/* Just make it easier to know what the parameter is */ +#define MBC(X) (X) +#define MRC(X) (X) +#define GLOBAL_ID(X) (X) +#define MEM(X) (X) +#define DOM(X) (X) +/* + *0|SPR|SPW|SPX,0|SUR|SUW|SWX, 0|NPR|NPW|NPX, 0|NUR|NUW|NUX + */ +#define PERM(X) (X) + struct mbc_mem_dom { u32 mem_glbcfg[4]; u32 nse_blk_index; @@ -364,68 +384,84 @@ void trdc_early_init(void) { int ret = 0, i; - ret |= release_rdc(0); - ret |= release_rdc(2); - ret |= release_rdc(1); - ret |= release_rdc(3); + ret |= release_rdc(TRDC_A); + ret |= release_rdc(TRDC_M); + ret |= release_rdc(TRDC_W); + ret |= release_rdc(TRDC_N); - if (!ret) { - /* Set OCRAM to RWX for secure, when OEM_CLOSE, the image is RX only */ - trdc_mbc_set_control(0x49010000, 3, 0, 0x7700); + if (ret) { + hang(); + return; + } + + /* Set OCRAM to RWX for secure, when OEM_CLOSE, the image is RX only */ + trdc_mbc_set_control(TRDC_NIC_BASE, MBC(3), GLOBAL_ID(0), PERM(0x7700)); - for (i = 0; i < 40; i++) - trdc_mbc_blk_config(0x49010000, 3, 3, 0, i, true, 0); + for (i = 0; i < 40; i++) { + trdc_mbc_blk_config(TRDC_NIC_BASE, MBC(3), DOM(3), MEM(0), i, + true, GLOBAL_ID(0)); - for (i = 0; i < 40; i++) - trdc_mbc_blk_config(0x49010000, 3, 3, 1, i, true, 0); + trdc_mbc_blk_config(TRDC_NIC_BASE, MBC(3), DOM(3), MEM(1), i, + true, GLOBAL_ID(0)); - for (i = 0; i < 40; i++) - trdc_mbc_blk_config(0x49010000, 3, 0, 0, i, true, 0); + trdc_mbc_blk_config(TRDC_NIC_BASE, MBC(3), DOM(0), MEM(0), i, + true, GLOBAL_ID(0)); - for (i = 0; i < 40; i++) - trdc_mbc_blk_config(0x49010000, 3, 0, 1, i, true, 0); + trdc_mbc_blk_config(TRDC_NIC_BASE, MBC(3), DOM(0), MEM(1), i, + true, GLOBAL_ID(0)); } } void trdc_init(void) { /* TRDC mega */ - if (trdc_mrc_enabled(0x49010000)) { + if (trdc_mrc_enabled(TRDC_NIC_BASE)) { /* DDR */ - trdc_mrc_set_control(0x49010000, 0, 0, 0x7777); + trdc_mrc_set_control(TRDC_NIC_BASE, MRC(0), GLOBAL_ID(0), PERM(0x7777)); /* ELE */ - trdc_mrc_region_config(0x49010000, 0, 0, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(0), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* MTR */ - trdc_mrc_region_config(0x49010000, 0, 1, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(1), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* M33 */ - trdc_mrc_region_config(0x49010000, 0, 2, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(2), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* A55*/ - trdc_mrc_region_config(0x49010000, 0, 3, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(3), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* For USDHC1 to DDR, USDHC1 is default force to non-secure */ - trdc_mrc_region_config(0x49010000, 0, 5, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(5), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* For USDHC2 to DDR, USDHC2 is default force to non-secure */ - trdc_mrc_region_config(0x49010000, 0, 6, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(6), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* eDMA */ - trdc_mrc_region_config(0x49010000, 0, 7, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(7), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /*CoreSight, TestPort*/ - trdc_mrc_region_config(0x49010000, 0, 8, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(8), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /* DAP */ - trdc_mrc_region_config(0x49010000, 0, 9, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(9), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /*SoC masters */ - trdc_mrc_region_config(0x49010000, 0, 10, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(10), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); /*USB*/ - trdc_mrc_region_config(0x49010000, 0, 11, 0x80000000, 0xFFFFFFFF, false, 0); + trdc_mrc_region_config(TRDC_NIC_BASE, MRC(0), DOM(11), 0x80000000, + 0xFFFFFFFF, false, GLOBAL_ID(0)); } } @@ -504,78 +540,78 @@ void trdc_dump(void) printf("TRDC AONMIX MBC\n"); - trdc_mbc_control_dump(0x44270000, 0, 0); - trdc_mbc_control_dump(0x44270000, 1, 0); + trdc_mbc_control_dump(TRDC_AON_BASE, MBC(0), GLOBAL_ID(0)); + trdc_mbc_control_dump(TRDC_AON_BASE, MBC(1), GLOBAL_ID(0)); for (i = 0; i < 11; i++) - trdc_mbc_mem_dump(0x44270000, 0, 3, 0, i); + trdc_mbc_mem_dump(TRDC_AON_BASE, MBC(0), DOM(3), MEM(0), i); for (i = 0; i < 1; i++) - trdc_mbc_mem_dump(0x44270000, 0, 3, 1, i); + trdc_mbc_mem_dump(TRDC_AON_BASE, MBC(0), DOM(3), MEM(1), i); for (i = 0; i < 4; i++) - trdc_mbc_mem_dump(0x44270000, 1, 3, 0, i); + trdc_mbc_mem_dump(TRDC_AON_BASE, MBC(1), DOM(3), MEM(0), i); for (i = 0; i < 4; i++) - trdc_mbc_mem_dump(0x44270000, 1, 3, 1, i); + trdc_mbc_mem_dump(TRDC_AON_BASE, MBC(1), DOM(3), MEM(1), i); printf("TRDC WAKEUP MBC\n"); - trdc_mbc_control_dump(0x42460000, 0, 0); - trdc_mbc_control_dump(0x42460000, 1, 0); + trdc_mbc_control_dump(TRDC_WAKEUP_BASE, MBC(0), GLOBAL_ID(0)); + trdc_mbc_control_dump(TRDC_WAKEUP_BASE, MBC(1), GLOBAL_ID(0)); for (i = 0; i < 15; i++) - trdc_mbc_mem_dump(0x42460000, 0, 3, 0, i); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, MBC(0), DOM(3), MEM(0), i); - trdc_mbc_mem_dump(0x42460000, 0, 3, 1, 0); - trdc_mbc_mem_dump(0x42460000, 0, 3, 2, 0); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, MBC(0), DOM(3), MEM(1), 0); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, 0, 3, 2, 0); for (i = 0; i < 2; i++) - trdc_mbc_mem_dump(0x42460000, 1, 3, 0, i); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, MBC(1), DOM(3), MEM(0), i); - trdc_mbc_mem_dump(0x42460000, 1, 3, 1, 0); - trdc_mbc_mem_dump(0x42460000, 1, 3, 2, 0); - trdc_mbc_mem_dump(0x42460000, 1, 3, 3, 0); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, MBC(1), DOM(3), MEM(1), 0); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, 1, 3, 2, 0); + trdc_mbc_mem_dump(TRDC_WAKEUP_BASE, MBC(1), DOM(3), MEM(3), 0); printf("TRDC NICMIX MBC\n"); - trdc_mbc_control_dump(0x49010000, 0, 0); - trdc_mbc_control_dump(0x49010000, 1, 0); - trdc_mbc_control_dump(0x49010000, 2, 0); - trdc_mbc_control_dump(0x49010000, 3, 0); + trdc_mbc_control_dump(TRDC_NIC_BASE, MBC(0), GLOBAL_ID(0)); + trdc_mbc_control_dump(TRDC_NIC_BASE, MBC(1), GLOBAL_ID(0)); + trdc_mbc_control_dump(TRDC_NIC_BASE, MBC(2), GLOBAL_ID(0)); + trdc_mbc_control_dump(TRDC_NIC_BASE, MBC(3), GLOBAL_ID(0)); for (i = 0; i < 7; i++) - trdc_mbc_mem_dump(0x49010000, 0, 3, 0, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(0), DOM(3), MEM(0), i); for (i = 0; i < 2; i++) - trdc_mbc_mem_dump(0x49010000, 0, 3, 1, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(0), DOM(3), MEM(1), i); for (i = 0; i < 5; i++) - trdc_mbc_mem_dump(0x49010000, 0, 3, 2, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(0), DOM(3), MEM(2), i); for (i = 0; i < 6; i++) - trdc_mbc_mem_dump(0x49010000, 0, 3, 3, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(0), DOM(3), MEM(3), i); for (i = 0; i < 1; i++) - trdc_mbc_mem_dump(0x49010000, 1, 3, 0, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(1), DOM(3), MEM(0), i); for (i = 0; i < 1; i++) - trdc_mbc_mem_dump(0x49010000, 1, 3, 1, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(1), DOM(3), MEM(1), i); for (i = 0; i < 3; i++) - trdc_mbc_mem_dump(0x49010000, 1, 3, 2, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(1), DOM(3), MEM(2), i); for (i = 0; i < 3; i++) - trdc_mbc_mem_dump(0x49010000, 1, 3, 3, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(1), DOM(3), MEM(3), i); for (i = 0; i < 2; i++) - trdc_mbc_mem_dump(0x49010000, 2, 3, 0, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(2), DOM(3), MEM(0), i); for (i = 0; i < 2; i++) - trdc_mbc_mem_dump(0x49010000, 2, 3, 1, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(2), DOM(3), MEM(1), i); for (i = 0; i < 5; i++) - trdc_mbc_mem_dump(0x49010000, 3, 3, 0, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(3), DOM(3), MEM(0), i); for (i = 0; i < 5; i++) - trdc_mbc_mem_dump(0x49010000, 3, 3, 1, i); + trdc_mbc_mem_dump(TRDC_NIC_BASE, MBC(3), DOM(3), MEM(1), i); } #endif