blob: 824479c099b6cfb311eb420bad5ba65143575fa0 [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>
Simon Glass807765b2019-12-28 10:44:54 -070011#include <fdt_support.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050013#include <ioports.h>
14#include <mpc83xx.h>
Simon Glasscd93d622020-05-10 11:40:13 -060015#include <asm/bitops.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050016#include <asm/mpc8349_pci.h>
17#include <i2c.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050018#include <spd_sdram.h>
Jon Loeligera30a5492008-03-04 10:03:03 -060019#include <miiphy.h>
Kim Phillipsb3458d22007-12-20 15:57:28 -060020#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090021#include <linux/libfdt.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050022#endif
Simon Glassc05ed002020-05-10 11:40:11 -060023#include <linux/delay.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050024
Simon Glass088454c2017-03-31 08:40:25 -060025DECLARE_GLOBAL_DATA_PTR;
26
Paul Gortmaker91e25762007-01-16 11:38:14 -050027int fixed_sdram(void);
28void sdram_init(void);
29
Peter Tyser0f898602009-05-22 17:23:24 -050030#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker91e25762007-01-16 11:38:14 -050031void ddr_enable_ecc(unsigned int dram_size);
32#endif
33
34#ifdef CONFIG_BOARD_EARLY_INIT_F
35int board_early_init_f (void)
36{
37 return 0;
38}
39#endif
40
41#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
42
Simon Glassf1683aa2017-04-06 12:47:05 -060043int dram_init(void)
Paul Gortmaker91e25762007-01-16 11:38:14 -050044{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050046 u32 msize = 0;
47
48 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
49 return -1;
50
Paul Gortmaker91e25762007-01-16 11:38:14 -050051 /* DDR SDRAM - Main SODIMM */
Mario Six8a81bfd2019-01-21 09:18:15 +010052 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050053#if defined(CONFIG_SPD_EEPROM)
54 msize = spd_sdram();
55#else
56 msize = fixed_sdram();
57#endif
58 /*
59 * Initialize SDRAM if it is on local bus.
60 */
61 sdram_init();
62
63#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
64 /*
65 * Initialize and enable DDR ECC.
66 */
67 ddr_enable_ecc(msize * 1024 * 1024);
68#endif
Simon Glass088454c2017-03-31 08:40:25 -060069 /* set total bus SDRAM size(bytes) -- DDR */
70 gd->ram_size = msize * 1024 * 1024;
71
72 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -050073}
74
75#if !defined(CONFIG_SPD_EEPROM)
76/*************************************************************************
77 * fixed sdram init -- doesn't use serial presence detect.
78 ************************************************************************/
79int fixed_sdram(void)
80{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger2e651b22011-10-11 23:57:31 -050082 u32 msize = CONFIG_SYS_DDR_SIZE;
83 u32 ddr_size = msize << 20; /* DDR size in bytes */
84 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker91e25762007-01-16 11:38:14 -050085
Mario Six133ec602019-01-21 09:18:16 +010086 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker91e25762007-01-16 11:38:14 -050087 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
88
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020089#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker91e25762007-01-16 11:38:14 -050090#warning Currently any ddr size other than 256 is not supported
91#endif
Joe Hershberger2e651b22011-10-11 23:57:31 -050092
Mario Six133ec602019-01-21 09:18:16 +010093#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger2e651b22011-10-11 23:57:31 -050094#warning Chip select bounds is only configurable in 16MB increments
95#endif
96 im->ddr.csbnds[2].csbnds =
Mario Six133ec602019-01-21 09:18:16 +010097 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
98 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger2e651b22011-10-11 23:57:31 -050099 CSBNDS_EA_SHIFT) & CSBNDS_EA);
100 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500101
102 /* currently we use only one CS, so disable the other banks */
103 im->ddr.cs_config[0] = 0;
104 im->ddr.cs_config[1] = 0;
105 im->ddr.cs_config[3] = 0;
106
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
108 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500109
110 im->ddr.sdram_cfg =
111 SDRAM_CFG_SREN
112#if defined(CONFIG_DDR_2T_TIMING)
113 | SDRAM_CFG_2T_EN
114#endif
Kim Phillipsbbea46f2007-08-16 22:52:48 -0500115 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500116#if defined (CONFIG_DDR_32BIT)
117 /* for 32-bit mode burst length is 8 */
118 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
119#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200120 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500121
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200122 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500123 udelay(200);
124
125 /* enable DDR controller */
126 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
127 return msize;
128}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200129#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker91e25762007-01-16 11:38:14 -0500130
131
132int checkboard (void)
133{
134 puts("Board: Wind River SBC834x\n");
135 return 0;
136}
137
138/*
139 * if board is fitted with SDRAM
140 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200141#if defined(CONFIG_SYS_BR2_PRELIM) \
142 && defined(CONFIG_SYS_OR2_PRELIM) \
143 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
144 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500145/*
146 * Initialize SDRAM memory on the Local Bus.
147 */
148
149void sdram_init(void)
150{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200151 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Brucef51cdaf2010-06-17 11:37:20 -0500152 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200153 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Six42c9a492019-01-21 09:18:17 +0100154 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
155 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
156 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500157
158 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200159 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker91e25762007-01-16 11:38:14 -0500160
161 /*
162 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
163 */
164
165 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Six42c9a492019-01-21 09:18:17 +0100166 lbc->lbcr = 0x00000000;
167 /* LB refresh timer prescal, 266MHz/32 */
168 lbc->mrtpr = 0x20000000;
169 /* LB sdram refresh timer, about 6us */
170 lbc->lsrt = 0x32000000;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500171 asm("sync");
172
173 /*
174 * Configure the SDRAM controller Machine Mode Register.
175 */
Mario Six42c9a492019-01-21 09:18:17 +0100176 /* 0x40636733; normal operation */
177 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500178
Mario Six42c9a492019-01-21 09:18:17 +0100179 /* 0x68636733; precharge all the banks */
180 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500181 asm("sync");
182 *sdram_addr = 0xff;
183 udelay(100);
184
Mario Six42c9a492019-01-21 09:18:17 +0100185 /* 0x48636733; auto refresh */
186 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500187 asm("sync");
188 /*1 times*/
189 *sdram_addr = 0xff;
190 udelay(100);
191 /*2 times*/
192 *sdram_addr = 0xff;
193 udelay(100);
194 /*3 times*/
195 *sdram_addr = 0xff;
196 udelay(100);
197 /*4 times*/
198 *sdram_addr = 0xff;
199 udelay(100);
200 /*5 times*/
201 *sdram_addr = 0xff;
202 udelay(100);
203 /*6 times*/
204 *sdram_addr = 0xff;
205 udelay(100);
206 /*7 times*/
207 *sdram_addr = 0xff;
208 udelay(100);
209 /*8 times*/
210 *sdram_addr = 0xff;
211 udelay(100);
212
213 /* 0x58636733; mode register write operation */
Mario Six42c9a492019-01-21 09:18:17 +0100214 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500215 asm("sync");
216 *sdram_addr = 0xff;
217 udelay(100);
218
Mario Six42c9a492019-01-21 09:18:17 +0100219 /* 0x40636733; normal operation */
220 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500221 asm("sync");
222 *sdram_addr = 0xff;
223 udelay(100);
224}
225#else
226void sdram_init(void)
227{
228 puts(" SDRAM on Local Bus: Disabled in config\n");
229}
230#endif
231
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500232#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900233int ft_board_setup(void *blob, struct bd_info *bd)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500234{
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500235 ft_cpu_setup(blob, bd);
236#ifdef CONFIG_PCI
237 ft_pci_setup(blob, bd);
238#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600239
240 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500241}
242#endif