Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 2 | /* Copyright 2013 Freescale Semiconductor, Inc. |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <common.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 6 | #include <console.h> |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 7 | #include <env_internal.h> |
Simon Glass | 9413387 | 2019-12-28 10:44:45 -0700 | [diff] [blame^] | 8 | #include <init.h> |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 9 | #include <ns16550.h> |
| 10 | #include <malloc.h> |
| 11 | #include <mmc.h> |
| 12 | #include <nand.h> |
| 13 | #include <i2c.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
York Sun | e386616 | 2014-02-11 11:57:26 -0800 | [diff] [blame] | 17 | phys_size_t get_effective_memsize(void) |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 18 | { |
| 19 | return CONFIG_SYS_L2_SIZE; |
| 20 | } |
| 21 | |
| 22 | void board_init_f(ulong bootflag) |
| 23 | { |
| 24 | u32 plat_ratio; |
| 25 | ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 26 | |
| 27 | console_init_f(); |
| 28 | |
| 29 | /* initialize selected port with appropriate baud rate */ |
| 30 | plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO; |
| 31 | plat_ratio >>= 1; |
| 32 | gd->bus_clk = CONFIG_SYS_CLK_FREQ * plat_ratio; |
| 33 | |
| 34 | NS16550_init((NS16550_t)CONFIG_SYS_NS16550_COM1, |
| 35 | gd->bus_clk / 16 / CONFIG_BAUDRATE); |
| 36 | |
| 37 | /* copy code to RAM and jump to it - this should not return */ |
| 38 | /* NOTE - code has to be copied out of NAND buffer before |
| 39 | * other blocks can be read. |
| 40 | */ |
| 41 | relocate_code(CONFIG_SPL_RELOC_STACK, 0, CONFIG_SPL_RELOC_TEXT_BASE); |
| 42 | } |
| 43 | |
| 44 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 45 | { |
| 46 | /* Pointer is writable since we allocated a register for it */ |
| 47 | gd = (gd_t *)CONFIG_SPL_GD_ADDR; |
| 48 | bd_t *bd; |
| 49 | |
| 50 | memset(gd, 0, sizeof(gd_t)); |
| 51 | bd = (bd_t *)(CONFIG_SPL_GD_ADDR + sizeof(gd_t)); |
| 52 | memset(bd, 0, sizeof(bd_t)); |
| 53 | gd->bd = bd; |
| 54 | bd->bi_memstart = CONFIG_SYS_INIT_L2_ADDR; |
| 55 | bd->bi_memsize = CONFIG_SYS_L2_SIZE; |
| 56 | |
Simon Glass | cbcbf71 | 2017-01-23 13:31:22 -0700 | [diff] [blame] | 57 | arch_cpu_init(); |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 58 | get_clocks(); |
| 59 | mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR, |
| 60 | CONFIG_SPL_RELOC_MALLOC_SIZE); |
Sumit Garg | ed4708a | 2016-05-25 12:41:48 -0400 | [diff] [blame] | 61 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 62 | |
| 63 | /* relocate environment function pointers etc. */ |
| 64 | nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
Tom Rini | a09fea1 | 2019-11-18 20:02:10 -0500 | [diff] [blame] | 65 | (uchar *)SPL_ENV_ADDR); |
| 66 | gd->env_addr = (ulong)(SPL_ENV_ADDR); |
Simon Glass | 203e94f | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 67 | gd->env_valid = ENV_VALID; |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 68 | |
| 69 | i2c_init_all(); |
| 70 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 71 | dram_init(); |
Po Liu | eb6b458 | 2014-01-10 10:10:59 +0800 | [diff] [blame] | 72 | |
| 73 | #ifdef CONFIG_SPL_NAND_BOOT |
| 74 | puts("TPL\n"); |
| 75 | #else |
| 76 | puts("SPL\n"); |
| 77 | #endif |
| 78 | |
| 79 | nand_boot(); |
| 80 | } |