Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 6 | #include <init.h> |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 7 | #include <malloc.h> |
| 8 | #include <errno.h> |
Simon Glass | 0c36441 | 2019-12-28 10:44:48 -0700 | [diff] [blame] | 9 | #include <net.h> |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 10 | #include <netdev.h> |
| 11 | #include <fsl_ifc.h> |
| 12 | #include <fsl_ddr.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <fdt_support.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 16 | #include <fsl-mc/fsl_mc.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 17 | #include <env_internal.h> |
Mingkai Hu | 0e58b51 | 2015-10-26 19:47:50 +0800 | [diff] [blame] | 18 | #include <asm/arch/soc.h> |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 19 | |
| 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
| 22 | int board_init(void) |
| 23 | { |
| 24 | init_final_memctl_regs(); |
Prabhakar Kushwaha | cf32918 | 2014-07-14 17:15:44 +0530 | [diff] [blame] | 25 | |
| 26 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 27 | gd->env_addr = (ulong)&default_environment[0]; |
| 28 | #endif |
| 29 | |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 30 | return 0; |
| 31 | } |
| 32 | |
| 33 | int board_early_init_f(void) |
| 34 | { |
Scott Wood | f64c98c | 2015-03-20 19:28:12 -0700 | [diff] [blame] | 35 | fsl_lsch3_early_init_f(); |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
York Sun | c7a0e30 | 2014-08-13 10:21:05 -0700 | [diff] [blame] | 39 | void detail_board_ddr_info(void) |
| 40 | { |
| 41 | puts("\nDDR "); |
| 42 | print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, ""); |
| 43 | print_ddr_info(0); |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 44 | #ifdef CONFIG_SYS_FSL_HAS_DP_DDR |
York Sun | cbe8e1c | 2016-04-04 11:41:26 -0700 | [diff] [blame] | 45 | if (soc_has_dp_ddr() && gd->bd->bi_dram[2].size) { |
York Sun | c7a0e30 | 2014-08-13 10:21:05 -0700 | [diff] [blame] | 46 | puts("\nDP-DDR "); |
| 47 | print_size(gd->bd->bi_dram[2].size, ""); |
| 48 | print_ddr_info(CONFIG_DP_DDR_CTRL); |
| 49 | } |
Prabhakar Kushwaha | 122bcfd | 2015-11-09 16:42:07 +0530 | [diff] [blame] | 50 | #endif |
York Sun | c7a0e30 | 2014-08-13 10:21:05 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 53 | int board_eth_init(struct bd_info *bis) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 54 | { |
| 55 | int error = 0; |
| 56 | |
| 57 | #ifdef CONFIG_SMC91111 |
| 58 | error = smc91111_initialize(0, CONFIG_SMC91111_BASE); |
| 59 | #endif |
| 60 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 61 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 62 | error = cpu_eth_init(bis); |
| 63 | #endif |
| 64 | return error; |
| 65 | } |
| 66 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 67 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 68 | void fdt_fixup_board_enet(void *fdt) |
| 69 | { |
| 70 | int offset; |
| 71 | |
Stuart Yoder | a346615 | 2016-03-02 16:37:13 -0600 | [diff] [blame] | 72 | offset = fdt_path_offset(fdt, "/soc/fsl-mc"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * TODO: Remove this when backward compatibility |
Stuart Yoder | a346615 | 2016-03-02 16:37:13 -0600 | [diff] [blame] | 76 | * with old DT node (/fsl-mc) is no longer needed. |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 77 | */ |
| 78 | if (offset < 0) |
Stuart Yoder | a346615 | 2016-03-02 16:37:13 -0600 | [diff] [blame] | 79 | offset = fdt_path_offset(fdt, "/fsl-mc"); |
J. German Rivera | 43e4ae3 | 2015-01-06 13:19:02 -0800 | [diff] [blame] | 80 | |
| 81 | if (offset < 0) { |
| 82 | printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n", |
| 83 | __func__, offset); |
| 84 | return; |
| 85 | } |
| 86 | |
Mian Yousaf Kaukab | 9712465 | 2018-12-18 14:01:17 +0100 | [diff] [blame] | 87 | if (get_mc_boot_status() == 0 && |
| 88 | (is_lazy_dpl_addr_valid() || get_dpl_apply_status() == 0)) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 89 | fdt_status_okay(fdt, offset); |
| 90 | else |
| 91 | fdt_status_fail(fdt, offset); |
| 92 | } |
Alexander Graf | 2ebeb44 | 2016-11-17 01:02:57 +0100 | [diff] [blame] | 93 | |
| 94 | void board_quiesce_devices(void) |
| 95 | { |
| 96 | fsl_mc_ldpaa_exit(gd->bd); |
| 97 | } |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 98 | #endif |
| 99 | |
| 100 | #ifdef CONFIG_OF_BOARD_SETUP |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 101 | int ft_board_setup(void *blob, struct bd_info *bd) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 102 | { |
Bhupesh Sharma | 0b10a1a | 2015-05-28 14:54:10 +0530 | [diff] [blame] | 103 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 104 | u64 size[CONFIG_NR_DRAM_BANKS]; |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 105 | |
York Sun | 290a83a | 2014-09-08 12:20:01 -0700 | [diff] [blame] | 106 | ft_cpu_setup(blob, bd); |
| 107 | |
Bhupesh Sharma | 0b10a1a | 2015-05-28 14:54:10 +0530 | [diff] [blame] | 108 | /* fixup DT for the two GPP DDR banks */ |
| 109 | base[0] = gd->bd->bi_dram[0].start; |
| 110 | size[0] = gd->bd->bi_dram[0].size; |
| 111 | base[1] = gd->bd->bi_dram[1].start; |
| 112 | size[1] = gd->bd->bi_dram[1].size; |
| 113 | |
York Sun | 4de24ef | 2017-03-06 09:02:28 -0800 | [diff] [blame] | 114 | #ifdef CONFIG_RESV_RAM |
| 115 | /* reduce size if reserved memory is within this bank */ |
| 116 | if (gd->arch.resv_ram >= base[0] && |
| 117 | gd->arch.resv_ram < base[0] + size[0]) |
| 118 | size[0] = gd->arch.resv_ram - base[0]; |
| 119 | else if (gd->arch.resv_ram >= base[1] && |
| 120 | gd->arch.resv_ram < base[1] + size[1]) |
| 121 | size[1] = gd->arch.resv_ram - base[1]; |
| 122 | #endif |
| 123 | |
Bhupesh Sharma | 0b10a1a | 2015-05-28 14:54:10 +0530 | [diff] [blame] | 124 | fdt_fixup_memory_banks(blob, base, size, 2); |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 125 | |
Nipun Gupta | d691264 | 2018-08-20 16:01:14 +0530 | [diff] [blame] | 126 | fdt_fsl_mc_fixup_iommu_map_entry(blob); |
| 127 | |
Santan Kumar | 1afa900 | 2017-05-05 15:42:29 +0530 | [diff] [blame] | 128 | #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD) |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 129 | fdt_fixup_board_enet(blob); |
| 130 | #endif |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 131 | |
| 132 | return 0; |
York Sun | 7b08d21 | 2014-06-23 15:15:56 -0700 | [diff] [blame] | 133 | } |
| 134 | #endif |
Bogdan Purcareata | 08bc014 | 2017-05-24 16:40:21 +0000 | [diff] [blame] | 135 | |
| 136 | #if defined(CONFIG_RESET_PHY_R) |
| 137 | void reset_phy(void) |
| 138 | { |
| 139 | } |
| 140 | #endif |
Rajesh Bhagat | d5691be | 2018-12-27 04:37:59 +0000 | [diff] [blame] | 141 | |
| 142 | #ifdef CONFIG_TFABOOT |
| 143 | void *env_sf_get_env_addr(void) |
| 144 | { |
| 145 | return (void *)(CONFIG_SYS_FSL_QSPI_BASE1 + CONFIG_ENV_OFFSET); |
| 146 | } |
| 147 | #endif |