Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion hal/armv7a/imx6ull/_init.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 41 additions & 1 deletion hal/armv7a/imx6ull/imx6ull.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */


Expand All @@ -64,6 +71,7 @@ static struct {
volatile u32 *iomux_snvs;
volatile u16 *wdog;
volatile u32 *src;
volatile u32 *snvs;
} imx6ull_common;


Expand Down Expand Up @@ -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) */
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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 */
Expand Down
12 changes: 11 additions & 1 deletion include/arch/armv7a/imx6ull/imx6ull.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,13 +203,19 @@ enum {
pctl_isel_usdhc2_wp
};


/* SNVS domain */
enum {
pctl_rtc_set_state
};
Comment on lines +207 to +210
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new enum pctl_rtc_set_state is defined but not used anywhere in the codebase. It seems to add confusion without providing functionality. If the intention is to define constants for enabling/disabling the RTC, it would be better to define them explicitly (e.g., RTC_STATE_DISABLE = 0, RTC_STATE_ENABLE = 1). As it is, this enum should probably be removed to avoid confusion.


/* 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 {
Expand Down Expand Up @@ -250,6 +256,10 @@ typedef struct {
unsigned int magic;
unsigned int reason;
} reboot;

struct {
unsigned char val;
} snvs;
};
} __attribute__((packed)) platformctl_t;

Expand Down
Loading