]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
545c8e0a MF |
2 | /* |
3 | * (C) Copyright 2000-2003 | |
4 | * Wolfgang Denk, DENX Software Engineering, [email protected]. | |
5 | * | |
6 | * Copyright (C) 2005-2008 Arthur Shipkowski ([email protected]) | |
7 | * | |
32dbaafa | 8 | * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved. |
545c8e0a MF |
9 | */ |
10 | ||
11 | #include <common.h> | |
49acd56e | 12 | #include <init.h> |
401d1c4f | 13 | #include <asm/global_data.h> |
545c8e0a | 14 | #include <asm/immap.h> |
32dbaafa | 15 | #include <asm/io.h> |
545c8e0a | 16 | |
088454cd SG |
17 | DECLARE_GLOBAL_DATA_PTR; |
18 | ||
545c8e0a MF |
19 | #define PERIOD 13 /* system bus period in ns */ |
20 | #define SDRAM_TREFI 7800 /* in ns */ | |
21 | ||
22 | int checkboard(void) | |
23 | { | |
24 | puts("Board: "); | |
25 | puts("Freescale MCF5275 EVB\n"); | |
26 | return 0; | |
27 | }; | |
28 | ||
f1683aa7 | 29 | int dram_init(void) |
545c8e0a | 30 | { |
32dbaafa AW |
31 | sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM); |
32 | gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO); | |
545c8e0a | 33 | |
32dbaafa AW |
34 | /* Enable SDRAM */ |
35 | out_be16(&gpio_reg->par_sdram, 0x3FF); | |
545c8e0a MF |
36 | |
37 | /* Set up chip select */ | |
32dbaafa AW |
38 | out_be32(&sdp->sdbar0, CONFIG_SYS_SDRAM_BASE); |
39 | out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V); | |
545c8e0a MF |
40 | |
41 | /* Set up timing */ | |
32dbaafa AW |
42 | out_be32(&sdp->sdcfg1, 0x83711630); |
43 | out_be32(&sdp->sdcfg2, 0x46770000); | |
545c8e0a MF |
44 | |
45 | /* Enable clock */ | |
32dbaafa | 46 | out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE); |
545c8e0a MF |
47 | |
48 | /* Set precharge */ | |
32dbaafa | 49 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
545c8e0a MF |
50 | |
51 | /* Dummy write to start SDRAM */ | |
6d0f6bcf | 52 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
545c8e0a MF |
53 | |
54 | /* Send LEMR */ | |
32dbaafa AW |
55 | setbits_be32(&sdp->sdmr, |
56 | MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) | | |
57 | MCF_SDRAMC_SDMR_CMD); | |
6d0f6bcf | 58 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
545c8e0a MF |
59 | |
60 | /* Send LMR */ | |
32dbaafa | 61 | out_be32(&sdp->sdmr, 0x058d0000); |
6d0f6bcf | 62 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
545c8e0a MF |
63 | |
64 | /* Stop sending commands */ | |
32dbaafa | 65 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
545c8e0a MF |
66 | |
67 | /* Set precharge */ | |
32dbaafa | 68 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
6d0f6bcf | 69 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
545c8e0a MF |
70 | |
71 | /* Stop manual precharge, send 2 IREF */ | |
32dbaafa AW |
72 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
73 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF); | |
6d0f6bcf JCPV |
74 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
75 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; | |
545c8e0a | 76 | |
32dbaafa AW |
77 | |
78 | out_be32(&sdp->sdmr, 0x018d0000); | |
6d0f6bcf | 79 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
545c8e0a MF |
80 | |
81 | /* Stop sending commands */ | |
32dbaafa AW |
82 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
83 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN); | |
545c8e0a MF |
84 | |
85 | /* Turn on auto refresh, lock SDMR */ | |
32dbaafa | 86 | out_be32(&sdp->sdcr, |
545c8e0a MF |
87 | 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) | |
32dbaafa | 92 | | MCF_SDRAMC_SDCR_DQS_OE(0x3)); |
545c8e0a | 93 | |
088454cd SG |
94 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
95 | ||
96 | return 0; | |
545c8e0a MF |
97 | }; |
98 | ||
99 | int testdram(void) | |
100 | { | |
101 | /* TODO: XXX XXX XXX */ | |
102 | printf("DRAM test not implemented!\n"); | |
103 | ||
104 | return (0); | |
105 | } |