blob: 9673118857b7d06f4ad1b7faee09bafa81c84217 [file] [log] [blame]
Stefan Roese16c0cc12007-03-21 13:39:57 +01001/*
2 * (C) Copyright 2007
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Stefan Roese16c0cc12007-03-21 13:39:57 +01006 */
7
Stefan Roese3cb86f32007-03-24 15:45:34 +01008/* define DEBUG for debugging output (obviously ;-)) */
9#if 0
10#define DEBUG
Stefan Roese16c0cc12007-03-21 13:39:57 +010011#endif
12
Stefan Roese3cb86f32007-03-24 15:45:34 +010013#include <common.h>
14#include <asm/processor.h>
15#include <asm/io.h>
Stefan Roese09887762010-09-16 14:30:37 +020016#include <asm/ppc4xx-gpio.h>
Stefan Roese3cb86f32007-03-24 15:45:34 +010017
Stefan Roesedf8a24c2007-06-19 16:42:31 +020018extern void board_pll_init_f(void);
19
Stefan Roese16c0cc12007-03-21 13:39:57 +010020static void cram_bcr_write(u32 wr_val)
21{
Stefan Roese3cb86f32007-03-24 15:45:34 +010022 wr_val <<= 2;
Stefan Roese16c0cc12007-03-21 13:39:57 +010023
Stefan Roese3cb86f32007-03-24 15:45:34 +010024 /* set CRAM_CRE to 1 */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020025 gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 1);
Stefan Roese16c0cc12007-03-21 13:39:57 +010026
Stefan Roese3cb86f32007-03-24 15:45:34 +010027 /* Write BCR to CRAM on CS1 */
28 out32(wr_val + 0x00200000, 0);
29 debug("CRAM VAL: %08x for CS1 ", wr_val + 0x00200000);
Stefan Roese16c0cc12007-03-21 13:39:57 +010030
Stefan Roese3cb86f32007-03-24 15:45:34 +010031 /* Write BCR to CRAM on CS2 */
32 out32(wr_val + 0x02200000, 0);
33 debug("CRAM VAL: %08x for CS2\n", wr_val + 0x02200000);
Stefan Roese16c0cc12007-03-21 13:39:57 +010034
Stefan Roese3cb86f32007-03-24 15:45:34 +010035 sync();
36 eieio();
Stefan Roese16c0cc12007-03-21 13:39:57 +010037
Stefan Roese3cb86f32007-03-24 15:45:34 +010038 /* set CRAM_CRE back to 0 (normal operation) */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020039 gpio_write_bit(CONFIG_SYS_GPIO_CRAM_CRE, 0);
Stefan Roese16c0cc12007-03-21 13:39:57 +010040
Stefan Roese16c0cc12007-03-21 13:39:57 +010041 return;
42}
43
Becky Bruce9973e3c2008-06-09 16:03:40 -050044phys_size_t initdram(int board_type)
Stefan Roese16c0cc12007-03-21 13:39:57 +010045{
Stefan Roesec440bfe2007-06-06 11:42:13 +020046 int i;
Stefan Roese3cb86f32007-03-24 15:45:34 +010047 u32 val;
Stefan Roese16c0cc12007-03-21 13:39:57 +010048
Stefan Roese3cb86f32007-03-24 15:45:34 +010049 /* 1. EBC need to program READY, CLK, ADV for ASync mode */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
51 gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
52 gpio_config(CONFIG_SYS_GPIO_CRAM_CRE, GPIO_OUT, GPIO_SEL, GPIO_OUT_0);
53 gpio_config(CONFIG_SYS_GPIO_CRAM_WAIT, GPIO_IN, GPIO_SEL, GPIO_OUT_NO_CHG);
Stefan Roese16c0cc12007-03-21 13:39:57 +010054
Stefan Roese3cb86f32007-03-24 15:45:34 +010055 /* 2. EBC in Async mode */
Stefan Roesed1c3b272009-09-09 16:25:29 +020056 mtebc(PB1AP, 0x078F1EC0);
57 mtebc(PB2AP, 0x078F1EC0);
58 mtebc(PB1CR, 0x000BC000);
59 mtebc(PB2CR, 0x020BC000);
Stefan Roese3cb86f32007-03-24 15:45:34 +010060
61 /* 3. Set CRAM in Sync mode */
62 cram_bcr_write(0x7012); /* CRAM burst setting */
63
64 /* 4. EBC in Sync mode */
Stefan Roesed1c3b272009-09-09 16:25:29 +020065 mtebc(PB1AP, 0x9C0201C0);
66 mtebc(PB2AP, 0x9C0201C0);
Stefan Roese3cb86f32007-03-24 15:45:34 +010067
68 /* Set GPIO pins back to alternate function */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020069 gpio_config(CONFIG_SYS_GPIO_CRAM_CLK, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG);
70 gpio_config(CONFIG_SYS_GPIO_CRAM_ADV, GPIO_OUT, GPIO_ALT1, GPIO_OUT_NO_CHG);
Stefan Roese3cb86f32007-03-24 15:45:34 +010071
72 /* Config EBC to use RDY */
Stefan Roesed1c3b272009-09-09 16:25:29 +020073 mfsdr(SDR0_ULTRA0, val);
74 mtsdr(SDR0_ULTRA0, val | SDR_ULTRA0_EBCRDYEN);
Stefan Roesec440bfe2007-06-06 11:42:13 +020075
76 /* Wait a short while, since for NAND booting this is too fast */
77 for (i=0; i<200000; i++)
78 ;
Stefan Roese3cb86f32007-03-24 15:45:34 +010079
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080 return (CONFIG_SYS_MBYTES_RAM << 20);
Stefan Roese16c0cc12007-03-21 13:39:57 +010081}