blob: 94cb93a42d5d203ea73340ff16b7157a5e1fcdb8 [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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060013#include <asm/bitops.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060014#include <asm/io.h>
Kumar Galab7c3ccf2010-04-20 10:02:24 -050015#include <asm/fsl_mpc83xx_serdes.h>
Jean-Christophe PLAGNIOL-VILLARD5fc8a4b2008-04-02 13:41:21 +020016#include <fdt_support.h>
Kim Phillips1cb07e62008-01-16 00:38:05 -060017#include <spd_sdram.h>
Timur Tabi3e1d49a2008-02-08 13:15:55 -060018#include <vsc7385.h>
Anton Vorontsov3628a932009-06-10 00:25:30 +040019#include <fsl_esdhc.h>
Simon Glassdbd79542020-05-10 11:40:11 -060020#include <linux/delay.h>
Timur Tabi3e1d49a2008-02-08 13:15:55 -060021
Simon Glass39f90ba2017-03-31 08:40:25 -060022DECLARE_GLOBAL_DATA_PTR;
23
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020024#if defined(CONFIG_SYS_DRAM_TEST)
Kim Phillips1cb07e62008-01-16 00:38:05 -060025int
26testdram(void)
27{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020028 uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
29 uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
Kim Phillips1cb07e62008-01-16 00:38:05 -060030 uint *p;
31
32 printf("Testing DRAM from 0x%08x to 0x%08x\n",
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033 CONFIG_SYS_MEMTEST_START,
34 CONFIG_SYS_MEMTEST_END);
Kim Phillips1cb07e62008-01-16 00:38:05 -060035
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
Peter Tysercb4731f2009-06-30 17:15:50 -050063#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips1cb07e62008-01-16 00:38:05 -060064void ddr_enable_ecc(unsigned int dram_size);
65#endif
66int fixed_sdram(void);
67
Simon Glassd35f3382017-04-06 12:47:05 -060068int dram_init(void)
Kim Phillips1cb07e62008-01-16 00:38:05 -060069{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020070 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
Kim Phillips1cb07e62008-01-16 00:38:05 -060071 u32 msize = 0;
72
73 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
Simon Glass39f90ba2017-03-31 08:40:25 -060074 return -ENXIO;
Kim Phillips1cb07e62008-01-16 00:38:05 -060075
76#if defined(CONFIG_SPD_EEPROM)
77 msize = spd_sdram();
78#else
79 msize = fixed_sdram();
80#endif
81
Peter Tysercb4731f2009-06-30 17:15:50 -050082#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Kim Phillips1cb07e62008-01-16 00:38:05 -060083 /* Initialize DDR ECC byte */
84 ddr_enable_ecc(msize * 1024 * 1024);
85#endif
86 /* return total bus DDR size(bytes) */
Simon Glass39f90ba2017-03-31 08:40:25 -060087 gd->ram_size = msize * 1024 * 1024;
88
89 return 0;
Kim Phillips1cb07e62008-01-16 00:38:05 -060090}
91
92#if !defined(CONFIG_SPD_EEPROM)
93/*************************************************************************
94 * fixed sdram init -- doesn't use serial presence detect.
95 ************************************************************************/
96int fixed_sdram(void)
97{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
99 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600100 u32 msize_log2 = __ilog2(msize);
101
Mario Six805cac12019-01-21 09:18:16 +0100102 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600103 im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
104
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105 im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600106 udelay(50000);
107
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600109 udelay(1000);
110
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200111 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
112 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600113 udelay(1000);
114
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200115 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;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600124 sync();
125 udelay(1000);
126
127 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
128 udelay(2000);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200129 return CONFIG_SYS_DDR_SIZE;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600130}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200131#endif /*!CONFIG_SYS_SPD_EEPROM */
Kim Phillips1cb07e62008-01-16 00:38:05 -0600132
133int checkboard(void)
134{
135 puts("Board: Freescale MPC837xERDB\n");
136 return 0;
137}
138
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300139int board_early_init_f(void)
140{
141#ifdef CONFIG_FSL_SERDES
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300143 u32 spridr = in_be32(&immr->sysconf.spridr);
144
145 /* we check only part num, and don't look for CPU revisions */
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500146 switch (PARTID_NO_E(spridr)) {
147 case SPR_8377:
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300148 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
149 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500150 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300151 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
152 break;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500153 case SPR_8378:
Anton Vorontsov642016b2008-10-02 18:31:53 +0400154 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300155 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
156 break;
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500157 case SPR_8379:
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300158 fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
159 FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
Kim Phillipsecb2d6f2008-03-28 10:19:07 -0500160 fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
Anton Vorontsov2b3c0042008-03-24 17:40:43 +0300161 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
Anton Vorontsov3628a932009-06-10 00:25:30 +0400172#ifdef CONFIG_FSL_ESDHC
173int board_mmc_init(bd_t *bd)
174{
175 struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
Sinan Akman8dc24e02015-01-20 20:47:01 -0500176 char buffer[HWCONFIG_BUFFER_SIZE] = {0};
177 int esdhc_hwconfig_enabled = 0;
178
Simon Glass64b723f2017-08-03 12:22:12 -0600179 if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
Sinan Akman8dc24e02015-01-20 20:47:01 -0500180 esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
Anton Vorontsov3628a932009-06-10 00:25:30 +0400181
Sinan Akman8dc24e02015-01-20 20:47:01 -0500182 if (esdhc_hwconfig_enabled == 0)
Anton Vorontsov3628a932009-06-10 00:25:30 +0400183 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
Timur Tabi3e1d49a2008-02-08 13:15:55 -0600192/*
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
Kim Phillips1cb07e62008-01-16 00:38:05 -0600212#if defined(CONFIG_OF_BOARD_SETUP)
213
Simon Glass2aec3cc2014-10-23 18:58:47 -0600214int ft_board_setup(void *blob, bd_t *bd)
Kim Phillips1cb07e62008-01-16 00:38:05 -0600215{
216#ifdef CONFIG_PCI
217 ft_pci_setup(blob, bd);
218#endif
219 ft_cpu_setup(blob, bd);
Sriram Dash9fd465c2016-09-16 17:12:15 +0530220 fsl_fdt_fixup_dr_usb(blob, bd);
Anton Vorontsov3628a932009-06-10 00:25:30 +0400221 fdt_fixup_esdhc(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600222
223 return 0;
Kim Phillips1cb07e62008-01-16 00:38:05 -0600224}
225#endif /* CONFIG_OF_BOARD_SETUP */