blob: a647de6b11217b0b05aa6b2741566b19df8c4215 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Paul Gortmaker91e25762007-01-16 11:38:14 -05002/*
3 * sbc8349.c -- WindRiver SBC8349 board support.
4 * Copyright (c) 2006-2007 Wind River Systems, Inc.
5 *
6 * Paul Gortmaker <paul.gortmaker@windriver.com>
7 * Based on board/mpc8349emds/mpc8349emds.c (and previous 834x releases.)
Paul Gortmaker91e25762007-01-16 11:38:14 -05008 */
9
10#include <common.h>
11#include <ioports.h>
12#include <mpc83xx.h>
13#include <asm/mpc8349_pci.h>
14#include <i2c.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050015#include <spd_sdram.h>
Jon Loeligera30a5492008-03-04 10:03:03 -060016#include <miiphy.h>
Kim Phillipsb3458d22007-12-20 15:57:28 -060017#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090018#include <linux/libfdt.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050019#endif
20
Simon Glass088454c2017-03-31 08:40:25 -060021DECLARE_GLOBAL_DATA_PTR;
22
Paul Gortmaker91e25762007-01-16 11:38:14 -050023int fixed_sdram(void);
24void sdram_init(void);
25
Peter Tyser0f898602009-05-22 17:23:24 -050026#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker91e25762007-01-16 11:38:14 -050027void ddr_enable_ecc(unsigned int dram_size);
28#endif
29
30#ifdef CONFIG_BOARD_EARLY_INIT_F
31int board_early_init_f (void)
32{
33 return 0;
34}
35#endif
36
37#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
38
Simon Glassf1683aa2017-04-06 12:47:05 -060039int dram_init(void)
Paul Gortmaker91e25762007-01-16 11:38:14 -050040{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020041 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050042 u32 msize = 0;
43
44 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
45 return -1;
46
Paul Gortmaker91e25762007-01-16 11:38:14 -050047 /* DDR SDRAM - Main SODIMM */
Mario Six8a81bfd2019-01-21 09:18:15 +010048 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050049#if defined(CONFIG_SPD_EEPROM)
50 msize = spd_sdram();
51#else
52 msize = fixed_sdram();
53#endif
54 /*
55 * Initialize SDRAM if it is on local bus.
56 */
57 sdram_init();
58
59#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
60 /*
61 * Initialize and enable DDR ECC.
62 */
63 ddr_enable_ecc(msize * 1024 * 1024);
64#endif
Simon Glass088454c2017-03-31 08:40:25 -060065 /* set total bus SDRAM size(bytes) -- DDR */
66 gd->ram_size = msize * 1024 * 1024;
67
68 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -050069}
70
71#if !defined(CONFIG_SPD_EEPROM)
72/*************************************************************************
73 * fixed sdram init -- doesn't use serial presence detect.
74 ************************************************************************/
75int fixed_sdram(void)
76{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020077 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger2e651b22011-10-11 23:57:31 -050078 u32 msize = CONFIG_SYS_DDR_SIZE;
79 u32 ddr_size = msize << 20; /* DDR size in bytes */
80 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker91e25762007-01-16 11:38:14 -050081
Mario Six133ec602019-01-21 09:18:16 +010082 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker91e25762007-01-16 11:38:14 -050083 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
84
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker91e25762007-01-16 11:38:14 -050086#warning Currently any ddr size other than 256 is not supported
87#endif
Joe Hershberger2e651b22011-10-11 23:57:31 -050088
Mario Six133ec602019-01-21 09:18:16 +010089#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger2e651b22011-10-11 23:57:31 -050090#warning Chip select bounds is only configurable in 16MB increments
91#endif
92 im->ddr.csbnds[2].csbnds =
Mario Six133ec602019-01-21 09:18:16 +010093 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
94 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger2e651b22011-10-11 23:57:31 -050095 CSBNDS_EA_SHIFT) & CSBNDS_EA);
96 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker91e25762007-01-16 11:38:14 -050097
98 /* currently we use only one CS, so disable the other banks */
99 im->ddr.cs_config[0] = 0;
100 im->ddr.cs_config[1] = 0;
101 im->ddr.cs_config[3] = 0;
102
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200103 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
104 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500105
106 im->ddr.sdram_cfg =
107 SDRAM_CFG_SREN
108#if defined(CONFIG_DDR_2T_TIMING)
109 | SDRAM_CFG_2T_EN
110#endif
Kim Phillipsbbea46f2007-08-16 22:52:48 -0500111 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500112#if defined (CONFIG_DDR_32BIT)
113 /* for 32-bit mode burst length is 8 */
114 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
115#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200116 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500117
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200118 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500119 udelay(200);
120
121 /* enable DDR controller */
122 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
123 return msize;
124}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200125#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker91e25762007-01-16 11:38:14 -0500126
127
128int checkboard (void)
129{
130 puts("Board: Wind River SBC834x\n");
131 return 0;
132}
133
134/*
135 * if board is fitted with SDRAM
136 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200137#if defined(CONFIG_SYS_BR2_PRELIM) \
138 && defined(CONFIG_SYS_OR2_PRELIM) \
139 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
140 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500141/*
142 * Initialize SDRAM memory on the Local Bus.
143 */
144
145void sdram_init(void)
146{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200147 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Brucef51cdaf2010-06-17 11:37:20 -0500148 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200149 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Six42c9a492019-01-21 09:18:17 +0100150 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
151 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
152 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500153
154 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200155 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker91e25762007-01-16 11:38:14 -0500156
157 /*
158 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
159 */
160
161 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Six42c9a492019-01-21 09:18:17 +0100162 lbc->lbcr = 0x00000000;
163 /* LB refresh timer prescal, 266MHz/32 */
164 lbc->mrtpr = 0x20000000;
165 /* LB sdram refresh timer, about 6us */
166 lbc->lsrt = 0x32000000;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500167 asm("sync");
168
169 /*
170 * Configure the SDRAM controller Machine Mode Register.
171 */
Mario Six42c9a492019-01-21 09:18:17 +0100172 /* 0x40636733; normal operation */
173 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500174
Mario Six42c9a492019-01-21 09:18:17 +0100175 /* 0x68636733; precharge all the banks */
176 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500177 asm("sync");
178 *sdram_addr = 0xff;
179 udelay(100);
180
Mario Six42c9a492019-01-21 09:18:17 +0100181 /* 0x48636733; auto refresh */
182 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500183 asm("sync");
184 /*1 times*/
185 *sdram_addr = 0xff;
186 udelay(100);
187 /*2 times*/
188 *sdram_addr = 0xff;
189 udelay(100);
190 /*3 times*/
191 *sdram_addr = 0xff;
192 udelay(100);
193 /*4 times*/
194 *sdram_addr = 0xff;
195 udelay(100);
196 /*5 times*/
197 *sdram_addr = 0xff;
198 udelay(100);
199 /*6 times*/
200 *sdram_addr = 0xff;
201 udelay(100);
202 /*7 times*/
203 *sdram_addr = 0xff;
204 udelay(100);
205 /*8 times*/
206 *sdram_addr = 0xff;
207 udelay(100);
208
209 /* 0x58636733; mode register write operation */
Mario Six42c9a492019-01-21 09:18:17 +0100210 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500211 asm("sync");
212 *sdram_addr = 0xff;
213 udelay(100);
214
Mario Six42c9a492019-01-21 09:18:17 +0100215 /* 0x40636733; normal operation */
216 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500217 asm("sync");
218 *sdram_addr = 0xff;
219 udelay(100);
220}
221#else
222void sdram_init(void)
223{
224 puts(" SDRAM on Local Bus: Disabled in config\n");
225}
226#endif
227
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500228#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600229int ft_board_setup(void *blob, bd_t *bd)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500230{
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500231 ft_cpu_setup(blob, bd);
232#ifdef CONFIG_PCI
233 ft_pci_setup(blob, bd);
234#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600235
236 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500237}
238#endif