Merge branch '2020-05-18-reduce-size-of-common.h'
[platform/kernel/u-boot.git] / board / freescale / corenet_ds / corenet_ds.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2009-2011 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <command.h>
8 #include <env.h>
9 #include <fdt_support.h>
10 #include <image.h>
11 #include <init.h>
12 #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>
20 #include <asm/fsl_liodn.h>
21 #include <fm_eth.h>
22
23 #include "../common/ngpixis.h"
24 #include "corenet_ds.h"
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 int checkboard (void)
29 {
30         u8 sw;
31         struct cpu_type *cpu = gd->arch.cpu;
32 #if defined(CONFIG_TARGET_P3041DS) || defined(CONFIG_TARGET_P5020DS) || \
33         defined(CONFIG_TARGET_P5040DS)
34         unsigned int i;
35 #endif
36         static const char * const freq[] = {"100", "125", "156.25", "212.5" };
37
38         printf("Board: %sDS, ", cpu->name);
39         printf("Sys ID: 0x%02x, Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
40                 in_8(&pixis->id), in_8(&pixis->arch), in_8(&pixis->scver));
41
42         sw = in_8(&PIXIS_SW(PIXIS_LBMAP_SWITCH));
43         sw = (sw & PIXIS_LBMAP_MASK) >> PIXIS_LBMAP_SHIFT;
44
45         if (sw < 0x8)
46                 printf("vBank: %d\n", sw);
47         else if (sw == 0x8)
48                 puts("Promjet\n");
49         else if (sw == 0x9)
50                 puts("NAND\n");
51         else
52                 printf("invalid setting of SW%u\n", PIXIS_LBMAP_SWITCH);
53
54         /* Display the actual SERDES reference clocks as configured by the
55          * dip switches on the board.  Note that the SWx registers could
56          * technically be set to force the reference clocks to match the
57          * values that the SERDES expects (or vice versa).  For now, however,
58          * we just display both values and hope the user notices when they
59          * don't match.
60          */
61         puts("SERDES Reference Clocks: ");
62 #if defined(CONFIG_TARGET_P3041DS) || defined(CONFIG_TARGET_P5020DS) || \
63         defined(CONFIG_TARGET_P5040DS)
64         sw = in_8(&PIXIS_SW(5));
65         for (i = 0; i < 3; i++) {
66                 unsigned int clock = (sw >> (6 - (2 * i))) & 3;
67
68                 printf("Bank%u=%sMhz ", i+1, freq[clock]);
69         }
70 #ifdef CONFIG_TARGET_P5040DS
71         /* On P5040DS, SW11[7:8] determines the Bank 4 frequency */
72         sw = in_8(&PIXIS_SW(9));
73         printf("Bank4=%sMhz ", freq[sw & 3]);
74 #endif
75         puts("\n");
76 #else
77         sw = in_8(&PIXIS_SW(3));
78         /* SW3[2]: 0 = 100 Mhz, 1 = 125 MHz */
79         /* SW3[3]: 0 = 125 Mhz, 1 = 156.25 MHz */
80         /* SW3[4]: 0 = 125 Mhz, 1 = 156.25 MHz */
81         printf("Bank1=%sMHz ", freq[!!(sw & 0x40)]);
82         printf("Bank2=%sMHz ", freq[1 + !!(sw & 0x20)]);
83         printf("Bank3=%sMHz\n", freq[1 + !!(sw & 0x10)]);
84 #endif
85
86         return 0;
87 }
88
89 int board_early_init_f(void)
90 {
91         volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
92
93         /*
94          * P4080 DS board only uses the DDR1_MCK0/3 and DDR2_MCK0/3
95          * disable the DDR1_MCK1/2/4/5 and DDR2_MCK1/2/4/5 to reduce
96          * the noise introduced by these unterminated and unused clock pairs.
97          */
98         setbits_be32(&gur->ddrclkdr, 0x001B001B);
99
100         return 0;
101 }
102
103 int board_early_init_r(void)
104 {
105         const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
106         int flash_esel = find_tlb_idx((void *)flashbase, 1);
107
108         /*
109          * Remap Boot flash + PROMJET region to caching-inhibited
110          * so that flash can be erased properly.
111          */
112
113         /* Flush d-cache and invalidate i-cache of any FLASH data */
114         flush_dcache();
115         invalidate_icache();
116
117         if (flash_esel == -1) {
118                 /* very unlikely unless something is messed up */
119                 puts("Error: Could not find TLB for FLASH BASE\n");
120                 flash_esel = 2; /* give our best effort to continue */
121         } else {
122                 /* invalidate existing TLB entry for flash + promjet */
123                 disable_tlb(flash_esel);
124         }
125
126         set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,       /* tlb, epn, rpn */
127                         MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G, /* perms, wimge */
128                         0, flash_esel, BOOKE_PAGESZ_256M, 1);   /* ts, esel, tsize, iprot */
129
130         return 0;
131 }
132
133 #define NUM_SRDS_BANKS  3
134
135 int misc_init_r(void)
136 {
137         serdes_corenet_t *srds_regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
138         u32 actual[NUM_SRDS_BANKS];
139         unsigned int i;
140         u8 sw;
141
142 #if defined(CONFIG_TARGET_P3041DS) || defined(CONFIG_TARGET_P5020DS) || \
143         defined(CONFIG_TARGET_P5040DS)
144         sw = in_8(&PIXIS_SW(5));
145         for (i = 0; i < 3; i++) {
146                 unsigned int clock = (sw >> (6 - (2 * i))) & 3;
147                 switch (clock) {
148                 case 0:
149                         actual[i] = SRDS_PLLCR0_RFCK_SEL_100;
150                         break;
151                 case 1:
152                         actual[i] = SRDS_PLLCR0_RFCK_SEL_125;
153                         break;
154                 case 2:
155                         actual[i] = SRDS_PLLCR0_RFCK_SEL_156_25;
156                         break;
157                 default:
158                         printf("Warning: SDREFCLK%u switch setting of '11' is "
159                                "unsupported\n", i + 1);
160                         break;
161                 }
162         }
163 #else
164         /* Warn if the expected SERDES reference clocks don't match the
165          * actual reference clocks.  This needs to be done after calling
166          * p4080_erratum_serdes8(), since that function may modify the clocks.
167          */
168         sw = in_8(&PIXIS_SW(3));
169         actual[0] = (sw & 0x40) ?
170                 SRDS_PLLCR0_RFCK_SEL_125 : SRDS_PLLCR0_RFCK_SEL_100;
171         actual[1] = (sw & 0x20) ?
172                 SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
173         actual[2] = (sw & 0x10) ?
174                 SRDS_PLLCR0_RFCK_SEL_156_25 : SRDS_PLLCR0_RFCK_SEL_125;
175 #endif
176
177         for (i = 0; i < NUM_SRDS_BANKS; i++) {
178                 u32 expected = srds_regs->bank[i].pllcr0 & SRDS_PLLCR0_RFCK_SEL_MASK;
179                 if (expected != actual[i]) {
180                         printf("Warning: SERDES bank %u expects reference clock"
181                                " %sMHz, but actual is %sMHz\n", i + 1,
182                                serdes_clock_to_string(expected),
183                                serdes_clock_to_string(actual[i]));
184                 }
185         }
186
187         return 0;
188 }
189
190 int ft_board_setup(void *blob, bd_t *bd)
191 {
192         phys_addr_t base;
193         phys_size_t size;
194
195         ft_cpu_setup(blob, bd);
196
197         base = env_get_bootm_low();
198         size = env_get_bootm_size();
199
200         fdt_fixup_memory(blob, (u64)base, (u64)size);
201
202 #ifdef CONFIG_PCI
203         pci_of_setup(blob, bd);
204 #endif
205
206         fdt_fixup_liodn(blob);
207         fsl_fdt_fixup_dr_usb(blob, bd);
208
209 #ifdef CONFIG_SYS_DPAA_FMAN
210         fdt_fixup_fman_ethernet(blob);
211         fdt_fixup_board_enet(blob);
212 #endif
213
214         return 0;
215 }