blob: 92dd9237ec7f884e368fe03309c57b1de202af0c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +05302/*
3 * Copyright 2013 Freescale Semiconductor, Inc.
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +05304 */
5
6#include <common.h>
7#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06008#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053010#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053012#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>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053020#include <asm/fsl_liodn.h>
21#include <fm_eth.h>
Zhao Qiang433e0af2014-03-21 16:21:46 +080022#include <hwconfig.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053023
tang yuantian10871092014-12-18 10:20:07 +080024#include "../common/sleep.h"
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053025#include "../common/qixis.h"
26#include "t1040qds.h"
27#include "t1040qds_qixis.h"
28
29DECLARE_GLOBAL_DATA_PTR;
30
31int checkboard(void)
32{
33 char buf[64];
34 u8 sw;
35 struct cpu_type *cpu = gd->arch.cpu;
36 static const char *const freq[] = {"100", "125", "156.25", "161.13",
37 "122.88", "122.88", "122.88"};
38 int clock;
39
40 printf("Board: %sQDS, ", cpu->name);
41 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
42 QIXIS_READ(id), QIXIS_READ(arch));
43
44 sw = QIXIS_READ(brdcfg[0]);
45 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
46
47 if (sw < 0x8)
48 printf("vBank: %d\n", sw);
49 else if (sw == 0x8)
50 puts("PromJet\n");
51 else if (sw == 0x9)
52 puts("NAND\n");
53 else if (sw == 0x15)
54 printf("IFCCard\n");
55 else
56 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
57
58 printf("FPGA: v%d (%s), build %d",
59 (int)QIXIS_READ(scver), qixis_read_tag(buf),
60 (int)qixis_read_minor());
61 /* the timestamp string contains "\n" at the end */
62 printf(" on %s", qixis_read_time(buf));
63
64 /*
65 * Display the actual SERDES reference clocks as configured by the
66 * dip switches on the board. Note that the SWx registers could
67 * technically be set to force the reference clocks to match the
68 * values that the SERDES expects (or vice versa). For now, however,
69 * we just display both values and hope the user notices when they
70 * don't match.
71 */
72 puts("SERDES Reference: ");
73 sw = QIXIS_READ(brdcfg[2]);
74 clock = (sw >> 6) & 3;
75 printf("Clock1=%sMHz ", freq[clock]);
76 clock = (sw >> 4) & 3;
77 printf("Clock2=%sMHz\n", freq[clock]);
78
79 return 0;
80}
81
82int select_i2c_ch_pca9547(u8 ch)
83{
84 int ret;
85
86 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
87 if (ret) {
88 puts("PCA: failed to select proper channel\n");
89 return ret;
90 }
91
92 return 0;
93}
94
Zhao Qiang433e0af2014-03-21 16:21:46 +080095static void qe_board_setup(void)
96{
97 u8 brdcfg15, brdcfg9;
98
99 if (hwconfig("qe") && hwconfig("tdm")) {
100 brdcfg15 = QIXIS_READ(brdcfg[15]);
101 /*
102 * TDMRiser uses QE-TDM
103 * Route QE_TDM signals to TDM Riser slot
104 */
105 QIXIS_WRITE(brdcfg[15], brdcfg15 | 7);
106 } else if (hwconfig("qe") && hwconfig("uart")) {
107 brdcfg15 = QIXIS_READ(brdcfg[15]);
108 brdcfg9 = QIXIS_READ(brdcfg[9]);
109 /*
110 * Route QE_TDM signals to UCC
111 * ProfiBus controlled by UCC3
112 */
113 brdcfg15 &= 0xfc;
114 QIXIS_WRITE(brdcfg[15], brdcfg15 | 2);
115 QIXIS_WRITE(brdcfg[9], brdcfg9 | 4);
116 }
117}
118
tang yuantian10871092014-12-18 10:20:07 +0800119int board_early_init_f(void)
120{
121#if defined(CONFIG_DEEP_SLEEP)
122 if (is_warm_boot())
123 fsl_dp_disable_console();
124#endif
125
126 return 0;
127}
128
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530129int board_early_init_r(void)
130{
131#ifdef CONFIG_SYS_FLASH_BASE
132 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700133 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530134
135 /*
136 * Remap Boot flash + PROMJET region to caching-inhibited
137 * so that flash can be erased properly.
138 */
139
140 /* Flush d-cache and invalidate i-cache of any FLASH data */
141 flush_dcache();
142 invalidate_icache();
143
York Sun220c3462014-06-24 21:16:20 -0700144 if (flash_esel == -1) {
145 /* very unlikely unless something is messed up */
146 puts("Error: Could not find TLB for FLASH BASE\n");
147 flash_esel = 2; /* give our best effort to continue */
148 } else {
149 /* invalidate existing TLB entry for flash + promjet */
150 disable_tlb(flash_esel);
151 }
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530152
153 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
154 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
155 0, flash_esel, BOOKE_PAGESZ_256M, 1);
156#endif
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530157 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
158
159 return 0;
160}
161
162unsigned long get_board_sys_clk(void)
163{
164 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
165
166 switch (sysclk_conf & 0x0F) {
167 case QIXIS_SYSCLK_64:
168 return 64000000;
169 case QIXIS_SYSCLK_83:
170 return 83333333;
171 case QIXIS_SYSCLK_100:
172 return 100000000;
173 case QIXIS_SYSCLK_125:
174 return 125000000;
175 case QIXIS_SYSCLK_133:
176 return 133333333;
177 case QIXIS_SYSCLK_150:
178 return 150000000;
179 case QIXIS_SYSCLK_160:
180 return 160000000;
181 case QIXIS_SYSCLK_166:
182 return 166666666;
183 }
184 return 66666666;
185}
186
187unsigned long get_board_ddr_clk(void)
188{
189 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
190
191 switch ((ddrclk_conf & 0x30) >> 4) {
192 case QIXIS_DDRCLK_100:
193 return 100000000;
194 case QIXIS_DDRCLK_125:
195 return 125000000;
196 case QIXIS_DDRCLK_133:
197 return 133333333;
198 }
199 return 66666666;
200}
201
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530202#define NUM_SRDS_BANKS 2
203int misc_init_r(void)
204{
205 u8 sw;
206 serdes_corenet_t *srds_regs =
207 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
208 u32 actual[NUM_SRDS_BANKS] = { 0 };
209 int i;
210
211 sw = QIXIS_READ(brdcfg[2]);
212 for (i = 0; i < NUM_SRDS_BANKS; i++) {
213 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
214 switch (clock) {
215 case 0:
216 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
217 break;
218 case 1:
219 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
220 break;
221 case 2:
222 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
223 break;
224 }
225 }
226
227 puts("SerDes1");
228 for (i = 0; i < NUM_SRDS_BANKS; i++) {
229 u32 pllcr0 = srds_regs->bank[i].pllcr0;
230 u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
231 if (expected != actual[i]) {
232 printf("expects ref clk%d %sMHz, but actual is %sMHz\n",
233 i + 1, serdes_clock_to_string(expected),
234 serdes_clock_to_string(actual[i]));
235 }
236 }
237
Zhao Qiang433e0af2014-03-21 16:21:46 +0800238 qe_board_setup();
239
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530240 return 0;
241}
242
Simon Glass2aec3cc2014-10-23 18:58:47 -0600243int ft_board_setup(void *blob, bd_t *bd)
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530244{
245 phys_addr_t base;
246 phys_size_t size;
247
248 ft_cpu_setup(blob, bd);
249
Simon Glassda1a1342017-08-03 12:22:15 -0600250 base = env_get_bootm_low();
251 size = env_get_bootm_size();
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530252
253 fdt_fixup_memory(blob, (u64)base, (u64)size);
254
255#ifdef CONFIG_PCI
256 pci_of_setup(blob, bd);
257#endif
258
259 fdt_fixup_liodn(blob);
260
261#ifdef CONFIG_HAS_FSL_DR_USB
Sriram Dash9fd465c2016-09-16 17:12:15 +0530262 fsl_fdt_fixup_dr_usb(blob, bd);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530263#endif
264
265#ifdef CONFIG_SYS_DPAA_FMAN
266 fdt_fixup_fman_ethernet(blob);
Prabhakar Kushwahae70cd8d2014-01-27 15:55:20 +0530267 fdt_fixup_board_enet(blob);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530268#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600269
270 return 0;
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530271}
272
273void qixis_dump_switch(void)
274{
275 int i, nr_of_cfgsw;
276
277 QIXIS_WRITE(cms[0], 0x00);
278 nr_of_cfgsw = QIXIS_READ(cms[1]);
279
280 puts("DIP switch settings dump:\n");
281 for (i = 1; i <= nr_of_cfgsw; i++) {
282 QIXIS_WRITE(cms[0], i);
283 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
284 }
285}
Prabhakar Kushwaha692256a2013-12-26 12:40:55 +0530286
287int board_need_mem_reset(void)
288{
289 return 1;
290}