2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-01-16 06:38:05 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Freescale Semiconductor, Inc.
|
|
|
|
* Kevin Lam <kevin.lam@freescale.com>
|
|
|
|
* Joe D'Abbraccio <joe.d'abbraccio@freescale.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-08-01 15:46:42 +00:00
|
|
|
#include <env.h>
|
2009-06-09 20:25:30 +00:00
|
|
|
#include <hwconfig.h>
|
2008-01-16 06:38:05 +00:00
|
|
|
#include <i2c.h>
|
2019-12-28 17:45:06 +00:00
|
|
|
#include <init.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <asm/bitops.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2008-01-16 06:38:05 +00:00
|
|
|
#include <asm/io.h>
|
2010-04-20 15:02:24 +00:00
|
|
|
#include <asm/fsl_mpc83xx_serdes.h>
|
2008-04-02 11:41:21 +00:00
|
|
|
#include <fdt_support.h>
|
2008-01-16 06:38:05 +00:00
|
|
|
#include <spd_sdram.h>
|
2008-02-08 19:15:55 +00:00
|
|
|
#include <vsc7385.h>
|
2009-06-09 20:25:30 +00:00
|
|
|
#include <fsl_esdhc.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2008-02-08 19:15:55 +00:00
|
|
|
|
2017-03-31 14:40:25 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_DRAM_TEST)
|
2008-01-16 06:38:05 +00:00
|
|
|
int
|
|
|
|
testdram(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
uint *pstart = (uint *) CONFIG_SYS_MEMTEST_START;
|
|
|
|
uint *pend = (uint *) CONFIG_SYS_MEMTEST_END;
|
2008-01-16 06:38:05 +00:00
|
|
|
uint *p;
|
|
|
|
|
|
|
|
printf("Testing DRAM from 0x%08x to 0x%08x\n",
|
2008-10-16 13:01:15 +00:00
|
|
|
CONFIG_SYS_MEMTEST_START,
|
|
|
|
CONFIG_SYS_MEMTEST_END);
|
2008-01-16 06:38:05 +00:00
|
|
|
|
|
|
|
printf("DRAM test phase 1:\n");
|
|
|
|
for (p = pstart; p < pend; p++)
|
|
|
|
*p = 0xaaaaaaaa;
|
|
|
|
|
|
|
|
for (p = pstart; p < pend; p++) {
|
|
|
|
if (*p != 0xaaaaaaaa) {
|
|
|
|
printf("DRAM test fails at: %08x\n", (uint) p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("DRAM test phase 2:\n");
|
|
|
|
for (p = pstart; p < pend; p++)
|
|
|
|
*p = 0x55555555;
|
|
|
|
|
|
|
|
for (p = pstart; p < pend; p++) {
|
|
|
|
if (*p != 0x55555555) {
|
|
|
|
printf("DRAM test fails at: %08x\n", (uint) p);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("DRAM test passed.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 22:15:50 +00:00
|
|
|
#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
|
2008-01-16 06:38:05 +00:00
|
|
|
void ddr_enable_ecc(unsigned int dram_size);
|
|
|
|
#endif
|
|
|
|
int fixed_sdram(void);
|
|
|
|
|
2017-04-06 18:47:05 +00:00
|
|
|
int dram_init(void)
|
2008-01-16 06:38:05 +00:00
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
2008-01-16 06:38:05 +00:00
|
|
|
u32 msize = 0;
|
|
|
|
|
|
|
|
if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32) im)
|
2017-03-31 14:40:25 +00:00
|
|
|
return -ENXIO;
|
2008-01-16 06:38:05 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_SPD_EEPROM)
|
|
|
|
msize = spd_sdram();
|
|
|
|
#else
|
|
|
|
msize = fixed_sdram();
|
|
|
|
#endif
|
|
|
|
|
2009-06-30 22:15:50 +00:00
|
|
|
#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
|
2008-01-16 06:38:05 +00:00
|
|
|
/* Initialize DDR ECC byte */
|
|
|
|
ddr_enable_ecc(msize * 1024 * 1024);
|
|
|
|
#endif
|
|
|
|
/* return total bus DDR size(bytes) */
|
2017-03-31 14:40:25 +00:00
|
|
|
gd->ram_size = msize * 1024 * 1024;
|
|
|
|
|
|
|
|
return 0;
|
2008-01-16 06:38:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(CONFIG_SPD_EEPROM)
|
|
|
|
/*************************************************************************
|
|
|
|
* fixed sdram init -- doesn't use serial presence detect.
|
|
|
|
************************************************************************/
|
|
|
|
int fixed_sdram(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
|
|
|
|
u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
|
2008-01-16 06:38:05 +00:00
|
|
|
u32 msize_log2 = __ilog2(msize);
|
|
|
|
|
2019-01-21 08:18:16 +00:00
|
|
|
im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
|
2008-01-16 06:38:05 +00:00
|
|
|
im->sysconf.ddrlaw[0].ar = LBLAWAR_EN | (msize_log2 - 1);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->sysconf.ddrcdr = CONFIG_SYS_DDRCDR_VALUE;
|
2008-01-16 06:38:05 +00:00
|
|
|
udelay(50000);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_SDRAM_CLK_CNTL;
|
2008-01-16 06:38:05 +00:00
|
|
|
udelay(1000);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
|
|
|
|
im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
|
2008-01-16 06:38:05 +00:00
|
|
|
udelay(1000);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
|
|
|
|
im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
|
|
|
|
im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
|
|
|
|
im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
|
|
|
|
im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
|
|
|
|
im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
|
|
|
|
im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
|
|
|
|
im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
|
|
|
|
im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
|
2008-01-16 06:38:05 +00:00
|
|
|
sync();
|
|
|
|
udelay(1000);
|
|
|
|
|
|
|
|
im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
|
|
|
|
udelay(2000);
|
2008-10-16 13:01:15 +00:00
|
|
|
return CONFIG_SYS_DDR_SIZE;
|
2008-01-16 06:38:05 +00:00
|
|
|
}
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif /*!CONFIG_SYS_SPD_EEPROM */
|
2008-01-16 06:38:05 +00:00
|
|
|
|
|
|
|
int checkboard(void)
|
|
|
|
{
|
|
|
|
puts("Board: Freescale MPC837xERDB\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-03-24 14:40:43 +00:00
|
|
|
int board_early_init_f(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
|
2020-04-04 05:16:47 +00:00
|
|
|
#ifdef CONFIG_FSL_SERDES
|
2008-03-24 14:40:43 +00:00
|
|
|
u32 spridr = in_be32(&immr->sysconf.spridr);
|
|
|
|
|
|
|
|
/* we check only part num, and don't look for CPU revisions */
|
2008-03-28 15:19:07 +00:00
|
|
|
switch (PARTID_NO_E(spridr)) {
|
|
|
|
case SPR_8377:
|
2008-03-24 14:40:43 +00:00
|
|
|
fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
|
|
|
|
FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
|
2008-03-28 15:19:07 +00:00
|
|
|
fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
|
2008-03-24 14:40:43 +00:00
|
|
|
FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
|
|
|
|
break;
|
2008-03-28 15:19:07 +00:00
|
|
|
case SPR_8378:
|
2008-10-02 14:31:53 +00:00
|
|
|
fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_PEX,
|
2008-03-24 14:40:43 +00:00
|
|
|
FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
|
|
|
|
break;
|
2008-03-28 15:19:07 +00:00
|
|
|
case SPR_8379:
|
2008-03-24 14:40:43 +00:00
|
|
|
fsl_setup_serdes(CONFIG_FSL_SERDES1, FSL_SERDES_PROTO_SATA,
|
|
|
|
FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
|
2008-03-28 15:19:07 +00:00
|
|
|
fsl_setup_serdes(CONFIG_FSL_SERDES2, FSL_SERDES_PROTO_SATA,
|
2008-03-24 14:40:43 +00:00
|
|
|
FSL_SERDES_CLK_100, FSL_SERDES_VDD_1V);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("serdes not configured: unknown CPU part number: "
|
|
|
|
"%04x\n", spridr >> 16);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FSL_SERDES */
|
2020-04-04 05:16:47 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_FSL_ESDHC
|
|
|
|
clrsetbits_be32(&immr->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
|
|
|
|
clrsetbits_be32(&immr->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD);
|
|
|
|
#endif
|
2008-03-24 14:40:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-09 20:25:30 +00:00
|
|
|
#ifdef CONFIG_FSL_ESDHC
|
2021-05-11 18:18:02 +00:00
|
|
|
#if !(CONFIG_IS_ENABLED(DM_MMC) || CONFIG_IS_ENABLED(DM_USB))
|
2020-06-26 06:13:33 +00:00
|
|
|
int board_mmc_init(struct bd_info *bd)
|
2009-06-09 20:25:30 +00:00
|
|
|
{
|
|
|
|
struct immap __iomem *im = (struct immap __iomem *)CONFIG_SYS_IMMR;
|
2015-01-21 01:47:01 +00:00
|
|
|
char buffer[HWCONFIG_BUFFER_SIZE] = {0};
|
|
|
|
int esdhc_hwconfig_enabled = 0;
|
2009-06-09 20:25:30 +00:00
|
|
|
|
2017-08-03 18:22:12 +00:00
|
|
|
if (env_get_f("hwconfig", buffer, sizeof(buffer)) > 0)
|
2015-01-21 01:47:01 +00:00
|
|
|
esdhc_hwconfig_enabled = hwconfig_f("esdhc", buffer);
|
|
|
|
|
|
|
|
if (esdhc_hwconfig_enabled == 0)
|
2009-06-09 20:25:30 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
clrsetbits_be32(&im->sysconf.sicrl, SICRL_USB_B, SICRL_USB_B_SD);
|
|
|
|
clrsetbits_be32(&im->sysconf.sicrh, SICRH_SPI, SICRH_SPI_SD);
|
|
|
|
|
|
|
|
return fsl_esdhc_mmc_init(bd);
|
|
|
|
}
|
|
|
|
#endif
|
2020-04-04 05:16:47 +00:00
|
|
|
#endif
|
2009-06-09 20:25:30 +00:00
|
|
|
|
2008-02-08 19:15:55 +00:00
|
|
|
/*
|
|
|
|
* Miscellaneous late-boot configurations
|
|
|
|
*
|
|
|
|
* If a VSC7385 microcode image is present, then upload it.
|
|
|
|
*/
|
|
|
|
int misc_init_r(void)
|
|
|
|
{
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
#ifdef CONFIG_VSC7385_IMAGE
|
|
|
|
if (vsc7385_upload_firmware((void *) CONFIG_VSC7385_IMAGE,
|
|
|
|
CONFIG_VSC7385_IMAGE_SIZE)) {
|
|
|
|
puts("Failure uploading VSC7385 microcode.\n");
|
|
|
|
rc = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:18:02 +00:00
|
|
|
int board_late_init(void)
|
|
|
|
{
|
|
|
|
volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
|
|
|
|
#ifdef CONFIG_USB
|
|
|
|
clrsetbits_be32(&immap->sysconf.sicrl, SICRL_USB_A, 0x40000000);
|
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-16 06:38:05 +00:00
|
|
|
#if defined(CONFIG_OF_BOARD_SETUP)
|
|
|
|
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
2008-01-16 06:38:05 +00:00
|
|
|
{
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
ft_pci_setup(blob, bd);
|
|
|
|
#endif
|
|
|
|
ft_cpu_setup(blob, bd);
|
2016-09-16 11:42:15 +00:00
|
|
|
fsl_fdt_fixup_dr_usb(blob, bd);
|
2009-06-09 20:25:30 +00:00
|
|
|
fdt_fixup_esdhc(blob, bd);
|
2014-10-24 00:58:47 +00:00
|
|
|
|
|
|
|
return 0;
|
2008-01-16 06:38:05 +00:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_OF_BOARD_SETUP */
|