blob: 8d1a66f223a2dc48d6b3df747b0b140c521155ea [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 Glass2dc9c342020-05-10 11:40:01 -060012#include <image.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070014#include <irq_func.h>
Simon Glass0f2af882020-05-10 11:40:05 -060015#include <log.h>
York Sun667ab1a2012-10-11 07:13:37 +000016#include <netdev.h>
17#include <linux/compiler.h>
18#include <asm/mmu.h>
19#include <asm/processor.h>
20#include <asm/cache.h>
21#include <asm/immap_85xx.h>
22#include <asm/fsl_law.h>
23#include <asm/fsl_serdes.h>
York Sun667ab1a2012-10-11 07:13:37 +000024#include <asm/fsl_liodn.h>
25#include <fm_eth.h>
Simon Glassdbd79542020-05-10 11:40:11 -060026#include <linux/delay.h>
York Sun667ab1a2012-10-11 07:13:37 +000027
28#include "../common/qixis.h"
29#include "../common/vsc3316_3308.h"
30#include "t4qds.h"
31#include "t4240qds_qixis.h"
32
33DECLARE_GLOBAL_DATA_PTR;
34
Shaohui Xie3d8095e2013-08-19 18:43:07 +080035static int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
Timur Tabie9fabd82012-12-12 11:07:12 +000036 {8, 8}, {9, 9}, {14, 14}, {15, 15} };
37
Shaohui Xie3d8095e2013-08-19 18:43:07 +080038static int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
Timur Tabie9fabd82012-12-12 11:07:12 +000039 {10, 10}, {11, 11}, {12, 12}, {13, 13} };
40
Shaohui Xie3d8095e2013-08-19 18:43:07 +080041static int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
Timur Tabie9fabd82012-12-12 11:07:12 +000042 {10, 11}, {11, 10}, {12, 2}, {13, 3} };
43
Shaohui Xie3d8095e2013-08-19 18:43:07 +080044static int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
Timur Tabie9fabd82012-12-12 11:07:12 +000045 {8, 9}, {9, 8}, {14, 1}, {15, 0} };
46
York Sun667ab1a2012-10-11 07:13:37 +000047int checkboard(void)
48{
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000049 char buf[64];
York Sun667ab1a2012-10-11 07:13:37 +000050 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000051 struct cpu_type *cpu = gd->arch.cpu;
York Sun667ab1a2012-10-11 07:13:37 +000052 unsigned int i;
53
54 printf("Board: %sQDS, ", cpu->name);
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000055 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
York Sun9b85a482013-06-27 10:48:29 -070056 QIXIS_READ(id), QIXIS_READ(arch));
York Sun667ab1a2012-10-11 07:13:37 +000057
58 sw = QIXIS_READ(brdcfg[0]);
59 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
60
61 if (sw < 0x8)
62 printf("vBank: %d\n", sw);
63 else if (sw == 0x8)
64 puts("Promjet\n");
65 else if (sw == 0x9)
66 puts("NAND\n");
67 else
68 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
69
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000070 printf("FPGA: v%d (%s), build %d",
York Sun9b85a482013-06-27 10:48:29 -070071 (int)QIXIS_READ(scver), qixis_read_tag(buf),
72 (int)qixis_read_minor());
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000073 /* the timestamp string contains "\n" at the end */
74 printf(" on %s", qixis_read_time(buf));
75
York Sun667ab1a2012-10-11 07:13:37 +000076 /*
77 * Display the actual SERDES reference clocks as configured by the
78 * dip switches on the board. Note that the SWx registers could
79 * technically be set to force the reference clocks to match the
80 * values that the SERDES expects (or vice versa). For now, however,
81 * we just display both values and hope the user notices when they
82 * don't match.
83 */
84 puts("SERDES Reference Clocks: ");
85 sw = QIXIS_READ(brdcfg[2]);
86 for (i = 0; i < MAX_SERDES; i++) {
York Sun9b85a482013-06-27 10:48:29 -070087 static const char * const freq[] = {
York Sun667ab1a2012-10-11 07:13:37 +000088 "100", "125", "156.25", "161.1328125"};
Roy Zangc04362f2013-03-25 07:33:15 +000089 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +000090
91 printf("SERDES%u=%sMHz ", i+1, freq[clock]);
92 }
93 puts("\n");
94
95 return 0;
96}
97
Biwen Li3e9d3952020-05-01 20:04:17 +080098int select_i2c_ch_pca9547(u8 ch, int bus_num)
York Sun667ab1a2012-10-11 07:13:37 +000099{
100 int ret;
101
Biwen Li3e9d3952020-05-01 20:04:17 +0800102#ifdef CONFIG_DM_I2C
103 struct udevice *dev;
104
105 ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
106 1, &dev);
107 if (ret) {
108 printf("%s: Cannot find udev for a bus %d\n", __func__,
109 bus_num);
110 return ret;
111 }
112
113 ret = dm_i2c_write(dev, 0, &ch, 1);
114#else
York Sun667ab1a2012-10-11 07:13:37 +0000115 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
Biwen Li3e9d3952020-05-01 20:04:17 +0800116#endif
York Sun667ab1a2012-10-11 07:13:37 +0000117 if (ret) {
118 puts("PCA: failed to select proper channel\n");
119 return ret;
120 }
121
122 return 0;
123}
124
York Sund58bef12013-03-25 07:33:22 +0000125/*
126 * read_voltage from sensor on I2C bus
127 * We use average of 4 readings, waiting for 532us befor another reading
128 */
129#define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
130#define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
131
132static inline int read_voltage(void)
133{
134 int i, ret, voltage_read = 0;
135 u16 vol_mon;
Biwen Li3e9d3952020-05-01 20:04:17 +0800136#ifdef CONFIG_DM_I2C
137 struct udevice *dev;
138 int bus_num = 0;
139#endif
York Sund58bef12013-03-25 07:33:22 +0000140
141 for (i = 0; i < NUM_READINGS; i++) {
Biwen Li3e9d3952020-05-01 20:04:17 +0800142#ifdef CONFIG_DM_I2C
143 ret = i2c_get_chip_for_busnum(bus_num, I2C_VOL_MONITOR_ADDR,
144 1, &dev);
145 if (ret) {
146 printf("%s: Cannot find udev for a bus %d\n", __func__,
147 bus_num);
148 return ret;
149 }
150
151 ret = dm_i2c_read(dev,
152 I2C_VOL_MONITOR_BUS_V_OFFSET,
153 (void *)&vol_mon, 2);
154#else
York Sund58bef12013-03-25 07:33:22 +0000155 ret = i2c_read(I2C_VOL_MONITOR_ADDR,
156 I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
Biwen Li3e9d3952020-05-01 20:04:17 +0800157#endif
York Sund58bef12013-03-25 07:33:22 +0000158 if (ret) {
159 printf("VID: failed to read core voltage\n");
160 return ret;
161 }
162 if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
163 printf("VID: Core voltage sensor error\n");
164 return -1;
165 }
166 debug("VID: bus voltage reads 0x%04x\n", vol_mon);
167 /* LSB = 4mv */
168 voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
169 udelay(WAIT_FOR_ADC);
170 }
171 /* calculate the average */
172 voltage_read /= NUM_READINGS;
173
174 return voltage_read;
175}
176
177/*
178 * We need to calculate how long before the voltage starts to drop or increase
179 * It returns with the loop count. Each loop takes several readings (532us)
180 */
181static inline int wait_for_voltage_change(int vdd_last)
182{
183 int timeout, vdd_current;
184
185 vdd_current = read_voltage();
186 /* wait until voltage starts to drop */
187 for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
188 timeout < 100; timeout++) {
189 vdd_current = read_voltage();
190 }
191 if (timeout >= 100) {
192 printf("VID: Voltage adjustment timeout\n");
193 return -1;
194 }
195 return timeout;
196}
197
198/*
199 * argument 'wait' is the time we know the voltage difference can be measured
200 * this function keeps reading the voltage until it is stable
201 */
202static inline int wait_for_voltage_stable(int wait)
203{
204 int timeout, vdd_current, vdd_last;
205
206 vdd_last = read_voltage();
207 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
208 /* wait until voltage is stable */
209 vdd_current = read_voltage();
210 for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
211 timeout < 100; timeout++) {
212 vdd_last = vdd_current;
213 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
214 vdd_current = read_voltage();
215 }
216 if (timeout >= 100) {
217 printf("VID: Voltage adjustment timeout\n");
218 return -1;
219 }
220
221 return vdd_current;
222}
223
224static inline int set_voltage(u8 vid)
225{
226 int wait, vdd_last;
227
228 vdd_last = read_voltage();
229 QIXIS_WRITE(brdcfg[6], vid);
230 wait = wait_for_voltage_change(vdd_last);
231 if (wait < 0)
232 return -1;
233 debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
234 wait = wait ? wait : 1;
235
236 vdd_last = wait_for_voltage_stable(wait);
237 if (vdd_last < 0)
238 return -1;
239 debug("VID: Current voltage is %d mV\n", vdd_last);
240
241 return vdd_last;
242}
243
244
York Sun844944c2013-03-25 07:40:01 +0000245static int adjust_vdd(ulong vdd_override)
York Sund58bef12013-03-25 07:33:22 +0000246{
247 int re_enable = disable_interrupts();
248 ccsr_gur_t __iomem *gur =
249 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
250 u32 fusesr;
251 u8 vid, vid_current;
252 int vdd_target, vdd_current, vdd_last;
253 int ret;
York Sun844944c2013-03-25 07:40:01 +0000254 unsigned long vdd_string_override;
255 char *vdd_string;
York Sund58bef12013-03-25 07:33:22 +0000256 static const uint16_t vdd[32] = {
257 0, /* unused */
258 9875, /* 0.9875V */
259 9750,
260 9625,
261 9500,
262 9375,
263 9250,
264 9125,
265 9000,
266 8875,
267 8750,
268 8625,
269 8500,
270 8375,
271 8250,
272 8125,
273 10000, /* 1.0000V */
274 10125,
275 10250,
276 10375,
277 10500,
278 10625,
279 10750,
280 10875,
281 11000,
282 0, /* reserved */
283 };
284 struct vdd_drive {
285 u8 vid;
286 unsigned voltage;
287 };
288
Biwen Li3e9d3952020-05-01 20:04:17 +0800289 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR, 0);
York Sund58bef12013-03-25 07:33:22 +0000290 if (ret) {
291 debug("VID: I2c failed to switch channel\n");
292 ret = -1;
293 goto exit;
294 }
295
296 /* get the voltage ID from fuse status register */
297 fusesr = in_be32(&gur->dcfg_fusesr);
298 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
299 FSL_CORENET_DCFG_FUSESR_VID_MASK;
300 if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
301 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
302 FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
303 }
304 vdd_target = vdd[vid];
York Sun844944c2013-03-25 07:40:01 +0000305
306 /* check override variable for overriding VDD */
Simon Glass64b723f2017-08-03 12:22:12 -0600307 vdd_string = env_get("t4240qds_vdd_mv");
York Sun844944c2013-03-25 07:40:01 +0000308 if (vdd_override == 0 && vdd_string &&
309 !strict_strtoul(vdd_string, 10, &vdd_string_override))
310 vdd_override = vdd_string_override;
311 if (vdd_override >= 819 && vdd_override <= 1212) {
312 vdd_target = vdd_override * 10; /* convert to 1/10 mV */
313 debug("VDD override is %lu\n", vdd_override);
314 } else if (vdd_override != 0) {
315 printf("Invalid value.\n");
316 }
317
York Sund58bef12013-03-25 07:33:22 +0000318 if (vdd_target == 0) {
319 debug("VID: VID not used\n");
320 ret = 0;
321 goto exit;
322 } else {
323 /* round up and divice by 10 to get a value in mV */
324 vdd_target = DIV_ROUND_UP(vdd_target, 10);
325 debug("VID: vid = %d mV\n", vdd_target);
326 }
327
328 /*
329 * Check current board VID setting
330 * Voltage regulator support output to 6.250mv step
331 * The highes voltage allowed for this board is (vid=0x40) 1.21250V
332 * the lowest is (vid=0x7f) 0.81875V
333 */
334 vid_current = QIXIS_READ(brdcfg[6]);
335 vdd_current = 121250 - (vid_current - 0x40) * 625;
336 debug("VID: Current vid setting is (0x%x) %d mV\n",
337 vid_current, vdd_current/100);
338
339 /*
340 * Read voltage monitor to check real voltage.
341 * Voltage monitor LSB is 4mv.
342 */
343 vdd_last = read_voltage();
344 if (vdd_last < 0) {
345 printf("VID: Could not read voltage sensor abort VID adjustment\n");
346 ret = -1;
347 goto exit;
348 }
349 debug("VID: Core voltage is at %d mV\n", vdd_last);
350 /*
351 * Adjust voltage to at or 8mV above target.
352 * Each step of adjustment is 6.25mV.
353 * Stepping down too fast may cause over current.
354 */
355 while (vdd_last > 0 && vid_current < 0x80 &&
356 vdd_last > (vdd_target + 8)) {
357 vid_current++;
358 vdd_last = set_voltage(vid_current);
359 }
360 /*
361 * Check if we need to step up
362 * This happens when board voltage switch was set too low
363 */
364 while (vdd_last > 0 && vid_current >= 0x40 &&
365 vdd_last < vdd_target + 2) {
366 vid_current--;
367 vdd_last = set_voltage(vid_current);
368 }
369 if (vdd_last > 0)
370 printf("VID: Core voltage %d mV\n", vdd_last);
371 else
372 ret = -1;
373
374exit:
375 if (re_enable)
376 enable_interrupts();
377 return ret;
378}
379
York Sun667ab1a2012-10-11 07:13:37 +0000380/* Configure Crossbar switches for Front-Side SerDes Ports */
381int config_frontside_crossbar_vsc3316(void)
382{
383 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
384 u32 srds_prtcl_s1, srds_prtcl_s2;
385 int ret;
386
Biwen Li3e9d3952020-05-01 20:04:17 +0800387 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS, 0);
York Sun667ab1a2012-10-11 07:13:37 +0000388 if (ret)
389 return ret;
390
391 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
392 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
393 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800394 switch (srds_prtcl_s1) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800395 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800396 case 38:
397 /* swap first lane and third lane on slot1 */
398 vsc3316_fsm1_tx[0][1] = 14;
399 vsc3316_fsm1_tx[6][1] = 0;
400 vsc3316_fsm1_rx[1][1] = 2;
401 vsc3316_fsm1_rx[6][1] = 13;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800402 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800403 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800404 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800405 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800406 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800407 case 48:
408 /* swap first lane and third lane on slot2 */
409 vsc3316_fsm1_tx[2][1] = 8;
410 vsc3316_fsm1_tx[4][1] = 6;
411 vsc3316_fsm1_rx[2][1] = 10;
412 vsc3316_fsm1_rx[5][1] = 5;
413 default:
York Sun667ab1a2012-10-11 07:13:37 +0000414 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
415 if (ret)
416 return ret;
417 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
418 if (ret)
419 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800420 break;
York Sun667ab1a2012-10-11 07:13:37 +0000421 }
422
423 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
424 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
425 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800426 switch (srds_prtcl_s2) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800427 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800428 case 38:
429 /* swap first lane and third lane on slot3 */
430 vsc3316_fsm2_tx[2][1] = 11;
431 vsc3316_fsm2_tx[5][1] = 4;
432 vsc3316_fsm2_rx[2][1] = 9;
433 vsc3316_fsm2_rx[4][1] = 7;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800434 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800435 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800436 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800437 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800438 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800439 case 48:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800440 case 49:
Shaohui Xie6e078702013-08-19 18:57:57 +0800441 case 50:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800442 case 51:
Shaohui Xie6e078702013-08-19 18:57:57 +0800443 case 52:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800444 case 53:
Shaohui Xie6e078702013-08-19 18:57:57 +0800445 case 54:
446 /* swap first lane and third lane on slot4 */
447 vsc3316_fsm2_tx[6][1] = 3;
448 vsc3316_fsm2_tx[1][1] = 12;
449 vsc3316_fsm2_rx[0][1] = 1;
450 vsc3316_fsm2_rx[6][1] = 15;
451 default:
York Sun667ab1a2012-10-11 07:13:37 +0000452 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
453 if (ret)
454 return ret;
455 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
456 if (ret)
457 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800458 break;
York Sun667ab1a2012-10-11 07:13:37 +0000459 }
460
461 return 0;
462}
463
464int config_backside_crossbar_mux(void)
465{
466 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
467 u32 srds_prtcl_s3, srds_prtcl_s4;
468 u8 brdcfg;
469
470 srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
471 FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
472 srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
473 switch (srds_prtcl_s3) {
474 case 0:
475 /* SerDes3 is not enabled */
476 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800477 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000478 case 2:
479 case 9:
480 case 10:
481 /* SD3(0:7) => SLOT5(0:7) */
482 brdcfg = QIXIS_READ(brdcfg[12]);
483 brdcfg &= ~BRDCFG12_SD3MX_MASK;
484 brdcfg |= BRDCFG12_SD3MX_SLOT5;
485 QIXIS_WRITE(brdcfg[12], brdcfg);
486 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800487 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000488 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800489 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000490 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800491 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000492 case 8:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800493 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000494 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800495 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000496 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800497 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000498 case 16:
499 case 17:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800500 case 18:
York Sun667ab1a2012-10-11 07:13:37 +0000501 case 19:
502 case 20:
503 /* SD3(4:7) => SLOT6(0:3) */
504 brdcfg = QIXIS_READ(brdcfg[12]);
505 brdcfg &= ~BRDCFG12_SD3MX_MASK;
506 brdcfg |= BRDCFG12_SD3MX_SLOT6;
507 QIXIS_WRITE(brdcfg[12], brdcfg);
508 break;
509 default:
510 printf("WARNING: unsupported for SerDes3 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700511 srds_prtcl_s3);
York Sun667ab1a2012-10-11 07:13:37 +0000512 return -1;
513 }
514
515 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
516 FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
517 srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
518 switch (srds_prtcl_s4) {
519 case 0:
520 /* SerDes4 is not enabled */
521 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800522 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000523 case 2:
524 /* 10b, SD4(0:7) => SLOT7(0:7) */
525 brdcfg = QIXIS_READ(brdcfg[12]);
526 brdcfg &= ~BRDCFG12_SD4MX_MASK;
527 brdcfg |= BRDCFG12_SD4MX_SLOT7;
528 QIXIS_WRITE(brdcfg[12], brdcfg);
529 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800530 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000531 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800532 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000533 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800534 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000535 case 8:
536 /* x1b, SD4(4:7) => SLOT8(0:3) */
537 brdcfg = QIXIS_READ(brdcfg[12]);
538 brdcfg &= ~BRDCFG12_SD4MX_MASK;
539 brdcfg |= BRDCFG12_SD4MX_SLOT8;
540 QIXIS_WRITE(brdcfg[12], brdcfg);
541 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800542 case 9:
York Sun667ab1a2012-10-11 07:13:37 +0000543 case 10:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800544 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000545 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800546 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000547 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800548 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000549 case 16:
550 case 18:
551 /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
552 brdcfg = QIXIS_READ(brdcfg[12]);
553 brdcfg &= ~BRDCFG12_SD4MX_MASK;
554 brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
555 QIXIS_WRITE(brdcfg[12], brdcfg);
556 break;
557 default:
558 printf("WARNING: unsupported for SerDes4 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700559 srds_prtcl_s4);
York Sun667ab1a2012-10-11 07:13:37 +0000560 return -1;
561 }
562
563 return 0;
564}
565
566int board_early_init_r(void)
567{
568 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700569 int flash_esel = find_tlb_idx((void *)flashbase, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000570
571 /*
572 * Remap Boot flash + PROMJET region to caching-inhibited
573 * so that flash can be erased properly.
574 */
575
576 /* Flush d-cache and invalidate i-cache of any FLASH data */
577 flush_dcache();
578 invalidate_icache();
579
York Sun220c3462014-06-24 21:16:20 -0700580 if (flash_esel == -1) {
581 /* very unlikely unless something is messed up */
582 puts("Error: Could not find TLB for FLASH BASE\n");
583 flash_esel = 2; /* give our best effort to continue */
584 } else {
585 /* invalidate existing TLB entry for flash + promjet */
586 disable_tlb(flash_esel);
587 }
York Sun667ab1a2012-10-11 07:13:37 +0000588
589 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
York Sun9b85a482013-06-27 10:48:29 -0700590 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
591 0, flash_esel, BOOKE_PAGESZ_256M, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000592
Ed Swarthouta55ec452013-03-25 07:39:37 +0000593 /* Disable remote I2C connection to qixis fpga */
594 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
York Sun667ab1a2012-10-11 07:13:37 +0000595
York Sund58bef12013-03-25 07:33:22 +0000596 /*
597 * Adjust core voltage according to voltage ID
598 * This function changes I2C mux to channel 2.
599 */
York Sun844944c2013-03-25 07:40:01 +0000600 if (adjust_vdd(0))
York Sund58bef12013-03-25 07:33:22 +0000601 printf("Warning: Adjusting core voltage failed.\n");
602
York Sun667ab1a2012-10-11 07:13:37 +0000603 /* Configure board SERDES ports crossbar */
604 config_frontside_crossbar_vsc3316();
605 config_backside_crossbar_mux();
Biwen Li3e9d3952020-05-01 20:04:17 +0800606 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
York Sun667ab1a2012-10-11 07:13:37 +0000607
608 return 0;
609}
610
611unsigned long get_board_sys_clk(void)
612{
613 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000614#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
615 /* use accurate clock measurement */
616 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
617 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
618 u32 val;
619
620 val = freq * base;
621 if (val) {
622 debug("SYS Clock measurement is: %d\n", val);
623 return val;
624 } else {
625 printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
626 }
627#endif
York Sun667ab1a2012-10-11 07:13:37 +0000628
629 switch (sysclk_conf & 0x0F) {
630 case QIXIS_SYSCLK_83:
631 return 83333333;
632 case QIXIS_SYSCLK_100:
633 return 100000000;
634 case QIXIS_SYSCLK_125:
635 return 125000000;
636 case QIXIS_SYSCLK_133:
637 return 133333333;
638 case QIXIS_SYSCLK_150:
639 return 150000000;
640 case QIXIS_SYSCLK_160:
641 return 160000000;
642 case QIXIS_SYSCLK_166:
643 return 166666666;
644 }
645 return 66666666;
646}
647
648unsigned long get_board_ddr_clk(void)
649{
650 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000651#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
652 /* use accurate clock measurement */
653 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
654 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
655 u32 val;
656
657 val = freq * base;
658 if (val) {
659 debug("DDR Clock measurement is: %d\n", val);
660 return val;
661 } else {
662 printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
663 }
664#endif
York Sun667ab1a2012-10-11 07:13:37 +0000665
666 switch ((ddrclk_conf & 0x30) >> 4) {
667 case QIXIS_DDRCLK_100:
668 return 100000000;
669 case QIXIS_DDRCLK_125:
670 return 125000000;
671 case QIXIS_DDRCLK_133:
672 return 133333333;
673 }
674 return 66666666;
675}
676
York Sun667ab1a2012-10-11 07:13:37 +0000677int misc_init_r(void)
678{
679 u8 sw;
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800680 void *srds_base = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
681 serdes_corenet_t *srds_regs;
York Sun667ab1a2012-10-11 07:13:37 +0000682 u32 actual[MAX_SERDES];
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800683 u32 pllcr0, expected;
York Sun667ab1a2012-10-11 07:13:37 +0000684 unsigned int i;
685
686 sw = QIXIS_READ(brdcfg[2]);
687 for (i = 0; i < MAX_SERDES; i++) {
Roy Zangc04362f2013-03-25 07:33:15 +0000688 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +0000689 switch (clock) {
690 case 0:
691 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
692 break;
693 case 1:
694 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
695 break;
696 case 2:
697 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
698 break;
699 case 3:
700 actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
701 break;
702 }
703 }
704
705 for (i = 0; i < MAX_SERDES; i++) {
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800706 srds_regs = srds_base + i * 0x1000;
707 pllcr0 = srds_regs->bank[0].pllcr0;
708 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
York Sun667ab1a2012-10-11 07:13:37 +0000709 if (expected != actual[i]) {
York Sun9b85a482013-06-27 10:48:29 -0700710 printf("Warning: SERDES%u expects reference clock %sMHz, but actual is %sMHz\n",
711 i + 1, serdes_clock_to_string(expected),
York Sun667ab1a2012-10-11 07:13:37 +0000712 serdes_clock_to_string(actual[i]));
713 }
714 }
715
716 return 0;
717}
718
Simon Glass2aec3cc2014-10-23 18:58:47 -0600719int ft_board_setup(void *blob, bd_t *bd)
York Sun667ab1a2012-10-11 07:13:37 +0000720{
721 phys_addr_t base;
722 phys_size_t size;
723
724 ft_cpu_setup(blob, bd);
725
Simon Glassda1a1342017-08-03 12:22:15 -0600726 base = env_get_bootm_low();
727 size = env_get_bootm_size();
York Sun667ab1a2012-10-11 07:13:37 +0000728
729 fdt_fixup_memory(blob, (u64)base, (u64)size);
730
731#ifdef CONFIG_PCI
732 pci_of_setup(blob, bd);
733#endif
734
735 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530736 fsl_fdt_fixup_dr_usb(blob, bd);
York Sun667ab1a2012-10-11 07:13:37 +0000737
738#ifdef CONFIG_SYS_DPAA_FMAN
739 fdt_fixup_fman_ethernet(blob);
740 fdt_fixup_board_enet(blob);
741#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600742
743 return 0;
York Sun667ab1a2012-10-11 07:13:37 +0000744}
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000745
746/*
York Sun997f5122013-03-25 07:39:24 +0000747 * This function is called by bdinfo to print detail board information.
748 * As an exmaple for future board, we organize the messages into
749 * several sections. If applicable, the message is in the format of
750 * <name> = <value>
751 * It should aligned with normal output of bdinfo command.
752 *
753 * Voltage: Core, DDR and another configurable voltages
754 * Clock : Critical clocks which are not printed already
755 * RCW : RCW source if not printed already
756 * Misc : Other important information not in above catagories
757 */
758void board_detail(void)
759{
760 int i;
761 u8 brdcfg[16], dutcfg[16], rst_ctl;
762 int vdd, rcwsrc;
763 static const char * const clk[] = {"66.67", "100", "125", "133.33"};
764
765 for (i = 0; i < 16; i++) {
766 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
767 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
768 }
769
770 /* Voltage secion */
Biwen Li3e9d3952020-05-01 20:04:17 +0800771 if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR, 0)) {
York Sun997f5122013-03-25 07:39:24 +0000772 vdd = read_voltage();
773 if (vdd > 0)
774 printf("Core voltage= %d mV\n", vdd);
Biwen Li3e9d3952020-05-01 20:04:17 +0800775 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
York Sun997f5122013-03-25 07:39:24 +0000776 }
777
778 printf("XVDD = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
779
780 /* clock section */
781 printf("SYSCLK = %s MHz\nDDRCLK = %s MHz\n",
782 clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
783
784 /* RCW section */
785 rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
786 puts("RCW source = ");
787 switch (rcwsrc) {
788 case 0x017:
789 case 0x01f:
790 puts("8-bit NOR\n");
791 break;
792 case 0x027:
793 case 0x02F:
794 puts("16-bit NOR\n");
795 break;
796 case 0x040:
797 puts("SDHC/eMMC\n");
798 break;
799 case 0x044:
800 puts("SPI 16-bit addressing\n");
801 break;
802 case 0x045:
803 puts("SPI 24-bit addressing\n");
804 break;
805 case 0x048:
806 puts("I2C normal addressing\n");
807 break;
808 case 0x049:
809 puts("I2C extended addressing\n");
810 break;
811 case 0x108:
812 case 0x109:
813 case 0x10a:
814 case 0x10b:
815 puts("8-bit NAND, 2KB\n");
816 break;
817 default:
818 if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
819 puts("Hard-coded RCW\n");
820 else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
821 puts("8-bit NAND, 4KB\n");
822 else
823 puts("unknown\n");
824 break;
825 }
826
827 /* Misc section */
828 rst_ctl = QIXIS_READ(rst_ctl);
829 puts("HRESET_REQ = ");
830 switch (rst_ctl & 0x30) {
831 case 0x00:
832 puts("Ignored\n");
833 break;
834 case 0x10:
835 puts("Assert HRESET\n");
836 break;
837 case 0x30:
838 puts("Reset system\n");
839 break;
840 default:
841 puts("N/A\n");
842 break;
843 }
844}
845
846/*
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000847 * Reverse engineering switch settings.
848 * Some bits cannot be figured out. They will be displayed as
849 * underscore in binary format. mask[] has those bits.
850 * Some bits are calculated differently than the actual switches
851 * if booting with overriding by FPGA.
852 */
853void qixis_dump_switch(void)
854{
855 int i;
856 u8 sw[9];
857
858 /*
859 * Any bit with 1 means that bit cannot be reverse engineered.
860 * It will be displayed as _ in binary format.
861 */
York Sun9e698742013-03-25 07:40:14 +0000862 static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000863 char buf[10];
864 u8 brdcfg[16], dutcfg[16];
865
866 for (i = 0; i < 16; i++) {
867 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
868 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
869 }
870
871 sw[0] = dutcfg[0];
York Sun9b85a482013-06-27 10:48:29 -0700872 sw[1] = (dutcfg[1] << 0x07) |
873 ((dutcfg[12] & 0xC0) >> 1) |
874 ((dutcfg[11] & 0xE0) >> 3) |
875 ((dutcfg[6] & 0x80) >> 6) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000876 ((dutcfg[1] & 0x80) >> 7);
York Sun9b85a482013-06-27 10:48:29 -0700877 sw[2] = ((brdcfg[1] & 0x0f) << 4) |
878 ((brdcfg[1] & 0x30) >> 2) |
879 ((brdcfg[1] & 0x40) >> 5) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000880 ((brdcfg[1] & 0x80) >> 7);
881 sw[3] = brdcfg[2];
York Sun9b85a482013-06-27 10:48:29 -0700882 sw[4] = ((dutcfg[2] & 0x01) << 7) |
883 ((dutcfg[2] & 0x06) << 4) |
884 ((~QIXIS_READ(present)) & 0x10) |
885 ((brdcfg[3] & 0x80) >> 4) |
886 ((brdcfg[3] & 0x01) << 2) |
887 ((brdcfg[6] == 0x62) ? 3 :
888 ((brdcfg[6] == 0x5a) ? 2 :
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000889 ((brdcfg[6] == 0x5e) ? 1 : 0)));
York Sun9b85a482013-06-27 10:48:29 -0700890 sw[5] = ((brdcfg[0] & 0x0f) << 4) |
891 ((QIXIS_READ(rst_ctl) & 0x30) >> 2) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000892 ((brdcfg[0] & 0x40) >> 5);
York Sun9e698742013-03-25 07:40:14 +0000893 sw[6] = (brdcfg[11] & 0x20) |
894 ((brdcfg[5] & 0x02) << 3);
York Sun9b85a482013-06-27 10:48:29 -0700895 sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000896 ((brdcfg[5] & 0x10) << 2);
York Sun9b85a482013-06-27 10:48:29 -0700897 sw[8] = ((brdcfg[12] & 0x08) << 4) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000898 ((brdcfg[12] & 0x03) << 5);
899
900 puts("DIP switch (reverse-engineering)\n");
901 for (i = 0; i < 9; i++) {
902 printf("SW%d = 0b%s (0x%02x)\n",
York Sun9b85a482013-06-27 10:48:29 -0700903 i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000904 }
905}
York Sun844944c2013-03-25 07:40:01 +0000906
Simon Glassed38aef2020-05-10 11:40:03 -0600907static int do_vdd_adjust(struct cmd_tbl *cmdtp,
York Sun9b85a482013-06-27 10:48:29 -0700908 int flag, int argc,
Simon Glassed38aef2020-05-10 11:40:03 -0600909 char *const argv[])
York Sun844944c2013-03-25 07:40:01 +0000910{
911 ulong override;
912
913 if (argc < 2)
914 return CMD_RET_USAGE;
915 if (!strict_strtoul(argv[1], 10, &override))
916 adjust_vdd(override); /* the value is checked by callee */
917 else
918 return CMD_RET_USAGE;
919
920 return 0;
921}
922
923U_BOOT_CMD(
924 vdd_override, 2, 0, do_vdd_adjust,
925 "Override VDD",
926 "- override with the voltage specified in mV, eg. 1050"
927);