blob: 9e253fdec27d079e08c5c6233065823570c724dc [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.
Biwen Li29cd2712020-05-01 20:04:21 +08004 * Copyright 2020 NXP
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +05305 */
6
7#include <common.h>
8#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06009#include <env.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070010#include <fdt_support.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053011#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053013#include <netdev.h>
14#include <linux/compiler.h>
15#include <asm/mmu.h>
16#include <asm/processor.h>
17#include <asm/cache.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_law.h>
20#include <asm/fsl_serdes.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053021#include <asm/fsl_liodn.h>
22#include <fm_eth.h>
Zhao Qiang433e0af2014-03-21 16:21:46 +080023#include <hwconfig.h>
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053024
tang yuantian10871092014-12-18 10:20:07 +080025#include "../common/sleep.h"
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053026#include "../common/qixis.h"
27#include "t1040qds.h"
28#include "t1040qds_qixis.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
32int checkboard(void)
33{
34 char buf[64];
35 u8 sw;
36 struct cpu_type *cpu = gd->arch.cpu;
37 static const char *const freq[] = {"100", "125", "156.25", "161.13",
38 "122.88", "122.88", "122.88"};
39 int clock;
40
41 printf("Board: %sQDS, ", cpu->name);
42 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
43 QIXIS_READ(id), QIXIS_READ(arch));
44
45 sw = QIXIS_READ(brdcfg[0]);
46 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
47
48 if (sw < 0x8)
49 printf("vBank: %d\n", sw);
50 else if (sw == 0x8)
51 puts("PromJet\n");
52 else if (sw == 0x9)
53 puts("NAND\n");
54 else if (sw == 0x15)
55 printf("IFCCard\n");
56 else
57 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
58
59 printf("FPGA: v%d (%s), build %d",
60 (int)QIXIS_READ(scver), qixis_read_tag(buf),
61 (int)qixis_read_minor());
62 /* the timestamp string contains "\n" at the end */
63 printf(" on %s", qixis_read_time(buf));
64
65 /*
66 * Display the actual SERDES reference clocks as configured by the
67 * dip switches on the board. Note that the SWx registers could
68 * technically be set to force the reference clocks to match the
69 * values that the SERDES expects (or vice versa). For now, however,
70 * we just display both values and hope the user notices when they
71 * don't match.
72 */
73 puts("SERDES Reference: ");
74 sw = QIXIS_READ(brdcfg[2]);
75 clock = (sw >> 6) & 3;
76 printf("Clock1=%sMHz ", freq[clock]);
77 clock = (sw >> 4) & 3;
78 printf("Clock2=%sMHz\n", freq[clock]);
79
80 return 0;
81}
82
Biwen Li29cd2712020-05-01 20:04:21 +080083int select_i2c_ch_pca9547(u8 ch, int bus_num)
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053084{
85 int ret;
86
Biwen Li29cd2712020-05-01 20:04:21 +080087#ifdef CONFIG_DM_I2C
88 struct udevice *dev;
89
90 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
91 if (ret) {
92 printf("%s: Cannot find udev for a bus %d\n", __func__,
93 bus_num);
94 return ret;
95 }
96
97 ret = dm_i2c_write(dev, 0, &ch, 1);
98#else
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +053099 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li29cd2712020-05-01 20:04:21 +0800100#endif
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530101 if (ret) {
102 puts("PCA: failed to select proper channel\n");
103 return ret;
104 }
105
106 return 0;
107}
108
Zhao Qiang433e0af2014-03-21 16:21:46 +0800109static void qe_board_setup(void)
110{
111 u8 brdcfg15, brdcfg9;
112
113 if (hwconfig("qe") && hwconfig("tdm")) {
114 brdcfg15 = QIXIS_READ(brdcfg[15]);
115 /*
116 * TDMRiser uses QE-TDM
117 * Route QE_TDM signals to TDM Riser slot
118 */
119 QIXIS_WRITE(brdcfg[15], brdcfg15 | 7);
120 } else if (hwconfig("qe") && hwconfig("uart")) {
121 brdcfg15 = QIXIS_READ(brdcfg[15]);
122 brdcfg9 = QIXIS_READ(brdcfg[9]);
123 /*
124 * Route QE_TDM signals to UCC
125 * ProfiBus controlled by UCC3
126 */
127 brdcfg15 &= 0xfc;
128 QIXIS_WRITE(brdcfg[15], brdcfg15 | 2);
129 QIXIS_WRITE(brdcfg[9], brdcfg9 | 4);
130 }
131}
132
tang yuantian10871092014-12-18 10:20:07 +0800133int board_early_init_f(void)
134{
135#if defined(CONFIG_DEEP_SLEEP)
136 if (is_warm_boot())
137 fsl_dp_disable_console();
138#endif
139
140 return 0;
141}
142
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530143int board_early_init_r(void)
144{
145#ifdef CONFIG_SYS_FLASH_BASE
146 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700147 int flash_esel = find_tlb_idx((void *)flashbase, 1);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530148
149 /*
150 * Remap Boot flash + PROMJET region to caching-inhibited
151 * so that flash can be erased properly.
152 */
153
154 /* Flush d-cache and invalidate i-cache of any FLASH data */
155 flush_dcache();
156 invalidate_icache();
157
York Sun220c3462014-06-24 21:16:20 -0700158 if (flash_esel == -1) {
159 /* very unlikely unless something is messed up */
160 puts("Error: Could not find TLB for FLASH BASE\n");
161 flash_esel = 2; /* give our best effort to continue */
162 } else {
163 /* invalidate existing TLB entry for flash + promjet */
164 disable_tlb(flash_esel);
165 }
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530166
167 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
168 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
169 0, flash_esel, BOOKE_PAGESZ_256M, 1);
170#endif
Biwen Li29cd2712020-05-01 20:04:21 +0800171 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530172
173 return 0;
174}
175
176unsigned long get_board_sys_clk(void)
177{
178 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
179
180 switch (sysclk_conf & 0x0F) {
181 case QIXIS_SYSCLK_64:
182 return 64000000;
183 case QIXIS_SYSCLK_83:
184 return 83333333;
185 case QIXIS_SYSCLK_100:
186 return 100000000;
187 case QIXIS_SYSCLK_125:
188 return 125000000;
189 case QIXIS_SYSCLK_133:
190 return 133333333;
191 case QIXIS_SYSCLK_150:
192 return 150000000;
193 case QIXIS_SYSCLK_160:
194 return 160000000;
195 case QIXIS_SYSCLK_166:
196 return 166666666;
197 }
198 return 66666666;
199}
200
201unsigned long get_board_ddr_clk(void)
202{
203 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
204
205 switch ((ddrclk_conf & 0x30) >> 4) {
206 case QIXIS_DDRCLK_100:
207 return 100000000;
208 case QIXIS_DDRCLK_125:
209 return 125000000;
210 case QIXIS_DDRCLK_133:
211 return 133333333;
212 }
213 return 66666666;
214}
215
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530216#define NUM_SRDS_BANKS 2
217int misc_init_r(void)
218{
219 u8 sw;
220 serdes_corenet_t *srds_regs =
221 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
222 u32 actual[NUM_SRDS_BANKS] = { 0 };
223 int i;
224
225 sw = QIXIS_READ(brdcfg[2]);
226 for (i = 0; i < NUM_SRDS_BANKS; i++) {
227 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
228 switch (clock) {
229 case 0:
230 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
231 break;
232 case 1:
233 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
234 break;
235 case 2:
236 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
237 break;
238 }
239 }
240
241 puts("SerDes1");
242 for (i = 0; i < NUM_SRDS_BANKS; i++) {
243 u32 pllcr0 = srds_regs->bank[i].pllcr0;
244 u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
245 if (expected != actual[i]) {
246 printf("expects ref clk%d %sMHz, but actual is %sMHz\n",
247 i + 1, serdes_clock_to_string(expected),
248 serdes_clock_to_string(actual[i]));
249 }
250 }
251
Zhao Qiang433e0af2014-03-21 16:21:46 +0800252 qe_board_setup();
253
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530254 return 0;
255}
256
Simon Glass2aec3cc2014-10-23 18:58:47 -0600257int ft_board_setup(void *blob, bd_t *bd)
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530258{
259 phys_addr_t base;
260 phys_size_t size;
261
262 ft_cpu_setup(blob, bd);
263
Simon Glassda1a1342017-08-03 12:22:15 -0600264 base = env_get_bootm_low();
265 size = env_get_bootm_size();
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530266
267 fdt_fixup_memory(blob, (u64)base, (u64)size);
268
269#ifdef CONFIG_PCI
270 pci_of_setup(blob, bd);
271#endif
272
273 fdt_fixup_liodn(blob);
274
275#ifdef CONFIG_HAS_FSL_DR_USB
Sriram Dash9fd465c2016-09-16 17:12:15 +0530276 fsl_fdt_fixup_dr_usb(blob, bd);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530277#endif
278
279#ifdef CONFIG_SYS_DPAA_FMAN
280 fdt_fixup_fman_ethernet(blob);
Prabhakar Kushwahae70cd8d2014-01-27 15:55:20 +0530281 fdt_fixup_board_enet(blob);
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530282#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600283
284 return 0;
Prabhakar Kushwaha768e1202013-09-12 11:11:28 +0530285}
286
287void qixis_dump_switch(void)
288{
289 int i, nr_of_cfgsw;
290
291 QIXIS_WRITE(cms[0], 0x00);
292 nr_of_cfgsw = QIXIS_READ(cms[1]);
293
294 puts("DIP switch settings dump:\n");
295 for (i = 1; i <= nr_of_cfgsw; i++) {
296 QIXIS_WRITE(cms[0], i);
297 printf("SW%d = (0x%02x)\n", i, QIXIS_READ(cms[1]));
298 }
299}
Prabhakar Kushwaha692256a2013-12-26 12:40:55 +0530300
301int board_need_mem_reset(void)
302{
303 return 1;
304}