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> |
| 12 | #include <asm/immap.h> |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 14 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 17 | #define PERIOD 13 /* system bus period in ns */ |
| 18 | #define SDRAM_TREFI 7800 /* in ns */ |
| 19 | |
| 20 | int checkboard(void) |
| 21 | { |
| 22 | puts("Board: "); |
| 23 | puts("Freescale MCF5275 EVB\n"); |
| 24 | return 0; |
| 25 | }; |
| 26 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 27 | int dram_init(void) |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 28 | { |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 29 | sdramctrl_t *sdp = (sdramctrl_t *)(MMAP_SDRAM); |
| 30 | gpio_t *gpio_reg = (gpio_t *)(MMAP_GPIO); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 31 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 32 | /* Enable SDRAM */ |
| 33 | out_be16(&gpio_reg->par_sdram, 0x3FF); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 34 | |
| 35 | /* Set up chip select */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 36 | out_be32(&sdp->sdbar0, CONFIG_SYS_SDRAM_BASE); |
| 37 | 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] | 38 | |
| 39 | /* Set up timing */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 40 | out_be32(&sdp->sdcfg1, 0x83711630); |
| 41 | out_be32(&sdp->sdcfg2, 0x46770000); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 42 | |
| 43 | /* Enable clock */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 44 | 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] | 45 | |
| 46 | /* Set precharge */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 47 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 48 | |
| 49 | /* Dummy write to start SDRAM */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 51 | |
| 52 | /* Send LEMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 53 | setbits_be32(&sdp->sdmr, |
| 54 | MCF_SDRAMC_SDMR_BNKAD_LEMR | MCF_SDRAMC_SDMR_AD(0x0) | |
| 55 | MCF_SDRAMC_SDMR_CMD); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 57 | |
| 58 | /* Send LMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 59 | out_be32(&sdp->sdmr, 0x058d0000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 60 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 61 | |
| 62 | /* Stop sending commands */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 63 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 64 | |
| 65 | /* Set precharge */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 66 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 68 | |
| 69 | /* Stop manual precharge, send 2 IREF */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 70 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IPALL); |
| 71 | setbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_IREF); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 72 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
| 73 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 74 | |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 75 | |
| 76 | out_be32(&sdp->sdmr, 0x018d0000); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 77 | *((volatile unsigned long *)CONFIG_SYS_SDRAM_BASE) = 0xa5a59696; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 78 | |
| 79 | /* Stop sending commands */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 80 | clrbits_be32(&sdp->sdmr, MCF_SDRAMC_SDMR_CMD); |
| 81 | clrbits_be32(&sdp->sdcr, MCF_SDRAMC_SDCR_MODE_EN); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 82 | |
| 83 | /* Turn on auto refresh, lock SDMR */ |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 84 | out_be32(&sdp->sdcr, |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 85 | MCF_SDRAMC_SDCR_CKE |
| 86 | | MCF_SDRAMC_SDCR_REF |
| 87 | | MCF_SDRAMC_SDCR_MUX(1) |
| 88 | /* 1 added to round up */ |
| 89 | | MCF_SDRAMC_SDCR_RCNT((SDRAM_TREFI/(PERIOD*64)) - 1 + 1) |
Alison Wang | 95bed1f | 2012-03-26 21:49:04 +0000 | [diff] [blame] | 90 | | MCF_SDRAMC_SDCR_DQS_OE(0x3)); |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 91 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 92 | gd->ram_size = CONFIG_SYS_SDRAM_SIZE * 1024 * 1024; |
| 93 | |
| 94 | return 0; |
Matthew Fettke | 9f3b3bb | 2008-01-24 14:02:32 -0600 | [diff] [blame] | 95 | }; |
| 96 | |
| 97 | int testdram(void) |
| 98 | { |
| 99 | /* TODO: XXX XXX XXX */ |
| 100 | printf("DRAM test not implemented!\n"); |
| 101 | |
| 102 | return (0); |
| 103 | } |