blob: 2c05ebb1bd514827dfdcfa667cf3c802ac6599e5 [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
22
Simon Glass39f90ba2017-03-31 08:40:25 -060023DECLARE_GLOBAL_DATA_PTR;
24
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050025int fixed_sdram(void);
26void sdram_init(void);
27
Peter Tyser62e73982009-05-22 17:23:24 -050028#if defined(CONFIG_DDR_ECC) && defined(CONFIG_MPC83xx)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050029void ddr_enable_ecc(unsigned int dram_size);
30#endif
31
32#ifdef CONFIG_BOARD_EARLY_INIT_F
33int board_early_init_f (void)
34{
35 return 0;
36}
37#endif
38
39#define ns2clk(ns) (ns / (1000000000 / CONFIG_8349_CLKIN) + 1)
40
Simon Glassd35f3382017-04-06 12:47:05 -060041int dram_init(void)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050042{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050044 u32 msize = 0;
45
46 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
47 return -1;
48
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050049 /* DDR SDRAM - Main SODIMM */
Mario Sixc9f92772019-01-21 09:18:15 +010050 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050051#if defined(CONFIG_SPD_EEPROM)
52 msize = spd_sdram();
53#else
54 msize = fixed_sdram();
55#endif
56 /*
57 * Initialize SDRAM if it is on local bus.
58 */
59 sdram_init();
60
61#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
62 /*
63 * Initialize and enable DDR ECC.
64 */
65 ddr_enable_ecc(msize * 1024 * 1024);
66#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060067 /* set total bus SDRAM size(bytes) -- DDR */
68 gd->ram_size = msize * 1024 * 1024;
69
70 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050071}
72
73#if !defined(CONFIG_SPD_EEPROM)
74/*************************************************************************
75 * fixed sdram init -- doesn't use serial presence detect.
76 ************************************************************************/
77int fixed_sdram(void)
78{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020079 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Joe Hershberger5ade3902011-10-11 23:57:31 -050080 u32 msize = CONFIG_SYS_DDR_SIZE;
81 u32 ddr_size = msize << 20; /* DDR size in bytes */
82 u32 ddr_size_log2 = __ilog2(msize);
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050083
Mario Six805cac12019-01-21 09:18:16 +010084 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_SDRAM_BASE & 0xfffff000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050085 im->sysconf.ddrlaw[0].ar = LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
86
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#if (CONFIG_SYS_DDR_SIZE != 256)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050088#warning Currently any ddr size other than 256 is not supported
89#endif
Joe Hershberger5ade3902011-10-11 23:57:31 -050090
Mario Six805cac12019-01-21 09:18:16 +010091#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger5ade3902011-10-11 23:57:31 -050092#warning Chip select bounds is only configurable in 16MB increments
93#endif
94 im->ddr.csbnds[2].csbnds =
Mario Six805cac12019-01-21 09:18:16 +010095 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
96 (((CONFIG_SYS_SDRAM_BASE + ddr_size - 1) >>
Joe Hershberger5ade3902011-10-11 23:57:31 -050097 CSBNDS_EA_SHIFT) & CSBNDS_EA);
98 im->ddr.cs_config[2] = CONFIG_SYS_DDR_CS2_CONFIG;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -050099
100 /* currently we use only one CS, so disable the other banks */
101 im->ddr.cs_config[0] = 0;
102 im->ddr.cs_config[1] = 0;
103 im->ddr.cs_config[3] = 0;
104
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200105 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
106 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500107
108 im->ddr.sdram_cfg =
109 SDRAM_CFG_SREN
110#if defined(CONFIG_DDR_2T_TIMING)
111 | SDRAM_CFG_2T_EN
112#endif
Kim Phillips3b9c20f2007-08-16 22:52:48 -0500113 | SDRAM_CFG_SDRAM_TYPE_DDR1;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500114#if defined (CONFIG_DDR_32BIT)
115 /* for 32-bit mode burst length is 8 */
116 im->ddr.sdram_cfg |= (SDRAM_CFG_32_BE | SDRAM_CFG_8_BE);
117#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200118 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500119
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200120 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500121 udelay(200);
122
123 /* enable DDR controller */
124 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
125 return msize;
126}
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200127#endif/*!CONFIG_SYS_SPD_EEPROM*/
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500128
129
130int checkboard (void)
131{
132 puts("Board: Wind River SBC834x\n");
133 return 0;
134}
135
136/*
137 * if board is fitted with SDRAM
138 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200139#if defined(CONFIG_SYS_BR2_PRELIM) \
140 && defined(CONFIG_SYS_OR2_PRELIM) \
141 && defined(CONFIG_SYS_LBLAWBAR2_PRELIM) \
142 && defined(CONFIG_SYS_LBLAWAR2_PRELIM)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500143/*
144 * Initialize SDRAM memory on the Local Bus.
145 */
146
147void sdram_init(void)
148{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200149 volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
Becky Bruce0d4cee12010-06-17 11:37:20 -0500150 volatile fsl_lbc_t *lbc = &immap->im_lbc;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200151 uint *sdram_addr = (uint *)CONFIG_SYS_LBC_SDRAM_BASE;
Mario Sixdc003002019-01-21 09:18:17 +0100152 const u32 lsdmr_common = LSDMR_RFEN | LSDMR_BSMA1516 | LSDMR_RFCR8 |
153 LSDMR_PRETOACT6 | LSDMR_ACTTORW3 | LSDMR_BL8 |
154 LSDMR_WRC3 | LSDMR_CL3;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500155
156 puts("\n SDRAM on Local Bus: ");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200157 print_size (CONFIG_SYS_LBC_SDRAM_SIZE * 1024 * 1024, "\n");
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500158
159 /*
160 * Setup SDRAM Base and Option Registers, already done in cpu_init.c
161 */
162
163 /* setup mtrpt, lsrt and lbcr for LB bus */
Mario Sixdc003002019-01-21 09:18:17 +0100164 lbc->lbcr = 0x00000000;
165 /* LB refresh timer prescal, 266MHz/32 */
166 lbc->mrtpr = 0x20000000;
167 /* LB sdram refresh timer, about 6us */
168 lbc->lsrt = 0x32000000;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500169 asm("sync");
170
171 /*
172 * Configure the SDRAM controller Machine Mode Register.
173 */
Mario Sixdc003002019-01-21 09:18:17 +0100174 /* 0x40636733; normal operation */
175 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500176
Mario Sixdc003002019-01-21 09:18:17 +0100177 /* 0x68636733; precharge all the banks */
178 lbc->lsdmr = lsdmr_common | LSDMR_OP_PCHALL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500179 asm("sync");
180 *sdram_addr = 0xff;
181 udelay(100);
182
Mario Sixdc003002019-01-21 09:18:17 +0100183 /* 0x48636733; auto refresh */
184 lbc->lsdmr = lsdmr_common | LSDMR_OP_ARFRSH;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500185 asm("sync");
186 /*1 times*/
187 *sdram_addr = 0xff;
188 udelay(100);
189 /*2 times*/
190 *sdram_addr = 0xff;
191 udelay(100);
192 /*3 times*/
193 *sdram_addr = 0xff;
194 udelay(100);
195 /*4 times*/
196 *sdram_addr = 0xff;
197 udelay(100);
198 /*5 times*/
199 *sdram_addr = 0xff;
200 udelay(100);
201 /*6 times*/
202 *sdram_addr = 0xff;
203 udelay(100);
204 /*7 times*/
205 *sdram_addr = 0xff;
206 udelay(100);
207 /*8 times*/
208 *sdram_addr = 0xff;
209 udelay(100);
210
211 /* 0x58636733; mode register write operation */
Mario Sixdc003002019-01-21 09:18:17 +0100212 lbc->lsdmr = lsdmr_common | LSDMR_OP_MRW;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500213 asm("sync");
214 *sdram_addr = 0xff;
215 udelay(100);
216
Mario Sixdc003002019-01-21 09:18:17 +0100217 /* 0x40636733; normal operation */
218 lbc->lsdmr = lsdmr_common | LSDMR_OP_NORMAL;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500219 asm("sync");
220 *sdram_addr = 0xff;
221 udelay(100);
222}
223#else
224void sdram_init(void)
225{
226 puts(" SDRAM on Local Bus: Disabled in config\n");
227}
228#endif
229
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500230#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600231int ft_board_setup(void *blob, bd_t *bd)
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500232{
Paul Gortmaker7b668d42007-12-20 12:58:16 -0500233 ft_cpu_setup(blob, bd);
234#ifdef CONFIG_PCI
235 ft_pci_setup(blob, bd);
236#endif
Simon Glass2aec3cc2014-10-23 18:58:47 -0600237
238 return 0;
Paul Gortmaker2bd9f1b2007-01-16 11:38:14 -0500239}
240#endif