blob: a01133612c515cba197c606daf24515009a2d251 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matthew Fettke545c8e02008-01-24 14:02:32 -06002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
6 * Copyright (C) 2005-2008 Arthur Shipkowski (art@videon-central.com)
7 *
Alison Wang32dbaaf2012-03-26 21:49:04 +00008 * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved.
Matthew Fettke545c8e02008-01-24 14:02:32 -06009 */
10
11#include <common.h>
12#include <asm/immap.h>
Alison Wang32dbaaf2012-03-26 21:49:04 +000013#include <asm/io.h>
Matthew Fettke545c8e02008-01-24 14:02:32 -060014
Simon Glass088454c2017-03-31 08:40:25 -060015DECLARE_GLOBAL_DATA_PTR;
16
Matthew Fettke545c8e02008-01-24 14:02:32 -060017#define PERIOD 13 /* system bus period in ns */
18#define SDRAM_TREFI 7800 /* in ns */
19
20int checkboard(void)
21{
22 puts("Board: ");
23 puts("Freescale MCF5275 EVB\n");
24 return 0;
25};
26
Simon Glassf1683aa2017-04-06 12:47:05 -060027int dram_init(void)
Matthew Fettke545c8e02008-01-24 14:02:32 -060028{
Alison Wang32dbaaf2012-03-26 21:49:04 +000029 sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM);
30 gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO);
Matthew Fettke545c8e02008-01-24 14:02:32 -060031
Alison Wang32dbaaf2012-03-26 21:49:04 +000032 /* Enable SDRAM */
33 out_be16(&gpio_reg->par_sdram, 0x3FF);
Matthew Fettke545c8e02008-01-24 14:02:32 -060034
35 /* Set up chip select */
Alison Wang32dbaaf2012-03-26 21:49:04 +000036 out_be32(&sdp->sdbar0, CONFIG_SYS_SDRAM_BASE);
37 out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V);
Matthew Fettke545c8e02008-01-24 14:02:32 -060038
39 /* Set up timing */
Alison Wang32dbaaf2012-03-26 21:49:04 +000040 out_be32(&sdp->sdcfg1, 0x83711630);
41 out_be32(&sdp->sdcfg2, 0x46770000);
Matthew Fettke545c8e02008-01-24 14:02:32 -060042
43 /* Enable clock */
Alison Wang32dbaaf2012-03-26 21:49:04 +000044 out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE);
Matthew Fettke545c8e02008-01-24 14:02:32 -060045
46 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000047 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Matthew Fettke545c8e02008-01-24 14:02:32 -060048
49 /* Dummy write to start SDRAM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020050 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060051
52 /* Send LEMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000053 setbits_be32(&sdp->sdmr,
54 MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) |
55 MCF_SDRAMC_SDMR_CMD);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060057
58 /* Send LMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000059 out_be32(&sdp->sdmr, 0x058d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020060 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060061
62 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000063 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
Matthew Fettke545c8e02008-01-24 14:02:32 -060064
65 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000066 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060068
69 /* Stop manual precharge, send 2 IREF */
Alison Wang32dbaaf2012-03-26 21:49:04 +000070 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
71 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020072 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
73 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060074
Alison Wang32dbaaf2012-03-26 21:49:04 +000075
76 out_be32(&sdp->sdmr, 0x018d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020077 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060078
79 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000080 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
81 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN);
Matthew Fettke545c8e02008-01-24 14:02:32 -060082
83 /* Turn on auto refresh, lock SDMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000084 out_be32(&sdp->sdcr,
Matthew Fettke545c8e02008-01-24 14:02:32 -060085 MCF_SDRAMC_SDCR_CKE
86 | MCF_SDRAMC_SDCR_REF
87 | MCF_SDRAMC_SDCR_MUX(1)
88 /* 1 added to round up */
89 | MCF_SDRAMC_SDCR_RCNT((SDRAM_TREFI/(PERIOD*64)) - 1 + 1)
Alison Wang32dbaaf2012-03-26 21:49:04 +000090 | MCF_SDRAMC_SDCR_DQS_OE(0x3));
Matthew Fettke545c8e02008-01-24 14:02:32 -060091
Simon Glass088454c2017-03-31 08:40:25 -060092 gd->ram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
93
94 return 0;
Matthew Fettke545c8e02008-01-24 14:02:32 -060095};
96
97int testdram(void)
98{
99 /* TODO: XXX XXX XXX */
100 printf("DRAM test not implemented!\n");
101
102 return (0);
103}