From 0ad64105c7da2cf4252d705a7a0b5c165142480c Mon Sep 17 00:00:00 2001 From: rmikielis Date: Thu, 19 Mar 2026 16:51:11 +0100 Subject: [PATCH] hal/armv7a/imx6ull: add pctl for RCT config --- hal/armv7a/imx6ull/_init.S | 5 +++- hal/armv7a/imx6ull/imx6ull.c | 42 ++++++++++++++++++++++++++- include/arch/armv7a/imx6ull/imx6ull.h | 12 +++++++- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/hal/armv7a/imx6ull/_init.S b/hal/armv7a/imx6ull/_init.S index c3ac6f250..c245ce819 100644 --- a/hal/armv7a/imx6ull/_init.S +++ b/hal/armv7a/imx6ull/_init.S @@ -682,8 +682,11 @@ kernel_ttl2: /* Map SRC registers 4KB P 0x020d8000 -> V CEIL(_end + 17 * SIZE_PAGE, SIZE_PAGE) */ ldr r1, =0x020d8012 - str r1, [r0] + str r1, [r0], #4 + /* Map SNVS registers */ + ldr r1, =0x020cc012 + str r1, [r0] /* IOMUX for UART1*/ ldr r0, =0x20e0084 diff --git a/hal/armv7a/imx6ull/imx6ull.c b/hal/armv7a/imx6ull/imx6ull.c index f980aac6c..af32058b7 100644 --- a/hal/armv7a/imx6ull/imx6ull.c +++ b/hal/armv7a/imx6ull/imx6ull.c @@ -51,6 +51,13 @@ enum { wdog_wcr = 0, wdog_wsr, wdog_wrsr, wdog_wicr, wdog_wmcr }; enum { src_scr = 0, src_sbmr1, src_srsr, src_sisr = src_srsr + 3, src_sbmr2 = src_sisr + 2, src_gpr1, src_gpr2, src_gpr3, src_gpr4, src_gpr5, src_gpr6, src_gpr7, src_gpr8, src_gpr9, src_gpr10 }; + + +/* SNVS registers */ +enum { snvps_hplr = 0, snvps_hpcomr, snvps_hpcr, snvps_hpsr = 5, snvps_hprtcmsr = 9, snvps_hprtclr, snvps_hptamr, + snvps_hptalr, snvps_lplr, snvps_lpcr, snvps_lpsr = 19, snvps_lpsrtcmr, snvps_lpsrtclr, snvps_lpsmcmr = 23, + snvps_lpsmclr, snvps_lpgpr = 26, snvps_hpvidr1 = 766, snvps_hpvidr2 }; + /* clang-format on */ @@ -64,6 +71,7 @@ static struct { volatile u32 *iomux_snvs; volatile u16 *wdog; volatile u32 *src; + volatile u32 *snvs; } imx6ull_common; @@ -334,6 +342,32 @@ static int _imx6ull_getIOisel(int isel, unsigned char *daisy) } +static int _imx6ull_setRTC(unsigned char state) +{ + unsigned int timeout = 0x1ffff; + unsigned int enable; + + if (state == 0U) { + enable = 0UL; + *(imx6ull_common.snvs + snvps_lpcr) &= ~(1UL); + } + else { + enable = 1UL; + *(imx6ull_common.snvs + snvps_lpcr) |= enable; + } + + enable = (enable + 1U) & 1U; + + while ((*(imx6ull_common.snvs + snvps_lpcr) & 1UL) == enable) { + if (--timeout == 0UL) { + return -1; + } + } + + return 0; +} + + __attribute__((noreturn)) static void _imx6ull_reboot(void) { /* assert SRS signal by writing 0 to bit 4 and 1 to bit 2 (WDOG enable) */ @@ -458,6 +492,11 @@ int hal_platformctl(void *ptr) /* No action required */ } break; + case pctl_snvs: + if (data->action == pctl_set) { + ret = _imx6ull_setRTC(data->snvs.val); + } + break; default: /* No action required*/ break; @@ -481,6 +520,7 @@ void _hal_platformInit(void) imx6ull_common.iomux_gpr = (void *)(((u32)&_end + (15U * SIZE_PAGE) - 1u) & ~(SIZE_PAGE - 1U)); imx6ull_common.wdog = (void *)(((u32)&_end + (16U * SIZE_PAGE) - 1U) & ~(SIZE_PAGE - 1U)); imx6ull_common.src = (void *)(((u32)&_end + (17U * SIZE_PAGE) - 1U) & ~(SIZE_PAGE - 1U)); + imx6ull_common.snvs = (void *)(((u32)&_end + (18U * SIZE_PAGE) - 1U) & ~(SIZE_PAGE - 1U)); /* remain in run mode in low power */ *(imx6ull_common.ccm + ccm_clpcr) &= ~0x3U; @@ -490,7 +530,7 @@ void _hal_platformInit(void) /* copy watchdog Reset Status Register to bootreason[23:16] */ imx6ull_bootReason &= 0xff00ffffU; - imx6ull_bootReason |= (u32)*(imx6ull_common.wdog + wdog_wrsr) << 16U; + imx6ull_bootReason |= (u32) * (imx6ull_common.wdog + wdog_wrsr) << 16U; /* Set ENFC clock to 198 MHz */ /* First disable all output clocks */ diff --git a/include/arch/armv7a/imx6ull/imx6ull.h b/include/arch/armv7a/imx6ull/imx6ull.h index cb6d32b91..75e173f77 100644 --- a/include/arch/armv7a/imx6ull/imx6ull.h +++ b/include/arch/armv7a/imx6ull/imx6ull.h @@ -203,13 +203,19 @@ enum { pctl_isel_usdhc2_wp }; + +/* SNVS domain */ +enum { + pctl_rtc_set_state +}; + /* clang-format on */ typedef struct { /* clang-format off */ enum { pctl_set = 0, pctl_get } action; - enum { pctl_devclock = 0, pctl_iogpr, pctl_iomux, pctl_iopad, pctl_ioisel, pctl_reboot } type; + enum { pctl_devclock = 0, pctl_iogpr, pctl_iomux, pctl_iopad, pctl_ioisel, pctl_reboot, pctl_snvs } type; /* clang-format on */ union { @@ -250,6 +256,10 @@ typedef struct { unsigned int magic; unsigned int reason; } reboot; + + struct { + unsigned char val; + } snvs; }; } __attribute__((packed)) platformctl_t;