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