York Sun | e2b65ea | 2015-03-20 19:28:24 -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> |
Yangbo Lu | 5a4d744 | 2015-05-28 14:53:55 +0530 | [diff] [blame^] | 13 | #include <hwconfig.h> |
York Sun | e2b65ea | 2015-03-20 19:28:24 -0700 | [diff] [blame] | 14 | #include <fdt_support.h> |
| 15 | #include <libfdt.h> |
| 16 | #include <fsl_debug_server.h> |
| 17 | #include <fsl-mc/fsl_mc.h> |
| 18 | #include <environment.h> |
| 19 | #include <i2c.h> |
| 20 | #include <asm/arch-fsl-lsch3/soc.h> |
| 21 | |
| 22 | #include "../common/qixis.h" |
| 23 | #include "ls2085ardb_qixis.h" |
| 24 | |
Yangbo Lu | 5a4d744 | 2015-05-28 14:53:55 +0530 | [diff] [blame^] | 25 | #define PIN_MUX_SEL_SDHC 0x00 |
| 26 | |
| 27 | #define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value) |
York Sun | e2b65ea | 2015-03-20 19:28:24 -0700 | [diff] [blame] | 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
Yangbo Lu | 5a4d744 | 2015-05-28 14:53:55 +0530 | [diff] [blame^] | 30 | enum { |
| 31 | MUX_TYPE_SDHC, |
| 32 | }; |
| 33 | |
York Sun | e2b65ea | 2015-03-20 19:28:24 -0700 | [diff] [blame] | 34 | unsigned long long get_qixis_addr(void) |
| 35 | { |
| 36 | unsigned long long addr; |
| 37 | |
| 38 | if (gd->flags & GD_FLG_RELOC) |
| 39 | addr = QIXIS_BASE_PHYS; |
| 40 | else |
| 41 | addr = QIXIS_BASE_PHYS_EARLY; |
| 42 | |
| 43 | /* |
| 44 | * IFC address under 256MB is mapped to 0x30000000, any address above |
| 45 | * is mapped to 0x5_10000000 up to 4GB. |
| 46 | */ |
| 47 | addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000; |
| 48 | |
| 49 | return addr; |
| 50 | } |
| 51 | |
| 52 | int checkboard(void) |
| 53 | { |
| 54 | u8 sw; |
| 55 | |
| 56 | sw = QIXIS_READ(arch); |
| 57 | printf("Board: %s, ", CONFIG_IDENT_STRING); |
| 58 | printf("Board Arch: V%d, ", sw >> 4); |
| 59 | printf("Board version: %c, boot from ", (sw & 0xf) + 'A' - 1); |
| 60 | |
| 61 | sw = QIXIS_READ(brdcfg[0]); |
| 62 | sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT; |
| 63 | |
| 64 | if (sw < 0x8) |
| 65 | printf("vBank: %d\n", sw); |
| 66 | else if (sw == 0x9) |
| 67 | puts("NAND\n"); |
| 68 | else |
| 69 | printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH); |
| 70 | |
| 71 | printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata)); |
| 72 | |
| 73 | puts("SERDES1 Reference : "); |
| 74 | printf("Clock1 = 156.25MHz "); |
| 75 | printf("Clock2 = 156.25MHz"); |
| 76 | |
| 77 | puts("\nSERDES2 Reference : "); |
| 78 | printf("Clock1 = 100MHz "); |
| 79 | printf("Clock2 = 100MHz\n"); |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | unsigned long get_board_sys_clk(void) |
| 85 | { |
| 86 | u8 sysclk_conf = QIXIS_READ(brdcfg[1]); |
| 87 | |
| 88 | switch (sysclk_conf & 0x0F) { |
| 89 | case QIXIS_SYSCLK_83: |
| 90 | return 83333333; |
| 91 | case QIXIS_SYSCLK_100: |
| 92 | return 100000000; |
| 93 | case QIXIS_SYSCLK_125: |
| 94 | return 125000000; |
| 95 | case QIXIS_SYSCLK_133: |
| 96 | return 133333333; |
| 97 | case QIXIS_SYSCLK_150: |
| 98 | return 150000000; |
| 99 | case QIXIS_SYSCLK_160: |
| 100 | return 160000000; |
| 101 | case QIXIS_SYSCLK_166: |
| 102 | return 166666666; |
| 103 | } |
| 104 | return 66666666; |
| 105 | } |
| 106 | |
| 107 | int select_i2c_ch_pca9547(u8 ch) |
| 108 | { |
| 109 | int ret; |
| 110 | |
| 111 | ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1); |
| 112 | if (ret) { |
| 113 | puts("PCA: failed to select proper channel\n"); |
| 114 | return ret; |
| 115 | } |
| 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | int board_init(void) |
| 121 | { |
| 122 | init_final_memctl_regs(); |
| 123 | |
| 124 | #ifdef CONFIG_ENV_IS_NOWHERE |
| 125 | gd->env_addr = (ulong)&default_environment[0]; |
| 126 | #endif |
| 127 | select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT); |
| 128 | |
| 129 | QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET_EN); |
| 130 | |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | int board_early_init_f(void) |
| 135 | { |
| 136 | fsl_lsch3_early_init_f(); |
| 137 | return 0; |
| 138 | } |
| 139 | |
Yangbo Lu | 5a4d744 | 2015-05-28 14:53:55 +0530 | [diff] [blame^] | 140 | int config_board_mux(int ctrl_type) |
| 141 | { |
| 142 | u8 reg5; |
| 143 | |
| 144 | reg5 = QIXIS_READ(brdcfg[5]); |
| 145 | |
| 146 | switch (ctrl_type) { |
| 147 | case MUX_TYPE_SDHC: |
| 148 | reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC); |
| 149 | break; |
| 150 | default: |
| 151 | printf("Wrong mux interface type\n"); |
| 152 | return -1; |
| 153 | } |
| 154 | |
| 155 | QIXIS_WRITE(brdcfg[5], reg5); |
| 156 | |
| 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | int misc_init_r(void) |
| 161 | { |
| 162 | if (hwconfig("sdhc")) |
| 163 | config_board_mux(MUX_TYPE_SDHC); |
| 164 | |
| 165 | return 0; |
| 166 | } |
| 167 | |
York Sun | e2b65ea | 2015-03-20 19:28:24 -0700 | [diff] [blame] | 168 | void detail_board_ddr_info(void) |
| 169 | { |
| 170 | puts("\nDDR "); |
| 171 | print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, ""); |
| 172 | print_ddr_info(0); |
| 173 | if (gd->bd->bi_dram[2].size) { |
| 174 | puts("\nDP-DDR "); |
| 175 | print_size(gd->bd->bi_dram[2].size, ""); |
| 176 | print_ddr_info(CONFIG_DP_DDR_CTRL); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | int dram_init(void) |
| 181 | { |
| 182 | gd->ram_size = initdram(0); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 188 | int arch_misc_init(void) |
| 189 | { |
| 190 | #ifdef CONFIG_FSL_DEBUG_SERVER |
| 191 | debug_server_init(); |
| 192 | #endif |
| 193 | |
| 194 | return 0; |
| 195 | } |
| 196 | #endif |
| 197 | |
| 198 | unsigned long get_dram_size_to_hide(void) |
| 199 | { |
| 200 | unsigned long dram_to_hide = 0; |
| 201 | |
| 202 | /* Carve the Debug Server private DRAM block from the end of DRAM */ |
| 203 | #ifdef CONFIG_FSL_DEBUG_SERVER |
| 204 | dram_to_hide += debug_server_get_dram_block_size(); |
| 205 | #endif |
| 206 | |
| 207 | /* Carve the MC private DRAM block from the end of DRAM */ |
| 208 | #ifdef CONFIG_FSL_MC_ENET |
| 209 | dram_to_hide += mc_get_dram_block_size(); |
| 210 | #endif |
| 211 | |
| 212 | return dram_to_hide; |
| 213 | } |
| 214 | |
York Sun | e2b65ea | 2015-03-20 19:28:24 -0700 | [diff] [blame] | 215 | #ifdef CONFIG_FSL_MC_ENET |
| 216 | void fdt_fixup_board_enet(void *fdt) |
| 217 | { |
| 218 | int offset; |
| 219 | |
| 220 | offset = fdt_path_offset(fdt, "/fsl-mc"); |
| 221 | |
| 222 | if (offset < 0) |
| 223 | offset = fdt_path_offset(fdt, "/fsl,dprc@0"); |
| 224 | |
| 225 | if (offset < 0) { |
| 226 | printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n", |
| 227 | __func__, offset); |
| 228 | return; |
| 229 | } |
| 230 | |
| 231 | if (get_mc_boot_status() == 0) |
| 232 | fdt_status_okay(fdt, offset); |
| 233 | else |
| 234 | fdt_status_fail(fdt, offset); |
| 235 | } |
| 236 | #endif |
| 237 | |
| 238 | #ifdef CONFIG_OF_BOARD_SETUP |
| 239 | int ft_board_setup(void *blob, bd_t *bd) |
| 240 | { |
| 241 | phys_addr_t base; |
| 242 | phys_size_t size; |
| 243 | |
| 244 | ft_cpu_setup(blob, bd); |
| 245 | |
| 246 | /* limit the memory size to bank 1 until Linux can handle 40-bit PA */ |
| 247 | base = getenv_bootm_low(); |
| 248 | size = getenv_bootm_size(); |
| 249 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 250 | |
| 251 | #ifdef CONFIG_FSL_MC_ENET |
| 252 | fdt_fixup_board_enet(blob); |
| 253 | fsl_mc_ldpaa_exit(bd); |
| 254 | #endif |
| 255 | |
| 256 | return 0; |
| 257 | } |
| 258 | #endif |
| 259 | |
| 260 | void qixis_dump_switch(void) |
| 261 | { |
| 262 | int i, nr_of_cfgsw; |
| 263 | |
| 264 | QIXIS_WRITE(cms[0], 0x00); |
| 265 | nr_of_cfgsw = QIXIS_READ(cms[1]); |
| 266 | |
| 267 | puts("DIP switch settings dump:\n"); |
| 268 | for (i = 1; i <= nr_of_cfgsw; i++) { |
| 269 | QIXIS_WRITE(cms[0], i); |
| 270 | printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1])); |
| 271 | } |
| 272 | } |