]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/freescale/t4qds/t4qds.c
zynq: Enable axi ethernet and emaclite driver initialization
[karo-tx-uboot.git] / board / freescale / t4qds / t4qds.c
1 /*
2  * Copyright 2009-2012 Freescale Semiconductor, Inc.
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <command.h>
9 #include <i2c.h>
10 #include <netdev.h>
11 #include <linux/compiler.h>
12 #include <asm/mmu.h>
13 #include <asm/processor.h>
14 #include <asm/cache.h>
15 #include <asm/immap_85xx.h>
16 #include <asm/fsl_law.h>
17 #include <asm/fsl_serdes.h>
18 #include <asm/fsl_portals.h>
19 #include <asm/fsl_liodn.h>
20 #include <fm_eth.h>
21
22 #include "../common/qixis.h"
23 #include "../common/vsc3316_3308.h"
24 #include "t4qds.h"
25 #include "t4240qds_qixis.h"
26
27 DECLARE_GLOBAL_DATA_PTR;
28
29 static const int8_t vsc3316_fsm1_tx[8][2] = { {0, 0}, {1, 1}, {6, 6}, {7, 7},
30                                 {8, 8}, {9, 9}, {14, 14}, {15, 15} };
31
32 static const int8_t vsc3316_fsm2_tx[8][2] = { {2, 2}, {3, 3}, {4, 4}, {5, 5},
33                                 {10, 10}, {11, 11}, {12, 12}, {13, 13} };
34
35 static const int8_t vsc3316_fsm1_rx[8][2] = { {2, 12}, {3, 13}, {4, 5}, {5, 4},
36                                 {10, 11}, {11, 10}, {12, 2}, {13, 3} };
37
38 static const int8_t vsc3316_fsm2_rx[8][2] = { {0, 15}, {1, 14}, {6, 7}, {7, 6},
39                                 {8, 9}, {9, 8}, {14, 1}, {15, 0} };
40
41 int checkboard(void)
42 {
43         char buf[64];
44         u8 sw;
45         struct cpu_type *cpu = gd->arch.cpu;
46         ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
47         unsigned int i;
48
49         printf("Board: %sQDS, ", cpu->name);
50         printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, ",
51                 QIXIS_READ(id), QIXIS_READ(arch));
52
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
65         printf("FPGA: v%d (%s), build %d",
66                 (int)QIXIS_READ(scver), qixis_read_tag(buf),
67                 (int)qixis_read_minor());
68         /* the timestamp string contains "\n" at the end */
69         printf(" on %s", qixis_read_time(buf));
70
71         /* Display the RCW, so that no one gets confused as to what RCW
72          * we're actually using for this boot.
73          */
74         puts("Reset Configuration Word (RCW):");
75         for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
76                 u32 rcw = in_be32(&gur->rcwsr[i]);
77
78                 if ((i % 4) == 0)
79                         printf("\n       %08x:", i * 4);
80                 printf(" %08x", rcw);
81         }
82         puts("\n");
83
84         /*
85          * Display the actual SERDES reference clocks as configured by the
86          * dip switches on the board.  Note that the SWx registers could
87          * technically be set to force the reference clocks to match the
88          * values that the SERDES expects (or vice versa).  For now, however,
89          * we just display both values and hope the user notices when they
90          * don't match.
91          */
92         puts("SERDES Reference Clocks: ");
93         sw = QIXIS_READ(brdcfg[2]);
94         for (i = 0; i < MAX_SERDES; i++) {
95                 static const char *freq[] = {
96                         "100", "125", "156.25", "161.1328125"};
97                 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
98
99                 printf("SERDES%u=%sMHz ", i+1, freq[clock]);
100         }
101         puts("\n");
102
103         return 0;
104 }
105
106 int select_i2c_ch_pca9547(u8 ch)
107 {
108         int ret;
109
110         ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
111         if (ret) {
112                 puts("PCA: failed to select proper channel\n");
113                 return ret;
114         }
115
116         return 0;
117 }
118
119 /*
120  * read_voltage from sensor on I2C bus
121  * We use average of 4 readings, waiting for 532us befor another reading
122  */
123 #define NUM_READINGS    4       /* prefer to be power of 2 for efficiency */
124 #define WAIT_FOR_ADC    532     /* wait for 532 microseconds for ADC */
125
126 static inline int read_voltage(void)
127 {
128         int i, ret, voltage_read = 0;
129         u16 vol_mon;
130
131         for (i = 0; i < NUM_READINGS; i++) {
132                 ret = i2c_read(I2C_VOL_MONITOR_ADDR,
133                         I2C_VOL_MONITOR_BUS_V_OFFSET, 1, (void *)&vol_mon, 2);
134                 if (ret) {
135                         printf("VID: failed to read core voltage\n");
136                         return ret;
137                 }
138                 if (vol_mon & I2C_VOL_MONITOR_BUS_V_OVF) {
139                         printf("VID: Core voltage sensor error\n");
140                         return -1;
141                 }
142                 debug("VID: bus voltage reads 0x%04x\n", vol_mon);
143                 /* LSB = 4mv */
144                 voltage_read += (vol_mon >> I2C_VOL_MONITOR_BUS_V_SHIFT) * 4;
145                 udelay(WAIT_FOR_ADC);
146         }
147         /* calculate the average */
148         voltage_read /= NUM_READINGS;
149
150         return voltage_read;
151 }
152
153 /*
154  * We need to calculate how long before the voltage starts to drop or increase
155  * It returns with the loop count. Each loop takes several readings (532us)
156  */
157 static inline int wait_for_voltage_change(int vdd_last)
158 {
159         int timeout, vdd_current;
160
161         vdd_current = read_voltage();
162         /* wait until voltage starts to drop */
163         for (timeout = 0; abs(vdd_last - vdd_current) <= 4 &&
164                 timeout < 100; timeout++) {
165                 vdd_current = read_voltage();
166         }
167         if (timeout >= 100) {
168                 printf("VID: Voltage adjustment timeout\n");
169                 return -1;
170         }
171         return timeout;
172 }
173
174 /*
175  * argument 'wait' is the time we know the voltage difference can be measured
176  * this function keeps reading the voltage until it is stable
177  */
178 static inline int wait_for_voltage_stable(int wait)
179 {
180         int timeout, vdd_current, vdd_last;
181
182         vdd_last = read_voltage();
183         udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
184         /* wait until voltage is stable */
185         vdd_current = read_voltage();
186         for (timeout = 0; abs(vdd_last - vdd_current) >= 4 &&
187                 timeout < 100; timeout++) {
188                 vdd_last = vdd_current;
189                 udelay(wait * NUM_READINGS * WAIT_FOR_ADC);
190                 vdd_current = read_voltage();
191         }
192         if (timeout >= 100) {
193                 printf("VID: Voltage adjustment timeout\n");
194                 return -1;
195         }
196
197         return vdd_current;
198 }
199
200 static inline int set_voltage(u8 vid)
201 {
202         int wait, vdd_last;
203
204         vdd_last = read_voltage();
205         QIXIS_WRITE(brdcfg[6], vid);
206         wait = wait_for_voltage_change(vdd_last);
207         if (wait < 0)
208                 return -1;
209         debug("VID: Waited %d us\n", wait * NUM_READINGS * WAIT_FOR_ADC);
210         wait = wait ? wait : 1;
211
212         vdd_last = wait_for_voltage_stable(wait);
213         if (vdd_last < 0)
214                 return -1;
215         debug("VID: Current voltage is %d mV\n", vdd_last);
216
217         return vdd_last;
218 }
219
220
221 static int adjust_vdd(ulong vdd_override)
222 {
223         int re_enable = disable_interrupts();
224         ccsr_gur_t __iomem *gur =
225                 (void __iomem *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
226         u32 fusesr;
227         u8 vid, vid_current;
228         int vdd_target, vdd_current, vdd_last;
229         int ret;
230         unsigned long vdd_string_override;
231         char *vdd_string;
232         static const uint16_t vdd[32] = {
233                 0,      /* unused */
234                 9875,   /* 0.9875V */
235                 9750,
236                 9625,
237                 9500,
238                 9375,
239                 9250,
240                 9125,
241                 9000,
242                 8875,
243                 8750,
244                 8625,
245                 8500,
246                 8375,
247                 8250,
248                 8125,
249                 10000,  /* 1.0000V */
250                 10125,
251                 10250,
252                 10375,
253                 10500,
254                 10625,
255                 10750,
256                 10875,
257                 11000,
258                 0,      /* reserved */
259         };
260         struct vdd_drive {
261                 u8 vid;
262                 unsigned voltage;
263         };
264
265         ret = select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR);
266         if (ret) {
267                 debug("VID: I2c failed to switch channel\n");
268                 ret = -1;
269                 goto exit;
270         }
271
272         /* get the voltage ID from fuse status register */
273         fusesr = in_be32(&gur->dcfg_fusesr);
274         vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_VID_SHIFT) &
275                 FSL_CORENET_DCFG_FUSESR_VID_MASK;
276         if (vid == FSL_CORENET_DCFG_FUSESR_VID_MASK) {
277                 vid = (fusesr >> FSL_CORENET_DCFG_FUSESR_ALTVID_SHIFT) &
278                         FSL_CORENET_DCFG_FUSESR_ALTVID_MASK;
279         }
280         vdd_target = vdd[vid];
281
282         /* check override variable for overriding VDD */
283         vdd_string = getenv("t4240qds_vdd_mv");
284         if (vdd_override == 0 && vdd_string &&
285             !strict_strtoul(vdd_string, 10, &vdd_string_override))
286                 vdd_override = vdd_string_override;
287         if (vdd_override >= 819 && vdd_override <= 1212) {
288                 vdd_target = vdd_override * 10; /* convert to 1/10 mV */
289                 debug("VDD override is %lu\n", vdd_override);
290         } else if (vdd_override != 0) {
291                 printf("Invalid value.\n");
292         }
293
294         if (vdd_target == 0) {
295                 debug("VID: VID not used\n");
296                 ret = 0;
297                 goto exit;
298         } else {
299                 /* round up and divice by 10 to get a value in mV */
300                 vdd_target = DIV_ROUND_UP(vdd_target, 10);
301                 debug("VID: vid = %d mV\n", vdd_target);
302         }
303
304         /*
305          * Check current board VID setting
306          * Voltage regulator support output to 6.250mv step
307          * The highes voltage allowed for this board is (vid=0x40) 1.21250V
308          * the lowest is (vid=0x7f) 0.81875V
309          */
310         vid_current =  QIXIS_READ(brdcfg[6]);
311         vdd_current = 121250 - (vid_current - 0x40) * 625;
312         debug("VID: Current vid setting is (0x%x) %d mV\n",
313               vid_current, vdd_current/100);
314
315         /*
316          * Read voltage monitor to check real voltage.
317          * Voltage monitor LSB is 4mv.
318          */
319         vdd_last = read_voltage();
320         if (vdd_last < 0) {
321                 printf("VID: Could not read voltage sensor abort VID adjustment\n");
322                 ret = -1;
323                 goto exit;
324         }
325         debug("VID: Core voltage is at %d mV\n", vdd_last);
326         /*
327          * Adjust voltage to at or 8mV above target.
328          * Each step of adjustment is 6.25mV.
329          * Stepping down too fast may cause over current.
330          */
331         while (vdd_last > 0 && vid_current < 0x80 &&
332                 vdd_last > (vdd_target + 8)) {
333                 vid_current++;
334                 vdd_last = set_voltage(vid_current);
335         }
336         /*
337          * Check if we need to step up
338          * This happens when board voltage switch was set too low
339          */
340         while (vdd_last > 0 && vid_current >= 0x40 &&
341                 vdd_last < vdd_target + 2) {
342                 vid_current--;
343                 vdd_last = set_voltage(vid_current);
344         }
345         if (vdd_last > 0)
346                 printf("VID: Core voltage %d mV\n", vdd_last);
347         else
348                 ret = -1;
349
350 exit:
351         if (re_enable)
352                 enable_interrupts();
353         return ret;
354 }
355
356 /* Configure Crossbar switches for Front-Side SerDes Ports */
357 int config_frontside_crossbar_vsc3316(void)
358 {
359         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
360         u32 srds_prtcl_s1, srds_prtcl_s2;
361         int ret;
362
363         ret = select_i2c_ch_pca9547(I2C_MUX_CH_VSC3316_FS);
364         if (ret)
365                 return ret;
366
367         srds_prtcl_s1 = in_be32(&gur->rcwsr[4]) &
368                         FSL_CORENET2_RCWSR4_SRDS1_PRTCL;
369         srds_prtcl_s1 >>= FSL_CORENET2_RCWSR4_SRDS1_PRTCL_SHIFT;
370         if (srds_prtcl_s1) {
371                 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm1_tx, 8);
372                 if (ret)
373                         return ret;
374                 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm1_rx, 8);
375                 if (ret)
376                         return ret;
377         }
378
379         srds_prtcl_s2 = in_be32(&gur->rcwsr[4]) &
380                                 FSL_CORENET2_RCWSR4_SRDS2_PRTCL;
381         srds_prtcl_s2 >>= FSL_CORENET2_RCWSR4_SRDS2_PRTCL_SHIFT;
382         if (srds_prtcl_s2) {
383                 ret = vsc3316_config(VSC3316_FSM_TX_ADDR, vsc3316_fsm2_tx, 8);
384                 if (ret)
385                         return ret;
386                 ret = vsc3316_config(VSC3316_FSM_RX_ADDR, vsc3316_fsm2_rx, 8);
387                 if (ret)
388                         return ret;
389         }
390
391         return 0;
392 }
393
394 int config_backside_crossbar_mux(void)
395 {
396         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
397         u32 srds_prtcl_s3, srds_prtcl_s4;
398         u8 brdcfg;
399
400         srds_prtcl_s3 = in_be32(&gur->rcwsr[4]) &
401                         FSL_CORENET2_RCWSR4_SRDS3_PRTCL;
402         srds_prtcl_s3 >>= FSL_CORENET2_RCWSR4_SRDS3_PRTCL_SHIFT;
403         switch (srds_prtcl_s3) {
404         case 0:
405                 /* SerDes3 is not enabled */
406                 break;
407         case 2:
408         case 9:
409         case 10:
410                 /* SD3(0:7) => SLOT5(0:7) */
411                 brdcfg = QIXIS_READ(brdcfg[12]);
412                 brdcfg &= ~BRDCFG12_SD3MX_MASK;
413                 brdcfg |= BRDCFG12_SD3MX_SLOT5;
414                 QIXIS_WRITE(brdcfg[12], brdcfg);
415                 break;
416         case 4:
417         case 6:
418         case 8:
419         case 12:
420         case 14:
421         case 16:
422         case 17:
423         case 19:
424         case 20:
425                 /* SD3(4:7) => SLOT6(0:3) */
426                 brdcfg = QIXIS_READ(brdcfg[12]);
427                 brdcfg &= ~BRDCFG12_SD3MX_MASK;
428                 brdcfg |= BRDCFG12_SD3MX_SLOT6;
429                 QIXIS_WRITE(brdcfg[12], brdcfg);
430                 break;
431         default:
432                 printf("WARNING: unsupported for SerDes3 Protocol %d\n",
433                                 srds_prtcl_s3);
434                 return -1;
435         }
436
437         srds_prtcl_s4 = in_be32(&gur->rcwsr[4]) &
438                         FSL_CORENET2_RCWSR4_SRDS4_PRTCL;
439         srds_prtcl_s4 >>= FSL_CORENET2_RCWSR4_SRDS4_PRTCL_SHIFT;
440         switch (srds_prtcl_s4) {
441         case 0:
442                 /* SerDes4 is not enabled */
443                 break;
444         case 2:
445                 /* 10b, SD4(0:7) => SLOT7(0:7) */
446                 brdcfg = QIXIS_READ(brdcfg[12]);
447                 brdcfg &= ~BRDCFG12_SD4MX_MASK;
448                 brdcfg |= BRDCFG12_SD4MX_SLOT7;
449                 QIXIS_WRITE(brdcfg[12], brdcfg);
450                 break;
451         case 4:
452         case 6:
453         case 8:
454                 /* x1b, SD4(4:7) => SLOT8(0:3) */
455                 brdcfg = QIXIS_READ(brdcfg[12]);
456                 brdcfg &= ~BRDCFG12_SD4MX_MASK;
457                 brdcfg |= BRDCFG12_SD4MX_SLOT8;
458                 QIXIS_WRITE(brdcfg[12], brdcfg);
459                 break;
460         case 10:
461         case 12:
462         case 14:
463         case 16:
464         case 18:
465                 /* 00b, SD4(4:5) => AURORA, SD4(6:7) => SATA */
466                 brdcfg = QIXIS_READ(brdcfg[12]);
467                 brdcfg &= ~BRDCFG12_SD4MX_MASK;
468                 brdcfg |= BRDCFG12_SD4MX_AURO_SATA;
469                 QIXIS_WRITE(brdcfg[12], brdcfg);
470                 break;
471         default:
472                 printf("WARNING: unsupported for SerDes4 Protocol %d\n",
473                                 srds_prtcl_s4);
474                 return -1;
475         }
476
477         return 0;
478 }
479
480 int board_early_init_r(void)
481 {
482         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
483         const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
484
485         /*
486          * Remap Boot flash + PROMJET region to caching-inhibited
487          * so that flash can be erased properly.
488          */
489
490         /* Flush d-cache and invalidate i-cache of any FLASH data */
491         flush_dcache();
492         invalidate_icache();
493
494         /* invalidate existing TLB entry for flash + promjet */
495         disable_tlb(flash_esel);
496
497         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
498                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
499                         0, flash_esel, BOOKE_PAGESZ_256M, 1);
500
501         set_liodns();
502 #ifdef CONFIG_SYS_DPAA_QBMAN
503         setup_portals();
504 #endif
505
506         /* Disable remote I2C connection to qixis fpga */
507         QIXIS_WRITE(brdcfg[5], QIXIS_READ(brdcfg[5]) & ~BRDCFG5_IRE);
508
509         /*
510          * Adjust core voltage according to voltage ID
511          * This function changes I2C mux to channel 2.
512          */
513         if (adjust_vdd(0))
514                 printf("Warning: Adjusting core voltage failed.\n");
515
516         /* Configure board SERDES ports crossbar */
517         config_frontside_crossbar_vsc3316();
518         config_backside_crossbar_mux();
519         select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
520
521         return 0;
522 }
523
524 unsigned long get_board_sys_clk(void)
525 {
526         u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
527 #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
528         /* use accurate clock measurement */
529         int freq = QIXIS_READ(clk_freq[0]) << 8 | QIXIS_READ(clk_freq[1]);
530         int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
531         u32 val;
532
533         val =  freq * base;
534         if (val) {
535                 debug("SYS Clock measurement is: %d\n", val);
536                 return val;
537         } else {
538                 printf("Warning: SYS clock measurement is invalid, using value from brdcfg1.\n");
539         }
540 #endif
541
542         switch (sysclk_conf & 0x0F) {
543         case QIXIS_SYSCLK_83:
544                 return 83333333;
545         case QIXIS_SYSCLK_100:
546                 return 100000000;
547         case QIXIS_SYSCLK_125:
548                 return 125000000;
549         case QIXIS_SYSCLK_133:
550                 return 133333333;
551         case QIXIS_SYSCLK_150:
552                 return 150000000;
553         case QIXIS_SYSCLK_160:
554                 return 160000000;
555         case QIXIS_SYSCLK_166:
556                 return 166666666;
557         }
558         return 66666666;
559 }
560
561 unsigned long get_board_ddr_clk(void)
562 {
563         u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
564 #ifdef CONFIG_FSL_QIXIS_CLOCK_MEASUREMENT
565         /* use accurate clock measurement */
566         int freq = QIXIS_READ(clk_freq[2]) << 8 | QIXIS_READ(clk_freq[3]);
567         int base = QIXIS_READ(clk_base[0]) << 8 | QIXIS_READ(clk_base[1]);
568         u32 val;
569
570         val =  freq * base;
571         if (val) {
572                 debug("DDR Clock measurement is: %d\n", val);
573                 return val;
574         } else {
575                 printf("Warning: DDR clock measurement is invalid, using value from brdcfg1.\n");
576         }
577 #endif
578
579         switch ((ddrclk_conf & 0x30) >> 4) {
580         case QIXIS_DDRCLK_100:
581                 return 100000000;
582         case QIXIS_DDRCLK_125:
583                 return 125000000;
584         case QIXIS_DDRCLK_133:
585                 return 133333333;
586         }
587         return 66666666;
588 }
589
590 static const char *serdes_clock_to_string(u32 clock)
591 {
592         switch (clock) {
593         case SRDS_PLLCR0_RFCK_SEL_100:
594                 return "100";
595         case SRDS_PLLCR0_RFCK_SEL_125:
596                 return "125";
597         case SRDS_PLLCR0_RFCK_SEL_156_25:
598                 return "156.25";
599         case SRDS_PLLCR0_RFCK_SEL_161_13:
600                 return "161.1328125";
601         default:
602                 return "???";
603         }
604 }
605
606 int misc_init_r(void)
607 {
608         u8 sw;
609         serdes_corenet_t *srds_regs =
610                 (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
611         u32 actual[MAX_SERDES];
612         unsigned int i;
613
614         sw = QIXIS_READ(brdcfg[2]);
615         for (i = 0; i < MAX_SERDES; i++) {
616                 unsigned int clock = (sw >> (6 - 2 * i)) & 3;
617                 switch (clock) {
618                 case 0:
619                         actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
620                         break;
621                 case 1:
622                         actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
623                         break;
624                 case 2:
625                         actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
626                         break;
627                 case 3:
628                         actual[i] = SRDS_PLLCR0_RFCK_SEL_161_13;
629                         break;
630                 }
631         }
632
633         for (i = 0; i < MAX_SERDES; i++) {
634                 u32 pllcr0 = srds_regs->bank[i].pllcr0;
635                 u32 expected = pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
636                 if (expected != actual[i]) {
637                         printf("Warning: SERDES%u expects reference clock"
638                                " %sMHz, but actual is %sMHz\n", i + 1,
639                                serdes_clock_to_string(expected),
640                                serdes_clock_to_string(actual[i]));
641                 }
642         }
643
644         return 0;
645 }
646
647 void ft_board_setup(void *blob, bd_t *bd)
648 {
649         phys_addr_t base;
650         phys_size_t size;
651
652         ft_cpu_setup(blob, bd);
653
654         base = getenv_bootm_low();
655         size = getenv_bootm_size();
656
657         fdt_fixup_memory(blob, (u64)base, (u64)size);
658
659 #ifdef CONFIG_PCI
660         pci_of_setup(blob, bd);
661 #endif
662
663         fdt_fixup_liodn(blob);
664         fdt_fixup_dr_usb(blob, bd);
665
666 #ifdef CONFIG_SYS_DPAA_FMAN
667         fdt_fixup_fman_ethernet(blob);
668         fdt_fixup_board_enet(blob);
669 #endif
670 }
671
672 /*
673  * This function is called by bdinfo to print detail board information.
674  * As an exmaple for future board, we organize the messages into
675  * several sections. If applicable, the message is in the format of
676  * <name>      = <value>
677  * It should aligned with normal output of bdinfo command.
678  *
679  * Voltage: Core, DDR and another configurable voltages
680  * Clock  : Critical clocks which are not printed already
681  * RCW    : RCW source if not printed already
682  * Misc   : Other important information not in above catagories
683  */
684 void board_detail(void)
685 {
686         int i;
687         u8 brdcfg[16], dutcfg[16], rst_ctl;
688         int vdd, rcwsrc;
689         static const char * const clk[] = {"66.67", "100", "125", "133.33"};
690
691         for (i = 0; i < 16; i++) {
692                 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
693                 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
694         }
695
696         /* Voltage secion */
697         if (!select_i2c_ch_pca9547(I2C_MUX_CH_VOL_MONITOR)) {
698                 vdd = read_voltage();
699                 if (vdd > 0)
700                         printf("Core voltage= %d mV\n", vdd);
701                 select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
702         }
703
704         printf("XVDD        = 1.%d V\n", ((brdcfg[8] & 0xf) - 4) * 5 + 25);
705
706         /* clock section */
707         printf("SYSCLK      = %s MHz\nDDRCLK      = %s MHz\n",
708                clk[(brdcfg[11] >> 2) & 0x3], clk[brdcfg[11] & 3]);
709
710         /* RCW section */
711         rcwsrc = (dutcfg[0] << 1) + (dutcfg[1] & 1);
712         puts("RCW source  = ");
713         switch (rcwsrc) {
714         case 0x017:
715         case 0x01f:
716                 puts("8-bit NOR\n");
717                 break;
718         case 0x027:
719         case 0x02F:
720                 puts("16-bit NOR\n");
721                 break;
722         case 0x040:
723                 puts("SDHC/eMMC\n");
724                 break;
725         case 0x044:
726                 puts("SPI 16-bit addressing\n");
727                 break;
728         case 0x045:
729                 puts("SPI 24-bit addressing\n");
730                 break;
731         case 0x048:
732                 puts("I2C normal addressing\n");
733                 break;
734         case 0x049:
735                 puts("I2C extended addressing\n");
736                 break;
737         case 0x108:
738         case 0x109:
739         case 0x10a:
740         case 0x10b:
741                 puts("8-bit NAND, 2KB\n");
742                 break;
743         default:
744                 if ((rcwsrc >= 0x080) && (rcwsrc <= 0x09f))
745                         puts("Hard-coded RCW\n");
746                 else if ((rcwsrc >= 0x110) && (rcwsrc <= 0x11f))
747                         puts("8-bit NAND, 4KB\n");
748                 else
749                         puts("unknown\n");
750                 break;
751         }
752
753         /* Misc section */
754         rst_ctl = QIXIS_READ(rst_ctl);
755         puts("HRESET_REQ  = ");
756         switch (rst_ctl & 0x30) {
757         case 0x00:
758                 puts("Ignored\n");
759                 break;
760         case 0x10:
761                 puts("Assert HRESET\n");
762                 break;
763         case 0x30:
764                 puts("Reset system\n");
765                 break;
766         default:
767                 puts("N/A\n");
768                 break;
769         }
770 }
771
772 /*
773  * Reverse engineering switch settings.
774  * Some bits cannot be figured out. They will be displayed as
775  * underscore in binary format. mask[] has those bits.
776  * Some bits are calculated differently than the actual switches
777  * if booting with overriding by FPGA.
778  */
779 void qixis_dump_switch(void)
780 {
781         int i;
782         u8 sw[9];
783
784         /*
785          * Any bit with 1 means that bit cannot be reverse engineered.
786          * It will be displayed as _ in binary format.
787          */
788         static const u8 mask[] = {0, 0, 0, 0, 0, 0x1, 0xcf, 0x3f, 0x1f};
789         char buf[10];
790         u8 brdcfg[16], dutcfg[16];
791
792         for (i = 0; i < 16; i++) {
793                 brdcfg[i] = qixis_read(offsetof(struct qixis, brdcfg[0]) + i);
794                 dutcfg[i] = qixis_read(offsetof(struct qixis, dutcfg[0]) + i);
795         }
796
797         sw[0] = dutcfg[0];
798         sw[1] = (dutcfg[1] << 0x07)             | \
799                 ((dutcfg[12] & 0xC0) >> 1)      | \
800                 ((dutcfg[11] & 0xE0) >> 3)      | \
801                 ((dutcfg[6] & 0x80) >> 6)       | \
802                 ((dutcfg[1] & 0x80) >> 7);
803         sw[2] = ((brdcfg[1] & 0x0f) << 4)       | \
804                 ((brdcfg[1] & 0x30) >> 2)       | \
805                 ((brdcfg[1] & 0x40) >> 5)       | \
806                 ((brdcfg[1] & 0x80) >> 7);
807         sw[3] = brdcfg[2];
808         sw[4] = ((dutcfg[2] & 0x01) << 7)       | \
809                 ((dutcfg[2] & 0x06) << 4)       | \
810                 ((~QIXIS_READ(present)) & 0x10) | \
811                 ((brdcfg[3] & 0x80) >> 4)       | \
812                 ((brdcfg[3] & 0x01) << 2)       | \
813                 ((brdcfg[6] == 0x62) ? 3 :      \
814                 ((brdcfg[6] == 0x5a) ? 2 :      \
815                 ((brdcfg[6] == 0x5e) ? 1 : 0)));
816         sw[5] = ((brdcfg[0] & 0x0f) << 4)       | \
817                 ((QIXIS_READ(rst_ctl) & 0x30) >> 2) | \
818                 ((brdcfg[0] & 0x40) >> 5);
819         sw[6] = (brdcfg[11] & 0x20)             |
820                 ((brdcfg[5] & 0x02) << 3);
821         sw[7] = (((~QIXIS_READ(rst_ctl)) & 0x40) << 1) | \
822                 ((brdcfg[5] & 0x10) << 2);
823         sw[8] = ((brdcfg[12] & 0x08) << 4)      | \
824                 ((brdcfg[12] & 0x03) << 5);
825
826         puts("DIP switch (reverse-engineering)\n");
827         for (i = 0; i < 9; i++) {
828                 printf("SW%d         = 0b%s (0x%02x)\n",
829                         i + 1, byte_to_binary_mask(sw[i], mask[i], buf), sw[i]);
830         }
831 }
832
833 static int do_vdd_adjust(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
834 {
835         ulong override;
836
837         if (argc < 2)
838                 return CMD_RET_USAGE;
839         if (!strict_strtoul(argv[1], 10, &override))
840                 adjust_vdd(override);   /* the value is checked by callee */
841         else
842                 return CMD_RET_USAGE;
843
844         return 0;
845 }
846
847 U_BOOT_CMD(
848         vdd_override, 2, 0, do_vdd_adjust,
849         "Override VDD",
850         "- override with the voltage specified in mV, eg. 1050"
851 );