1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #ifndef __DA1469X_PDC_H_
21 #define __DA1469X_PDC_H_
22
23 #include <stdint.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #define MCU_PDC_CTRL_REGS(_i) (((__IO uint32_t*)&PDC->PDC_CTRL0_REG)[_i])
30 #define MCU_PDC_CTRL_REGS_COUNT 16
31
32 /* PDC trigger can be either a GPIO number or one of following values */
33 #define MCU_PDC_TRIGGER_TIMER (0x40 | 0)
34 #define MCU_PDC_TRIGGER_TIMER2 (0x40 | 1)
35 #define MCU_PDC_TRIGGER_TIMER3 (0x40 | 2)
36 #define MCU_PDC_TRIGGER_TIMER4 (0x40 | 3)
37 #define MCU_PDC_TRIGGER_RTC_ALARM (0x40 | 4)
38 #define MCU_PDC_TRIGGER_RTC_TIMER (0x40 | 5)
39 #define MCU_PDC_TRIGGER_MAC_TIMER (0x40 | 6)
40 #define MCU_PDC_TRIGGER_MOTOR_CONTROLLER (0x40 | 7)
41 #define MCU_PDC_TRIGGER_XTAL32M_READY (0x40 | 8)
42 #define MCU_PDC_TRIGGER_RFDIAG (0x40 | 9)
43 #define MCU_PDC_TRIGGER_COMBO (0x40 | 10) /* VBUS, IO, JTAG, CMAC2SYS */
44 #define MCU_PDC_TRIGGER_SNC (0x40 | 11)
45 #define MCU_PDC_TRIGGER_SW_TRIGGER (0x40 | 15)
46
47 /* PDC master can be either of following values */
48 #define MCU_PDC_MASTER_M33 1
49 #define MCU_PDC_MASTER_CMAC 2
50 #define MCU_PDC_MASTER_SNC 3
51
52 /* PDC enable bitmask can consist of following values */
53 #define MCU_PDC_EN_NONE 0x00
54 #define MCU_PDC_EN_XTAL 0x01
55 #define MCU_PDC_EN_PD_TMR 0x02
56 #define MCU_PDC_EN_PD_PER 0x04
57 #define MCU_PDC_EN_PD_COM 0x08
58
59 /**
60 * Add entry to PDC lookup table
61 *
62 * This adds new entry to PDC lookup table. Unused entry index is selected
63 * automatically.
64 *
65 * @param trigger Trigger source
66 * @param master Master to wakeup
67 * @param en Power domains to enable
68 *
69 * @return entry index, SYS_ENOENT if all lookup table entries are used
70 */
71 int da1469x_pdc_add(uint8_t trigger, uint8_t master, uint8_t en);
72
73 /**
74 * Delete entry from PDC lookup table
75 *
76 * This removed existing entry from PDC lookup table. It assumes requested
77 * entry is set.
78 *
79 * @param idx Entry index
80 */
81 void da1469x_pdc_del(int idx);
82
83 /**
84 * Find entry in PDC lookup table matching given values
85 *
86 * Set either \p trigger or \p master to negative value to disable matching on
87 * that value.
88 * \p en matches at least specified power domains, more domains can be included
89 * in matched entry.
90 *
91 * @param trigger Trigger to match
92 * @param master Master to wakeup to match
93 * @param en Required power domains to enable
94 *
95 * @return entry index on success, SYS_ENOENT if not found
96 */
97 int da1469x_pdc_find(int trigger, int master, uint8_t en);
98
99 /**
100 * Reset PDC lookup table
101 *
102 * This deletes all valid entried from LUT and acknowledges them in case some
103 * were pending.
104 */
105 void da1469x_pdc_reset(void);
106
107 /**
108 * Acknowledge pending PDC lookup table entry
109 *
110 * @param idx Entry index
111 */
112 static inline void
da1469x_pdc_ack(int idx)113 da1469x_pdc_ack(int idx)
114 {
115 PDC->PDC_ACKNOWLEDGE_REG = idx;
116 }
117
118 /**
119 * Set PDC lookup table entry as pending
120 *
121 * @param idx Entry index
122 */
123 static inline void
da1469x_pdc_set(int idx)124 da1469x_pdc_set(int idx)
125 {
126 PDC->PDC_SET_PENDING_REG = idx;
127 }
128
129 /**
130 * Check if PDC lookup table entry is pending
131 *
132 * @param idx Entry index
133 *
134 * @return true if entry is pending, false otherwise
135 */
136 static inline bool
da1469x_pdc_is_pending(int idx)137 da1469x_pdc_is_pending(int idx)
138 {
139 return PDC->PDC_PENDING_REG & (1 << idx);
140 }
141
142 /**
143 * Acknowledge all pending entries on M33 core
144 */
145 void da1469x_pdc_ack_all_m33(void);
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif /* __DA1469X_PDC_H_ */
152