blob: cfb23a53f7458275f5cc829bc90a0c3d809d8063 [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"
27#include "kmp204x.h"
28
Valentin Longchamp14039f82015-02-10 17:10:15 +010029static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
30
Valentin Longchampc98bf292013-10-18 11:47:24 +020031int checkboard(void)
32{
Holger Brunckb3d5f192019-11-26 19:09:02 +010033 printf("Board: Keymile %s\n", CONFIG_SYS_CONFIG_NAME);
Valentin Longchampc98bf292013-10-18 11:47:24 +020034
35 return 0;
36}
37
Rainer Boschung71a2e822014-02-03 08:45:40 +010038/* I2C deblocking uses the algorithm defined in board/keymile/common/common.c
39 * 2 dedicated QRIO GPIOs externally pull the SCL and SDA lines
40 * For I2C only the low state is activly driven and high state is pulled-up
41 * by a resistor. Therefore the deblock GPIOs are used
42 * -> as an active output to drive a low state
43 * -> as an open-drain input to have a pulled-up high state
44 */
45
46/* QRIO GPIOs used for deblocking */
47#define DEBLOCK_PORT1 GPIO_A
48#define DEBLOCK_SCL1 20
49#define DEBLOCK_SDA1 21
50
51/* By default deblock GPIOs are floating */
52static void i2c_deblock_gpio_cfg(void)
53{
54 /* set I2C bus 1 deblocking GPIOs input, but 0 value for open drain */
55 qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SCL1);
56 qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SDA1);
57
58 qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, 0);
59 qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, 0);
60}
61
62void set_sda(int state)
Valentin Longchampc98bf292013-10-18 11:47:24 +020063{
Rainer Boschung71a2e822014-02-03 08:45:40 +010064 qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, state);
Valentin Longchampc98bf292013-10-18 11:47:24 +020065}
66
Rainer Boschung71a2e822014-02-03 08:45:40 +010067void set_scl(int state)
68{
69 qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, state);
70}
71
72int get_sda(void)
73{
74 return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1);
75}
76
77int get_scl(void)
78{
79 return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1);
80}
81
82
Valentin Longchampc98bf292013-10-18 11:47:24 +020083#define ZL30158_RST 8
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +020084#define BFTIC4_RST 0
Boschung, Rainer59a31c92014-06-03 09:05:18 +020085#define RSTRQSR1_WDT_RR 0x00200000
86#define RSTRQSR1_SW_RR 0x00100000
Valentin Longchampc98bf292013-10-18 11:47:24 +020087
88int board_early_init_f(void)
89{
90 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
Boschung, Rainer59a31c92014-06-03 09:05:18 +020091 bool cpuwd_flag = false;
Valentin Longchampc98bf292013-10-18 11:47:24 +020092
Boschung, Rainer6e093fc2014-06-03 09:05:20 +020093 /* configure mode for uP reset request */
94 qrio_uprstreq(UPREQ_CORE_RST);
95
Valentin Longchampc98bf292013-10-18 11:47:24 +020096 /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */
97 setbits_be32(&gur->ddrclkdr, 0x001f000f);
98
Boschung, Rainer59a31c92014-06-03 09:05:18 +020099 /* set reset reason according CPU register */
100 if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
101 RSTRQSR1_WDT_RR)
102 cpuwd_flag = true;
103
104 qrio_cpuwd_flag(cpuwd_flag);
105 /* clear CPU bits by writing 1 */
106 setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
107
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200108 /* set the BFTIC's prstcfg to reset at power-up and unit reset only */
109 qrio_prstcfg(BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
110 /* and enable WD on it */
111 qrio_wdmask(BFTIC4_RST, true);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200112
Valentin Longchamp2b293032014-08-19 15:40:04 +0200113 /* set the ZL30138's prstcfg to reset at power-up only */
114 qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_RST);
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200115 /* and take it out of reset as soon as possible (needed for Hooper) */
116 qrio_prst(ZL30158_RST, false, false);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200117
118 return 0;
119}
120
121int board_early_init_r(void)
122{
Valentin Longchampdc146da2014-01-27 11:49:12 +0100123 int ret = 0;
Valentin Longchampc98bf292013-10-18 11:47:24 +0200124 /* Flush d-cache and invalidate i-cache of any FLASH data */
125 flush_dcache();
126 invalidate_icache();
127
128 set_liodns();
Ahmed Mansouraa270b42017-12-15 16:01:00 -0500129 setup_qbman_portals();
Valentin Longchampc98bf292013-10-18 11:47:24 +0200130
Valentin Longchampdc146da2014-01-27 11:49:12 +0100131 ret = trigger_fpga_config();
132 if (ret)
133 printf("error triggering PCIe FPGA config\n");
134
Stefan Bigler8b6f6c32014-05-02 10:48:41 +0200135 /* enable the Unit LED (red) & Boot LED (on) */
136 qrio_set_leds();
137
Stefan Biglerdafc72d2014-05-02 10:49:27 +0200138 /* enable Application Buffer */
139 qrio_enable_app_buffer();
140
Valentin Longchampdc146da2014-01-27 11:49:12 +0100141 return ret;
Valentin Longchampc98bf292013-10-18 11:47:24 +0200142}
143
144unsigned long get_board_sys_clk(unsigned long dummy)
145{
146 return 66666666;
147}
148
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200149#define ETH_FRONT_PHY_RST 15
150#define QSFP2_RST 11
151#define QSFP1_RST 10
152#define ZL30343_RST 9
153
Rainer Boschung71a2e822014-02-03 08:45:40 +0100154int misc_init_f(void)
155{
156 /* configure QRIO pis for i2c deblocking */
157 i2c_deblock_gpio_cfg();
158
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200159 /* configure the front phy's prstcfg and take it out of reset */
160 qrio_prstcfg(ETH_FRONT_PHY_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
161 qrio_prst(ETH_FRONT_PHY_RST, false, false);
162
Valentin Longchamp2b293032014-08-19 15:40:04 +0200163 /* set the ZL30343 prstcfg to reset at power-up only */
164 qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_RST);
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200165 /* and enable the WD on it */
166 qrio_wdmask(ZL30343_RST, true);
167
168 /* set the QSFPs' prstcfg to reset at power-up and unit rst only */
169 qrio_prstcfg(QSFP1_RST, PRSTCFG_POWUP_UNIT_RST);
170 qrio_prstcfg(QSFP2_RST, PRSTCFG_POWUP_UNIT_RST);
171
172 /* and enable the WD on them */
173 qrio_wdmask(QSFP1_RST, true);
174 qrio_wdmask(QSFP2_RST, true);
175
Rainer Boschung71a2e822014-02-03 08:45:40 +0100176 return 0;
177}
178
Valentin Longchampc98bf292013-10-18 11:47:24 +0200179#define NUM_SRDS_BANKS 2
Valentin Longchampc98bf292013-10-18 11:47:24 +0200180
181int misc_init_r(void)
182{
183 serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
184 u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100,
185 SRDS_PLLCR0_RFCK_SEL_125};
186 unsigned int i;
187
188 /* check SERDES reference clocks */
189 for (i = 0; i < NUM_SRDS_BANKS; i++) {
190 u32 actual = in_be32(&regs->bank[i].pllcr0);
191 actual &= SRDS_PLLCR0_RFCK_SEL_MASK;
192 if (actual != expected[i]) {
193 printf("Warning: SERDES bank %u expects reference \
194 clock %sMHz, but actual is %sMHz\n", i + 1,
195 serdes_clock_to_string(expected[i]),
196 serdes_clock_to_string(actual));
197 }
198 }
199
Holger Brunck0340b6a2019-11-25 17:24:14 +0100200 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
201 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200202 return 0;
203}
204
205#if defined(CONFIG_HUSH_INIT_VAR)
206int hush_init_var(void)
207{
Valentin Longchamp14039f82015-02-10 17:10:15 +0100208 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200209 return 0;
210}
211#endif
212
213#if defined(CONFIG_LAST_STAGE_INIT)
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200214
Valentin Longchampc98bf292013-10-18 11:47:24 +0200215int last_stage_init(void)
216{
Stefan Biglerdafc72d2014-05-02 10:49:27 +0200217#if defined(CONFIG_KMCOGE4)
218 /* on KMCOGE4, the BFTIC4 is on the LBAPP2 */
219 struct bfticu_iomap *bftic4 =
220 (struct bfticu_iomap *)CONFIG_SYS_LBAPP2_BASE;
221 u8 dip_switch = in_8((u8 *)&(bftic4->mswitch)) & BFTICU_DIPSWITCH_MASK;
222
223 if (dip_switch != 0) {
224 /* start bootloader */
225 puts("DIP: Enabled\n");
Simon Glass6a38e412017-08-03 12:22:09 -0600226 env_set("actual_bank", "0");
Stefan Biglerdafc72d2014-05-02 10:49:27 +0200227 }
228#endif
Valentin Longchampc98bf292013-10-18 11:47:24 +0200229 set_km_env();
Valentin Longchamp5eb9dab2014-04-30 15:01:46 +0200230
Valentin Longchampc98bf292013-10-18 11:47:24 +0200231 return 0;
232}
233#endif
234
235#ifdef CONFIG_SYS_DPAA_FMAN
236void fdt_fixup_fman_mac_addresses(void *blob)
237{
238 int node, i, ret;
239 char *tmp, *end;
240 unsigned char mac_addr[6];
241
242 /* get the mac addr from env */
Simon Glass64b723f2017-08-03 12:22:12 -0600243 tmp = env_get("ethaddr");
Valentin Longchampc98bf292013-10-18 11:47:24 +0200244 if (!tmp) {
245 printf("ethaddr env variable not defined\n");
246 return;
247 }
248 for (i = 0; i < 6; i++) {
249 mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
250 if (tmp)
251 tmp = (*end) ? end+1 : end;
252 }
253
254 /* find the correct fdt ethernet path and correct it */
255 node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000");
256 if (node < 0) {
257 printf("no /soc/fman/ethernet path offset\n");
258 return;
259 }
260 ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6);
261 if (ret) {
262 printf("error setting local-mac-address property\n");
263 return;
264 }
265}
266#endif
267
Simon Glass2aec3cc2014-10-23 18:58:47 -0600268int ft_board_setup(void *blob, bd_t *bd)
Valentin Longchampc98bf292013-10-18 11:47:24 +0200269{
270 phys_addr_t base;
271 phys_size_t size;
272
273 ft_cpu_setup(blob, bd);
274
Simon Glassda1a1342017-08-03 12:22:15 -0600275 base = env_get_bootm_low();
276 size = env_get_bootm_size();
Valentin Longchampc98bf292013-10-18 11:47:24 +0200277
278 fdt_fixup_memory(blob, (u64)base, (u64)size);
279
280#if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
Sriram Dash9fd465c2016-09-16 17:12:15 +0530281 fsl_fdt_fixup_dr_usb(blob, bd);
Valentin Longchampc98bf292013-10-18 11:47:24 +0200282#endif
283
284#ifdef CONFIG_PCI
285 pci_of_setup(blob, bd);
286#endif
287
288 fdt_fixup_liodn(blob);
289#ifdef CONFIG_SYS_DPAA_FMAN
290 fdt_fixup_fman_ethernet(blob);
291 fdt_fixup_fman_mac_addresses(blob);
292#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600293
294 return 0;
Valentin Longchampc98bf292013-10-18 11:47:24 +0200295}
Valentin Longchampec92cdb2014-04-30 15:01:44 +0200296
297#if defined(CONFIG_POST)
298
299/* DIC26_SELFTEST GPIO used to start factory test sw */
300#define SELFTEST_PORT GPIO_A
301#define SELFTEST_PIN 31
302
303int post_hotkeys_pressed(void)
304{
305 qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
306 return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);
307}
308#endif