Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2013 Keymile AG |
| 4 | * Valentin Longchamp <valentin.longchamp@keymile.com> |
| 5 | * |
| 6 | * Copyright 2011,2012 Freescale Semiconductor, Inc. |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <command.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 12 | #include <fdt_support.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <image.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 14 | #include <init.h> |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 15 | #include <netdev.h> |
| 16 | #include <linux/compiler.h> |
| 17 | #include <asm/mmu.h> |
| 18 | #include <asm/processor.h> |
| 19 | #include <asm/cache.h> |
| 20 | #include <asm/immap_85xx.h> |
| 21 | #include <asm/fsl_law.h> |
| 22 | #include <asm/fsl_serdes.h> |
| 23 | #include <asm/fsl_portals.h> |
| 24 | #include <asm/fsl_liodn.h> |
| 25 | #include <fm_eth.h> |
| 26 | |
| 27 | #include "../common/common.h" |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 28 | #include "../common/qrio.h" |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 29 | #include "kmp204x.h" |
| 30 | |
Valentin Longchamp | 14039f8 | 2015-02-10 17:10:15 +0100 | [diff] [blame] | 31 | static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN]; |
| 32 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 33 | int checkboard(void) |
| 34 | { |
Holger Brunck | b3d5f19 | 2019-11-26 19:09:02 +0100 | [diff] [blame] | 35 | printf("Board: Keymile %s\n", CONFIG_SYS_CONFIG_NAME); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 36 | |
| 37 | return 0; |
| 38 | } |
| 39 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 40 | #define ZL30158_RST 8 |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 41 | #define BFTIC4_RST 0 |
Boschung, Rainer | 59a31c9 | 2014-06-03 09:05:18 +0200 | [diff] [blame] | 42 | #define RSTRQSR1_WDT_RR 0x00200000 |
| 43 | #define RSTRQSR1_SW_RR 0x00100000 |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 44 | |
| 45 | int board_early_init_f(void) |
| 46 | { |
| 47 | ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR); |
Boschung, Rainer | 59a31c9 | 2014-06-03 09:05:18 +0200 | [diff] [blame] | 48 | bool cpuwd_flag = false; |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 49 | |
Boschung, Rainer | 6e093fc | 2014-06-03 09:05:20 +0200 | [diff] [blame] | 50 | /* configure mode for uP reset request */ |
| 51 | qrio_uprstreq(UPREQ_CORE_RST); |
| 52 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 53 | /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */ |
| 54 | setbits_be32(&gur->ddrclkdr, 0x001f000f); |
| 55 | |
Boschung, Rainer | 59a31c9 | 2014-06-03 09:05:18 +0200 | [diff] [blame] | 56 | /* set reset reason according CPU register */ |
| 57 | if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) == |
| 58 | RSTRQSR1_WDT_RR) |
| 59 | cpuwd_flag = true; |
| 60 | |
| 61 | qrio_cpuwd_flag(cpuwd_flag); |
| 62 | /* clear CPU bits by writing 1 */ |
| 63 | setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR); |
| 64 | |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 65 | /* set the BFTIC's prstcfg to reset at power-up and unit reset only */ |
| 66 | qrio_prstcfg(BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST); |
| 67 | /* and enable WD on it */ |
| 68 | qrio_wdmask(BFTIC4_RST, true); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 69 | |
Valentin Longchamp | 2b29303 | 2014-08-19 15:40:04 +0200 | [diff] [blame] | 70 | /* set the ZL30138's prstcfg to reset at power-up only */ |
| 71 | qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_RST); |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 72 | /* and take it out of reset as soon as possible (needed for Hooper) */ |
| 73 | qrio_prst(ZL30158_RST, false, false); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 74 | |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | int board_early_init_r(void) |
| 79 | { |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 80 | int ret = 0; |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 81 | /* Flush d-cache and invalidate i-cache of any FLASH data */ |
| 82 | flush_dcache(); |
| 83 | invalidate_icache(); |
| 84 | |
| 85 | set_liodns(); |
Ahmed Mansour | aa270b4 | 2017-12-15 16:01:00 -0500 | [diff] [blame] | 86 | setup_qbman_portals(); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 87 | |
Valentin Longchamp | dc146da | 2014-01-27 11:49:12 +0100 | [diff] [blame] | 88 | ret = trigger_fpga_config(); |
| 89 | if (ret) |
| 90 | printf("error triggering PCIe FPGA config\n"); |
| 91 | |
Stefan Bigler | 8b6f6c3 | 2014-05-02 10:48:41 +0200 | [diff] [blame] | 92 | /* enable the Unit LED (red) & Boot LED (on) */ |
| 93 | qrio_set_leds(); |
| 94 | |
Stefan Bigler | dafc72d | 2014-05-02 10:49:27 +0200 | [diff] [blame] | 95 | /* enable Application Buffer */ |
| 96 | qrio_enable_app_buffer(); |
| 97 | |
Holger Brunck | 67d1602 | 2020-01-10 12:47:41 +0100 | [diff] [blame] | 98 | return 0; |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | unsigned long get_board_sys_clk(unsigned long dummy) |
| 102 | { |
| 103 | return 66666666; |
| 104 | } |
| 105 | |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 106 | #define ETH_FRONT_PHY_RST 15 |
| 107 | #define QSFP2_RST 11 |
| 108 | #define QSFP1_RST 10 |
| 109 | #define ZL30343_RST 9 |
| 110 | |
Rainer Boschung | 71a2e82 | 2014-02-03 08:45:40 +0100 | [diff] [blame] | 111 | int misc_init_f(void) |
| 112 | { |
| 113 | /* configure QRIO pis for i2c deblocking */ |
| 114 | i2c_deblock_gpio_cfg(); |
| 115 | |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 116 | /* configure the front phy's prstcfg and take it out of reset */ |
| 117 | qrio_prstcfg(ETH_FRONT_PHY_RST, PRSTCFG_POWUP_UNIT_CORE_RST); |
| 118 | qrio_prst(ETH_FRONT_PHY_RST, false, false); |
| 119 | |
Valentin Longchamp | 2b29303 | 2014-08-19 15:40:04 +0200 | [diff] [blame] | 120 | /* set the ZL30343 prstcfg to reset at power-up only */ |
| 121 | qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_RST); |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 122 | /* and enable the WD on it */ |
| 123 | qrio_wdmask(ZL30343_RST, true); |
| 124 | |
| 125 | /* set the QSFPs' prstcfg to reset at power-up and unit rst only */ |
| 126 | qrio_prstcfg(QSFP1_RST, PRSTCFG_POWUP_UNIT_RST); |
| 127 | qrio_prstcfg(QSFP2_RST, PRSTCFG_POWUP_UNIT_RST); |
| 128 | |
| 129 | /* and enable the WD on them */ |
| 130 | qrio_wdmask(QSFP1_RST, true); |
| 131 | qrio_wdmask(QSFP2_RST, true); |
| 132 | |
Rainer Boschung | 71a2e82 | 2014-02-03 08:45:40 +0100 | [diff] [blame] | 133 | return 0; |
| 134 | } |
| 135 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 136 | #define NUM_SRDS_BANKS 2 |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 137 | |
| 138 | int misc_init_r(void) |
| 139 | { |
| 140 | serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR; |
| 141 | u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100, |
| 142 | SRDS_PLLCR0_RFCK_SEL_125}; |
| 143 | unsigned int i; |
| 144 | |
| 145 | /* check SERDES reference clocks */ |
| 146 | for (i = 0; i < NUM_SRDS_BANKS; i++) { |
| 147 | u32 actual = in_be32(®s->bank[i].pllcr0); |
| 148 | actual &= SRDS_PLLCR0_RFCK_SEL_MASK; |
| 149 | if (actual != expected[i]) { |
| 150 | printf("Warning: SERDES bank %u expects reference \ |
| 151 | clock %sMHz, but actual is %sMHz\n", i + 1, |
| 152 | serdes_clock_to_string(expected[i]), |
| 153 | serdes_clock_to_string(actual)); |
| 154 | } |
| 155 | } |
| 156 | |
Holger Brunck | 0340b6a | 2019-11-25 17:24:14 +0100 | [diff] [blame] | 157 | ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN, |
| 158 | CONFIG_PIGGY_MAC_ADDRESS_OFFSET); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | #if defined(CONFIG_HUSH_INIT_VAR) |
| 163 | int hush_init_var(void) |
| 164 | { |
Valentin Longchamp | 14039f8 | 2015-02-10 17:10:15 +0100 | [diff] [blame] | 165 | ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | #endif |
| 169 | |
| 170 | #if defined(CONFIG_LAST_STAGE_INIT) |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 171 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 172 | int last_stage_init(void) |
| 173 | { |
Stefan Bigler | dafc72d | 2014-05-02 10:49:27 +0200 | [diff] [blame] | 174 | #if defined(CONFIG_KMCOGE4) |
| 175 | /* on KMCOGE4, the BFTIC4 is on the LBAPP2 */ |
| 176 | struct bfticu_iomap *bftic4 = |
| 177 | (struct bfticu_iomap *)CONFIG_SYS_LBAPP2_BASE; |
| 178 | u8 dip_switch = in_8((u8 *)&(bftic4->mswitch)) & BFTICU_DIPSWITCH_MASK; |
| 179 | |
| 180 | if (dip_switch != 0) { |
| 181 | /* start bootloader */ |
| 182 | puts("DIP: Enabled\n"); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 183 | env_set("actual_bank", "0"); |
Stefan Bigler | dafc72d | 2014-05-02 10:49:27 +0200 | [diff] [blame] | 184 | } |
| 185 | #endif |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 186 | set_km_env(); |
Valentin Longchamp | 5eb9dab | 2014-04-30 15:01:46 +0200 | [diff] [blame] | 187 | |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | #endif |
| 191 | |
| 192 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 193 | void fdt_fixup_fman_mac_addresses(void *blob) |
| 194 | { |
| 195 | int node, i, ret; |
| 196 | char *tmp, *end; |
| 197 | unsigned char mac_addr[6]; |
| 198 | |
| 199 | /* get the mac addr from env */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 200 | tmp = env_get("ethaddr"); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 201 | if (!tmp) { |
| 202 | printf("ethaddr env variable not defined\n"); |
| 203 | return; |
| 204 | } |
| 205 | for (i = 0; i < 6; i++) { |
| 206 | mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0; |
| 207 | if (tmp) |
| 208 | tmp = (*end) ? end+1 : end; |
| 209 | } |
| 210 | |
| 211 | /* find the correct fdt ethernet path and correct it */ |
| 212 | node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000"); |
| 213 | if (node < 0) { |
| 214 | printf("no /soc/fman/ethernet path offset\n"); |
| 215 | return; |
| 216 | } |
| 217 | ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6); |
| 218 | if (ret) { |
| 219 | printf("error setting local-mac-address property\n"); |
| 220 | return; |
| 221 | } |
| 222 | } |
| 223 | #endif |
| 224 | |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 225 | int ft_board_setup(void *blob, struct bd_info *bd) |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 226 | { |
| 227 | phys_addr_t base; |
| 228 | phys_size_t size; |
| 229 | |
| 230 | ft_cpu_setup(blob, bd); |
| 231 | |
Simon Glass | da1a134 | 2017-08-03 12:22:15 -0600 | [diff] [blame] | 232 | base = env_get_bootm_low(); |
| 233 | size = env_get_bootm_size(); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 234 | |
| 235 | fdt_fixup_memory(blob, (u64)base, (u64)size); |
| 236 | |
| 237 | #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB) |
Sriram Dash | 9fd465c | 2016-09-16 17:12:15 +0530 | [diff] [blame] | 238 | fsl_fdt_fixup_dr_usb(blob, bd); |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 239 | #endif |
| 240 | |
| 241 | #ifdef CONFIG_PCI |
| 242 | pci_of_setup(blob, bd); |
| 243 | #endif |
| 244 | |
| 245 | fdt_fixup_liodn(blob); |
| 246 | #ifdef CONFIG_SYS_DPAA_FMAN |
| 247 | fdt_fixup_fman_ethernet(blob); |
| 248 | fdt_fixup_fman_mac_addresses(blob); |
| 249 | #endif |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 250 | |
| 251 | return 0; |
Valentin Longchamp | c98bf29 | 2013-10-18 11:47:24 +0200 | [diff] [blame] | 252 | } |
Valentin Longchamp | ec92cdb | 2014-04-30 15:01:44 +0200 | [diff] [blame] | 253 | |
| 254 | #if defined(CONFIG_POST) |
| 255 | |
| 256 | /* DIC26_SELFTEST GPIO used to start factory test sw */ |
Holger Brunck | 9562687 | 2020-01-10 12:47:42 +0100 | [diff] [blame] | 257 | #define SELFTEST_PORT QRIO_GPIO_A |
Valentin Longchamp | ec92cdb | 2014-04-30 15:01:44 +0200 | [diff] [blame] | 258 | #define SELFTEST_PIN 31 |
| 259 | |
| 260 | int post_hotkeys_pressed(void) |
| 261 | { |
| 262 | qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN); |
| 263 | return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN); |
| 264 | } |
| 265 | #endif |