blob: 11f7489fa21840f3fcfc07f7a4bb8b2443316180 [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.
York Sun667ab1a2012-10-11 07:13:37 +00004 */
5
6#include <common.h>
7#include <command.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -06008#include <env.h>
York Sun667ab1a2012-10-11 07:13:37 +00009#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070011#include <irq_func.h>
York Sun667ab1a2012-10-11 07:13:37 +000012#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>
York Sun667ab1a2012-10-11 07:13:37 +000020#include <asm/fsl_liodn.h>
21#include <fm_eth.h>
22
23#include "../common/qixis.h"
24#include "../common/vsc3316_3308.h"
25#include "t4qds.h"
26#include "t4240qds_qixis.h"
27
28DECLARE_GLOBAL_DATA_PTR;
29
Shaohui Xie3d8095e2013-08-19 18:43:07 +080030static int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
Timur Tabie9fabd82012-12-12 11:07:12 +000031 {8, 8}, {9, 9}, {14, 14}, {15, 15} };
32
Shaohui Xie3d8095e2013-08-19 18:43:07 +080033static int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
Timur Tabie9fabd82012-12-12 11:07:12 +000034 {10, 10}, {11, 11}, {12, 12}, {13, 13} };
35
Shaohui Xie3d8095e2013-08-19 18:43:07 +080036static int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
Timur Tabie9fabd82012-12-12 11:07:12 +000037 {10, 11}, {11, 10}, {12, 2}, {13, 3} };
38
Shaohui Xie3d8095e2013-08-19 18:43:07 +080039static int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
Timur Tabie9fabd82012-12-12 11:07:12 +000040 {8, 9}, {9, 8}, {14, 1}, {15, 0} };
41
York Sun667ab1a2012-10-11 07:13:37 +000042int checkboard(void)
43{
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000044 char buf[64];
York Sun667ab1a2012-10-11 07:13:37 +000045 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000046 struct cpu_type *cpu = gd->arch.cpu;
York Sun667ab1a2012-10-11 07:13:37 +000047 unsigned int i;
48
49 printf("Board: %sQDS, ", cpu->name);
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000050 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
York Sun9b85a482013-06-27 10:48:29 -070051 QIXIS_READ(id), QIXIS_READ(arch));
York Sun667ab1a2012-10-11 07:13:37 +000052
53 sw = QIXIS_READ(brdcfg[0]);
54 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
55
56 if (sw < 0x8)
57 printf("vBank: %d\n", sw);
58 else if (sw == 0x8)
59 puts("Promjet\n");
60 else if (sw == 0x9)
61 puts("NAND\n");
62 else
63 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
64
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000065 printf("FPGA: v%d (%s), build %d",
York Sun9b85a482013-06-27 10:48:29 -070066 (int)QIXIS_READ(scver), qixis_read_tag(buf),
67 (int)qixis_read_minor());
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000068 /* the timestamp string contains "\n" at the end */
69 printf(" on %s", qixis_read_time(buf));
70
York Sun667ab1a2012-10-11 07:13:37 +000071 /*
72 * Display the actual SERDES reference clocks as configured by the
73 * dip switches on the board. Note that the SWx registers could
74 * technically be set to force the reference clocks to match the
75 * values that the SERDES expects (or vice versa). For now, however,
76 * we just display both values and hope the user notices when they
77 * don't match.
78 */
79 puts("SERDES Reference Clocks: ");
80 sw = QIXIS_READ(brdcfg[2]);
81 for (i = 0; i < MAX_SERDES; i++) {
York Sun9b85a482013-06-27 10:48:29 -070082 static const char * const freq[] = {
York Sun667ab1a2012-10-11 07:13:37 +000083 "100", "125", "156.25", "161.1328125"};
Roy Zangc04362f2013-03-25 07:33:15 +000084 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +000085
86 printf("SERDES%u=%sMHz ", i+1, freq[clock]);
87 }
88 puts("\n");
89
90 return 0;
91}
92
93int select_i2c_ch_pca9547(u8 ch)
94{
95 int ret;
96
97 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
98 if (ret) {
99 puts("PCA: failed to select proper channel\n");
100 return ret;
101 }
102
103 return 0;
104}
105
York Sund58bef12013-03-25 07:33:22 +0000106/*
107 * read_voltage from sensor on I2C bus
108 * We use average of 4 readings, waiting for 532us befor another reading
109 */
110#define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
111#define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
112
113static inline int read_voltage(void)
114{
115 int i, ret, voltage_read = 0;
116 u16 vol_mon;
117
118 for (i = 0; i < NUM_READINGS; i++) {
119 ret = i2c_read(I2C_VOL_MONITOR_ADDR,
120 I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
121 if (ret) {
122 printf("VID: failed to read core voltage\n");
123 return ret;
124 }
125 if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
126 printf("VID: Core voltage sensor error\n");
127 return -1;
128 }
129 debug("VID: bus voltage reads 0x%04x\n", vol_mon);
130 /* LSB = 4mv */
131 voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
132 udelay(WAIT_FOR_ADC);
133 }
134 /* calculate the average */
135 voltage_read /= NUM_READINGS;
136
137 return voltage_read;
138}
139
140/*
141 * We need to calculate how long before the voltage starts to drop or increase
142 * It returns with the loop count. Each loop takes several readings (532us)
143 */
144static inline int wait_for_voltage_change(int vdd_last)
145{
146 int timeout, vdd_current;
147
148 vdd_current = read_voltage();
149 /* wait until voltage starts to drop */
150 for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
151 timeout < 100; timeout++) {
152 vdd_current = read_voltage();
153 }
154 if (timeout >= 100) {
155 printf("VID: Voltage adjustment timeout\n");
156 return -1;
157 }
158 return timeout;
159}
160
161/*
162 * argument 'wait' is the time we know the voltage difference can be measured
163 * this function keeps reading the voltage until it is stable
164 */
165static inline int wait_for_voltage_stable(int wait)
166{
167 int timeout, vdd_current, vdd_last;
168
169 vdd_last = read_voltage();
170 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
171 /* wait until voltage is stable */
172 vdd_current = read_voltage();
173 for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
174 timeout < 100; timeout++) {
175 vdd_last = vdd_current;
176 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
177 vdd_current = read_voltage();
178 }
179 if (timeout >= 100) {
180 printf("VID: Voltage adjustment timeout\n");
181 return -1;
182 }
183
184 return vdd_current;
185}
186
187static inline int set_voltage(u8 vid)
188{
189 int wait, vdd_last;
190
191 vdd_last = read_voltage();
192 QIXIS_WRITE(brdcfg[6], vid);
193 wait = wait_for_voltage_change(vdd_last);
194 if (wait < 0)
195 return -1;
196 debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
197 wait = wait ? wait : 1;
198
199 vdd_last = wait_for_voltage_stable(wait);
200 if (vdd_last < 0)
201 return -1;
202 debug("VID: Current voltage is %d mV\n", vdd_last);
203
204 return vdd_last;
205}
206
207
York Sun844944c2013-03-25 07:40:01 +0000208static int adjust_vdd(ulong vdd_override)
York Sund58bef12013-03-25 07:33:22 +0000209{
210 int re_enable = disable_interrupts();
211 ccsr_gur_t __iomem *gur =
212 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
213 u32 fusesr;
214 u8 vid, vid_current;
215 int vdd_target, vdd_current, vdd_last;
216 int ret;
York Sun844944c2013-03-25 07:40:01 +0000217 unsigned long vdd_string_override;
218 char *vdd_string;
York Sund58bef12013-03-25 07:33:22 +0000219 static const uint16_t vdd[32] = {
220 0, /* unused */
221 9875, /* 0.9875V */
222 9750,
223 9625,
224 9500,
225 9375,
226 9250,
227 9125,
228 9000,
229 8875,
230 8750,
231 8625,
232 8500,
233 8375,
234 8250,
235 8125,
236 10000, /* 1.0000V */
237 10125,
238 10250,
239 10375,
240 10500,
241 10625,
242 10750,
243 10875,
244 11000,
245 0, /* reserved */
246 };
247 struct vdd_drive {
248 u8 vid;
249 unsigned voltage;
250 };
251
252 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR);
253 if (ret) {
254 debug("VID: I2c failed to switch channel\n");
255 ret = -1;
256 goto exit;
257 }
258
259 /* get the voltage ID from fuse status register */
260 fusesr = in_be32(&gur->dcfg_fusesr);
261 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
262 FSL_CORENET_DCFG_FUSESR_VID_MASK;
263 if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
264 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
265 FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
266 }
267 vdd_target = vdd[vid];
York Sun844944c2013-03-25 07:40:01 +0000268
269 /* check override variable for overriding VDD */
Simon Glass64b723f2017-08-03 12:22:12 -0600270 vdd_string = env_get("t4240qds_vdd_mv");
York Sun844944c2013-03-25 07:40:01 +0000271 if (vdd_override == 0 && vdd_string &&
272 !strict_strtoul(vdd_string, 10, &vdd_string_override))
273 vdd_override = vdd_string_override;
274 if (vdd_override >= 819 && vdd_override <= 1212) {
275 vdd_target = vdd_override * 10; /* convert to 1/10 mV */
276 debug("VDD override is %lu\n", vdd_override);
277 } else if (vdd_override != 0) {
278 printf("Invalid value.\n");
279 }
280
York Sund58bef12013-03-25 07:33:22 +0000281 if (vdd_target == 0) {
282 debug("VID: VID not used\n");
283 ret = 0;
284 goto exit;
285 } else {
286 /* round up and divice by 10 to get a value in mV */
287 vdd_target = DIV_ROUND_UP(vdd_target, 10);
288 debug("VID: vid = %d mV\n", vdd_target);
289 }
290
291 /*
292 * Check current board VID setting
293 * Voltage regulator support output to 6.250mv step
294 * The highes voltage allowed for this board is (vid=0x40) 1.21250V
295 * the lowest is (vid=0x7f) 0.81875V
296 */
297 vid_current = QIXIS_READ(brdcfg[6]);
298 vdd_current = 121250 - (vid_current - 0x40) * 625;
299 debug("VID: Current vid setting is (0x%x) %d mV\n",
300 vid_current, vdd_current/100);
301
302 /*
303 * Read voltage monitor to check real voltage.
304 * Voltage monitor LSB is 4mv.
305 */
306 vdd_last = read_voltage();
307 if (vdd_last < 0) {
308 printf("VID: Could not read voltage sensor abort VID adjustment\n");
309 ret = -1;
310 goto exit;
311 }
312 debug("VID: Core voltage is at %d mV\n", vdd_last);
313 /*
314 * Adjust voltage to at or 8mV above target.
315 * Each step of adjustment is 6.25mV.
316 * Stepping down too fast may cause over current.
317 */
318 while (vdd_last > 0 && vid_current < 0x80 &&
319 vdd_last > (vdd_target + 8)) {
320 vid_current++;
321 vdd_last = set_voltage(vid_current);
322 }
323 /*
324 * Check if we need to step up
325 * This happens when board voltage switch was set too low
326 */
327 while (vdd_last > 0 && vid_current >= 0x40 &&
328 vdd_last < vdd_target + 2) {
329 vid_current--;
330 vdd_last = set_voltage(vid_current);
331 }
332 if (vdd_last > 0)
333 printf("VID: Core voltage %d mV\n", vdd_last);
334 else
335 ret = -1;
336
337exit:
338 if (re_enable)
339 enable_interrupts();
340 return ret;
341}
342
York Sun667ab1a2012-10-11 07:13:37 +0000343/* Configure Crossbar switches for Front-Side SerDes Ports */
344int config_frontside_crossbar_vsc3316(void)
345{
346 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
347 u32 srds_prtcl_s1, srds_prtcl_s2;
348 int ret;
349
350 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS);
351 if (ret)
352 return ret;
353
354 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
355 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
356 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800357 switch (srds_prtcl_s1) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800358 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800359 case 38:
360 /* swap first lane and third lane on slot1 */
361 vsc3316_fsm1_tx[0][1] = 14;
362 vsc3316_fsm1_tx[6][1] = 0;
363 vsc3316_fsm1_rx[1][1] = 2;
364 vsc3316_fsm1_rx[6][1] = 13;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800365 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800366 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800367 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800368 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800369 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800370 case 48:
371 /* swap first lane and third lane on slot2 */
372 vsc3316_fsm1_tx[2][1] = 8;
373 vsc3316_fsm1_tx[4][1] = 6;
374 vsc3316_fsm1_rx[2][1] = 10;
375 vsc3316_fsm1_rx[5][1] = 5;
376 default:
York Sun667ab1a2012-10-11 07:13:37 +0000377 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
378 if (ret)
379 return ret;
380 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
381 if (ret)
382 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800383 break;
York Sun667ab1a2012-10-11 07:13:37 +0000384 }
385
386 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
387 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
388 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800389 switch (srds_prtcl_s2) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800390 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800391 case 38:
392 /* swap first lane and third lane on slot3 */
393 vsc3316_fsm2_tx[2][1] = 11;
394 vsc3316_fsm2_tx[5][1] = 4;
395 vsc3316_fsm2_rx[2][1] = 9;
396 vsc3316_fsm2_rx[4][1] = 7;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800397 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800398 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800399 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800400 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800401 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800402 case 48:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800403 case 49:
Shaohui Xie6e078702013-08-19 18:57:57 +0800404 case 50:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800405 case 51:
Shaohui Xie6e078702013-08-19 18:57:57 +0800406 case 52:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800407 case 53:
Shaohui Xie6e078702013-08-19 18:57:57 +0800408 case 54:
409 /* swap first lane and third lane on slot4 */
410 vsc3316_fsm2_tx[6][1] = 3;
411 vsc3316_fsm2_tx[1][1] = 12;
412 vsc3316_fsm2_rx[0][1] = 1;
413 vsc3316_fsm2_rx[6][1] = 15;
414 default:
York Sun667ab1a2012-10-11 07:13:37 +0000415 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
416 if (ret)
417 return ret;
418 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
419 if (ret)
420 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800421 break;
York Sun667ab1a2012-10-11 07:13:37 +0000422 }
423
424 return 0;
425}
426
427int config_backside_crossbar_mux(void)
428{
429 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
430 u32 srds_prtcl_s3, srds_prtcl_s4;
431 u8 brdcfg;
432
433 srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
434 FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
435 srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
436 switch (srds_prtcl_s3) {
437 case 0:
438 /* SerDes3 is not enabled */
439 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800440 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000441 case 2:
442 case 9:
443 case 10:
444 /* SD3(0:7) => SLOT5(0:7) */
445 brdcfg = QIXIS_READ(brdcfg[12]);
446 brdcfg &= ~BRDCFG12_SD3MX_MASK;
447 brdcfg |= BRDCFG12_SD3MX_SLOT5;
448 QIXIS_WRITE(brdcfg[12], brdcfg);
449 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800450 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000451 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800452 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000453 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800454 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000455 case 8:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800456 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000457 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800458 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000459 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800460 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000461 case 16:
462 case 17:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800463 case 18:
York Sun667ab1a2012-10-11 07:13:37 +0000464 case 19:
465 case 20:
466 /* SD3(4:7) => SLOT6(0:3) */
467 brdcfg = QIXIS_READ(brdcfg[12]);
468 brdcfg &= ~BRDCFG12_SD3MX_MASK;
469 brdcfg |= BRDCFG12_SD3MX_SLOT6;
470 QIXIS_WRITE(brdcfg[12], brdcfg);
471 break;
472 default:
473 printf("WARNING: unsupported for SerDes3 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700474 srds_prtcl_s3);
York Sun667ab1a2012-10-11 07:13:37 +0000475 return -1;
476 }
477
478 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
479 FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
480 srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
481 switch (srds_prtcl_s4) {
482 case 0:
483 /* SerDes4 is not enabled */
484 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800485 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000486 case 2:
487 /* 10b, SD4(0:7) => SLOT7(0:7) */
488 brdcfg = QIXIS_READ(brdcfg[12]);
489 brdcfg &= ~BRDCFG12_SD4MX_MASK;
490 brdcfg |= BRDCFG12_SD4MX_SLOT7;
491 QIXIS_WRITE(brdcfg[12], brdcfg);
492 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800493 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000494 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800495 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000496 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800497 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000498 case 8:
499 /* x1b, SD4(4:7) => SLOT8(0:3) */
500 brdcfg = QIXIS_READ(brdcfg[12]);
501 brdcfg &= ~BRDCFG12_SD4MX_MASK;
502 brdcfg |= BRDCFG12_SD4MX_SLOT8;
503 QIXIS_WRITE(brdcfg[12], brdcfg);
504 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800505 case 9:
York Sun667ab1a2012-10-11 07:13:37 +0000506 case 10:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800507 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000508 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800509 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000510 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800511 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000512 case 16:
513 case 18:
514 /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
515 brdcfg = QIXIS_READ(brdcfg[12]);
516 brdcfg &= ~BRDCFG12_SD4MX_MASK;
517 brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
518 QIXIS_WRITE(brdcfg[12], brdcfg);
519 break;
520 default:
521 printf("WARNING: unsupported for SerDes4 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700522 srds_prtcl_s4);
York Sun667ab1a2012-10-11 07:13:37 +0000523 return -1;
524 }
525
526 return 0;
527}
528
529int board_early_init_r(void)
530{
531 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700532 int flash_esel = find_tlb_idx((void *)flashbase, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000533
534 /*
535 * Remap Boot flash + PROMJET region to caching-inhibited
536 * so that flash can be erased properly.
537 */
538
539 /* Flush d-cache and invalidate i-cache of any FLASH data */
540 flush_dcache();
541 invalidate_icache();
542
York Sun220c3462014-06-24 21:16:20 -0700543 if (flash_esel == -1) {
544 /* very unlikely unless something is messed up */
545 puts("Error: Could not find TLB for FLASH BASE\n");
546 flash_esel = 2; /* give our best effort to continue */
547 } else {
548 /* invalidate existing TLB entry for flash + promjet */
549 disable_tlb(flash_esel);
550 }
York Sun667ab1a2012-10-11 07:13:37 +0000551
552 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
York Sun9b85a482013-06-27 10:48:29 -0700553 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
554 0, flash_esel, BOOKE_PAGESZ_256M, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000555
Ed Swarthouta55ec452013-03-25 07:39:37 +0000556 /* Disable remote I2C connection to qixis fpga */
557 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
York Sun667ab1a2012-10-11 07:13:37 +0000558
York Sund58bef12013-03-25 07:33:22 +0000559 /*
560 * Adjust core voltage according to voltage ID
561 * This function changes I2C mux to channel 2.
562 */
York Sun844944c2013-03-25 07:40:01 +0000563 if (adjust_vdd(0))
York Sund58bef12013-03-25 07:33:22 +0000564 printf("Warning: Adjusting core voltage failed.\n");
565
York Sun667ab1a2012-10-11 07:13:37 +0000566 /* Configure board SERDES ports crossbar */
567 config_frontside_crossbar_vsc3316();
568 config_backside_crossbar_mux();
569 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
570
571 return 0;
572}
573
574unsigned long get_board_sys_clk(void)
575{
576 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000577#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
578 /* use accurate clock measurement */
579 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
580 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
581 u32 val;
582
583 val = freq * base;
584 if (val) {
585 debug("SYS Clock measurement is: %d\n", val);
586 return val;
587 } else {
588 printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
589 }
590#endif
York Sun667ab1a2012-10-11 07:13:37 +0000591
592 switch (sysclk_conf & 0x0F) {
593 case QIXIS_SYSCLK_83:
594 return 83333333;
595 case QIXIS_SYSCLK_100:
596 return 100000000;
597 case QIXIS_SYSCLK_125:
598 return 125000000;
599 case QIXIS_SYSCLK_133:
600 return 133333333;
601 case QIXIS_SYSCLK_150:
602 return 150000000;
603 case QIXIS_SYSCLK_160:
604 return 160000000;
605 case QIXIS_SYSCLK_166:
606 return 166666666;
607 }
608 return 66666666;
609}
610
611unsigned long get_board_ddr_clk(void)
612{
613 u8 ddrclk_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[2]) << 8 | QIXIS_READ(clk_freq[3]);
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("DDR Clock measurement is: %d\n", val);
623 return val;
624 } else {
625 printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
626 }
627#endif
York Sun667ab1a2012-10-11 07:13:37 +0000628
629 switch ((ddrclk_conf & 0x30) >> 4) {
630 case QIXIS_DDRCLK_100:
631 return 100000000;
632 case QIXIS_DDRCLK_125:
633 return 125000000;
634 case QIXIS_DDRCLK_133:
635 return 133333333;
636 }
637 return 66666666;
638}
639
York Sun667ab1a2012-10-11 07:13:37 +0000640int misc_init_r(void)
641{
642 u8 sw;
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800643 void *srds_base = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
644 serdes_corenet_t *srds_regs;
York Sun667ab1a2012-10-11 07:13:37 +0000645 u32 actual[MAX_SERDES];
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800646 u32 pllcr0, expected;
York Sun667ab1a2012-10-11 07:13:37 +0000647 unsigned int i;
648
649 sw = QIXIS_READ(brdcfg[2]);
650 for (i = 0; i < MAX_SERDES; i++) {
Roy Zangc04362f2013-03-25 07:33:15 +0000651 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +0000652 switch (clock) {
653 case 0:
654 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
655 break;
656 case 1:
657 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
658 break;
659 case 2:
660 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
661 break;
662 case 3:
663 actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
664 break;
665 }
666 }
667
668 for (i = 0; i < MAX_SERDES; i++) {
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800669 srds_regs = srds_base + i * 0x1000;
670 pllcr0 = srds_regs->bank[0].pllcr0;
671 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
York Sun667ab1a2012-10-11 07:13:37 +0000672 if (expected != actual[i]) {
York Sun9b85a482013-06-27 10:48:29 -0700673 printf("Warning: SERDES%u expects reference clock %sMHz, but actual is %sMHz\n",
674 i + 1, serdes_clock_to_string(expected),
York Sun667ab1a2012-10-11 07:13:37 +0000675 serdes_clock_to_string(actual[i]));
676 }
677 }
678
679 return 0;
680}
681
Simon Glass2aec3cc2014-10-23 18:58:47 -0600682int ft_board_setup(void *blob, bd_t *bd)
York Sun667ab1a2012-10-11 07:13:37 +0000683{
684 phys_addr_t base;
685 phys_size_t size;
686
687 ft_cpu_setup(blob, bd);
688
Simon Glassda1a1342017-08-03 12:22:15 -0600689 base = env_get_bootm_low();
690 size = env_get_bootm_size();
York Sun667ab1a2012-10-11 07:13:37 +0000691
692 fdt_fixup_memory(blob, (u64)base, (u64)size);
693
694#ifdef CONFIG_PCI
695 pci_of_setup(blob, bd);
696#endif
697
698 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530699 fsl_fdt_fixup_dr_usb(blob, bd);
York Sun667ab1a2012-10-11 07:13:37 +0000700
701#ifdef CONFIG_SYS_DPAA_FMAN
702 fdt_fixup_fman_ethernet(blob);
703 fdt_fixup_board_enet(blob);
704#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600705
706 return 0;
York Sun667ab1a2012-10-11 07:13:37 +0000707}
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000708
709/*
York Sun997f5122013-03-25 07:39:24 +0000710 * This function is called by bdinfo to print detail board information.
711 * As an exmaple for future board, we organize the messages into
712 * several sections. If applicable, the message is in the format of
713 * <name> = <value>
714 * It should aligned with normal output of bdinfo command.
715 *
716 * Voltage: Core, DDR and another configurable voltages
717 * Clock : Critical clocks which are not printed already
718 * RCW : RCW source if not printed already
719 * Misc : Other important information not in above catagories
720 */
721void board_detail(void)
722{
723 int i;
724 u8 brdcfg[16], dutcfg[16], rst_ctl;
725 int vdd, rcwsrc;
726 static const char * const clk[] = {"66.67", "100", "125", "133.33"};
727
728 for (i = 0; i < 16; i++) {
729 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
730 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
731 }
732
733 /* Voltage secion */
734 if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR)) {
735 vdd = read_voltage();
736 if (vdd > 0)
737 printf("Core voltage= %d mV\n", vdd);
738 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
739 }
740
741 printf("XVDD = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
742
743 /* clock section */
744 printf("SYSCLK = %s MHz\nDDRCLK = %s MHz\n",
745 clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
746
747 /* RCW section */
748 rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
749 puts("RCW source = ");
750 switch (rcwsrc) {
751 case 0x017:
752 case 0x01f:
753 puts("8-bit NOR\n");
754 break;
755 case 0x027:
756 case 0x02F:
757 puts("16-bit NOR\n");
758 break;
759 case 0x040:
760 puts("SDHC/eMMC\n");
761 break;
762 case 0x044:
763 puts("SPI 16-bit addressing\n");
764 break;
765 case 0x045:
766 puts("SPI 24-bit addressing\n");
767 break;
768 case 0x048:
769 puts("I2C normal addressing\n");
770 break;
771 case 0x049:
772 puts("I2C extended addressing\n");
773 break;
774 case 0x108:
775 case 0x109:
776 case 0x10a:
777 case 0x10b:
778 puts("8-bit NAND, 2KB\n");
779 break;
780 default:
781 if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
782 puts("Hard-coded RCW\n");
783 else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
784 puts("8-bit NAND, 4KB\n");
785 else
786 puts("unknown\n");
787 break;
788 }
789
790 /* Misc section */
791 rst_ctl = QIXIS_READ(rst_ctl);
792 puts("HRESET_REQ = ");
793 switch (rst_ctl & 0x30) {
794 case 0x00:
795 puts("Ignored\n");
796 break;
797 case 0x10:
798 puts("Assert HRESET\n");
799 break;
800 case 0x30:
801 puts("Reset system\n");
802 break;
803 default:
804 puts("N/A\n");
805 break;
806 }
807}
808
809/*
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000810 * Reverse engineering switch settings.
811 * Some bits cannot be figured out. They will be displayed as
812 * underscore in binary format. mask[] has those bits.
813 * Some bits are calculated differently than the actual switches
814 * if booting with overriding by FPGA.
815 */
816void qixis_dump_switch(void)
817{
818 int i;
819 u8 sw[9];
820
821 /*
822 * Any bit with 1 means that bit cannot be reverse engineered.
823 * It will be displayed as _ in binary format.
824 */
York Sun9e698742013-03-25 07:40:14 +0000825 static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000826 char buf[10];
827 u8 brdcfg[16], dutcfg[16];
828
829 for (i = 0; i < 16; i++) {
830 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
831 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
832 }
833
834 sw[0] = dutcfg[0];
York Sun9b85a482013-06-27 10:48:29 -0700835 sw[1] = (dutcfg[1] << 0x07) |
836 ((dutcfg[12] & 0xC0) >> 1) |
837 ((dutcfg[11] & 0xE0) >> 3) |
838 ((dutcfg[6] & 0x80) >> 6) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000839 ((dutcfg[1] & 0x80) >> 7);
York Sun9b85a482013-06-27 10:48:29 -0700840 sw[2] = ((brdcfg[1] & 0x0f) << 4) |
841 ((brdcfg[1] & 0x30) >> 2) |
842 ((brdcfg[1] & 0x40) >> 5) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000843 ((brdcfg[1] & 0x80) >> 7);
844 sw[3] = brdcfg[2];
York Sun9b85a482013-06-27 10:48:29 -0700845 sw[4] = ((dutcfg[2] & 0x01) << 7) |
846 ((dutcfg[2] & 0x06) << 4) |
847 ((~QIXIS_READ(present)) & 0x10) |
848 ((brdcfg[3] & 0x80) >> 4) |
849 ((brdcfg[3] & 0x01) << 2) |
850 ((brdcfg[6] == 0x62) ? 3 :
851 ((brdcfg[6] == 0x5a) ? 2 :
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000852 ((brdcfg[6] == 0x5e) ? 1 : 0)));
York Sun9b85a482013-06-27 10:48:29 -0700853 sw[5] = ((brdcfg[0] & 0x0f) << 4) |
854 ((QIXIS_READ(rst_ctl) & 0x30) >> 2) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000855 ((brdcfg[0] & 0x40) >> 5);
York Sun9e698742013-03-25 07:40:14 +0000856 sw[6] = (brdcfg[11] & 0x20) |
857 ((brdcfg[5] & 0x02) << 3);
York Sun9b85a482013-06-27 10:48:29 -0700858 sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000859 ((brdcfg[5] & 0x10) << 2);
York Sun9b85a482013-06-27 10:48:29 -0700860 sw[8] = ((brdcfg[12] & 0x08) << 4) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000861 ((brdcfg[12] & 0x03) << 5);
862
863 puts("DIP switch (reverse-engineering)\n");
864 for (i = 0; i < 9; i++) {
865 printf("SW%d = 0b%s (0x%02x)\n",
York Sun9b85a482013-06-27 10:48:29 -0700866 i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000867 }
868}
York Sun844944c2013-03-25 07:40:01 +0000869
York Sun9b85a482013-06-27 10:48:29 -0700870static int do_vdd_adjust(cmd_tbl_t *cmdtp,
871 int flag, int argc,
872 char * const argv[])
York Sun844944c2013-03-25 07:40:01 +0000873{
874 ulong override;
875
876 if (argc < 2)
877 return CMD_RET_USAGE;
878 if (!strict_strtoul(argv[1], 10, &override))
879 adjust_vdd(override); /* the value is checked by callee */
880 else
881 return CMD_RET_USAGE;
882
883 return 0;
884}
885
886U_BOOT_CMD(
887 vdd_override, 2, 0, do_vdd_adjust,
888 "Override VDD",
889 "- override with the voltage specified in mV, eg. 1050"
890);