blob: 0a6cf1fd29a06e096aba336a9c188d3f0498a575 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Valentin Longchampc98bf292013-10-18 11:47:24 +02002/*
3 * (C) Copyright 2013 Keymile AG
4 * Valentin Longchamp <valentin.longchamp@keymile.com>
5 *
6 * Copyright 2011,2012 Freescale Semiconductor, Inc.
Valentin Longchampc98bf292013-10-18 11:47:24 +02007 */
8
9#include <common.h>
10#include <command.h>
Simon Glass5e6201b2019-08-01 09:46:51 -060011#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070012#include <fdt_support.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Valentin Longchampc98bf292013-10-18 11:47:24 +020014#include <netdev.h>
15#include <linux/compiler.h>
16#include <asm/mmu.h>
17#include <asm/processor.h>
18#include <asm/cache.h>
19#include <asm/immap_85xx.h>
20#include <asm/fsl_law.h>
21#include <asm/fsl_serdes.h>
22#include <asm/fsl_portals.h>
23#include <asm/fsl_liodn.h>
24#include <fm_eth.h>
25
26#include "../common/common.h"
Holger Brunck95626872020-01-10 12:47:42 +010027#include "../common/qrio.h"
Valentin Longchampc98bf292013-10-18 11:47:24 +020028#include "kmp204x.h"
29
Valentin Longchamp14039f82015-02-10 17:10:15 +010030static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
31
Valentin Longchampc98bf292013-10-18 11:47:24 +020032int checkboard(void)
33{
Holger Brunckb3d5f192019-11-26 19:09:02 +010034 printf("Board: Keymile %s\n", CONFIG_SYS_CONFIG_NAME);
Valentin Longchampc98bf292013-10-18 11:47:24 +020035
36 return 0;
37}
38
Valentin Longchampc98bf292013-10-18 11:47:24 +020039#define ZL30158_RST 8
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +020040#define BFTIC4_RST 0
Boschung, Rainer59a31c92014-06-03 09:05:18 +020041#define RSTRQSR1_WDT_RR 0x00200000
42#define RSTRQSR1_SW_RR 0x00100000
Valentin Longchampc98bf292013-10-18 11:47:24 +020043
44int board_early_init_f(void)
45{
46 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Boschung, Rainer59a31c92014-06-03 09:05:18 +020047 bool cpuwd_flag = false;
Valentin Longchampc98bf292013-10-18 11:47:24 +020048
Boschung, Rainer6e093fc2014-06-03 09:05:20 +020049 /* configure mode for uP reset request */
50 qrio_uprstreq(UPREQ_CORE_RST);
51
Valentin Longchampc98bf292013-10-18 11:47:24 +020052 /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */
53 setbits_be32(&gur->ddrclkdr, 0x001f000f);
54
Boschung, Rainer59a31c92014-06-03 09:05:18 +020055 /* set reset reason according CPU register */
56 if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
57 RSTRQSR1_WDT_RR)
58 cpuwd_flag = true;
59
60 qrio_cpuwd_flag(cpuwd_flag);
61 /* clear CPU bits by writing 1 */
62 setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
63
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +020064 /* set the BFTIC's prstcfg to reset at power-up and unit reset only */
65 qrio_prstcfg(BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
66 /* and enable WD on it */
67 qrio_wdmask(BFTIC4_RST, true);
Valentin Longchampc98bf292013-10-18 11:47:24 +020068
Valentin Longchamp2b293032014-08-19 15:40:04 +020069 /* set the ZL30138's prstcfg to reset at power-up only */
70 qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_RST);
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +020071 /* and take it out of reset as soon as possible (needed for Hooper) */
72 qrio_prst(ZL30158_RST, false, false);
Valentin Longchampc98bf292013-10-18 11:47:24 +020073
74 return 0;
75}
76
77int board_early_init_r(void)
78{
Valentin Longchampdc146da2014-01-27 11:49:12 +010079 int ret = 0;
Valentin Longchampc98bf292013-10-18 11:47:24 +020080 /* Flush d-cache and invalidate i-cache of any FLASH data */
81 flush_dcache();
82 invalidate_icache();
83
84 set_liodns();
Ahmed Mansouraa270b42017-12-15 16:01:00 -050085 setup_qbman_portals();
Valentin Longchampc98bf292013-10-18 11:47:24 +020086
Valentin Longchampdc146da2014-01-27 11:49:12 +010087 ret = trigger_fpga_config();
88 if (ret)
89 printf("error triggering PCIe FPGA config\n");
90
Stefan Bigler8b6f6c32014-05-02 10:48:41 +020091 /* enable the Unit LED (red) & Boot LED (on) */
92 qrio_set_leds();
93
Stefan Biglerdafc72d2014-05-02 10:49:27 +020094 /* enable Application Buffer */
95 qrio_enable_app_buffer();
96
Holger Brunck67d16022020-01-10 12:47:41 +010097 return 0;
Valentin Longchampc98bf292013-10-18 11:47:24 +020098}
99
100unsigned long get_board_sys_clk(unsigned long dummy)
101{
102 return 66666666;
103}
104
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200105#define ETH_FRONT_PHY_RST 15
106#define QSFP2_RST 11
107#define QSFP1_RST 10
108#define ZL30343_RST 9
109
Rainer Boschung71a2e822014-02-03 08:45:40 +0100110int misc_init_f(void)
111{
112 /* configure QRIO pis for i2c deblocking */
113 i2c_deblock_gpio_cfg();
114
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200115 /* configure the front phy's prstcfg and take it out of reset */
116 qrio_prstcfg(ETH_FRONT_PHY_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
117 qrio_prst(ETH_FRONT_PHY_RST, false, false);
118
Valentin Longchamp2b293032014-08-19 15:40:04 +0200119 /* set the ZL30343 prstcfg to reset at power-up only */
120 qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_RST);
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200121 /* and enable the WD on it */
122 qrio_wdmask(ZL30343_RST, true);
123
124 /* set the QSFPs' prstcfg to reset at power-up and unit rst only */
125 qrio_prstcfg(QSFP1_RST, PRSTCFG_POWUP_UNIT_RST);
126 qrio_prstcfg(QSFP2_RST, PRSTCFG_POWUP_UNIT_RST);
127
128 /* and enable the WD on them */
129 qrio_wdmask(QSFP1_RST, true);
130 qrio_wdmask(QSFP2_RST, true);
131
Rainer Boschung71a2e822014-02-03 08:45:40 +0100132 return 0;
133}
134
Valentin Longchampc98bf292013-10-18 11:47:24 +0200135#define NUM_SRDS_BANKS 2
Valentin Longchampc98bf292013-10-18 11:47:24 +0200136
137int misc_init_r(void)
138{
139 serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
140 u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100,
141 SRDS_PLLCR0_RFCK_SEL_125};
142 unsigned int i;
143
144 /* check SERDES reference clocks */
145 for (i = 0; i < NUM_SRDS_BANKS; i++) {
146 u32 actual = in_be32(&regs->bank[i].pllcr0);
147 actual &= SRDS_PLLCR0_RFCK_SEL_MASK;
148 if (actual != expected[i]) {
149 printf("Warning: SERDES bank %u expects reference \
150 clock %sMHz, but actual is %sMHz\n", i + 1,
151 serdes_clock_to_string(expected[i]),
152 serdes_clock_to_string(actual));
153 }
154 }
155
Holger Brunck0340b6a2019-11-25 17:24:14 +0100156 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
157 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200158 return 0;
159}
160
161#if defined(CONFIG_HUSH_INIT_VAR)
162int hush_init_var(void)
163{
Valentin Longchamp14039f82015-02-10 17:10:15 +0100164 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200165 return 0;
166}
167#endif
168
169#if defined(CONFIG_LAST_STAGE_INIT)
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200170
Valentin Longchampc98bf292013-10-18 11:47:24 +0200171int last_stage_init(void)
172{
Stefan Biglerdafc72d2014-05-02 10:49:27 +0200173#if defined(CONFIG_KMCOGE4)
174 /* on KMCOGE4, the BFTIC4 is on the LBAPP2 */
175 struct bfticu_iomap *bftic4 =
176 (struct bfticu_iomap *)CONFIG_SYS_LBAPP2_BASE;
177 u8 dip_switch = in_8((u8 *)&(bftic4->mswitch)) & BFTICU_DIPSWITCH_MASK;
178
179 if (dip_switch != 0) {
180 /* start bootloader */
181 puts("DIP: Enabled\n");
Simon Glass6a38e412017-08-03 12:22:09 -0600182 env_set("actual_bank", "0");
Stefan Biglerdafc72d2014-05-02 10:49:27 +0200183 }
184#endif
Valentin Longchampc98bf292013-10-18 11:47:24 +0200185 set_km_env();
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200186
Valentin Longchampc98bf292013-10-18 11:47:24 +0200187 return 0;
188}
189#endif
190
191#ifdef CONFIG_SYS_DPAA_FMAN
192void fdt_fixup_fman_mac_addresses(void *blob)
193{
194 int node, i, ret;
195 char *tmp, *end;
196 unsigned char mac_addr[6];
197
198 /* get the mac addr from env */
Simon Glass64b723f2017-08-03 12:22:12 -0600199 tmp = env_get("ethaddr");
Valentin Longchampc98bf292013-10-18 11:47:24 +0200200 if (!tmp) {
201 printf("ethaddr env variable not defined\n");
202 return;
203 }
204 for (i = 0; i < 6; i++) {
205 mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
206 if (tmp)
207 tmp = (*end) ? end+1 : end;
208 }
209
210 /* find the correct fdt ethernet path and correct it */
211 node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000");
212 if (node < 0) {
213 printf("no /soc/fman/ethernet path offset\n");
214 return;
215 }
216 ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6);
217 if (ret) {
218 printf("error setting local-mac-address property\n");
219 return;
220 }
221}
222#endif
223
Simon Glass2aec3cc2014-10-23 18:58:47 -0600224int ft_board_setup(void *blob, bd_t *bd)
Valentin Longchampc98bf292013-10-18 11:47:24 +0200225{
226 phys_addr_t base;
227 phys_size_t size;
228
229 ft_cpu_setup(blob, bd);
230
Simon Glassda1a1342017-08-03 12:22:15 -0600231 base = env_get_bootm_low();
232 size = env_get_bootm_size();
Valentin Longchampc98bf292013-10-18 11:47:24 +0200233
234 fdt_fixup_memory(blob, (u64)base, (u64)size);
235
236#if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530237 fsl_fdt_fixup_dr_usb(blob, bd);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200238#endif
239
240#ifdef CONFIG_PCI
241 pci_of_setup(blob, bd);
242#endif
243
244 fdt_fixup_liodn(blob);
245#ifdef CONFIG_SYS_DPAA_FMAN
246 fdt_fixup_fman_ethernet(blob);
247 fdt_fixup_fman_mac_addresses(blob);
248#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600249
250 return 0;
Valentin Longchampc98bf292013-10-18 11:47:24 +0200251}
Valentin Longchampec92cdb2014-04-30 15:01:44 +0200252
253#if defined(CONFIG_POST)
254
255/* DIC26_SELFTEST GPIO used to start factory test sw */
Holger Brunck95626872020-01-10 12:47:42 +0100256#define SELFTEST_PORT QRIO_GPIO_A
Valentin Longchampec92cdb2014-04-30 15:01:44 +0200257#define SELFTEST_PIN 31
258
259int post_hotkeys_pressed(void)
260{
261 qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
262 return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);
263}
264#endif