blob: 16083d1bc0ef5c74681a07b010c65164e6d35821 [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
16#define PERIOD 13 /* system bus period in ns */
17#define SDRAM_TREFI 7800 /* in ns */
18
19int checkboard(void)
20{
21 puts("Board: ");
22 puts("Freescale MCF5275 EVB\n");
23 return 0;
24};
25
Becky Bruce9973e3c2008-06-09 16:03:40 -050026phys_size_t initdram(int board_type)
Matthew Fettke545c8e02008-01-24 14:02:32 -060027{
Alison Wang32dbaaf2012-03-26 21:49:04 +000028 sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM);
29 gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO);
Matthew Fettke545c8e02008-01-24 14:02:32 -060030
Alison Wang32dbaaf2012-03-26 21:49:04 +000031 /* Enable SDRAM */
32 out_be16(&gpio_reg->par_sdram, 0x3FF);
Matthew Fettke545c8e02008-01-24 14:02:32 -060033
34 /* Set up chip select */
Alison Wang32dbaaf2012-03-26 21:49:04 +000035 out_be32(&sdp->sdbar0, CONFIG_SYS_SDRAM_BASE);
36 out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V);
Matthew Fettke545c8e02008-01-24 14:02:32 -060037
38 /* Set up timing */
Alison Wang32dbaaf2012-03-26 21:49:04 +000039 out_be32(&sdp->sdcfg1, 0x83711630);
40 out_be32(&sdp->sdcfg2, 0x46770000);
Matthew Fettke545c8e02008-01-24 14:02:32 -060041
42 /* Enable clock */
Alison Wang32dbaaf2012-03-26 21:49:04 +000043 out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE);
Matthew Fettke545c8e02008-01-24 14:02:32 -060044
45 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000046 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Matthew Fettke545c8e02008-01-24 14:02:32 -060047
48 /* Dummy write to start SDRAM */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020049 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060050
51 /* Send LEMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000052 setbits_be32(&sdp->sdmr,
53 MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) |
54 MCF_SDRAMC_SDMR_CMD);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060056
57 /* Send LMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000058 out_be32(&sdp->sdmr, 0x058d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060060
61 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000062 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
Matthew Fettke545c8e02008-01-24 14:02:32 -060063
64 /* Set precharge */
Alison Wang32dbaaf2012-03-26 21:49:04 +000065 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020066 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060067
68 /* Stop manual precharge, send 2 IREF */
Alison Wang32dbaaf2012-03-26 21:49:04 +000069 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL);
70 setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020071 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
72 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060073
Alison Wang32dbaaf2012-03-26 21:49:04 +000074
75 out_be32(&sdp->sdmr, 0x018d0000);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020076 *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696;
Matthew Fettke545c8e02008-01-24 14:02:32 -060077
78 /* Stop sending commands */
Alison Wang32dbaaf2012-03-26 21:49:04 +000079 clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD);
80 clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN);
Matthew Fettke545c8e02008-01-24 14:02:32 -060081
82 /* Turn on auto refresh, lock SDMR */
Alison Wang32dbaaf2012-03-26 21:49:04 +000083 out_be32(&sdp->sdcr,
Matthew Fettke545c8e02008-01-24 14:02:32 -060084 MCF_SDRAMC_SDCR_CKE
85 | MCF_SDRAMC_SDCR_REF
86 | MCF_SDRAMC_SDCR_MUX(1)
87 /* 1 added to round up */
88 | MCF_SDRAMC_SDCR_RCNT((SDRAM_TREFI/(PERIOD*64)) - 1 + 1)
Alison Wang32dbaaf2012-03-26 21:49:04 +000089 | MCF_SDRAMC_SDCR_DQS_OE(0x3));
Matthew Fettke545c8e02008-01-24 14:02:32 -060090
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020091 return CONFIG_SYS_SDRAM_SIZE * 1024 * 1024;
Matthew Fettke545c8e02008-01-24 14:02:32 -060092};
93
94int testdram(void)
95{
96 /* TODO: XXX XXX XXX */
97 printf("DRAM test not implemented!\n");
98
99 return (0);
100}