blob: 5608774afd19e3194808179d0c8494da5af235be [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>
Simon Glass3bbe70c2019-12-28 10:44:54 -07009#include <fdt_support.h>
York Sun667ab1a2012-10-11 07:13:37 +000010#include <i2c.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass8f3f7612019-11-14 12:57:42 -070012#include <irq_func.h>
York Sun667ab1a2012-10-11 07:13:37 +000013#include <netdev.h>
14#include <linux/compiler.h>
15#include <asm/mmu.h>
16#include <asm/processor.h>
17#include <asm/cache.h>
18#include <asm/immap_85xx.h>
19#include <asm/fsl_law.h>
20#include <asm/fsl_serdes.h>
York Sun667ab1a2012-10-11 07:13:37 +000021#include <asm/fsl_liodn.h>
22#include <fm_eth.h>
23
24#include "../common/qixis.h"
25#include "../common/vsc3316_3308.h"
26#include "t4qds.h"
27#include "t4240qds_qixis.h"
28
29DECLARE_GLOBAL_DATA_PTR;
30
Shaohui Xie3d8095e2013-08-19 18:43:07 +080031static int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
Timur Tabie9fabd82012-12-12 11:07:12 +000032 {8, 8}, {9, 9}, {14, 14}, {15, 15} };
33
Shaohui Xie3d8095e2013-08-19 18:43:07 +080034static int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
Timur Tabie9fabd82012-12-12 11:07:12 +000035 {10, 10}, {11, 11}, {12, 12}, {13, 13} };
36
Shaohui Xie3d8095e2013-08-19 18:43:07 +080037static int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
Timur Tabie9fabd82012-12-12 11:07:12 +000038 {10, 11}, {11, 10}, {12, 2}, {13, 3} };
39
Shaohui Xie3d8095e2013-08-19 18:43:07 +080040static int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
Timur Tabie9fabd82012-12-12 11:07:12 +000041 {8, 9}, {9, 8}, {14, 1}, {15, 0} };
42
York Sun667ab1a2012-10-11 07:13:37 +000043int checkboard(void)
44{
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000045 char buf[64];
York Sun667ab1a2012-10-11 07:13:37 +000046 u8 sw;
Simon Glassa8b57392012-12-13 20:48:48 +000047 struct cpu_type *cpu = gd->arch.cpu;
York Sun667ab1a2012-10-11 07:13:37 +000048 unsigned int i;
49
50 printf("Board: %sQDS, ", cpu->name);
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000051 printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
York Sun9b85a482013-06-27 10:48:29 -070052 QIXIS_READ(id), QIXIS_READ(arch));
York Sun667ab1a2012-10-11 07:13:37 +000053
54 sw = QIXIS_READ(brdcfg[0]);
55 sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
56
57 if (sw < 0x8)
58 printf("vBank: %d\n", sw);
59 else if (sw == 0x8)
60 puts("Promjet\n");
61 else if (sw == 0x9)
62 puts("NAND\n");
63 else
64 printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
65
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000066 printf("FPGA: v%d (%s), build %d",
York Sun9b85a482013-06-27 10:48:29 -070067 (int)QIXIS_READ(scver), qixis_read_tag(buf),
68 (int)qixis_read_minor());
Prabhakar Kushwaha033d07e2012-12-23 19:26:03 +000069 /* the timestamp string contains "\n" at the end */
70 printf(" on %s", qixis_read_time(buf));
71
York Sun667ab1a2012-10-11 07:13:37 +000072 /*
73 * Display the actual SERDES reference clocks as configured by the
74 * dip switches on the board. Note that the SWx registers could
75 * technically be set to force the reference clocks to match the
76 * values that the SERDES expects (or vice versa). For now, however,
77 * we just display both values and hope the user notices when they
78 * don't match.
79 */
80 puts("SERDES Reference Clocks: ");
81 sw = QIXIS_READ(brdcfg[2]);
82 for (i = 0; i < MAX_SERDES; i++) {
York Sun9b85a482013-06-27 10:48:29 -070083 static const char * const freq[] = {
York Sun667ab1a2012-10-11 07:13:37 +000084 "100", "125", "156.25", "161.1328125"};
Roy Zangc04362f2013-03-25 07:33:15 +000085 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +000086
87 printf("SERDES%u=%sMHz ", i+1, freq[clock]);
88 }
89 puts("\n");
90
91 return 0;
92}
93
94int select_i2c_ch_pca9547(u8 ch)
95{
96 int ret;
97
98 ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
99 if (ret) {
100 puts("PCA: failed to select proper channel\n");
101 return ret;
102 }
103
104 return 0;
105}
106
York Sund58bef12013-03-25 07:33:22 +0000107/*
108 * read_voltage from sensor on I2C bus
109 * We use average of 4 readings, waiting for 532us befor another reading
110 */
111#define NUM_READINGS 4 /* prefer to be power of 2 for efficiency */
112#define WAIT_FOR_ADC 532 /* wait for 532 microseconds for ADC */
113
114static inline int read_voltage(void)
115{
116 int i, ret, voltage_read = 0;
117 u16 vol_mon;
118
119 for (i = 0; i < NUM_READINGS; i++) {
120 ret = i2c_read(I2C_VOL_MONITOR_ADDR,
121 I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
122 if (ret) {
123 printf("VID: failed to read core voltage\n");
124 return ret;
125 }
126 if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
127 printf("VID: Core voltage sensor error\n");
128 return -1;
129 }
130 debug("VID: bus voltage reads 0x%04x\n", vol_mon);
131 /* LSB = 4mv */
132 voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
133 udelay(WAIT_FOR_ADC);
134 }
135 /* calculate the average */
136 voltage_read /= NUM_READINGS;
137
138 return voltage_read;
139}
140
141/*
142 * We need to calculate how long before the voltage starts to drop or increase
143 * It returns with the loop count. Each loop takes several readings (532us)
144 */
145static inline int wait_for_voltage_change(int vdd_last)
146{
147 int timeout, vdd_current;
148
149 vdd_current = read_voltage();
150 /* wait until voltage starts to drop */
151 for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
152 timeout < 100; timeout++) {
153 vdd_current = read_voltage();
154 }
155 if (timeout >= 100) {
156 printf("VID: Voltage adjustment timeout\n");
157 return -1;
158 }
159 return timeout;
160}
161
162/*
163 * argument 'wait' is the time we know the voltage difference can be measured
164 * this function keeps reading the voltage until it is stable
165 */
166static inline int wait_for_voltage_stable(int wait)
167{
168 int timeout, vdd_current, vdd_last;
169
170 vdd_last = read_voltage();
171 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
172 /* wait until voltage is stable */
173 vdd_current = read_voltage();
174 for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
175 timeout < 100; timeout++) {
176 vdd_last = vdd_current;
177 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
178 vdd_current = read_voltage();
179 }
180 if (timeout >= 100) {
181 printf("VID: Voltage adjustment timeout\n");
182 return -1;
183 }
184
185 return vdd_current;
186}
187
188static inline int set_voltage(u8 vid)
189{
190 int wait, vdd_last;
191
192 vdd_last = read_voltage();
193 QIXIS_WRITE(brdcfg[6], vid);
194 wait = wait_for_voltage_change(vdd_last);
195 if (wait < 0)
196 return -1;
197 debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
198 wait = wait ? wait : 1;
199
200 vdd_last = wait_for_voltage_stable(wait);
201 if (vdd_last < 0)
202 return -1;
203 debug("VID: Current voltage is %d mV\n", vdd_last);
204
205 return vdd_last;
206}
207
208
York Sun844944c2013-03-25 07:40:01 +0000209static int adjust_vdd(ulong vdd_override)
York Sund58bef12013-03-25 07:33:22 +0000210{
211 int re_enable = disable_interrupts();
212 ccsr_gur_t __iomem *gur =
213 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
214 u32 fusesr;
215 u8 vid, vid_current;
216 int vdd_target, vdd_current, vdd_last;
217 int ret;
York Sun844944c2013-03-25 07:40:01 +0000218 unsigned long vdd_string_override;
219 char *vdd_string;
York Sund58bef12013-03-25 07:33:22 +0000220 static const uint16_t vdd[32] = {
221 0, /* unused */
222 9875, /* 0.9875V */
223 9750,
224 9625,
225 9500,
226 9375,
227 9250,
228 9125,
229 9000,
230 8875,
231 8750,
232 8625,
233 8500,
234 8375,
235 8250,
236 8125,
237 10000, /* 1.0000V */
238 10125,
239 10250,
240 10375,
241 10500,
242 10625,
243 10750,
244 10875,
245 11000,
246 0, /* reserved */
247 };
248 struct vdd_drive {
249 u8 vid;
250 unsigned voltage;
251 };
252
253 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR);
254 if (ret) {
255 debug("VID: I2c failed to switch channel\n");
256 ret = -1;
257 goto exit;
258 }
259
260 /* get the voltage ID from fuse status register */
261 fusesr = in_be32(&gur->dcfg_fusesr);
262 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
263 FSL_CORENET_DCFG_FUSESR_VID_MASK;
264 if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
265 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
266 FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
267 }
268 vdd_target = vdd[vid];
York Sun844944c2013-03-25 07:40:01 +0000269
270 /* check override variable for overriding VDD */
Simon Glass64b723f2017-08-03 12:22:12 -0600271 vdd_string = env_get("t4240qds_vdd_mv");
York Sun844944c2013-03-25 07:40:01 +0000272 if (vdd_override == 0 && vdd_string &&
273 !strict_strtoul(vdd_string, 10, &vdd_string_override))
274 vdd_override = vdd_string_override;
275 if (vdd_override >= 819 && vdd_override <= 1212) {
276 vdd_target = vdd_override * 10; /* convert to 1/10 mV */
277 debug("VDD override is %lu\n", vdd_override);
278 } else if (vdd_override != 0) {
279 printf("Invalid value.\n");
280 }
281
York Sund58bef12013-03-25 07:33:22 +0000282 if (vdd_target == 0) {
283 debug("VID: VID not used\n");
284 ret = 0;
285 goto exit;
286 } else {
287 /* round up and divice by 10 to get a value in mV */
288 vdd_target = DIV_ROUND_UP(vdd_target, 10);
289 debug("VID: vid = %d mV\n", vdd_target);
290 }
291
292 /*
293 * Check current board VID setting
294 * Voltage regulator support output to 6.250mv step
295 * The highes voltage allowed for this board is (vid=0x40) 1.21250V
296 * the lowest is (vid=0x7f) 0.81875V
297 */
298 vid_current = QIXIS_READ(brdcfg[6]);
299 vdd_current = 121250 - (vid_current - 0x40) * 625;
300 debug("VID: Current vid setting is (0x%x) %d mV\n",
301 vid_current, vdd_current/100);
302
303 /*
304 * Read voltage monitor to check real voltage.
305 * Voltage monitor LSB is 4mv.
306 */
307 vdd_last = read_voltage();
308 if (vdd_last < 0) {
309 printf("VID: Could not read voltage sensor abort VID adjustment\n");
310 ret = -1;
311 goto exit;
312 }
313 debug("VID: Core voltage is at %d mV\n", vdd_last);
314 /*
315 * Adjust voltage to at or 8mV above target.
316 * Each step of adjustment is 6.25mV.
317 * Stepping down too fast may cause over current.
318 */
319 while (vdd_last > 0 && vid_current < 0x80 &&
320 vdd_last > (vdd_target + 8)) {
321 vid_current++;
322 vdd_last = set_voltage(vid_current);
323 }
324 /*
325 * Check if we need to step up
326 * This happens when board voltage switch was set too low
327 */
328 while (vdd_last > 0 && vid_current >= 0x40 &&
329 vdd_last < vdd_target + 2) {
330 vid_current--;
331 vdd_last = set_voltage(vid_current);
332 }
333 if (vdd_last > 0)
334 printf("VID: Core voltage %d mV\n", vdd_last);
335 else
336 ret = -1;
337
338exit:
339 if (re_enable)
340 enable_interrupts();
341 return ret;
342}
343
York Sun667ab1a2012-10-11 07:13:37 +0000344/* Configure Crossbar switches for Front-Side SerDes Ports */
345int config_frontside_crossbar_vsc3316(void)
346{
347 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
348 u32 srds_prtcl_s1, srds_prtcl_s2;
349 int ret;
350
351 ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS);
352 if (ret)
353 return ret;
354
355 srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
356 FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
357 srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800358 switch (srds_prtcl_s1) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800359 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800360 case 38:
361 /* swap first lane and third lane on slot1 */
362 vsc3316_fsm1_tx[0][1] = 14;
363 vsc3316_fsm1_tx[6][1] = 0;
364 vsc3316_fsm1_rx[1][1] = 2;
365 vsc3316_fsm1_rx[6][1] = 13;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800366 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800367 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800368 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800369 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800370 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800371 case 48:
372 /* swap first lane and third lane on slot2 */
373 vsc3316_fsm1_tx[2][1] = 8;
374 vsc3316_fsm1_tx[4][1] = 6;
375 vsc3316_fsm1_rx[2][1] = 10;
376 vsc3316_fsm1_rx[5][1] = 5;
377 default:
York Sun667ab1a2012-10-11 07:13:37 +0000378 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
379 if (ret)
380 return ret;
381 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
382 if (ret)
383 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800384 break;
York Sun667ab1a2012-10-11 07:13:37 +0000385 }
386
387 srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
388 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
389 srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
Shaohui Xie6e078702013-08-19 18:57:57 +0800390 switch (srds_prtcl_s2) {
Shaohui Xied9a1d832014-05-16 10:52:33 +0800391 case 37:
Shaohui Xie6e078702013-08-19 18:57:57 +0800392 case 38:
393 /* swap first lane and third lane on slot3 */
394 vsc3316_fsm2_tx[2][1] = 11;
395 vsc3316_fsm2_tx[5][1] = 4;
396 vsc3316_fsm2_rx[2][1] = 9;
397 vsc3316_fsm2_rx[4][1] = 7;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800398 case 39:
Shaohui Xie6e078702013-08-19 18:57:57 +0800399 case 40:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800400 case 45:
Shaohui Xie6e078702013-08-19 18:57:57 +0800401 case 46:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800402 case 47:
Shaohui Xie6e078702013-08-19 18:57:57 +0800403 case 48:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800404 case 49:
Shaohui Xie6e078702013-08-19 18:57:57 +0800405 case 50:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800406 case 51:
Shaohui Xie6e078702013-08-19 18:57:57 +0800407 case 52:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800408 case 53:
Shaohui Xie6e078702013-08-19 18:57:57 +0800409 case 54:
410 /* swap first lane and third lane on slot4 */
411 vsc3316_fsm2_tx[6][1] = 3;
412 vsc3316_fsm2_tx[1][1] = 12;
413 vsc3316_fsm2_rx[0][1] = 1;
414 vsc3316_fsm2_rx[6][1] = 15;
415 default:
York Sun667ab1a2012-10-11 07:13:37 +0000416 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
417 if (ret)
418 return ret;
419 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
420 if (ret)
421 return ret;
Shaohui Xie6e078702013-08-19 18:57:57 +0800422 break;
York Sun667ab1a2012-10-11 07:13:37 +0000423 }
424
425 return 0;
426}
427
428int config_backside_crossbar_mux(void)
429{
430 ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
431 u32 srds_prtcl_s3, srds_prtcl_s4;
432 u8 brdcfg;
433
434 srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
435 FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
436 srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
437 switch (srds_prtcl_s3) {
438 case 0:
439 /* SerDes3 is not enabled */
440 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800441 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000442 case 2:
443 case 9:
444 case 10:
445 /* SD3(0:7) => SLOT5(0:7) */
446 brdcfg = QIXIS_READ(brdcfg[12]);
447 brdcfg &= ~BRDCFG12_SD3MX_MASK;
448 brdcfg |= BRDCFG12_SD3MX_SLOT5;
449 QIXIS_WRITE(brdcfg[12], brdcfg);
450 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800451 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000452 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800453 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000454 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800455 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000456 case 8:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800457 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000458 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800459 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000460 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800461 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000462 case 16:
463 case 17:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800464 case 18:
York Sun667ab1a2012-10-11 07:13:37 +0000465 case 19:
466 case 20:
467 /* SD3(4:7) => SLOT6(0:3) */
468 brdcfg = QIXIS_READ(brdcfg[12]);
469 brdcfg &= ~BRDCFG12_SD3MX_MASK;
470 brdcfg |= BRDCFG12_SD3MX_SLOT6;
471 QIXIS_WRITE(brdcfg[12], brdcfg);
472 break;
473 default:
474 printf("WARNING: unsupported for SerDes3 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700475 srds_prtcl_s3);
York Sun667ab1a2012-10-11 07:13:37 +0000476 return -1;
477 }
478
479 srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
480 FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
481 srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
482 switch (srds_prtcl_s4) {
483 case 0:
484 /* SerDes4 is not enabled */
485 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800486 case 1:
York Sun667ab1a2012-10-11 07:13:37 +0000487 case 2:
488 /* 10b, SD4(0:7) => SLOT7(0:7) */
489 brdcfg = QIXIS_READ(brdcfg[12]);
490 brdcfg &= ~BRDCFG12_SD4MX_MASK;
491 brdcfg |= BRDCFG12_SD4MX_SLOT7;
492 QIXIS_WRITE(brdcfg[12], brdcfg);
493 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800494 case 3:
York Sun667ab1a2012-10-11 07:13:37 +0000495 case 4:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800496 case 5:
York Sun667ab1a2012-10-11 07:13:37 +0000497 case 6:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800498 case 7:
York Sun667ab1a2012-10-11 07:13:37 +0000499 case 8:
500 /* x1b, SD4(4:7) => SLOT8(0:3) */
501 brdcfg = QIXIS_READ(brdcfg[12]);
502 brdcfg &= ~BRDCFG12_SD4MX_MASK;
503 brdcfg |= BRDCFG12_SD4MX_SLOT8;
504 QIXIS_WRITE(brdcfg[12], brdcfg);
505 break;
Shaohui Xied9a1d832014-05-16 10:52:33 +0800506 case 9:
York Sun667ab1a2012-10-11 07:13:37 +0000507 case 10:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800508 case 11:
York Sun667ab1a2012-10-11 07:13:37 +0000509 case 12:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800510 case 13:
York Sun667ab1a2012-10-11 07:13:37 +0000511 case 14:
Shaohui Xied9a1d832014-05-16 10:52:33 +0800512 case 15:
York Sun667ab1a2012-10-11 07:13:37 +0000513 case 16:
514 case 18:
515 /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
516 brdcfg = QIXIS_READ(brdcfg[12]);
517 brdcfg &= ~BRDCFG12_SD4MX_MASK;
518 brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
519 QIXIS_WRITE(brdcfg[12], brdcfg);
520 break;
521 default:
522 printf("WARNING: unsupported for SerDes4 Protocol %d\n",
York Sun9b85a482013-06-27 10:48:29 -0700523 srds_prtcl_s4);
York Sun667ab1a2012-10-11 07:13:37 +0000524 return -1;
525 }
526
527 return 0;
528}
529
530int board_early_init_r(void)
531{
532 const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
York Sun220c3462014-06-24 21:16:20 -0700533 int flash_esel = find_tlb_idx((void *)flashbase, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000534
535 /*
536 * Remap Boot flash + PROMJET region to caching-inhibited
537 * so that flash can be erased properly.
538 */
539
540 /* Flush d-cache and invalidate i-cache of any FLASH data */
541 flush_dcache();
542 invalidate_icache();
543
York Sun220c3462014-06-24 21:16:20 -0700544 if (flash_esel == -1) {
545 /* very unlikely unless something is messed up */
546 puts("Error: Could not find TLB for FLASH BASE\n");
547 flash_esel = 2; /* give our best effort to continue */
548 } else {
549 /* invalidate existing TLB entry for flash + promjet */
550 disable_tlb(flash_esel);
551 }
York Sun667ab1a2012-10-11 07:13:37 +0000552
553 set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
York Sun9b85a482013-06-27 10:48:29 -0700554 MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
555 0, flash_esel, BOOKE_PAGESZ_256M, 1);
York Sun667ab1a2012-10-11 07:13:37 +0000556
Ed Swarthouta55ec452013-03-25 07:39:37 +0000557 /* Disable remote I2C connection to qixis fpga */
558 QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
York Sun667ab1a2012-10-11 07:13:37 +0000559
York Sund58bef12013-03-25 07:33:22 +0000560 /*
561 * Adjust core voltage according to voltage ID
562 * This function changes I2C mux to channel 2.
563 */
York Sun844944c2013-03-25 07:40:01 +0000564 if (adjust_vdd(0))
York Sund58bef12013-03-25 07:33:22 +0000565 printf("Warning: Adjusting core voltage failed.\n");
566
York Sun667ab1a2012-10-11 07:13:37 +0000567 /* Configure board SERDES ports crossbar */
568 config_frontside_crossbar_vsc3316();
569 config_backside_crossbar_mux();
570 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
571
572 return 0;
573}
574
575unsigned long get_board_sys_clk(void)
576{
577 u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000578#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
579 /* use accurate clock measurement */
580 int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
581 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
582 u32 val;
583
584 val = freq * base;
585 if (val) {
586 debug("SYS Clock measurement is: %d\n", val);
587 return val;
588 } else {
589 printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
590 }
591#endif
York Sun667ab1a2012-10-11 07:13:37 +0000592
593 switch (sysclk_conf & 0x0F) {
594 case QIXIS_SYSCLK_83:
595 return 83333333;
596 case QIXIS_SYSCLK_100:
597 return 100000000;
598 case QIXIS_SYSCLK_125:
599 return 125000000;
600 case QIXIS_SYSCLK_133:
601 return 133333333;
602 case QIXIS_SYSCLK_150:
603 return 150000000;
604 case QIXIS_SYSCLK_160:
605 return 160000000;
606 case QIXIS_SYSCLK_166:
607 return 166666666;
608 }
609 return 66666666;
610}
611
612unsigned long get_board_ddr_clk(void)
613{
614 u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
Ed Swarthout817f28e2013-03-25 07:40:10 +0000615#ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
616 /* use accurate clock measurement */
617 int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
618 int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
619 u32 val;
620
621 val = freq * base;
622 if (val) {
623 debug("DDR Clock measurement is: %d\n", val);
624 return val;
625 } else {
626 printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
627 }
628#endif
York Sun667ab1a2012-10-11 07:13:37 +0000629
630 switch ((ddrclk_conf & 0x30) >> 4) {
631 case QIXIS_DDRCLK_100:
632 return 100000000;
633 case QIXIS_DDRCLK_125:
634 return 125000000;
635 case QIXIS_DDRCLK_133:
636 return 133333333;
637 }
638 return 66666666;
639}
640
York Sun667ab1a2012-10-11 07:13:37 +0000641int misc_init_r(void)
642{
643 u8 sw;
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800644 void *srds_base = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
645 serdes_corenet_t *srds_regs;
York Sun667ab1a2012-10-11 07:13:37 +0000646 u32 actual[MAX_SERDES];
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800647 u32 pllcr0, expected;
York Sun667ab1a2012-10-11 07:13:37 +0000648 unsigned int i;
649
650 sw = QIXIS_READ(brdcfg[2]);
651 for (i = 0; i < MAX_SERDES; i++) {
Roy Zangc04362f2013-03-25 07:33:15 +0000652 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
York Sun667ab1a2012-10-11 07:13:37 +0000653 switch (clock) {
654 case 0:
655 actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
656 break;
657 case 1:
658 actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
659 break;
660 case 2:
661 actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
662 break;
663 case 3:
664 actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
665 break;
666 }
667 }
668
669 for (i = 0; i < MAX_SERDES; i++) {
Shaohui Xiea24a6aa2014-06-27 14:39:31 +0800670 srds_regs = srds_base + i * 0x1000;
671 pllcr0 = srds_regs->bank[0].pllcr0;
672 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
York Sun667ab1a2012-10-11 07:13:37 +0000673 if (expected != actual[i]) {
York Sun9b85a482013-06-27 10:48:29 -0700674 printf("Warning: SERDES%u expects reference clock %sMHz, but actual is %sMHz\n",
675 i + 1, serdes_clock_to_string(expected),
York Sun667ab1a2012-10-11 07:13:37 +0000676 serdes_clock_to_string(actual[i]));
677 }
678 }
679
680 return 0;
681}
682
Simon Glass2aec3cc2014-10-23 18:58:47 -0600683int ft_board_setup(void *blob, bd_t *bd)
York Sun667ab1a2012-10-11 07:13:37 +0000684{
685 phys_addr_t base;
686 phys_size_t size;
687
688 ft_cpu_setup(blob, bd);
689
Simon Glassda1a1342017-08-03 12:22:15 -0600690 base = env_get_bootm_low();
691 size = env_get_bootm_size();
York Sun667ab1a2012-10-11 07:13:37 +0000692
693 fdt_fixup_memory(blob, (u64)base, (u64)size);
694
695#ifdef CONFIG_PCI
696 pci_of_setup(blob, bd);
697#endif
698
699 fdt_fixup_liodn(blob);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530700 fsl_fdt_fixup_dr_usb(blob, bd);
York Sun667ab1a2012-10-11 07:13:37 +0000701
702#ifdef CONFIG_SYS_DPAA_FMAN
703 fdt_fixup_fman_ethernet(blob);
704 fdt_fixup_board_enet(blob);
705#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600706
707 return 0;
York Sun667ab1a2012-10-11 07:13:37 +0000708}
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000709
710/*
York Sun997f5122013-03-25 07:39:24 +0000711 * This function is called by bdinfo to print detail board information.
712 * As an exmaple for future board, we organize the messages into
713 * several sections. If applicable, the message is in the format of
714 * <name> = <value>
715 * It should aligned with normal output of bdinfo command.
716 *
717 * Voltage: Core, DDR and another configurable voltages
718 * Clock : Critical clocks which are not printed already
719 * RCW : RCW source if not printed already
720 * Misc : Other important information not in above catagories
721 */
722void board_detail(void)
723{
724 int i;
725 u8 brdcfg[16], dutcfg[16], rst_ctl;
726 int vdd, rcwsrc;
727 static const char * const clk[] = {"66.67", "100", "125", "133.33"};
728
729 for (i = 0; i < 16; i++) {
730 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
731 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
732 }
733
734 /* Voltage secion */
735 if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR)) {
736 vdd = read_voltage();
737 if (vdd > 0)
738 printf("Core voltage= %d mV\n", vdd);
739 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
740 }
741
742 printf("XVDD = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
743
744 /* clock section */
745 printf("SYSCLK = %s MHz\nDDRCLK = %s MHz\n",
746 clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
747
748 /* RCW section */
749 rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
750 puts("RCW source = ");
751 switch (rcwsrc) {
752 case 0x017:
753 case 0x01f:
754 puts("8-bit NOR\n");
755 break;
756 case 0x027:
757 case 0x02F:
758 puts("16-bit NOR\n");
759 break;
760 case 0x040:
761 puts("SDHC/eMMC\n");
762 break;
763 case 0x044:
764 puts("SPI 16-bit addressing\n");
765 break;
766 case 0x045:
767 puts("SPI 24-bit addressing\n");
768 break;
769 case 0x048:
770 puts("I2C normal addressing\n");
771 break;
772 case 0x049:
773 puts("I2C extended addressing\n");
774 break;
775 case 0x108:
776 case 0x109:
777 case 0x10a:
778 case 0x10b:
779 puts("8-bit NAND, 2KB\n");
780 break;
781 default:
782 if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
783 puts("Hard-coded RCW\n");
784 else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
785 puts("8-bit NAND, 4KB\n");
786 else
787 puts("unknown\n");
788 break;
789 }
790
791 /* Misc section */
792 rst_ctl = QIXIS_READ(rst_ctl);
793 puts("HRESET_REQ = ");
794 switch (rst_ctl & 0x30) {
795 case 0x00:
796 puts("Ignored\n");
797 break;
798 case 0x10:
799 puts("Assert HRESET\n");
800 break;
801 case 0x30:
802 puts("Reset system\n");
803 break;
804 default:
805 puts("N/A\n");
806 break;
807 }
808}
809
810/*
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000811 * Reverse engineering switch settings.
812 * Some bits cannot be figured out. They will be displayed as
813 * underscore in binary format. mask[] has those bits.
814 * Some bits are calculated differently than the actual switches
815 * if booting with overriding by FPGA.
816 */
817void qixis_dump_switch(void)
818{
819 int i;
820 u8 sw[9];
821
822 /*
823 * Any bit with 1 means that bit cannot be reverse engineered.
824 * It will be displayed as _ in binary format.
825 */
York Sun9e698742013-03-25 07:40:14 +0000826 static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000827 char buf[10];
828 u8 brdcfg[16], dutcfg[16];
829
830 for (i = 0; i < 16; i++) {
831 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
832 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
833 }
834
835 sw[0] = dutcfg[0];
York Sun9b85a482013-06-27 10:48:29 -0700836 sw[1] = (dutcfg[1] << 0x07) |
837 ((dutcfg[12] & 0xC0) >> 1) |
838 ((dutcfg[11] & 0xE0) >> 3) |
839 ((dutcfg[6] & 0x80) >> 6) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000840 ((dutcfg[1] & 0x80) >> 7);
York Sun9b85a482013-06-27 10:48:29 -0700841 sw[2] = ((brdcfg[1] & 0x0f) << 4) |
842 ((brdcfg[1] & 0x30) >> 2) |
843 ((brdcfg[1] & 0x40) >> 5) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000844 ((brdcfg[1] & 0x80) >> 7);
845 sw[3] = brdcfg[2];
York Sun9b85a482013-06-27 10:48:29 -0700846 sw[4] = ((dutcfg[2] & 0x01) << 7) |
847 ((dutcfg[2] & 0x06) << 4) |
848 ((~QIXIS_READ(present)) & 0x10) |
849 ((brdcfg[3] & 0x80) >> 4) |
850 ((brdcfg[3] & 0x01) << 2) |
851 ((brdcfg[6] == 0x62) ? 3 :
852 ((brdcfg[6] == 0x5a) ? 2 :
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000853 ((brdcfg[6] == 0x5e) ? 1 : 0)));
York Sun9b85a482013-06-27 10:48:29 -0700854 sw[5] = ((brdcfg[0] & 0x0f) << 4) |
855 ((QIXIS_READ(rst_ctl) & 0x30) >> 2) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000856 ((brdcfg[0] & 0x40) >> 5);
York Sun9e698742013-03-25 07:40:14 +0000857 sw[6] = (brdcfg[11] & 0x20) |
858 ((brdcfg[5] & 0x02) << 3);
York Sun9b85a482013-06-27 10:48:29 -0700859 sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000860 ((brdcfg[5] & 0x10) << 2);
York Sun9b85a482013-06-27 10:48:29 -0700861 sw[8] = ((brdcfg[12] & 0x08) << 4) |
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000862 ((brdcfg[12] & 0x03) << 5);
863
864 puts("DIP switch (reverse-engineering)\n");
865 for (i = 0; i < 9; i++) {
866 printf("SW%d = 0b%s (0x%02x)\n",
York Sun9b85a482013-06-27 10:48:29 -0700867 i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
Shaveta Leekha4038ab62012-12-23 19:25:50 +0000868 }
869}
York Sun844944c2013-03-25 07:40:01 +0000870
York Sun9b85a482013-06-27 10:48:29 -0700871static int do_vdd_adjust(cmd_tbl_t *cmdtp,
872 int flag, int argc,
873 char * const argv[])
York Sun844944c2013-03-25 07:40:01 +0000874{
875 ulong override;
876
877 if (argc < 2)
878 return CMD_RET_USAGE;
879 if (!strict_strtoul(argv[1], 10, &override))
880 adjust_vdd(override); /* the value is checked by callee */
881 else
882 return CMD_RET_USAGE;
883
884 return 0;
885}
886
887U_BOOT_CMD(
888 vdd_override, 2, 0, do_vdd_adjust,
889 "Override VDD",
890 "- override with the voltage specified in mV, eg. 1050"
891);