Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Freescale Semiconductor, Inc. |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <i2c.h> |
| 9 | #include <asm/io.h> |
| 10 | #include <asm/arch/clock.h> |
| 11 | #include <asm/arch/fsl_serdes.h> |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 12 | #ifdef CONFIG_FSL_LS_PPA |
| 13 | #include <asm/arch/ppa.h> |
| 14 | #endif |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 15 | #include <asm/arch/mmu.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 16 | #include <asm/arch/soc.h> |
| 17 | #include <hwconfig.h> |
| 18 | #include <ahci.h> |
| 19 | #include <mmc.h> |
| 20 | #include <scsi.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 21 | #include <fsl_esdhc.h> |
| 22 | #include <environment.h> |
| 23 | #include <fsl_mmdc.h> |
| 24 | #include <netdev.h> |
Vinitha Pillai-B57223 | eea4a32 | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 25 | #include <fsl_sec.h> |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 26 | |
| 27 | DECLARE_GLOBAL_DATA_PTR; |
| 28 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 29 | int checkboard(void) |
| 30 | { |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 31 | #ifdef CONFIG_TARGET_LS1012ARDB |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 32 | u8 in1; |
| 33 | |
| 34 | puts("Board: LS1012ARDB "); |
| 35 | |
| 36 | /* Initialize i2c early for Serial flash bank information */ |
| 37 | i2c_set_bus_num(0); |
| 38 | |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 39 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &in1, 1) < 0) { |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 40 | printf("Error reading i2c boot information!\n"); |
| 41 | return 0; /* Don't want to hang() on this error */ |
| 42 | } |
| 43 | |
| 44 | puts("Version"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 45 | switch (in1 & SW_REV_MASK) { |
| 46 | case SW_REV_A: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 47 | puts(": RevA"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 48 | break; |
| 49 | case SW_REV_B: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 50 | puts(": RevB"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 51 | break; |
| 52 | case SW_REV_C: |
| 53 | puts(": RevC"); |
| 54 | break; |
| 55 | case SW_REV_C1: |
| 56 | puts(": RevC1"); |
| 57 | break; |
| 58 | case SW_REV_C2: |
| 59 | puts(": RevC2"); |
| 60 | break; |
| 61 | case SW_REV_D: |
| 62 | puts(": RevD"); |
| 63 | break; |
| 64 | case SW_REV_E: |
| 65 | puts(": RevE"); |
| 66 | break; |
| 67 | default: |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 68 | puts(": unknown"); |
Yangbo Lu | 13acb0d | 2017-12-08 15:35:36 +0800 | [diff] [blame] | 69 | break; |
| 70 | } |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 71 | |
| 72 | printf(", boot from QSPI"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 73 | if ((in1 & SW_BOOT_MASK) == SW_BOOT_EMU) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 74 | puts(": emu\n"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 75 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK1) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 76 | puts(": bank1\n"); |
Yangbo Lu | 2786f90 | 2017-12-08 15:35:35 +0800 | [diff] [blame] | 77 | else if ((in1 & SW_BOOT_MASK) == SW_BOOT_BANK2) |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 78 | puts(": bank2\n"); |
| 79 | else |
| 80 | puts("unknown\n"); |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 81 | #else |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 82 | |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 83 | puts("Board: LS1012A2G5RDB "); |
| 84 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 88 | int dram_init(void) |
| 89 | { |
York Sun | c1e979b | 2016-09-26 08:09:25 -0700 | [diff] [blame] | 90 | static const struct fsl_mmdc_info mparam = { |
| 91 | 0x05180000, /* mdctl */ |
| 92 | 0x00030035, /* mdpdc */ |
| 93 | 0x12554000, /* mdotc */ |
| 94 | 0xbabf7954, /* mdcfg0 */ |
| 95 | 0xdb328f64, /* mdcfg1 */ |
| 96 | 0x01ff00db, /* mdcfg2 */ |
| 97 | 0x00001680, /* mdmisc */ |
| 98 | 0x0f3c8000, /* mdref */ |
| 99 | 0x00002000, /* mdrwd */ |
| 100 | 0x00bf1023, /* mdor */ |
| 101 | 0x0000003f, /* mdasp */ |
| 102 | 0x0000022a, /* mpodtctrl */ |
| 103 | 0xa1390003, /* mpzqhwctrl */ |
| 104 | }; |
| 105 | |
| 106 | mmdc_init(&mparam); |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 107 | |
| 108 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE; |
York Sun | 729f2d1 | 2017-03-06 09:02:34 -0800 | [diff] [blame] | 109 | #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD) |
| 110 | /* This will break-before-make MMU for DDR */ |
| 111 | update_early_mmu_table(); |
| 112 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int board_eth_init(bd_t *bis) |
| 118 | { |
| 119 | return pci_eth_init(bis); |
| 120 | } |
| 121 | |
| 122 | int board_early_init_f(void) |
| 123 | { |
| 124 | fsl_lsch2_early_init_f(); |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | int board_init(void) |
| 130 | { |
Ashish Kumar | 1123406 | 2017-08-11 11:09:14 +0530 | [diff] [blame] | 131 | struct ccsr_cci400 *cci = (struct ccsr_cci400 *)(CONFIG_SYS_IMMR + |
| 132 | CONFIG_SYS_CCI400_OFFSET); |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 133 | /* |
| 134 | * Set CCI-400 control override register to enable barrier |
| 135 | * transaction |
| 136 | */ |
| 137 | out_le32(&cci->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); |
| 138 | |
Hou Zhiqiang | 4b23ca8 | 2016-08-02 19:03:27 +0800 | [diff] [blame] | 139 | #ifdef CONFIG_SYS_FSL_ERRATUM_A010315 |
| 140 | erratum_a010315(); |
| 141 | #endif |
| 142 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 143 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 144 | gd->env_addr = (ulong)&default_environment[0]; |
| 145 | #endif |
| 146 | |
Vinitha Pillai-B57223 | eea4a32 | 2017-03-23 13:48:20 +0530 | [diff] [blame] | 147 | #ifdef CONFIG_FSL_CAAM |
| 148 | sec_init(); |
| 149 | #endif |
| 150 | |
Prabhakar Kushwaha | 74d129b | 2017-01-30 17:05:35 +0530 | [diff] [blame] | 151 | #ifdef CONFIG_FSL_LS_PPA |
| 152 | ppa_init(); |
| 153 | #endif |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 154 | return 0; |
| 155 | } |
| 156 | |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 157 | #ifdef CONFIG_TARGET_LS1012ARDB |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 158 | int esdhc_status_fixup(void *blob, const char *compat) |
| 159 | { |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 160 | char esdhc1_path[] = "/soc/esdhc@1580000"; |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 161 | bool sdhc2_en = false; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 162 | u8 mux_sdhc2; |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 163 | u8 io = 0; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 164 | |
| 165 | i2c_set_bus_num(0); |
| 166 | |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 167 | /* IO1[7:3] is the field of board revision info. */ |
| 168 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_1, 1, &io, 1) < 0) { |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 169 | printf("Error reading i2c boot information!\n"); |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 170 | return 0; |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 171 | } |
| 172 | |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 173 | /* hwconfig method is used for RevD and later versions. */ |
| 174 | if ((io & SW_REV_MASK) <= SW_REV_D) { |
| 175 | #ifdef CONFIG_HWCONFIG |
| 176 | if (hwconfig("esdhc1")) |
| 177 | sdhc2_en = true; |
| 178 | #endif |
| 179 | } else { |
| 180 | /* |
| 181 | * The I2C IO-expander for mux select is used to control |
| 182 | * the muxing of various onboard interfaces. |
| 183 | * |
| 184 | * IO0[3:2] indicates SDHC2 interface demultiplexer |
| 185 | * select lines. |
| 186 | * 00 - SDIO wifi |
| 187 | * 01 - GPIO (to Arduino) |
| 188 | * 10 - eMMC Memory |
| 189 | * 11 - SPI |
| 190 | */ |
| 191 | if (i2c_read(I2C_MUX_IO_ADDR, I2C_MUX_IO_0, 1, &io, 1) < 0) { |
| 192 | printf("Error reading i2c boot information!\n"); |
| 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | mux_sdhc2 = (io & 0x0c) >> 2; |
| 197 | /* Enable SDHC2 only when use SDIO wifi and eMMC */ |
| 198 | if (mux_sdhc2 == 2 || mux_sdhc2 == 0) |
| 199 | sdhc2_en = true; |
| 200 | } |
Yangbo Lu | 878c978 | 2017-12-08 15:35:37 +0800 | [diff] [blame] | 201 | if (sdhc2_en) |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 202 | do_fixup_by_path(blob, esdhc1_path, "status", "okay", |
| 203 | sizeof("okay"), 1); |
| 204 | else |
| 205 | do_fixup_by_path(blob, esdhc1_path, "status", "disabled", |
| 206 | sizeof("disabled"), 1); |
| 207 | return 0; |
| 208 | } |
Bhaskar Upadhaya | 7fff22a | 2018-01-11 20:03:31 +0530 | [diff] [blame] | 209 | #endif |
Yangbo Lu | b2495c0 | 2017-01-17 10:43:56 +0800 | [diff] [blame] | 210 | |
Prabhakar Kushwaha | a315c66 | 2016-06-03 18:41:35 +0530 | [diff] [blame] | 211 | int ft_board_setup(void *blob, bd_t *bd) |
| 212 | { |
| 213 | arch_fixup_fdt(blob); |
| 214 | |
| 215 | ft_cpu_setup(blob, bd); |
| 216 | |
| 217 | return 0; |
| 218 | } |