Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 2 | /* |
| 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 Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | 3bbe70c | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 12 | #include <fdt_support.h> |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 13 | #include <init.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 14 | #include <linux/libfdt.h> |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 15 | #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 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | extern void disable_addr_trans (void); |
| 26 | extern void enable_addr_trans (void); |
| 27 | |
| 28 | int checkboard(void) |
| 29 | { |
| 30 | puts("Board: ve8313\n"); |
| 31 | return 0; |
| 32 | } |
| 33 | |
| 34 | static 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 Six | 805cac1 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 43 | (CONFIG_SYS_SDRAM_BASE & 0xfffff000)); |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 44 | 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 Six | 805cac1 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 53 | #if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0) |
Joe Hershberger | 5ade390 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 54 | #warning Chip select bounds is only configurable in 16MB increments |
| 55 | #endif |
| 56 | out_be32(&im->ddr.csbnds[0].csbnds, |
Mario Six | 805cac1 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 57 | ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) | |
| 58 | (((CONFIG_SYS_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) & |
Joe Hershberger | 5ade390 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 59 | CSBNDS_EA)); |
| 60 | out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG); |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 61 | |
| 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 Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 85 | msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize); |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 86 | enable_addr_trans (); |
| 87 | #endif |
| 88 | |
| 89 | return msize; |
| 90 | } |
| 91 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 92 | int dram_init(void) |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 93 | { |
| 94 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
Kumar Gala | 0d555f0 | 2010-08-19 01:48:14 -0500 | [diff] [blame] | 95 | volatile fsl_lbc_t *lbc = &im->im_lbc; |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 96 | 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 Six | dc00300 | 2019-01-21 09:18:17 +0100 | [diff] [blame] | 105 | out_be32(&lbc->lbcr, 0x00040000); |
| 106 | out_be32(&lbc->mrtpr, 0x20000000); |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 107 | sync(); |
| 108 | |
| 109 | /* return total bus SDRAM size(bytes) -- DDR */ |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 110 | gd->ram_size = msize; |
| 111 | |
| 112 | return 0; |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | #define VE8313_WDT_EN 0x00020000 |
| 116 | #define VE8313_WDT_TRIG 0x00040000 |
| 117 | |
| 118 | int 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) |
| 137 | void 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) |
| 153 | static 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 | |
| 174 | void 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 Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 180 | |
| 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 Tyser | e228332 | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 193 | mpc83xx_pci_init(1, reg); |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 194 | } |
| 195 | #endif |
| 196 | |
| 197 | #if defined(CONFIG_OF_BOARD_SETUP) |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 198 | int ft_board_setup(void *blob, bd_t *bd) |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 199 | { |
| 200 | ft_cpu_setup(blob, bd); |
| 201 | #ifdef CONFIG_PCI |
| 202 | ft_pci_setup(blob, bd); |
| 203 | #endif |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 204 | |
| 205 | return 0; |
Heiko Schocher | 147d0a2 | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 206 | } |
| 207 | #endif |