Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 2 | /* |
| 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 Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 8 | * Copyright (C) 2012 Freescale Semiconductor, Inc. All Rights Reserved. |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 9 | */ |
| 10 | |
| 11 | #include <common.h> |
Simon Glass | 0ffd9db | 2019-12-28 10:45:06 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 14 | #include <asm/immap.h> |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 16 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 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 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 29 | int dram_init(void) |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 30 | { |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 31 | sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM); |
| 32 | gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 33 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 34 | /* Enable SDRAM */ |
| 35 | out_be16(&gpio_reg->par_sdram, 0x3FF); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 36 | |
| 37 | /* Set up chip select */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 38 | out_be32(&sdp->sdbar0, CFG_SYS_SDRAM_BASE); |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 39 | out_be32(&sdp->sdbmr0, MCF_SDRAMC_SDMRn_BAM_32M | MCF_SDRAMC_SDMRn_V); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 40 | |
| 41 | /* Set up timing */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 42 | out_be32(&sdp->sdcfg1, 0x83711630); |
| 43 | out_be32(&sdp->sdcfg2, 0x46770000); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 44 | |
| 45 | /* Enable clock */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 46 | out_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN | MCF_SDRAMC_SDCR_CKE); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 47 | |
| 48 | /* Set precharge */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 49 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 50 | |
| 51 | /* Dummy write to start SDRAM */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 52 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 53 | |
| 54 | /* Send LEMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 55 | setbits_be32(&sdp->sdmr, |
| 56 | MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) | |
| 57 | MCF_SDRAMC_SDMR_CMD); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 58 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 59 | |
| 60 | /* Send LMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 61 | out_be32(&sdp->sdmr, 0x058d0000); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 62 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 63 | |
| 64 | /* Stop sending commands */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 65 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 66 | |
| 67 | /* Set precharge */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 68 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 69 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 70 | |
| 71 | /* Stop manual precharge, send 2 IREF */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 72 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
| 73 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 74 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
| 75 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 76 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 77 | |
| 78 | out_be32(&sdp->sdmr, 0x018d0000); |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 79 | *((volatile unsigned long *)CFG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 80 | |
| 81 | /* Stop sending commands */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 82 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
| 83 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 84 | |
| 85 | /* Turn on auto refresh, lock SDMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 86 | out_be32(&sdp->sdcr, |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 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) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 92 | | MCF_SDRAMC_SDCR_DQS_OE(0x3)); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 93 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 94 | gd->ram_size = CFG_SYS_SDRAM_SIZE * 1024 * 1024; |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 95 | |
| 96 | return 0; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 97 | }; |
| 98 | |
| 99 | int testdram(void) |
| 100 | { |
| 101 | /* TODO: XXX XXX XXX */ |
| 102 | printf("DRAM test not implemented!\n"); |
| 103 | |
| 104 | return (0); |
| 105 | } |