blob: 510af33e4c3cd91e07c63f71668228ce709332b6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
TsiChungLiew99b037a2008-01-14 17:43:33 -06002/*
3 * (C) Copyright 2000-2003
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 *
Alison Wang8bce3ec2012-03-26 21:49:03 +00006 * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
TsiChungLiew99b037a2008-01-14 17:43:33 -06007 * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
TsiChungLiew99b037a2008-01-14 17:43:33 -06008 */
9
10#include <common.h>
Simon Glass0ffd9db2019-12-28 10:45:06 -070011#include <init.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060012#include <asm/global_data.h>
TsiChungLiew99b037a2008-01-14 17:43:33 -060013#include <asm/immap.h>
Alison Wang8bce3ec2012-03-26 21:49:03 +000014#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060015#include <linux/delay.h>
TsiChungLiew99b037a2008-01-14 17:43:33 -060016
17DECLARE_GLOBAL_DATA_PTR;
18
19int checkboard(void)
20{
21 puts("Board: ");
22 puts("Freescale M52277 EVB\n");
23 return 0;
24};
25
Simon Glassd35f3382017-04-06 12:47:05 -060026int dram_init(void)
TsiChungLiew99b037a2008-01-14 17:43:33 -060027{
TsiChung Liew39966e32008-10-21 15:37:02 +000028 u32 dramsize;
29
30#ifdef CONFIG_CF_SBF
31 /*
32 * Serial Boot: The dram is already initialized in start.S
33 * only require to return DRAM size
34 */
35 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
36#else
Alison Wang8bce3ec2012-03-26 21:49:03 +000037 sdramc_t *sdram = (sdramc_t *)(MMAP_SDRAM);
38 gpio_t *gpio = (gpio_t *)(MMAP_GPIO);
TsiChung Liew39966e32008-10-21 15:37:02 +000039 u32 i;
TsiChungLiew99b037a2008-01-14 17:43:33 -060040
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 dramsize = CONFIG_SYS_SDRAM_SIZE * 0x100000;
TsiChungLiew99b037a2008-01-14 17:43:33 -060042
43 for (i = 0x13; i < 0x20; i++) {
44 if (dramsize == (1 << i))
45 break;
46 }
47 i--;
48
Alison Wang8bce3ec2012-03-26 21:49:03 +000049 out_8(&gpio->mscr_sdram, CONFIG_SYS_SDRAM_DRV_STRENGTH);
TsiChung Liew39966e32008-10-21 15:37:02 +000050
Alison Wang8bce3ec2012-03-26 21:49:03 +000051 out_be32(&sdram->sdcs0, CONFIG_SYS_SDRAM_BASE | i);
TsiChungLiew99b037a2008-01-14 17:43:33 -060052
Alison Wang8bce3ec2012-03-26 21:49:03 +000053 out_be32(&sdram->sdcfg1, CONFIG_SYS_SDRAM_CFG1);
54 out_be32(&sdram->sdcfg2, CONFIG_SYS_SDRAM_CFG2);
TsiChungLiew99b037a2008-01-14 17:43:33 -060055
56 /* Issue PALL */
Alison Wang8bce3ec2012-03-26 21:49:03 +000057 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
TsiChung Liew39966e32008-10-21 15:37:02 +000058 __asm__("nop");
TsiChungLiew99b037a2008-01-14 17:43:33 -060059
60 /* Issue LEMR */
Alison Wang8bce3ec2012-03-26 21:49:03 +000061 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_MODE);
TsiChung Liew39966e32008-10-21 15:37:02 +000062 __asm__("nop");
Alison Wang8bce3ec2012-03-26 21:49:03 +000063 out_be32(&sdram->sdmr, CONFIG_SYS_SDRAM_EMOD);
TsiChung Liew39966e32008-10-21 15:37:02 +000064 __asm__("nop");
TsiChungLiew99b037a2008-01-14 17:43:33 -060065
66 udelay(1000);
67
68 /* Issue PALL */
Alison Wang8bce3ec2012-03-26 21:49:03 +000069 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 2);
TsiChung Liew39966e32008-10-21 15:37:02 +000070 __asm__("nop");
TsiChungLiew99b037a2008-01-14 17:43:33 -060071
72 /* Perform two refresh cycles */
Alison Wang8bce3ec2012-03-26 21:49:03 +000073 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
TsiChung Liew39966e32008-10-21 15:37:02 +000074 __asm__("nop");
Alison Wang8bce3ec2012-03-26 21:49:03 +000075 out_be32(&sdram->sdcr, CONFIG_SYS_SDRAM_CTRL | 4);
TsiChung Liew39966e32008-10-21 15:37:02 +000076 __asm__("nop");
TsiChungLiew99b037a2008-01-14 17:43:33 -060077
Alison Wang8bce3ec2012-03-26 21:49:03 +000078 out_be32(&sdram->sdcr,
79 (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000c00);
TsiChungLiew99b037a2008-01-14 17:43:33 -060080
81 udelay(100);
TsiChung Liew39966e32008-10-21 15:37:02 +000082#endif
Simon Glass39f90ba2017-03-31 08:40:25 -060083 gd->ram_size = dramsize;
84
85 return 0;
TsiChungLiew99b037a2008-01-14 17:43:33 -060086};
87
88int testdram(void)
89{
90 /* TODO: XXX XXX XXX */
91 printf("DRAM test not implemented!\n");
92
93 return (0);
94}