Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 2 | /* |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 3 | * Copyright 2017-2018 NXP |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 7 | #include <fdt_support.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 8 | #include <i2c.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <asm/cache.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 11 | #include <asm/global_data.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/clock.h> |
| 14 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 15 | #ifdef CONFIG_FSL_LS_PPA |
| 16 | #include <asm/arch/ppa.h> |
| 17 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 18 | #include <asm/arch/mmu.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 19 | #include <asm/arch/soc.h> |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 20 | #include <fsl_esdhc.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 21 | #include <hwconfig.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 22 | #include <env_internal.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 23 | #include <fsl_mmdc.h> |
| 24 | #include <netdev.h> |
Vinitha V Pillai | ad698c3 | 2018-05-23 11:03:31 +0530 | [diff] [blame] | 25 | #include <fsl_sec.h> |
Mian Yousaf Kaukab | 2529deae | 2021-04-14 12:33:58 +0200 | [diff] [blame] | 26 | #include <net/pfe_eth/pfe/pfe_hw.h> |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 27 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 30 | static inline int get_board_version(void) |
| 31 | { |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 32 | uint32_t val; |
| 33 | #ifdef CONFIG_TARGET_LS1012AFRDM |
| 34 | val = 0; |
| 35 | #else |
| 36 | struct ccsr_gpio *pgpio = (void *)(GPIO2_BASE_ADDR); |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 37 | |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 38 | val = in_be32(&pgpio->gpdat) & BOARD_REV_MASK;/*Get GPIO2 11,12,14*/ |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 39 | |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 40 | #endif |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 41 | return val; |
| 42 | } |
| 43 | |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 44 | int checkboard(void) |
| 45 | { |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 46 | #ifdef CONFIG_TARGET_LS1012AFRDM |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 47 | puts("Board: LS1012AFRDM "); |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 48 | #else |
| 49 | int rev; |
| 50 | |
| 51 | rev = get_board_version(); |
| 52 | |
| 53 | puts("Board: FRWY-LS1012A "); |
| 54 | |
| 55 | puts("Version"); |
| 56 | |
| 57 | switch (rev) { |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 58 | case BOARD_REV_A_B: |
| 59 | puts(": RevA/B "); |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 60 | break; |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 61 | case BOARD_REV_C: |
| 62 | puts(": RevC "); |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 63 | break; |
| 64 | default: |
| 65 | puts(": unknown"); |
| 66 | break; |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | #ifdef CONFIG_TARGET_LS1012AFRWY |
| 74 | int esdhc_status_fixup(void *blob, const char *compat) |
| 75 | { |
| 76 | char esdhc0_path[] = "/soc/esdhc@1560000"; |
| 77 | char esdhc1_path[] = "/soc/esdhc@1580000"; |
| 78 | |
| 79 | do_fixup_by_path(blob, esdhc0_path, "status", "okay", |
| 80 | sizeof("okay"), 1); |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 81 | |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 82 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 83 | sizeof("disabled"), 1); |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 84 | return 0; |
| 85 | } |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 86 | #endif |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 87 | |
Rajesh Bhagat | 487084e | 2018-11-05 18:03:08 +0000 | [diff] [blame] | 88 | #ifdef CONFIG_TFABOOT |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 89 | int dram_init(void) |
| 90 | { |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 91 | #ifdef CONFIG_TARGET_LS1012AFRWY |
| 92 | int board_rev; |
| 93 | #endif |
Rajesh Bhagat | 487084e | 2018-11-05 18:03:08 +0000 | [diff] [blame] | 94 | |
| 95 | gd->ram_size = tfa_get_dram_size(); |
| 96 | |
| 97 | if (!gd->ram_size) { |
| 98 | #ifdef CONFIG_TARGET_LS1012AFRWY |
| 99 | board_rev = get_board_version(); |
| 100 | |
| 101 | if (board_rev & BOARD_REV_C) |
| 102 | gd->ram_size = SYS_SDRAM_SIZE_1024; |
| 103 | else |
| 104 | gd->ram_size = SYS_SDRAM_SIZE_512; |
| 105 | #else |
| 106 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
| 107 | #endif |
| 108 | } |
| 109 | return 0; |
| 110 | } |
| 111 | #else |
| 112 | int dram_init(void) |
| 113 | { |
| 114 | #ifdef CONFIG_TARGET_LS1012AFRWY |
| 115 | int board_rev; |
| 116 | #endif |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 117 | struct fsl_mmdc_info mparam = { |
York Sun | c1e979b | 2016-09-26 08:09:25 -0700 | [diff] [blame] | 118 | 0x04180000, /* mdctl */ |
| 119 | 0x00030035, /* mdpdc */ |
| 120 | 0x12554000, /* mdotc */ |
| 121 | 0xbabf7954, /* mdcfg0 */ |
| 122 | 0xdb328f64, /* mdcfg1 */ |
| 123 | 0x01ff00db, /* mdcfg2 */ |
| 124 | 0x00001680, /* mdmisc */ |
| 125 | 0x0f3c8000, /* mdref */ |
| 126 | 0x00002000, /* mdrwd */ |
| 127 | 0x00bf1023, /* mdor */ |
| 128 | 0x0000003f, /* mdasp */ |
| 129 | 0x0000022a, /* mpodtctrl */ |
| 130 | 0xa1390003, /* mpzqhwctrl */ |
| 131 | }; |
| 132 | |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 133 | #ifdef CONFIG_TARGET_LS1012AFRWY |
| 134 | board_rev = get_board_version(); |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 135 | |
Pramod Kumar | 46d752a | 2018-08-14 09:49:55 +0530 | [diff] [blame] | 136 | if (board_rev == BOARD_REV_C) { |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 137 | mparam.mdctl = 0x05180000; |
| 138 | gd->ram_size = SYS_SDRAM_SIZE_1024; |
| 139 | } else { |
| 140 | gd->ram_size = SYS_SDRAM_SIZE_512; |
| 141 | } |
| 142 | #else |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 143 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
Bhaskar Upadhaya | 5e6f598 | 2018-05-23 11:03:30 +0530 | [diff] [blame] | 144 | #endif |
| 145 | mmdc_init(&mparam); |
| 146 | |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 147 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 148 | /* This will break-before-make MMU for DDR */ |
| 149 | update_early_mmu_table(); |
| 150 | #endif |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 151 | |
| 152 | return 0; |
| 153 | } |
Rajesh Bhagat | 487084e | 2018-11-05 18:03:08 +0000 | [diff] [blame] | 154 | #endif |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 155 | |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 156 | int board_early_init_f(void) |
| 157 | { |
| 158 | fsl_lsch2_early_init_f(); |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | int board_init(void) |
| 164 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 165 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 166 | CONFIG_SYS_CCI400_OFFSET); |
| 167 | |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 168 | /* |
| 169 | * Set CCI-400 control override register to enable barrier |
| 170 | * transaction |
| 171 | */ |
Rajesh Bhagat | 487084e | 2018-11-05 18:03:08 +0000 | [diff] [blame] | 172 | if (current_el() == 3) |
| 173 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 174 | |
| 175 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 176 | gd->env_addr = (ulong)&default_environment[0]; |
| 177 | #endif |
| 178 | |
Vinitha V Pillai | ad698c3 | 2018-05-23 11:03:31 +0530 | [diff] [blame] | 179 | #ifdef CONFIG_FSL_CAAM |
| 180 | sec_init(); |
| 181 | #endif |
| 182 | |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 183 | #ifdef CONFIG_FSL_LS_PPA |
| 184 | ppa_init(); |
| 185 | #endif |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 186 | return 0; |
| 187 | } |
| 188 | |
Mian Yousaf Kaukab | 2529deae | 2021-04-14 12:33:58 +0200 | [diff] [blame] | 189 | #ifdef CONFIG_FSL_PFE |
| 190 | void board_quiesce_devices(void) |
| 191 | { |
| 192 | pfe_command_stop(0, NULL); |
| 193 | } |
| 194 | #endif |
| 195 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 196 | int ft_board_setup(void *blob, struct bd_info *bd) |
Prabhakar Kushwaha | 9e7ee7b | 2016-06-03 18:41:36 +0530 | [diff] [blame] | 197 | { |
| 198 | arch_fixup_fdt(blob); |
| 199 | |
| 200 | ft_cpu_setup(blob, bd); |
| 201 | |
| 202 | return 0; |
| 203 | } |