blob: b440a0b17e9721c21a8db59bc1dd4ea41e5af13d [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>
Simon Glass401d1c42020-10-30 21:38:53 -060016#include <asm/global_data.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050017#include <asm/mpc8349_pci.h>
18#include <i2c.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050019#include <spd_sdram.h>
Jon Loeligera30a5492008-03-04 10:03:03 -060020#include <miiphy.h>
Kim Phillipsb3458d22007-12-20 15:57:28 -060021#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090022#include <linux/libfdt.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050023#endif
Simon Glassc05ed002020-05-10 11:40:11 -060024#include <linux/delay.h>
Paul Gortmaker91e25762007-01-16 11:38:14 -050025
Simon Glass088454c2017-03-31 08:40:25 -060026DECLARE_GLOBAL_DATA_PTR;
27
Paul Gortmaker91e25762007-01-16 11:38:14 -050028int fixed_sdram(void);
29void sdram_init(void);
30
Peter Tyser0f898602009-05-22 17:23:24 -050031#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker91e25762007-01-16 11:38:14 -050032void ddr_enable_ecc(unsigned int dram_size);
33#endif
34
35#ifdef CONFIG_BOARD_EARLY_INIT_F
36int board_early_init_f (void)
37{
38 return 0;
39}
40#endif
41
42#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
43
Simon Glassf1683aa2017-04-06 12:47:05 -060044int dram_init(void)
Paul Gortmaker91e25762007-01-16 11:38:14 -050045{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050047 u32 msize = 0;
48
49 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
50 return -1;
51
Paul Gortmaker91e25762007-01-16 11:38:14 -050052 /* DDR SDRAM - Main SODIMM */
Mario Six8a81bfd2019-01-21 09:18:15 +010053 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker91e25762007-01-16 11:38:14 -050054#if defined(CONFIG_SPD_EEPROM)
55 msize = spd_sdram();
56#else
57 msize = fixed_sdram();
58#endif
59 /*
60 * Initialize SDRAM if it is on local bus.
61 */
62 sdram_init();
63
64#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
65 /*
66 * Initialize and enable DDR ECC.
67 */
68 ddr_enable_ecc(msize * 1024 * 1024);
69#endif
Simon Glass088454c2017-03-31 08:40:25 -060070 /* set total bus SDRAM size(bytes) -- DDR */
71 gd->ram_size = msize * 1024 * 1024;
72
73 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -050074}
75
76#if !defined(CONFIG_SPD_EEPROM)
77/*************************************************************************
78 * fixed sdram init -- doesn't use serial presence detect.
79 ************************************************************************/
80int fixed_sdram(void)
81{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020082 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger2e651b22011-10-11 23:57:31 -050083 u32 msize = CONFIG_SYS_DDR_SIZE;
84 u32 ddr_size = msize << 20; /* DDR size in bytes */
85 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker91e25762007-01-16 11:38:14 -050086
Mario Six133ec602019-01-21 09:18:16 +010087 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker91e25762007-01-16 11:38:14 -050088 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
89
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020090#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker91e25762007-01-16 11:38:14 -050091#warning Currently any ddr size other than 256 is not supported
92#endif
Joe Hershberger2e651b22011-10-11 23:57:31 -050093
Mario Six133ec602019-01-21 09:18:16 +010094#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger2e651b22011-10-11 23:57:31 -050095#warning Chip select bounds is only configurable in 16MB increments
96#endif
97 im->ddr.csbnds[2].csbnds =
Mario Six133ec602019-01-21 09:18:16 +010098 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
99 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger2e651b22011-10-11 23:57:31 -0500100 CSBNDS_EA_SHIFT) & CSBNDS_EA);
101 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500102
103 /* currently we use only one CS, so disable the other banks */
104 im->ddr.cs_config[0] = 0;
105 im->ddr.cs_config[1] = 0;
106 im->ddr.cs_config[3] = 0;
107
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200108 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
109 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500110
111 im->ddr.sdram_cfg =
112 SDRAM_CFG_SREN
113#if defined(CONFIG_DDR_2T_TIMING)
114 | SDRAM_CFG_2T_EN
115#endif
Kim Phillipsbbea46f2007-08-16 22:52:48 -0500116 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500117#if defined (CONFIG_DDR_32BIT)
118 /* for 32-bit mode burst length is 8 */
119 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
120#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200121 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500122
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200123 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500124 udelay(200);
125
126 /* enable DDR controller */
127 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
128 return msize;
129}
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200130#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker91e25762007-01-16 11:38:14 -0500131
132
133int checkboard (void)
134{
135 puts("Board: Wind River SBC834x\n");
136 return 0;
137}
138
139/*
140 * if board is fitted with SDRAM
141 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200142#if defined(CONFIG_SYS_BR2_PRELIM) \
143 && defined(CONFIG_SYS_OR2_PRELIM) \
144 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
145 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500146/*
147 * Initialize SDRAM memory on the Local Bus.
148 */
149
150void sdram_init(void)
151{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200152 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Brucef51cdaf2010-06-17 11:37:20 -0500153 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200154 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Six42c9a492019-01-21 09:18:17 +0100155 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
156 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
157 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500158
159 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200160 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker91e25762007-01-16 11:38:14 -0500161
162 /*
163 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
164 */
165
166 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Six42c9a492019-01-21 09:18:17 +0100167 lbc->lbcr = 0x00000000;
168 /* LB refresh timer prescal, 266MHz/32 */
169 lbc->mrtpr = 0x20000000;
170 /* LB sdram refresh timer, about 6us */
171 lbc->lsrt = 0x32000000;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500172 asm("sync");
173
174 /*
175 * Configure the SDRAM controller Machine Mode Register.
176 */
Mario Six42c9a492019-01-21 09:18:17 +0100177 /* 0x40636733; normal operation */
178 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500179
Mario Six42c9a492019-01-21 09:18:17 +0100180 /* 0x68636733; precharge all the banks */
181 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500182 asm("sync");
183 *sdram_addr = 0xff;
184 udelay(100);
185
Mario Six42c9a492019-01-21 09:18:17 +0100186 /* 0x48636733; auto refresh */
187 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500188 asm("sync");
189 /*1 times*/
190 *sdram_addr = 0xff;
191 udelay(100);
192 /*2 times*/
193 *sdram_addr = 0xff;
194 udelay(100);
195 /*3 times*/
196 *sdram_addr = 0xff;
197 udelay(100);
198 /*4 times*/
199 *sdram_addr = 0xff;
200 udelay(100);
201 /*5 times*/
202 *sdram_addr = 0xff;
203 udelay(100);
204 /*6 times*/
205 *sdram_addr = 0xff;
206 udelay(100);
207 /*7 times*/
208 *sdram_addr = 0xff;
209 udelay(100);
210 /*8 times*/
211 *sdram_addr = 0xff;
212 udelay(100);
213
214 /* 0x58636733; mode register write operation */
Mario Six42c9a492019-01-21 09:18:17 +0100215 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500216 asm("sync");
217 *sdram_addr = 0xff;
218 udelay(100);
219
Mario Six42c9a492019-01-21 09:18:17 +0100220 /* 0x40636733; normal operation */
221 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500222 asm("sync");
223 *sdram_addr = 0xff;
224 udelay(100);
225}
226#else
227void sdram_init(void)
228{
229 puts(" SDRAM on Local Bus: Disabled in config\n");
230}
231#endif
232
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500233#if defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900234int ft_board_setup(void *blob, struct bd_info *bd)
Paul Gortmaker91e25762007-01-16 11:38:14 -0500235{
Paul Gortmaker2408b3f2007-12-20 12:58:16 -0500236 ft_cpu_setup(blob, bd);
237#ifdef CONFIG_PCI
238 ft_pci_setup(blob, bd);
239#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600240
241 return 0;
Paul Gortmaker91e25762007-01-16 11:38:14 -0500242}
243#endif