3f070353c3626260c3f21006bcfbca78fb101b9c
[oweals/u-boot.git] / board / freescale / mpc8641hpcn / mpc8641hpcn.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2006, 2007, 2010-2011 Freescale Semiconductor.
4  */
5
6 #include <common.h>
7 #include <init.h>
8 #include <log.h>
9 #include <net.h>
10 #include <pci.h>
11 #include <asm/processor.h>
12 #include <asm/immap_86xx.h>
13 #include <asm/fsl_pci.h>
14 #include <fsl_ddr_sdram.h>
15 #include <asm/fsl_serdes.h>
16 #include <asm/io.h>
17 #include <linux/libfdt.h>
18 #include <fdt_support.h>
19 #include <netdev.h>
20
21 DECLARE_GLOBAL_DATA_PTR;
22
23 phys_size_t fixed_sdram(void);
24
25 int checkboard(void)
26 {
27         u8 vboot;
28         u8 *pixis_base = (u8 *)PIXIS_BASE;
29
30         printf ("Board: MPC8641HPCN, Sys ID: 0x%02x, "
31                 "Sys Ver: 0x%02x, FPGA Ver: 0x%02x, ",
32                 in_8(pixis_base + PIXIS_ID), in_8(pixis_base + PIXIS_VER),
33                 in_8(pixis_base + PIXIS_PVER));
34
35         vboot = in_8(pixis_base + PIXIS_VBOOT);
36         if (vboot & PIXIS_VBOOT_FMAP)
37                 printf ("vBank: %d\n", ((vboot & PIXIS_VBOOT_FBANK) >> 6));
38         else
39                 puts ("Promjet\n");
40
41         return 0;
42 }
43
44 int dram_init(void)
45 {
46         phys_size_t dram_size = 0;
47
48 #if defined(CONFIG_SPD_EEPROM)
49         dram_size = fsl_ddr_sdram();
50 #else
51         dram_size = fixed_sdram();
52 #endif
53
54         setup_ddr_bat(dram_size);
55
56         debug("    DDR: ");
57         gd->ram_size = dram_size;
58
59         return 0;
60 }
61
62
63 #if !defined(CONFIG_SPD_EEPROM)
64 /*
65  * Fixed sdram init -- doesn't use serial presence detect.
66  */
67 phys_size_t
68 fixed_sdram(void)
69 {
70 #if !defined(CONFIG_SYS_RAMBOOT)
71         volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
72         struct ccsr_ddr __iomem *ddr = &immap->im_ddr1;
73
74         ddr->cs0_bnds = CONFIG_SYS_DDR_CS0_BNDS;
75         ddr->cs0_config = CONFIG_SYS_DDR_CS0_CONFIG;
76         ddr->timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
77         ddr->timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
78         ddr->timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
79         ddr->timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
80         ddr->sdram_mode = CONFIG_SYS_DDR_MODE_1;
81         ddr->sdram_mode_2 = CONFIG_SYS_DDR_MODE_2;
82         ddr->sdram_interval = CONFIG_SYS_DDR_INTERVAL;
83         ddr->sdram_data_init = CONFIG_SYS_DDR_DATA_INIT;
84         ddr->sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CTRL;
85         ddr->sdram_ocd_cntl = CONFIG_SYS_DDR_OCD_CTRL;
86         ddr->sdram_ocd_status = CONFIG_SYS_DDR_OCD_STATUS;
87
88 #if defined (CONFIG_DDR_ECC)
89         ddr->err_disable = 0x0000008D;
90         ddr->err_sbe = 0x00ff0000;
91 #endif
92         asm("sync;isync");
93
94         udelay(500);
95
96 #if defined (CONFIG_DDR_ECC)
97         /* Enable ECC checking */
98         ddr->sdram_cfg = (CONFIG_SYS_DDR_CONTROL | 0x20000000);
99 #else
100         ddr->sdram_cfg = CONFIG_SYS_DDR_CONTROL;
101         ddr->sdram_cfg_2 = CONFIG_SYS_DDR_CONTROL2;
102 #endif
103         asm("sync; isync");
104
105         udelay(500);
106 #endif
107         return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
108 }
109 #endif  /* !defined(CONFIG_SPD_EEPROM) */
110
111 void pci_init_board(void)
112 {
113         fsl_pcie_init_board(0);
114
115 #ifdef CONFIG_PCIE1
116                 /*
117                  * Activate ULI1575 legacy chip by performing a fake
118                  * memory access.  Needed to make ULI RTC work.
119                  */
120                 in_be32((unsigned *) ((char *)(CONFIG_SYS_PCIE1_MEM_VIRT
121                                        + CONFIG_SYS_PCIE1_MEM_SIZE - 0x1000000)));
122 #endif /* CONFIG_PCIE1 */
123 }
124
125
126 #if defined(CONFIG_OF_BOARD_SETUP)
127 int ft_board_setup(void *blob, bd_t *bd)
128 {
129         int off;
130         u64 *tmp;
131         int addrcells;
132
133         ft_cpu_setup(blob, bd);
134
135         FT_FSL_PCI_SETUP;
136
137         /*
138          * Warn if it looks like the device tree doesn't match u-boot.
139          * This is just an estimation, based on the location of CCSR,
140          * which is defined by the "reg" property in the soc node.
141          */
142         off = fdt_path_offset(blob, "/soc8641");
143         addrcells = fdt_address_cells(blob, 0);
144         tmp = (u64 *)fdt_getprop(blob, off, "reg", NULL);
145
146         if (tmp) {
147                 u64 addr;
148
149                 if (addrcells == 1)
150                         addr = *(u32 *)tmp;
151                 else
152                         addr = *tmp;
153
154                 if (addr != CONFIG_SYS_CCSRBAR_PHYS)
155                         printf("WARNING: The CCSRBAR address in your .dts "
156                                "does not match the address of the CCSR "
157                                "in u-boot.  This means your .dts might "
158                                "be old.\n");
159         }
160
161         return 0;
162 }
163 #endif
164
165
166 /*
167  * get_board_sys_clk
168  *      Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
169  */
170
171 unsigned long
172 get_board_sys_clk(ulong dummy)
173 {
174         u8 i, go_bit, rd_clks;
175         ulong val = 0;
176         u8 *pixis_base = (u8 *)PIXIS_BASE;
177
178         go_bit = in_8(pixis_base + PIXIS_VCTL);
179         go_bit &= 0x01;
180
181         rd_clks = in_8(pixis_base + PIXIS_VCFGEN0);
182         rd_clks &= 0x1C;
183
184         /*
185          * Only if both go bit and the SCLK bit in VCFGEN0 are set
186          * should we be using the AUX register. Remember, we also set the
187          * GO bit to boot from the alternate bank on the on-board flash
188          */
189
190         if (go_bit) {
191                 if (rd_clks == 0x1c)
192                         i = in_8(pixis_base + PIXIS_AUX);
193                 else
194                         i = in_8(pixis_base + PIXIS_SPD);
195         } else {
196                 i = in_8(pixis_base + PIXIS_SPD);
197         }
198
199         i &= 0x07;
200
201         switch (i) {
202         case 0:
203                 val = 33000000;
204                 break;
205         case 1:
206                 val = 40000000;
207                 break;
208         case 2:
209                 val = 50000000;
210                 break;
211         case 3:
212                 val = 66000000;
213                 break;
214         case 4:
215                 val = 83000000;
216                 break;
217         case 5:
218                 val = 100000000;
219                 break;
220         case 6:
221                 val = 134000000;
222                 break;
223         case 7:
224                 val = 166000000;
225                 break;
226         }
227
228         return val;
229 }
230
231 int board_eth_init(bd_t *bis)
232 {
233         /* Initialize TSECs */
234         cpu_eth_init(bis);
235         return pci_eth_init(bis);
236 }
237
238 void board_reset(void)
239 {
240         u8 *pixis_base = (u8 *)PIXIS_BASE;
241
242         out_8(pixis_base + PIXIS_RST, 0);
243
244         while (1)
245                 ;
246 }