1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2016 Keymile AG
6 * Copyright 2013 Freescale Semiconductor, Inc.
10 #include <asm/fsl_fdt.h>
11 #include <asm/fsl_law.h>
12 #include <asm/fsl_liodn.h>
13 #include <asm/fsl_portals.h>
14 #include <asm/fsl_serdes.h>
15 #include <asm/immap_85xx.h>
17 #include <asm/processor.h>
18 #include <fdt_support.h>
22 #include <linux/compiler.h>
27 #include "../common/common.h"
28 #include "../common/qrio.h"
30 DECLARE_GLOBAL_DATA_PTR;
32 static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
36 printf("Board: Hitachi Power Grids %s\n", KM_BOARD_NAME);
41 #define RSTRQSR1_WDT_RR 0x00200000
42 #define RSTRQSR1_SW_RR 0x00100000
44 int board_early_init_f(void)
46 struct fsl_ifc ifc = {(void *)CONFIG_SYS_IFC_ADDR, (void *)NULL};
47 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
48 bool cpuwd_flag = false;
50 /* board specific IFC configuration: increased bus turnaround time */
51 setbits_be32(&ifc.gregs->ifc_gcr, 8 << IFC_GCR_TBCTL_TRN_TIME_SHIFT);
53 /* configure mode for uP reset request */
54 qrio_uprstreq(UPREQ_CORE_RST);
56 /* board only uses the DDR_MCK0, so disable the DDR_MCK1 */
57 setbits_be32(&gur->ddrclkdr, 0x40000000);
59 /* set reset reason according CPU register */
60 if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
64 qrio_cpuwd_flag(cpuwd_flag);
65 /* clear CPU bits by writing 1 */
66 setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
68 /* configure PRST lines for the application: */
71 * reset at power-up and unit reset only and enable WD on it
73 qrio_prstcfg(KM_ETHSW_DDR_RST, PRSTCFG_POWUP_UNIT_RST);
74 qrio_wdmask(KM_ETHSW_DDR_RST, true);
77 * reset at power-up and unit reset only and enable WD on it
79 qrio_prstcfg(KM_XES_PHY_RST, PRSTCFG_POWUP_UNIT_RST);
80 qrio_wdmask(KM_XES_PHY_RST, true);
83 * reset at power-up and unit reset only and enable WD on it
85 qrio_prstcfg(KM_ES_PHY_RST, PRSTCFG_POWUP_UNIT_RST);
86 qrio_wdmask(KM_ES_PHY_RST, true);
89 * reset at power-up and unit reset only and enable WD on it
91 qrio_prstcfg(KM_EFE_RST, PRSTCFG_POWUP_UNIT_RST);
92 qrio_wdmask(KM_EFE_RST, true);
95 * reset at power-up and unit reset only and enable WD on it
97 qrio_prstcfg(KM_BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
98 qrio_wdmask(KM_BFTIC4_RST, true);
101 * reset at power-up and unit reset only and enable WD on it
103 qrio_prstcfg(KM_DPAXE_RST, PRSTCFG_POWUP_UNIT_RST);
104 qrio_wdmask(KM_DPAXE_RST, true);
107 * reset at power-up and unit reset only, deassert reset w/o WD
109 qrio_prstcfg(KM_PEXSW_RST, PRSTCFG_POWUP_UNIT_RST);
110 qrio_prst(KM_PEXSW_RST, false, false);
113 * reset at power-up and unit reset only, deassert reset w/o WD
115 qrio_prstcfg(KM_PEXSW_NT_RST, PRSTCFG_POWUP_UNIT_RST);
116 qrio_prst(KM_PEXSW_NT_RST, false, false);
119 * reset at power-up and unit reset only, deassert reset w/o WD
121 qrio_prstcfg(KM_BOBCAT_RST, PRSTCFG_POWUP_UNIT_RST);
122 qrio_prst(KM_BOBCAT_RST, false, false);
125 * reset at power-up and unit reset only and enable WD
127 qrio_prstcfg(KM_FEMT_RST, PRSTCFG_POWUP_UNIT_RST);
128 qrio_wdmask(KM_FEMT_RST, true);
131 * reset at power-up and unit reset only and enable WD
133 qrio_prstcfg(KM_FOAM_RST, PRSTCFG_POWUP_UNIT_RST);
134 qrio_wdmask(KM_FOAM_RST, true);
139 int board_early_init_r(void)
143 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
144 int flash_esel = find_tlb_idx((void *)flashbase, 1);
147 * Remap Boot flash region to caching-inhibited
148 * so that flash can be erased properly.
151 /* Flush d-cache and invalidate i-cache of any FLASH data */
155 if (flash_esel == -1) {
156 /* very unlikely unless something is messed up */
157 puts("Error: Could not find TLB for FLASH BASE\n");
158 flash_esel = 2; /* give our best effort to continue */
160 /* invalidate existing TLB entry for flash */
161 disable_tlb(flash_esel);
164 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
165 MAS3_SX | MAS3_SW | MAS3_SR, MAS2_I | MAS2_G,
166 0, flash_esel, BOOKE_PAGESZ_256M, 1);
169 setup_qbman_portals();
173 /* enable Application Buffer */
174 qrio_enable_app_buffer();
179 unsigned long get_serial_clock(unsigned long dummy)
181 return (gd->bus_clk / 2);
184 int misc_init_f(void)
186 /* configure QRIO pis for i2c deblocking */
187 i2c_deblock_gpio_cfg();
190 * CFE_RST (front phy):
191 * reset at power-up, unit and core reset, deasset reset w/o WD
193 qrio_prstcfg(KM_CFE_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
194 qrio_prst(KM_CFE_RST, false, false);
197 * ZL30158_RST (PTP clock generator):
198 * reset at power-up only, deassert reset and enable WD on it
200 qrio_prstcfg(KM_ZL30158_RST, PRSTCFG_POWUP_RST);
201 qrio_prst(KM_ZL30158_RST, false, false);
204 * ZL30364_RST (EEC generator):
205 * reset at power-up only, deassert reset and enable WD on it
207 qrio_prstcfg(KM_ZL30364_RST, PRSTCFG_POWUP_RST);
208 qrio_prst(KM_ZL30364_RST, false, false);
213 #define USED_SRDS_BANK 0
214 #define EXPECTED_SRDS_RFCK SRDS_PLLCR0_RFCK_SEL_100
216 #define BRG01_IOCLK12 0x02000000
217 #define EC2_GTX_CLK125 0x08000000
219 int misc_init_r(void)
221 serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
222 struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_MPC85xx_SCFG;
223 ccsr_gur_t __iomem *gur = (ccsr_gur_t __iomem *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
225 /* check SERDES bank 0 reference clock */
226 u32 actual = in_be32(®s->bank[USED_SRDS_BANK].pllcr0);
228 if (actual & SRDS_PLLCR0_POFF)
229 printf("Warning: SERDES bank %u pll is off\n", USED_SRDS_BANK);
230 if ((actual & SRDS_PLLCR0_RFCK_SEL_MASK) != EXPECTED_SRDS_RFCK) {
231 printf("Warning: SERDES bank %u expects %sMHz clock, is %sMHz\n",
233 serdes_clock_to_string(EXPECTED_SRDS_RFCK),
234 serdes_clock_to_string(actual));
237 /* QE IO clk : BRG01 is used over clk12 for HDLC clk (20 MhZ) */
238 out_be32(&scfg->qeioclkcr,
239 in_be32(&scfg->qeioclkcr) | BRG01_IOCLK12);
241 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
242 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
244 /* Fix polarity of Card Detect and Write Protect */
245 out_be32(&gur->sdhcpcr, 0xFFFFFFFF);
248 * EC1 is disabled in our design, so we must explicitly set GTXCLKSEL
251 out_be32(&scfg->emiiocr, in_be32(&scfg->emiiocr) | EC2_GTX_CLK125);
256 int hush_init_var(void)
258 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
262 int last_stage_init(void)
265 /* DIP switch support on BFTIC */
266 struct bfticu_iomap *bftic4 =
267 (struct bfticu_iomap *)SYS_BFTIC_BASE;
268 u8 dip_switch = in_8((u8 *)&bftic4->mswitch) & BFTICU_DIPSWITCH_MASK;
270 if (dip_switch != 0) {
271 /* start bootloader */
272 puts("DIP: Enabled\n");
273 env_set("actual_bank", "0");
279 * bootm_size is used to fixup the FDT memory node
280 * set it to kernelmem that has the same value
282 kmem = env_get("kernelmem");
284 env_set("bootm_size", kmem);
289 void fdt_fixup_fman_mac_addresses(void *blob)
293 unsigned char mac_addr[6];
296 * Just the fm1-mac5 must be set by us, u-boot handle the 2 others,
297 * get the mac addr from env
299 if (!eth_env_get_enetaddr_by_index("eth", 4, mac_addr)) {
300 printf("eth4addr env variable not defined\n");
304 /* local management port */
305 strcpy(path, "/soc/fman/ethernet@e8000");
306 node = fdt_path_offset(blob, path);
308 printf("no %s\n", path);
312 ret = fdt_setprop(blob, node, "local-mac-address", mac_addr, 6);
314 printf("%s\n\terror setting local-mac-address property\n",
319 int ft_board_setup(void *blob, struct bd_info *bd)
324 ft_cpu_setup(blob, bd);
326 base = env_get_bootm_low();
327 size = env_get_bootm_size();
329 fdt_fixup_memory(blob, (u64)base, (u64)size);
331 fdt_fixup_liodn(blob);
333 fdt_fixup_fman_mac_addresses(blob);
335 if (hwconfig("qe-tdm"))
340 /* DIC26_SELFTEST GPIO used to start factory test sw */
341 #define SELFTEST_PORT QRIO_GPIO_A
342 #define SELFTEST_PIN 0
344 int post_hotkeys_pressed(void)
346 qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
347 return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);