Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 4 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 8 | /* define DEBUG for debugging output (obviously ;-)) */ |
| 9 | #if 0 |
| 10 | #define DEBUG |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 11 | #endif |
| 12 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 13 | #include <common.h> |
| 14 | #include <asm/processor.h> |
| 15 | #include <asm/io.h> |
Stefan Roese | 0988776 | 2010-09-16 14:30:37 +0200 | [diff] [blame] | 16 | #include <asm/ppc4xx-gpio.h> |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 17 | |
Stefan Roese | df8a24c | 2007-06-19 16:42:31 +0200 | [diff] [blame] | 18 | extern void board_pll_init_f(void); |
| 19 | |
Stefan Roese | c440bfe | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 20 | #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 21 | static void cram_bcr_write(u32 wr_val) |
| 22 | { |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 23 | wr_val <<= 2; |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 24 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 25 | /* set CRAM_CRE to 1 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 26 | gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 1); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 27 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 28 | /* Write BCR to CRAM on CS1 */ |
| 29 | out32(wr_val + 0x00200000, 0); |
| 30 | debug("CRAM VAL: %08x for CS1 ", wr_val + 0x00200000); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 31 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 32 | /* Write BCR to CRAM on CS2 */ |
| 33 | out32(wr_val + 0x02200000, 0); |
| 34 | debug("CRAM VAL: %08x for CS2\n", wr_val + 0x02200000); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 35 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 36 | sync(); |
| 37 | eieio(); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 38 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 39 | /* set CRAM_CRE back to 0 (normal operation) */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 40 | gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 0); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 41 | |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 42 | return; |
| 43 | } |
Stefan Roese | c440bfe | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 44 | #endif |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 45 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 46 | phys_size_t initdram(int board_type) |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 47 | { |
Stefan Roese | df8a24c | 2007-06-19 16:42:31 +0200 | [diff] [blame] | 48 | #if defined(CONFIG_NAND_SPL) |
| 49 | u32 reg; |
| 50 | |
| 51 | /* don't reinit PLL when booting via I2C bootstrap option */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 52 | mfsdr(SDR0_PINSTP, reg); |
Stefan Roese | df8a24c | 2007-06-19 16:42:31 +0200 | [diff] [blame] | 53 | if (reg != 0xf0000000) |
| 54 | board_pll_init_f(); |
| 55 | #endif |
| 56 | |
Stefan Roese | c440bfe | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 57 | #if !defined(CONFIG_NAND_U_BOOT) || defined(CONFIG_NAND_SPL) |
| 58 | int i; |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 59 | u32 val; |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 60 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 61 | /* 1. EBC need to program READY, CLK, ADV for ASync mode */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 62 | gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_SEL, GPIO_OUT_0); |
| 63 | gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_SEL, GPIO_OUT_0); |
| 64 | gpio_config(CONFIG_SYS_GPIO_CRAM_CRE, GPIO_OUT, GPIO_SEL, GPIO_OUT_0); |
| 65 | gpio_config(CONFIG_SYS_GPIO_CRAM_WAIT, GPIO_IN, GPIO_SEL, GPIO_OUT_NO_CHG); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 66 | |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 67 | /* 2. EBC in Async mode */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 68 | mtebc(PB1AP, 0x078F1EC0); |
| 69 | mtebc(PB2AP, 0x078F1EC0); |
| 70 | mtebc(PB1CR, 0x000BC000); |
| 71 | mtebc(PB2CR, 0x020BC000); |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 72 | |
| 73 | /* 3. Set CRAM in Sync mode */ |
| 74 | cram_bcr_write(0x7012); /* CRAM burst setting */ |
| 75 | |
| 76 | /* 4. EBC in Sync mode */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 77 | mtebc(PB1AP, 0x9C0201C0); |
| 78 | mtebc(PB2AP, 0x9C0201C0); |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 79 | |
| 80 | /* Set GPIO pins back to alternate function */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 81 | gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG); |
| 82 | gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG); |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 83 | |
| 84 | /* Config EBC to use RDY */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 85 | mfsdr(SDR0_ULTRA0, val); |
| 86 | mtsdr(SDR0_ULTRA0, val | SDR_ULTRA0_EBCRDYEN); |
Stefan Roese | c440bfe | 2007-06-06 11:42:13 +0200 | [diff] [blame] | 87 | |
| 88 | /* Wait a short while, since for NAND booting this is too fast */ |
| 89 | for (i=0; i<200000; i++) |
| 90 | ; |
| 91 | #endif |
Stefan Roese | 3cb86f3 | 2007-03-24 15:45:34 +0100 | [diff] [blame] | 92 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 93 | return (CONFIG_SYS_MBYTES_RAM << 20); |
Stefan Roese | 16c0cc1 | 2007-03-21 13:39:57 +0100 | [diff] [blame] | 94 | } |