2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-01-16 16:38:14 +00:00
|
|
|
/*
|
|
|
|
* sbc8349.c -- WindRiver SBC8349 board support.
|
|
|
|
* Copyright (c) 2006-2007 Wind River Systems, Inc.
|
|
|
|
*
|
|
|
|
* Paul Gortmaker <paul.gortmaker@windriver.com>
|
|
|
|
* Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:44:54 +00:00
|
|
|
#include <fdt_support.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2007-01-16 16:38:14 +00:00
|
|
|
#include <ioports.h>
|
|
|
|
#include <mpc83xx.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <asm/bitops.h>
|
2007-01-16 16:38:14 +00:00
|
|
|
#include <asm/mpc8349_pci.h>
|
|
|
|
#include <i2c.h>
|
|
|
|
#include <spd_sdram.h>
|
2008-03-04 16:03:03 +00:00
|
|
|
#include <miiphy.h>
|
2007-12-20 21:57:28 +00:00
|
|
|
#if defined(CONFIG_OF_LIBFDT)
|
2018-03-04 16:20:11 +00:00
|
|
|
#include <linux/libfdt.h>
|
2007-01-16 16:38:14 +00:00
|
|
|
#endif
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2007-01-16 16:38:14 +00:00
|
|
|
|
2017-03-31 14:40:25 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2007-01-16 16:38:14 +00:00
|
|
|
int fixed_sdram(void);
|
|
|
|
void sdram_init(void);
|
|
|
|
|
2009-05-22 22:23:24 +00:00
|
|
|
#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
|
2007-01-16 16:38:14 +00:00
|
|
|
void ddr_enable_ecc(unsigned int dram_size);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_BOARD_EARLY_INIT_F
|
|
|
|
int board_early_init_f (void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
|
|
|
|
|
2017-04-06 18:47:05 +00:00
|
|
|
int dram_init(void)
|
2007-01-16 16:38:14 +00:00
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
|
2007-01-16 16:38:14 +00:00
|
|
|
u32 msize = 0;
|
|
|
|
|
|
|
|
if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* DDR SDRAM - Main SODIMM */
|
2019-01-21 08:18:15 +00:00
|
|
|
im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
|
2007-01-16 16:38:14 +00:00
|
|
|
#if defined(CONFIG_SPD_EEPROM)
|
|
|
|
msize = spd_sdram();
|
|
|
|
#else
|
|
|
|
msize = fixed_sdram();
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* Initialize SDRAM if it is on local bus.
|
|
|
|
*/
|
|
|
|
sdram_init();
|
|
|
|
|
|
|
|
#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
|
|
|
|
/*
|
|
|
|
* Initialize and enable DDR ECC.
|
|
|
|
*/
|
|
|
|
ddr_enable_ecc(msize * 1024 * 1024);
|
|
|
|
#endif
|
2017-03-31 14:40:25 +00:00
|
|
|
/* set total bus SDRAM size(bytes) -- DDR */
|
|
|
|
gd->ram_size = msize * 1024 * 1024;
|
|
|
|
|
|
|
|
return 0;
|
2007-01-16 16:38:14 +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
|
|
|
volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
|
2011-10-12 04:57:31 +00:00
|
|
|
u32 msize = CONFIG_SYS_DDR_SIZE;
|
|
|
|
u32 ddr_size = msize << 20; /* DDR size in bytes */
|
|
|
|
u32 ddr_size_log2 = __ilog2(msize);
|
|
|
|
|
2019-01-21 08:18:16 +00:00
|
|
|
im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
|
2007-01-16 16:38:14 +00:00
|
|
|
im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
#if (CONFIG_SYS_DDR_SIZE != 256)
|
2007-01-16 16:38:14 +00:00
|
|
|
#warning Currently any ddr size other than 256 is not supported
|
|
|
|
#endif
|
2011-10-12 04:57:31 +00:00
|
|
|
|
2019-01-21 08:18:16 +00:00
|
|
|
#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
|
2011-10-12 04:57:31 +00:00
|
|
|
#warning Chip select bounds is only configurable in 16MB increments
|
|
|
|
#endif
|
|
|
|
im->ddr.csbnds[2].csbnds =
|
2019-01-21 08:18:16 +00:00
|
|
|
((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
|
|
|
|
(((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
|
2011-10-12 04:57:31 +00:00
|
|
|
CSBNDS_EA_SHIFT) & CSBNDS_EA);
|
|
|
|
im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
|
2007-01-16 16:38:14 +00:00
|
|
|
|
|
|
|
/* currently we use only one CS, so disable the other banks */
|
|
|
|
im->ddr.cs_config[0] = 0;
|
|
|
|
im->ddr.cs_config[1] = 0;
|
|
|
|
im->ddr.cs_config[3] = 0;
|
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
|
|
|
|
im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
|
2007-01-16 16:38:14 +00:00
|
|
|
|
|
|
|
im->ddr.sdram_cfg =
|
|
|
|
SDRAM_CFG_SREN
|
|
|
|
#if defined(CONFIG_DDR_2T_TIMING)
|
|
|
|
| SDRAM_CFG_2T_EN
|
|
|
|
#endif
|
2007-08-17 03:52:48 +00:00
|
|
|
| SDRAM_CFG_SDRAM_TYPE_DDR1;
|
2007-01-16 16:38:14 +00:00
|
|
|
#if defined (CONFIG_DDR_32BIT)
|
|
|
|
/* for 32-bit mode burst length is 8 */
|
|
|
|
im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
|
|
|
|
#endif
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
|
2007-01-16 16:38:14 +00:00
|
|
|
|
2008-10-16 13:01:15 +00:00
|
|
|
im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
|
2007-01-16 16:38:14 +00:00
|
|
|
udelay(200);
|
|
|
|
|
|
|
|
/* enable DDR controller */
|
|
|
|
im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
|
|
|
|
return msize;
|
|
|
|
}
|
2008-10-16 13:01:15 +00:00
|
|
|
#endif/*!CONFIG_SYS_SPD_EEPROM*/
|
2007-01-16 16:38:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
int checkboard (void)
|
|
|
|
{
|
|
|
|
puts("Board: Wind River SBC834x\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if board is fitted with SDRAM
|
|
|
|
*/
|
2008-10-16 13:01:15 +00:00
|
|
|
#if defined(CONFIG_SYS_BR2_PRELIM) \
|
|
|
|
&& defined(CONFIG_SYS_OR2_PRELIM) \
|
|
|
|
&& defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
|
|
|
|
&& defined(CONFIG_SYS_LBLAWAR2_PRELIM)
|
2007-01-16 16:38:14 +00:00
|
|
|
/*
|
|
|
|
* Initialize SDRAM memory on the Local Bus.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void sdram_init(void)
|
|
|
|
{
|
2008-10-16 13:01:15 +00:00
|
|
|
volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
|
2010-06-17 16:37:20 +00:00
|
|
|
volatile fsl_lbc_t *lbc = &immap->im_lbc;
|
2008-10-16 13:01:15 +00:00
|
|
|
uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
|
2019-01-21 08:18:17 +00:00
|
|
|
const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
|
|
|
|
LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
|
|
|
|
LSDMR_WRC3 | LSDMR_CL3;
|
2007-01-16 16:38:14 +00:00
|
|
|
|
|
|
|
puts("\n SDRAM on Local Bus: ");
|
2008-10-16 13:01:15 +00:00
|
|
|
print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
|
2007-01-16 16:38:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup SDRAM Base and Option Registers, already done in cpu_init.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* setup mtrpt, lsrt and lbcr for LB bus */
|
2019-01-21 08:18:17 +00:00
|
|
|
lbc->lbcr = 0x00000000;
|
|
|
|
/* LB refresh timer prescal, 266MHz/32 */
|
|
|
|
lbc->mrtpr = 0x20000000;
|
|
|
|
/* LB sdram refresh timer, about 6us */
|
|
|
|
lbc->lsrt = 0x32000000;
|
2007-01-16 16:38:14 +00:00
|
|
|
asm("sync");
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the SDRAM controller Machine Mode Register.
|
|
|
|
*/
|
2019-01-21 08:18:17 +00:00
|
|
|
/* 0x40636733; normal operation */
|
|
|
|
lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
|
2007-01-16 16:38:14 +00:00
|
|
|
|
2019-01-21 08:18:17 +00:00
|
|
|
/* 0x68636733; precharge all the banks */
|
|
|
|
lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
|
2007-01-16 16:38:14 +00:00
|
|
|
asm("sync");
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
|
2019-01-21 08:18:17 +00:00
|
|
|
/* 0x48636733; auto refresh */
|
|
|
|
lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
|
2007-01-16 16:38:14 +00:00
|
|
|
asm("sync");
|
|
|
|
/*1 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*2 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*3 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*4 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*5 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*6 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*7 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
/*8 times*/
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
|
|
|
|
/* 0x58636733; mode register write operation */
|
2019-01-21 08:18:17 +00:00
|
|
|
lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
|
2007-01-16 16:38:14 +00:00
|
|
|
asm("sync");
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
|
2019-01-21 08:18:17 +00:00
|
|
|
/* 0x40636733; normal operation */
|
|
|
|
lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
|
2007-01-16 16:38:14 +00:00
|
|
|
asm("sync");
|
|
|
|
*sdram_addr = 0xff;
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void sdram_init(void)
|
|
|
|
{
|
|
|
|
puts(" SDRAM on Local Bus: Disabled in config\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-12-20 17:58:16 +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)
|
2007-01-16 16:38:14 +00:00
|
|
|
{
|
2007-12-20 17:58:16 +00:00
|
|
|
ft_cpu_setup(blob, bd);
|
|
|
|
#ifdef CONFIG_PCI
|
|
|
|
ft_pci_setup(blob, bd);
|
|
|
|
#endif
|
2014-10-24 00:58:47 +00:00
|
|
|
|
|
|
|
return 0;
|
2007-01-16 16:38:14 +00:00
|
|
|
}
|
|
|
|
#endif
|