Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heiko Schocher | 4e43b2e | 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 | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | 807765b | 2019-12-28 10:44:54 -0700 | [diff] [blame] | 12 | #include <fdt_support.h> |
Simon Glass | 2cf431c | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 13 | #include <init.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 14 | #include <linux/delay.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 15 | #include <linux/libfdt.h> |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 16 | #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 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | extern void disable_addr_trans (void); |
| 27 | extern void enable_addr_trans (void); |
| 28 | |
| 29 | int checkboard(void) |
| 30 | { |
| 31 | puts("Board: ve8313\n"); |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | static 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 Six | 133ec60 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 44 | (CONFIG_SYS_SDRAM_BASE & 0xfffff000)); |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 45 | 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 Six | 133ec60 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 54 | #if ((CONFIG_SYS_SDRAM_BASE & 0x00FFFFFF) != 0) |
Joe Hershberger | 2e651b2 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 55 | #warning Chip select bounds is only configurable in 16MB increments |
| 56 | #endif |
| 57 | out_be32(&im->ddr.csbnds[0].csbnds, |
Mario Six | 133ec60 | 2019-01-21 09:18:16 +0100 | [diff] [blame] | 58 | ((CONFIG_SYS_SDRAM_BASE >> CSBNDS_SA_SHIFT) & CSBNDS_SA) | |
| 59 | (((CONFIG_SYS_SDRAM_BASE + msize - 1) >> CSBNDS_EA_SHIFT) & |
Joe Hershberger | 2e651b2 | 2011-10-11 23:57:31 -0500 | [diff] [blame] | 60 | CSBNDS_EA)); |
| 61 | out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG); |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 62 | |
| 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 Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 86 | msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize); |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 87 | enable_addr_trans (); |
| 88 | #endif |
| 89 | |
| 90 | return msize; |
| 91 | } |
| 92 | |
Simon Glass | f1683aa | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 93 | int dram_init(void) |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 94 | { |
| 95 | volatile immap_t *im = (volatile immap_t *)CONFIG_SYS_IMMR; |
Kumar Gala | a2243b8 | 2010-08-19 01:48:14 -0500 | [diff] [blame] | 96 | volatile fsl_lbc_t *lbc = &im->im_lbc; |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 97 | 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 Six | 42c9a49 | 2019-01-21 09:18:17 +0100 | [diff] [blame] | 106 | out_be32(&lbc->lbcr, 0x00040000); |
| 107 | out_be32(&lbc->mrtpr, 0x20000000); |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 108 | sync(); |
| 109 | |
| 110 | /* return total bus SDRAM size(bytes) -- DDR */ |
Simon Glass | 088454c | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 111 | gd->ram_size = msize; |
| 112 | |
| 113 | return 0; |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | #define VE8313_WDT_EN 0x00020000 |
| 117 | #define VE8313_WDT_TRIG 0x00040000 |
| 118 | |
| 119 | int 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) |
| 138 | void 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) |
| 154 | static 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 | |
| 175 | void 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 Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 181 | |
| 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 Tyser | 6aa3d3b | 2010-09-14 19:13:50 -0500 | [diff] [blame] | 194 | mpc83xx_pci_init(1, reg); |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 195 | } |
| 196 | #endif |
| 197 | |
| 198 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | b75d8dc | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 199 | int ft_board_setup(void *blob, struct bd_info *bd) |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 200 | { |
| 201 | ft_cpu_setup(blob, bd); |
| 202 | #ifdef CONFIG_PCI |
| 203 | ft_pci_setup(blob, bd); |
| 204 | #endif |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 205 | |
| 206 | return 0; |
Heiko Schocher | 4e43b2e | 2010-07-07 12:26:34 +0200 | [diff] [blame] | 207 | } |
| 208 | #endif |