blob: 3fd2c5e84943e96a11881debe40161df66017cee [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kim Phillips1cb07e62008-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 Phillips1cb07e62008-01-16 00:38:05 -06006 */
7
8#include <common.h>
Simon Glassdb229612019-08-01 09:46:42 -06009#include <env.h>
Anton Vorontsov3628a932009-06-10 00:25:30 +040010#include <hwconfig.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060011#include <i2c.h>
Simon Glass0ffd9db2019-12-28 10:45:06 -070012#include <init.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060013#include <asm/io.h>
Kumar Galab7c3ccf2010-04-20 10:02:24 -050014#include <asm/fsl_mpc83xx_serdes.h>
Jean-Christophe PLAGNIOL-VILLARD5fc8a4b2008-04-02 13:41:21 +020015#include <fdt_support.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060016#include <spd_sdram.h>
Timur Tabi3e1d49a2008-02-08 13:15:55 -060017#include <vsc7385.h>
Anton Vorontsov3628a932009-06-10 00:25:30 +040018#include <fsl_esdhc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060019#include <linux/delay.h>
Timur Tabi3e1d49a2008-02-08 13:15:55 -060020
Simon Glass39f90ba2017-03-31 08:40:25 -060021DECLARE_GLOBAL_DATA_PTR;
22
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020023#if defined(CONFIG_SYS_DRAM_TEST)
Kim Phillips1cb07e62008-01-16 00:38:05 -060024int
25testdram(void)
26{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020027 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
28 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Kim Phillips1cb07e62008-01-16 00:38:05 -060029 uint *p;
30
31 printf("Testing DRAM from 0x%08x to 0x%08x\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020032 CONFIG_SYS_MEMTEST_START,
33 CONFIG_SYS_MEMTEST_END);
Kim Phillips1cb07e62008-01-16 00:38:05 -060034
35 printf("DRAM test phase 1:\n");
36 for (p = pstart; p < pend; p++)
37 *p = 0xaaaaaaaa;
38
39 for (p = pstart; p < pend; p++) {
40 if (*p != 0xaaaaaaaa) {
41 printf("DRAM test fails at: %08x\n", (uint) p);
42 return 1;
43 }
44 }
45
46 printf("DRAM test phase 2:\n");
47 for (p = pstart; p < pend; p++)
48 *p = 0x55555555;
49
50 for (p = pstart; p < pend; p++) {
51 if (*p != 0x55555555) {
52 printf("DRAM test fails at: %08x\n", (uint) p);
53 return 1;
54 }
55 }
56
57 printf("DRAM test passed.\n");
58 return 0;
59}
60#endif
61
Peter Tysercb4731f2009-06-30 17:15:50 -050062#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips1cb07e62008-01-16 00:38:05 -060063void ddr_enable_ecc(unsigned int dram_size);
64#endif
65int fixed_sdram(void);
66
Simon Glassd35f3382017-04-06 12:47:05 -060067int dram_init(void)
Kim Phillips1cb07e62008-01-16 00:38:05 -060068{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020069 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1cb07e62008-01-16 00:38:05 -060070 u32 msize = 0;
71
72 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass39f90ba2017-03-31 08:40:25 -060073 return -ENXIO;
Kim Phillips1cb07e62008-01-16 00:38:05 -060074
75#if defined(CONFIG_SPD_EEPROM)
76 msize = spd_sdram();
77#else
78 msize = fixed_sdram();
79#endif
80
Peter Tysercb4731f2009-06-30 17:15:50 -050081#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips1cb07e62008-01-16 00:38:05 -060082 /* Initialize DDR ECC byte */
83 ddr_enable_ecc(msize * 1024 * 1024);
84#endif
85 /* return total bus DDR size(bytes) */
Simon Glass39f90ba2017-03-31 08:40:25 -060086 gd->ram_size = msize * 1024 * 1024;
87
88 return 0;
Kim Phillips1cb07e62008-01-16 00:38:05 -060089}
90
91#if !defined(CONFIG_SPD_EEPROM)
92/*************************************************************************
93 * fixed sdram init -- doesn't use serial presence detect.
94 ************************************************************************/
95int fixed_sdram(void)
96{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
98 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
Kim Phillips1cb07e62008-01-16 00:38:05 -060099 u32 msize_log2 = __ilog2(msize);
100
Mario Six805cac12019-01-21 09:18:16 +0100101 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600102 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
103
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600105 udelay(50000);
106
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200107 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600108 udelay(1000);
109
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
111 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600112 udelay(1000);
113
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
115 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
116 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
117 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
118 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
119 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
120 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
121 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
122 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600123 sync();
124 udelay(1000);
125
126 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
127 udelay(2000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200128 return CONFIG_SYS_DDR_SIZE;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600129}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200130#endif /*!CONFIG_SYS_SPD_EEPROM */
Kim Phillips1cb07e62008-01-16 00:38:05 -0600131
132int checkboard(void)
133{
134 puts("Board: Freescale MPC837xERDB\n");
135 return 0;
136}
137
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300138int board_early_init_f(void)
139{
140#ifdef CONFIG_FSL_SERDES
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200141 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300142 u32 spridr = in_be32(&immr->sysconf.spridr);
143
144 /* we check only part num, and don't look for CPU revisions */
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500145 switch (PARTID_NO_E(spridr)) {
146 case SPR_8377:
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300147 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
148 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500149 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300150 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
151 break;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500152 case SPR_8378:
Anton Vorontsov642016b2008-10-02 18:31:53 +0400153 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300154 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
155 break;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500156 case SPR_8379:
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300157 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
158 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500159 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300160 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
161 break;
162 default:
163 printf("serdes not configured: unknown CPU part number: "
164 "%04x\n", spridr >> 16);
165 break;
166 }
167#endif /* CONFIG_FSL_SERDES */
168 return 0;
169}
170
Anton Vorontsov3628a932009-06-10 00:25:30 +0400171#ifdef CONFIG_FSL_ESDHC
172int board_mmc_init(bd_t *bd)
173{
174 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
Sinan Akman8dc24e02015-01-20 20:47:01 -0500175 char buffer[HWCONFIG_BUFFER_SIZE] = {0};
176 int esdhc_hwconfig_enabled = 0;
177
Simon Glass64b723f2017-08-03 12:22:12 -0600178 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
Sinan Akman8dc24e02015-01-20 20:47:01 -0500179 esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
Anton Vorontsov3628a932009-06-10 00:25:30 +0400180
Sinan Akman8dc24e02015-01-20 20:47:01 -0500181 if (esdhc_hwconfig_enabled == 0)
Anton Vorontsov3628a932009-06-10 00:25:30 +0400182 return 0;
183
184 clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
185 clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD);
186
187 return fsl_esdhc_mmc_init(bd);
188}
189#endif
190
Timur Tabi3e1d49a2008-02-08 13:15:55 -0600191/*
192 * Miscellaneous late-boot configurations
193 *
194 * If a VSC7385 microcode image is present, then upload it.
195*/
196int misc_init_r(void)
197{
198 int rc = 0;
199
200#ifdef CONFIG_VSC7385_IMAGE
201 if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
202 CONFIG_VSC7385_IMAGE_SIZE)) {
203 puts("Failure uploading VSC7385 microcode.\n");
204 rc = 1;
205 }
206#endif
207
208 return rc;
209}
210
Kim Phillips1cb07e62008-01-16 00:38:05 -0600211#if defined(CONFIG_OF_BOARD_SETUP)
212
Simon Glass2aec3cc2014-10-23 18:58:47 -0600213int ft_board_setup(void *blob, bd_t *bd)
Kim Phillips1cb07e62008-01-16 00:38:05 -0600214{
215#ifdef CONFIG_PCI
216 ft_pci_setup(blob, bd);
217#endif
218 ft_cpu_setup(blob, bd);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530219 fsl_fdt_fixup_dr_usb(blob, bd);
Anton Vorontsov3628a932009-06-10 00:25:30 +0400220 fdt_fixup_esdhc(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600221
222 return 0;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600223}
224#endif /* CONFIG_OF_BOARD_SETUP */