]> Git Repo - J-u-boot.git/blame - board/freescale/mpc837xerdb/mpc837xerdb.c
treewide: convert bd_t to struct bd_info by coccinelle
[J-u-boot.git] / board / freescale / mpc837xerdb / mpc837xerdb.c
CommitLineData
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>
5e918a98 14#include <asm/io.h>
7e1afb62 15#include <asm/fsl_mpc83xx_serdes.h>
1ac4f320 16#include <fdt_support.h>
5e918a98 17#include <spd_sdram.h>
89c7784e 18#include <vsc7385.h>
c9646ed7 19#include <fsl_esdhc.h>
c05ed00a 20#include <linux/delay.h>
89c7784e 21
088454cd
SG
22DECLARE_GLOBAL_DATA_PTR;
23
6d0f6bcf 24#if defined(CONFIG_SYS_DRAM_TEST)
5e918a98
KP
25int
26testdram(void)
27{
6d0f6bcf
JCPV
28 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
29 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
5e918a98
KP
30 uint *p;
31
32 printf("Testing DRAM from 0x%08x to 0x%08x\n",
6d0f6bcf
JCPV
33 CONFIG_SYS_MEMTEST_START,
34 CONFIG_SYS_MEMTEST_END);
5e918a98
KP
35
36 printf("DRAM test phase 1:\n");
37 for (p = pstart; p < pend; p++)
38 *p = 0xaaaaaaaa;
39
40 for (p = pstart; p < pend; p++) {
41 if (*p != 0xaaaaaaaa) {
42 printf("DRAM test fails at: %08x\n", (uint) p);
43 return 1;
44 }
45 }
46
47 printf("DRAM test phase 2:\n");
48 for (p = pstart; p < pend; p++)
49 *p = 0x55555555;
50
51 for (p = pstart; p < pend; p++) {
52 if (*p != 0x55555555) {
53 printf("DRAM test fails at: %08x\n", (uint) p);
54 return 1;
55 }
56 }
57
58 printf("DRAM test passed.\n");
59 return 0;
60}
61#endif
62
9adda545 63#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
5e918a98
KP
64void ddr_enable_ecc(unsigned int dram_size);
65#endif
66int fixed_sdram(void);
67
f1683aa7 68int dram_init(void)
5e918a98 69{
6d0f6bcf 70 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
5e918a98
KP
71 u32 msize = 0;
72
73 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
088454cd 74 return -ENXIO;
5e918a98
KP
75
76#if defined(CONFIG_SPD_EEPROM)
77 msize = spd_sdram();
78#else
79 msize = fixed_sdram();
80#endif
81
9adda545 82#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
5e918a98
KP
83 /* Initialize DDR ECC byte */
84 ddr_enable_ecc(msize * 1024 * 1024);
85#endif
86 /* return total bus DDR size(bytes) */
088454cd
SG
87 gd->ram_size = msize * 1024 * 1024;
88
89 return 0;
5e918a98
KP
90}
91
92#if !defined(CONFIG_SPD_EEPROM)
93/*************************************************************************
94 * fixed sdram init -- doesn't use serial presence detect.
95 ************************************************************************/
96int fixed_sdram(void)
97{
6d0f6bcf
JCPV
98 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
99 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
5e918a98
KP
100 u32 msize_log2 = __ilog2(msize);
101
133ec602 102 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
5e918a98
KP
103 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
104
6d0f6bcf 105 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
5e918a98
KP
106 udelay(50000);
107
6d0f6bcf 108 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
5e918a98
KP
109 udelay(1000);
110
6d0f6bcf
JCPV
111 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
112 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
5e918a98
KP
113 udelay(1000);
114
6d0f6bcf
JCPV
115 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
116 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
117 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
118 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
119 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
120 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
121 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
122 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
123 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
5e918a98
KP
124 sync();
125 udelay(1000);
126
127 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
128 udelay(2000);
6d0f6bcf 129 return CONFIG_SYS_DDR_SIZE;
5e918a98 130}
6d0f6bcf 131#endif /*!CONFIG_SYS_SPD_EEPROM */
5e918a98
KP
132
133int checkboard(void)
134{
135 puts("Board: Freescale MPC837xERDB\n");
136 return 0;
137}
138
2bd7460e
AV
139int board_early_init_f(void)
140{
141#ifdef CONFIG_FSL_SERDES
6d0f6bcf 142 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
2bd7460e
AV
143 u32 spridr = in_be32(&immr->sysconf.spridr);
144
145 /* we check only part num, and don't look for CPU revisions */
e5c4ade4
KP
146 switch (PARTID_NO_E(spridr)) {
147 case SPR_8377:
2bd7460e
AV
148 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
149 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
e5c4ade4 150 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
2bd7460e
AV
151 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
152 break;
e5c4ade4 153 case SPR_8378:
55c53198 154 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
2bd7460e
AV
155 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
156 break;
e5c4ade4 157 case SPR_8379:
2bd7460e
AV
158 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
159 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
e5c4ade4 160 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
2bd7460e
AV
161 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
162 break;
163 default:
164 printf("serdes not configured: unknown CPU part number: "
165 "%04x\n", spridr >> 16);
166 break;
167 }
168#endif /* CONFIG_FSL_SERDES */
169 return 0;
170}
171
c9646ed7 172#ifdef CONFIG_FSL_ESDHC
b75d8dc5 173int board_mmc_init(struct bd_info *bd)
c9646ed7
AV
174{
175 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
19e5118d
SA
176 char buffer[HWCONFIG_BUFFER_SIZE] = {0};
177 int esdhc_hwconfig_enabled = 0;
c9646ed7 178
00caae6d 179 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
19e5118d
SA
180 esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
181
182 if (esdhc_hwconfig_enabled == 0)
c9646ed7
AV
183 return 0;
184
185 clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
186 clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD);
187
188 return fsl_esdhc_mmc_init(bd);
189}
190#endif
191
89c7784e
TT
192/*
193 * Miscellaneous late-boot configurations
194 *
195 * If a VSC7385 microcode image is present, then upload it.
196*/
197int misc_init_r(void)
198{
199 int rc = 0;
200
201#ifdef CONFIG_VSC7385_IMAGE
202 if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
203 CONFIG_VSC7385_IMAGE_SIZE)) {
204 puts("Failure uploading VSC7385 microcode.\n");
205 rc = 1;
206 }
207#endif
208
209 return rc;
210}
211
5e918a98
KP
212#if defined(CONFIG_OF_BOARD_SETUP)
213
b75d8dc5 214int ft_board_setup(void *blob, struct bd_info *bd)
5e918a98
KP
215{
216#ifdef CONFIG_PCI
217 ft_pci_setup(blob, bd);
218#endif
219 ft_cpu_setup(blob, bd);
a5c289b9 220 fsl_fdt_fixup_dr_usb(blob, bd);
c9646ed7 221 fdt_fixup_esdhc(blob, bd);
e895a4b0
SG
222
223 return 0;
5e918a98
KP
224}
225#endif /* CONFIG_OF_BOARD_SETUP */
This page took 0.572597 seconds and 4 git commands to generate.