b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * (C)Copyright 2022 ASR. All Rights Reserved. |
| 4 | * |
| 5 | |
| 6 | ******************************************************************************/ |
| 7 | |
| 8 | #include "PlatformConfig.h" |
| 9 | #include "platform_interrupts.h" |
| 10 | #include "predefines.h" |
| 11 | #include "USB_controller.h" |
| 12 | #include "USB_PHY.h" |
| 13 | #include "PMUA.h" |
| 14 | #include "Flash.h" |
| 15 | #include "timer.h" |
| 16 | #include "uart_regs.h" |
| 17 | #include "geu_interface.h" |
| 18 | #include "APBC.h" |
| 19 | #include "obm2osl.h" |
| 20 | #include "misc.h" |
| 21 | #include "sdhc2.h" |
| 22 | #include "Provisioning.h" |
| 23 | #include "Typedef.h" |
| 24 | #include "serial.h" |
| 25 | #include "downloader.h" |
| 26 | #include "BootLoader.h" |
| 27 | #include "sdram_config.h" |
| 28 | #include "I2C.h" |
| 29 | #include "CIU.h" |
| 30 | #include "spi.h" |
| 31 | #include "tinyalloc.h" |
| 32 | |
| 33 | #include "PlatformCommon.h" |
| 34 | |
| 35 | static UINT8_T rdp_buf_idx = 0; |
| 36 | |
| 37 | /* |
| 38 | * Table definitions for multi function pin registers |
| 39 | */ |
| 40 | |
| 41 | #if UPDATE_USE_GPIO |
| 42 | CS_REGISTER_PAIR_S gpio_key_pins[] = |
| 43 | { |
| 44 | (int *) (APPS_PAD_BASE | 0x02f0), 0xB081, 0x0, //GPIO55 -> Key_uAP |
| 45 | (int *) (APPS_PAD_BASE | 0x02f4), 0xB081, 0x0, //GPIO56 -> Key_TD |
| 46 | (int *) (APPS_PAD_BASE | 0x0300), 0xB081, 0x0, //GPIO59 -> Key_WiFi |
| 47 | 0x0,0x0,0x0 // termination |
| 48 | }; |
| 49 | #endif |
| 50 | |
| 51 | #if MMC_CODE |
| 52 | // MMC2 controller compatible pinout |
| 53 | CS_REGISTER_PAIR_S mmc2_pins[]= |
| 54 | { |
| 55 | (INT *) (APPS_PAD_BASE | 0x02FC), 0x1040, 0x0, //MMC2_CMD |
| 56 | (INT *) (APPS_PAD_BASE | 0x0300), 0x1040, 0x0, //MMC2_CLK |
| 57 | (INT *) (APPS_PAD_BASE | 0x02F8), 0x1040, 0x0, //MMC2_DAT0 |
| 58 | (INT *) (APPS_PAD_BASE | 0x02F4), 0x1040, 0x0, //MMC2_DAT1 |
| 59 | (INT *) (APPS_PAD_BASE | 0x02F0), 0x1040, 0x0, //MMC2_DAT2 |
| 60 | (INT *) (APPS_PAD_BASE | 0x02EC), 0x1040, 0x0, //MMC2_DAT3 |
| 61 | (INT *) (APPS_PAD_BASE | 0x02D0), 0xd042, 0x0, //MMC2_DAT4 |
| 62 | (INT *) (APPS_PAD_BASE | 0x02CC), 0xd042, 0x0, //MMC2_DAT5 |
| 63 | (INT *) (APPS_PAD_BASE | 0x02C8), 0xd042, 0x0, //MMC2_DAT6 |
| 64 | (INT *) (APPS_PAD_BASE | 0x02C4), 0xd042, 0x0, //MMC2_DAT7 |
| 65 | 0x0,0x0,0x0 //termination |
| 66 | }; |
| 67 | |
| 68 | #endif |
| 69 | |
| 70 | CS_REGISTER_PAIR_S uart_pins[]= |
| 71 | { |
| 72 | #if CPUART |
| 73 | (int *) (APPS_PAD_BASE | 0x01A8), 0x5081, 0x0, //TX |
| 74 | (int *) (APPS_PAD_BASE | 0x01AC), 0x5081, 0x0, //RX |
| 75 | #else |
| 76 | (int *) (APPS_PAD_BASE | 0x0150), 0x5081, 0x0, //TX |
| 77 | (int *) (APPS_PAD_BASE | 0x0154), 0x5081, 0x0, //RX |
| 78 | #endif |
| 79 | 0x0,0x0,0x0 //termination |
| 80 | }; |
| 81 | |
| 82 | #if SPINOR_CODE |
| 83 | CS_REGISTER_PAIR_S spi_nor_pins[]= |
| 84 | { |
| 85 | (int *) (APPS_PAD_BASE | 0x2C4), 0x1081, 0x0, //nHold |
| 86 | (int *) (APPS_PAD_BASE | 0x2C8), 0x1081, 0x0, //nWP |
| 87 | (int *) (APPS_PAD_BASE | 0x2CC), 0x1082, 0x0, //RX |
| 88 | (int *) (APPS_PAD_BASE | 0x2D0), 0x1082, 0x0, //TX |
| 89 | (int *) (APPS_PAD_BASE | 0x2D4), 0x1082, 0x0, //CLK |
| 90 | #ifdef SSP_CS_USE_GPIO |
| 91 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1081, 0x0, //FRM (CS): GPIO_76 |
| 92 | #else |
| 93 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1082, 0x0, //FRM (CS) |
| 94 | #endif |
| 95 | 0x0,0x0,0x0 //termination |
| 96 | }; |
| 97 | |
| 98 | CS_REGISTER_PAIR_S spi_nor_pins_falcon_z1[]= |
| 99 | { |
| 100 | /* Falcon Z1: GPIO12-15 is used for SSP2, QSPI use dedicatd pins |
| 101 | * TODO: Falcon A0 will use the same pins with QSPI |
| 102 | */ |
| 103 | (int *) (APPS_PAD_BASE | 0x114), 0x1087, 0x0, //RX |
| 104 | (int *) (APPS_PAD_BASE | 0x118), 0x1087, 0x0, //TX |
| 105 | (int *) (APPS_PAD_BASE | 0x10C), 0x1087, 0x0, //CLK |
| 106 | #ifdef SSP_CS_USE_GPIO |
| 107 | (int *) (APPS_PAD_BASE | 0x110), 0x1080, 0x0, //FRM (CS) GPIO_13 |
| 108 | #else |
| 109 | (int *) (APPS_PAD_BASE | 0x110), 0x1087, 0x0, //FRM (CS) |
| 110 | #endif |
| 111 | 0x0,0x0,0x0 //termination |
| 112 | }; |
| 113 | |
| 114 | CS_REGISTER_PAIR_S spi_nor_pins_falcon_a0[]= |
| 115 | { |
| 116 | (int *) (APPS_PAD_BASE | 0x2C4), 0x1081, 0x0, //nHold |
| 117 | (int *) (APPS_PAD_BASE | 0x2C8), 0x1081, 0x0, //nWP |
| 118 | (int *) (APPS_PAD_BASE | 0x2CC), 0x1084, 0x0, //RX |
| 119 | (int *) (APPS_PAD_BASE | 0x2D0), 0x1084, 0x0, //TX |
| 120 | (int *) (APPS_PAD_BASE | 0x2D4), 0x1084, 0x0, //CLK |
| 121 | #ifdef SSP_CS_USE_GPIO |
| 122 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1081, 0x0, //FRM (CS): GPIO_76 |
| 123 | #else |
| 124 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1084, 0x0, //FRM (CS) |
| 125 | #endif |
| 126 | 0x0,0x0,0x0 //termination |
| 127 | }; |
| 128 | #endif |
| 129 | |
| 130 | #if SPINAND_CODE |
| 131 | CS_REGISTER_PAIR_S spi_nand_pins[]= |
| 132 | { |
| 133 | (int *) (APPS_PAD_BASE | 0x2C4), 0x1081, 0x0, //nHold |
| 134 | (int *) (APPS_PAD_BASE | 0x2C8), 0x1081, 0x0, //nWP |
| 135 | (int *) (APPS_PAD_BASE | 0x2CC), 0x1082, 0x0, //RX |
| 136 | (int *) (APPS_PAD_BASE | 0x2D0), 0x1082, 0x0, //TX |
| 137 | (int *) (APPS_PAD_BASE | 0x2D4), 0x1082, 0x0, //CLK |
| 138 | #ifdef SSP_CS_USE_GPIO |
| 139 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1081, 0x0, //FRM (CS): GPIO_76 |
| 140 | #else |
| 141 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1082, 0x0, //FRM (CS) |
| 142 | #endif |
| 143 | 0x0,0x0,0x0 //termination |
| 144 | }; |
| 145 | |
| 146 | CS_REGISTER_PAIR_S spi_nand_pins_falcon_z1[]= |
| 147 | { |
| 148 | /* Falcon Z1: GPIO12-15 is used for SSP2, QSPI use dedicatd pins |
| 149 | * TODO: Falcon A0 will use the same pins with QSPI |
| 150 | */ |
| 151 | (int *) (APPS_PAD_BASE | 0x114), 0x1087, 0x0, //RX |
| 152 | (int *) (APPS_PAD_BASE | 0x118), 0x1087, 0x0, //TX |
| 153 | (int *) (APPS_PAD_BASE | 0x10C), 0x1087, 0x0, //CLK |
| 154 | #ifdef SSP_CS_USE_GPIO |
| 155 | (int *) (APPS_PAD_BASE | 0x110), 0x1080, 0x0, //FRM (CS) GPIO_13 |
| 156 | #else |
| 157 | (int *) (APPS_PAD_BASE | 0x110), 0x1087, 0x0, //FRM (CS) |
| 158 | #endif |
| 159 | 0x0,0x0,0x0 //termination |
| 160 | }; |
| 161 | |
| 162 | CS_REGISTER_PAIR_S spi_nand_pins_falcon_a0[]= |
| 163 | { |
| 164 | (int *) (APPS_PAD_BASE | 0x2C4), 0x1081, 0x0, //nHold |
| 165 | (int *) (APPS_PAD_BASE | 0x2C8), 0x1081, 0x0, //nWP |
| 166 | (int *) (APPS_PAD_BASE | 0x2CC), 0x1084, 0x0, //RX |
| 167 | (int *) (APPS_PAD_BASE | 0x2D0), 0x1084, 0x0, //TX |
| 168 | (int *) (APPS_PAD_BASE | 0x2D4), 0x1084, 0x0, //CLK |
| 169 | #ifdef SSP_CS_USE_GPIO |
| 170 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1081, 0x0, //FRM (CS): GPIO_76 |
| 171 | #else |
| 172 | (int *) (APPS_PAD_BASE | 0x2D8), 0x1084, 0x0, //FRM (CS) |
| 173 | #endif |
| 174 | 0x0,0x0,0x0 //termination |
| 175 | }; |
| 176 | #endif |
| 177 | |
| 178 | const CS_REGISTER_PAIR_S pi2c_pins[]= |
| 179 | { |
| 180 | (int *) (APPS_PAD_BASE | 0x01B0), 0xd0c2, 0x0, //CI2C_SCL |
| 181 | (int *) (APPS_PAD_BASE | 0x01B4), 0xd0c2, 0x0, //CI2C_SDA |
| 182 | 0x0,0x0,0x0 //termination |
| 183 | }; |
| 184 | |
| 185 | #if QSPINAND_CODE || QSPINOR_CODE |
| 186 | const CS_REGISTER_PAIR_S qspi_pins[]= |
| 187 | { |
| 188 | (int *) (APPS_PAD_BASE | 0x2c4), 0xd000, 0x0, //QSPI_DAT3 |
| 189 | (int *) (APPS_PAD_BASE | 0x2c8), 0xd000, 0x0, //QSPI_DAT2 |
| 190 | (int *) (APPS_PAD_BASE | 0x2cc), 0x1000, 0x0, //QSPI_DAT1 |
| 191 | (int *) (APPS_PAD_BASE | 0x2d0), 0x1000, 0x0, //QSPI_DAT0 |
| 192 | (int *) (APPS_PAD_BASE | 0x2d4), 0x1000, 0x0, //QSPI_CLK |
| 193 | (int *) (APPS_PAD_BASE | 0x2d8), 0x1000, 0x0, //QSPI_CS1 |
| 194 | 0x0,0x0,0x0 //termination |
| 195 | }; |
| 196 | #endif |
| 197 | |
| 198 | #if SPINOR_CODE |
| 199 | void ChipSelectSPINOR( void ) |
| 200 | { |
| 201 | obm_printf("ManuCS 26MHz\n\r"); |
| 202 | reg_write(APBC_SSP2_CLK_RST, BIT0 | BIT1 | BIT2); |
| 203 | reg_write(APBC_SSP2_CLK_RST, BIT0 | BIT1 | (2 << 4)); // 26MHZ |
| 204 | |
| 205 | if(PlatformIsNezhac()){ |
| 206 | ConfigRegWrite(spi_nor_pins); |
| 207 | |
| 208 | //GPIO 71/72 output high |
| 209 | reg_bit_set((GPIO2_BASE + GPIO_SDR), 0x180); |
| 210 | reg_bit_set((GPIO2_BASE + GPIO_PSR), 0x180); |
| 211 | |
| 212 | //GPIO 76 output high |
| 213 | reg_bit_set((GPIO2_BASE + GPIO_SDR), (1 << 12)); // high |
| 214 | reg_bit_set((GPIO2_BASE + GPIO_PSR), (1 << 12)); // output |
| 215 | } else if (PlatformIsFalconA0() || PlatformIsFalconT()) { |
| 216 | obm_printf("Falcon A0 spi pinmux for NOR\n\r"); |
| 217 | ConfigRegWrite(spi_nor_pins_falcon_a0); |
| 218 | |
| 219 | //GPIO 71/72 output high |
| 220 | reg_bit_set((GPIO2_BASE + GPIO_SDR), 0x180); |
| 221 | reg_bit_set((GPIO2_BASE + GPIO_PSR), 0x180); |
| 222 | |
| 223 | //GPIO 76 output high |
| 224 | reg_bit_set((GPIO2_BASE + GPIO_SDR), (1 << 12)); // high |
| 225 | reg_bit_set((GPIO2_BASE + GPIO_PSR), (1 << 12)); // output |
| 226 | |
| 227 | }else{ |
| 228 | ConfigRegWrite(spi_nor_pins_falcon_z1); |
| 229 | } |
| 230 | return; |
| 231 | } |
| 232 | #endif |
| 233 | |
| 234 | #if SPINAND_CODE |
| 235 | void ChipSelectSPINAND( void ) |
| 236 | { |
| 237 | //enabled SSP2 clock, then take out of reset |
| 238 | obm_printf("ManuCS 26MHz\n\r"); |
| 239 | reg_write(APBC_SSP2_CLK_RST, BIT0 | BIT1 | BIT2); |
| 240 | reg_write(APBC_SSP2_CLK_RST, BIT0 | BIT1 | (2 << 4)); // 26MHZ |
| 241 | |
| 242 | if(PlatformIsNezhac()){ |
| 243 | ConfigRegWrite(spi_nand_pins); |
| 244 | |
| 245 | //GPIO 71/72 output high |
| 246 | reg_bit_set((GPIO2_BASE + GPIO_SDR), 0x180); |
| 247 | reg_bit_set((GPIO2_BASE + GPIO_PSR), 0x180); |
| 248 | |
| 249 | //GPIO 76 output high |
| 250 | reg_bit_set((GPIO2_BASE + GPIO_SDR), (1 << 12)); // high |
| 251 | reg_bit_set((GPIO2_BASE + GPIO_PSR), (1 << 12)); // output |
| 252 | } else if (PlatformIsFalconA0() || PlatformIsFalconT()) { |
| 253 | obm_printf("Falcon A0 spi pinmux\n\r"); |
| 254 | ConfigRegWrite(spi_nand_pins_falcon_a0); |
| 255 | |
| 256 | //GPIO 71/72 output high |
| 257 | reg_bit_set((GPIO2_BASE + GPIO_SDR), 0x180); |
| 258 | reg_bit_set((GPIO2_BASE + GPIO_PSR), 0x180); |
| 259 | |
| 260 | //GPIO 76 output high |
| 261 | reg_bit_set((GPIO2_BASE + GPIO_SDR), (1 << 12)); // high |
| 262 | reg_bit_set((GPIO2_BASE + GPIO_PSR), (1 << 12)); // output |
| 263 | |
| 264 | }else{ |
| 265 | ConfigRegWrite(spi_nand_pins_falcon_z1); |
| 266 | } |
| 267 | |
| 268 | return; |
| 269 | } |
| 270 | #endif |
| 271 | |
| 272 | #if QSPINAND_CODE || QSPINOR_CODE |
| 273 | void ChipSelectQSPI( void ) |
| 274 | { |
| 275 | ConfigRegWrite(qspi_pins); |
| 276 | return; |
| 277 | } |
| 278 | #endif |
| 279 | |
| 280 | UINT_T getPlatformPortSelection(unsigned int *default_usb_port) |
| 281 | { |
| 282 | UINT_T port; |
| 283 | |
| 284 | *default_usb_port = CI2_USB_D; |
| 285 | port = 7; // send default configuration USB only |
| 286 | |
| 287 | return port; |
| 288 | } |
| 289 | |
| 290 | #if UPDATE_USE_GPIO |
| 291 | UINT_T PlatformGPIOKeyConfig(void) |
| 292 | { |
| 293 | UINT_T Temp; |
| 294 | |
| 295 | ConfigRegWrite(gpio_key_pins); |
| 296 | |
| 297 | *(VUINT_T *)(GPIO1_BASE + GPIO_CDR) |= BIT23 | BIT24 | BIT27; // GPIO 55, 56, 59 |
| 298 | Delay(1000); |
| 299 | Temp = *(VUINT_T *)(GPIO1_BASE + GPIO_CDR); |
| 300 | Temp = *(VUINT_T *)(GPIO1_BASE + GPIO_PLR); |
| 301 | |
| 302 | return (NoError); |
| 303 | } |
| 304 | |
| 305 | UINT_T PlatformCheckGPIOKey(void) |
| 306 | { |
| 307 | UINT_T RegisterValue, i; |
| 308 | UINT_T key_detected = 0; |
| 309 | |
| 310 | RegisterValue = *(VUINT_T *)(GPIO1_BASE + GPIO_PLR); |
| 311 | if (((RegisterValue >> 23) & 1) == 1) // GPIO55/Key_uAP |
| 312 | key_detected = KEYID_PRODUCT_USB_MODE_REQUEST; |
| 313 | |
| 314 | return key_detected; |
| 315 | } |
| 316 | #endif |
| 317 | |
| 318 | UINT_T PlatformUARTConfig(void) |
| 319 | { |
| 320 | UINT_T temp; |
| 321 | ConfigRegWrite(uart_pins); |
| 322 | #if LAPW |
| 323 | *(VUINT_T *)APBC_UART3_CLK_RST = (BIT4 | BIT1 | BIT0); |
| 324 | temp = *(VUINT_T *)APBC_UART3_CLK_RST; |
| 325 | #else |
| 326 | #if CPUART |
| 327 | *(VUINT_T *)APBC_UART1_CLK_RST = (BIT4 | BIT1 | BIT0); |
| 328 | temp = *(VUINT_T *)APBC_UART1_CLK_RST; |
| 329 | #else |
| 330 | *(VUINT_T *)APBC_UART0_CLK_RST = (BIT4 | BIT1 | BIT0); |
| 331 | temp = *(VUINT_T *)APBC_UART0_CLK_RST; |
| 332 | #endif |
| 333 | #endif |
| 334 | |
| 335 | return (NoError); |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * Set NAND and UART clocks in the PMUM Clock Gating Register |
| 340 | */ |
| 341 | void CheckDefaultClocks(void) |
| 342 | { |
| 343 | volatile UINT_T Temp; //-JML- declared volatile since it's not used and to resolve compiler warning #550 |
| 344 | |
| 345 | *(VUINT_T *)PMUM_ACGR = 0xFFFFFFFF; |
| 346 | *(VUINT_T *)PMUM_CCGR = 0xFFFFFFFF; |
| 347 | |
| 348 | // AIB unit must be out of reset for MFPR set up |
| 349 | *(VUINT_T *)APBC_AIB_CLK_RST = 0x7; |
| 350 | Temp = *(VUINT_T *)APBC_AIB_CLK_RST; |
| 351 | *(VUINT_T *)APBC_AIB_CLK_RST = 0x3; |
| 352 | Temp = *(VUINT_T *)APBC_AIB_CLK_RST; |
| 353 | |
| 354 | // Get the GPIO unit out of reset, too. |
| 355 | *(VUINT_T *)APBC_GPIO_CLK_RST = 0x7; |
| 356 | Temp = *(VUINT_T *)APBC_GPIO_CLK_RST; |
| 357 | *(VUINT_T *)APBC_GPIO_CLK_RST = 0x3; |
| 358 | Temp = *(VUINT_T *)APBC_GPIO_CLK_RST; |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | #if MMC_CODE |
| 363 | // MMC |
| 364 | CONTROLLER_TYPE ConfigureMMC(UINT8_T FlashNum, UINT_T *pBaseAddress, UINT_T *pInterruptMask, UINT_T *pFusePartitionNumber) |
| 365 | { |
| 366 | UINT_T sdh_clk; |
| 367 | |
| 368 | // Tavor TD only supports MMC3 boot |
| 369 | ConfigRegSave(mmc2_pins); |
| 370 | ConfigRegWrite(mmc2_pins); |
| 371 | *pBaseAddress = SDHC0_2_BASE; |
| 372 | *pInterruptMask = INT_MMC; |
| 373 | |
| 374 | //Enable PMUA clock for this interface |
| 375 | // Notes: |
| 376 | // Documentation should state that: |
| 377 | // PMUA_SDH0_CLK_RES_CTRL -> offset 0x054 |
| 378 | // PMUA_SDH1_CLK_RES_CTRL -> offset 0x058 |
| 379 | // PMUA_SDH2_CLK_RES_CTRL -> offset 0x0E0 |
| 380 | // |
| 381 | // However, out header file PMUA.H states: |
| 382 | // PMUA_SDH0_CLK_RES_CTRL -> offset 0x054 |
| 383 | // PMUA_SDH1_CLK_RES_CTRL -> offset 0x0E0 |
| 384 | |
| 385 | #if BASE_CLOCK_208MHZ |
| 386 | sdh_clk = SDH_CLK_FC_REQ | SDH_CLK_SEL_416MHZ | SDH_CLK_DIV(1); // 208MHZ |
| 387 | #else |
| 388 | sdh_clk = SDH_CLK_FC_REQ | SDH_CLK_SEL_416MHZ | SDH_CLK_DIV(3); // 104MHZ |
| 389 | #endif |
| 390 | reg_write(PMUA_SDH0_CLK_RES_CTRL, sdh_clk | APMU_PERIPH_CLK_EN | APMU_AXI_CLK_EN | APMU_PERIPH_RESET | APMU_AXI_RESET); |
| 391 | reg_write(PMUA_SDH1_CLK_RES_CTRL, sdh_clk | APMU_PERIPH_CLK_EN | APMU_AXI_CLK_EN | APMU_PERIPH_RESET | APMU_AXI_RESET); |
| 392 | |
| 393 | while ((*(VUINT_T *) PMUA_SDH0_CLK_RES_CTRL) & SDH_CLK_FC_REQ); |
| 394 | while ((*(VUINT_T *) PMUA_SDH1_CLK_RES_CTRL) & SDH_CLK_FC_REQ); |
| 395 | |
| 396 | // Now pick the partition we are supposed to boot from. |
| 397 | *pFusePartitionNumber = MMC_SD_USER_PARTITION; |
| 398 | |
| 399 | return MMCSDHC1_1; // MMC2 |
| 400 | } |
| 401 | |
| 402 | void DisableMMCSlots() |
| 403 | { |
| 404 | DisablePeripheralIRQInterrupt(INT_MMC); |
| 405 | |
| 406 | // Disable PMUA clocks for the SD controllers |
| 407 | *(UINT_T *) PMUA_SDH1_CLK_RES_CTRL = 0x0; //Disable PMUA clock for this interface |
| 408 | |
| 409 | // Restores the MMC GPIO's back to their default values |
| 410 | ConfigRegRestore(mmc2_pins); |
| 411 | } |
| 412 | |
| 413 | UINT_T MMCHighSpeedTimingEnabled() |
| 414 | { |
| 415 | return 1; |
| 416 | } |
| 417 | #endif |
| 418 | |
| 419 | void Platform_PortEnable(pFUSE_SET pFuses) |
| 420 | { |
| 421 | pTIM pTIM_h = GetTimPointer(); |
| 422 | SetUpUSBDescriptors (pTIM_h, 1); |
| 423 | InitPort(30); |
| 424 | |
| 425 | return; |
| 426 | } |
| 427 | |
| 428 | void Platform_USB2_Shutdown() |
| 429 | { |
| 430 | // Power down PHY and PLL |
| 431 | // only turn off only those that BR |
| 432 | // had to turn on |
| 433 | //------------------------------------ |
| 434 | //*ACCR1 &= (~ci2ACCR1TurnOns); //DCB TTC-bringup |
| 435 | |
| 436 | // Use D0CKEN_C reg to turn off 26Mhz |
| 437 | // clock, for PHY PLL input |
| 438 | // only turn-off only those that BR |
| 439 | // had to turn on |
| 440 | //------------------------------------ |
| 441 | //*D0CKEN_C &= (~ci2D0TurnOns); //DCB TTC-bringup |
| 442 | |
| 443 | //*OSCC &= ~0x800; // turn off CLK_POUT |
| 444 | |
| 445 | #if KAGU |
| 446 | BU_REG_WRITE((PMUA_BASE+0x170), 0x00000); //turn off USB AXI clock |
| 447 | #else |
| 448 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL = 0x0; //turn off USB AXI clock |
| 449 | #endif |
| 450 | } |
| 451 | |
| 452 | //---------------------------------------------- |
| 453 | // OTG PHY setup TTD2 |
| 454 | // |
| 455 | //---------------------------------------------- |
| 456 | void Platform_KAGU_USB2_ON_USB2_PHY_Init(void) |
| 457 | { |
| 458 | UINT32 usb_reset_timeout = 3000; |
| 459 | UINT32 pll_wait_us = 400; |
| 460 | UINT32 val; |
| 461 | |
| 462 | //wait for 200 us |
| 463 | BU_REG_WRITE((PMUA_BASE+0x170), 0x00000); |
| 464 | //need to wait 10us |
| 465 | Delay(10); |
| 466 | BU_REG_WRITE((PMUA_BASE+0x170), 0x1E000); |
| 467 | Delay(5); |
| 468 | |
| 469 | //USB PHY config |
| 470 | //step.1 |
| 471 | //config phphy, sw init done, ref clk cfg=2 |
| 472 | //open allclk en bits |
| 473 | BU_REG_WRITE(PUPHY0_REG02, 0x97C); |
| 474 | |
| 475 | //step.2 wait for PUPHY PLL READY |
| 476 | while((BU_REG_READ(PUPHY0_REG02) & 0x1) != 0x1) |
| 477 | { |
| 478 | Delay(1); |
| 479 | pll_wait_us--; |
| 480 | if (pll_wait_us == 0) |
| 481 | break; |
| 482 | } |
| 483 | |
| 484 | //step.3 override pipe_phystatus to 0 if puphy pll not ready |
| 485 | if (pll_wait_us == 0) |
| 486 | BU_REG_WRITE(PUPHY0_REG10, (BU_REG_READ(PUPHY0_REG10) | (0x1 << 10))); |
| 487 | |
| 488 | //step.4 wait for USB2 PHY PLL READY |
| 489 | pll_wait_us = 400; |
| 490 | while (((BU_REG_READ(USB2_PHY0_REG01) & USB2_PLL_BIT_RDY) != USB2_PLL_BIT_RDY) |
| 491 | && (pll_wait_us--)) |
| 492 | { |
| 493 | Delay(1); |
| 494 | } |
| 495 | |
| 496 | BU_REG_WRITE(USB2_PHY0_REG29, BU_REG_READ(USB2_PHY0_REG29) & (~BIT14)); |
| 497 | //Step 5&6 |
| 498 | //Release usb2 phy internal reset and enable clock gating |
| 499 | BU_REG_WRITE(USB2_PHY0_REG01, 0x60ef); |
| 500 | BU_REG_WRITE(USB2_PHY0_REG0D, 0x1C); |
| 501 | |
| 502 | //STEP.7 |
| 503 | /*0x1: serial mode, 0x0: parallel mode |
| 504 | * USB2_PHY0_REG06 (USB2_BASE+0x18) |
| 505 | */ |
| 506 | /* set to serial mode for stability */ |
| 507 | BU_REG_WRITE(USB2_PHY0_REG06, BU_REG_READ(USB2_PHY0_REG06) | (BIT0)); |
| 508 | |
| 509 | /* TX DAC increase 10% */ |
| 510 | BU_REG_WRITE(USB2_PHY0_REG29, |
| 511 | (BU_REG_READ(USB2_PHY0_REG29) & (~0x1F)) | (BIT4 | 0xB)); |
| 512 | } |
| 513 | |
| 514 | void Platform_LPWG_USB2_ON_USB2_PHY_Init(void) |
| 515 | { |
| 516 | UINT32 pll_wait_us = 200; |
| 517 | |
| 518 | /* reset usb phy/controller to default state */ |
| 519 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL = 0; |
| 520 | //wait for 50 us |
| 521 | Delay(50); |
| 522 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= PMUA_USB_CLK_RES_CTRL_USB_AXICLK_EN; |
| 523 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= PMUA_USB_CLK_RES_CTRL_USB_SPH_AXI_RST; |
| 524 | |
| 525 | /* Release usb controller and axi */ |
| 526 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= (PMUA_USB_CLK_RES_CTRL_USB_AXI_RST | PMUA_USB_CTRL_RLS_RST); |
| 527 | |
| 528 | //step.1 wait for USB2 PHY PLL READY |
| 529 | pll_wait_us = 400; |
| 530 | while (((BU_REG_READ(USB2_PHY0_REG01) & USB2_PLL_BIT_RDY) != USB2_PLL_BIT_RDY) |
| 531 | && (pll_wait_us--)) |
| 532 | { |
| 533 | Delay(1); |
| 534 | } |
| 535 | |
| 536 | //Step 2&3 |
| 537 | //Release usb2 phy internal reset and enable clock gating |
| 538 | BU_REG_WRITE(USB2_PHY0_REG01, 0x60ef); |
| 539 | BU_REG_WRITE(USB2_PHY0_REG0D, 0x1C); |
| 540 | |
| 541 | //STEP.4 |
| 542 | /*0x1: serial mode, 0x0: parallel mode |
| 543 | * USB2_PHY0_REG06 (USB2_BASE+0x18) |
| 544 | */ |
| 545 | /* set to serial mode for stability */ |
| 546 | BU_REG_WRITE(USB2_PHY0_REG06, BU_REG_READ(USB2_PHY0_REG06) | (BIT0)); |
| 547 | } |
| 548 | |
| 549 | void Platform_USB2_ON_USB2_PHY_Init(void) |
| 550 | { |
| 551 | UINT32 usb_reset_timeout = 3000; |
| 552 | UINT32 pll_wait_us = 200; |
| 553 | volatile int j = 0, k = 0; |
| 554 | |
| 555 | #if KAGU |
| 556 | Platform_KAGU_USB2_ON_USB2_PHY_Init(); |
| 557 | return; |
| 558 | #elif LAPW |
| 559 | Platform_LPWG_USB2_ON_USB2_PHY_Init(); |
| 560 | return; |
| 561 | #else |
| 562 | |
| 563 | /* reset usb phy/controller to default state */ |
| 564 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL = PMUA_USB_CLK_RES_CTRL_USB_SPH_AXI_RST; |
| 565 | //wait for 50 us |
| 566 | Delay(50); |
| 567 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= PMUA_USB_CLK_RES_CTRL_USB_AXICLK_EN; |
| 568 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= PMUA_USB_CLK_RES_CTRL_USB_AXI_RST; |
| 569 | |
| 570 | //wait for 50 us |
| 571 | Delay(50); |
| 572 | |
| 573 | //WAIT FOR PHY PLL RDY |
| 574 | while (((BU_REG_READ(USB2_PHY_REG01) & USB2_PLL_BIT_RDY) != USB2_PLL_BIT_RDY) |
| 575 | && (pll_wait_us--)) |
| 576 | { |
| 577 | Delay(1); |
| 578 | } |
| 579 | |
| 580 | #if NZAC |
| 581 | //Workaround for usb fs phy issue |
| 582 | BU_REG_WRITE(USB2_PHY_REG28, BU_REG_READ(USB2_PHY_REG28) & (~BIT14)); |
| 583 | BU_REG_WRITE(USB_CMD, BU_REG_READ(USB_CMD) & (~BIT0)); |
| 584 | BU_REG_WRITE(USB2_PHY_REG08, BU_REG_READ(USB2_PHY_REG08) & (~BIT6)); |
| 585 | BU_REG_WRITE(USB2_PHY_REG0A, BU_REG_READ(USB2_PHY_REG0A) | (BIT4)); |
| 586 | /* Make some delay */ |
| 587 | Delay(40); |
| 588 | BU_REG_WRITE(USB2_PHY_REG0A, BU_REG_READ(USB2_PHY_REG0A) & (~BIT4)); |
| 589 | #endif |
| 590 | |
| 591 | #if FLCN || FACT |
| 592 | BU_REG_WRITE(USB2_PHY_REG29, BU_REG_READ(USB2_PHY_REG29) & (~BIT14)); |
| 593 | /* set to serial mode for stability */ |
| 594 | BU_REG_WRITE(USB2_PHY_REG06, BU_REG_READ(USB2_PHY_REG06) | (BIT0)); |
| 595 | |
| 596 | /* TX DAC increase 10%, will add back for some speciall cases */ |
| 597 | /* BU_REG_WRITE(USB2_PHY_REG29, |
| 598 | (BU_REG_READ(USB2_PHY_REG29) & (~0x1F)) | (BIT4 | 0xB)); */ |
| 599 | #endif |
| 600 | |
| 601 | //Release usb2 phy internal reset and enable clock gating |
| 602 | BU_REG_WRITE(USB2_PHY_REG01, 0x60ef); |
| 603 | BU_REG_WRITE(USB2_PHY_REG0D, 0x1C); |
| 604 | |
| 605 | //enable parallel mode, default is serial mode |
| 606 | //BU_REG_WRITE(USB2_PHY_REG06, BU_REG_READ(USB2_PHY_REG06) & ~(USB2_CFG_HS_SRCS_SEL)); |
| 607 | |
| 608 | /* Release usb controller */ |
| 609 | #if FACT |
| 610 | *(VUINT_T *)PMUA_USB_CLK_RES_CTRL |= PMUA_USB_CTRL_RLS_RST; |
| 611 | #endif |
| 612 | |
| 613 | #endif |
| 614 | } |
| 615 | |
| 616 | VOID DisplaySecurityInfo(VOID) |
| 617 | { |
| 618 | UINT_T AP_Config[3]; |
| 619 | UINT_T op_mode; |
| 620 | |
| 621 | GEU_ReadApConfigFuseBits(AP_Config, 10); |
| 622 | op_mode = ((AP_Config[2] & 0xC00) >> 10); |
| 623 | |
| 624 | obm_printf("BootROM OP Mode: %d\n\r", op_mode); |
| 625 | |
| 626 | if(op_mode == 2) |
| 627 | obm_printf("Trusted Boot enabled\n\r"); |
| 628 | else |
| 629 | obm_printf("Trusted Boot not enabled\n\r"); |
| 630 | |
| 631 | #if ATRB_ENABLE |
| 632 | if(GEU_MajorAntiRollBackEnabled()){ |
| 633 | obm_printf("Anti-rollback fuse enabled\n\r") |
| 634 | obm_printf("ATRB Major Version: 0x%x\n\r", GEU_ReadMajorVersion()); |
| 635 | } |
| 636 | #endif |
| 637 | } |
| 638 | |
| 639 | void ShutdownPort(void) |
| 640 | { |
| 641 | DisablePeripheralIRQInterrupt(USB0_OTG_INT); |
| 642 | Platform_USB2_Shutdown(); |
| 643 | } |
| 644 | |
| 645 | #if 0 |
| 646 | INT_T PlatformIsNezhac(void) |
| 647 | { |
| 648 | UINT ChipID_value = PlatformGetChipID(); |
| 649 | |
| 650 | return (ChipID_value == 0x1802); |
| 651 | } |
| 652 | |
| 653 | INT_T PlatformIsFalcon(void) |
| 654 | { |
| 655 | UINT ChipID_value = PlatformGetChipID(); |
| 656 | |
| 657 | return (ChipID_value == 0x1803); |
| 658 | } |
| 659 | |
| 660 | INT_T PlatformIsFalconT(void) |
| 661 | { |
| 662 | UINT ChipID_value = PlatformGetChipID(); |
| 663 | |
| 664 | return (ChipID_value == 0x1806); |
| 665 | } |
| 666 | |
| 667 | INT_T PlatformIsFalconA0(void) |
| 668 | { |
| 669 | UINT ChipID_value = PlatformGetChipID(); |
| 670 | UINT StepID_value = PlatformGetRevisionID(); |
| 671 | |
| 672 | return (ChipID_value == 0x1803 && StepID_value == 0xA0); |
| 673 | } |
| 674 | |
| 675 | INT_T PlatformIsKagu(void) |
| 676 | { |
| 677 | UINT ChipID_value = PlatformGetChipID(); |
| 678 | |
| 679 | return (ChipID_value == 0x1829); |
| 680 | } |
| 681 | |
| 682 | INT_T PlatformIsLapwing(void) |
| 683 | { |
| 684 | UINT ChipID_value = PlatformGetChipID(); |
| 685 | |
| 686 | return (ChipID_value == 0x1903); |
| 687 | } |
| 688 | #endif |
| 689 | |
| 690 | #if LAPW |
| 691 | INT_T PlatformIsLapwA0(void) |
| 692 | { |
| 693 | UINT ChipID_value = PlatformGetChipID(); |
| 694 | UINT StepID = PlatformGetRevisionID(); |
| 695 | |
| 696 | return ((ChipID_value == 0x1903) && (StepID == 0xA0)); |
| 697 | } |
| 698 | |
| 699 | INT_T PlatformIsLapwB0(void) |
| 700 | { |
| 701 | UINT ChipID_value = PlatformGetChipID(); |
| 702 | UINT StepID = PlatformGetRevisionID(); |
| 703 | |
| 704 | return ((ChipID_value == 0x1903) && (StepID == 0xB0)); |
| 705 | } |
| 706 | |
| 707 | INT_T PlatformIsLapwZ1(void) |
| 708 | { |
| 709 | UINT ChipID_value = PlatformGetChipID(); |
| 710 | UINT StepID = PlatformGetRevisionID(); |
| 711 | |
| 712 | return ((ChipID_value == 0x1903) && (StepID == 0xF0)); |
| 713 | } |
| 714 | #endif |
| 715 | |
| 716 | UINT_T PlatformPI2CConfig(void) |
| 717 | { |
| 718 | // Get the TWSI unit out of reset, too. |
| 719 | reg_write(APBCP_ICER, 0x0); |
| 720 | reg_write(APBCP_ICER, 0x7); |
| 721 | reg_write(APBCP_ICER, 0x3); |
| 722 | |
| 723 | return NoError; |
| 724 | } |
| 725 | |
| 726 | UINT_T PlatformPI2CConfig2(void) |
| 727 | { |
| 728 | // Get the TWSI unit out of reset, too. |
| 729 | reg_write(APBC_TWSI1_CLK_RST, 0x7); |
| 730 | reg_write(APBC_TWSI1_CLK_RST, 0x3); |
| 731 | |
| 732 | return NoError; |
| 733 | } |
| 734 | |
| 735 | UINT_T PlatformCheckEMMDStatus(void) |
| 736 | { |
| 737 | UINT_T emmd_status0 = 0; |
| 738 | UINT_T emmd_status1 = 0; |
| 739 | UINT_T emmd_status2 = 0; |
| 740 | |
| 741 | emmd_status0 = *(VUINT_T *)DDR_RDCA_LOAD_ADDR0; |
| 742 | emmd_status1 = *(VUINT_T *)DDR_RDCA_LOAD_ADDR1; |
| 743 | emmd_status2 = *(VUINT_T *)DDR_RDCA_LOAD_ADDR2; |
| 744 | PlatformReleaseEMMDStatus(); |
| 745 | |
| 746 | /* firstly check the rdp flag is set at DDR_RDCA_LOAD_ADDR0, and secondly |
| 747 | * check it at DDR_RDCA_LOAD_ADDR1, DDR_RDCA_LOAD_ADDR2 |
| 748 | */ |
| 749 | if (RDCAIDENTIFIER == emmd_status0) { |
| 750 | rdp_buf_idx = 0; |
| 751 | return 1; |
| 752 | } else if (RDCAIDENTIFIER == emmd_status1) { |
| 753 | rdp_buf_idx = 1; |
| 754 | return 1; |
| 755 | } else if (RDCAIDENTIFIER == emmd_status2) { |
| 756 | rdp_buf_idx = 2; |
| 757 | return 1; |
| 758 | } else { |
| 759 | return 0; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | void PlatformSetEMMDStatus(void) |
| 764 | { |
| 765 | if (0 == rdp_buf_idx) |
| 766 | *(VUINT_T *)DDR_RDCA_LOAD_ADDR0 = RDCAIDENTIFIER; |
| 767 | else if (1 == rdp_buf_idx) |
| 768 | *(VUINT_T *)DDR_RDCA_LOAD_ADDR1 = RDCAIDENTIFIER; |
| 769 | else |
| 770 | *(VUINT_T *)DDR_RDCA_LOAD_ADDR2 = RDCAIDENTIFIER; |
| 771 | } |
| 772 | |
| 773 | void PlatformReleaseEMMDStatus(void) |
| 774 | { |
| 775 | if (!is_heap_init()) |
| 776 | return; |
| 777 | free(RAMDUMP_MEM_START); |
| 778 | } |
| 779 | |
| 780 | void PlatformEnableBusReset(void) |
| 781 | { |
| 782 | UINT_T value = 0; |
| 783 | |
| 784 | value = BU_REG_READ(PI2C_BASE_REGS + I2C_ICYC_offset); |
| 785 | BU_REG_WRITE((PI2C_BASE_REGS + I2C_ICYC_offset), value | 0x9); // 9 cycles |
| 786 | |
| 787 | value = BU_REG_READ(PI2C_BASE_REGS + I2C_ICR_offset); |
| 788 | BU_REG_WRITE((PI2C_BASE_REGS + I2C_ICR_offset), value | BIT28); // enable bus reset |
| 789 | |
| 790 | Delay(5000); // wait until the control bit is self-cleared |
| 791 | |
| 792 | value = BU_REG_READ(PI2C_BASE_REGS + I2C_ICR_offset); |
| 793 | if (value & BIT28) // still not cleared |
| 794 | obm_printf("Bus Reset is not self-cleared\n\r"); |
| 795 | } |
| 796 | |
| 797 | //TODO: better to skip ddr freq change if don't do ddr test to keep the same flow as old code |
| 798 | //TODO: MCK5_Check_LPDDR2_Info should be called before this function to keep ddr work @266mhz |
| 799 | UINT_T PlatformFrequencyChange(INT_T CorePP, INT_T DdrPP, INT_T AxiPP) |
| 800 | { |
| 801 | UINT_T cfg, div, idx; |
| 802 | UINT_T time_out = 1000; |
| 803 | UINT_T clk_sel = 0, clk_div = 1; |
| 804 | |
| 805 | if (CorePP == -1) |
| 806 | goto skip_cpu_fc; |
| 807 | #if !CP_BOOT |
| 808 | switch(CorePP){ |
| 809 | #if 0 /* not used and reduce code size ? */ |
| 810 | case 0: |
| 811 | obm_printf("Core@624 "); |
| 812 | //PLL_624 pclk_div=0x1 mem_clk_div=2 bus_clk_div=3 |
| 813 | cfg = (0x2<<9) | (0x1<<6) | (0x0<<3) | (0x0<<0); |
| 814 | break; |
| 815 | #endif |
| 816 | case 1: |
| 817 | #if !NZAC |
| 818 | //PLL1 SW control, enable PLL1_832 which default is off on Falcon |
| 819 | BU_REG_WRITE(APB_SPARE2_REG, BU_REG_READ(APB_SPARE2_REG) | 0x1); |
| 820 | #endif |
| 821 | obm_printf("Core@832 "); |
| 822 | //PLL_832 pclk_div=0x1 mem_clk_div=2 bus_clk_div=2 |
| 823 | cfg = (0x1<<9) | (0x1<<6) | (0x0<<3) | (0x4<<0); |
| 824 | break; |
| 825 | #if 0 /* voltage is not enought for this pp and reduce code size ? */ |
| 826 | case 2: |
| 827 | obm_printf("Core@1248 "); |
| 828 | //Enable PLL1_1248 |
| 829 | #if NZAC |
| 830 | BU_REG_WRITE(APB_SPARE2_REG, BU_REG_READ(APB_SPARE2_REG) | (1 << 3)); |
| 831 | #else |
| 832 | BU_REG_WRITE(APB_SPARE2_REG, BU_REG_READ(APB_SPARE2_REG) | (1 << 8)); //Falcon |
| 833 | #endif |
| 834 | //PLL_1248 pclk_div=0x1 mem_clk_div=2 bus_clk_div=2 |
| 835 | cfg = (0x1<<9) | (0x1<<6) | (0x0<<3) | (0x5<<0); |
| 836 | break; |
| 837 | #endif |
| 838 | default: |
| 839 | break; |
| 840 | } |
| 841 | cfg |= (1 << 12); |
| 842 | BU_REG_WRITE(PMUA_AP_CLK_CTRL, cfg); |
| 843 | do{ |
| 844 | cfg = BU_REG_READ(PMUA_AP_CLK_CTRL); |
| 845 | if((cfg & 0x1000) == 0) |
| 846 | break; |
| 847 | Delay(1); |
| 848 | time_out --; |
| 849 | }while(time_out); |
| 850 | if(time_out == 0) |
| 851 | { |
| 852 | obm_printf("CA7 frequency change failed\n\r"); |
| 853 | } |
| 854 | #endif |
| 855 | |
| 856 | skip_cpu_fc: |
| 857 | #if 1 |
| 858 | if (DdrPP == -1) |
| 859 | goto skip_ddr_fc; |
| 860 | |
| 861 | //ddr frequency change |
| 862 | switch(DdrPP) |
| 863 | { |
| 864 | case 0: |
| 865 | obm_printf("DDR@266 "); |
| 866 | //266 |
| 867 | div = 0x4; |
| 868 | idx = 0; |
| 869 | #if LAPW |
| 870 | clk_sel = (0 << 18); |
| 871 | clk_div = (1 << 16); |
| 872 | #endif |
| 873 | break; |
| 874 | case 1: |
| 875 | //533 1:1 |
| 876 | obm_printf("DDR@533 "); |
| 877 | div = 0x0; |
| 878 | idx = 1; |
| 879 | #if LAPW |
| 880 | clk_sel = (0 << 18); |
| 881 | clk_div = (0 << 16); |
| 882 | #endif |
| 883 | break; |
| 884 | } |
| 885 | |
| 886 | #if !LAPW |
| 887 | cfg = BU_REG_READ(PMUA_CKPHY_FC_CTRL); |
| 888 | cfg &= 0xfffffff0; |
| 889 | cfg |= div; |
| 890 | BU_REG_WRITE(PMUA_CKPHY_FC_CTRL, cfg); |
| 891 | |
| 892 | cfg = BU_REG_READ(PMUA_MC_HW_SLP_TYPE); |
| 893 | cfg &= ~(3 << 5); |
| 894 | cfg |= (idx << 5); //select table |
| 895 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 896 | |
| 897 | cfg |= 0x01000000; |
| 898 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 899 | #else |
| 900 | if (PlatformIsLapwZ1()) { |
| 901 | cfg = BU_REG_READ(PMUA_CKPHY_FC_CTRL); |
| 902 | cfg &= 0xfffffff0; |
| 903 | cfg |= div; |
| 904 | BU_REG_WRITE(PMUA_CKPHY_FC_CTRL, cfg); |
| 905 | |
| 906 | cfg = BU_REG_READ(PMUA_MC_HW_SLP_TYPE); |
| 907 | cfg &= ~(3 << 5); |
| 908 | cfg |= (idx << 5); //select table |
| 909 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 910 | |
| 911 | cfg |= 0x01000000; |
| 912 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 913 | } else { |
| 914 | obm_printf("19003a0p\n\r"); |
| 915 | cfg = BU_REG_READ(PMUA_MC_HW_SLP_TYPE); |
| 916 | cfg &= ~(MC_HW_SLP_TYPE_MASK | MC_HW_SLP_DCLK_SRC_MASK); |
| 917 | cfg |= ((idx << 5) | clk_sel | clk_div); //select table |
| 918 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 919 | |
| 920 | cfg |= 0x01000000; |
| 921 | BU_REG_WRITE(PMUA_MC_HW_SLP_TYPE, cfg); |
| 922 | } |
| 923 | #endif |
| 924 | |
| 925 | time_out = 1000; |
| 926 | do{ |
| 927 | cfg = BU_REG_READ(PMUA_MC_HW_SLP_TYPE); |
| 928 | if((cfg & 0x01000000) == 0) |
| 929 | break; |
| 930 | Delay(1); |
| 931 | time_out --; |
| 932 | }while(time_out); |
| 933 | if(time_out == 0) |
| 934 | { |
| 935 | obm_printf("DDR frequency change failed\n\r"); |
| 936 | } |
| 937 | #endif |
| 938 | |
| 939 | skip_ddr_fc: |
| 940 | |
| 941 | if (AxiPP == -1) |
| 942 | goto skip_axi_fc; |
| 943 | //axi frequency change |
| 944 | switch(AxiPP) |
| 945 | { |
| 946 | #if 0 /* not used and reduce code size ? */ |
| 947 | case 0: |
| 948 | obm_printf("AXI@156\n\r"); |
| 949 | #if FACT |
| 950 | cfg = 0x4; |
| 951 | #elif KAGU |
| 952 | cfg = 0x5; |
| 953 | #else |
| 954 | cfg = 0x0 << 0; //156 |
| 955 | #endif |
| 956 | break; |
| 957 | #endif |
| 958 | case 0: |
| 959 | case 1: |
| 960 | obm_printf("AXI@208\n\r"); |
| 961 | #if KAGU |
| 962 | cfg = 0x0; |
| 963 | #else |
| 964 | cfg = 0x1 << 0; //208 |
| 965 | #endif |
| 966 | break; |
| 967 | default: |
| 968 | break; |
| 969 | } |
| 970 | cfg |= (1 << 4); |
| 971 | BU_REG_WRITE(PMUA_ACLK_CTRL, cfg); |
| 972 | time_out = 1000; |
| 973 | do{ |
| 974 | cfg = BU_REG_READ(PMUA_ACLK_CTRL); |
| 975 | if((cfg & 0x10) == 0) |
| 976 | break; |
| 977 | Delay(1); |
| 978 | time_out --; |
| 979 | }while(time_out); |
| 980 | if(time_out == 0) |
| 981 | { |
| 982 | obm_printf("AXI frequency change failed\n\r"); |
| 983 | } |
| 984 | skip_axi_fc: |
| 985 | return NoError; |
| 986 | } |
| 987 | |
| 988 | void PlatformHoldStateEnable(void) |
| 989 | { |
| 990 | //After reset, this bit should be cleared to 0 |
| 991 | //If not, something may be wrong |
| 992 | if((BU_REG_READ(STATE_HOLD_CTRL) & 1) != 0){ |
| 993 | obm_printf("State hold controlling error\n\r"); |
| 994 | return; |
| 995 | } |
| 996 | |
| 997 | obm_printf("DVC_STATUS_HD: 0x%x\n\r", BU_REG_READ(DVC_STATUS_HD)); |
| 998 | obm_printf("CP_PMU_STATUS_HD: 0x%x\n\r", BU_REG_READ(CP_PMU_STATUS_HD)); |
| 999 | obm_printf("AP_PMU_STATUS_HD: 0x%x\n\r", BU_REG_READ(AP_PMU_STATUS_HD)); |
| 1000 | #if LAPW |
| 1001 | obm_printf("CR5 HD registers:\n\r"); |
| 1002 | obm_printf("PC: 0x%08x --> 0x%08x\n\r", BU_REG_READ(LAPW_CR5_PC_LST), BU_REG_READ(LAPW_CR5_PC_HD)); |
| 1003 | obm_printf("SP: 0x%08x CPSR: 0x%08x\n\r", BU_REG_READ(LAPW_CR5_SP_HD), BU_REG_READ(LAPW_CR5_CPSR_HD)); |
| 1004 | obm_printf("LR: 0x%08x SPSR: 0x%08x\n\r", BU_REG_READ(LAPW_CR5_LR_HD), BU_REG_READ(LAPW_CR5_SPSR_HD)); |
| 1005 | obm_printf("CA7 HD registers:\n\r"); |
| 1006 | obm_printf("PC: 0x%08x --> 0x%08x\n\r", BU_REG_READ(LAPW_CA7_PC_LST), BU_REG_READ(LAPW_CA7_PC_HD)); |
| 1007 | obm_printf("SP: 0x%08x CPSR: 0x%08x\n\r", BU_REG_READ(LAPW_CA7_SP_HD), BU_REG_READ(LAPW_CA7_CPSR_HD)); |
| 1008 | obm_printf("LR: 0x%08x SPSR: 0x%08x\n\r", BU_REG_READ(LAPW_CA7_LR_HD), BU_REG_READ(LAPW_CA7_SPSR_HD)); |
| 1009 | #else |
| 1010 | obm_printf("CR5_PC_HD: 0x%x\n\r", BU_REG_READ(CR5_PC_HD)); |
| 1011 | obm_printf("CR5_CPSR_HD: 0x%x\n\r", BU_REG_READ(CR5_CPSR_HD)); |
| 1012 | obm_printf("CR5_SPSR_HD: 0x%x\n\r", BU_REG_READ(CR5_SPSR_HD)); |
| 1013 | obm_printf("CA7_PC_HD: 0x%x\n\r", BU_REG_READ(CA7_PC_HD)); |
| 1014 | obm_printf("CA7_CPSR_HD: 0x%x\n\r", BU_REG_READ(CA7_CPSR_HD)); |
| 1015 | obm_printf("CA7_SPSR_HD: 0x%x\n\r", BU_REG_READ(CA7_SPSR_HD)); |
| 1016 | #endif |
| 1017 | |
| 1018 | BU_REG_WRITE(STATE_HOLD_CTRL, 0x1); |
| 1019 | } |
| 1020 | |
| 1021 | VOID PlatformInitFM(UINT_T *max_tim_size_byte) |
| 1022 | { |
| 1023 | #if NZAC |
| 1024 | *max_tim_size_byte = 0x1000; |
| 1025 | #elif FACT || LAPW |
| 1026 | *max_tim_size_byte = 0x4000; |
| 1027 | #else |
| 1028 | *max_tim_size_byte = 0x2000; //Falcon, Kagu |
| 1029 | #endif |
| 1030 | } |
| 1031 | |
| 1032 | INT_T PlatformUSBPluggedIn(void) |
| 1033 | { |
| 1034 | if ((*(VUINT_T *)PMUA_SD_ROT_WAKE_CLR) & PMUA_SD_ROT_WAKE_CLR_USB_VBUS_STS) |
| 1035 | return 1; |
| 1036 | |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
| 1040 | CHAR *PlatformName(void) |
| 1041 | { |
| 1042 | #if NZAC |
| 1043 | return "ASR1802SL"; |
| 1044 | #endif |
| 1045 | |
| 1046 | #if FLCN |
| 1047 | return "ASR1803"; |
| 1048 | #endif |
| 1049 | |
| 1050 | #if KAGU |
| 1051 | return "ASR1828"; |
| 1052 | #endif |
| 1053 | |
| 1054 | #if FACT |
| 1055 | return "ASR1806"; |
| 1056 | #endif |
| 1057 | |
| 1058 | #if LAPW |
| 1059 | return "ASR1903"; |
| 1060 | #endif |
| 1061 | |
| 1062 | return "Unknow Chip"; |
| 1063 | } |
| 1064 | |
| 1065 | VOID PlatformLateInit(VOID) |
| 1066 | { |
| 1067 | //Enable State hold feature and dump HD registers |
| 1068 | PlatformHoldStateEnable(); |
| 1069 | |
| 1070 | //CA7@832 DDR@533 AXI@208 |
| 1071 | PlatformFrequencyChange(1, -1, 1); |
| 1072 | } |
| 1073 | |
| 1074 | #if LAPW |
| 1075 | BR_ESTATE lBR_Estate; |
| 1076 | VOID ParseBR_ExtraState(UINT_T EstateValue) |
| 1077 | { |
| 1078 | if(!PlatformIsLapwB0()) { |
| 1079 | lBR_Estate.value = 0; |
| 1080 | return; |
| 1081 | } |
| 1082 | |
| 1083 | lBR_Estate.value = EstateValue; |
| 1084 | |
| 1085 | obm_printf("EBRState: 0x%x\n\r", EstateValue); |
| 1086 | |
| 1087 | #if 0 |
| 1088 | if(lBR_Estate.bits.HwHash) { |
| 1089 | obm_printf("HW hash enabled\n\r"); |
| 1090 | } |
| 1091 | |
| 1092 | if(lBR_Estate.bits.HwRSAV) { |
| 1093 | obm_printf("HW RSAV enabled\n\r"); |
| 1094 | } |
| 1095 | |
| 1096 | if(lBR_Estate.bits.BkupTIM) { |
| 1097 | obm_printf("Boot from Backup TIM\n\r"); |
| 1098 | } |
| 1099 | |
| 1100 | if(lBR_Estate.bits.BkupOBM) { |
| 1101 | obm_printf("Boot from Backup OBM\n\r"); |
| 1102 | } |
| 1103 | |
| 1104 | if(lBR_Estate.bits.A7Fdis) { |
| 1105 | obm_printf("A7 Fuse disabled\n\r"); |
| 1106 | } |
| 1107 | #endif |
| 1108 | } |
| 1109 | |
| 1110 | INT_T HwHashIsUsed(void) |
| 1111 | { |
| 1112 | return lBR_Estate.bits.HwHash; |
| 1113 | } |
| 1114 | |
| 1115 | INT_T HwRASVIsUsed(void) |
| 1116 | { |
| 1117 | return lBR_Estate.bits.HwRSAV; |
| 1118 | } |
| 1119 | |
| 1120 | #endif |