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