1 /*
2  * Copyright (c) 2024, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/devicetree.h>
8 #include <zephyr/kernel.h>
9 #include <zephyr/drivers/retained_mem/nrf_retained_mem.h>
10 
11 #include <helpers/nrfx_ram_ctrl.h>
12 
13 #define _BUILD_MEM_REGION(node_id)		    \
14 	{.dt_addr = DT_REG_ADDR(DT_PARENT(node_id)),\
15 	 .dt_size = DT_REG_SIZE(DT_PARENT(node_id))}
16 
17 struct ret_mem_region {
18 	uintptr_t dt_addr;
19 	size_t dt_size;
20 };
21 
22 static const struct ret_mem_region ret_mem_regions[] = {
23 	DT_FOREACH_STATUS_OKAY(zephyr_retained_ram, _BUILD_MEM_REGION)
24 };
25 
z_nrf_retained_mem_retention_apply(void)26 int z_nrf_retained_mem_retention_apply(void)
27 {
28 	const struct ret_mem_region *rmr;
29 
30 	for (size_t i = 0; i < ARRAY_SIZE(ret_mem_regions); i++) {
31 		rmr = &ret_mem_regions[i];
32 		nrfx_ram_ctrl_retention_enable_set((void *)rmr->dt_addr, rmr->dt_size, true);
33 	}
34 
35 	return 0;
36 }
37