Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2004 |
| 6 | * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com. |
| 7 | * |
| 8 | * (C) Copyright 2006 |
| 9 | * Eric Schumann, Phytec Messtechnik GmbH |
| 10 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <mpc5xxx.h> |
| 16 | #include <pci.h> |
Peter Tyser | 133c0fe | 2010-04-12 22:28:07 -0500 | [diff] [blame] | 17 | #include <asm/io.h> |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 18 | |
| 19 | #include "mt46v32m16-75.h" |
| 20 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 21 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 23 | #ifndef CONFIG_SYS_RAMBOOT |
| 24 | static void sdram_start(int hi_addr) |
| 25 | { |
| 26 | volatile struct mpc5xxx_cdm *cdm = |
| 27 | (struct mpc5xxx_cdm *)MPC5XXX_CDM; |
| 28 | volatile struct mpc5xxx_sdram *sdram = |
| 29 | (struct mpc5xxx_sdram *)MPC5XXX_SDRAM; |
| 30 | |
| 31 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 32 | |
| 33 | /* unlock mode register */ |
| 34 | out_be32 (&sdram->ctrl, |
| 35 | (SDRAM_CONTROL | 0x80000000 | hi_addr_bit)); |
| 36 | |
| 37 | /* precharge all banks */ |
| 38 | out_be32 (&sdram->ctrl, |
| 39 | (SDRAM_CONTROL | 0x80000002 | hi_addr_bit)); |
| 40 | |
| 41 | #ifdef SDRAM_DDR |
| 42 | /* set mode register: extended mode */ |
| 43 | out_be32 (&sdram->mode, (SDRAM_EMODE)); |
| 44 | |
| 45 | /* set mode register: reset DLL */ |
| 46 | out_be32 (&sdram->mode, |
| 47 | (SDRAM_MODE | 0x04000000)); |
| 48 | #endif |
| 49 | |
| 50 | /* precharge all banks */ |
| 51 | out_be32 (&sdram->ctrl, |
| 52 | (SDRAM_CONTROL | 0x80000002 | hi_addr_bit)); |
| 53 | |
| 54 | /* auto refresh */ |
| 55 | out_be32 (&sdram->ctrl, |
| 56 | (SDRAM_CONTROL | 0x80000004 | hi_addr_bit)); |
| 57 | |
| 58 | /* set mode register */ |
| 59 | out_be32 (&sdram->mode, (SDRAM_MODE)); |
| 60 | |
| 61 | /* normal operation */ |
| 62 | out_be32 (&sdram->ctrl, |
| 63 | (SDRAM_CONTROL | hi_addr_bit)); |
| 64 | |
| 65 | /* set CDM clock enable register, set MPC5200B SDRAM bus */ |
| 66 | /* to reduced driver strength */ |
| 67 | out_be32 (&cdm->clock_enable, (0x00CFFFFF)); |
| 68 | } |
| 69 | #endif |
| 70 | |
| 71 | /* |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 72 | * ATTENTION: Although partially referenced dram_init does NOT make |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 73 | * real use of CONFIG_SYS_SDRAM_BASE. The code does not |
| 74 | * work if CONFIG_SYS_SDRAM_BASE |
| 75 | * is something else than 0x00000000. |
| 76 | */ |
| 77 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 78 | int dram_init(void) |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 79 | { |
| 80 | volatile struct mpc5xxx_mmap_ctl *mm = |
| 81 | (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR; |
| 82 | volatile struct mpc5xxx_cdm *cdm = |
| 83 | (struct mpc5xxx_cdm *)MPC5XXX_CDM; |
| 84 | volatile struct mpc5xxx_sdram *sdram = |
| 85 | (struct mpc5xxx_sdram *)MPC5XXX_SDRAM; |
| 86 | ulong dramsize = 0; |
| 87 | ulong dramsize2 = 0; |
| 88 | #ifndef CONFIG_SYS_RAMBOOT |
| 89 | ulong test1, test2; |
| 90 | |
| 91 | /* setup SDRAM chip selects */ |
| 92 | /* 256MB at 0x0 */ |
| 93 | out_be32 (&mm->sdram0, 0x0000001b); |
| 94 | /* disabled */ |
| 95 | out_be32 (&mm->sdram1, 0x10000000); |
| 96 | |
| 97 | /* setup config registers */ |
| 98 | out_be32 (&sdram->config1, SDRAM_CONFIG1); |
| 99 | out_be32 (&sdram->config2, SDRAM_CONFIG2); |
| 100 | |
| 101 | #if defined(SDRAM_DDR) && defined(SDRAM_TAPDELAY) |
| 102 | /* set tap delay */ |
| 103 | out_be32 (&cdm->porcfg, SDRAM_TAPDELAY); |
| 104 | #endif |
| 105 | |
| 106 | /* find RAM size using SDRAM CS0 only */ |
| 107 | sdram_start(0); |
| 108 | test1 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000); |
| 109 | sdram_start(1); |
| 110 | test2 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000); |
| 111 | if (test1 > test2) { |
| 112 | sdram_start(0); |
| 113 | dramsize = test1; |
| 114 | } else |
| 115 | dramsize = test2; |
| 116 | |
| 117 | /* memory smaller than 1MB is impossible */ |
| 118 | if (dramsize < (1 << 20)) |
| 119 | dramsize = 0; |
| 120 | |
| 121 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 122 | if (dramsize > 0) { |
| 123 | out_be32 (&mm->sdram0, |
| 124 | (0x13 + __builtin_ffs(dramsize >> 20) - 1)); |
| 125 | } else { |
| 126 | /* disabled */ |
| 127 | out_be32 (&mm->sdram0, 0); |
| 128 | } |
| 129 | |
| 130 | #else /* CONFIG_SYS_RAMBOOT */ |
| 131 | |
| 132 | /* retrieve size of memory connected to SDRAM CS0 */ |
| 133 | dramsize = in_be32(&mm->sdram0) & 0xFF; |
| 134 | if (dramsize >= 0x13) |
| 135 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 136 | else |
| 137 | dramsize = 0; |
| 138 | |
| 139 | /* retrieve size of memory connected to SDRAM CS1 */ |
| 140 | dramsize2 = in_be32(&mm->sdram1) & 0xFF; |
| 141 | if (dramsize2 >= 0x13) |
| 142 | dramsize2 = (1 << (dramsize2 - 0x13)) << 20; |
| 143 | else |
| 144 | dramsize2 = 0; |
| 145 | |
| 146 | #endif /* CONFIG_SYS_RAMBOOT */ |
| 147 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 148 | gd->ram_size = dramsize + dramsize2; |
| 149 | |
| 150 | return 0; |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | int checkboard(void) |
| 154 | { |
| 155 | puts("Board: phyCORE-MPC5200B-tiny\n"); |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | #ifdef CONFIG_PCI |
| 160 | static struct pci_controller hose; |
| 161 | |
| 162 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 163 | |
| 164 | void pci_init_board(void) |
| 165 | { |
| 166 | pci_mpc5xxx_init(&hose); |
| 167 | } |
| 168 | #endif |
| 169 | |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 170 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 171 | int ft_board_setup(void *blob, bd_t *bd) |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 172 | { |
| 173 | ft_cpu_setup(blob, bd); |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 174 | |
| 175 | return 0; |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 176 | } |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 177 | #endif /* CONFIG_OF_BOARD_SETUP */ |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 178 | |
Simon Glass | b569a01 | 2017-05-17 03:25:30 -0600 | [diff] [blame] | 179 | #if defined(CONFIG_IDE) && defined(CONFIG_IDE_RESET) |
Jon Smirl | bc03df9 | 2009-06-14 18:21:28 -0400 | [diff] [blame] | 180 | |
| 181 | #define GPIO_PSC2_4 0x02000000UL |
| 182 | |
| 183 | void init_ide_reset(void) |
| 184 | { |
| 185 | volatile struct mpc5xxx_wu_gpio *wu_gpio = |
| 186 | (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO; |
| 187 | debug("init_ide_reset\n"); |
| 188 | |
| 189 | /* Configure PSC2_4 as GPIO output for ATA reset */ |
| 190 | setbits_be32(&wu_gpio->enable, GPIO_PSC2_4); |
| 191 | setbits_be32(&wu_gpio->ddr, GPIO_PSC2_4); |
| 192 | /* Deassert reset */ |
| 193 | setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4); |
| 194 | } |
| 195 | |
| 196 | void ide_set_reset(int idereset) |
| 197 | { |
| 198 | volatile struct mpc5xxx_wu_gpio *wu_gpio = |
| 199 | (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO; |
| 200 | debug("ide_reset(%d)\n", idereset); |
| 201 | |
| 202 | if (idereset) { |
| 203 | clrbits_be32(&wu_gpio->dvo, GPIO_PSC2_4); |
| 204 | /* Make a delay. MPC5200 spec says 25 usec min */ |
| 205 | udelay(500000); |
| 206 | } else |
| 207 | setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4); |
| 208 | } |
Simon Glass | b569a01 | 2017-05-17 03:25:30 -0600 | [diff] [blame] | 209 | #endif /* defined(CONFIG_IDE) && defined(CONFIG_IDE_RESET) */ |