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