blob: d1c9535f46ead79e4f79139376cbb0a74391d199 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocher4e43b2e2010-07-07 12:26:34 +02002/*
3 * Copyright (C) Freescale Semiconductor, Inc. 2006-2007
4 *
5 * Author: Scott Wood <scottwood@freescale.com>
6 *
7 * (C) Copyright 2010
8 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
Heiko Schocher4e43b2e2010-07-07 12:26:34 +02009 */
10
11#include <common.h>
Simon Glass807765b2019-12-28 10:44:54 -070012#include <fdt_support.h>
Simon Glass2cf431c2019-11-14 12:57:47 -070013#include <init.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090014#include <linux/libfdt.h>
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020015#include <pci.h>
16#include <mpc83xx.h>
17#include <ns16550.h>
18#include <nand.h>
19
20#include <asm/bitops.h>
21#include <asm/io.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
25extern void disable_addr_trans (void);
26extern void enable_addr_trans (void);
27
28int checkboard(void)
29{
30 puts("Board: ve8313\n");
31 return 0;
32}
33
34static long fixed_sdram(void)
35{
36 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
37
38#ifndef CONFIG_SYS_RAMBOOT
39 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
40 u32 msize_log2 = __ilog2(msize);
41
42 out_be32(&im->sysconf.ddrlaw[0].bar,
Mario Six133ec602019-01-21 09:18:16 +010043 (CONFIG_SYS_SDRAM_BASE & 0xfffff000));
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020044 out_be32(&im->sysconf.ddrlaw[0].ar, (LBLAWAR_EN | (msize_log2 - 1)));
45 out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
46
47 /*
48 * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
49 * or the DDR2 controller may fail to initialize correctly.
50 */
51 __udelay(50000);
52
Mario Six133ec602019-01-21 09:18:16 +010053#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger2e651b22011-10-11 23:57:31 -050054#warning Chip select bounds is only configurable in 16MB increments
55#endif
56 out_be32(&im->ddr.csbnds[0].csbnds,
Mario Six133ec602019-01-21 09:18:16 +010057 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
58 (((CONFIG_SYS_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) &
Joe Hershberger2e651b22011-10-11 23:57:31 -050059 CSBNDS_EA));
60 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020061
62 /* Currently we use only one CS, so disable the other bank. */
63 out_be32(&im->ddr.cs_config[1], 0);
64
65 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
66 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
67 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
68 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
69 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
70
71 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_SDRAM_CFG);
72
73 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_SDRAM_CFG2);
74 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
75 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE_2);
76
77 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
78 sync();
79
80 /* enable DDR controller */
81 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
82
83 /* now check the real size */
84 disable_addr_trans ();
Simon Glass9b4a2052019-12-28 10:45:05 -070085 msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020086 enable_addr_trans ();
87#endif
88
89 return msize;
90}
91
Simon Glassf1683aa2017-04-06 12:47:05 -060092int dram_init(void)
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020093{
94 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
Kumar Galaa2243b82010-08-19 01:48:14 -050095 volatile fsl_lbc_t *lbc = &im->im_lbc;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020096 u32 msize;
97
98 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
99 return -1;
100
101 /* DDR SDRAM - Main SODIMM */
102 msize = fixed_sdram();
103
104 /* Local Bus setup lbcr and mrtpr */
Mario Six42c9a492019-01-21 09:18:17 +0100105 out_be32(&lbc->lbcr, 0x00040000);
106 out_be32(&lbc->mrtpr, 0x20000000);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200107 sync();
108
109 /* return total bus SDRAM size(bytes) -- DDR */
Simon Glass088454c2017-03-31 08:40:25 -0600110 gd->ram_size = msize;
111
112 return 0;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200113}
114
115#define VE8313_WDT_EN 0x00020000
116#define VE8313_WDT_TRIG 0x00040000
117
118int board_early_init_f (void)
119{
120 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
121 volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
122
123#if defined(CONFIG_HW_WATCHDOG)
124 /* enable WDT */
125 clrbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
126#else
127 /* disable WDT */
128 setbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
129#endif
130 /* set WDT pins as output */
131 setbits_be32(&gpio->dir, VE8313_WDT_EN | VE8313_WDT_TRIG);
132
133 return 0;
134}
135
136#if defined(CONFIG_HW_WATCHDOG)
137void hw_watchdog_reset(void)
138{
139 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
140 volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
141 unsigned long reg;
142
143 reg = in_be32(&gpio->dat);
144 if (reg & VE8313_WDT_TRIG)
145 clrbits_be32(&gpio->dat, VE8313_WDT_TRIG);
146 else
147 setbits_be32(&gpio->dat, VE8313_WDT_TRIG);
148}
149#endif
150
151
152#if defined(CONFIG_PCI)
153static struct pci_region pci_regions[] = {
154 {
155 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
156 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
157 size: CONFIG_SYS_PCI1_MEM_SIZE,
158 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
159 },
160 {
161 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
162 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
163 size: CONFIG_SYS_PCI1_MMIO_SIZE,
164 flags: PCI_REGION_MEM
165 },
166 {
167 bus_start: CONFIG_SYS_PCI1_IO_BASE,
168 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
169 size: CONFIG_SYS_PCI1_IO_SIZE,
170 flags: PCI_REGION_IO
171 }
172};
173
174void pci_init_board(void)
175{
176 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
177 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
178 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
179 struct pci_region *reg[] = { pci_regions };
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200180
181 /* Enable all 3 PCI_CLK_OUTPUTs. */
182 setbits_be32(&clk->occr, 0xe0000000);
183
184 /*
185 * Configure PCI Local Access Windows
186 */
187 out_be32(&pci_law[0].bar, CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR);
188 out_be32(&pci_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
189
190 out_be32(&pci_law[1].bar, CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR);
191 out_be32(&pci_law[1].ar, LBLAWAR_EN | LBLAWAR_1MB);
192
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500193 mpc83xx_pci_init(1, reg);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200194}
195#endif
196
197#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600198int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200199{
200 ft_cpu_setup(blob, bd);
201#ifdef CONFIG_PCI
202 ft_pci_setup(blob, bd);
203#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600204
205 return 0;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200206}
207#endif