blob: 44161a0b0a1c441753e3f95850f762d50cd2111b [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>
Simon Glass3ba929a2020-10-30 21:38:53 -060013#include <asm/global_data.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050014#include <asm/immap.h>
Alison Wangd132fe62012-03-26 21:49:06 +000015#include <asm/io.h>
TsiChungLiewb859ef12007-08-16 19:23:50 -050016
17DECLARE_GLOBAL_DATA_PTR;
18
19int checkboard(void)
20{
21 puts("Board: ");
22 puts("Freescale M5235 EVB\n");
23 return 0;
24};
25
Simon Glassd35f3382017-04-06 12:47:05 -060026int dram_init(void)
TsiChungLiewb859ef12007-08-16 19:23:50 -050027{
Alison Wangd132fe62012-03-26 21:49:06 +000028 sdram_t *sdram = (sdram_t *)(MMAP_SDRAM);
29 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChungLiewb859ef12007-08-16 19:23:50 -050030 u32 dramsize, i, dramclk;
31
32 /*
33 * When booting from external Flash, the port-size is less than
34 * the port-size of SDRAM. In this case it is necessary to enable
35 * Data[15:0] on Port Address/Data.
36 */
Alison Wangd132fe62012-03-26 21:49:06 +000037 out_8(&gpio->par_ad,
38 GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 |
39 GPIO_PAR_AD_DATAL);
TsiChungLiewb859ef12007-08-16 19:23:50 -050040
41 /* Initialize PAR to enable SDRAM signals */
Alison Wangd132fe62012-03-26 21:49:06 +000042 out_8(&gpio->par_sdram,
43 GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS |
44 GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE |
45 GPIO_PAR_SDRAM_SDCS(3));
TsiChungLiewb859ef12007-08-16 19:23:50 -050046
Tom Rinibb4dd962022-11-16 13:10:37 -050047 dramsize = CFG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiewb859ef12007-08-16 19:23:50 -050048 for (i = 0x13; i < 0x20; i++) {
49 if (dramsize == (1 << i))
50 break;
51 }
52 i--;
53
Alison Wangd132fe62012-03-26 21:49:06 +000054 if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ);
TsiChungLiewb859ef12007-08-16 19:23:50 -050056
57 /* Initialize DRAM Control Register: DCR */
Alison Wangd132fe62012-03-26 21:49:06 +000058 out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS |
59 SDRAMC_DCR_RTIM_6CLKS |
60 SDRAMC_DCR_RC((15 * dramclk) >> 4));
TsiChungLiewb859ef12007-08-16 19:23:50 -050061
62 /* Initialize DACR0 */
Alison Wangd132fe62012-03-26 21:49:06 +000063 out_be32(&sdram->dacr0,
Tom Rinibb4dd962022-11-16 13:10:37 -050064 SDRAMC_DARCn_BA(CFG_SYS_SDRAM_BASE) |
Alison Wangd132fe62012-03-26 21:49:06 +000065 SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 |
66 SDRAMC_DARCn_PS_32);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050067 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050068
69 /* Initialize DMR0 */
Alison Wangd132fe62012-03-26 21:49:06 +000070 out_be32(&sdram->dmr0,
71 ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050072 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050073
74 /* Set IP (bit 3) in DACR */
Alison Wangd132fe62012-03-26 21:49:06 +000075 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP);
TsiChungLiewb859ef12007-08-16 19:23:50 -050076
77 /* Wait 30ns to allow banks to precharge */
78 for (i = 0; i < 5; i++) {
79 asm("nop");
80 }
81
82 /* Write to this block to initiate precharge */
Tom Rinibb4dd962022-11-16 13:10:37 -050083 *(u32 *) (CFG_SYS_SDRAM_BASE) = 0xA5A59696;
TsiChungLiewb859ef12007-08-16 19:23:50 -050084
85 /* Set RE (bit 15) in DACR */
Alison Wangd132fe62012-03-26 21:49:06 +000086 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE);
TsiChungLiewb859ef12007-08-16 19:23:50 -050087
88 /* Wait for at least 8 auto refresh cycles to occur */
89 for (i = 0; i < 0x2000; i++) {
90 asm("nop");
91 }
92
93 /* Finish the configuration by issuing the MRS. */
Alison Wangd132fe62012-03-26 21:49:06 +000094 setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS);
TsiChung Liew94e3f0f2008-06-18 19:27:23 -050095 asm("nop");
TsiChungLiewb859ef12007-08-16 19:23:50 -050096
97 /* Write to the SDRAM Mode Register */
Tom Rinibb4dd962022-11-16 13:10:37 -050098 *(u32 *) (CFG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696;
TsiChungLiewb859ef12007-08-16 19:23:50 -050099 }
100
Simon Glass39f90ba2017-03-31 08:40:25 -0600101 gd->ram_size = dramsize;
102
103 return 0;
TsiChungLiewb859ef12007-08-16 19:23:50 -0500104};
105
106int testdram(void)
107{
108 /* TODO: XXX XXX XXX */
109 printf("DRAM test not implemented!\n");
110
111 return (0);
112}