blob: 48ad4a86b9e33563644ee942670bb10c6084f985 [file] [log] [blame]
Matthew Fettke545c8e02008-01-24 14:02:32 -06001/*
2 * (C) Copyright 2000-2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * Copyright (C) 2005-2008 Arthur Shipkowski (art@videon-central.com)
6 *
Alison Wang32dbaaf2012-03-26 21:49:04 +00007 * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved.
8 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02009 * SPDX-License-Identifier: GPL-2.0+
Matthew Fettke545c8e02008-01-24 14:02:32 -060010 */
11
12#include <common.h>
13#include <asm/immap.h>
Alison Wang32dbaaf2012-03-26 21:49:04 +000014#include <asm/io.h>
Matthew Fettke545c8e02008-01-24 14:02:32 -060015
Simon Glass088454c2017-03-31 08:40:25 -060016DECLARE_GLOBAL_DATA_PTR;
17
Matthew Fettke545c8e02008-01-24 14:02:32 -060018#define PERIOD 13 /* system bus period in ns */
19#define SDRAM_TREFI 7800 /* in ns */
20
21int checkboard(void)
22{
23 puts("Board: ");
24 puts("Freescale MCF5275 EVB\n");
25 return 0;
26};
27
Simon Glass088454c2017-03-31 08:40:25 -060028int initdram(void)
Matthew Fettke545c8e02008-01-24 14:02:32 -060029{
Alison Wang32dbaaf2012-03-26 21:49:04 +000030 sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM);
31 gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO);
Matthew Fettke545c8e02008-01-24 14:02:32 -060032
Alison Wang32dbaaf2012-03-26 21:49:04 +000033 /* Enable SDRAM */
34 out_be16(&gpio_reg->par_sdram, 0x3FF);
Matthew Fettke545c8e02008-01-24 14:02:32 -060035
36 /* Set up chip select */
Alison Wang32dbaaf2012-03-26 21:49:04 +000037 out_be32(&sdp->sdbar0, CONFIG_SYS_SDRAM_BASE);
38 out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V);
Matthew Fettke545c8e02008-01-24 14:02:32 -060039
40 /* Set up timing */
Alison Wang32dbaaf2012-03-26 21:49:04 +000041 out_be32(&sdp->sdcfg1, 0x83711630);
42 out_be32(&sdp->sdcfg2, 0x46770000);
Matthew Fettke545c8e02008-01-24 14:02:32 -060043
44 /* Enable clock */
Alison Wang32dbaaf2012-03-26 21:49:04 +000045 out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE);
Matthew Fettke545c8e02008-01-24 14:02:32 -060046
47 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000048 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Matthew Fettke545c8e02008-01-24 14:02:32 -060049
50 /* Dummy write to start SDRAM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020051 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060052
53 /* Send LEMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000054 setbits_be32(&sdp->sdmr,
55 MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) |
56 MCF_SDRAMC_SDMR_CMD);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020057 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060058
59 /* Send LMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000060 out_be32(&sdp->sdmr, 0x058d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020061 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060062
63 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000064 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
Matthew Fettke545c8e02008-01-24 14:02:32 -060065
66 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000067 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020068 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060069
70 /* Stop manual precharge, send 2 IREF */
Alison Wang32dbaaf2012-03-26 21:49:04 +000071 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
72 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020073 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
74 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060075
Alison Wang32dbaaf2012-03-26 21:49:04 +000076
77 out_be32(&sdp->sdmr, 0x018d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020078 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060079
80 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000081 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
82 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN);
Matthew Fettke545c8e02008-01-24 14:02:32 -060083
84 /* Turn on auto refresh, lock SDMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000085 out_be32(&sdp->sdcr,
Matthew Fettke545c8e02008-01-24 14:02:32 -060086 MCF_SDRAMC_SDCR_CKE
87 | MCF_SDRAMC_SDCR_REF
88 | MCF_SDRAMC_SDCR_MUX(1)
89 /* 1 added to round up */
90 | MCF_SDRAMC_SDCR_RCNT((SDRAM_TREFI/(PERIOD*64)) - 1 + 1)
Alison Wang32dbaaf2012-03-26 21:49:04 +000091 | MCF_SDRAMC_SDCR_DQS_OE(0x3));
Matthew Fettke545c8e02008-01-24 14:02:32 -060092
Simon Glass088454c2017-03-31 08:40:25 -060093 gd->ram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
94
95 return 0;
Matthew Fettke545c8e02008-01-24 14:02:32 -060096};
97
98int testdram(void)
99{
100 /* TODO: XXX XXX XXX */
101 printf("DRAM test not implemented!\n");
102
103 return (0);
104}