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