3434#define ENABLE_BUS_CLK_CALC
3535
3636#ifndef BUILD_LOADER_STAGE1
37- /* Tests */
38- #if 0
39- #define TEST_DDR
40- #define TEST_TPM
41- #endif
4237 #define ENABLE_PCIE
4338 #define ENABLE_CPLD /* Board Configuration and Status Registers (BCSR) */
4439 #define ENABLE_CONF_IO
4540 #define ENABLE_QE /* QUICC Engine */
46- #if defined(WOLFBOOT_TPM ) || defined( TEST_TPM )
41+ #if defined(WOLFBOOT_TPM )
4742 #define ENABLE_ESPI /* SPI for TPM */
4843 #endif
4944 #define ENABLE_MP /* multi-core support */
5045 #define ENABLE_IRQ
5146 /* #define ENABLE_QE_CRC32 */ /* CRC32 check on QE disabled by default */
5247#endif
5348
54- /* Foward declarations */
55- #if defined(ENABLE_DDR ) && defined(TEST_DDR )
56- static int test_ddr (void );
57- #endif
58- #if defined(ENABLE_ESPI ) && defined(TEST_TPM )
59- static int test_tpm (void );
60- #endif
61-
6249#ifdef ENABLE_ESPI
6350#include "spi_drv.h" /* for transfer flags and chip select */
6451#endif
@@ -488,11 +475,7 @@ static uint32_t flash_idx;
488475int ext_flash_read (uintptr_t address , uint8_t * data , int len );
489476#endif
490477
491- /* generic share NXP QorIQ driver code */
492- #include "nxp_ppc.c"
493-
494-
495- /* local functions */
478+ /* P1021 bus clock: reads GUTS_PORPLLSR (different from E5500/E6500 CLOCKING regs) */
496479#ifdef ENABLE_BUS_CLK_CALC
497480static uint32_t hal_get_bus_clk (void )
498481{
@@ -508,53 +491,16 @@ static uint32_t hal_get_bus_clk(void)
508491#define hal_get_bus_clk () (uint32_t)(SYS_CLK * 6)
509492#endif
510493
494+ /* E500 uses bus-clock based delay (not TIMEBASE like E5500/E6500) */
511495#define DELAY_US (hal_get_bus_clk() / 1000000)
512496static void udelay (uint32_t delay_us )
513497{
514498 wait_ticks (delay_us * DELAY_US );
515499}
516500
517- #if 0 /* useful timer code */
518-
519- uint64_t hal_timer_ms (void )
520- {
521- uint64_t val ;
522- /* time base is updated every 8 CCB clocks */
523- uint64_t cntfrq = hal_get_bus_clk () / 8 ;
524- uint64_t cntpct = get_ticks ();
525- val = (cntpct * 1000ULL ) / cntfrq ;
526- return val ;
527- }
528-
529- /* example usage */
530- //uint64_t start = hal_get_tick_count();
531- // do some work
532- //wolfBoot_printf("done (%lu ms)\n", (uint32_t)hal_elapsed_time_ms(start));
533-
534- /* Calculate elapsed time in milliseconds, handling timer overflow properly */
535- uint64_t hal_elapsed_time_ms (uint64_t start_ticks )
536- {
537- uint64_t current_ticks , elapsed_ticks ;
538- uint64_t cntfrq = hal_get_bus_clk () / 8 ;
539-
540- current_ticks = get_ticks ();
541-
542- /* Handle timer overflow using unsigned arithmetic
543- * This works correctly even if the timer has rolled over,
544- * as long as the elapsed time is less than the full timer range
545- */
546- elapsed_ticks = current_ticks - start_ticks ;
547-
548- /* Convert elapsed ticks to milliseconds */
549- return (elapsed_ticks * 1000ULL ) / cntfrq ;
550- }
501+ /* generic share NXP QorIQ driver code (uart_init/uart_write use hal_get_bus_clk above) */
502+ #include "nxp_ppc.c"
551503
552- /* Get current tick count for use with hal_elapsed_time_ms() */
553- uint64_t hal_get_tick_count (void )
554- {
555- return get_ticks ();
556- }
557- #endif
558504
559505/* ---- eSPI Driver ---- */
560506#ifdef ENABLE_ESPI
@@ -673,47 +619,7 @@ void hal_espi_deinit(void)
673619}
674620#endif /* ENABLE_ESPI */
675621
676- /* ---- DUART Driver ---- */
677- #ifdef DEBUG_UART
678-
679- void uart_init (void )
680- {
681- /* calc divisor for UART
682- * baud rate = CCSRBAR frequency ÷ (16 x [UDMB||UDLB])
683- */
684- /* compute UART divisor - round up */
685- uint32_t div = (hal_get_bus_clk () + (16 /2 * BAUD_RATE )) / (16 * BAUD_RATE );
686-
687- while (!(get8 (UART_LSR (UART_SEL )) & UART_LSR_TEMT ))
688- ;
689-
690- /* set ier, fcr, mcr */
691- set8 (UART_IER (UART_SEL ), 0 );
692- set8 (UART_FCR (UART_SEL ), (UART_FCR_TFR | UART_FCR_RFR | UART_FCR_FEN ));
693-
694- /* enable baud rate access (DLAB=1) - divisor latch access bit*/
695- set8 (UART_LCR (UART_SEL ), (UART_LCR_DLAB | UART_LCR_WLS ));
696- /* set divisor */
697- set8 (UART_DLB (UART_SEL ), (div & 0xff ));
698- set8 (UART_DMB (UART_SEL ), ((div >>8 ) & 0xff ));
699- /* disable rate access (DLAB=0) */
700- set8 (UART_LCR (UART_SEL ), (UART_LCR_WLS ));
701- }
702-
703- void uart_write (const char * buf , uint32_t sz )
704- {
705- uint32_t pos = 0 ;
706- while (sz -- > 0 ) {
707- char c = buf [pos ++ ];
708- if (c == '\n' ) { /* handle CRLF */
709- while ((get8 (UART_LSR (UART_SEL )) & UART_LSR_THRE ) == 0 );
710- set8 (UART_THR (UART_SEL ), '\r' );
711- }
712- while ((get8 (UART_LSR (UART_SEL )) & UART_LSR_THRE ) == 0 );
713- set8 (UART_THR (UART_SEL ), c );
714- }
715- }
716- #endif /* DEBUG_UART */
622+ /* uart_init and uart_write are provided by nxp_ppc.c shared code */
717623
718624/* ---- eLBC Driver ---- */
719625#ifdef ENABLE_ELBC
0 commit comments