1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015 Atmel Corporation,
4  *                    Nicolas Ferre <nicolas.ferre@atmel.com>
5  * Copyright (c) 2021, Microchip
6  */
7 
8 #ifndef __DRIVERS_ATMEL_SHDWC_H
9 #define __DRIVERS_ATMEL_SHDWC_H
10 
11 #include <compiler.h>
12 #include <stdbool.h>
13 #include <stdint.h>
14 #include <util.h>
15 
16 /* Shut Down Control Register */
17 #define AT91_SHDW_CR		0x00
18 /* Shut Down command */
19 #define AT91_SHDW_SHDW		BIT(0)
20 /* KEY Password */
21 #define AT91_SHDW_KEY		SHIFT_U32(0xa5UL, 24)
22 
23 /* Shut Down Mode Register */
24 #define AT91_SHDW_MR		0x04
25 #define AT91_SHDW_WKUPDBC_SHIFT	24
26 #define AT91_SHDW_WKUPDBC_MASK	GENMASK_32(26, 24)
27 #define AT91_SHDW_WKUPDBC(x)	(SHIFT_U32((x), AT91_SHDW_WKUPDBC_SHIFT) & \
28 				 AT91_SHDW_WKUPDBC_MASK)
29 #define AT91_SHDW_RTCWKEN	BIT32(17)
30 
31 /* Shut Down Status Register */
32 #define AT91_SHDW_SR		0x08
33 #define AT91_SHDW_WKUPIS_SHIFT	16
34 #define AT91_SHDW_WKUPIS_MASK	GENMASK_32(31, 16)
35 #define AT91_SHDW_WKUPIS(x)	(BIT32((x) + AT91_SHDW_WKUPIS_SHIFT))
36 
37 /* Shutdown Wake-up Inputs Register */
38 #define AT91_SHDW_WUIR		0x0c
39 #define AT91_SHDW_WKUPEN_MASK	GENMASK_32(15, 0)
40 #define AT91_SHDW_WKUPEN(x)	(BIT32(x) & AT91_SHDW_WKUPEN_MASK)
41 #define AT91_SHDW_WKUPT_SHIFT	16
42 #define AT91_SHDW_WKUPT_MASK	GENMASK_32(31, 16)
43 #define AT91_SHDW_WKUPT(x)	(BIT32((x) + AT91_SHDW_WKUPT_SHIFT))
44 
45 #ifndef __ASSEMBLER__
46 #if defined(CFG_ATMEL_SHDWC)
47 
48 void __atmel_shdwc_shutdown(uint32_t mpddrc_base, uint32_t shdwc_base,
49 			    uint32_t pmc_base);
50 
51 bool atmel_shdwc_available(void);
52 
53 void __noreturn atmel_shdwc_shutdown(void);
54 #else
atmel_shdwc_available(void)55 static inline bool atmel_shdwc_available(void)
56 {
57 	return false;
58 }
59 
atmel_shdwc_shutdown(void)60 static inline void atmel_shdwc_shutdown(void) {}
61 #endif /* defined(CFG_ATMEL_SHDWC) */
62 #endif /* __ASSEMBLER__*/
63 
64 #endif /* __DRIVERS_ATMEL_SHDWC_H */
65