blob: fbd2e616045da8f7baeeea10bba339da1d77f970 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiew4a442d32007-08-16 19:23:50 -05002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangc6d88632012-03-26 21:49:06 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew4a442d32007-08-16 19:23:50 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiew4a442d32007-08-16 19:23:50 -05008 */
9
10#include <config.h>
11#include <common.h>
12#include <asm/immap.h>
Alison Wangc6d88632012-03-26 21:49:06 +000013#include <asm/io.h>
TsiChungLiew4a442d32007-08-16 19:23:50 -050014
15DECLARE_GLOBAL_DATA_PTR;
16
17int checkboard(void)
18{
19 puts("Board: ");
20 puts("Freescale M5235 EVB\n");
21 return 0;
22};
23
Simon Glassf1683aa2017-04-06 12:47:05 -060024int dram_init(void)
TsiChungLiew4a442d32007-08-16 19:23:50 -050025{
Alison Wangc6d88632012-03-26 21:49:06 +000026 sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
27 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChungLiew4a442d32007-08-16 19:23:50 -050028 u32 dramsize, i, dramclk;
29
30 /*
31 * When booting from external Flash, the port-size is less than
32 * the port-size of SDRAM. In this case it is necessary to enable
33 * Data[15:0] on Port Address/Data.
34 */
Alison Wangc6d88632012-03-26 21:49:06 +000035 out_8(&gpio->par_ad,
36 GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 |
37 GPIO_PAR_AD_DATAL);
TsiChungLiew4a442d32007-08-16 19:23:50 -050038
39 /* Initialize PAR to enable SDRAM signals */
Alison Wangc6d88632012-03-26 21:49:06 +000040 out_8(&gpio->par_sdram,
41 GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS |
42 GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE |
43 GPIO_PAR_SDRAM_SDCS(3));
TsiChungLiew4a442d32007-08-16 19:23:50 -050044
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiew4a442d32007-08-16 19:23:50 -050046 for (i = 0x13; i < 0x20; i++) {
47 if (dramsize == (1 << i))
48 break;
49 }
50 i--;
51
Alison Wangc6d88632012-03-26 21:49:06 +000052 if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) {
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020053 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiew4a442d32007-08-16 19:23:50 -050054
55 /* Initialize DRAM Control Register: DCR */
Alison Wangc6d88632012-03-26 21:49:06 +000056 out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS |
57 SDRAMC_DCR_RTIM_6CLKS |
58 SDRAMC_DCR_RC((15 * dramclk) >> 4));
TsiChungLiew4a442d32007-08-16 19:23:50 -050059
60 /* Initialize DACR0 */
Alison Wangc6d88632012-03-26 21:49:06 +000061 out_be32(&sdram->dacr0,
62 SDRAMC_DARCn_BA(CONFIG_SYS_SDRAM_BASE) |
63 SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 |
64 SDRAMC_DARCn_PS_32);
TsiChung Liewab4860b2008-06-18 19:27:23 -050065 asm("nop");
TsiChungLiew4a442d32007-08-16 19:23:50 -050066
67 /* Initialize DMR0 */
Alison Wangc6d88632012-03-26 21:49:06 +000068 out_be32(&sdram->dmr0,
69 ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V);
TsiChung Liewab4860b2008-06-18 19:27:23 -050070 asm("nop");
TsiChungLiew4a442d32007-08-16 19:23:50 -050071
72 /* Set IP (bit 3) in DACR */
Alison Wangc6d88632012-03-26 21:49:06 +000073 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP);
TsiChungLiew4a442d32007-08-16 19:23:50 -050074
75 /* Wait 30ns to allow banks to precharge */
76 for (i = 0; i < 5; i++) {
77 asm("nop");
78 }
79
80 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020081 *(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChungLiew4a442d32007-08-16 19:23:50 -050082
83 /* Set RE (bit 15) in DACR */
Alison Wangc6d88632012-03-26 21:49:06 +000084 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE);
TsiChungLiew4a442d32007-08-16 19:23:50 -050085
86 /* Wait for at least 8 auto refresh cycles to occur */
87 for (i = 0; i < 0x2000; i++) {
88 asm("nop");
89 }
90
91 /* Finish the configuration by issuing the MRS. */
Alison Wangc6d88632012-03-26 21:49:06 +000092 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS);
TsiChung Liewab4860b2008-06-18 19:27:23 -050093 asm("nop");
TsiChungLiew4a442d32007-08-16 19:23:50 -050094
95 /* Write to the SDRAM Mode Register */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096 *(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiew4a442d32007-08-16 19:23:50 -050097 }
98
Simon Glass088454c2017-03-31 08:40:25 -060099 gd->ram_size = dramsize;
100
101 return 0;
TsiChungLiew4a442d32007-08-16 19:23:50 -0500102};
103
104int testdram(void)
105{
106 /* TODO: XXX XXX XXX */
107 printf("DRAM test not implemented!\n");
108
109 return (0);
110}