Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009-2011 eXMeritus, A Boeing Company |
| 3 | * Copyright 2007-2009 Freescale Semiconductor, Inc. |
| 4 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <command.h> |
| 10 | #include <pci.h> |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/mmu.h> |
| 13 | #include <asm/cache.h> |
| 14 | #include <asm/immap_85xx.h> |
| 15 | #include <asm/fsl_pci.h> |
York Sun | 5614e71 | 2013-09-30 09:22:09 -0700 | [diff] [blame] | 16 | #include <fsl_ddr_sdram.h> |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 17 | #include <asm/io.h> |
| 18 | #include <miiphy.h> |
| 19 | #include <libfdt.h> |
| 20 | #include <linux/ctype.h> |
| 21 | #include <fdt_support.h> |
| 22 | #include <fsl_mdio.h> |
| 23 | #include <tsec.h> |
| 24 | #include <asm/fsl_law.h> |
| 25 | #include <netdev.h> |
| 26 | #include <malloc.h> |
| 27 | #include <i2c.h> |
| 28 | #include <pca953x.h> |
| 29 | |
| 30 | #include "gpios.h" |
| 31 | |
| 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
| 34 | int checkboard(void) |
| 35 | { |
| 36 | unsigned int gpio_high = 0; |
| 37 | unsigned int gpio_low = 0; |
| 38 | unsigned int gpio_in = 0; |
| 39 | unsigned int i; |
York Sun | 9a17eb5 | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 40 | struct ccsr_ddr __iomem *ddr; |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 41 | |
| 42 | puts("Board: HWW-1U-1A "); |
| 43 | |
| 44 | /* |
| 45 | * First just figure out which CPU we're on, then use that to |
| 46 | * configure the lists of other GPIOs to be programmed. |
| 47 | */ |
| 48 | mpc85xx_gpio_set_in(GPIO_CPU_ID); |
| 49 | if (hww1u1a_is_cpu_a()) { |
| 50 | puts("CPU A\n"); |
| 51 | |
| 52 | /* We want to turn on some LEDs */ |
| 53 | gpio_high |= GPIO_CPUA_CPU_READY; |
| 54 | gpio_low |= GPIO_CPUA_DEBUG_LED1; |
| 55 | gpio_low |= GPIO_CPUA_DEBUG_LED2; |
| 56 | |
| 57 | /* Disable the unused transmitters */ |
| 58 | gpio_low |= GPIO_CPUA_TDIS1A; |
| 59 | gpio_high |= GPIO_CPUA_TDIS1B; |
| 60 | gpio_low |= GPIO_CPUA_TDIS2A; |
| 61 | gpio_high |= GPIO_CPUA_TDIS2B; |
| 62 | } else { |
| 63 | puts("CPU B\n"); |
| 64 | |
| 65 | /* We want to turn on some LEDs */ |
| 66 | gpio_high |= GPIO_CPUB_CPU_READY; |
| 67 | gpio_low |= GPIO_CPUB_DEBUG_LED1; |
| 68 | gpio_low |= GPIO_CPUB_DEBUG_LED2; |
| 69 | |
| 70 | /* Enable the appropriate receivers */ |
| 71 | gpio_high |= GPIO_CPUB_RMUX_SEL0A; |
| 72 | gpio_high |= GPIO_CPUB_RMUX_SEL0B; |
| 73 | gpio_low |= GPIO_CPUB_RMUX_SEL1A; |
| 74 | gpio_low |= GPIO_CPUB_RMUX_SEL1B; |
| 75 | } |
| 76 | |
| 77 | /* These GPIOs are common */ |
| 78 | gpio_in |= IRQ_I2CINT | IRQ_FANINT | IRQ_DIMM_EVENT; |
| 79 | gpio_low |= GPIO_RS422_RE; |
| 80 | gpio_high |= GPIO_RS422_DE; |
| 81 | |
| 82 | /* Ok, now go ahead and program all of those in one go */ |
| 83 | mpc85xx_gpio_set(gpio_high|gpio_low|gpio_in, |
| 84 | gpio_high|gpio_low, |
| 85 | gpio_high); |
| 86 | |
| 87 | /* |
| 88 | * If things have been taken out of reset early (for example, by one |
| 89 | * of the BDI3000 debuggers), then we need to put them back in reset |
| 90 | * and delay a while before we continue. |
| 91 | */ |
| 92 | if (mpc85xx_gpio_get(GPIO_RESETS)) { |
York Sun | 9a17eb5 | 2013-11-18 10:29:32 -0800 | [diff] [blame] | 93 | ddr = (struct ccsr_ddr __iomem *)CONFIG_SYS_FSL_DDR_ADDR; |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 94 | |
| 95 | puts("Debugger detected... extra device reset enabled!\n"); |
| 96 | |
| 97 | /* Put stuff into reset and disable the DDR controller */ |
| 98 | mpc85xx_gpio_set_low(GPIO_RESETS); |
| 99 | out_be32(&ddr->sdram_cfg, 0x00000000); |
| 100 | |
| 101 | puts(" Waiting 1 sec for reset..."); |
| 102 | for (i = 0; i < 10; i++) { |
| 103 | udelay(100000); |
| 104 | puts("."); |
| 105 | } |
| 106 | puts("\n"); |
| 107 | } |
| 108 | |
| 109 | /* Now bring everything back out of reset again */ |
| 110 | mpc85xx_gpio_set_high(GPIO_RESETS); |
| 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * This little shell function just returns whether or not it's CPU A. |
| 116 | * It can be used to select the right device-tree when booting, etc. |
| 117 | */ |
| 118 | int do_hww1u1a_test_cpu_a(cmd_tbl_t *cmdtp, int flag, |
| 119 | int argc, char * const argv[]) |
| 120 | { |
| 121 | if (argc > 1) |
| 122 | cmd_usage(cmdtp); |
| 123 | |
| 124 | if (hww1u1a_is_cpu_a()) |
| 125 | return 0; |
| 126 | else |
| 127 | return 1; |
| 128 | } |
| 129 | U_BOOT_CMD( |
| 130 | test_cpu_a, 1, 0, do_hww1u1a_test_cpu_a, |
| 131 | "Test if this is CPU A (versus B) on the eXMeritus HWW-1U-1A board", |
| 132 | "" |
| 133 | ); |
| 134 | |
| 135 | /* Create a prompt-like string: "uboot@HOSTNAME% " */ |
| 136 | #define PROMPT_PREFIX "uboot@exm" |
| 137 | #define PROMPT_SUFFIX "% " |
| 138 | |
| 139 | /* This function returns a PS1 prompt based on the serial number */ |
| 140 | static char *hww1u1a_prompt; |
| 141 | const char *hww1u1a_get_ps1(void) |
| 142 | { |
| 143 | unsigned long len, i, j; |
| 144 | const char *serialnr; |
| 145 | |
| 146 | /* If our prompt was already set, just use that */ |
| 147 | if (hww1u1a_prompt) |
| 148 | return hww1u1a_prompt; |
| 149 | |
| 150 | /* Use our serial number if present, otherwise a default */ |
| 151 | serialnr = getenv("serial#"); |
| 152 | if (!serialnr || !serialnr[0]) |
| 153 | serialnr = "999999-X"; |
| 154 | |
| 155 | /* |
| 156 | * We will turn the serial number into a hostname by: |
| 157 | * (A) Delete all non-alphanumerics. |
| 158 | * (B) Lowercase all letters. |
| 159 | * (C) Prefix "exm". |
| 160 | * (D) Suffix "a" for CPU A and "b" for CPU B. |
| 161 | */ |
| 162 | for (i = 0, len = 0; serialnr[i]; i++) { |
| 163 | if (isalnum(serialnr[i])) |
| 164 | len++; |
| 165 | } |
| 166 | |
| 167 | len += sizeof(PROMPT_PREFIX PROMPT_SUFFIX) + 1; /* Includes NUL */ |
| 168 | hww1u1a_prompt = malloc(len); |
| 169 | if (!hww1u1a_prompt) |
| 170 | return PROMPT_PREFIX "UNKNOWN(ENOMEM)" PROMPT_SUFFIX; |
| 171 | |
| 172 | /* Now actually fill it in */ |
| 173 | i = 0; |
| 174 | |
| 175 | /* Handle the prefix */ |
| 176 | for (j = 0; j < sizeof(PROMPT_PREFIX) - 1; j++) |
| 177 | hww1u1a_prompt[i++] = PROMPT_PREFIX[j]; |
| 178 | |
| 179 | /* Now the serial# part of the hostname */ |
| 180 | for (j = 0; serialnr[j]; j++) |
| 181 | if (isalnum(serialnr[j])) |
| 182 | hww1u1a_prompt[i++] = tolower(serialnr[j]); |
| 183 | |
| 184 | /* Now the CPU id ("a" or "b") */ |
| 185 | hww1u1a_prompt[i++] = hww1u1a_is_cpu_a() ? 'a' : 'b'; |
| 186 | |
| 187 | /* Finally the suffix */ |
| 188 | for (j = 0; j < sizeof(PROMPT_SUFFIX); j++) |
| 189 | hww1u1a_prompt[i++] = PROMPT_SUFFIX[j]; |
| 190 | |
| 191 | /* This should all have added up, but just in case */ |
| 192 | hww1u1a_prompt[len - 1] = '\0'; |
| 193 | |
| 194 | /* Now we're done */ |
| 195 | return hww1u1a_prompt; |
| 196 | } |
| 197 | |
| 198 | void pci_init_board(void) |
| 199 | { |
| 200 | fsl_pcie_init_board(0); |
| 201 | } |
| 202 | |
| 203 | int board_early_init_r(void) |
| 204 | { |
| 205 | const unsigned int flashbase = CONFIG_SYS_FLASH_BASE; |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 206 | int flash_esel = find_tlb_idx((void *)flashbase, 1); |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 207 | |
| 208 | /* |
| 209 | * Remap bootflash region to caching-inhibited |
| 210 | * so that flash can be erased properly. |
| 211 | */ |
| 212 | |
| 213 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 214 | flush_dcache(); |
| 215 | invalidate_icache(); |
| 216 | |
York Sun | 9d04568 | 2014-06-24 21:16:20 -0700 | [diff] [blame] | 217 | if (flash_esel == -1) { |
| 218 | /* very unlikely unless something is messed up */ |
| 219 | puts("Error: Could not find TLB for FLASH BASE\n"); |
| 220 | flash_esel = 2; /* give our best effort to continue */ |
| 221 | } else { |
| 222 | /* invalidate existing TLB entry for FLASH */ |
| 223 | disable_tlb(flash_esel); |
| 224 | } |
Kyle Moffett | f8bbb4d | 2011-12-07 16:39:16 -0500 | [diff] [blame] | 225 | |
| 226 | set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS, |
| 227 | MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, |
| 228 | 0, flash_esel, BOOKE_PAGESZ_256M, 1); |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | int board_eth_init(bd_t *bis) |
| 234 | { |
| 235 | struct tsec_info_struct tsec_info[4]; |
| 236 | struct fsl_pq_mdio_info mdio_info; |
| 237 | |
| 238 | SET_STD_TSEC_INFO(tsec_info[0], 1); |
| 239 | SET_STD_TSEC_INFO(tsec_info[1], 2); |
| 240 | SET_STD_TSEC_INFO(tsec_info[2], 3); |
| 241 | |
| 242 | if (hww1u1a_is_cpu_a()) |
| 243 | tsec_info[2].phyaddr = TSEC3_PHY_ADDR_CPUA; |
| 244 | else |
| 245 | tsec_info[2].phyaddr = TSEC3_PHY_ADDR_CPUB; |
| 246 | |
| 247 | mdio_info.regs = (struct tsec_mii_mng *)CONFIG_SYS_MDIO_BASE_ADDR; |
| 248 | mdio_info.name = DEFAULT_MII_NAME; |
| 249 | fsl_pq_mdio_init(bis, &mdio_info); |
| 250 | |
| 251 | tsec_eth_init(bis, tsec_info, 3); |
| 252 | return pci_eth_init(bis); |
| 253 | } |
| 254 | |
| 255 | void ft_board_setup(void *blob, bd_t *bd) |
| 256 | { |
| 257 | phys_addr_t base; |
| 258 | phys_size_t size; |
| 259 | |
| 260 | ft_cpu_setup(blob, bd); |
| 261 | |
| 262 | base = getenv_bootm_low(); |
| 263 | size = getenv_bootm_size(); |
| 264 | |
| 265 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 266 | |
| 267 | FT_FSL_PCI_SETUP; |
| 268 | } |