blob: 5d4039375530e7a639499a7952a66587803abf9c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiewb859ef12007-08-16 19:23:50 -05002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wangd132fe62012-03-26 21:49:06 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiewb859ef12007-08-16 19:23:50 -05007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiewb859ef12007-08-16 19:23:50 -05008 */
9
10#include <config.h>
11#include <common.h>
Simon Glass0ffd9db2019-12-28 10:45:06 -070012#include <init.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050013#include <asm/immap.h>
Alison Wangd132fe62012-03-26 21:49:06 +000014#include <asm/io.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050015
16DECLARE_GLOBAL_DATA_PTR;
17
18int checkboard(void)
19{
20 puts("Board: ");
21 puts("Freescale M5235 EVB\n");
22 return 0;
23};
24
Simon Glassd35f3382017-04-06 12:47:05 -060025int dram_init(void)
TsiChungLiewb859ef12007-08-16 19:23:50 -050026{
Alison Wangd132fe62012-03-26 21:49:06 +000027 sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
28 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChungLiewb859ef12007-08-16 19:23:50 -050029 u32 dramsize, i, dramclk;
30
31 /*
32 * When booting from external Flash, the port-size is less than
33 * the port-size of SDRAM. In this case it is necessary to enable
34 * Data[15:0] on Port Address/Data.
35 */
Alison Wangd132fe62012-03-26 21:49:06 +000036 out_8(&gpio->par_ad,
37 GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 |
38 GPIO_PAR_AD_DATAL);
TsiChungLiewb859ef12007-08-16 19:23:50 -050039
40 /* Initialize PAR to enable SDRAM signals */
Alison Wangd132fe62012-03-26 21:49:06 +000041 out_8(&gpio->par_sdram,
42 GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS |
43 GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE |
44 GPIO_PAR_SDRAM_SDCS(3));
TsiChungLiewb859ef12007-08-16 19:23:50 -050045
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiewb859ef12007-08-16 19:23:50 -050047 for (i = 0x13; i < 0x20; i++) {
48 if (dramsize == (1 << i))
49 break;
50 }
51 i--;
52
Alison Wangd132fe62012-03-26 21:49:06 +000053 if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020054 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiewb859ef12007-08-16 19:23:50 -050055
56 /* Initialize DRAM Control Register: DCR */
Alison Wangd132fe62012-03-26 21:49:06 +000057 out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS |
58 SDRAMC_DCR_RTIM_6CLKS |
59 SDRAMC_DCR_RC((15 * dramclk) >> 4));
TsiChungLiewb859ef12007-08-16 19:23:50 -050060
61 /* Initialize DACR0 */
Alison Wangd132fe62012-03-26 21:49:06 +000062 out_be32(&sdram->dacr0,
63 SDRAMC_DARCn_BA(CONFIG_SYS_SDRAM_BASE) |
64 SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 |
65 SDRAMC_DARCn_PS_32);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050066 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050067
68 /* Initialize DMR0 */
Alison Wangd132fe62012-03-26 21:49:06 +000069 out_be32(&sdram->dmr0,
70 ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050071 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050072
73 /* Set IP (bit 3) in DACR */
Alison Wangd132fe62012-03-26 21:49:06 +000074 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP);
TsiChungLiewb859ef12007-08-16 19:23:50 -050075
76 /* Wait 30ns to allow banks to precharge */
77 for (i = 0; i < 5; i++) {
78 asm("nop");
79 }
80
81 /* Write to this block to initiate precharge */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 *(u32 *) (CONFIG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChungLiewb859ef12007-08-16 19:23:50 -050083
84 /* Set RE (bit 15) in DACR */
Alison Wangd132fe62012-03-26 21:49:06 +000085 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050086
87 /* Wait for at least 8 auto refresh cycles to occur */
88 for (i = 0; i < 0x2000; i++) {
89 asm("nop");
90 }
91
92 /* Finish the configuration by issuing the MRS. */
Alison Wangd132fe62012-03-26 21:49:06 +000093 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050094 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050095
96 /* Write to the SDRAM Mode Register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097 *(u32 *) (CONFIG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiewb859ef12007-08-16 19:23:50 -050098 }
99
Simon Glass39f90ba2017-03-31 08:40:25 -0600100 gd->ram_size = dramsize;
101
102 return 0;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500103};
104
105int testdram(void)
106{
107 /* TODO: XXX XXX XXX */
108 printf("DRAM test not implemented!\n");
109
110 return (0);
111}