York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Freescale Semiconductor |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | #include <common.h> |
| 7 | #include <malloc.h> |
| 8 | #include <errno.h> |
| 9 | #include <netdev.h> |
| 10 | #include <fsl_ifc.h> |
| 11 | #include <fsl_ddr.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <fdt_support.h> |
| 14 | #include <libfdt.h> |
| 15 | #include <fsl_debug_server.h> |
| 16 | #include <fsl-mc/fsl_mc.h> |
| 17 | #include <environment.h> |
| 18 | #include <i2c.h> |
| 19 | #include <asm/arch-fsl-lsch3/soc.h> |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 20 | #include <hwconfig.h> |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 21 | |
| 22 | #include "../common/qixis.h" |
| 23 | #include "ls2085aqds_qixis.h" |
| 24 | |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 25 | #define PIN_MUX_SEL_SDHC 0x00 |
| 26 | #define PIN_MUX_SEL_DSPI 0x0a |
| 27 | |
| 28 | #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value) |
| 29 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
| 31 | |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 32 | enum { |
| 33 | MUX_TYPE_SDHC, |
| 34 | MUX_TYPE_DSPI, |
| 35 | }; |
| 36 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 37 | unsigned long long get_qixis_addr(void) |
| 38 | { |
| 39 | unsigned long long addr; |
| 40 | |
| 41 | if (gd->flags & GD_FLG_RELOC) |
| 42 | addr = QIXIS_BASE_PHYS; |
| 43 | else |
| 44 | addr = QIXIS_BASE_PHYS_EARLY; |
| 45 | |
| 46 | /* |
| 47 | * IFC address under 256MB is mapped to 0x30000000, any address above |
| 48 | * is mapped to 0x5_10000000 up to 4GB. |
| 49 | */ |
| 50 | addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000; |
| 51 | |
| 52 | return addr; |
| 53 | } |
| 54 | |
| 55 | int checkboard(void) |
| 56 | { |
| 57 | char buf[64]; |
| 58 | u8 sw; |
| 59 | static const char *const freq[] = {"100", "125", "156.25", |
| 60 | "100 separate SSCG"}; |
| 61 | int clock; |
| 62 | |
Prabhakar Kushwaha | ff1b8e3 | 2015-05-28 14:54:07 +0530 | [diff] [blame] | 63 | cpu_name(buf); |
| 64 | printf("Board: %s-QDS, ", buf); |
| 65 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 66 | sw = QIXIS_READ(arch); |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 67 | printf("Board Arch: V%d, ", sw >> 4); |
| 68 | printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1); |
| 69 | |
Prabhakar Kushwaha | ff1b8e3 | 2015-05-28 14:54:07 +0530 | [diff] [blame] | 70 | memset((u8 *)buf, 0x00, ARRAY_SIZE(buf)); |
| 71 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 72 | sw = QIXIS_READ(brdcfg[0]); |
| 73 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 74 | |
| 75 | if (sw < 0x8) |
| 76 | printf("vBank: %d\n", sw); |
| 77 | else if (sw == 0x8) |
| 78 | puts("PromJet\n"); |
| 79 | else if (sw == 0x9) |
| 80 | puts("NAND\n"); |
| 81 | else if (sw == 0x15) |
| 82 | printf("IFCCard\n"); |
| 83 | else |
| 84 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 85 | |
| 86 | printf("FPGA: v%d (%s), build %d", |
| 87 | (int)QIXIS_READ(scver), qixis_read_tag(buf), |
| 88 | (int)qixis_read_minor()); |
| 89 | /* the timestamp string contains "\n" at the end */ |
| 90 | printf(" on %s", qixis_read_time(buf)); |
| 91 | |
| 92 | /* |
| 93 | * Display the actual SERDES reference clocks as configured by the |
| 94 | * dip switches on the board. Note that the SWx registers could |
| 95 | * technically be set to force the reference clocks to match the |
| 96 | * values that the SERDES expects (or vice versa). For now, however, |
| 97 | * we just display both values and hope the user notices when they |
| 98 | * don't match. |
| 99 | */ |
| 100 | puts("SERDES1 Reference : "); |
| 101 | sw = QIXIS_READ(brdcfg[2]); |
| 102 | clock = (sw >> 6) & 3; |
| 103 | printf("Clock1 = %sMHz ", freq[clock]); |
| 104 | clock = (sw >> 4) & 3; |
| 105 | printf("Clock2 = %sMHz", freq[clock]); |
| 106 | |
| 107 | puts("\nSERDES2 Reference : "); |
| 108 | clock = (sw >> 2) & 3; |
| 109 | printf("Clock1 = %sMHz ", freq[clock]); |
| 110 | clock = (sw >> 0) & 3; |
| 111 | printf("Clock2 = %sMHz\n", freq[clock]); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | unsigned long get_board_sys_clk(void) |
| 117 | { |
| 118 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 119 | |
| 120 | switch (sysclk_conf & 0x0F) { |
| 121 | case QIXIS_SYSCLK_83: |
| 122 | return 83333333; |
| 123 | case QIXIS_SYSCLK_100: |
| 124 | return 100000000; |
| 125 | case QIXIS_SYSCLK_125: |
| 126 | return 125000000; |
| 127 | case QIXIS_SYSCLK_133: |
| 128 | return 133333333; |
| 129 | case QIXIS_SYSCLK_150: |
| 130 | return 150000000; |
| 131 | case QIXIS_SYSCLK_160: |
| 132 | return 160000000; |
| 133 | case QIXIS_SYSCLK_166: |
| 134 | return 166666666; |
| 135 | } |
| 136 | return 66666666; |
| 137 | } |
| 138 | |
| 139 | unsigned long get_board_ddr_clk(void) |
| 140 | { |
| 141 | u8 ddrclk_conf = QIXIS_READ(brdcfg[1]); |
| 142 | |
| 143 | switch ((ddrclk_conf & 0x30) >> 4) { |
| 144 | case QIXIS_DDRCLK_100: |
| 145 | return 100000000; |
| 146 | case QIXIS_DDRCLK_125: |
| 147 | return 125000000; |
| 148 | case QIXIS_DDRCLK_133: |
| 149 | return 133333333; |
| 150 | } |
| 151 | return 66666666; |
| 152 | } |
| 153 | |
| 154 | int select_i2c_ch_pca9547(u8 ch) |
| 155 | { |
| 156 | int ret; |
| 157 | |
| 158 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
| 159 | if (ret) { |
| 160 | puts("PCA: failed to select proper channel\n"); |
| 161 | return ret; |
| 162 | } |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 167 | int config_board_mux(int ctrl_type) |
| 168 | { |
| 169 | u8 reg5; |
| 170 | |
| 171 | reg5 = QIXIS_READ(brdcfg[5]); |
| 172 | |
| 173 | switch (ctrl_type) { |
| 174 | case MUX_TYPE_SDHC: |
| 175 | reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC); |
| 176 | break; |
| 177 | case MUX_TYPE_DSPI: |
| 178 | reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI); |
| 179 | break; |
| 180 | default: |
| 181 | printf("Wrong mux interface type\n"); |
| 182 | return -1; |
| 183 | } |
| 184 | |
| 185 | QIXIS_WRITE(brdcfg[5], reg5); |
| 186 | |
| 187 | return 0; |
| 188 | } |
| 189 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 190 | int board_init(void) |
| 191 | { |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 192 | char *env_hwconfig; |
| 193 | u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE; |
| 194 | u32 val; |
| 195 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 196 | init_final_memctl_regs(); |
| 197 | |
Haikun Wang | e71a980 | 2015-06-26 19:58:12 +0800 | [diff] [blame] | 198 | val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4); |
| 199 | |
| 200 | env_hwconfig = getenv("hwconfig"); |
| 201 | |
| 202 | if (hwconfig_f("dspi", env_hwconfig) && |
| 203 | DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8))) |
| 204 | config_board_mux(MUX_TYPE_DSPI); |
| 205 | else |
| 206 | config_board_mux(MUX_TYPE_SDHC); |
| 207 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 208 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 209 | gd->env_addr = (ulong)&default_environment[0]; |
| 210 | #endif |
| 211 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 212 | |
| 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | int board_early_init_f(void) |
| 217 | { |
| 218 | fsl_lsch3_early_init_f(); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | void detail_board_ddr_info(void) |
| 223 | { |
| 224 | puts("\nDDR "); |
| 225 | print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, ""); |
| 226 | print_ddr_info(0); |
| 227 | if (gd->bd->bi_dram[2].size) { |
| 228 | puts("\nDP-DDR "); |
| 229 | print_size(gd->bd->bi_dram[2].size, ""); |
| 230 | print_ddr_info(CONFIG_DP_DDR_CTRL); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | int dram_init(void) |
| 235 | { |
| 236 | gd->ram_size = initdram(0); |
| 237 | |
| 238 | return 0; |
| 239 | } |
| 240 | |
| 241 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 242 | int arch_misc_init(void) |
| 243 | { |
| 244 | #ifdef CONFIG_FSL_DEBUG_SERVER |
| 245 | debug_server_init(); |
| 246 | #endif |
| 247 | |
| 248 | return 0; |
| 249 | } |
| 250 | #endif |
| 251 | |
| 252 | unsigned long get_dram_size_to_hide(void) |
| 253 | { |
| 254 | unsigned long dram_to_hide = 0; |
| 255 | |
| 256 | /* Carve the Debug Server private DRAM block from the end of DRAM */ |
| 257 | #ifdef CONFIG_FSL_DEBUG_SERVER |
| 258 | dram_to_hide += debug_server_get_dram_block_size(); |
| 259 | #endif |
| 260 | |
| 261 | /* Carve the MC private DRAM block from the end of DRAM */ |
| 262 | #ifdef CONFIG_FSL_MC_ENET |
| 263 | dram_to_hide += mc_get_dram_block_size(); |
| 264 | #endif |
| 265 | |
Prabhakar Kushwaha | 5c05508 | 2015-06-02 10:55:52 +0530 | [diff] [blame] | 266 | return roundup(dram_to_hide, CONFIG_SYS_MEM_TOP_HIDE_MIN); |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 267 | } |
| 268 | |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 269 | #ifdef CONFIG_FSL_MC_ENET |
| 270 | void fdt_fixup_board_enet(void *fdt) |
| 271 | { |
| 272 | int offset; |
| 273 | |
| 274 | offset = fdt_path_offset(fdt, "/fsl-mc"); |
| 275 | |
| 276 | if (offset < 0) |
| 277 | offset = fdt_path_offset(fdt, "/fsl,dprc@0"); |
| 278 | |
| 279 | if (offset < 0) { |
| 280 | printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n", |
| 281 | __func__, offset); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | if (get_mc_boot_status() == 0) |
| 286 | fdt_status_okay(fdt, offset); |
| 287 | else |
| 288 | fdt_status_fail(fdt, offset); |
| 289 | } |
| 290 | #endif |
| 291 | |
| 292 | #ifdef CONFIG_OF_BOARD_SETUP |
| 293 | int ft_board_setup(void *blob, bd_t *bd) |
| 294 | { |
Bhupesh Sharma | a2dc818 | 2015-05-28 14:54:10 +0530 | [diff] [blame] | 295 | u64 base[CONFIG_NR_DRAM_BANKS]; |
| 296 | u64 size[CONFIG_NR_DRAM_BANKS]; |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 297 | |
| 298 | ft_cpu_setup(blob, bd); |
| 299 | |
Bhupesh Sharma | a2dc818 | 2015-05-28 14:54:10 +0530 | [diff] [blame] | 300 | /* fixup DT for the two GPP DDR banks */ |
| 301 | base[0] = gd->bd->bi_dram[0].start; |
| 302 | size[0] = gd->bd->bi_dram[0].size; |
| 303 | base[1] = gd->bd->bi_dram[1].start; |
| 304 | size[1] = gd->bd->bi_dram[1].size; |
| 305 | |
| 306 | fdt_fixup_memory_banks(blob, base, size, 2); |
York Sun | 7288c2c | 2015-03-20 19:28:23 -0700 | [diff] [blame] | 307 | |
| 308 | #ifdef CONFIG_FSL_MC_ENET |
| 309 | fdt_fixup_board_enet(blob); |
| 310 | fsl_mc_ldpaa_exit(bd); |
| 311 | #endif |
| 312 | |
| 313 | return 0; |
| 314 | } |
| 315 | #endif |
| 316 | |
| 317 | void qixis_dump_switch(void) |
| 318 | { |
| 319 | int i, nr_of_cfgsw; |
| 320 | |
| 321 | QIXIS_WRITE(cms[0], 0x00); |
| 322 | nr_of_cfgsw = QIXIS_READ(cms[1]); |
| 323 | |
| 324 | puts("DIP switch settings dump:\n"); |
| 325 | for (i = 1; i <= nr_of_cfgsw; i++) { |
| 326 | QIXIS_WRITE(cms[0], i); |
| 327 | printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1])); |
| 328 | } |
| 329 | } |