wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 1 | /* |
Detlev Zundel | 27e2e47 | 2009-03-30 00:31:34 +0200 | [diff] [blame] | 2 | * (C) Copyright 2008-2009 |
| 3 | * Andreas Pfefferle, DENX Software Engineering, ap@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2009 |
| 6 | * Detlev Zundel, DENX Software Engineering, dzu@denx.de. |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 7 | * |
| 8 | * (C) Copyright 2004 |
| 9 | * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com. |
| 10 | * |
| 11 | * (C) Copyright 2004 |
| 12 | * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de |
| 13 | * |
Detlev Zundel | 27e2e47 | 2009-03-30 00:31:34 +0200 | [diff] [blame] | 14 | * (C) Copyright 2003-2004 |
| 15 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 16 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 17 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Detlev Zundel | 6906496 | 2009-03-30 00:31:35 +0200 | [diff] [blame] | 20 | #include <asm/io.h> |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 21 | #include <common.h> |
| 22 | #include <mpc5xxx.h> |
| 23 | #include <pci.h> |
| 24 | |
Marian Balakowicz | 209d513 | 2007-11-15 13:29:55 +0100 | [diff] [blame] | 25 | #if defined(CONFIG_DDR_MT46V16M16) |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 26 | #include "mt46v16m16-75.h" |
Marian Balakowicz | 209d513 | 2007-11-15 13:29:55 +0100 | [diff] [blame] | 27 | #elif defined(CONFIG_SDR_MT48LC16M16A2) |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 28 | #include "mt48lc16m16a2-75.h" |
Marian Balakowicz | 209d513 | 2007-11-15 13:29:55 +0100 | [diff] [blame] | 29 | #elif defined(CONFIG_DDR_MT46V32M16) |
| 30 | #include "mt46v32m16.h" |
| 31 | #elif defined(CONFIG_DDR_HYB25D512160BF) |
| 32 | #include "hyb25d512160bf.h" |
| 33 | #elif defined(CONFIG_DDR_K4H511638C) |
| 34 | #include "k4h511638c.h" |
| 35 | #else |
| 36 | #error "INKA4x0 SDRAM: invalid chip type specified!" |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 39 | #ifndef CONFIG_SYS_RAMBOOT |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 40 | static void sdram_start (int hi_addr) |
| 41 | { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 42 | volatile struct mpc5xxx_sdram *sdram = |
| 43 | (struct mpc5xxx_sdram *)MPC5XXX_SDRAM; |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 44 | long hi_addr_bit = hi_addr ? 0x01000000 : 0; |
| 45 | |
| 46 | /* unlock mode register */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 47 | out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000000 | hi_addr_bit); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 48 | |
| 49 | /* precharge all banks */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 50 | out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 51 | |
| 52 | #if SDRAM_DDR |
| 53 | /* set mode register: extended mode */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 54 | out_be32(&sdram->mode, SDRAM_EMODE); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 55 | |
| 56 | /* set mode register: reset DLL */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 57 | out_be32(&sdram->mode, SDRAM_MODE | 0x04000000); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 58 | #endif |
| 59 | |
| 60 | /* precharge all banks */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 61 | out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 62 | |
| 63 | /* auto refresh */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 64 | out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000004 | hi_addr_bit); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 65 | |
| 66 | /* set mode register */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 67 | out_be32(&sdram->mode, SDRAM_MODE); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 68 | |
| 69 | /* normal operation */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 70 | out_be32(&sdram->ctrl, SDRAM_CONTROL | hi_addr_bit); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 71 | } |
| 72 | #endif |
| 73 | |
| 74 | /* |
| 75 | * ATTENTION: Although partially referenced initdram does NOT make real use |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 76 | * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 77 | * is something else than 0x00000000. |
| 78 | */ |
| 79 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 80 | phys_size_t initdram (int board_type) |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 81 | { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 82 | volatile struct mpc5xxx_mmap_ctl *mm = |
| 83 | (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR; |
| 84 | volatile struct mpc5xxx_cdm *cdm = |
| 85 | (struct mpc5xxx_cdm *) MPC5XXX_CDM; |
| 86 | volatile struct mpc5xxx_sdram *sdram = |
| 87 | (struct mpc5xxx_sdram *) MPC5XXX_SDRAM; |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 88 | ulong dramsize = 0; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | #ifndef CONFIG_SYS_RAMBOOT |
Marian Balakowicz | 8cfe7a8 | 2007-11-15 13:24:43 +0100 | [diff] [blame] | 90 | long test1, test2; |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 91 | |
| 92 | /* setup SDRAM chip selects */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 93 | out_be32(&mm->sdram0, 0x0000001c); /* 512MB at 0x0 */ |
| 94 | out_be32(&mm->sdram1, 0x40000000); /* disabled */ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 95 | |
| 96 | /* setup config registers */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 97 | out_be32(&sdram->config1, SDRAM_CONFIG1); |
| 98 | out_be32(&sdram->config2, SDRAM_CONFIG2); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 99 | |
| 100 | #if SDRAM_DDR |
| 101 | /* set tap delay */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 102 | out_be32(&cdm->porcfg, SDRAM_TAPDELAY); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
| 105 | /* find RAM size using SDRAM CS0 only */ |
| 106 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 108 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 109 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 110 | if (test1 > test2) { |
| 111 | sdram_start(0); |
| 112 | dramsize = test1; |
| 113 | } else { |
| 114 | dramsize = test2; |
| 115 | } |
| 116 | |
| 117 | /* memory smaller than 1MB is impossible */ |
| 118 | if (dramsize < (1 << 20)) { |
| 119 | dramsize = 0; |
| 120 | } |
| 121 | |
| 122 | /* set SDRAM CS0 size according to the amount of RAM found */ |
| 123 | if (dramsize > 0) { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 124 | out_be32(&mm->sdram0, 0x13 + |
| 125 | __builtin_ffs(dramsize >> 20) - 1); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 126 | } else { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 127 | out_be32(&mm->sdram0, 0); /* disabled */ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 130 | out_be32(&mm->sdram1, dramsize); /* disabled */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | #else /* CONFIG_SYS_RAMBOOT */ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 132 | |
| 133 | /* retrieve size of memory connected to SDRAM CS0 */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 134 | dramsize = in_be32(&mm->sdram0) & 0xFF; |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 135 | if (dramsize >= 0x13) { |
| 136 | dramsize = (1 << (dramsize - 0x13)) << 20; |
| 137 | } else { |
| 138 | dramsize = 0; |
| 139 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 140 | #endif /* CONFIG_SYS_RAMBOOT */ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 141 | |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 142 | return dramsize; |
| 143 | } |
| 144 | |
| 145 | int checkboard (void) |
| 146 | { |
wdenk | 7f5ad44 | 2004-12-19 21:39:27 +0000 | [diff] [blame] | 147 | puts ("Board: INKA 4X0\n"); |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | void flash_preinit(void) |
| 152 | { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 153 | volatile struct mpc5xxx_lpb *lpb = (struct mpc5xxx_lpb *)MPC5XXX_LPB; |
| 154 | |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 155 | /* |
| 156 | * Now, when we are in RAM, enable flash write |
| 157 | * access for detection process. |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 158 | * Note that CS_BOOT (CS0) cannot be cleared when |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 159 | * executing in flash. |
| 160 | */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 161 | clrbits_be32(&lpb->cs0_cfg, 0x1); /* clear RO */ |
wdenk | 4ca3236 | 2004-12-16 15:52:40 +0000 | [diff] [blame] | 162 | } |
wdenk | 8141446 | 2005-01-31 22:09:11 +0000 | [diff] [blame] | 163 | |
wdenk | 99408ba | 2005-02-24 22:44:16 +0000 | [diff] [blame] | 164 | int misc_init_f (void) |
| 165 | { |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 166 | volatile struct mpc5xxx_gpio *gpio = |
| 167 | (struct mpc5xxx_gpio *) MPC5XXX_GPIO; |
| 168 | volatile struct mpc5xxx_wu_gpio *wu_gpio = |
| 169 | (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO; |
| 170 | volatile struct mpc5xxx_gpt *gpt; |
Marian Balakowicz | 8cfe7a8 | 2007-11-15 13:24:43 +0100 | [diff] [blame] | 171 | char tmp[10]; |
wdenk | f189a0d | 2005-03-14 13:14:58 +0000 | [diff] [blame] | 172 | int i, br; |
| 173 | |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 174 | i = getenv_f("brightness", tmp, sizeof(tmp)); |
wdenk | f189a0d | 2005-03-14 13:14:58 +0000 | [diff] [blame] | 175 | br = (i > 0) |
| 176 | ? (int) simple_strtoul (tmp, NULL, 10) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 177 | : CONFIG_SYS_BRIGHTNESS; |
wdenk | f189a0d | 2005-03-14 13:14:58 +0000 | [diff] [blame] | 178 | if (br > 255) |
| 179 | br = 255; |
| 180 | |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 181 | /* Initialize GPIO output pins. |
| 182 | */ |
wdenk | a2b932d | 2005-06-27 13:30:03 +0000 | [diff] [blame] | 183 | /* Configure GPT as GPIO output (and set them as they control low-active LEDs */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 184 | for (i = 0; i <= 5; i++) { |
| 185 | gpt = (struct mpc5xxx_gpt *)(MPC5XXX_GPT + (i * 0x10)); |
| 186 | out_be32(&gpt->emsr, 0x34); |
| 187 | } |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 188 | |
wdenk | f189a0d | 2005-03-14 13:14:58 +0000 | [diff] [blame] | 189 | /* Configure GPT7 as PWM timer, 1kHz, no ints. */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 190 | gpt = (struct mpc5xxx_gpt *)(MPC5XXX_GPT + (7 * 0x10)); |
| 191 | out_be32(&gpt->emsr, 0); /* Disable */ |
| 192 | out_be32(&gpt->cir, 0x020000fe); |
| 193 | out_be32(&gpt->pwmcr, (br << 16)); |
| 194 | out_be32(&gpt->emsr, 0x3); /* Enable PWM mode and start */ |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 195 | |
| 196 | /* Configure PSC3_6,7 as GPIO output */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 197 | setbits_be32(&gpio->simple_gpioe, MPC5XXX_GPIO_SIMPLE_PSC3_6 | |
| 198 | MPC5XXX_GPIO_SIMPLE_PSC3_7); |
| 199 | setbits_be32(&gpio->simple_ddr, MPC5XXX_GPIO_SIMPLE_PSC3_6 | |
| 200 | MPC5XXX_GPIO_SIMPLE_PSC3_7); |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 201 | |
| 202 | /* Configure PSC3_9 and GPIO_WKUP6,7 as GPIO output */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 203 | setbits_8(&wu_gpio->enable, MPC5XXX_GPIO_WKUP_6 | |
| 204 | MPC5XXX_GPIO_WKUP_7 | |
| 205 | MPC5XXX_GPIO_WKUP_PSC3_9); |
| 206 | setbits_8(&wu_gpio->ddr, MPC5XXX_GPIO_WKUP_6 | |
| 207 | MPC5XXX_GPIO_WKUP_7 | |
| 208 | MPC5XXX_GPIO_WKUP_PSC3_9); |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 209 | |
wdenk | a2b932d | 2005-06-27 13:30:03 +0000 | [diff] [blame] | 210 | /* Set LR mirror bit because it is low-active */ |
Detlev Zundel | af771d1 | 2009-03-30 00:31:36 +0200 | [diff] [blame] | 211 | setbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_7); |
| 212 | |
| 213 | /* Reset Coral-P graphics controller */ |
| 214 | setbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_PSC3_9); |
| 215 | |
| 216 | /* Enable display backlight */ |
| 217 | clrbits_8(&gpio->sint_inten, MPC5XXX_GPIO_SINT_PSC3_8); |
| 218 | setbits_8(&gpio->sint_gpioe, MPC5XXX_GPIO_SINT_PSC3_8); |
| 219 | setbits_8(&gpio->sint_ddr, MPC5XXX_GPIO_SINT_PSC3_8); |
| 220 | setbits_8(&gpio->sint_dvo, MPC5XXX_GPIO_SINT_PSC3_8); |
Detlev Zundel | 6906496 | 2009-03-30 00:31:35 +0200 | [diff] [blame] | 221 | |
| 222 | /* |
| 223 | * Configure three wire serial interface to RTC (PSC1_4, |
| 224 | * PSC2_4, PSC3_4, PSC3_5) |
| 225 | */ |
| 226 | setbits_8(&wu_gpio->enable, MPC5XXX_GPIO_WKUP_PSC1_4 | |
| 227 | MPC5XXX_GPIO_WKUP_PSC2_4); |
| 228 | setbits_8(&wu_gpio->ddr, MPC5XXX_GPIO_WKUP_PSC1_4 | |
| 229 | MPC5XXX_GPIO_WKUP_PSC2_4); |
| 230 | clrbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_PSC1_4); |
| 231 | clrbits_8(&gpio->sint_inten, MPC5XXX_GPIO_SINT_PSC3_4 | |
| 232 | MPC5XXX_GPIO_SINT_PSC3_5); |
| 233 | setbits_8(&gpio->sint_gpioe, MPC5XXX_GPIO_SINT_PSC3_4 | |
| 234 | MPC5XXX_GPIO_SINT_PSC3_5); |
| 235 | setbits_8(&gpio->sint_ddr, MPC5XXX_GPIO_SINT_PSC3_5); |
| 236 | clrbits_8(&gpio->sint_dvo, MPC5XXX_GPIO_SINT_PSC3_5); |
| 237 | |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 238 | return 0; |
wdenk | 99408ba | 2005-02-24 22:44:16 +0000 | [diff] [blame] | 239 | } |
| 240 | |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 241 | #ifdef CONFIG_PCI |
wdenk | 8141446 | 2005-01-31 22:09:11 +0000 | [diff] [blame] | 242 | static struct pci_controller hose; |
| 243 | |
| 244 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 245 | |
| 246 | void pci_init_board(void) |
| 247 | { |
wdenk | b995b0f | 2005-03-06 01:21:30 +0000 | [diff] [blame] | 248 | pci_mpc5xxx_init(&hose); |
wdenk | 8141446 | 2005-01-31 22:09:11 +0000 | [diff] [blame] | 249 | } |
| 250 | #endif |