Shengzhou Liu | 4d66668 | 2014-04-18 16:43:40 +0800 | [diff] [blame] | 1 | /* Copyright 2013 Freescale Semiconductor, Inc. |
| 2 | * |
| 3 | * SPDX-License-Identifier: GPL-2.0+ |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 7 | #include <console.h> |
Shengzhou Liu | 4d66668 | 2014-04-18 16:43:40 +0800 | [diff] [blame] | 8 | #include <malloc.h> |
| 9 | #include <ns16550.h> |
| 10 | #include <nand.h> |
| 11 | #include <i2c.h> |
| 12 | #include <mmc.h> |
| 13 | #include <fsl_esdhc.h> |
| 14 | #include <spi_flash.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | phys_size_t get_effective_memsize(void) |
| 19 | { |
| 20 | return CONFIG_SYS_L3_SIZE; |
| 21 | } |
| 22 | |
| 23 | unsigned long get_board_sys_clk(void) |
| 24 | { |
| 25 | return CONFIG_SYS_CLK_FREQ; |
| 26 | } |
| 27 | |
| 28 | unsigned long get_board_ddr_clk(void) |
| 29 | { |
| 30 | return CONFIG_DDR_CLK_FREQ; |
| 31 | } |
| 32 | |
| 33 | void board_init_f(ulong bootflag) |
| 34 | { |
| 35 | u32 plat_ratio, sys_clk, ccb_clk; |
| 36 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 37 | |
| 38 | /* Memcpy existing GD at CONFIG_SPL_GD_ADDR */ |
| 39 | memcpy((void *)CONFIG_SPL_GD_ADDR, (void *)gd, sizeof(gd_t)); |
| 40 | |
| 41 | /* Update GD pointer */ |
| 42 | gd = (gd_t *)(CONFIG_SPL_GD_ADDR); |
| 43 | |
| 44 | console_init_f(); |
| 45 | |
| 46 | /* initialize selected port with appropriate baud rate */ |
| 47 | sys_clk = get_board_sys_clk(); |
| 48 | plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; |
| 49 | ccb_clk = sys_clk * plat_ratio / 2; |
| 50 | |
| 51 | NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, |
| 52 | ccb_clk / 16 / CONFIG_BAUDRATE); |
| 53 | |
| 54 | #if defined(CONFIG_SPL_MMC_BOOT) |
| 55 | puts("\nSD boot...\n"); |
| 56 | #elif defined(CONFIG_SPL_SPI_BOOT) |
| 57 | puts("\nSPI boot...\n"); |
| 58 | #elif defined(CONFIG_SPL_NAND_BOOT) |
| 59 | puts("\nNAND boot...\n"); |
| 60 | #endif |
| 61 | |
| 62 | relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0); |
| 63 | } |
| 64 | |
| 65 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 66 | { |
| 67 | bd_t *bd; |
| 68 | |
| 69 | bd = (bd_t *)(gd + sizeof(gd_t)); |
| 70 | memset(bd, 0, sizeof(bd_t)); |
| 71 | gd->bd = bd; |
| 72 | bd->bi_memstart = CONFIG_SYS_INIT_L3_ADDR; |
| 73 | bd->bi_memsize = CONFIG_SYS_L3_SIZE; |
| 74 | |
| 75 | probecpu(); |
| 76 | get_clocks(); |
| 77 | mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR, |
| 78 | CONFIG_SPL_RELOC_MALLOC_SIZE); |
Sumit Garg | ed4708a | 2016-05-25 12:41:48 -0400 | [diff] [blame] | 79 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
Shengzhou Liu | 4d66668 | 2014-04-18 16:43:40 +0800 | [diff] [blame] | 80 | |
| 81 | #ifdef CONFIG_SPL_NAND_BOOT |
| 82 | nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 83 | (uchar *)CONFIG_ENV_ADDR); |
| 84 | #endif |
| 85 | #ifdef CONFIG_SPL_MMC_BOOT |
| 86 | mmc_initialize(bd); |
| 87 | mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 88 | (uchar *)CONFIG_ENV_ADDR); |
| 89 | #endif |
| 90 | #ifdef CONFIG_SPL_SPI_BOOT |
| 91 | spi_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
| 92 | (uchar *)CONFIG_ENV_ADDR); |
| 93 | #endif |
| 94 | |
| 95 | gd->env_addr = (ulong)(CONFIG_ENV_ADDR); |
| 96 | gd->env_valid = 1; |
| 97 | |
| 98 | i2c_init_all(); |
| 99 | |
| 100 | gd->ram_size = initdram(0); |
| 101 | |
| 102 | #ifdef CONFIG_SPL_MMC_BOOT |
| 103 | mmc_boot(); |
| 104 | #elif defined(CONFIG_SPL_SPI_BOOT) |
| 105 | spi_boot(); |
| 106 | #elif defined(CONFIG_SPL_NAND_BOOT) |
| 107 | nand_boot(); |
| 108 | #endif |
| 109 | } |