blob: c84146a6086665c387face990013b17a097cf597 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Paul Gortmaker2bd9f1b2007-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 Gortmaker2bd9f1b2007-01-16 11:38:14 -05008 */
9
10#include <common.h>
Simon Glass3bbe70c2019-12-28 10:44:54 -070011#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050013#include <ioports.h>
14#include <mpc83xx.h>
15#include <asm/mpc8349_pci.h>
16#include <i2c.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050017#include <spd_sdram.h>
Jon Loeligerde9737d2008-03-04 10:03:03 -060018#include <miiphy.h>
Kim Phillips3204c7c2007-12-20 15:57:28 -060019#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamada75f82d02018-03-05 01:20:11 +090020#include <linux/libfdt.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050021#endif
Simon Glassdbd79542020-05-10 11:40:11 -060022#include <linux/delay.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050023
Simon Glass39f90ba2017-03-31 08:40:25 -060024DECLARE_GLOBAL_DATA_PTR;
25
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050026int fixed_sdram(void);
27void sdram_init(void);
28
Peter Tyser62e73982009-05-22 17:23:24 -050029#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050030void ddr_enable_ecc(unsigned int dram_size);
31#endif
32
33#ifdef CONFIG_BOARD_EARLY_INIT_F
34int board_early_init_f (void)
35{
36 return 0;
37}
38#endif
39
40#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
41
Simon Glassd35f3382017-04-06 12:47:05 -060042int dram_init(void)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050043{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020044 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050045 u32 msize = 0;
46
47 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
48 return -1;
49
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050050 /* DDR SDRAM - Main SODIMM */
Mario Sixc9f92772019-01-21 09:18:15 +010051 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050052#if defined(CONFIG_SPD_EEPROM)
53 msize = spd_sdram();
54#else
55 msize = fixed_sdram();
56#endif
57 /*
58 * Initialize SDRAM if it is on local bus.
59 */
60 sdram_init();
61
62#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
63 /*
64 * Initialize and enable DDR ECC.
65 */
66 ddr_enable_ecc(msize * 1024 * 1024);
67#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060068 /* set total bus SDRAM size(bytes) -- DDR */
69 gd->ram_size = msize * 1024 * 1024;
70
71 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050072}
73
74#if !defined(CONFIG_SPD_EEPROM)
75/*************************************************************************
76 * fixed sdram init -- doesn't use serial presence detect.
77 ************************************************************************/
78int fixed_sdram(void)
79{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020080 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger5ade3902011-10-11 23:57:31 -050081 u32 msize = CONFIG_SYS_DDR_SIZE;
82 u32 ddr_size = msize << 20; /* DDR size in bytes */
83 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050084
Mario Six805cac12019-01-21 09:18:16 +010085 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050086 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
87
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050089#warning Currently any ddr size other than 256 is not supported
90#endif
Joe Hershberger5ade3902011-10-11 23:57:31 -050091
Mario Six805cac12019-01-21 09:18:16 +010092#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger5ade3902011-10-11 23:57:31 -050093#warning Chip select bounds is only configurable in 16MB increments
94#endif
95 im->ddr.csbnds[2].csbnds =
Mario Six805cac12019-01-21 09:18:16 +010096 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
97 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger5ade3902011-10-11 23:57:31 -050098 CSBNDS_EA_SHIFT) & CSBNDS_EA);
99 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500100
101 /* currently we use only one CS, so disable the other banks */
102 im->ddr.cs_config[0] = 0;
103 im->ddr.cs_config[1] = 0;
104 im->ddr.cs_config[3] = 0;
105
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200106 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
107 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500108
109 im->ddr.sdram_cfg =
110 SDRAM_CFG_SREN
111#if defined(CONFIG_DDR_2T_TIMING)
112 | SDRAM_CFG_2T_EN
113#endif
Kim Phillips3b9c20f2007-08-16 22:52:48 -0500114 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500115#if defined (CONFIG_DDR_32BIT)
116 /* for 32-bit mode burst length is 8 */
117 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
118#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500120
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200121 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500122 udelay(200);
123
124 /* enable DDR controller */
125 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
126 return msize;
127}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200128#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500129
130
131int checkboard (void)
132{
133 puts("Board: Wind River SBC834x\n");
134 return 0;
135}
136
137/*
138 * if board is fitted with SDRAM
139 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200140#if defined(CONFIG_SYS_BR2_PRELIM) \
141 && defined(CONFIG_SYS_OR2_PRELIM) \
142 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
143 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500144/*
145 * Initialize SDRAM memory on the Local Bus.
146 */
147
148void sdram_init(void)
149{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Bruce0d4cee12010-06-17 11:37:20 -0500151 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200152 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Sixdc003002019-01-21 09:18:17 +0100153 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
154 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
155 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500156
157 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200158 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500159
160 /*
161 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
162 */
163
164 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Sixdc003002019-01-21 09:18:17 +0100165 lbc->lbcr = 0x00000000;
166 /* LB refresh timer prescal, 266MHz/32 */
167 lbc->mrtpr = 0x20000000;
168 /* LB sdram refresh timer, about 6us */
169 lbc->lsrt = 0x32000000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500170 asm("sync");
171
172 /*
173 * Configure the SDRAM controller Machine Mode Register.
174 */
Mario Sixdc003002019-01-21 09:18:17 +0100175 /* 0x40636733; normal operation */
176 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500177
Mario Sixdc003002019-01-21 09:18:17 +0100178 /* 0x68636733; precharge all the banks */
179 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500180 asm("sync");
181 *sdram_addr = 0xff;
182 udelay(100);
183
Mario Sixdc003002019-01-21 09:18:17 +0100184 /* 0x48636733; auto refresh */
185 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500186 asm("sync");
187 /*1 times*/
188 *sdram_addr = 0xff;
189 udelay(100);
190 /*2 times*/
191 *sdram_addr = 0xff;
192 udelay(100);
193 /*3 times*/
194 *sdram_addr = 0xff;
195 udelay(100);
196 /*4 times*/
197 *sdram_addr = 0xff;
198 udelay(100);
199 /*5 times*/
200 *sdram_addr = 0xff;
201 udelay(100);
202 /*6 times*/
203 *sdram_addr = 0xff;
204 udelay(100);
205 /*7 times*/
206 *sdram_addr = 0xff;
207 udelay(100);
208 /*8 times*/
209 *sdram_addr = 0xff;
210 udelay(100);
211
212 /* 0x58636733; mode register write operation */
Mario Sixdc003002019-01-21 09:18:17 +0100213 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500214 asm("sync");
215 *sdram_addr = 0xff;
216 udelay(100);
217
Mario Sixdc003002019-01-21 09:18:17 +0100218 /* 0x40636733; normal operation */
219 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500220 asm("sync");
221 *sdram_addr = 0xff;
222 udelay(100);
223}
224#else
225void sdram_init(void)
226{
227 puts(" SDRAM on Local Bus: Disabled in config\n");
228}
229#endif
230
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500231#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600232int ft_board_setup(void *blob, bd_t *bd)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500233{
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500234 ft_cpu_setup(blob, bd);
235#ifdef CONFIG_PCI
236 ft_pci_setup(blob, bd);
237#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600238
239 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500240}
241#endif