]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - arch/blackfin/cpu/initcode.c
Merge branch 'master' of git://git.denx.de/u-boot-arm
[karo-tx-uboot.git] / arch / blackfin / cpu / initcode.c
index 1a066806d1fe1e765d2d576574ee5e7cbfacc0d3..fde54eaa3e55cefb8858214fcb1c3228fea77c6e 100644 (file)
 
 #include <config.h>
 #include <asm/blackfin.h>
+#include <asm/mach-common/bits/watchdog.h>
 #include <asm/mach-common/bits/bootrom.h>
 #include <asm/mach-common/bits/core.h>
-
-#define BUG() while (1) { asm volatile("emuexcpt;"); }
-
-#include "serial.h"
+#include <asm/serial.h>
 
 #ifndef __ADSPBF60x__
 #include <asm/mach-common/bits/ebiu.h>
@@ -147,8 +145,6 @@ static struct ddr_config ddr_config_table[] = {
 __attribute__((always_inline))
 static inline void serial_init(void)
 {
-       uint32_t uart_base = UART_BASE;
-
 #if defined(__ADSPBF54x__) || defined(__ADSPBF60x__)
 # ifdef BFIN_BOOT_UART_USE_RTS
 #  define BFIN_UART_USE_RTS 1
@@ -156,6 +152,7 @@ static inline void serial_init(void)
 #  define BFIN_UART_USE_RTS 0
 # endif
        if (BFIN_UART_USE_RTS && CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) {
+               uint32_t uart_base = UART_BASE;
                size_t i;
 
                /* force RTS rather than relying on auto RTS */
@@ -193,17 +190,12 @@ static inline void serial_init(void)
        }
 #endif
 
+#if CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_BYPASS
        if (BFIN_DEBUG_EARLY_SERIAL) {
-               int enabled = serial_early_enabled(uart_base);
-
-               serial_early_init(uart_base);
-
-               /* If the UART is off, that means we need to program
-                * the baud rate ourselves initially.
-                */
-               if (!enabled)
-                       serial_early_set_baud(uart_base, CONFIG_BAUDRATE);
+               serial_early_init(UART_BASE);
+               serial_early_set_baud(UART_BASE, CONFIG_BAUDRATE);
        }
+#endif
 }
 
 __attribute__((always_inline))
@@ -262,7 +254,8 @@ program_nmi_handler(void)
                "%1 = RETS;" /* Load addr of NMI handler */
                "RETS = %0;" /* Restore RETS */
                "[%2] = %1;" /* Write NMI handler */
-               : "=r"(tmp1), "=r"(tmp2) : "ab"(EVT2)
+               : "=d"(tmp1), "=d"(tmp2)
+               : "ab"(EVT2)
        );
 }
 
@@ -462,19 +455,29 @@ program_early_devices(ADI_BOOT_DATA *bs, uint *sdivB, uint *divB, uint *vcoB)
        if (CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_BYPASS) {
                serial_putc('e');
 #ifdef __ADSPBF60x__
+               /* Reset system event controller */
                bfin_write_SEC_GCTL(0x2);
+               bfin_write_SEC_CCTL(0x2);
                SSYNC();
+
+               /* Enable fault event input and system reset action in fault
+                * controller. Route watchdog timeout event to fault interface.
+                */
                bfin_write_SEC_FCTL(0xc1);
+               /* Enable watchdog interrupt source */
                bfin_write_SEC_SCTL(2, bfin_read_SEC_SCTL(2) | 0x6);
-
-               bfin_write_SEC_CCTL(0x2);
                SSYNC();
+
+               /* Enable system event controller */
                bfin_write_SEC_GCTL(0x1);
                bfin_write_SEC_CCTL(0x1);
+               SSYNC();
 #endif
+               bfin_write_WDOG_CTL(WDDIS);
+               SSYNC();
                bfin_write_WDOG_CNT(MSEC_TO_SCLK(CONFIG_HW_WATCHDOG_TIMEOUT_INITCODE));
 #if CONFIG_BFIN_BOOT_MODE != BFIN_BOOT_UART
-               bfin_write_WDOG_CTL(0);
+               bfin_write_WDOG_CTL(WDEN);
 #endif
                serial_putc('f');
        }
