1 /*
2  * Copyright (c) 2019 Microchip Technology Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __DEVICE_POWER_H
8 #define __DEVICE_POWER_H
9 
10 #ifndef _ASMLANGUAGE
11 
12 #define DEBUG_SLEEP
13 #define DEBUG_DEEP_SLEEP_CLK_REQ
14 
15 /*
16  * Disable UART deep sleep save/restore. If a UART TX FIFO has data on deep
17  * sleep entry it will de-assert its CLK_REQ once TX FIFO empties.  If the
18  * UART has TX empty interrupt enabled then the system will wake.
19  */
20 /* #define DEEP_SLEEP_UART_SAVE_RESTORE */
21 
22 /* Comment out to use JTAG without interruptions.
23  * Beware this blocks PLL going off, hence should be enabled
24  * for power consumption measurements
25  * Note: To attach JTAG for any debug need to be performed with breakpoint
26  * prior to deep sleep entry.
27  */
28 /* #define DEEP_SLEEP_JTAG */
29 
30 /*
31  * Enabling this would take a snapshot from clock requested values,
32  * these can be dump on exit to identify which HW block is blocking.
33  */
34 #define DEEP_SLEEP_CLK_REQ_DUMP
35 
36 /*
37  * Some peripherals if enabled always assert their CLK_REQ bits.
38  * For example, any peripheral with a clock generator such as
39  * timers, counters, UART, etc. We save the enables for these
40  * peripherals, disable them, and restore the enabled state upon
41  * wake.
42  */
43 #define DEEP_SLEEP_PERIPH_SAVE_RESTORE
44 
45 /* Power optimization if certain HW blocks are not used.
46  * These are not part of any Zephyr subsystem.
47  *  #define DEEP_SLEEP_PERIPH_SAVE_RESTORE_EXTENDED
48  */
49 #define DEEP_SLEEP_PERIPH_SAVE_RESTORE_EXTENDED
50 
51 #define NUM_DS_TIMER_ENTRIES 6
52 
53 struct ds_timer_info {
54 	uintptr_t addr;
55 	uint32_t stop_mask;
56 	uint32_t restore_mask;
57 };
58 
59 struct ds_peci_info {
60 	uint32_t peci_ctrl;
61 	uint32_t peci_dis;
62 };
63 
64 struct ds_dev_info {
65 	uint32_t ecs[2];
66 	uint32_t timers[NUM_DS_TIMER_ENTRIES];
67 #ifdef DEEP_SLEEP_UART_SAVE_RESTORE
68 	uint8_t uart_info[MCHP_UART_INSTANCES];
69 #endif
70 	/* Analog power */
71 #ifdef CONFIG_PECI
72 	struct ds_peci_info peci_info;
73 #endif
74 #ifdef CONFIG_I2C
75 	uint32_t smb_info[MCHP_I2C_SMB_INSTANCES];
76 #endif
77 	uint32_t slwclk_info;
78 	uint8_t tfdp_en;
79 	uint8_t comp_en;
80 };
81 
82 void soc_deep_sleep_periph_save(void);
83 void soc_deep_sleep_periph_restore(void);
84 void soc_deep_sleep_non_wake_en(void);
85 void soc_deep_sleep_non_wake_dis(void);
86 void soc_deep_sleep_wake_en(void);
87 void soc_deep_sleep_wake_dis(void);
88 
89 #ifdef DEBUG_DEEP_SLEEP_CLK_REQ
90 void soc_debug_sleep_clk_req(void);
91 #endif
92 
93 #endif /* _ASMLANGUAGE */
94 #endif /* __DEVICE_POWER_H */
95