]> git.sur5r.net Git - u-boot/blob - board/freescale/p2041rdb/p2041rdb.c
powerpc/p2041rdb: Add ethernet support on P2041RDB board
[u-boot] / board / freescale / p2041rdb / p2041rdb.c
1 /*
2  * Copyright 2011 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_serdes.h>
33 #include <asm/fsl_portals.h>
34 #include <asm/fsl_liodn.h>
35 #include <fm_eth.h>
36
37 extern void pci_of_setup(void *blob, bd_t *bd);
38
39 #include "cpld.h"
40
41 DECLARE_GLOBAL_DATA_PTR;
42
43 int checkboard(void)
44 {
45         u8 sw;
46         struct cpu_type *cpu = gd->cpu;
47         ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
48         unsigned int i;
49
50         printf("Board: %sRDB, ", cpu->name);
51         printf("CPLD version: %d.%d ", CPLD_READ(cpld_ver),
52                         CPLD_READ(cpld_ver_sub));
53
54         sw = CPLD_READ(fbank_sel);
55         printf("vBank: %d\n", sw & 0x1);
56
57 #ifdef CONFIG_PHYS_64BIT
58         puts("36-bit Addressing\n");
59 #endif
60
61         /*
62          * Display the RCW, so that no one gets confused as to what RCW
63          * we're actually using for this boot.
64          */
65         puts("Reset Configuration Word (RCW):");
66         for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
67                 u32 rcw = in_be32(&gur->rcwsr[i]);
68
69                 if ((i % 4) == 0)
70                         printf("\n       %08x:", i * 4);
71                 printf(" %08x", rcw);
72         }
73         puts("\n");
74
75         /*
76          * Display the actual SERDES reference clocks as configured by the
77          * dip switches on the board.  Note that the SWx registers could
78          * technically be set to force the reference clocks to match the
79          * values that the SERDES expects (or vice versa).  For now, however,
80          * we just display both values and hope the user notices when they
81          * don't match.
82          */
83         puts("SERDES Reference Clocks: ");
84         sw = in_8(&CPLD_SW(2)) >> 2;
85         for (i = 0; i < 2; i++) {
86                 static const char * const freq[] = {"0", "100", "125"};
87                 unsigned int clock = (sw >> (2 * i)) & 3;
88
89                 printf("Bank%u=%sMhz ", i+1, freq[clock]);
90         }
91         puts("\n");
92
93         return 0;
94 }
95
96 int board_early_init_f(void)
97 {
98         ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
99
100         /* board only uses the DDR_MCK0/1, so disable the DDR_MCK2/3 */
101         setbits_be32(&gur->ddrclkdr, 0x000f000f);
102
103         return 0;
104 }
105
106 int board_early_init_r(void)
107 {
108         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
109         const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
110
111         /*
112          * Remap Boot flash + PROMJET region to caching-inhibited
113          * so that flash can be erased properly.
114          */
115
116         /* Flush d-cache and invalidate i-cache of any FLASH data */
117         flush_dcache();
118         invalidate_icache();
119
120         /* invalidate existing TLB entry for flash + promjet */
121         disable_tlb(flash_esel);
122
123         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
124                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
125                         0, flash_esel, BOOKE_PAGESZ_256M, 1);
126
127         set_liodns();
128         setup_portals();
129
130         return 0;
131 }
132
133 static const char *serdes_clock_to_string(u32 clock)
134 {
135         switch (clock) {
136         case SRDS_PLLCR0_RFCK_SEL_100:
137                 return "100";
138         case SRDS_PLLCR0_RFCK_SEL_125:
139                 return "125";
140         case SRDS_PLLCR0_RFCK_SEL_156_25:
141                 return "156.25";
142         default:
143                 return "150";
144         }
145 }
146
147 #define NUM_SRDS_BANKS  2
148
149 int misc_init_r(void)
150 {
151         serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
152         u32 actual[NUM_SRDS_BANKS];
153         unsigned int i;
154         u8 sw;
155
156         sw = in_8(&CPLD_SW(2)) >> 2;
157         for (i = 0; i < NUM_SRDS_BANKS; i++) {
158                 unsigned int clock = (sw >> (2 * i)) & 3;
159                 switch (clock) {
160                 case 1:
161                         actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
162                         break;
163                 case 2:
164                         actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
165                         break;
166                 default:
167                         printf("Warning: SDREFCLK%u switch setting of '11' is "
168                                "unsupported\n", i + 1);
169                         break;
170                 }
171         }
172
173         for (i = 0; i < NUM_SRDS_BANKS; i++) {
174                 u32 expected = in_be32(&regs->bank[i].pllcr0);
175                 expected &= SRDS_PLLCR0_RFCK_SEL_MASK;
176                 if (expected != actual[i]) {
177                         printf("Warning: SERDES bank %u expects reference clock"
178                                " %sMHz, but actual is %sMHz\n", i + 1,
179                                serdes_clock_to_string(expected),
180                                serdes_clock_to_string(actual[i]));
181                 }
182         }
183
184         return 0;
185 }
186
187 void ft_board_setup(void *blob, bd_t *bd)
188 {
189         phys_addr_t base;
190         phys_size_t size;
191
192         ft_cpu_setup(blob, bd);
193
194         base = getenv_bootm_low();
195         size = getenv_bootm_size();
196
197         fdt_fixup_memory(blob, (u64)base, (u64)size);
198
199 #ifdef CONFIG_PCI
200         pci_of_setup(blob, bd);
201 #endif
202
203         fdt_fixup_liodn(blob);
204 #ifdef CONFIG_SYS_DPAA_FMAN
205         fdt_fixup_fman_ethernet(blob);
206 #endif
207 }