]> git.sur5r.net Git - u-boot/blob - board/freescale/corenet_ds/corenet_ds.c
Merge branch 'master' of git://git.denx.de/u-boot-mips
[u-boot] / board / freescale / corenet_ds / corenet_ds.c
1 /*
2  * Copyright 2009-2010 Freescale Semiconductor, Inc.
3  *
4  * See file CREDITS for list of people who contributed to this
5  * project.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20  * MA 02111-1307 USA
21  */
22
23 #include <common.h>
24 #include <command.h>
25 #include <netdev.h>
26 #include <linux/compiler.h>
27 #include <asm/mmu.h>
28 #include <asm/processor.h>
29 #include <asm/cache.h>
30 #include <asm/immap_85xx.h>
31 #include <asm/fsl_law.h>
32 #include <asm/fsl_ddr_sdram.h>
33 #include <asm/fsl_serdes.h>
34 #include <asm/fsl_portals.h>
35 #include <asm/fsl_liodn.h>
36
37 extern void pci_of_setup(void *blob, bd_t *bd);
38
39 #include "../common/ngpixis.h"
40
41 DECLARE_GLOBAL_DATA_PTR;
42
43 void cpu_mp_lmb_reserve(struct lmb *lmb);
44
45 int checkboard (void)
46 {
47         u8 sw;
48         struct cpu_type *cpu = gd->cpu;
49
50         printf("Board: %sDS, ", cpu->name);
51         printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
52                 in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
53
54         sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
55         sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_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", PIXIS_LBMAP_SWITCH);
65
66 #ifdef CONFIG_PHYS_64BIT
67         puts("36-bit Addressing\n");
68 #endif
69
70         /* Display the actual SERDES reference clocks as configured by the
71          * dip switches on the board.  Note that the SWx registers could
72          * technically be set to force the reference clocks to match the
73          * values that the SERDES expects (or vice versa).  For now, however,
74          * we just display both values and hope the user notices when they
75          * don't match.
76          */
77         puts("SERDES Reference Clocks: ");
78         sw = in_8(&PIXIS_SW(3));
79         printf("Bank1=%uMHz ", (sw & 0x40) ? 125 : 100);
80         printf("Bank2=%sMHz ", (sw & 0x20) ? "156.25" : "125");
81         printf("Bank3=%sMHz\n", (sw & 0x10) ? "156.25" : "125");
82
83         return 0;
84 }
85
86 int board_early_init_f(void)
87 {
88         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
89
90         /*
91          * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3
92          * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce
93          * the noise introduced by these unterminated and unused clock pairs.
94          */
95         setbits_be32(&gur->ddrclkdr, 0x001B001B);
96
97         return 0;
98 }
99
100 int board_early_init_r(void)
101 {
102         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
103         const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
104
105         /*
106          * Remap Boot flash + PROMJET region to caching-inhibited
107          * so that flash can be erased properly.
108          */
109
110         /* Flush d-cache and invalidate i-cache of any FLASH data */
111         flush_dcache();
112         invalidate_icache();
113
114         /* invalidate existing TLB entry for flash + promjet */
115         disable_tlb(flash_esel);
116
117         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,       /* tlb, epn, rpn */
118                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
119                         0, flash_esel, BOOKE_PAGESZ_256M, 1);   /* ts, esel, tsize, iprot */
120
121         set_liodns();
122         setup_portals();
123
124         return 0;
125 }
126
127 static const char *serdes_clock_to_string(u32 clock)
128 {
129         switch(clock) {
130         case SRDS_PLLCR0_RFCK_SEL_100:
131                 return "100";
132         case SRDS_PLLCR0_RFCK_SEL_125:
133                 return "125";
134         case SRDS_PLLCR0_RFCK_SEL_156_25:
135                 return "156.25";
136         default:
137                 return "???";
138         }
139 }
140
141 #define NUM_SRDS_BANKS  3
142
143 int misc_init_r(void)
144 {
145         serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
146         __maybe_unused ccsr_gur_t *gur;
147         u32 actual[NUM_SRDS_BANKS];
148         unsigned int i;
149         u8 sw3;
150
151         gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
152 #ifdef CONFIG_SRIO1
153         if (is_serdes_configured(SRIO1)) {
154                 set_next_law(CONFIG_SYS_RIO1_MEM_PHYS, LAW_SIZE_256M,
155                                 LAW_TRGT_IF_RIO_1);
156         } else {
157                 printf ("    SRIO1: disabled\n");
158         }
159 #else
160         setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO1); /* disable */
161 #endif
162
163 #ifdef CONFIG_SRIO2
164         if (is_serdes_configured(SRIO2)) {
165                 set_next_law(CONFIG_SYS_RIO2_MEM_PHYS, LAW_SIZE_256M,
166                                 LAW_TRGT_IF_RIO_2);
167         } else {
168                 printf ("    SRIO2: disabled\n");
169         }
170 #else
171         setbits_be32(&gur->devdisr, FSL_CORENET_DEVDISR_SRIO2); /* disable */
172 #endif
173
174         /* Warn if the expected SERDES reference clocks don't match the
175          * actual reference clocks.  This needs to be done after calling
176          * p4080_erratum_serdes8(), since that function may modify the clocks.
177          */
178         sw3 = in_8(&PIXIS_SW(3));
179         actual[0] = (sw3 & 0x40) ?
180                 SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100;
181         actual[1] = (sw3 & 0x20) ?
182                 SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
183         actual[2] = (sw3 & 0x10) ?
184                 SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
185
186         for (i = 0; i < NUM_SRDS_BANKS; i++) {
187                 u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
188                 if (expected != actual[i]) {
189                         printf("Warning: SERDES bank %u expects reference clock"
190                                " %sMHz, but actual is %sMHz\n", i + 1,
191                                serdes_clock_to_string(expected),
192                                serdes_clock_to_string(actual[i]));
193                 }
194         }
195
196         return 0;
197 }
198
199 phys_size_t initdram(int board_type)
200 {
201         phys_size_t dram_size;
202
203         puts("Initializing....\n");
204
205         dram_size = fsl_ddr_sdram();
206
207         setup_ddr_tlbs(dram_size / 0x100000);
208
209         puts("    DDR: ");
210         return dram_size;
211 }
212
213 #ifdef CONFIG_MP
214 void board_lmb_reserve(struct lmb *lmb)
215 {
216         cpu_mp_lmb_reserve(lmb);
217 }
218 #endif
219
220 void ft_srio_setup(void *blob)
221 {
222 #ifdef CONFIG_SRIO1
223         if (!is_serdes_configured(SRIO1)) {
224                 fdt_del_node_and_alias(blob, "rio0");
225         }
226 #else
227         fdt_del_node_and_alias(blob, "rio0");
228 #endif
229 #ifdef CONFIG_SRIO2
230         if (!is_serdes_configured(SRIO2)) {
231                 fdt_del_node_and_alias(blob, "rio1");
232         }
233 #else
234         fdt_del_node_and_alias(blob, "rio1");
235 #endif
236 }
237
238 void ft_board_setup(void *blob, bd_t *bd)
239 {
240         phys_addr_t base;
241         phys_size_t size;
242
243         ft_cpu_setup(blob, bd);
244
245         ft_srio_setup(blob);
246
247         base = getenv_bootm_low();
248         size = getenv_bootm_size();
249
250         fdt_fixup_memory(blob, (u64)base, (u64)size);
251
252 #ifdef CONFIG_PCI
253         pci_of_setup(blob, bd);
254 #endif
255
256         fdt_fixup_liodn(blob);
257 }
258
259 int board_eth_init(bd_t *bis)
260 {
261         return pci_eth_init(bis);
262 }