Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 2 | /* Copyright 2013 Freescale Semiconductor, Inc. |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 3 | */ |
| 4 | |
| 5 | #include <common.h> |
Simon Glass | d96c260 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 6 | #include <clock_legacy.h> |
Simon Glass | 24b852a | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 7 | #include <console.h> |
Simon Glass | 4bfd1f5 | 2019-08-01 09:46:43 -0600 | [diff] [blame] | 8 | #include <env.h> |
Simon Glass | f3998fd | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 9 | #include <env_internal.h> |
Simon Glass | 9413387 | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 10 | #include <init.h> |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 11 | #include <ns16550.h> |
| 12 | #include <malloc.h> |
| 13 | #include <mmc.h> |
| 14 | #include <nand.h> |
| 15 | #include <i2c.h> |
| 16 | #include <fsl_esdhc.h> |
| 17 | #include <spi_flash.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Simon Glass | ea022a3 | 2016-09-24 18:20:10 -0600 | [diff] [blame] | 19 | #include "../common/spl.h" |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 20 | |
| 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Tom Rini | a7e8c15 | 2014-02-25 12:44:13 -0500 | [diff] [blame] | 23 | phys_size_t get_effective_memsize(void) |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 24 | { |
| 25 | return CONFIG_SYS_L2_SIZE; |
| 26 | } |
| 27 | |
| 28 | void board_init_f(ulong bootflag) |
| 29 | { |
| 30 | u32 plat_ratio; |
Tom Rini | 5155207 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 31 | ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR; |
Tom Rini | 65cc0e2 | 2022-11-16 13:10:41 -0500 | [diff] [blame] | 32 | struct fsl_ifc ifc = {(void *)CFG_SYS_IFC_ADDR, (void *)NULL}; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 33 | |
| 34 | console_init_f(); |
| 35 | |
| 36 | /* Clock configuration to access CPLD using IFC(GPCM) */ |
Jaiprakash Singh | 39b0bbb | 2015-03-20 19:28:27 -0700 | [diff] [blame] | 37 | setbits_be32(&ifc.gregs->ifc_gcr, 1 << IFC_GCR_TBCTL_TRN_TIME_SHIFT); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 38 | |
York Sun | 7601686 | 2016-11-16 13:30:06 -0800 | [diff] [blame] | 39 | #ifdef CONFIG_TARGET_P1010RDB_PB |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 40 | setbits_be32(&gur->pmuxcr2, MPC85xx_PMUXCR2_GPIO01_DRVVBUS); |
| 41 | #endif |
| 42 | |
| 43 | /* initialize selected port with appropriate baud rate */ |
| 44 | plat_ratio = in_be32(&gur->porpllsr) & MPC85xx_PORPLLSR_PLAT_RATIO; |
| 45 | plat_ratio >>= 1; |
Tom Rini | 2f8a6db | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 46 | gd->bus_clk = get_board_sys_clk() * plat_ratio; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 47 | |
Tom Rini | 9109213 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 48 | ns16550_init((struct ns16550 *)CFG_SYS_NS16550_COM1, |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 49 | gd->bus_clk / 16 / CONFIG_BAUDRATE); |
| 50 | |
| 51 | #ifdef CONFIG_SPL_MMC_BOOT |
| 52 | puts("\nSD boot...\n"); |
| 53 | #elif defined(CONFIG_SPL_SPI_BOOT) |
| 54 | puts("\nSPI Flash boot...\n"); |
| 55 | #endif |
| 56 | /* copy code to RAM and jump to it - this should not return */ |
| 57 | /* NOTE - code has to be copied out of NAND buffer before |
| 58 | * other blocks can be read. |
| 59 | */ |
Tom Rini | 55cf860 | 2022-05-26 16:59:30 -0400 | [diff] [blame] | 60 | relocate_code(CONFIG_VAL(RELOC_STACK), 0, CONFIG_SPL_RELOC_TEXT_BASE); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 64 | { |
| 65 | /* Pointer is writable since we allocated a register for it */ |
Tom Rini | 7f2c91e | 2022-05-27 16:19:05 -0400 | [diff] [blame] | 66 | gd = (gd_t *)CONFIG_VAL(GD_ADDR); |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 67 | struct bd_info *bd; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 68 | |
| 69 | memset(gd, 0, sizeof(gd_t)); |
Tom Rini | 7f2c91e | 2022-05-27 16:19:05 -0400 | [diff] [blame] | 70 | bd = (struct bd_info *)(CONFIG_VAL(GD_ADDR) + sizeof(gd_t)); |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 71 | memset(bd, 0, sizeof(struct bd_info)); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 72 | gd->bd = bd; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 73 | |
Simon Glass | cbcbf71 | 2017-01-23 13:31:22 -0700 | [diff] [blame] | 74 | arch_cpu_init(); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 75 | get_clocks(); |
Tom Rini | 55cf860 | 2022-05-26 16:59:30 -0400 | [diff] [blame] | 76 | mem_malloc_init(CONFIG_VAL(RELOC_MALLOC_ADDR), |
| 77 | CONFIG_VAL(RELOC_MALLOC_SIZE)); |
Sumit Garg | ed4708a | 2016-05-25 12:41:48 -0400 | [diff] [blame] | 78 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 79 | |
| 80 | #ifndef CONFIG_SPL_NAND_BOOT |
| 81 | env_init(); |
| 82 | #endif |
| 83 | #ifdef CONFIG_SPL_MMC_BOOT |
| 84 | mmc_initialize(bd); |
| 85 | #endif |
| 86 | |
| 87 | /* relocate environment function pointers etc. */ |
| 88 | #ifdef CONFIG_SPL_NAND_BOOT |
| 89 | nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
Tom Rini | a09fea1 | 2019-11-18 20:02:10 -0500 | [diff] [blame] | 90 | (uchar *)SPL_ENV_ADDR); |
| 91 | gd->env_addr = (ulong)(SPL_ENV_ADDR); |
Simon Glass | 203e94f | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 92 | gd->env_valid = ENV_VALID; |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 93 | #else |
| 94 | env_relocate(); |
| 95 | #endif |
| 96 | |
| 97 | i2c_init_all(); |
| 98 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 99 | dram_init(); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 100 | #ifdef CONFIG_SPL_NAND_BOOT |
| 101 | puts("\nTertiary program loader running in sram..."); |
| 102 | #else |
| 103 | puts("\nSecond program loader running in sram..."); |
| 104 | #endif |
| 105 | |
| 106 | #ifdef CONFIG_SPL_MMC_BOOT |
| 107 | mmc_boot(); |
| 108 | #elif defined(CONFIG_SPL_SPI_BOOT) |
Simon Glass | ea022a3 | 2016-09-24 18:20:10 -0600 | [diff] [blame] | 109 | fsl_spi_boot(); |
Ying Zhang | c9e1f58 | 2014-01-24 15:50:09 +0800 | [diff] [blame] | 110 | #elif defined(CONFIG_SPL_NAND_BOOT) |
| 111 | nand_boot(); |
| 112 | #endif |
| 113 | } |