Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2015 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * Author: Chunhe Lan <Chunhe.Lan@freescale.com> |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
Tom Rini | abb9a04 | 2024-05-18 20:20:43 -0600 | [diff] [blame^] | 8 | #include <common.h> |
Simon Glass | 85d6531 | 2019-12-28 10:44:58 -0700 | [diff] [blame] | 9 | #include <clock_legacy.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 10 | #include <console.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 11 | #include <env_internal.h> |
Simon Glass | 284f71b | 2019-12-28 10:44:45 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 14 | #include <asm/spl.h> |
| 15 | #include <malloc.h> |
| 16 | #include <ns16550.h> |
| 17 | #include <nand.h> |
| 18 | #include <mmc.h> |
| 19 | #include <fsl_esdhc.h> |
| 20 | #include <i2c.h> |
| 21 | |
| 22 | #include "t4rdb.h" |
| 23 | |
| 24 | #define FSL_CORENET_CCSR_PORSR1_RCW_MASK 0xFF800000 |
| 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | phys_size_t get_effective_memsize(void) |
| 29 | { |
| 30 | return CONFIG_SYS_L3_SIZE; |
| 31 | } |
| 32 | |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 33 | void board_init_f(ulong bootflag) |
| 34 | { |
| 35 | u32 plat_ratio, sys_clk, ccb_clk; |
Tom Rini | d5c3bf2 | 2022-10-28 20:27:12 -0400 | [diff] [blame] | 36 | ccsr_gur_t *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR; |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 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 | /* compiler optimization barrier needed for GCC >= 3.4 */ |
| 45 | __asm__ __volatile__("" : : : "memory"); |
| 46 | |
| 47 | console_init_f(); |
| 48 | |
| 49 | /* initialize selected port with appropriate baud rate */ |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 50 | sys_clk = get_board_sys_clk(); |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 51 | plat_ratio = (in_be32(&gur->rcwsr[0]) >> 25) & 0x1f; |
| 52 | ccb_clk = sys_clk * plat_ratio / 2; |
| 53 | |
Tom Rini | df6a215 | 2022-11-16 13:10:28 -0500 | [diff] [blame] | 54 | ns16550_init((struct ns16550 *)CFG_SYS_NS16550_COM1, |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 55 | ccb_clk / 16 / CONFIG_BAUDRATE); |
| 56 | |
| 57 | puts("\nSD boot...\n"); |
| 58 | |
| 59 | relocate_code(CONFIG_SPL_RELOC_STACK, (gd_t *)CONFIG_SPL_GD_ADDR, 0x0); |
| 60 | } |
| 61 | |
| 62 | void board_init_r(gd_t *gd, ulong dest_addr) |
| 63 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 64 | struct bd_info *bd; |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 65 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 66 | bd = (struct bd_info *)(gd + sizeof(gd_t)); |
| 67 | memset(bd, 0, sizeof(struct bd_info)); |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 68 | gd->bd = bd; |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 69 | |
Simon Glass | 302445a | 2017-01-23 13:31:22 -0700 | [diff] [blame] | 70 | arch_cpu_init(); |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 71 | get_clocks(); |
| 72 | mem_malloc_init(CONFIG_SPL_RELOC_MALLOC_ADDR, |
| 73 | CONFIG_SPL_RELOC_MALLOC_SIZE); |
Sumit Garg | 2ff056b | 2016-05-25 12:41:48 -0400 | [diff] [blame] | 74 | gd->flags |= GD_FLG_FULL_MALLOC_INIT; |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 75 | |
| 76 | mmc_initialize(bd); |
| 77 | mmc_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE, |
Tom Rini | 5cd7ece | 2019-11-18 20:02:10 -0500 | [diff] [blame] | 78 | (uchar *)SPL_ENV_ADDR); |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 79 | |
Tom Rini | 5cd7ece | 2019-11-18 20:02:10 -0500 | [diff] [blame] | 80 | gd->env_addr = (ulong)(SPL_ENV_ADDR); |
Simon Glass | 4bc2ad2 | 2017-08-03 12:21:56 -0600 | [diff] [blame] | 81 | gd->env_valid = ENV_VALID; |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 82 | |
| 83 | i2c_init_all(); |
| 84 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 85 | dram_init(); |
Chunhe Lan | 66cba6b | 2015-03-20 17:08:54 +0800 | [diff] [blame] | 86 | |
| 87 | mmc_boot(); |
| 88 | } |