blob: 00fa35ca5f71b8efcd941a94cc45066a2e171638 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Matthew Fettke9f3b3bb2008-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 Wang95bed1f2012-03-26 21:49:04 +00008 * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved.
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -06009 */
10
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>
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060014#include <asm/immap.h>
Alison Wang95bed1f2012-03-26 21:49:04 +000015#include <asm/io.h>
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060016
Simon Glass39f90ba2017-03-31 08:40:25 -060017DECLARE_GLOBAL_DATA_PTR;
18
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060019#define PERIOD 13 /* system bus period in ns */
20#define SDRAM_TREFI 7800 /* in ns */
21
22int checkboard(void)
23{
24 puts("Board: ");
25 puts("Freescale MCF5275 EVB\n");
26 return 0;
27};
28
Simon Glassd35f3382017-04-06 12:47:05 -060029int dram_init(void)
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060030{
Alison Wang95bed1f2012-03-26 21:49:04 +000031 sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM);
32 gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060033
Alison Wang95bed1f2012-03-26 21:49:04 +000034 /* Enable SDRAM */
35 out_be16(&gpio_reg->par_sdram, 0x3FF);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060036
37 /* Set up chip select */
Tom Rinibb4dd962022-11-16 13:10:37 -050038 out_be32(&sdp->sdbar0, CFG_SYS_SDRAM_BASE);
Alison Wang95bed1f2012-03-26 21:49:04 +000039 out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060040
41 /* Set up timing */
Alison Wang95bed1f2012-03-26 21:49:04 +000042 out_be32(&sdp->sdcfg1, 0x83711630);
43 out_be32(&sdp->sdcfg2, 0x46770000);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060044
45 /* Enable clock */
Alison Wang95bed1f2012-03-26 21:49:04 +000046 out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060047
48 /* Set precharge */
Alison Wang95bed1f2012-03-26 21:49:04 +000049 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060050
51 /* Dummy write to start SDRAM */
Tom Rinibb4dd962022-11-16 13:10:37 -050052 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060053
54 /* Send LEMR */
Alison Wang95bed1f2012-03-26 21:49:04 +000055 setbits_be32(&sdp->sdmr,
56 MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) |
57 MCF_SDRAMC_SDMR_CMD);
Tom Rinibb4dd962022-11-16 13:10:37 -050058 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060059
60 /* Send LMR */
Alison Wang95bed1f2012-03-26 21:49:04 +000061 out_be32(&sdp->sdmr, 0x058d0000);
Tom Rinibb4dd962022-11-16 13:10:37 -050062 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060063
64 /* Stop sending commands */
Alison Wang95bed1f2012-03-26 21:49:04 +000065 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060066
67 /* Set precharge */
Alison Wang95bed1f2012-03-26 21:49:04 +000068 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Tom Rinibb4dd962022-11-16 13:10:37 -050069 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060070
71 /* Stop manual precharge, send 2 IREF */
Alison Wang95bed1f2012-03-26 21:49:04 +000072 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
73 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF);
Tom Rinibb4dd962022-11-16 13:10:37 -050074 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
75 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060076
Alison Wang95bed1f2012-03-26 21:49:04 +000077
78 out_be32(&sdp->sdmr, 0x018d0000);
Tom Rinibb4dd962022-11-16 13:10:37 -050079 *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060080
81 /* Stop sending commands */
Alison Wang95bed1f2012-03-26 21:49:04 +000082 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
83 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN);
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060084
85 /* Turn on auto refresh, lock SDMR */
Alison Wang95bed1f2012-03-26 21:49:04 +000086 out_be32(&sdp->sdcr,
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060087 MCF_SDRAMC_SDCR_CKE
88 | MCF_SDRAMC_SDCR_REF
89 | MCF_SDRAMC_SDCR_MUX(1)
90 /* 1 added to round up */
91 | MCF_SDRAMC_SDCR_RCNT((SDRAM_TREFI/(PERIOD*64)) - 1 + 1)
Alison Wang95bed1f2012-03-26 21:49:04 +000092 | MCF_SDRAMC_SDCR_DQS_OE(0x3));
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060093
Tom Rinibb4dd962022-11-16 13:10:37 -050094 gd->ram_size = CFG_SYS_SDRAM_SIZE * 1024 * 1024;
Simon Glass39f90ba2017-03-31 08:40:25 -060095
96 return 0;
Matthew Fettke9f3b3bb2008-01-24 14:02:32 -060097};
98
99int testdram(void)
100{
101 /* TODO: XXX XXX XXX */
102 printf("DRAM test not implemented!\n");
103
104 return (0);
105}