1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2021, Microchip
4 */
5
6 #include <drivers/atmel_rstc.h>
7 #include <io.h>
8 #include <kernel/dt.h>
9 #include <tee_api_defines.h>
10 #include <tee_api_types.h>
11 #include <types_ext.h>
12
13 #define AT91_RSTC_CR 0x0
14 #define AT91_RSTC_CR_KEY SHIFT_U32(0xA5, 24)
15 #define AT91_RSTC_CR_PROCRST BIT32(0)
16 #define AT91_RSTC_CR_PERRST BIT32(2)
17
18 static vaddr_t rstc_base;
19
atmel_rstc_available(void)20 bool atmel_rstc_available(void)
21 {
22 return rstc_base != 0;
23 }
24
atmel_rstc_reset(void)25 void __noreturn atmel_rstc_reset(void)
26 {
27 uint32_t val = AT91_RSTC_CR_KEY | AT91_RSTC_CR_PROCRST |
28 AT91_RSTC_CR_PERRST;
29
30 io_write32(rstc_base + AT91_RSTC_CR, val);
31
32 /*
33 * After the previous write, the CPU will reset so we will never hit
34 * this loop.
35 */
36 while (true)
37 ;
38 }
39
atmel_rstc_probe(const void * fdt,int node,const void * compat_data __unused)40 static TEE_Result atmel_rstc_probe(const void *fdt, int node,
41 const void *compat_data __unused)
42
43 {
44 size_t size = 0;
45
46 if (dt_map_dev(fdt, node, &rstc_base, &size) < 0)
47 return TEE_ERROR_GENERIC;
48
49 return TEE_SUCCESS;
50 }
51
52 static const struct dt_device_match atmel_rstc_match_table[] = {
53 { .compatible = "atmel,sama5d3-rstc" },
54 { }
55 };
56
57 DEFINE_DT_DRIVER(atmel_rstc_dt_driver) = {
58 .name = "atmel_rstc",
59 .type = DT_DRIVER_NOTYPE,
60 .match_table = atmel_rstc_match_table,
61 .probe = atmel_rstc_probe,
62 };
63