]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/keymile/kmp204x/kmp204x.c
225262e49c8176fd2c297b7e3fb916f23e107446
[karo-tx-uboot.git] / board / keymile / kmp204x / kmp204x.c
1 /*
2  * (C) Copyright 2013 Keymile AG
3  * Valentin Longchamp <valentin.longchamp@keymile.com>
4  *
5  * Copyright 2011,2012 Freescale Semiconductor, Inc.
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <command.h>
12 #include <netdev.h>
13 #include <linux/compiler.h>
14 #include <asm/mmu.h>
15 #include <asm/processor.h>
16 #include <asm/cache.h>
17 #include <asm/immap_85xx.h>
18 #include <asm/fsl_law.h>
19 #include <asm/fsl_serdes.h>
20 #include <asm/fsl_portals.h>
21 #include <asm/fsl_liodn.h>
22 #include <fm_eth.h>
23
24 #include "../common/common.h"
25 #include "kmp204x.h"
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 int checkboard(void)
30 {
31         printf("Board: Keymile %s\n", CONFIG_KM_BOARD_NAME);
32
33         return 0;
34 }
35
36 /* I2C deblocking uses the algorithm defined in board/keymile/common/common.c
37  * 2 dedicated QRIO GPIOs externally pull the SCL and SDA lines
38  * For I2C only the low state is activly driven and high state is pulled-up
39  * by a resistor. Therefore the deblock GPIOs are used
40  *  -> as an active output to drive a low state
41  *  -> as an open-drain input to have a pulled-up high state
42  */
43
44 /* QRIO GPIOs used for deblocking */
45 #define DEBLOCK_PORT1   GPIO_A
46 #define DEBLOCK_SCL1    20
47 #define DEBLOCK_SDA1    21
48
49 /* By default deblock GPIOs are floating */
50 static void i2c_deblock_gpio_cfg(void)
51 {
52         /* set I2C bus 1 deblocking GPIOs input, but 0 value for open drain */
53         qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SCL1);
54         qrio_gpio_direction_input(DEBLOCK_PORT1, DEBLOCK_SDA1);
55
56         qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, 0);
57         qrio_set_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, 0);
58 }
59
60 void set_sda(int state)
61 {
62         qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1, state);
63 }
64
65 void set_scl(int state)
66 {
67         qrio_set_opendrain_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1, state);
68 }
69
70 int get_sda(void)
71 {
72         return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SDA1);
73 }
74
75 int get_scl(void)
76 {
77         return qrio_get_gpio(DEBLOCK_PORT1, DEBLOCK_SCL1);
78 }
79
80
81 #define ZL30158_RST     8
82 #define BFTIC4_RST      0
83 #define RSTRQSR1_WDT_RR 0x00200000
84 #define RSTRQSR1_SW_RR  0x00100000
85
86 int board_early_init_f(void)
87 {
88         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
89         bool cpuwd_flag = false;
90
91         /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */
92         setbits_be32(&gur->ddrclkdr, 0x001f000f);
93
94         /* set reset reason according CPU register */
95         if ((gur->rstrqsr1 & (RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR)) ==
96             RSTRQSR1_WDT_RR)
97                 cpuwd_flag = true;
98
99         qrio_cpuwd_flag(cpuwd_flag);
100         /* clear CPU bits by writing 1 */
101         setbits_be32(&gur->rstrqsr1, RSTRQSR1_WDT_RR | RSTRQSR1_SW_RR);
102
103         /* set the BFTIC's prstcfg to reset at power-up and unit reset only */
104         qrio_prstcfg(BFTIC4_RST, PRSTCFG_POWUP_UNIT_RST);
105         /* and enable WD on it */
106         qrio_wdmask(BFTIC4_RST, true);
107
108         /* set the ZL30138's prstcfg to reset at power-up and unit reset only */
109         qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_UNIT_RST);
110         /* and take it out of reset as soon as possible (needed for Hooper) */
111         qrio_prst(ZL30158_RST, false, false);
112
113         return 0;
114 }
115
116 int board_early_init_r(void)
117 {
118         int ret = 0;
119         /* Flush d-cache and invalidate i-cache of any FLASH data */
120         flush_dcache();
121         invalidate_icache();
122
123         set_liodns();
124         setup_portals();
125
126         ret = trigger_fpga_config();
127         if (ret)
128                 printf("error triggering PCIe FPGA config\n");
129
130         /* enable the Unit LED (red) & Boot LED (on) */
131         qrio_set_leds();
132
133         /* enable Application Buffer */
134         qrio_enable_app_buffer();
135
136         return ret;
137 }
138
139 unsigned long get_board_sys_clk(unsigned long dummy)
140 {
141         return 66666666;
142 }
143
144 #define ETH_FRONT_PHY_RST       15
145 #define QSFP2_RST               11
146 #define QSFP1_RST               10
147 #define ZL30343_RST             9
148
149 int misc_init_f(void)
150 {
151         /* configure QRIO pis for i2c deblocking */
152         i2c_deblock_gpio_cfg();
153
154         /* configure the front phy's prstcfg and take it out of reset */
155         qrio_prstcfg(ETH_FRONT_PHY_RST, PRSTCFG_POWUP_UNIT_CORE_RST);
156         qrio_prst(ETH_FRONT_PHY_RST, false, false);
157
158         /* set the ZL30343 prstcfg to reset at power-up and unit reset only */
159         qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_UNIT_RST);
160         /* and enable the WD on it */
161         qrio_wdmask(ZL30343_RST, true);
162
163         /* set the QSFPs' prstcfg to reset at power-up and unit rst only */
164         qrio_prstcfg(QSFP1_RST, PRSTCFG_POWUP_UNIT_RST);
165         qrio_prstcfg(QSFP2_RST, PRSTCFG_POWUP_UNIT_RST);
166
167         /* and enable the WD on them */
168         qrio_wdmask(QSFP1_RST, true);
169         qrio_wdmask(QSFP2_RST, true);
170
171         return 0;
172 }
173
174 #define NUM_SRDS_BANKS  2
175
176 int misc_init_r(void)
177 {
178         serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
179         u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100,
180                 SRDS_PLLCR0_RFCK_SEL_125};
181         unsigned int i;
182
183         /* check SERDES reference clocks */
184         for (i = 0; i < NUM_SRDS_BANKS; i++) {
185                 u32 actual = in_be32(&regs->bank[i].pllcr0);
186                 actual &= SRDS_PLLCR0_RFCK_SEL_MASK;
187                 if (actual != expected[i]) {
188                         printf("Warning: SERDES bank %u expects reference \
189                                clock %sMHz, but actual is %sMHz\n", i + 1,
190                                serdes_clock_to_string(expected[i]),
191                                serdes_clock_to_string(actual));
192                 }
193         }
194
195         return 0;
196 }
197
198 #if defined(CONFIG_HUSH_INIT_VAR)
199 int hush_init_var(void)
200 {
201         ivm_read_eeprom();
202         return 0;
203 }
204 #endif
205
206 #if defined(CONFIG_LAST_STAGE_INIT)
207
208 int last_stage_init(void)
209 {
210 #if defined(CONFIG_KMCOGE4)
211         /* on KMCOGE4, the BFTIC4 is on the LBAPP2 */
212         struct bfticu_iomap *bftic4 =
213                 (struct bfticu_iomap *)CONFIG_SYS_LBAPP2_BASE;
214         u8 dip_switch = in_8((u8 *)&(bftic4->mswitch)) & BFTICU_DIPSWITCH_MASK;
215
216         if (dip_switch != 0) {
217                 /* start bootloader */
218                 puts("DIP:   Enabled\n");
219                 setenv("actual_bank", "0");
220         }
221 #endif
222         set_km_env();
223
224         return 0;
225 }
226 #endif
227
228 #ifdef CONFIG_SYS_DPAA_FMAN
229 void fdt_fixup_fman_mac_addresses(void *blob)
230 {
231         int node, i, ret;
232         char *tmp, *end;
233         unsigned char mac_addr[6];
234
235         /* get the mac addr from env */
236         tmp = getenv("ethaddr");
237         if (!tmp) {
238                 printf("ethaddr env variable not defined\n");
239                 return;
240         }
241         for (i = 0; i < 6; i++) {
242                 mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
243                 if (tmp)
244                         tmp = (*end) ? end+1 : end;
245         }
246
247         /* find the correct fdt ethernet path and correct it */
248         node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000");
249         if (node < 0) {
250                 printf("no /soc/fman/ethernet path offset\n");
251                 return;
252         }
253         ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6);
254         if (ret) {
255                 printf("error setting local-mac-address property\n");
256                 return;
257         }
258 }
259 #endif
260
261 void ft_board_setup(void *blob, bd_t *bd)
262 {
263         phys_addr_t base;
264         phys_size_t size;
265
266         ft_cpu_setup(blob, bd);
267
268         base = getenv_bootm_low();
269         size = getenv_bootm_size();
270
271         fdt_fixup_memory(blob, (u64)base, (u64)size);
272
273 #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
274         fdt_fixup_dr_usb(blob, bd);
275 #endif
276
277 #ifdef CONFIG_PCI
278         pci_of_setup(blob, bd);
279 #endif
280
281         fdt_fixup_liodn(blob);
282 #ifdef CONFIG_SYS_DPAA_FMAN
283         fdt_fixup_fman_ethernet(blob);
284         fdt_fixup_fman_mac_addresses(blob);
285 #endif
286 }
287
288 #if defined(CONFIG_POST)
289
290 /* DIC26_SELFTEST GPIO used to start factory test sw */
291 #define SELFTEST_PORT   GPIO_A
292 #define SELFTEST_PIN    31
293
294 int post_hotkeys_pressed(void)
295 {
296         qrio_gpio_direction_input(SELFTEST_PORT, SELFTEST_PIN);
297         return qrio_get_gpio(SELFTEST_PORT, SELFTEST_PIN);
298 }
299 #endif