blob: 9051392cd09f12c5f483bba4c970d8c060a96c99 [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>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050012#include <ioports.h>
13#include <mpc83xx.h>
14#include <asm/mpc8349_pci.h>
15#include <i2c.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050016#include <spd_sdram.h>
Jon Loeligerde9737d2008-03-04 10:03:03 -060017#include <miiphy.h>
Kim Phillips3204c7c2007-12-20 15:57:28 -060018#if defined(CONFIG_OF_LIBFDT)
Masahiro Yamada75f82d02018-03-05 01:20:11 +090019#include <linux/libfdt.h>
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050020#endif
21
Simon Glass39f90ba2017-03-31 08:40:25 -060022DECLARE_GLOBAL_DATA_PTR;
23
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050024int fixed_sdram(void);
25void sdram_init(void);
26
Peter Tyser62e73982009-05-22 17:23:24 -050027#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050028void ddr_enable_ecc(unsigned int dram_size);
29#endif
30
31#ifdef CONFIG_BOARD_EARLY_INIT_F
32int board_early_init_f (void)
33{
34 return 0;
35}
36#endif
37
38#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
39
Simon Glassd35f3382017-04-06 12:47:05 -060040int dram_init(void)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050041{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020042 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050043 u32 msize = 0;
44
45 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
46 return -1;
47
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050048 /* DDR SDRAM - Main SODIMM */
Mario Sixc9f92772019-01-21 09:18:15 +010049 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050050#if defined(CONFIG_SPD_EEPROM)
51 msize = spd_sdram();
52#else
53 msize = fixed_sdram();
54#endif
55 /*
56 * Initialize SDRAM if it is on local bus.
57 */
58 sdram_init();
59
60#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
61 /*
62 * Initialize and enable DDR ECC.
63 */
64 ddr_enable_ecc(msize * 1024 * 1024);
65#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060066 /* set total bus SDRAM size(bytes) -- DDR */
67 gd->ram_size = msize * 1024 * 1024;
68
69 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050070}
71
72#if !defined(CONFIG_SPD_EEPROM)
73/*************************************************************************
74 * fixed sdram init -- doesn't use serial presence detect.
75 ************************************************************************/
76int fixed_sdram(void)
77{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020078 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger5ade3902011-10-11 23:57:31 -050079 u32 msize = CONFIG_SYS_DDR_SIZE;
80 u32 ddr_size = msize << 20; /* DDR size in bytes */
81 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050082
Mario Six805cac12019-01-21 09:18:16 +010083 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050084 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
85
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050087#warning Currently any ddr size other than 256 is not supported
88#endif
Joe Hershberger5ade3902011-10-11 23:57:31 -050089
Mario Six805cac12019-01-21 09:18:16 +010090#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger5ade3902011-10-11 23:57:31 -050091#warning Chip select bounds is only configurable in 16MB increments
92#endif
93 im->ddr.csbnds[2].csbnds =
Mario Six805cac12019-01-21 09:18:16 +010094 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
95 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger5ade3902011-10-11 23:57:31 -050096 CSBNDS_EA_SHIFT) & CSBNDS_EA);
97 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050098
99 /* currently we use only one CS, so disable the other banks */
100 im->ddr.cs_config[0] = 0;
101 im->ddr.cs_config[1] = 0;
102 im->ddr.cs_config[3] = 0;
103
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
105 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500106
107 im->ddr.sdram_cfg =
108 SDRAM_CFG_SREN
109#if defined(CONFIG_DDR_2T_TIMING)
110 | SDRAM_CFG_2T_EN
111#endif
Kim Phillips3b9c20f2007-08-16 22:52:48 -0500112 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500113#if defined (CONFIG_DDR_32BIT)
114 /* for 32-bit mode burst length is 8 */
115 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
116#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200117 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500118
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500120 udelay(200);
121
122 /* enable DDR controller */
123 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
124 return msize;
125}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500127
128
129int checkboard (void)
130{
131 puts("Board: Wind River SBC834x\n");
132 return 0;
133}
134
135/*
136 * if board is fitted with SDRAM
137 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138#if defined(CONFIG_SYS_BR2_PRELIM) \
139 && defined(CONFIG_SYS_OR2_PRELIM) \
140 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
141 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500142/*
143 * Initialize SDRAM memory on the Local Bus.
144 */
145
146void sdram_init(void)
147{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200148 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Bruce0d4cee12010-06-17 11:37:20 -0500149 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200150 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Sixdc003002019-01-21 09:18:17 +0100151 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
152 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
153 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500154
155 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200156 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500157
158 /*
159 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
160 */
161
162 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Sixdc003002019-01-21 09:18:17 +0100163 lbc->lbcr = 0x00000000;
164 /* LB refresh timer prescal, 266MHz/32 */
165 lbc->mrtpr = 0x20000000;
166 /* LB sdram refresh timer, about 6us */
167 lbc->lsrt = 0x32000000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500168 asm("sync");
169
170 /*
171 * Configure the SDRAM controller Machine Mode Register.
172 */
Mario Sixdc003002019-01-21 09:18:17 +0100173 /* 0x40636733; normal operation */
174 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500175
Mario Sixdc003002019-01-21 09:18:17 +0100176 /* 0x68636733; precharge all the banks */
177 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500178 asm("sync");
179 *sdram_addr = 0xff;
180 udelay(100);
181
Mario Sixdc003002019-01-21 09:18:17 +0100182 /* 0x48636733; auto refresh */
183 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500184 asm("sync");
185 /*1 times*/
186 *sdram_addr = 0xff;
187 udelay(100);
188 /*2 times*/
189 *sdram_addr = 0xff;
190 udelay(100);
191 /*3 times*/
192 *sdram_addr = 0xff;
193 udelay(100);
194 /*4 times*/
195 *sdram_addr = 0xff;
196 udelay(100);
197 /*5 times*/
198 *sdram_addr = 0xff;
199 udelay(100);
200 /*6 times*/
201 *sdram_addr = 0xff;
202 udelay(100);
203 /*7 times*/
204 *sdram_addr = 0xff;
205 udelay(100);
206 /*8 times*/
207 *sdram_addr = 0xff;
208 udelay(100);
209
210 /* 0x58636733; mode register write operation */
Mario Sixdc003002019-01-21 09:18:17 +0100211 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500212 asm("sync");
213 *sdram_addr = 0xff;
214 udelay(100);
215
Mario Sixdc003002019-01-21 09:18:17 +0100216 /* 0x40636733; normal operation */
217 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500218 asm("sync");
219 *sdram_addr = 0xff;
220 udelay(100);
221}
222#else
223void sdram_init(void)
224{
225 puts(" SDRAM on Local Bus: Disabled in config\n");
226}
227#endif
228
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500229#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600230int ft_board_setup(void *blob, bd_t *bd)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500231{
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500232 ft_cpu_setup(blob, bd);
233#ifdef CONFIG_PCI
234 ft_pci_setup(blob, bd);
235#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600236
237 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500238}
239#endif