]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
5e918a98 KP |
2 | /* |
3 | * Copyright (C) 2007 Freescale Semiconductor, Inc. | |
4 | * Kevin Lam <[email protected]> | |
5 | * Joe D'Abbraccio <joe.d'[email protected]> | |
5e918a98 KP |
6 | */ |
7 | ||
8 | #include <common.h> | |
3a7d5571 | 9 | #include <env.h> |
c9646ed7 | 10 | #include <hwconfig.h> |
5e918a98 | 11 | #include <i2c.h> |
49acd56e | 12 | #include <init.h> |
cd93d625 | 13 | #include <asm/bitops.h> |
401d1c4f | 14 | #include <asm/global_data.h> |
5e918a98 | 15 | #include <asm/io.h> |
7e1afb62 | 16 | #include <asm/fsl_mpc83xx_serdes.h> |
1ac4f320 | 17 | #include <fdt_support.h> |
5e918a98 | 18 | #include <spd_sdram.h> |
89c7784e | 19 | #include <vsc7385.h> |
c9646ed7 | 20 | #include <fsl_esdhc.h> |
c05ed00a | 21 | #include <linux/delay.h> |
89c7784e | 22 | |
088454cd SG |
23 | DECLARE_GLOBAL_DATA_PTR; |
24 | ||
65cc0e2a | 25 | #if defined(CFG_SYS_DRAM_TEST) |
5e918a98 KP |
26 | int |
27 | testdram(void) | |
28 | { | |
6d0f6bcf JCPV |
29 | uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START; |
30 | uint *pend = (uint *) CONFIG_SYS_MEMTEST_END; | |
5e918a98 KP |
31 | uint *p; |
32 | ||
33 | printf("Testing DRAM from 0x%08x to 0x%08x\n", | |
6d0f6bcf JCPV |
34 | CONFIG_SYS_MEMTEST_START, |
35 | CONFIG_SYS_MEMTEST_END); | |
5e918a98 KP |
36 | |
37 | printf("DRAM test phase 1:\n"); | |
38 | for (p = pstart; p < pend; p++) | |
39 | *p = 0xaaaaaaaa; | |
40 | ||
41 | for (p = pstart; p < pend; p++) { | |
42 | if (*p != 0xaaaaaaaa) { | |
43 | printf("DRAM test fails at: %08x\n", (uint) p); | |
44 | return 1; | |
45 | } | |
46 | } | |
47 | ||
48 | printf("DRAM test phase 2:\n"); | |
49 | for (p = pstart; p < pend; p++) | |
50 | *p = 0x55555555; | |
51 | ||
52 | for (p = pstart; p < pend; p++) { | |
53 | if (*p != 0x55555555) { | |
54 | printf("DRAM test fails at: %08x\n", (uint) p); | |
55 | return 1; | |
56 | } | |
57 | } | |
58 | ||
59 | printf("DRAM test passed.\n"); | |
60 | return 0; | |
61 | } | |
62 | #endif | |
63 | ||
9adda545 | 64 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
5e918a98 KP |
65 | void ddr_enable_ecc(unsigned int dram_size); |
66 | #endif | |
67 | int fixed_sdram(void); | |
68 | ||
f1683aa7 | 69 | int dram_init(void) |
5e918a98 | 70 | { |
6d0f6bcf | 71 | immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
5e918a98 KP |
72 | u32 msize = 0; |
73 | ||
74 | if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im) | |
088454cd | 75 | return -ENXIO; |
5e918a98 KP |
76 | |
77 | #if defined(CONFIG_SPD_EEPROM) | |
78 | msize = spd_sdram(); | |
79 | #else | |
80 | msize = fixed_sdram(); | |
81 | #endif | |
82 | ||
9adda545 | 83 | #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER) |
5e918a98 KP |
84 | /* Initialize DDR ECC byte */ |
85 | ddr_enable_ecc(msize * 1024 * 1024); | |
86 | #endif | |
87 | /* return total bus DDR size(bytes) */ | |
088454cd SG |
88 | gd->ram_size = msize * 1024 * 1024; |
89 | ||
90 | return 0; | |
5e918a98 KP |
91 | } |
92 | ||
93 | #if !defined(CONFIG_SPD_EEPROM) | |
94 | /************************************************************************* | |
95 | * fixed sdram init -- doesn't use serial presence detect. | |
96 | ************************************************************************/ | |
97 | int fixed_sdram(void) | |
98 | { | |
6d0f6bcf | 99 | immap_t *im = (immap_t *) CONFIG_SYS_IMMR; |
aa6e94de | 100 | u32 msize = CFG_SYS_SDRAM_SIZE; |
5e918a98 KP |
101 | u32 msize_log2 = __ilog2(msize); |
102 | ||
aa6e94de | 103 | im->sysconf.ddrlaw[0].bar = CFG_SYS_SDRAM_BASE & 0xfffff000; |
5e918a98 KP |
104 | im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1); |
105 | ||
65cc0e2a | 106 | im->sysconf.ddrcdr = CFG_SYS_DDRCDR_VALUE; |
5e918a98 KP |
107 | udelay(50000); |
108 | ||
65cc0e2a | 109 | im->ddr.sdram_clk_cntl = CFG_SYS_DDR_SDRAM_CLK_CNTL; |
5e918a98 KP |
110 | udelay(1000); |
111 | ||
65cc0e2a TR |
112 | im->ddr.csbnds[0].csbnds = CFG_SYS_DDR_CS0_BNDS; |
113 | im->ddr.cs_config[0] = CFG_SYS_DDR_CS0_CONFIG; | |
5e918a98 KP |
114 | udelay(1000); |
115 | ||
65cc0e2a TR |
116 | im->ddr.timing_cfg_0 = CFG_SYS_DDR_TIMING_0; |
117 | im->ddr.timing_cfg_1 = CFG_SYS_DDR_TIMING_1; | |
118 | im->ddr.timing_cfg_2 = CFG_SYS_DDR_TIMING_2; | |
119 | im->ddr.timing_cfg_3 = CFG_SYS_DDR_TIMING_3; | |
120 | im->ddr.sdram_cfg = CFG_SYS_DDR_SDRAM_CFG; | |
121 | im->ddr.sdram_cfg2 = CFG_SYS_DDR_SDRAM_CFG2; | |
122 | im->ddr.sdram_mode = CFG_SYS_DDR_MODE; | |
123 | im->ddr.sdram_mode2 = CFG_SYS_DDR_MODE2; | |
124 | im->ddr.sdram_interval = CFG_SYS_DDR_INTERVAL; | |
5e918a98 KP |
125 | sync(); |
126 | udelay(1000); | |
127 | ||
128 | im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN; | |
129 | udelay(2000); | |
aa6e94de | 130 | return CFG_SYS_SDRAM_SIZE >> 20; |
5e918a98 | 131 | } |
6d0f6bcf | 132 | #endif /*!CONFIG_SYS_SPD_EEPROM */ |
5e918a98 KP |
133 | |
134 | int checkboard(void) | |
135 | { | |
136 | puts("Board: Freescale MPC837xERDB\n"); | |
137 | return 0; | |
138 | } | |
139 | ||
2bd7460e AV |
140 | int board_early_init_f(void) |
141 | { | |
6d0f6bcf | 142 | immap_t *immr = (immap_t *)CONFIG_SYS_IMMR; |
a2c48cb7 | 143 | #ifdef CONFIG_FSL_SERDES |
2bd7460e AV |
144 | u32 spridr = in_be32(&immr->sysconf.spridr); |
145 | ||
146 | /* we check only part num, and don't look for CPU revisions */ | |
e5c4ade4 KP |
147 | switch (PARTID_NO_E(spridr)) { |
148 | case SPR_8377: | |
da495570 | 149 | fsl_setup_serdes(CFG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
2bd7460e | 150 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
315390e4 | 151 | fsl_setup_serdes(CFG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
2bd7460e AV |
152 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
153 | break; | |
e5c4ade4 | 154 | case SPR_8378: |
315390e4 | 155 | fsl_setup_serdes(CFG_FSL_SERDES2, FSL_SERDES_PROTO_PEX, |
2bd7460e AV |
156 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
157 | break; | |
e5c4ade4 | 158 | case SPR_8379: |
da495570 | 159 | fsl_setup_serdes(CFG_FSL_SERDES1, FSL_SERDES_PROTO_SATA, |
2bd7460e | 160 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
315390e4 | 161 | fsl_setup_serdes(CFG_FSL_SERDES2, FSL_SERDES_PROTO_SATA, |
2bd7460e AV |
162 | FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V); |
163 | break; | |
164 | default: | |
165 | printf("serdes not configured: unknown CPU part number: " | |
166 | "%04x\n", spridr >> 16); | |
167 | break; | |
168 | } | |
169 | #endif /* CONFIG_FSL_SERDES */ | |
a2c48cb7 SA |
170 | |
171 | #ifdef CONFIG_FSL_ESDHC | |
172 | clrsetbits_be32(&immr->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD); | |
173 | clrsetbits_be32(&immr->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD); | |
174 | #endif | |
2bd7460e AV |
175 | return 0; |
176 | } | |
177 | ||
c9646ed7 | 178 | #ifdef CONFIG_FSL_ESDHC |
c8be85f3 | 179 | #if !(CONFIG_IS_ENABLED(DM_MMC) || CONFIG_IS_ENABLED(DM_USB)) |
b75d8dc5 | 180 | int board_mmc_init(struct bd_info *bd) |
c9646ed7 AV |
181 | { |
182 | struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR; | |
19e5118d SA |
183 | char buffer[HWCONFIG_BUFFER_SIZE] = {0}; |
184 | int esdhc_hwconfig_enabled = 0; | |
c9646ed7 | 185 | |
00caae6d | 186 | if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0) |
19e5118d SA |
187 | esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer); |
188 | ||
189 | if (esdhc_hwconfig_enabled == 0) | |
c9646ed7 AV |
190 | return 0; |
191 | ||
192 | clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD); | |
193 | clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD); | |
194 | ||
195 | return fsl_esdhc_mmc_init(bd); | |
196 | } | |
197 | #endif | |
a2c48cb7 | 198 | #endif |
c9646ed7 | 199 | |
89c7784e TT |
200 | /* |
201 | * Miscellaneous late-boot configurations | |
202 | * | |
203 | * If a VSC7385 microcode image is present, then upload it. | |
204 | */ | |
205 | int misc_init_r(void) | |
206 | { | |
207 | int rc = 0; | |
208 | ||
209 | #ifdef CONFIG_VSC7385_IMAGE | |
210 | if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE, | |
211 | CONFIG_VSC7385_IMAGE_SIZE)) { | |
212 | puts("Failure uploading VSC7385 microcode.\n"); | |
213 | rc = 1; | |
214 | } | |
215 | #endif | |
216 | ||
217 | return rc; | |
218 | } | |
219 | ||
c8be85f3 SA |
220 | int board_late_init(void) |
221 | { | |
222 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; | |
e8d3eaad | 223 | #ifdef CONFIG_USB_HOST |
c8be85f3 SA |
224 | clrsetbits_be32(&immap->sysconf.sicrl, SICRL_USB_A, 0x40000000); |
225 | #endif | |
226 | return 0; | |
227 | } | |
228 | ||
5e918a98 KP |
229 | #if defined(CONFIG_OF_BOARD_SETUP) |
230 | ||
b75d8dc5 | 231 | int ft_board_setup(void *blob, struct bd_info *bd) |
5e918a98 KP |
232 | { |
233 | #ifdef CONFIG_PCI | |
234 | ft_pci_setup(blob, bd); | |
235 | #endif | |
236 | ft_cpu_setup(blob, bd); | |
a5c289b9 | 237 | fsl_fdt_fixup_dr_usb(blob, bd); |
c9646ed7 | 238 | fdt_fixup_esdhc(blob, bd); |
e895a4b0 SG |
239 | |
240 | return 0; | |
5e918a98 KP |
241 | } |
242 | #endif /* CONFIG_OF_BOARD_SETUP */ |