blob: 869c01de92b91fd2658058f119849d8844e63c10 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
York Sun667ab1a2012-10-11 07:13:37 +00002/*
3 * Copyright 2009-2012 Freescale Semiconductor, Inc.
Biwen Li3e9d3952020-05-01 20:04:17 +08004 * Copyright 2020 NXP
York Sun667ab1a2012-10-11 07:13:37 +00005 */
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>
York Sun667ab1a2012-10-11 07:13:37 +000011#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070013#include <irq_func.h>
York Sun667ab1a2012-10-11 07:13:37 +000014#include <netdev.h>
15#include <linux/compiler.h>
16#include <asm/mmu.h>
17#include <asm/processor.h>
18#include <asm/cache.h>
19#include <asm/immap_85xx.h>
20#include <asm/fsl_law.h>
21#include <asm/fsl_serdes.h>
York Sun667ab1a2012-10-11 07:13:37 +000022#include <asm/fsl_liodn.h>
23#include <fm_eth.h>
24
25#include "../common/qixis.h"
26#include "../common/vsc3316_3308.h"
27#include "t4qds.h"
28#include "t4240qds_qixis.h"
29
30DECLARE_GLOBAL_DATA_PTR;
31
Shaohui Xie3d8095e2013-08-19 18:43:07 +080032static int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
Timur Tabie9fabd82012-12-12 11:07:12 +000033 {8, 8}, {9, 9}, {14, 14}, {15, 15} };
34
Shaohui Xie3d8095e2013-08-19 18:43:07 +080035static int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
Timur Tabie9fabd82012-12-12 11:07:12 +000036 {10, 10}, {11, 11}, {12, 12}, {13, 13} };
37
Shaohui Xie3d8095e2013-08-19 18:43:07 +080038static int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
Timur Tabie9fabd82012-12-12 11:07:12 +000039 {10, 11}, {11, 10}, {12, 2}, {13, 3} };
40
Shaohui Xie3d8095e2013-08-19 18:43:07 +080041static int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
Timur Tabie9fabd82012-12-12 11:07:12 +000042 {8, 9}, {9, 8}, {14, 1}, {15, 0} };
43
York Sun667ab1a2012-10-11 07:13:37 +000044int checkboard(void)
45{
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000046 char buf[64];
York Sun667ab1a2012-10-11 07:13:37 +000047 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000048 struct cpu_type *cpu = gd->arch.cpu;
York Sun667ab1a2012-10-11 07:13:37 +000049 unsigned int i;
50
51 printf("Board: %sQDS, ", cpu->name);
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000052 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
York Sun9b85a482013-06-27 10:48:29 -070053 QIXIS_READ(id), QIXIS_READ(arch));
York Sun667ab1a2012-10-11 07:13:37 +000054
55 sw = QIXIS_READ(brdcfg[0]);
56 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
57
58 if (sw < 0x8)
59 printf("vBank: %d\n", sw);
60 else if (sw == 0x8)
61 puts("Promjet\n");
62 else if (sw == 0x9)
63 puts("NAND\n");
64 else
65 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
66
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000067 printf("FPGA: v%d (%s), build %d",
York Sun9b85a482013-06-27 10:48:29 -070068 (int)QIXIS_READ(scver), qixis_read_tag(buf),
69 (int)qixis_read_minor());
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000070 /* the timestamp string contains "\n" at the end */
71 printf(" on %s", qixis_read_time(buf));
72
York Sun667ab1a2012-10-11 07:13:37 +000073 /*
74 * Display the actual SERDES reference clocks as configured by the
75 * dip switches on the board. Note that the SWx registers could
76 * technically be set to force the reference clocks to match the
77 * values that the SERDES expects (or vice versa). For now, however,
78 * we just display both values and hope the user notices when they
79 * don't match.
80 */
81 puts("SERDES Reference Clocks: ");
82 sw = QIXIS_READ(brdcfg[2]);
83 for (i = 0; i < MAX_SERDES; i++) {
York Sun9b85a482013-06-27 10:48:29 -070084 static const char * const freq[] = {
York Sun667ab1a2012-10-11 07:13:37 +000085 "100", "125", "156.25", "161.1328125"};
Roy Zangc04362f2013-03-25 07:33:15 +000086 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +000087
88 printf("SERDES%u=%sMHz ", i+1, freq[clock]);
89 }
90 puts("\n");
91
92 return 0;
93}
94
Biwen Li3e9d3952020-05-01 20:04:17 +080095int select_i2c_ch_pca9547(u8 ch, int bus_num)
York Sun667ab1a2012-10-11 07:13:37 +000096{
97 int ret;
98
Biwen Li3e9d3952020-05-01 20:04:17 +080099#ifdef CONFIG_DM_I2C
100 struct udevice *dev;
101
102 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
103 1, &dev);
104 if (ret) {
105 printf("%s: Cannot find udev for a bus %d\n", __func__,
106 bus_num);
107 return ret;
108 }
109
110 ret = dm_i2c_write(dev, 0, &ch, 1);
111#else
York Sun667ab1a2012-10-11 07:13:37 +0000112 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li3e9d3952020-05-01 20:04:17 +0800113#endif
York Sun667ab1a2012-10-11 07:13:37 +0000114 if (ret) {
115 puts("PCA: failed to select proper channel\n");
116 return ret;
117 }
118
119 return 0;
120}
121
York Sund58bef12013-03-25 07:33:22 +0000122/*
123 * read_voltage from sensor on I2C bus
124 * We use average of 4 readings, waiting for 532us befor another reading
125 */
126#define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
127#define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
128
129static inline int read_voltage(void)
130{
131 int i, ret, voltage_read = 0;
132 u16 vol_mon;
Biwen Li3e9d3952020-05-01 20:04:17 +0800133#ifdef CONFIG_DM_I2C
134 struct udevice *dev;
135 int bus_num = 0;
136#endif
York Sund58bef12013-03-25 07:33:22 +0000137
138 for (i = 0; i < NUM_READINGS; i++) {
Biwen Li3e9d3952020-05-01 20:04:17 +0800139#ifdef CONFIG_DM_I2C
140 ret = i2c_get_chip_for_busnum(bus_num, I2C_VOL_MONITOR_ADDR,
141 1, &dev);
142 if (ret) {
143 printf("%s: Cannot find udev for a bus %d\n", __func__,
144 bus_num);
145 return ret;
146 }
147
148 ret = dm_i2c_read(dev,
149 I2C_VOL_MONITOR_BUS_V_OFFSET,
150 (void *)&vol_mon, 2);
151#else
York Sund58bef12013-03-25 07:33:22 +0000152 ret = i2c_read(I2C_VOL_MONITOR_ADDR,
153 I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
Biwen Li3e9d3952020-05-01 20:04:17 +0800154#endif
York Sund58bef12013-03-25 07:33:22 +0000155 if (ret) {
156 printf("VID: failed to read core voltage\n");
157 return ret;
158 }
159 if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
160 printf("VID: Core voltage sensor error\n");
161 return -1;
162 }
163 debug("VID: bus voltage reads 0x%04x\n", vol_mon);
164 /* LSB = 4mv */
165 voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
166 udelay(WAIT_FOR_ADC);
167 }
168 /* calculate the average */
169 voltage_read /= NUM_READINGS;
170
171 return voltage_read;
172}
173
174/*
175 * We need to calculate how long before the voltage starts to drop or increase
176 * It returns with the loop count. Each loop takes several readings (532us)
177 */
178static inline int wait_for_voltage_change(int vdd_last)
179{
180 int timeout, vdd_current;
181
182 vdd_current = read_voltage();
183 /* wait until voltage starts to drop */
184 for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
185 timeout < 100; timeout++) {
186 vdd_current = read_voltage();
187 }
188 if (timeout >= 100) {
189 printf("VID: Voltage adjustment timeout\n");
190 return -1;
191 }
192 return timeout;
193}
194
195/*
196 * argument 'wait' is the time we know the voltage difference can be measured
197 * this function keeps reading the voltage until it is stable
198 */
199static inline int wait_for_voltage_stable(int wait)
200{
201 int timeout, vdd_current, vdd_last;
202
203 vdd_last = read_voltage();
204 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
205 /* wait until voltage is stable */
206 vdd_current = read_voltage();
207 for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
208 timeout < 100; timeout++) {
209 vdd_last = vdd_current;
210 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
211 vdd_current = read_voltage();
212 }
213 if (timeout >= 100) {
214 printf("VID: Voltage adjustment timeout\n");
215 return -1;
216 }
217
218 return vdd_current;
219}
220
221static inline int set_voltage(u8 vid)
222{
223 int wait, vdd_last;
224
225 vdd_last = read_voltage();
226 QIXIS_WRITE(brdcfg[6], vid);
227 wait = wait_for_voltage_change(vdd_last);
228 if (wait < 0)
229 return -1;
230 debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
231 wait = wait ? wait : 1;
232
233 vdd_last = wait_for_voltage_stable(wait);
234 if (vdd_last < 0)
235 return -1;
236 debug("VID: Current voltage is %d mV\n", vdd_last);
237
238 return vdd_last;
239}
240
241
York Sun844944c2013-03-25 07:40:01 +0000242static int adjust_vdd(ulong vdd_override)
York Sund58bef12013-03-25 07:33:22 +0000243{
244 int re_enable = disable_interrupts();
245 ccsr_gur_t __iomem *gur =
246 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
247 u32 fusesr;
248 u8 vid, vid_current;
249 int vdd_target, vdd_current, vdd_last;
250 int ret;
York Sun844944c2013-03-25 07:40:01 +0000251 unsigned long vdd_string_override;
252 char *vdd_string;
York Sund58bef12013-03-25 07:33:22 +0000253 static const uint16_t vdd[32] = {
254 0, /* unused */
255 9875, /* 0.9875V */
256 9750,
257 9625,
258 9500,
259 9375,
260 9250,
261 9125,
262 9000,
263 8875,
264 8750,
265 8625,
266 8500,
267 8375,
268 8250,
269 8125,
270 10000, /* 1.0000V */
271 10125,
272 10250,
273 10375,
274 10500,
275 10625,
276 10750,
277 10875,
278 11000,
279 0, /* reserved */
280 };
281 struct vdd_drive {
282 u8 vid;
283 unsigned voltage;
284 };
285
Biwen Li3e9d3952020-05-01 20:04:17 +0800286 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR, 0);
York Sund58bef12013-03-25 07:33:22 +0000287 if (ret) {
288 debug("VID: I2c failed to switch channel\n");
289 ret = -1;
290 goto exit;
291 }
292
293 /* get the voltage ID from fuse status register */
294 fusesr = in_be32(&gur->dcfg_fusesr);
295 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
296 FSL_CORENET_DCFG_FUSESR_VID_MASK;
297 if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
298 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
299 FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
300 }
301 vdd_target = vdd[vid];
York Sun844944c2013-03-25 07:40:01 +0000302
303 /* check override variable for overriding VDD */
Simon Glass64b723f2017-08-03 12:22:12 -0600304 vdd_string = env_get("t4240qds_vdd_mv");
York Sun844944c2013-03-25 07:40:01 +0000305 if (vdd_override == 0 && vdd_string &&
306 !strict_strtoul(vdd_string, 10, &vdd_string_override))
307 vdd_override = vdd_string_override;
308 if (vdd_override >= 819 && vdd_override <= 1212) {
309 vdd_target = vdd_override * 10; /* convert to 1/10 mV */
310 debug("VDD override is %lu\n", vdd_override);
311 } else if (vdd_override != 0) {
312 printf("Invalid value.\n");
313 }
314
York Sund58bef12013-03-25 07:33:22 +0000315 if (vdd_target == 0) {
316 debug("VID: VID not used\n");
317 ret = 0;
318 goto exit;
319 } else {
320 /* round up and divice by 10 to get a value in mV */
321 vdd_target = DIV_ROUND_UP(vdd_target, 10);
322 debug("VID: vid = %d mV\n", vdd_target);
323 }
324
325 /*
326 * Check current board VID setting
327 * Voltage regulator support output to 6.250mv step
328 * The highes voltage allowed for this board is (vid=0x40) 1.21250V
329 * the lowest is (vid=0x7f) 0.81875V
330 */
331 vid_current = QIXIS_READ(brdcfg[6]);
332 vdd_current = 121250 - (vid_current - 0x40) * 625;
333 debug("VID: Current vid setting is (0x%x) %d mV\n",
334 vid_current, vdd_current/100);
335
336 /*
337 * Read voltage monitor to check real voltage.
338 * Voltage monitor LSB is 4mv.
339 */
340 vdd_last = read_voltage();
341 if (vdd_last < 0) {
342 printf("VID: Could not read voltage sensor abort VID adjustment\n");
343 ret = -1;
344 goto exit;
345 }
346 debug("VID: Core voltage is at %d mV\n", vdd_last);
347 /*
348 * Adjust voltage to at or 8mV above target.
349 * Each step of adjustment is 6.25mV.
350 * Stepping down too fast may cause over current.
351 */
352 while (vdd_last > 0 && vid_current < 0x80 &&
353 vdd_last > (vdd_target + 8)) {
354 vid_current++;
355 vdd_last = set_voltage(vid_current);
356 }
357 /*
358 * Check if we need to step up
359 * This happens when board voltage switch was set too low
360 */
361 while (vdd_last > 0 && vid_current >= 0x40 &&
362 vdd_last < vdd_target + 2) {
363 vid_current--;
364 vdd_last = set_voltage(vid_current);
365 }
366 if (vdd_last > 0)
367 printf("VID: Core voltage %d mV\n", vdd_last);
368 else
369 ret = -1;
370
371exit:
372 if (re_enable)
373 enable_interrupts();
374 return ret;
375}
376
York Sun667ab1a2012-10-11 07:13:37 +0000377/* Configure Crossbar switches for Front-Side SerDes Ports */
378int config_frontside_crossbar_vsc3316(void)
379{
380 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
381 u32 srds_prtcl_s1, srds_prtcl_s2;
382 int ret;
383
Biwen Li3e9d3952020-05-01 20:04:17 +0800384 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS, 0);
York Sun667ab1a2012-10-11 07:13:37 +0000385 if (ret)
386 return ret;
387
388 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
389 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
390 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800391 switch (srds_prtcl_s1) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800392 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800393 case 38:
394 /* swap first lane and third lane on slot1 */
395 vsc3316_fsm1_tx[0][1] = 14;
396 vsc3316_fsm1_tx[6][1] = 0;
397 vsc3316_fsm1_rx[1][1] = 2;
398 vsc3316_fsm1_rx[6][1] = 13;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800399 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800400 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800401 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800402 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800403 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800404 case 48:
405 /* swap first lane and third lane on slot2 */
406 vsc3316_fsm1_tx[2][1] = 8;
407 vsc3316_fsm1_tx[4][1] = 6;
408 vsc3316_fsm1_rx[2][1] = 10;
409 vsc3316_fsm1_rx[5][1] = 5;
410 default:
York Sun667ab1a2012-10-11 07:13:37 +0000411 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
412 if (ret)
413 return ret;
414 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
415 if (ret)
416 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800417 break;
York Sun667ab1a2012-10-11 07:13:37 +0000418 }
419
420 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
421 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
422 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800423 switch (srds_prtcl_s2) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800424 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800425 case 38:
426 /* swap first lane and third lane on slot3 */
427 vsc3316_fsm2_tx[2][1] = 11;
428 vsc3316_fsm2_tx[5][1] = 4;
429 vsc3316_fsm2_rx[2][1] = 9;
430 vsc3316_fsm2_rx[4][1] = 7;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800431 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800432 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800433 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800434 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800435 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800436 case 48:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800437 case 49:
Shaohui Xie6e078702013-08-19 18:57:57 +0800438 case 50:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800439 case 51:
Shaohui Xie6e078702013-08-19 18:57:57 +0800440 case 52:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800441 case 53:
Shaohui Xie6e078702013-08-19 18:57:57 +0800442 case 54:
443 /* swap first lane and third lane on slot4 */
444 vsc3316_fsm2_tx[6][1] = 3;
445 vsc3316_fsm2_tx[1][1] = 12;
446 vsc3316_fsm2_rx[0][1] = 1;
447 vsc3316_fsm2_rx[6][1] = 15;
448 default:
York Sun667ab1a2012-10-11 07:13:37 +0000449 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
450 if (ret)
451 return ret;
452 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
453 if (ret)
454 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800455 break;
York Sun667ab1a2012-10-11 07:13:37 +0000456 }
457
458 return 0;
459}
460
461int config_backside_crossbar_mux(void)
462{
463 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
464 u32 srds_prtcl_s3, srds_prtcl_s4;
465 u8 brdcfg;
466
467 srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
468 FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
469 srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
470 switch (srds_prtcl_s3) {
471 case 0:
472 /* SerDes3 is not enabled */
473 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800474 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000475 case 2:
476 case 9:
477 case 10:
478 /* SD3(0:7) => SLOT5(0:7) */
479 brdcfg = QIXIS_READ(brdcfg[12]);
480 brdcfg &= ~BRDCFG12_SD3MX_MASK;
481 brdcfg |= BRDCFG12_SD3MX_SLOT5;
482 QIXIS_WRITE(brdcfg[12], brdcfg);
483 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800484 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000485 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800486 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000487 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800488 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000489 case 8:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800490 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000491 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800492 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000493 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800494 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000495 case 16:
496 case 17:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800497 case 18:
York Sun667ab1a2012-10-11 07:13:37 +0000498 case 19:
499 case 20:
500 /* SD3(4:7) => SLOT6(0:3) */
501 brdcfg = QIXIS_READ(brdcfg[12]);
502 brdcfg &= ~BRDCFG12_SD3MX_MASK;
503 brdcfg |= BRDCFG12_SD3MX_SLOT6;
504 QIXIS_WRITE(brdcfg[12], brdcfg);
505 break;
506 default:
507 printf("WARNING: unsupported for SerDes3 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700508 srds_prtcl_s3);
York Sun667ab1a2012-10-11 07:13:37 +0000509 return -1;
510 }
511
512 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
513 FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
514 srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
515 switch (srds_prtcl_s4) {
516 case 0:
517 /* SerDes4 is not enabled */
518 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800519 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000520 case 2:
521 /* 10b, SD4(0:7) => SLOT7(0:7) */
522 brdcfg = QIXIS_READ(brdcfg[12]);
523 brdcfg &= ~BRDCFG12_SD4MX_MASK;
524 brdcfg |= BRDCFG12_SD4MX_SLOT7;
525 QIXIS_WRITE(brdcfg[12], brdcfg);
526 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800527 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000528 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800529 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000530 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800531 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000532 case 8:
533 /* x1b, SD4(4:7) => SLOT8(0:3) */
534 brdcfg = QIXIS_READ(brdcfg[12]);
535 brdcfg &= ~BRDCFG12_SD4MX_MASK;
536 brdcfg |= BRDCFG12_SD4MX_SLOT8;
537 QIXIS_WRITE(brdcfg[12], brdcfg);
538 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800539 case 9:
York Sun667ab1a2012-10-11 07:13:37 +0000540 case 10:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800541 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000542 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800543 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000544 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800545 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000546 case 16:
547 case 18:
548 /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
549 brdcfg = QIXIS_READ(brdcfg[12]);
550 brdcfg &= ~BRDCFG12_SD4MX_MASK;
551 brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
552 QIXIS_WRITE(brdcfg[12], brdcfg);
553 break;
554 default:
555 printf("WARNING: unsupported for SerDes4 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700556 srds_prtcl_s4);
York Sun667ab1a2012-10-11 07:13:37 +0000557 return -1;
558 }
559
560 return 0;
561}
562
563int board_early_init_r(void)
564{
565 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700566 int flash_esel = find_tlb_idx((void *)flashbase, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000567
568 /*
569 * Remap Boot flash + PROMJET region to caching-inhibited
570 * so that flash can be erased properly.
571 */
572
573 /* Flush d-cache and invalidate i-cache of any FLASH data */
574 flush_dcache();
575 invalidate_icache();
576
York Sun220c3462014-06-24 21:16:20 -0700577 if (flash_esel == -1) {
578 /* very unlikely unless something is messed up */
579 puts("Error: Could not find TLB for FLASH BASE\n");
580 flash_esel = 2; /* give our best effort to continue */
581 } else {
582 /* invalidate existing TLB entry for flash + promjet */
583 disable_tlb(flash_esel);
584 }
York Sun667ab1a2012-10-11 07:13:37 +0000585
586 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
York Sun9b85a482013-06-27 10:48:29 -0700587 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
588 0, flash_esel, BOOKE_PAGESZ_256M, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000589
Ed Swarthouta55ec452013-03-25 07:39:37 +0000590 /* Disable remote I2C connection to qixis fpga */
591 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
York Sun667ab1a2012-10-11 07:13:37 +0000592
York Sund58bef12013-03-25 07:33:22 +0000593 /*
594 * Adjust core voltage according to voltage ID
595 * This function changes I2C mux to channel 2.
596 */
York Sun844944c2013-03-25 07:40:01 +0000597 if (adjust_vdd(0))
York Sund58bef12013-03-25 07:33:22 +0000598 printf("Warning: Adjusting core voltage failed.\n");
599
York Sun667ab1a2012-10-11 07:13:37 +0000600 /* Configure board SERDES ports crossbar */
601 config_frontside_crossbar_vsc3316();
602 config_backside_crossbar_mux();
Biwen Li3e9d3952020-05-01 20:04:17 +0800603 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
York Sun667ab1a2012-10-11 07:13:37 +0000604
605 return 0;
606}
607
608unsigned long get_board_sys_clk(void)
609{
610 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000611#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
612 /* use accurate clock measurement */
613 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
614 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
615 u32 val;
616
617 val = freq * base;
618 if (val) {
619 debug("SYS Clock measurement is: %d\n", val);
620 return val;
621 } else {
622 printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
623 }
624#endif
York Sun667ab1a2012-10-11 07:13:37 +0000625
626 switch (sysclk_conf & 0x0F) {
627 case QIXIS_SYSCLK_83:
628 return 83333333;
629 case QIXIS_SYSCLK_100:
630 return 100000000;
631 case QIXIS_SYSCLK_125:
632 return 125000000;
633 case QIXIS_SYSCLK_133:
634 return 133333333;
635 case QIXIS_SYSCLK_150:
636 return 150000000;
637 case QIXIS_SYSCLK_160:
638 return 160000000;
639 case QIXIS_SYSCLK_166:
640 return 166666666;
641 }
642 return 66666666;
643}
644
645unsigned long get_board_ddr_clk(void)
646{
647 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000648#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
649 /* use accurate clock measurement */
650 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
651 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
652 u32 val;
653
654 val = freq * base;
655 if (val) {
656 debug("DDR Clock measurement is: %d\n", val);
657 return val;
658 } else {
659 printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
660 }
661#endif
York Sun667ab1a2012-10-11 07:13:37 +0000662
663 switch ((ddrclk_conf & 0x30) >> 4) {
664 case QIXIS_DDRCLK_100:
665 return 100000000;
666 case QIXIS_DDRCLK_125:
667 return 125000000;
668 case QIXIS_DDRCLK_133:
669 return 133333333;
670 }
671 return 66666666;
672}
673
York Sun667ab1a2012-10-11 07:13:37 +0000674int misc_init_r(void)
675{
676 u8 sw;
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800677 void *srds_base = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
678 serdes_corenet_t *srds_regs;
York Sun667ab1a2012-10-11 07:13:37 +0000679 u32 actual[MAX_SERDES];
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800680 u32 pllcr0, expected;
York Sun667ab1a2012-10-11 07:13:37 +0000681 unsigned int i;
682
683 sw = QIXIS_READ(brdcfg[2]);
684 for (i = 0; i < MAX_SERDES; i++) {
Roy Zangc04362f2013-03-25 07:33:15 +0000685 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +0000686 switch (clock) {
687 case 0:
688 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
689 break;
690 case 1:
691 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
692 break;
693 case 2:
694 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
695 break;
696 case 3:
697 actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
698 break;
699 }
700 }
701
702 for (i = 0; i < MAX_SERDES; i++) {
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800703 srds_regs = srds_base + i * 0x1000;
704 pllcr0 = srds_regs->bank[0].pllcr0;
705 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
York Sun667ab1a2012-10-11 07:13:37 +0000706 if (expected != actual[i]) {
York Sun9b85a482013-06-27 10:48:29 -0700707 printf("Warning: SERDES%u expects reference clock %sMHz, but actual is %sMHz\n",
708 i + 1, serdes_clock_to_string(expected),
York Sun667ab1a2012-10-11 07:13:37 +0000709 serdes_clock_to_string(actual[i]));
710 }
711 }
712
713 return 0;
714}
715
Simon Glass2aec3cc2014-10-23 18:58:47 -0600716int ft_board_setup(void *blob, bd_t *bd)
York Sun667ab1a2012-10-11 07:13:37 +0000717{
718 phys_addr_t base;
719 phys_size_t size;
720
721 ft_cpu_setup(blob, bd);
722
Simon Glassda1a1342017-08-03 12:22:15 -0600723 base = env_get_bootm_low();
724 size = env_get_bootm_size();
York Sun667ab1a2012-10-11 07:13:37 +0000725
726 fdt_fixup_memory(blob, (u64)base, (u64)size);
727
728#ifdef CONFIG_PCI
729 pci_of_setup(blob, bd);
730#endif
731
732 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530733 fsl_fdt_fixup_dr_usb(blob, bd);
York Sun667ab1a2012-10-11 07:13:37 +0000734
735#ifdef CONFIG_SYS_DPAA_FMAN
736 fdt_fixup_fman_ethernet(blob);
737 fdt_fixup_board_enet(blob);
738#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600739
740 return 0;
York Sun667ab1a2012-10-11 07:13:37 +0000741}
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000742
743/*
York Sun997f5122013-03-25 07:39:24 +0000744 * This function is called by bdinfo to print detail board information.
745 * As an exmaple for future board, we organize the messages into
746 * several sections. If applicable, the message is in the format of
747 * <name> = <value>
748 * It should aligned with normal output of bdinfo command.
749 *
750 * Voltage: Core, DDR and another configurable voltages
751 * Clock : Critical clocks which are not printed already
752 * RCW : RCW source if not printed already
753 * Misc : Other important information not in above catagories
754 */
755void board_detail(void)
756{
757 int i;
758 u8 brdcfg[16], dutcfg[16], rst_ctl;
759 int vdd, rcwsrc;
760 static const char * const clk[] = {"66.67", "100", "125", "133.33"};
761
762 for (i = 0; i < 16; i++) {
763 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
764 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
765 }
766
767 /* Voltage secion */
Biwen Li3e9d3952020-05-01 20:04:17 +0800768 if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR, 0)) {
York Sun997f5122013-03-25 07:39:24 +0000769 vdd = read_voltage();
770 if (vdd > 0)
771 printf("Core voltage= %d mV\n", vdd);
Biwen Li3e9d3952020-05-01 20:04:17 +0800772 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
York Sun997f5122013-03-25 07:39:24 +0000773 }
774
775 printf("XVDD = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
776
777 /* clock section */
778 printf("SYSCLK = %s MHz\nDDRCLK = %s MHz\n",
779 clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
780
781 /* RCW section */
782 rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
783 puts("RCW source = ");
784 switch (rcwsrc) {
785 case 0x017:
786 case 0x01f:
787 puts("8-bit NOR\n");
788 break;
789 case 0x027:
790 case 0x02F:
791 puts("16-bit NOR\n");
792 break;
793 case 0x040:
794 puts("SDHC/eMMC\n");
795 break;
796 case 0x044:
797 puts("SPI 16-bit addressing\n");
798 break;
799 case 0x045:
800 puts("SPI 24-bit addressing\n");
801 break;
802 case 0x048:
803 puts("I2C normal addressing\n");
804 break;
805 case 0x049:
806 puts("I2C extended addressing\n");
807 break;
808 case 0x108:
809 case 0x109:
810 case 0x10a:
811 case 0x10b:
812 puts("8-bit NAND, 2KB\n");
813 break;
814 default:
815 if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
816 puts("Hard-coded RCW\n");
817 else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
818 puts("8-bit NAND, 4KB\n");
819 else
820 puts("unknown\n");
821 break;
822 }
823
824 /* Misc section */
825 rst_ctl = QIXIS_READ(rst_ctl);
826 puts("HRESET_REQ = ");
827 switch (rst_ctl & 0x30) {
828 case 0x00:
829 puts("Ignored\n");
830 break;
831 case 0x10:
832 puts("Assert HRESET\n");
833 break;
834 case 0x30:
835 puts("Reset system\n");
836 break;
837 default:
838 puts("N/A\n");
839 break;
840 }
841}
842
843/*
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000844 * Reverse engineering switch settings.
845 * Some bits cannot be figured out. They will be displayed as
846 * underscore in binary format. mask[] has those bits.
847 * Some bits are calculated differently than the actual switches
848 * if booting with overriding by FPGA.
849 */
850void qixis_dump_switch(void)
851{
852 int i;
853 u8 sw[9];
854
855 /*
856 * Any bit with 1 means that bit cannot be reverse engineered.
857 * It will be displayed as _ in binary format.
858 */
York Sun9e698742013-03-25 07:40:14 +0000859 static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000860 char buf[10];
861 u8 brdcfg[16], dutcfg[16];
862
863 for (i = 0; i < 16; i++) {
864 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
865 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
866 }
867
868 sw[0] = dutcfg[0];
York Sun9b85a482013-06-27 10:48:29 -0700869 sw[1] = (dutcfg[1] << 0x07) |
870 ((dutcfg[12] & 0xC0) >> 1) |
871 ((dutcfg[11] & 0xE0) >> 3) |
872 ((dutcfg[6] & 0x80) >> 6) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000873 ((dutcfg[1] & 0x80) >> 7);
York Sun9b85a482013-06-27 10:48:29 -0700874 sw[2] = ((brdcfg[1] & 0x0f) << 4) |
875 ((brdcfg[1] & 0x30) >> 2) |
876 ((brdcfg[1] & 0x40) >> 5) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000877 ((brdcfg[1] & 0x80) >> 7);
878 sw[3] = brdcfg[2];
York Sun9b85a482013-06-27 10:48:29 -0700879 sw[4] = ((dutcfg[2] & 0x01) << 7) |
880 ((dutcfg[2] & 0x06) << 4) |
881 ((~QIXIS_READ(present)) & 0x10) |
882 ((brdcfg[3] & 0x80) >> 4) |
883 ((brdcfg[3] & 0x01) << 2) |
884 ((brdcfg[6] == 0x62) ? 3 :
885 ((brdcfg[6] == 0x5a) ? 2 :
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000886 ((brdcfg[6] == 0x5e) ? 1 : 0)));
York Sun9b85a482013-06-27 10:48:29 -0700887 sw[5] = ((brdcfg[0] & 0x0f) << 4) |
888 ((QIXIS_READ(rst_ctl) & 0x30) >> 2) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000889 ((brdcfg[0] & 0x40) >> 5);
York Sun9e698742013-03-25 07:40:14 +0000890 sw[6] = (brdcfg[11] & 0x20) |
891 ((brdcfg[5] & 0x02) << 3);
York Sun9b85a482013-06-27 10:48:29 -0700892 sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000893 ((brdcfg[5] & 0x10) << 2);
York Sun9b85a482013-06-27 10:48:29 -0700894 sw[8] = ((brdcfg[12] & 0x08) << 4) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000895 ((brdcfg[12] & 0x03) << 5);
896
897 puts("DIP switch (reverse-engineering)\n");
898 for (i = 0; i < 9; i++) {
899 printf("SW%d = 0b%s (0x%02x)\n",
York Sun9b85a482013-06-27 10:48:29 -0700900 i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000901 }
902}
York Sun844944c2013-03-25 07:40:01 +0000903
York Sun9b85a482013-06-27 10:48:29 -0700904static int do_vdd_adjust(cmd_tbl_t *cmdtp,
905 int flag, int argc,
906 char * const argv[])
York Sun844944c2013-03-25 07:40:01 +0000907{
908 ulong override;
909
910 if (argc < 2)
911 return CMD_RET_USAGE;
912 if (!strict_strtoul(argv[1], 10, &override))
913 adjust_vdd(override); /* the value is checked by callee */
914 else
915 return CMD_RET_USAGE;
916
917 return 0;
918}
919
920U_BOOT_CMD(
921 vdd_override, 2, 0, do_vdd_adjust,
922 "Override VDD",
923 "- override with the voltage specified in mV, eg. 1050"
924);