blob: 82010481934780e33f9b36602394987f8e7c5854 [file] [log] [blame]
York Sune12abcb2015-03-20 19:28:24 -07001/*
2 * Copyright 2015 Freescale Semiconductor
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6#include <common.h>
7#include <malloc.h>
8#include <errno.h>
9#include <netdev.h>
10#include <fsl_ifc.h>
11#include <fsl_ddr.h>
12#include <asm/io.h>
Yangbo Lucf005552015-05-28 14:53:55 +053013#include <hwconfig.h>
York Sune12abcb2015-03-20 19:28:24 -070014#include <fdt_support.h>
15#include <libfdt.h>
16#include <fsl_debug_server.h>
17#include <fsl-mc/fsl_mc.h>
18#include <environment.h>
19#include <i2c.h>
Mingkai Hu0e58b512015-10-26 19:47:50 +080020#include <asm/arch/soc.h>
Saksham Jainc0c38d22016-03-23 16:24:35 +053021#include <fsl_sec.h>
York Sune12abcb2015-03-20 19:28:24 -070022
23#include "../common/qixis.h"
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +053024#include "ls2080ardb_qixis.h"
Rai Harninder6aa1f3b2016-03-23 17:04:38 +053025#include "../common/vid.h"
York Sune12abcb2015-03-20 19:28:24 -070026
Yangbo Lucf005552015-05-28 14:53:55 +053027#define PIN_MUX_SEL_SDHC 0x00
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +080028#define PIN_MUX_SEL_DSPI 0x0a
Yangbo Lucf005552015-05-28 14:53:55 +053029
30#define SET_SDHC_MUX_SEL(reg, value) ((reg & 0xf0) | value)
York Sune12abcb2015-03-20 19:28:24 -070031DECLARE_GLOBAL_DATA_PTR;
32
Yangbo Lucf005552015-05-28 14:53:55 +053033enum {
34 MUX_TYPE_SDHC,
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +080035 MUX_TYPE_DSPI,
Yangbo Lucf005552015-05-28 14:53:55 +053036};
37
York Sune12abcb2015-03-20 19:28:24 -070038unsigned long long get_qixis_addr(void)
39{
40 unsigned long long addr;
41
42 if (gd->flags & GD_FLG_RELOC)
43 addr = QIXIS_BASE_PHYS;
44 else
45 addr = QIXIS_BASE_PHYS_EARLY;
46
47 /*
48 * IFC address under 256MB is mapped to 0x30000000, any address above
49 * is mapped to 0x5_10000000 up to 4GB.
50 */
51 addr = addr > 0x10000000 ? addr + 0x500000000ULL : addr + 0x30000000;
52
53 return addr;
54}
55
56int checkboard(void)
57{
58 u8 sw;
Prabhakar Kushwaha67f2e9c2015-05-28 14:54:07 +053059 char buf[15];
60
61 cpu_name(buf);
62 printf("Board: %s-RDB, ", buf);
York Sune12abcb2015-03-20 19:28:24 -070063
64 sw = QIXIS_READ(arch);
York Sune12abcb2015-03-20 19:28:24 -070065 printf("Board Arch: V%d, ", sw >> 4);
Prabhakar Kushwaha8368a592015-05-28 14:54:04 +053066 printf("Board version: %c, boot from ", (sw & 0xf) + 'A');
York Sune12abcb2015-03-20 19:28:24 -070067
68 sw = QIXIS_READ(brdcfg[0]);
69 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
70
71 if (sw < 0x8)
72 printf("vBank: %d\n", sw);
73 else if (sw == 0x9)
74 puts("NAND\n");
75 else
76 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
77
78 printf("FPGA: v%d.%d\n", QIXIS_READ(scver), QIXIS_READ(tagdata));
79
80 puts("SERDES1 Reference : ");
81 printf("Clock1 = 156.25MHz ");
82 printf("Clock2 = 156.25MHz");
83
84 puts("\nSERDES2 Reference : ");
85 printf("Clock1 = 100MHz ");
86 printf("Clock2 = 100MHz\n");
87
88 return 0;
89}
90
91unsigned long get_board_sys_clk(void)
92{
93 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
94
95 switch (sysclk_conf & 0x0F) {
96 case QIXIS_SYSCLK_83:
97 return 83333333;
98 case QIXIS_SYSCLK_100:
99 return 100000000;
100 case QIXIS_SYSCLK_125:
101 return 125000000;
102 case QIXIS_SYSCLK_133:
103 return 133333333;
104 case QIXIS_SYSCLK_150:
105 return 150000000;
106 case QIXIS_SYSCLK_160:
107 return 160000000;
108 case QIXIS_SYSCLK_166:
109 return 166666666;
110 }
111 return 66666666;
112}
113
114int select_i2c_ch_pca9547(u8 ch)
115{
116 int ret;
117
118 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
119 if (ret) {
120 puts("PCA: failed to select proper channel\n");
121 return ret;
122 }
123
124 return 0;
125}
126
Rai Harninder6aa1f3b2016-03-23 17:04:38 +0530127int i2c_multiplexer_select_vid_channel(u8 channel)
128{
129 return select_i2c_ch_pca9547(channel);
130}
131
Yangbo Lucf005552015-05-28 14:53:55 +0530132int config_board_mux(int ctrl_type)
133{
134 u8 reg5;
135
136 reg5 = QIXIS_READ(brdcfg[5]);
137
138 switch (ctrl_type) {
139 case MUX_TYPE_SDHC:
140 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_SDHC);
141 break;
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +0800142 case MUX_TYPE_DSPI:
143 reg5 = SET_SDHC_MUX_SEL(reg5, PIN_MUX_SEL_DSPI);
144 break;
Yangbo Lucf005552015-05-28 14:53:55 +0530145 default:
146 printf("Wrong mux interface type\n");
147 return -1;
148 }
149
150 QIXIS_WRITE(brdcfg[5], reg5);
151
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +0800152 return 0;
153}
154
155int board_init(void)
156{
157 char *env_hwconfig;
158 u32 __iomem *dcfg_ccsr = (u32 __iomem *)DCFG_BASE;
Shaohui Xie8c7ce822016-01-28 15:38:15 +0800159 u32 __iomem *irq_ccsr = (u32 __iomem *)ISC_BASE;
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +0800160 u32 val;
161
162 init_final_memctl_regs();
163
164 val = in_le32(dcfg_ccsr + DCFG_RCWSR13 / 4);
165
166 env_hwconfig = getenv("hwconfig");
167
168 if (hwconfig_f("dspi", env_hwconfig) &&
169 DCFG_RCWSR13_DSPI == (val & (u32)(0xf << 8)))
170 config_board_mux(MUX_TYPE_DSPI);
171 else
172 config_board_mux(MUX_TYPE_SDHC);
173
174#ifdef CONFIG_ENV_IS_NOWHERE
175 gd->env_addr = (ulong)&default_environment[0];
176#endif
177 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
178
179 QIXIS_WRITE(rst_ctl, QIXIS_RST_CTL_RESET_EN);
180
Shaohui Xie8c7ce822016-01-28 15:38:15 +0800181 /* invert AQR405 IRQ pins polarity */
182 out_le32(irq_ccsr + IRQCR_OFFSET / 4, AQR405_IRQ_MASK);
183
Haikun.Wang@freescale.comb8a258c2015-06-26 19:58:24 +0800184 return 0;
185}
186
187int board_early_init_f(void)
188{
189 fsl_lsch3_early_init_f();
Yangbo Lucf005552015-05-28 14:53:55 +0530190 return 0;
191}
192
193int misc_init_r(void)
194{
195 if (hwconfig("sdhc"))
196 config_board_mux(MUX_TYPE_SDHC);
197
Rai Harninder6aa1f3b2016-03-23 17:04:38 +0530198 if (adjust_vdd(0))
199 printf("Warning: Adjusting core voltage failed.\n");
200
Yangbo Lucf005552015-05-28 14:53:55 +0530201 return 0;
202}
203
York Sune12abcb2015-03-20 19:28:24 -0700204void detail_board_ddr_info(void)
205{
206 puts("\nDDR ");
207 print_size(gd->bd->bi_dram[0].size + gd->bd->bi_dram[1].size, "");
208 print_ddr_info(0);
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530209#ifdef CONFIG_SYS_FSL_HAS_DP_DDR
York Sune12abcb2015-03-20 19:28:24 -0700210 if (gd->bd->bi_dram[2].size) {
211 puts("\nDP-DDR ");
212 print_size(gd->bd->bi_dram[2].size, "");
213 print_ddr_info(CONFIG_DP_DDR_CTRL);
214 }
Prabhakar Kushwaha122bcfd2015-11-09 16:42:07 +0530215#endif
York Sune12abcb2015-03-20 19:28:24 -0700216}
217
218int dram_init(void)
219{
220 gd->ram_size = initdram(0);
221
222 return 0;
223}
224
225#if defined(CONFIG_ARCH_MISC_INIT)
226int arch_misc_init(void)
227{
228#ifdef CONFIG_FSL_DEBUG_SERVER
229 debug_server_init();
230#endif
Saksham Jainc0c38d22016-03-23 16:24:35 +0530231#ifdef CONFIG_FSL_CAAM
232 sec_init();
233#endif
York Sune12abcb2015-03-20 19:28:24 -0700234 return 0;
235}
236#endif
237
York Sune12abcb2015-03-20 19:28:24 -0700238#ifdef CONFIG_FSL_MC_ENET
239void fdt_fixup_board_enet(void *fdt)
240{
241 int offset;
242
Stuart Yodera3466152016-03-02 16:37:13 -0600243 offset = fdt_path_offset(fdt, "/soc/fsl-mc");
York Sune12abcb2015-03-20 19:28:24 -0700244
245 if (offset < 0)
Stuart Yodera3466152016-03-02 16:37:13 -0600246 offset = fdt_path_offset(fdt, "/fsl-mc");
York Sune12abcb2015-03-20 19:28:24 -0700247
248 if (offset < 0) {
249 printf("%s: ERROR: fsl-mc node not found in device tree (error %d)\n",
250 __func__, offset);
251 return;
252 }
253
254 if (get_mc_boot_status() == 0)
255 fdt_status_okay(fdt, offset);
256 else
257 fdt_status_fail(fdt, offset);
258}
259#endif
260
261#ifdef CONFIG_OF_BOARD_SETUP
262int ft_board_setup(void *blob, bd_t *bd)
263{
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530264 int err;
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530265 u64 base[CONFIG_NR_DRAM_BANKS];
266 u64 size[CONFIG_NR_DRAM_BANKS];
York Sune12abcb2015-03-20 19:28:24 -0700267
268 ft_cpu_setup(blob, bd);
269
Bhupesh Sharma0b10a1a2015-05-28 14:54:10 +0530270 /* fixup DT for the two GPP DDR banks */
271 base[0] = gd->bd->bi_dram[0].start;
272 size[0] = gd->bd->bi_dram[0].size;
273 base[1] = gd->bd->bi_dram[1].start;
274 size[1] = gd->bd->bi_dram[1].size;
275
276 fdt_fixup_memory_banks(blob, base, size, 2);
York Sune12abcb2015-03-20 19:28:24 -0700277
278#ifdef CONFIG_FSL_MC_ENET
279 fdt_fixup_board_enet(blob);
Prabhakar Kushwaha316b71c2015-11-04 12:25:59 +0530280 err = fsl_mc_ldpaa_exit(bd);
281 if (err)
282 return err;
York Sune12abcb2015-03-20 19:28:24 -0700283#endif
284
285 return 0;
286}
287#endif
288
289void qixis_dump_switch(void)
290{
291 int i, nr_of_cfgsw;
292
293 QIXIS_WRITE(cms[0], 0x00);
294 nr_of_cfgsw = QIXIS_READ(cms[1]);
295
296 puts("DIP switch settings dump:\n");
297 for (i = 1; i <= nr_of_cfgsw; i++) {
298 QIXIS_WRITE(cms[0], i);
299 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
300 }
301}
York Sunac192a92015-05-28 14:54:09 +0530302
303/*
304 * Board rev C and earlier has duplicated I2C addresses for 2nd controller.
305 * Both slots has 0x54, resulting 2nd slot unusable.
306 */
307void update_spd_address(unsigned int ctrl_num,
308 unsigned int slot,
309 unsigned int *addr)
310{
311 u8 sw;
312
313 sw = QIXIS_READ(arch);
314 if ((sw & 0xf) < 0x3) {
315 if (ctrl_num == 1 && slot == 0)
316 *addr = SPD_EEPROM_ADDRESS4;
317 else if (ctrl_num == 1 && slot == 1)
318 *addr = SPD_EEPROM_ADDRESS3;
319 }
320}