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 <kernel/dt_driver.h> 10 #include <matrix.h> 11 #include <sama5d2.h> 12 #include <tee_api_defines.h> 13 #include <tee_api_types.h> 14 #include <types_ext.h> 15 16 #define AT91_RSTC_CR 0x0 17 #define AT91_RSTC_CR_KEY SHIFT_U32(0xA5, 24) 18 #define AT91_RSTC_CR_PROCRST BIT32(0) 19 #define AT91_RSTC_CR_PERRST BIT32(2) 20 21 static vaddr_t rstc_base; 22 23 bool atmel_rstc_available(void) 24 { 25 return rstc_base != 0; 26 } 27 28 void __noreturn atmel_rstc_reset(void) 29 { 30 uint32_t val = AT91_RSTC_CR_KEY | AT91_RSTC_CR_PROCRST | 31 AT91_RSTC_CR_PERRST; 32 33 io_write32(rstc_base + AT91_RSTC_CR, val); 34 35 /* 36 * After the previous write, the CPU will reset so we will never hit 37 * this loop. 38 */ 39 while (true) 40 ; 41 } 42 43 static TEE_Result atmel_rstc_probe(const void *fdt, int node, 44 const void *compat_data __unused) 45 46 { 47 size_t size = 0; 48 49 if (fdt_get_status(fdt, node) != DT_STATUS_OK_SEC) 50 return TEE_ERROR_BAD_PARAMETERS; 51 52 matrix_configure_periph_secure(AT91C_ID_SYS); 53 54 if (dt_map_dev(fdt, node, &rstc_base, &size, DT_MAP_AUTO) < 0) 55 return TEE_ERROR_GENERIC; 56 57 return TEE_SUCCESS; 58 } 59 60 static const struct dt_device_match atmel_rstc_match_table[] = { 61 { .compatible = "atmel,sama5d3-rstc" }, 62 { } 63 }; 64 65 DEFINE_DT_DRIVER(atmel_rstc_dt_driver) = { 66 .name = "atmel_rstc", 67 .type = DT_DRIVER_NOTYPE, 68 .match_table = atmel_rstc_match_table, 69 .probe = atmel_rstc_probe, 70 }; 71