@@ -541,7 +544,7 @@ maybe_self_refresh(ADI_BOOT_DATA *bs)
 __attribute__((always_inline)) static inline u16
 program_clocks(ADI_BOOT_DATA *bs, bool put_into_srfs)
 {
-       u16 vr_ctl;
+       u16 vr_ctl = 0;
 
        serial_putc('a');
 
@@ -713,37 +716,36 @@ program_clocks(ADI_BOOT_DATA *bs, bool put_into_srfs)
 __attribute__((always_inline)) static inline void
 update_serial_clocks(ADI_BOOT_DATA *bs, uint sdivB, uint divB, uint vcoB)
 {
-       serial_putc('a');
-
        /* Since we've changed the SCLK above, we may need to update
         * the UART divisors (UART baud rates are based on SCLK).
         * Do the division by hand as there are no native instructions
         * for dividing which means we'd generate a libgcc reference.
         */
-       if (CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) {
-               unsigned int sdivR, vcoR;
-               int dividend = sdivB * divB * vcoR;
-               int divisor = vcoB * sdivR;
-               unsigned int quotient;
+       unsigned int sdivR, vcoR;
+       unsigned int dividend;
+       unsigned int divisor;
+       unsigned int quotient;
 
-               serial_putc('b');
+       serial_putc('a');
 
+       if (BFIN_DEBUG_EARLY_SERIAL ||
+               CONFIG_BFIN_BOOT_MODE == BFIN_BOOT_UART) {
 #ifdef __ADSPBF60x__
-               sdivR = bfin_read_CGU_DIV();
-               sdivR = ((sdivR >> 8) & 0x1f) * ((sdivR >> 5) & 0x7);
-               vcoR = (bfin_read_CGU_CTL() >> 8) & 0x7f;
+       sdivR = bfin_read_CGU_DIV();
+       sdivR = ((sdivR >> 8) & 0x1f) * ((sdivR >> 5) & 0x7);
+       vcoR = (bfin_read_CGU_CTL() >> 8) & 0x7f;
 #else
-               sdivR = bfin_read_PLL_DIV() & 0xf;
-               vcoR = (bfin_read_PLL_CTL() >> 9) & 0x3f;
+       sdivR = bfin_read_PLL_DIV() & 0xf;
+       vcoR = (bfin_read_PLL_CTL() >> 9) & 0x3f;
 #endif
 
-               for (quotient = 0; dividend > 0; ++quotient)
-                       dividend -= divisor;
-               serial_early_put_div(quotient - ANOMALY_05000230);
-               serial_putc('c');
+       dividend = sdivB * divB * vcoR;
+       divisor = vcoB * sdivR;
+       quotient = early_division(dividend, divisor);
+       serial_early_put_div(quotient - ANOMALY_05000230);
        }
 
-       serial_putc('d');
+       serial_putc('c');
 }
 
 __attribute__((always_inline)) static inline void
@@ -912,7 +914,8 @@ check_hibernation(ADI_BOOT_DATA *bs, u16 vr_ctl, bool put_into_srfs)
                        continue;
 
                serial_putc('z');
-               uint32_t *hibernate_magic = bfin_read32(DPM0_RESTORE4);
+               uint32_t *hibernate_magic =
+                       (uint32_t *)bfin_read32(DPM0_RESTORE4);
                SSYNC(); /* make sure memory controller is done */
                if (hibernate_magic[0] == 0xDEADBEEF) {
                        serial_putc('c');
@@ -952,6 +955,7 @@ check_hibernation(ADI_BOOT_DATA *bs, u16 vr_ctl, bool put_into_srfs)
                uint32_t *hibernate_magic = 0;
 
                SSYNC();
+               /* cppcheck-suppress nullPointer */
                if (hibernate_magic[0] == 0xDEADBEEF) {
                        serial_putc('c');
                        bfin_write_EVT15(hibernate_magic[1]);