diff options
Diffstat (limited to 'lib_blackfin')
| -rw-r--r-- | lib_blackfin/Makefile | 6 | ||||
| -rw-r--r-- | lib_blackfin/board.c | 111 | ||||
| -rw-r--r-- | lib_blackfin/boot.c (renamed from lib_blackfin/bootm.c) | 19 | ||||
| -rw-r--r-- | lib_blackfin/cache.c | 18 | ||||
| -rw-r--r-- | lib_blackfin/clocks.c | 77 | ||||
| -rw-r--r-- | lib_blackfin/post.c | 4 | ||||
| -rw-r--r-- | lib_blackfin/string.c | 71 | ||||
| -rw-r--r-- | lib_blackfin/tests.c | 3 |
8 files changed, 200 insertions, 109 deletions
diff --git a/lib_blackfin/Makefile b/lib_blackfin/Makefile index 3f69770d6..46ef7f331 100644 --- a/lib_blackfin/Makefile +++ b/lib_blackfin/Makefile @@ -37,12 +37,12 @@ SOBJS-y += memmove.o SOBJS-y += memset.o COBJS-y += board.o -COBJS-y += bootm.o +COBJS-y += boot.o COBJS-y += cache.o +COBJS-y += clocks.o COBJS-y += muldi3.o -COBJS-y += post.o +COBJS-$(CONFIG_POST) += post.o tests.o COBJS-y += string.o -COBJS-y += tests.o SRCS := $(SOBJS-y:.o=.S) $(COBJS-y:.o=.c) OBJS := $(addprefix $(obj),$(SOBJS-y) $(COBJS-y)) diff --git a/lib_blackfin/board.c b/lib_blackfin/board.c index fde4bbe0f..c22371197 100644 --- a/lib_blackfin/board.c +++ b/lib_blackfin/board.c @@ -13,10 +13,10 @@ #include <command.h> #include <devices.h> #include <environment.h> -#include <i2c.h> #include <malloc.h> #include <net.h> #include <timestamp.h> +#include <status_led.h> #include <version.h> #include <asm/cplb.h> @@ -44,50 +44,6 @@ static inline void serial_early_puts(const char *s) #endif } -/* Get the input voltage */ -static u_long get_vco(void) -{ - u_long msel; - u_long vco; - - msel = (*pPLL_CTL >> 9) & 0x3F; - if (0 == msel) - msel = 64; - - vco = CONFIG_CLKIN_HZ; - vco >>= (1 & *pPLL_CTL); /* DF bit */ - vco = msel * vco; - return vco; -} - -/* Get the Core clock */ -u_long get_cclk(void) -{ - u_long csel, ssel; - if (*pPLL_STAT & 0x1) - return CONFIG_CLKIN_HZ; - - ssel = *pPLL_DIV; - csel = ((ssel >> 4) & 0x03); - ssel &= 0xf; - if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */ - return get_vco() / ssel; - return get_vco() >> csel; -} - -/* Get the System clock */ -u_long get_sclk(void) -{ - u_long ssel; - - if (*pPLL_STAT & 0x1) - return CONFIG_CLKIN_HZ; - - ssel = (*pPLL_DIV & 0xf); - - return get_vco() / ssel; -} - static void *mem_malloc_start, *mem_malloc_end, *mem_malloc_brk; static void mem_malloc_init(void) @@ -114,7 +70,11 @@ void *sbrk(ptrdiff_t increment) static int display_banner(void) { printf("\n\n%s\n\n", version_string); - printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " (Detected Rev: 0.%d)\n", bfin_revid()); + printf("CPU: ADSP " MK_STR(CONFIG_BFIN_CPU) " " + "(Detected Rev: 0.%d) " + "(%s boot)\n", + bfin_revid(), + get_bfin_boot_mode(CONFIG_BFIN_BOOT_MODE)); return 0; } @@ -257,6 +217,7 @@ void board_init_f(ulong bootflag) { ulong addr; bd_t *bd; + char buf[32]; #ifdef CONFIG_BOARD_EARLY_INIT_F serial_early_puts("Board early init flash\n"); @@ -278,9 +239,13 @@ void board_init_f(ulong bootflag) dcache_enable(); #endif +#ifdef DEBUG + if (CONFIG_SYS_GBL_DATA_SIZE < sizeof(*gd)) + hang(); +#endif serial_early_puts("Init global data\n"); gd = (gd_t *) (CONFIG_SYS_GBL_DATA_ADDR); - memset((void *)gd, 0, sizeof(gd_t)); + memset((void *)gd, 0, CONFIG_SYS_GBL_DATA_SIZE); /* Board data initialization */ addr = (CONFIG_SYS_GBL_DATA_ADDR + sizeof(gd_t)); @@ -315,8 +280,9 @@ void board_init_f(ulong bootflag) checkboard(); timer_init(); - printf("Clock: VCO: %lu MHz, Core: %lu MHz, System: %lu MHz\n", - get_vco() / 1000000, get_cclk() / 1000000, get_sclk() / 1000000); + printf("Clock: VCO: %s MHz, ", strmhz(buf, get_vco())); + printf("Core: %s MHz, ", strmhz(buf, get_cclk())); + printf("System: %s MHz\n", strmhz(buf, get_sclk())); printf("RAM: "); print_size(initdram(0), "\n"); @@ -329,16 +295,6 @@ void board_init_f(ulong bootflag) board_init_r((gd_t *) gd, 0x20000010); } -#if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) -static int init_func_i2c(void) -{ - puts("I2C: "); - i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); - puts("ready\n"); - return (0); -} -#endif - void board_init_r(gd_t * id, ulong dest_addr) { extern void malloc_bin_reloc(void); @@ -354,14 +310,14 @@ void board_init_r(gd_t * id, ulong dest_addr) #endif #if !defined(CONFIG_SYS_NO_FLASH) - /* There are some other pointer constants we must deal with */ - /* configure available FLASH banks */ + /* Initialize the flash and protect u-boot by default */ extern flash_info_t flash_info[]; ulong size = flash_init(); puts("Flash: "); print_size(size, "\n"); flash_protect(FLAG_PROTECT_SET, CONFIG_SYS_FLASH_BASE, - CONFIG_SYS_FLASH_BASE + 0x1ffff, &flash_info[0]); + CONFIG_SYS_FLASH_BASE + CONFIG_SYS_MONITOR_LEN - 1, + &flash_info[0]); bd->bi_flashstart = CONFIG_SYS_FLASH_BASE; bd->bi_flashsize = size; bd->bi_flashoffset = 0; @@ -374,13 +330,6 @@ void board_init_r(gd_t * id, ulong dest_addr) mem_malloc_init(); malloc_bin_reloc(); -#ifdef CONFIG_SPI -# if ! defined(CONFIG_ENV_IS_IN_EEPROM) - spi_init_f(); -# endif - spi_init_r(); -#endif - #ifdef CONFIG_CMD_NAND puts("NAND: "); nand_init(); /* go init the NAND */ @@ -425,6 +374,11 @@ void board_init_r(gd_t * id, ulong dest_addr) /* Initialize the console (after the relocation and devices init) */ console_init_r(); +#ifdef CONFIG_STATUS_LED + status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING); + status_led_set(STATUS_LED_CRASH, STATUS_LED_OFF); +#endif + /* Initialize from environment */ if ((s = getenv("loadaddr")) != NULL) load_addr = simple_strtoul(s, NULL, 16); @@ -441,14 +395,19 @@ void board_init_r(gd_t * id, ulong dest_addr) #ifdef CONFIG_CMD_NET printf("Net: "); eth_initialize(gd->bd); - if (getenv("ethaddr")) + if ((s = getenv("ethaddr"))) { +# ifndef CONFIG_NET_MULTI + size_t i; + char *e; + for (i = 0; i < 6; ++i) { + bd->bi_enetaddr[i] = simple_strtoul(s, &e, 16); + s = (*e) ? e + 1 : e; + } +# endif printf("MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", bd->bi_enetaddr[0], bd->bi_enetaddr[1], bd->bi_enetaddr[2], bd->bi_enetaddr[3], bd->bi_enetaddr[4], bd->bi_enetaddr[5]); -#endif - -#if defined(CONFIG_SOFT_I2C) || defined(CONFIG_HARD_I2C) - init_func_i2c(); + } #endif display_global_data(); @@ -465,6 +424,10 @@ void board_init_r(gd_t * id, ulong dest_addr) void hang(void) { +#ifdef CONFIG_STATUS_LED + status_led_set(STATUS_LED_BOOT, STATUS_LED_OFF); + status_led_set(STATUS_LED_CRASH, STATUS_LED_BLINKING); +#endif puts("### ERROR ### Please RESET the board ###\n"); while (1) /* If a JTAG emulator is hooked up, we'll automatically trigger diff --git a/lib_blackfin/bootm.c b/lib_blackfin/boot.c index 195eb9c00..951d5b0d0 100644 --- a/lib_blackfin/bootm.c +++ b/lib_blackfin/boot.c @@ -1,5 +1,5 @@ /* - * U-boot - bootm.c - misc boot helper functions + * U-boot - boot.c - misc boot helper functions * * Copyright (c) 2005-2008 Analog Devices Inc. * @@ -20,17 +20,19 @@ extern void swap_to(int device_id); static char *make_command_line(void) { - char *dest = (char *)CMD_LINE_ADDR; + char *dest = (char *)CONFIG_LINUX_CMDLINE_ADDR; char *bootargs = getenv("bootargs"); if (bootargs == NULL) return NULL; - strncpy(dest, bootargs, 0x1000); - dest[0xfff] = 0; + strncpy(dest, bootargs, CONFIG_LINUX_CMDLINE_SIZE); + dest[CONFIG_LINUX_CMDLINE_SIZE - 1] = 0; return dest; } +extern ulong bfin_poweron_retx; + int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) { int (*appl) (char *cmdline); @@ -45,11 +47,16 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) appl = (int (*)(char *))images->ep; - printf("Starting Kernel at = %x\n", appl); + printf("Starting Kernel at = %p\n", appl); cmdline = make_command_line(); icache_disable(); dcache_disable(); - (*appl) (cmdline); + asm __volatile__( + "RETX = %[retx];" + "CALL (%0);" + : + : "p"(appl), "q0"(cmdline), [retx] "d"(bfin_poweron_retx) + ); /* does not return */ return 1; diff --git a/lib_blackfin/cache.c b/lib_blackfin/cache.c index 870c5bfba..1557864f9 100644 --- a/lib_blackfin/cache.c +++ b/lib_blackfin/cache.c @@ -15,15 +15,25 @@ void flush_cache(unsigned long addr, unsigned long size) { + void *start_addr, *end_addr; + int istatus, dstatus; + /* no need to flush stuff in on chip memory (L1/L2/etc...) */ if (addr >= 0xE0000000) return; - if (icache_status()) - blackfin_icache_flush_range((void *)addr, (void *)(addr + size)); + start_addr = (void *)addr; + end_addr = (void *)(addr + size); + istatus = icache_status(); + dstatus = dcache_status(); - if (dcache_status()) - blackfin_dcache_flush_range((void *)addr, (void *)(addr + size)); + if (istatus) { + if (dstatus) + blackfin_icache_dcache_flush_range(start_addr, end_addr); + else + blackfin_icache_flush_range(start_addr, end_addr); + } else if (dstatus) + blackfin_dcache_flush_range(start_addr, end_addr); } void icache_enable(void) diff --git a/lib_blackfin/clocks.c b/lib_blackfin/clocks.c new file mode 100644 index 000000000..0be395bb3 --- /dev/null +++ b/lib_blackfin/clocks.c @@ -0,0 +1,77 @@ +/* + * clocks.c - figure out sclk/cclk/vco and such + * + * Copyright (c) 2005-2008 Analog Devices Inc. + * + * Licensed under the GPL-2 or later. + */ + +#include <common.h> +#include <asm/blackfin.h> + +/* Get the voltage input multiplier */ +static u_long cached_vco_pll_ctl, cached_vco; +u_long get_vco(void) +{ + u_long msel; + + u_long pll_ctl = bfin_read_PLL_CTL(); + if (pll_ctl == cached_vco_pll_ctl) + return cached_vco; + else + cached_vco_pll_ctl = pll_ctl; + + msel = (pll_ctl >> 9) & 0x3F; + if (0 == msel) + msel = 64; + + cached_vco = CONFIG_CLKIN_HZ; + cached_vco >>= (1 & pll_ctl); /* DF bit */ + cached_vco *= msel; + return cached_vco; +} + +/* Get the Core clock */ +static u_long cached_cclk_pll_div, cached_cclk; +u_long get_cclk(void) +{ + u_long csel, ssel; + + if (bfin_read_PLL_STAT() & 0x1) + return CONFIG_CLKIN_HZ; + + ssel = bfin_read_PLL_DIV(); + if (ssel == cached_cclk_pll_div) + return cached_cclk; + else + cached_cclk_pll_div = ssel; + + csel = ((ssel >> 4) & 0x03); + ssel &= 0xf; + if (ssel && ssel < (1 << csel)) /* SCLK > CCLK */ + cached_cclk = get_vco() / ssel; + else + cached_cclk = get_vco() >> csel; + return cached_cclk; +} + +/* Get the System clock */ +static u_long cached_sclk_pll_div, cached_sclk; +u_long get_sclk(void) +{ + u_long ssel; + + if (bfin_read_PLL_STAT() & 0x1) + return CONFIG_CLKIN_HZ; + + ssel = bfin_read_PLL_DIV(); + if (ssel == cached_sclk_pll_div) + return cached_sclk; + else + cached_sclk_pll_div = ssel; + + ssel &= 0xf; + + cached_sclk = get_vco() / ssel; + return cached_sclk; +} diff --git a/lib_blackfin/post.c b/lib_blackfin/post.c index 4ab9e8bf0..35ccd3cd7 100644 --- a/lib_blackfin/post.c +++ b/lib_blackfin/post.c @@ -30,8 +30,6 @@ #include <logbuff.h> #endif -#ifdef CONFIG_POST - DECLARE_GLOBAL_DATA_PTR; #define POST_MAX_NUMBER 32 @@ -421,5 +419,3 @@ unsigned long post_time_ms(unsigned long base) { return (unsigned long)get_ticks() / (get_tbclk() / CONFIG_SYS_HZ) - base; } - -#endif /* CONFIG_POST */ diff --git a/lib_blackfin/string.c b/lib_blackfin/string.c index 6887c93de..12b6d2405 100644 --- a/lib_blackfin/string.c +++ b/lib_blackfin/string.c @@ -1,7 +1,7 @@ /* * U-boot - string.c Contains library routines. * - * Copyright (c) 2005-2007 Analog Devices Inc. + * Copyright (c) 2005-2008 Analog Devices Inc. * * (C) Copyright 2000-2004 * Wolfgang Denk, DENX Software Engineering, wd@denx.de. @@ -130,12 +130,41 @@ int strncmp(const char *cs, const char *ct, size_t count) # define bfin_write_MDMA_D0_IRQ_STATUS bfin_write_MDMA1_D0_IRQ_STATUS # define bfin_read_MDMA_D0_IRQ_STATUS bfin_read_MDMA1_D0_IRQ_STATUS #endif -static void *dma_memcpy(void *dst, const void *src, size_t count) +/* This version misbehaves for count values of 0 and 2^16+. + * Perhaps we should detect that ? Nowhere do we actually + * use dma memcpy for those types of lengths though ... + */ +void dma_memcpy_nocache(void *dst, const void *src, size_t count) { - if (dcache_status()) - blackfin_dcache_flush_range(src, src + count); + uint16_t wdsize, mod; + + /* Disable DMA in case it's still running (older u-boot's did not + * always turn them off). Do it before the if statement below so + * we can be cheap and not do a SSYNC() due to the forced abort. + */ + bfin_write_MDMA_D0_CONFIG(0); + bfin_write_MDMA_S0_CONFIG(0); + bfin_write_MDMA_D0_IRQ_STATUS(DMA_RUN | DMA_DONE | DMA_ERR); - bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR); + /* Scratchpad cannot be a DMA source or destination */ + if (((unsigned long)src >= L1_SRAM_SCRATCH && + (unsigned long)src < L1_SRAM_SCRATCH_END) || + ((unsigned long)dst >= L1_SRAM_SCRATCH && + (unsigned long)dst < L1_SRAM_SCRATCH_END)) + hang(); + + if (((unsigned long)dst | (unsigned long)src | count) & 0x1) { + wdsize = WDSIZE_8; + mod = 1; + } else if (((unsigned long)dst | (unsigned long)src | count) & 0x2) { + wdsize = WDSIZE_16; + count >>= 1; + mod = 2; + } else { + wdsize = WDSIZE_32; + count >>= 2; + mod = 4; + } /* Copy sram functions from sdram to sram */ /* Setup destination start address */ @@ -143,31 +172,43 @@ static void *dma_memcpy(void *dst, const void *src, size_t count) /* Setup destination xcount */ bfin_write_MDMA_D0_X_COUNT(count); /* Setup destination xmodify */ - bfin_write_MDMA_D0_X_MODIFY(1); + bfin_write_MDMA_D0_X_MODIFY(mod); /* Setup Source start address */ bfin_write_MDMA_S0_START_ADDR(src); /* Setup Source xcount */ bfin_write_MDMA_S0_X_COUNT(count); /* Setup Source xmodify */ - bfin_write_MDMA_S0_X_MODIFY(1); + bfin_write_MDMA_S0_X_MODIFY(mod); /* Enable source DMA */ - bfin_write_MDMA_S0_CONFIG(DMAEN); + bfin_write_MDMA_S0_CONFIG(wdsize | DMAEN); + bfin_write_MDMA_D0_CONFIG(wdsize | DMAEN | WNR | DI_EN); SSYNC(); - bfin_write_MDMA_D0_CONFIG(WNR | DMAEN); + while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE)) + continue; + + bfin_write_MDMA_D0_IRQ_STATUS(DMA_RUN | DMA_DONE | DMA_ERR); + bfin_write_MDMA_D0_CONFIG(0); + bfin_write_MDMA_S0_CONFIG(0); +} +/* We should do a dcache invalidate on the destination after the dma, but since + * we lack such hardware capability, we'll flush/invalidate the destination + * before the dma and bank on the idea that u-boot is single threaded. + */ +void *dma_memcpy(void *dst, const void *src, size_t count) +{ + if (dcache_status()) { + blackfin_dcache_flush_range(src, src + count); + blackfin_dcache_flush_invalidate_range(dst, dst + count); + } - while (bfin_read_MDMA_D0_IRQ_STATUS() & DMA_RUN) - bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR); - bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() | DMA_DONE | DMA_ERR); + dma_memcpy_nocache(dst, src, count); if (icache_status()) blackfin_icache_flush_range(dst, dst + count); - if (dcache_status()) - blackfin_dcache_invalidate_range(dst, dst + count); - return dst; } diff --git a/lib_blackfin/tests.c b/lib_blackfin/tests.c index c2319ecb7..bf7fba00c 100644 --- a/lib_blackfin/tests.c +++ b/lib_blackfin/tests.c @@ -27,7 +27,6 @@ #include <common.h> #include <config.h> -#ifdef CONFIG_POST #include <post.h> #define CONFIG_SYS_POST_FLASH 0x00004000 @@ -249,5 +248,3 @@ struct post_test post_list[] = { }; unsigned int post_list_size = sizeof(post_list) / sizeof(struct post_test); - -#endif /* CONFIG_POST */ |