blob: ceb3d755522deea02f9cdb3c50bcba81509e3346 [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>
Simon Glassc05ed002020-05-10 11:40:11 -060014#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090015#include <linux/libfdt.h>
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020016#include <pci.h>
17#include <mpc83xx.h>
18#include <ns16550.h>
19#include <nand.h>
20
21#include <asm/bitops.h>
22#include <asm/io.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26extern void disable_addr_trans (void);
27extern void enable_addr_trans (void);
28
29int checkboard(void)
30{
31 puts("Board: ve8313\n");
32 return 0;
33}
34
35static long fixed_sdram(void)
36{
37 u32 msize = CONFIG_SYS_DDR_SIZE * 1024 * 1024;
38
39#ifndef CONFIG_SYS_RAMBOOT
40 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
41 u32 msize_log2 = __ilog2(msize);
42
43 out_be32(&im->sysconf.ddrlaw[0].bar,
Mario Six133ec602019-01-21 09:18:16 +010044 (CONFIG_SYS_SDRAM_BASE & 0xfffff000));
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020045 out_be32(&im->sysconf.ddrlaw[0].ar, (LBLAWAR_EN | (msize_log2 - 1)));
46 out_be32(&im->sysconf.ddrcdr, CONFIG_SYS_DDRCDR_VALUE);
47
48 /*
49 * Erratum DDR3 requires a 50ms delay after clearing DDRCDR[DDR_cfg],
50 * or the DDR2 controller may fail to initialize correctly.
51 */
52 __udelay(50000);
53
Mario Six133ec602019-01-21 09:18:16 +010054#if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0)
Joe Hershberger2e651b22011-10-11 23:57:31 -050055#warning Chip select bounds is only configurable in 16MB increments
56#endif
57 out_be32(&im->ddr.csbnds[0].csbnds,
Mario Six133ec602019-01-21 09:18:16 +010058 ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) |
59 (((CONFIG_SYS_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) &
Joe Hershberger2e651b22011-10-11 23:57:31 -050060 CSBNDS_EA));
61 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020062
63 /* Currently we use only one CS, so disable the other bank. */
64 out_be32(&im->ddr.cs_config[1], 0);
65
66 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
67 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
68 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
69 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
70 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
71
72 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_SDRAM_CFG);
73
74 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_SDRAM_CFG2);
75 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
76 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE_2);
77
78 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
79 sync();
80
81 /* enable DDR controller */
82 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
83
84 /* now check the real size */
85 disable_addr_trans ();
Simon Glass9b4a2052019-12-28 10:45:05 -070086 msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020087 enable_addr_trans ();
88#endif
89
90 return msize;
91}
92
Simon Glassf1683aa2017-04-06 12:47:05 -060093int dram_init(void)
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020094{
95 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
Kumar Galaa2243b82010-08-19 01:48:14 -050096 volatile fsl_lbc_t *lbc = &im->im_lbc;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +020097 u32 msize;
98
99 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
100 return -1;
101
102 /* DDR SDRAM - Main SODIMM */
103 msize = fixed_sdram();
104
105 /* Local Bus setup lbcr and mrtpr */
Mario Six42c9a492019-01-21 09:18:17 +0100106 out_be32(&lbc->lbcr, 0x00040000);
107 out_be32(&lbc->mrtpr, 0x20000000);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200108 sync();
109
110 /* return total bus SDRAM size(bytes) -- DDR */
Simon Glass088454c2017-03-31 08:40:25 -0600111 gd->ram_size = msize;
112
113 return 0;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200114}
115
116#define VE8313_WDT_EN 0x00020000
117#define VE8313_WDT_TRIG 0x00040000
118
119int board_early_init_f (void)
120{
121 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
122 volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
123
124#if defined(CONFIG_HW_WATCHDOG)
125 /* enable WDT */
126 clrbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
127#else
128 /* disable WDT */
129 setbits_be32(&gpio->dat, VE8313_WDT_EN | VE8313_WDT_TRIG);
130#endif
131 /* set WDT pins as output */
132 setbits_be32(&gpio->dir, VE8313_WDT_EN | VE8313_WDT_TRIG);
133
134 return 0;
135}
136
137#if defined(CONFIG_HW_WATCHDOG)
138void hw_watchdog_reset(void)
139{
140 volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR;
141 volatile gpio83xx_t *gpio = (volatile gpio83xx_t *)im->gpio;
142 unsigned long reg;
143
144 reg = in_be32(&gpio->dat);
145 if (reg & VE8313_WDT_TRIG)
146 clrbits_be32(&gpio->dat, VE8313_WDT_TRIG);
147 else
148 setbits_be32(&gpio->dat, VE8313_WDT_TRIG);
149}
150#endif
151
152
153#if defined(CONFIG_PCI)
154static struct pci_region pci_regions[] = {
155 {
156 bus_start: CONFIG_SYS_PCI1_MEM_BASE,
157 phys_start: CONFIG_SYS_PCI1_MEM_PHYS,
158 size: CONFIG_SYS_PCI1_MEM_SIZE,
159 flags: PCI_REGION_MEM | PCI_REGION_PREFETCH
160 },
161 {
162 bus_start: CONFIG_SYS_PCI1_MMIO_BASE,
163 phys_start: CONFIG_SYS_PCI1_MMIO_PHYS,
164 size: CONFIG_SYS_PCI1_MMIO_SIZE,
165 flags: PCI_REGION_MEM
166 },
167 {
168 bus_start: CONFIG_SYS_PCI1_IO_BASE,
169 phys_start: CONFIG_SYS_PCI1_IO_PHYS,
170 size: CONFIG_SYS_PCI1_IO_SIZE,
171 flags: PCI_REGION_IO
172 }
173};
174
175void pci_init_board(void)
176{
177 volatile immap_t *immr = (volatile immap_t *)CONFIG_SYS_IMMR;
178 volatile clk83xx_t *clk = (volatile clk83xx_t *)&immr->clk;
179 volatile law83xx_t *pci_law = immr->sysconf.pcilaw;
180 struct pci_region *reg[] = { pci_regions };
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200181
182 /* Enable all 3 PCI_CLK_OUTPUTs. */
183 setbits_be32(&clk->occr, 0xe0000000);
184
185 /*
186 * Configure PCI Local Access Windows
187 */
188 out_be32(&pci_law[0].bar, CONFIG_SYS_PCI1_MEM_PHYS & LAWBAR_BAR);
189 out_be32(&pci_law[0].ar, LBLAWAR_EN | LBLAWAR_512MB);
190
191 out_be32(&pci_law[1].bar, CONFIG_SYS_PCI1_IO_PHYS & LAWBAR_BAR);
192 out_be32(&pci_law[1].ar, LBLAWAR_EN | LBLAWAR_1MB);
193
Peter Tyser6aa3d3b2010-09-14 19:13:50 -0500194 mpc83xx_pci_init(1, reg);
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200195}
196#endif
197
198#if defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600199int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200200{
201 ft_cpu_setup(blob, bd);
202#ifdef CONFIG_PCI
203 ft_pci_setup(blob, bd);
204#endif
Simon Glasse895a4b2014-10-23 18:58:47 -0600205
206 return 0;
Heiko Schocher4e43b2e2010-07-07 12:26:34 +0200207}
208#endif