1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Keymile AG
6 * Copyright 2013 Freescale Semiconductor, Inc.
10 #include <asm/cache.h>
11 #include <asm/fsl_fdt.h>
12 #include <asm/fsl_law.h>
13 #include <asm/fsl_liodn.h>
14 #include <asm/fsl_portals.h>
15 #include <asm/fsl_serdes.h>
16 #include <asm/immap_85xx.h>
18 #include <asm/processor.h>
19 #include <fdt_support.h>
23 #include <linux/compiler.h>
28 #include "../common/common.h"
29 #include "../common/qrio.h"
31 DECLARE_GLOBAL_DATA_PTR;
33 static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
37 printf("Board: Hitachi Power Grids kmcent2\n");
42 #define RSTRQSR1_WDT_RR 0x00200000
43 #define RSTRQSR1_SW_RR 0x00100000
45 int board_early_init_f(void)
47 struct fsl_ifc ifc = {(void *)CFG_SYS_IFC_ADDR, (void *)NULL};
48 ccsr_gur_t *gur = (void *)(CFG_SYS_MPC85xx_GUTS_ADDR);
49 bool cpuwd_flag = false;
51 /* board specific IFC configuration: increased bus turnaround time */
52 setbits_be32(&ifc.gregs->ifc_gcr, 8 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
54 /* configure mode for uP reset request */
55 qrio_uprstreq(UPREQ_CORE_RST);
57 /* board only uses the DDR_MCK0, so disable the DDR_MCK1 */
58 setbits_be32(&gur->ddrclkdr, 0x40000000);
60 /* set reset reason according CPU register */
61 if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
65 qrio_cpuwd_flag(cpuwd_flag);
66 /* clear CPU bits by writing 1 */
67 setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
69 /* configure PRST lines for the application: */
72 * reset at power-up and unit reset only and enable WD on it
74 qrio_prstcfg(KM_ETHSW_DDR_RST, PRSTCFG_POWUP_UNIT_RST);
75 qrio_wdmask(KM_ETHSW_DDR_RST, true);
78 * reset at power-up and unit reset only and enable WD on it
80 qrio_prstcfg(KM_XES_PHY_RST, PRSTCFG_POWUP_UNIT_RST);
81 qrio_wdmask(KM_XES_PHY_RST, true);
84 * reset at power-up and unit reset only and enable WD on it
86 qrio_prstcfg(KM_ES_PHY_RST, PRSTCFG_POWUP_UNIT_RST);
87 qrio_wdmask(KM_ES_PHY_RST, true);
90 * reset at power-up and unit reset only and enable WD on it
92 qrio_prstcfg(KM_EFE_RST, PRSTCFG_POWUP_UNIT_RST);
93 qrio_wdmask(KM_EFE_RST, true);
96 * reset at power-up and unit reset only and enable WD on it
98 qrio_prstcfg(KM_BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
99 qrio_wdmask(KM_BFTIC4_RST, true);
102 * reset at power-up and unit reset only and enable WD on it
104 qrio_prstcfg(KM_DPAXE_RST, PRSTCFG_POWUP_UNIT_RST);
105 qrio_wdmask(KM_DPAXE_RST, true);
108 * reset at power-up and unit reset only, deassert reset w/o WD
110 qrio_prstcfg(KM_PEXSW_RST, PRSTCFG_POWUP_UNIT_RST);
111 qrio_prst(KM_PEXSW_RST, false, false);
114 * reset at power-up and unit reset only, deassert reset w/o WD
116 qrio_prstcfg(KM_PEXSW_NT_RST, PRSTCFG_POWUP_UNIT_RST);
117 qrio_prst(KM_PEXSW_NT_RST, false, false);
120 * reset at power-up and unit reset only, deassert reset w/o WD
122 qrio_prstcfg(KM_BOBCAT_RST, PRSTCFG_POWUP_UNIT_RST);
123 qrio_prst(KM_BOBCAT_RST, false, false);
126 * reset at power-up and unit reset only and enable WD
128 qrio_prstcfg(KM_FEMT_RST, PRSTCFG_POWUP_UNIT_RST);
129 qrio_wdmask(KM_FEMT_RST, true);
132 * reset at power-up and unit reset only and enable WD
134 qrio_prstcfg(KM_FOAM_RST, PRSTCFG_POWUP_UNIT_RST);
135 qrio_wdmask(KM_FOAM_RST, true);
140 int board_early_init_r(void)
144 const unsigned int flashbase = CFG_SYS_FLASH_BASE;
145 int flash_esel = find_tlb_idx((void *)flashbase, 1);
148 * Remap Boot flash region to caching-inhibited
149 * so that flash can be erased properly.
152 /* Flush d-cache and invalidate i-cache of any FLASH data */
156 if (flash_esel == -1) {
157 /* very unlikely unless something is messed up */
158 puts("Error: Could not find TLB for FLASH BASE\n");
159 flash_esel = 2; /* give our best effort to continue */
161 /* invalidate existing TLB entry for flash */
162 disable_tlb(flash_esel);
165 set_tlb(1, flashbase, CFG_SYS_FLASH_BASE_PHYS,
166 MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
167 0, flash_esel, BOOKE_PAGESZ_256M, 1);
170 setup_qbman_portals();
174 /* enable Application Buffer */
175 qrio_enable_app_buffer();
180 unsigned long get_serial_clock(unsigned long dummy)
182 return (gd->bus_clk / 2);
185 static int kmcent2_misc_init_f(void)
187 /* configure QRIO pis for i2c deblocking */
188 i2c_deblock_gpio_cfg();
191 * CFE_RST (front phy):
192 * reset at power-up, unit and core reset, deasset reset w/o WD
194 qrio_prstcfg(KM_CFE_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
195 qrio_prst(KM_CFE_RST, false, false);
198 * ZL30158_RST (PTP clock generator):
199 * reset at power-up only, deassert reset and enable WD on it
201 qrio_prstcfg(KM_ZL30158_RST, PRSTCFG_POWUP_RST);
202 qrio_prst(KM_ZL30158_RST, false, false);
205 * ZL30364_RST (EEC generator):
206 * reset at power-up only, deassert reset and enable WD on it
208 qrio_prstcfg(KM_ZL30364_RST, PRSTCFG_POWUP_RST);
209 qrio_prst(KM_ZL30364_RST, false, false);
213 EVENT_SPY_SIMPLE(EVT_MISC_INIT_F, kmcent2_misc_init_f);
215 #define USED_SRDS_BANK 0
216 #define EXPECTED_SRDS_RFCK SRDS_PLLCR0_RFCK_SEL_100
218 #define BRG01_IOCLK12 0x02000000
219 #define EC2_GTX_CLK125 0x08000000
221 int misc_init_r(void)
223 serdes_corenet_t *regs = (void *)CFG_SYS_FSL_CORENET_SERDES_ADDR;
224 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CFG_SYS_MPC85xx_SCFG;
225 ccsr_gur_t __iomem *gur = (ccsr_gur_t __iomem *)CFG_SYS_MPC85xx_GUTS_ADDR;
227 /* check SERDES bank 0 reference clock */
228 u32 actual = in_be32(®s->bank[USED_SRDS_BANK].pllcr0);
230 if (actual & SRDS_PLLCR0_POFF)
231 printf("Warning: SERDES bank %u pll is off\n", USED_SRDS_BANK);
232 if ((actual & SRDS_PLLCR0_RFCK_SEL_MASK) != EXPECTED_SRDS_RFCK) {
233 printf("Warning: SERDES bank %u expects %sMHz clock, is %sMHz\n",
235 serdes_clock_to_string(EXPECTED_SRDS_RFCK),
236 serdes_clock_to_string(actual));
239 /* QE IO clk : BRG01 is used over clk12 for HDLC clk (20 MhZ) */
240 out_be32(&scfg->qeioclkcr,
241 in_be32(&scfg->qeioclkcr) | BRG01_IOCLK12);
243 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
244 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
246 /* Fix polarity of Card Detect and Write Protect */
247 out_be32(&gur->sdhcpcr, 0xFFFFFFFF);
250 * EC1 is disabled in our design, so we must explicitly set GTXCLKSEL
253 out_be32(&scfg->emiiocr, in_be32(&scfg->emiiocr) | EC2_GTX_CLK125);
258 int hush_init_var(void)
260 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
264 static int last_stage_init(void)
267 /* DIP switch support on BFTIC */
268 struct bfticu_iomap *bftic4 =
269 (struct bfticu_iomap *)SYS_BFTIC_BASE;
270 u8 dip_switch = in_8((u8 *)&bftic4->mswitch) & BFTICU_DIPSWITCH_MASK;
272 if (dip_switch != 0) {
273 /* start bootloader */
274 puts("DIP: Enabled\n");
275 env_set("actual_bank", "0");
281 * bootm_size is used to fixup the FDT memory node
282 * set it to kernelmem that has the same value
284 kmem = env_get("kernelmem");
286 env_set("bootm_size", kmem);
290 EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, last_stage_init);
292 void fdt_fixup_fman_mac_addresses(void *blob)
296 unsigned char mac_addr[6];
299 * Just the fm1-mac5 must be set by us, u-boot handle the 2 others,
300 * get the mac addr from env
302 if (!eth_env_get_enetaddr_by_index("eth", 4, mac_addr)) {
303 printf("eth4addr env variable not defined\n");
307 /* local management port */
308 strcpy(path, "/soc/fman/ethernet@e8000");
309 node = fdt_path_offset(blob, path);
311 printf("no %s\n", path);
315 ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
317 printf("%s\n\terror setting local-mac-address property\n",
322 int ft_board_setup(void *blob, struct bd_info *bd)
327 ft_cpu_setup(blob, bd);
329 base = env_get_bootm_low();
330 size = env_get_bootm_size();
332 fdt_fixup_memory(blob, (u64)base, (u64)size);
334 fdt_fixup_liodn(blob);
336 fdt_fixup_fman_mac_addresses(blob);
338 if (hwconfig("qe-tdm"))
343 /* DIC26_SELFTEST GPIO used to start factory test sw */
344 #define SELFTEST_PORT QRIO_GPIO_A
345 #define SELFTEST_PIN 0
347 int post_hotkeys_pressed(void)
349 qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
350 return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);