]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/keymile/kmp204x/kmp204x.c
bbb24531557dcb0d54dbfaaaa1dcbf767b4d8010
[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 /* TODO: implement the I2C deblocking function */
37 int i2c_make_abort(void)
38 {
39         return 1;
40 }
41
42 #define ZL30158_RST     8
43 #define ZL30343_RST     9
44
45 int board_early_init_f(void)
46 {
47         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
48
49         /* board only uses the DDR_MCK0, so disable the DDR_MCK1/2/3 */
50         setbits_be32(&gur->ddrclkdr, 0x001f000f);
51
52         /* take the Zarlinks out of reset as soon as possible */
53         qrio_prst(ZL30158_RST, false, false);
54         qrio_prst(ZL30343_RST, false, false);
55
56         /* and set their reset to power-up only */
57         qrio_prstcfg(ZL30158_RST, PRSTCFG_POWUP_RST);
58         qrio_prstcfg(ZL30343_RST, PRSTCFG_POWUP_RST);
59
60         return 0;
61 }
62
63 int board_early_init_r(void)
64 {
65         /* Flush d-cache and invalidate i-cache of any FLASH data */
66         flush_dcache();
67         invalidate_icache();
68
69         set_liodns();
70         setup_portals();
71
72         return 0;
73 }
74
75 unsigned long get_board_sys_clk(unsigned long dummy)
76 {
77         return 66666666;
78 }
79
80 #define NUM_SRDS_BANKS  2
81 #define PHY_RST         15
82
83 int misc_init_r(void)
84 {
85         serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
86         u32 expected[NUM_SRDS_BANKS] = {SRDS_PLLCR0_RFCK_SEL_100,
87                 SRDS_PLLCR0_RFCK_SEL_125};
88         unsigned int i;
89
90         /* check SERDES reference clocks */
91         for (i = 0; i < NUM_SRDS_BANKS; i++) {
92                 u32 actual = in_be32(&regs->bank[i].pllcr0);
93                 actual &= SRDS_PLLCR0_RFCK_SEL_MASK;
94                 if (actual != expected[i]) {
95                         printf("Warning: SERDES bank %u expects reference \
96                                clock %sMHz, but actual is %sMHz\n", i + 1,
97                                serdes_clock_to_string(expected[i]),
98                                serdes_clock_to_string(actual));
99                 }
100         }
101
102         /* take the mgmt eth phy out of reset */
103         qrio_prst(PHY_RST, false, false);
104
105         return 0;
106 }
107
108 #if defined(CONFIG_HUSH_INIT_VAR)
109 int hush_init_var(void)
110 {
111         ivm_read_eeprom();
112         return 0;
113 }
114 #endif
115
116 #if defined(CONFIG_LAST_STAGE_INIT)
117 int last_stage_init(void)
118 {
119         set_km_env();
120         return 0;
121 }
122 #endif
123
124 #ifdef CONFIG_SYS_DPAA_FMAN
125 void fdt_fixup_fman_mac_addresses(void *blob)
126 {
127         int node, i, ret;
128         char *tmp, *end;
129         unsigned char mac_addr[6];
130
131         /* get the mac addr from env */
132         tmp = getenv("ethaddr");
133         if (!tmp) {
134                 printf("ethaddr env variable not defined\n");
135                 return;
136         }
137         for (i = 0; i < 6; i++) {
138                 mac_addr[i] = tmp ? simple_strtoul(tmp, &end, 16) : 0;
139                 if (tmp)
140                         tmp = (*end) ? end+1 : end;
141         }
142
143         /* find the correct fdt ethernet path and correct it */
144         node = fdt_path_offset(blob, "/soc/fman/ethernet@e8000");
145         if (node < 0) {
146                 printf("no /soc/fman/ethernet path offset\n");
147                 return;
148         }
149         ret = fdt_setprop(blob, node, "local-mac-address", &mac_addr, 6);
150         if (ret) {
151                 printf("error setting local-mac-address property\n");
152                 return;
153         }
154 }
155 #endif
156
157 void ft_board_setup(void *blob, bd_t *bd)
158 {
159         phys_addr_t base;
160         phys_size_t size;
161
162         ft_cpu_setup(blob, bd);
163
164         base = getenv_bootm_low();
165         size = getenv_bootm_size();
166
167         fdt_fixup_memory(blob, (u64)base, (u64)size);
168
169 #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
170         fdt_fixup_dr_usb(blob, bd);
171 #endif
172
173 #ifdef CONFIG_PCI
174         pci_of_setup(blob, bd);
175 #endif
176
177         fdt_fixup_liodn(blob);
178 #ifdef CONFIG_SYS_DPAA_FMAN
179         fdt_fixup_fman_ethernet(blob);
180         fdt_fixup_fman_mac_addresses(blob);
181 #endif
182 }