wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2003 |
| 6 | * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de |
| 7 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
| 12 | #include <mpc5xxx.h> |
| 13 | #include <pci.h> |
| 14 | |
| 15 | /***************************************************************************** |
| 16 | * initialize SDRAM/DDRAM controller. |
| 17 | * TBD: get data from I2C EEPROM |
| 18 | *****************************************************************************/ |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 19 | phys_size_t initdram (int board_type) |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 20 | { |
| 21 | ulong dramsize = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 22 | #ifndef CONFIG_SYS_RAMBOOT |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 23 | #if 0 |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 24 | ulong t; |
| 25 | ulong tap_del; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 26 | #endif |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 27 | |
| 28 | #define MODE_EN 0x80000000 |
| 29 | #define SOFT_PRE 2 |
| 30 | #define SOFT_REF 4 |
| 31 | |
| 32 | /* configure SDRAM start/end */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 33 | *(vu_long *)MPC5XXX_SDRAM_CS0CFG = (CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | CONFIG_SYS_DRAM_RAM_SIZE; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 34 | *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */ |
| 35 | |
| 36 | /* setup config registers */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 37 | *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = CONFIG_SYS_DRAM_CONFIG1; |
| 38 | *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = CONFIG_SYS_DRAM_CONFIG2; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 39 | |
| 40 | /* unlock mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 41 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 42 | /* precharge all banks */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 43 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE; |
| 44 | #ifdef CONFIG_SYS_DRAM_DDR |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 45 | /* set extended mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_EMODE; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 47 | #endif |
| 48 | /* set mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 49 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE | 0x0400; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 50 | /* precharge all banks */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 52 | /* auto refresh */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_REF; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 54 | /* set mode register */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 56 | /* normal operation */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 57 | *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 58 | /* write default TAP delay */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | *(vu_long *)MPC5XXX_CDM_PORCFG = CONFIG_SYS_DRAM_TAP_DEL << 24; |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 60 | |
| 61 | #if 0 |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 62 | for (tap_del = 0; tap_del < 32; tap_del++) |
| 63 | { |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 64 | *(vu_long *)MPC5XXX_CDM_PORCFG = tap_del << 24; |
| 65 | |
| 66 | printf ("\nTAP Delay:%x Filling DRAM...", *(vu_long *)MPC5XXX_CDM_PORCFG); |
| 67 | for (t = 0; t < 0x04000000; t+=4) |
| 68 | *(vu_long *) t = t; |
| 69 | printf ("Checking DRAM...\n"); |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 70 | for (t = 0; t < 0x04000000; t+=4) |
| 71 | { |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 72 | ulong rval = *(vu_long *) t; |
wdenk | 1ebf41e | 2004-01-02 14:00:00 +0000 | [diff] [blame] | 73 | if (rval != t) |
| 74 | { |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 75 | printf ("mismatch at %x: ", t); |
| 76 | printf (" 1.read %x", rval); |
| 77 | printf (" 2.read %x", *(vu_long *) t); |
| 78 | printf (" 3.read %x", *(vu_long *) t); |
| 79 | break; |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | #endif |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 84 | #endif /* CONFIG_SYS_RAMBOOT */ |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 85 | |
| 86 | dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20); |
| 87 | |
| 88 | /* return total ram size */ |
| 89 | return dramsize; |
| 90 | } |
| 91 | |
| 92 | /***************************************************************************** |
| 93 | * print board identification |
| 94 | *****************************************************************************/ |
| 95 | int checkboard (void) |
| 96 | { |
| 97 | #if defined (CONFIG_EVAL5200) |
| 98 | puts ("Board: EMK TOP5200 on EVAL5200\n"); |
| 99 | #else |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 100 | #if defined (CONFIG_LITE5200) |
| 101 | puts ("Board: LITE5200\n"); |
| 102 | #else |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 103 | #if defined (CONFIG_MINI5200) |
| 104 | puts ("Board: EMK TOP5200 on MINI5200\n"); |
| 105 | #else |
| 106 | puts ("Board: EMK TOP5200\n"); |
| 107 | #endif |
| 108 | #endif |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 109 | #endif |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | /***************************************************************************** |
| 114 | * prepare for FLASH detection |
| 115 | *****************************************************************************/ |
| 116 | void flash_preinit(void) |
| 117 | { |
| 118 | /* |
| 119 | * Now, when we are in RAM, enable flash write |
| 120 | * access for detection process. |
| 121 | * Note that CS_BOOT cannot be cleared when |
| 122 | * executing in flash. |
| 123 | */ |
| 124 | *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */ |
| 125 | } |
| 126 | |
| 127 | /***************************************************************************** |
| 128 | * finalize FLASH setup |
| 129 | *****************************************************************************/ |
| 130 | void flash_afterinit(uint bank, ulong start, ulong size) |
| 131 | { |
| 132 | if (bank == 0) { /* adjust mapping */ |
| 133 | *(vu_long *)MPC5XXX_BOOTCS_START = |
| 134 | *(vu_long *)MPC5XXX_CS0_START = START_REG(start); |
| 135 | *(vu_long *)MPC5XXX_BOOTCS_STOP = |
| 136 | *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(start, size); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | /***************************************************************************** |
| 141 | * otherinits after RAM is there and we are relocated to RAM |
| 142 | * note: though this is an int function, nobody cares for the result! |
| 143 | *****************************************************************************/ |
| 144 | int misc_init_r (void) |
| 145 | { |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 146 | #if !defined (CONFIG_LITE5200) |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 147 | /* read 'factory' part of EEPROM */ |
wdenk | e97d3d9 | 2004-02-23 22:22:28 +0000 | [diff] [blame] | 148 | extern void read_factory_r (void); |
| 149 | read_factory_r (); |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 150 | #endif |
wdenk | 78e3ab3 | 2003-12-28 11:44:59 +0000 | [diff] [blame] | 151 | return (0); |
| 152 | } |
| 153 | |
| 154 | /***************************************************************************** |
| 155 | * initialize the PCI system |
| 156 | *****************************************************************************/ |
| 157 | #ifdef CONFIG_PCI |
| 158 | static struct pci_controller hose; |
| 159 | |
| 160 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 161 | |
| 162 | void pci_init_board(void) |
| 163 | { |
| 164 | pci_mpc5xxx_init(&hose); |
| 165 | } |
| 166 | #endif |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 167 | |
| 168 | /***************************************************************************** |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 169 | * provide the IDE Reset Function |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 170 | *****************************************************************************/ |
Jon Loeliger | 13f7599 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 171 | #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 172 | |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 173 | void init_ide_reset (void) |
| 174 | { |
| 175 | debug ("init_ide_reset\n"); |
| 176 | |
Wolfgang Denk | 87b3d4b | 2006-11-30 18:02:20 +0100 | [diff] [blame] | 177 | /* Configure PSC1_4 as GPIO output for ATA reset */ |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 178 | *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4; |
| 179 | *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4; |
| 180 | } |
| 181 | |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 182 | void ide_set_reset (int idereset) |
| 183 | { |
wdenk | 19c8fb7 | 2004-04-18 22:26:17 +0000 | [diff] [blame] | 184 | debug ("ide_reset(%d)\n", idereset); |
| 185 | |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 186 | if (idereset) { |
Bartlomiej Sieka | 79eecbfb | 2006-11-01 01:38:16 +0100 | [diff] [blame] | 187 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4; |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 188 | } else { |
Bartlomiej Sieka | 79eecbfb | 2006-11-01 01:38:16 +0100 | [diff] [blame] | 189 | *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4; |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 190 | } |
wdenk | 369d43d | 2004-03-14 14:09:05 +0000 | [diff] [blame] | 191 | } |
Jon Loeliger | 13f7599 | 2007-07-10 10:39:10 -0500 | [diff] [blame] | 192 | #endif |