blob: d9a47b90b2f270c35222afbf7d9498835a44ad87 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kim Phillips5e918a92008-01-16 00:38:05 -06002/*
3 * Copyright (C) 2007 Freescale Semiconductor, Inc.
4 * Kevin Lam <kevin.lam@freescale.com>
5 * Joe D'Abbraccio <joe.d'abbraccio@freescale.com>
Kim Phillips5e918a92008-01-16 00:38:05 -06006 */
7
8#include <common.h>
Anton Vorontsovc9646ed2009-06-10 00:25:30 +04009#include <hwconfig.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060010#include <i2c.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060011#include <asm/io.h>
Kumar Gala7e1afb62010-04-20 10:02:24 -050012#include <asm/fsl_mpc83xx_serdes.h>
Jean-Christophe PLAGNIOL-VILLARD1ac4f322008-04-02 13:41:21 +020013#include <fdt_support.h>
Kim Phillips5e918a92008-01-16 00:38:05 -060014#include <spd_sdram.h>
Timur Tabi89c77842008-02-08 13:15:55 -060015#include <vsc7385.h>
Anton Vorontsovc9646ed2009-06-10 00:25:30 +040016#include <fsl_esdhc.h>
Timur Tabi89c77842008-02-08 13:15:55 -060017
Simon Glass088454c2017-03-31 08:40:25 -060018DECLARE_GLOBAL_DATA_PTR;
19
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020020#if defined(CONFIG_SYS_DRAM_TEST)
Kim Phillips5e918a92008-01-16 00:38:05 -060021int
22testdram(void)
23{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020024 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
25 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Kim Phillips5e918a92008-01-16 00:38:05 -060026 uint *p;
27
28 printf("Testing DRAM from 0x%08x to 0x%08x\n",
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020029 CONFIG_SYS_MEMTEST_START,
30 CONFIG_SYS_MEMTEST_END);
Kim Phillips5e918a92008-01-16 00:38:05 -060031
32 printf("DRAM test phase 1:\n");
33 for (p = pstart; p < pend; p++)
34 *p = 0xaaaaaaaa;
35
36 for (p = pstart; p < pend; p++) {
37 if (*p != 0xaaaaaaaa) {
38 printf("DRAM test fails at: %08x\n", (uint) p);
39 return 1;
40 }
41 }
42
43 printf("DRAM test phase 2:\n");
44 for (p = pstart; p < pend; p++)
45 *p = 0x55555555;
46
47 for (p = pstart; p < pend; p++) {
48 if (*p != 0x55555555) {
49 printf("DRAM test fails at: %08x\n", (uint) p);
50 return 1;
51 }
52 }
53
54 printf("DRAM test passed.\n");
55 return 0;
56}
57#endif
58
Peter Tyser9adda542009-06-30 17:15:50 -050059#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips5e918a92008-01-16 00:38:05 -060060void ddr_enable_ecc(unsigned int dram_size);
61#endif
62int fixed_sdram(void);
63
Simon Glassf1683aa2017-04-06 12:47:05 -060064int dram_init(void)
Kim Phillips5e918a92008-01-16 00:38:05 -060065{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020066 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips5e918a92008-01-16 00:38:05 -060067 u32 msize = 0;
68
69 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass088454c2017-03-31 08:40:25 -060070 return -ENXIO;
Kim Phillips5e918a92008-01-16 00:38:05 -060071
72#if defined(CONFIG_SPD_EEPROM)
73 msize = spd_sdram();
74#else
75 msize = fixed_sdram();
76#endif
77
Peter Tyser9adda542009-06-30 17:15:50 -050078#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips5e918a92008-01-16 00:38:05 -060079 /* Initialize DDR ECC byte */
80 ddr_enable_ecc(msize * 1024 * 1024);
81#endif
82 /* return total bus DDR size(bytes) */
Simon Glass088454c2017-03-31 08:40:25 -060083 gd->ram_size = msize * 1024 * 1024;
84
85 return 0;
Kim Phillips5e918a92008-01-16 00:38:05 -060086}
87
88#if !defined(CONFIG_SPD_EEPROM)
89/*************************************************************************
90 * fixed sdram init -- doesn't use serial presence detect.
91 ************************************************************************/
92int fixed_sdram(void)
93{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020094 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
95 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
Kim Phillips5e918a92008-01-16 00:38:05 -060096 u32 msize_log2 = __ilog2(msize);
97
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_SDRAM_BASE & 0xfffff000;
Kim Phillips5e918a92008-01-16 00:38:05 -060099 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
100
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200101 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
Kim Phillips5e918a92008-01-16 00:38:05 -0600102 udelay(50000);
103
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200104 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Kim Phillips5e918a92008-01-16 00:38:05 -0600105 udelay(1000);
106
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
108 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
Kim Phillips5e918a92008-01-16 00:38:05 -0600109 udelay(1000);
110
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200111 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
112 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
113 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
114 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
115 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
116 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
117 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
118 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
119 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillips5e918a92008-01-16 00:38:05 -0600120 sync();
121 udelay(1000);
122
123 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
124 udelay(2000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125 return CONFIG_SYS_DDR_SIZE;
Kim Phillips5e918a92008-01-16 00:38:05 -0600126}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200127#endif /*!CONFIG_SYS_SPD_EEPROM */
Kim Phillips5e918a92008-01-16 00:38:05 -0600128
129int checkboard(void)
130{
131 puts("Board: Freescale MPC837xERDB\n");
132 return 0;
133}
134
Anton Vorontsov2bd74602008-03-24 17:40:43 +0300135int board_early_init_f(void)
136{
137#ifdef CONFIG_FSL_SERDES
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200138 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov2bd74602008-03-24 17:40:43 +0300139 u32 spridr = in_be32(&immr->sysconf.spridr);
140
141 /* we check only part num, and don't look for CPU revisions */
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500142 switch (PARTID_NO_E(spridr)) {
143 case SPR_8377:
Anton Vorontsov2bd74602008-03-24 17:40:43 +0300144 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
145 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
146 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
147 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
148 break;
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500149 case SPR_8378:
Anton Vorontsov55c53192008-10-02 18:31:53 +0400150 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Kim Phillipse5c4ade2008-03-28 10:19:07 -0500151 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
152 break;
153 case SPR_8379:
154 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
155 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
156 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
157 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
158 break;
Anton Vorontsov2bd74602008-03-24 17:40:43 +0300159 default:
160 printf("serdes not configured: unknown CPU part number: "
161 "%04x\n", spridr >> 16);
162 break;
163 }
164#endif /* CONFIG_FSL_SERDES */
165 return 0;
166}
167
Anton Vorontsovc9646ed2009-06-10 00:25:30 +0400168#ifdef CONFIG_FSL_ESDHC
169int board_mmc_init(bd_t *bd)
170{
171 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
Sinan Akman19e51182015-01-20 20:47:01 -0500172 char buffer[HWCONFIG_BUFFER_SIZE] = {0};
173 int esdhc_hwconfig_enabled = 0;
Anton Vorontsovc9646ed2009-06-10 00:25:30 +0400174
Simon Glass00caae62017-08-03 12:22:12 -0600175 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
Sinan Akman19e51182015-01-20 20:47:01 -0500176 esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
177
178 if (esdhc_hwconfig_enabled == 0)
Anton Vorontsovc9646ed2009-06-10 00:25:30 +0400179 return 0;
180
181 clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
182 clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD);
183
184 return fsl_esdhc_mmc_init(bd);
185}
186#endif
187
Timur Tabi89c77842008-02-08 13:15:55 -0600188/*
189 * Miscellaneous late-boot configurations
190 *
191 * If a VSC7385 microcode image is present, then upload it.
192*/
193int misc_init_r(void)
194{
195 int rc = 0;
196
197#ifdef CONFIG_VSC7385_IMAGE
198 if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
199 CONFIG_VSC7385_IMAGE_SIZE)) {
200 puts("Failure uploading VSC7385 microcode.\n");
201 rc = 1;
202 }
203#endif
204
205 return rc;
206}
207
Kim Phillips5e918a92008-01-16 00:38:05 -0600208#if defined(CONFIG_OF_BOARD_SETUP)
209
Simon Glasse895a4b2014-10-23 18:58:47 -0600210int ft_board_setup(void *blob, bd_t *bd)
Kim Phillips5e918a92008-01-16 00:38:05 -0600211{
212#ifdef CONFIG_PCI
213 ft_pci_setup(blob, bd);
214#endif
215 ft_cpu_setup(blob, bd);
Sriram Dasha5c289b2016-09-16 17:12:15 +0530216 fsl_fdt_fixup_dr_usb(blob, bd);
Anton Vorontsovc9646ed2009-06-10 00:25:30 +0400217 fdt_fixup_esdhc(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600218
219 return 0;
Kim Phillips5e918a92008-01-16 00:38:05 -0600220}
221#endif /* CONFIG_OF_BOARD_SETUP */