1 /* 2 * Copyright (c) 2021-2024 HPMicro 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 9 #ifndef HPM_PLLCTLV2_H 10 #define HPM_PLLCTLV2_H 11 12 typedef struct { 13 __RW uint32_t XTAL; /* 0x0: OSC configuration */ 14 __R uint8_t RESERVED0[124]; /* 0x4 - 0x7F: Reserved */ 15 struct { 16 __RW uint32_t MFI; /* 0x80: PLL0 multiple register */ 17 __RW uint32_t MFN; /* 0x84: PLL0 fraction numerator register */ 18 __RW uint32_t MFD; /* 0x88: PLL0 fraction demoninator register */ 19 __RW uint32_t SS_STEP; /* 0x8C: PLL0 spread spectrum step register */ 20 __RW uint32_t SS_STOP; /* 0x90: PLL0 spread spectrum stop register */ 21 __RW uint32_t CONFIG; /* 0x94: PLL0 confguration register */ 22 __RW uint32_t LOCKTIME; /* 0x98: PLL0 lock time register */ 23 __RW uint32_t STEPTIME; /* 0x9C: PLL0 step time register */ 24 __RW uint32_t ADVANCED; /* 0xA0: PLL0 advance configuration register */ 25 __R uint8_t RESERVED0[28]; /* 0xA4 - 0xBF: Reserved */ 26 __RW uint32_t DIV[3]; /* 0xC0 - 0xC8: PLL0 divider output 0 configuration register */ 27 __R uint8_t RESERVED1[52]; /* 0xCC - 0xFF: Reserved */ 28 } PLL[2]; 29 } PLLCTLV2_Type; 30 31 32 /* Bitfield definition for register: XTAL */ 33 /* 34 * BUSY (RO) 35 * 36 * Busy flag 37 * 0: Oscillator is working or shutdown 38 * 1: Oscillator is changing status 39 */ 40 #define PLLCTLV2_XTAL_BUSY_MASK (0x80000000UL) 41 #define PLLCTLV2_XTAL_BUSY_SHIFT (31U) 42 #define PLLCTLV2_XTAL_BUSY_GET(x) (((uint32_t)(x) & PLLCTLV2_XTAL_BUSY_MASK) >> PLLCTLV2_XTAL_BUSY_SHIFT) 43 44 /* 45 * RESPONSE (RO) 46 * 47 * Crystal oscillator status 48 * 0: Oscillator is not stable 49 * 1: Oscillator is stable for use 50 */ 51 #define PLLCTLV2_XTAL_RESPONSE_MASK (0x20000000UL) 52 #define PLLCTLV2_XTAL_RESPONSE_SHIFT (29U) 53 #define PLLCTLV2_XTAL_RESPONSE_GET(x) (((uint32_t)(x) & PLLCTLV2_XTAL_RESPONSE_MASK) >> PLLCTLV2_XTAL_RESPONSE_SHIFT) 54 55 /* 56 * ENABLE (RO) 57 * 58 * Crystal oscillator enable status 59 * 0: Oscillator is off 60 * 1: Oscillator is on 61 */ 62 #define PLLCTLV2_XTAL_ENABLE_MASK (0x10000000UL) 63 #define PLLCTLV2_XTAL_ENABLE_SHIFT (28U) 64 #define PLLCTLV2_XTAL_ENABLE_GET(x) (((uint32_t)(x) & PLLCTLV2_XTAL_ENABLE_MASK) >> PLLCTLV2_XTAL_ENABLE_SHIFT) 65 66 /* 67 * RAMP_TIME (RW) 68 * 69 * Rampup time of XTAL oscillator in cycles of RC24M clock 70 * 0: 0 cycle 71 * 1: 1 cycle 72 * 2: 2 cycle 73 * 1048575: 1048575 cycles 74 */ 75 #define PLLCTLV2_XTAL_RAMP_TIME_MASK (0xFFFFFUL) 76 #define PLLCTLV2_XTAL_RAMP_TIME_SHIFT (0U) 77 #define PLLCTLV2_XTAL_RAMP_TIME_SET(x) (((uint32_t)(x) << PLLCTLV2_XTAL_RAMP_TIME_SHIFT) & PLLCTLV2_XTAL_RAMP_TIME_MASK) 78 #define PLLCTLV2_XTAL_RAMP_TIME_GET(x) (((uint32_t)(x) & PLLCTLV2_XTAL_RAMP_TIME_MASK) >> PLLCTLV2_XTAL_RAMP_TIME_SHIFT) 79 80 /* Bitfield definition for register of struct array PLL: MFI */ 81 /* 82 * BUSY (RO) 83 * 84 * Busy flag 85 * 0: PLL is stable or shutdown 86 * 1: PLL is changing status 87 */ 88 #define PLLCTLV2_PLL_MFI_BUSY_MASK (0x80000000UL) 89 #define PLLCTLV2_PLL_MFI_BUSY_SHIFT (31U) 90 #define PLLCTLV2_PLL_MFI_BUSY_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFI_BUSY_MASK) >> PLLCTLV2_PLL_MFI_BUSY_SHIFT) 91 92 /* 93 * RESPONSE (RO) 94 * 95 * PLL status 96 * 0: PLL is not stable 97 * 1: PLL is stable for use 98 */ 99 #define PLLCTLV2_PLL_MFI_RESPONSE_MASK (0x20000000UL) 100 #define PLLCTLV2_PLL_MFI_RESPONSE_SHIFT (29U) 101 #define PLLCTLV2_PLL_MFI_RESPONSE_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFI_RESPONSE_MASK) >> PLLCTLV2_PLL_MFI_RESPONSE_SHIFT) 102 103 /* 104 * ENABLE (RO) 105 * 106 * PLL enable status 107 * 0: PLL is off 108 * 1: PLL is on 109 */ 110 #define PLLCTLV2_PLL_MFI_ENABLE_MASK (0x10000000UL) 111 #define PLLCTLV2_PLL_MFI_ENABLE_SHIFT (28U) 112 #define PLLCTLV2_PLL_MFI_ENABLE_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFI_ENABLE_MASK) >> PLLCTLV2_PLL_MFI_ENABLE_SHIFT) 113 114 /* 115 * MFI (RW) 116 * 117 * loop back divider of PLL, support from 13 to 42, f=fref*(mfi + mfn/mfd) 118 * 0-15: invalid 119 * 16: divide by 16 120 * 17: divide by17 121 * . . . 122 * 42: divide by 42 123 * 43~:invalid 124 */ 125 #define PLLCTLV2_PLL_MFI_MFI_MASK (0x7FU) 126 #define PLLCTLV2_PLL_MFI_MFI_SHIFT (0U) 127 #define PLLCTLV2_PLL_MFI_MFI_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_MFI_MFI_SHIFT) & PLLCTLV2_PLL_MFI_MFI_MASK) 128 #define PLLCTLV2_PLL_MFI_MFI_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFI_MFI_MASK) >> PLLCTLV2_PLL_MFI_MFI_SHIFT) 129 130 /* Bitfield definition for register of struct array PLL: MFN */ 131 /* 132 * MFN (RW) 133 * 134 * Numeratorof fractional part,f=fref*(mfi + mfn/mfd). This field supports changing while running. 135 */ 136 #define PLLCTLV2_PLL_MFN_MFN_MASK (0x3FFFFFFFUL) 137 #define PLLCTLV2_PLL_MFN_MFN_SHIFT (0U) 138 #define PLLCTLV2_PLL_MFN_MFN_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_MFN_MFN_SHIFT) & PLLCTLV2_PLL_MFN_MFN_MASK) 139 #define PLLCTLV2_PLL_MFN_MFN_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFN_MFN_MASK) >> PLLCTLV2_PLL_MFN_MFN_SHIFT) 140 141 /* Bitfield definition for register of struct array PLL: MFD */ 142 /* 143 * MFD (RW) 144 * 145 * Demoninator of fraction part,f=fref*(mfi + mfn/mfd). This field should not be changed during PLL enabled. If changed, change will take efftect when PLL re-enabled. 146 */ 147 #define PLLCTLV2_PLL_MFD_MFD_MASK (0x3FFFFFFFUL) 148 #define PLLCTLV2_PLL_MFD_MFD_SHIFT (0U) 149 #define PLLCTLV2_PLL_MFD_MFD_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_MFD_MFD_SHIFT) & PLLCTLV2_PLL_MFD_MFD_MASK) 150 #define PLLCTLV2_PLL_MFD_MFD_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_MFD_MFD_MASK) >> PLLCTLV2_PLL_MFD_MFD_SHIFT) 151 152 /* Bitfield definition for register of struct array PLL: SS_STEP */ 153 /* 154 * STEP (RW) 155 * 156 * Step of spread spectrum modulator. 157 * This register should not be changed during PLL and spread spectrum enabled. If changed, new value will take effect when PLL disabled or spread spectrum disabled. 158 */ 159 #define PLLCTLV2_PLL_SS_STEP_STEP_MASK (0x3FFFFFFFUL) 160 #define PLLCTLV2_PLL_SS_STEP_STEP_SHIFT (0U) 161 #define PLLCTLV2_PLL_SS_STEP_STEP_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_SS_STEP_STEP_SHIFT) & PLLCTLV2_PLL_SS_STEP_STEP_MASK) 162 #define PLLCTLV2_PLL_SS_STEP_STEP_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_SS_STEP_STEP_MASK) >> PLLCTLV2_PLL_SS_STEP_STEP_SHIFT) 163 164 /* Bitfield definition for register of struct array PLL: SS_STOP */ 165 /* 166 * STOP (RW) 167 * 168 * Stop point of spread spectrum modulator 169 * This register should not be changed during PLL and spread spectrum enabled. If changed, new value will take effect when PLL disabled or spread spectrum disabled. 170 */ 171 #define PLLCTLV2_PLL_SS_STOP_STOP_MASK (0x3FFFFFFFUL) 172 #define PLLCTLV2_PLL_SS_STOP_STOP_SHIFT (0U) 173 #define PLLCTLV2_PLL_SS_STOP_STOP_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_SS_STOP_STOP_SHIFT) & PLLCTLV2_PLL_SS_STOP_STOP_MASK) 174 #define PLLCTLV2_PLL_SS_STOP_STOP_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_SS_STOP_STOP_MASK) >> PLLCTLV2_PLL_SS_STOP_STOP_SHIFT) 175 176 /* Bitfield definition for register of struct array PLL: CONFIG */ 177 /* 178 * SPREAD (RW) 179 * 180 * Enable spread spectrum function. This field supports changing during PLL running. 181 */ 182 #define PLLCTLV2_PLL_CONFIG_SPREAD_MASK (0x100U) 183 #define PLLCTLV2_PLL_CONFIG_SPREAD_SHIFT (8U) 184 #define PLLCTLV2_PLL_CONFIG_SPREAD_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_CONFIG_SPREAD_SHIFT) & PLLCTLV2_PLL_CONFIG_SPREAD_MASK) 185 #define PLLCTLV2_PLL_CONFIG_SPREAD_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_CONFIG_SPREAD_MASK) >> PLLCTLV2_PLL_CONFIG_SPREAD_SHIFT) 186 187 /* 188 * REFSEL (RW) 189 * 190 * Select reference clock, This filed support changing while running, but application must take frequency error and jitter into consideration. And if MFN changed before reference switch, application need make sure time is enough for MFN updating. 191 * 0: XTAL24M 192 * 1: IRC24M 193 */ 194 #define PLLCTLV2_PLL_CONFIG_REFSEL_MASK (0x1U) 195 #define PLLCTLV2_PLL_CONFIG_REFSEL_SHIFT (0U) 196 #define PLLCTLV2_PLL_CONFIG_REFSEL_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_CONFIG_REFSEL_SHIFT) & PLLCTLV2_PLL_CONFIG_REFSEL_MASK) 197 #define PLLCTLV2_PLL_CONFIG_REFSEL_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_CONFIG_REFSEL_MASK) >> PLLCTLV2_PLL_CONFIG_REFSEL_SHIFT) 198 199 /* Bitfield definition for register of struct array PLL: LOCKTIME */ 200 /* 201 * LOCKTIME (RW) 202 * 203 * Lock time of PLL in 24M clock cycles, typical value is 2500. If MFI changed during PLL startup, PLL lock time may be longer than this setting. 204 */ 205 #define PLLCTLV2_PLL_LOCKTIME_LOCKTIME_MASK (0xFFFFU) 206 #define PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SHIFT (0U) 207 #define PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SHIFT) & PLLCTLV2_PLL_LOCKTIME_LOCKTIME_MASK) 208 #define PLLCTLV2_PLL_LOCKTIME_LOCKTIME_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_LOCKTIME_LOCKTIME_MASK) >> PLLCTLV2_PLL_LOCKTIME_LOCKTIME_SHIFT) 209 210 /* Bitfield definition for register of struct array PLL: STEPTIME */ 211 /* 212 * STEPTIME (RW) 213 * 214 * Step time for MFI on-the-fly change in 24M clock cycles, typical value is 2500. 215 */ 216 #define PLLCTLV2_PLL_STEPTIME_STEPTIME_MASK (0xFFFFU) 217 #define PLLCTLV2_PLL_STEPTIME_STEPTIME_SHIFT (0U) 218 #define PLLCTLV2_PLL_STEPTIME_STEPTIME_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_STEPTIME_STEPTIME_SHIFT) & PLLCTLV2_PLL_STEPTIME_STEPTIME_MASK) 219 #define PLLCTLV2_PLL_STEPTIME_STEPTIME_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_STEPTIME_STEPTIME_MASK) >> PLLCTLV2_PLL_STEPTIME_STEPTIME_SHIFT) 220 221 /* Bitfield definition for register of struct array PLL: ADVANCED */ 222 /* 223 * SLOW (RW) 224 * 225 * Use slow lock flow, PLL lock expendite is disabled. This mode might be stabler. And software need config LOCKTIME field accordingly. 226 * 0: fast lock enabled, lock time is 100us 227 * 1: fast lock disabled, lock time is 400us 228 */ 229 #define PLLCTLV2_PLL_ADVANCED_SLOW_MASK (0x10000000UL) 230 #define PLLCTLV2_PLL_ADVANCED_SLOW_SHIFT (28U) 231 #define PLLCTLV2_PLL_ADVANCED_SLOW_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_ADVANCED_SLOW_SHIFT) & PLLCTLV2_PLL_ADVANCED_SLOW_MASK) 232 #define PLLCTLV2_PLL_ADVANCED_SLOW_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_ADVANCED_SLOW_MASK) >> PLLCTLV2_PLL_ADVANCED_SLOW_SHIFT) 233 234 /* 235 * DITHER (RW) 236 * 237 * Enable dither function 238 */ 239 #define PLLCTLV2_PLL_ADVANCED_DITHER_MASK (0x1000000UL) 240 #define PLLCTLV2_PLL_ADVANCED_DITHER_SHIFT (24U) 241 #define PLLCTLV2_PLL_ADVANCED_DITHER_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_ADVANCED_DITHER_SHIFT) & PLLCTLV2_PLL_ADVANCED_DITHER_MASK) 242 #define PLLCTLV2_PLL_ADVANCED_DITHER_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_ADVANCED_DITHER_MASK) >> PLLCTLV2_PLL_ADVANCED_DITHER_SHIFT) 243 244 /* Bitfield definition for register of struct array PLL: DIV0 */ 245 /* 246 * BUSY (RO) 247 * 248 * Busy flag 249 * 0: divider is working 250 * 1: divider is changing status 251 */ 252 #define PLLCTLV2_PLL_DIV_BUSY_MASK (0x80000000UL) 253 #define PLLCTLV2_PLL_DIV_BUSY_SHIFT (31U) 254 #define PLLCTLV2_PLL_DIV_BUSY_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_DIV_BUSY_MASK) >> PLLCTLV2_PLL_DIV_BUSY_SHIFT) 255 256 /* 257 * RESPONSE (RO) 258 * 259 * Divider response status 260 * 0: Divider is not stable 261 * 1: Divider is stable for use 262 */ 263 #define PLLCTLV2_PLL_DIV_RESPONSE_MASK (0x20000000UL) 264 #define PLLCTLV2_PLL_DIV_RESPONSE_SHIFT (29U) 265 #define PLLCTLV2_PLL_DIV_RESPONSE_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_DIV_RESPONSE_MASK) >> PLLCTLV2_PLL_DIV_RESPONSE_SHIFT) 266 267 /* 268 * ENABLE (RO) 269 * 270 * Divider enable status 271 * 0: Divider is off 272 * 1: Divider is on 273 */ 274 #define PLLCTLV2_PLL_DIV_ENABLE_MASK (0x10000000UL) 275 #define PLLCTLV2_PLL_DIV_ENABLE_SHIFT (28U) 276 #define PLLCTLV2_PLL_DIV_ENABLE_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_DIV_ENABLE_MASK) >> PLLCTLV2_PLL_DIV_ENABLE_SHIFT) 277 278 /* 279 * DIV (RW) 280 * 281 * Divider factor, divider factor is DIV/5 + 1 282 * 0: divide by 1 283 * 1: divide by 1.2 284 * 2: divide by 1.4 285 * . . . 286 * 63: divide by 13.6 287 */ 288 #define PLLCTLV2_PLL_DIV_DIV_MASK (0x3FU) 289 #define PLLCTLV2_PLL_DIV_DIV_SHIFT (0U) 290 #define PLLCTLV2_PLL_DIV_DIV_SET(x) (((uint32_t)(x) << PLLCTLV2_PLL_DIV_DIV_SHIFT) & PLLCTLV2_PLL_DIV_DIV_MASK) 291 #define PLLCTLV2_PLL_DIV_DIV_GET(x) (((uint32_t)(x) & PLLCTLV2_PLL_DIV_DIV_MASK) >> PLLCTLV2_PLL_DIV_DIV_SHIFT) 292 293 294 295 /* DIV register group index macro definition */ 296 #define PLLCTLV2_PLL_DIV_DIV0 (0UL) 297 #define PLLCTLV2_PLL_DIV_DIV1 (1UL) 298 #define PLLCTLV2_PLL_DIV_DIV2 (2UL) 299 300 /* PLL register group index macro definition */ 301 #define PLLCTLV2_PLL_PLL0 (0UL) 302 #define PLLCTLV2_PLL_PLL1 (1UL) 303 304 305 #endif /* HPM_PLLCTLV2_H */ 306