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