Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 7 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 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> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 14 | #include <asm/immap.h> |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | int checkboard(void) |
| 20 | { |
| 21 | puts("Board: "); |
| 22 | puts("Freescale M5235 EVB\n"); |
| 23 | return 0; |
| 24 | }; |
| 25 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 26 | int dram_init(void) |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 27 | { |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 28 | sdram_t *sdram = (sdram_t *)(MMAP_SDRAM); |
| 29 | gpio_t *gpio = (gpio_t *)(MMAP_GPIO); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 30 | u32 dramsize, i, dramclk; |
| 31 | |
| 32 | /* |
| 33 | * When booting from external Flash, the port-size is less than |
| 34 | * the port-size of SDRAM. In this case it is necessary to enable |
| 35 | * Data[15:0] on Port Address/Data. |
| 36 | */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 37 | out_8(&gpio->par_ad, |
| 38 | GPIO_PAR_AD_ADDR23 | GPIO_PAR_AD_ADDR22 | GPIO_PAR_AD_ADDR21 | |
| 39 | GPIO_PAR_AD_DATAL); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 40 | |
| 41 | /* Initialize PAR to enable SDRAM signals */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 42 | out_8(&gpio->par_sdram, |
| 43 | GPIO_PAR_SDRAM_SDWE | GPIO_PAR_SDRAM_SCAS | |
| 44 | GPIO_PAR_SDRAM_SRAS | GPIO_PAR_SDRAM_SCKE | |
| 45 | GPIO_PAR_SDRAM_SDCS(3)); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 46 | |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 47 | dramsize = CFG_SYS_SDRAM_SIZE * 0x100000; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 48 | for (i = 0x13; i < 0x20; i++) { |
| 49 | if (dramsize == (1 << i)) |
| 50 | break; |
| 51 | } |
| 52 | i--; |
| 53 | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 54 | if (!(in_be32(&sdram->dacr0) & SDRAMC_DARCn_RE)) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 55 | dramclk = gd->bus_clk / (CONFIG_SYS_HZ * CONFIG_SYS_HZ); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 56 | |
| 57 | /* Initialize DRAM Control Register: DCR */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 58 | out_be16(&sdram->dcr, SDRAMC_DCR_RTIM_9CLKS | |
| 59 | SDRAMC_DCR_RTIM_6CLKS | |
| 60 | SDRAMC_DCR_RC((15 * dramclk) >> 4)); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 61 | |
| 62 | /* Initialize DACR0 */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 63 | out_be32(&sdram->dacr0, |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 64 | SDRAMC_DARCn_BA(CFG_SYS_SDRAM_BASE) | |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 65 | SDRAMC_DARCn_CASL_C1 | SDRAMC_DARCn_CBM_CMD20 | |
| 66 | SDRAMC_DARCn_PS_32); |
TsiChung Liew | 94e3f0f | 2008-06-18 19:27:23 -0500 | [diff] [blame] | 67 | asm("nop"); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 68 | |
| 69 | /* Initialize DMR0 */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 70 | out_be32(&sdram->dmr0, |
| 71 | ((dramsize - 1) & 0xFFFC0000) | SDRAMC_DMRn_V); |
TsiChung Liew | 94e3f0f | 2008-06-18 19:27:23 -0500 | [diff] [blame] | 72 | asm("nop"); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 73 | |
| 74 | /* Set IP (bit 3) in DACR */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 75 | setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IP); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 76 | |
| 77 | /* Wait 30ns to allow banks to precharge */ |
| 78 | for (i = 0; i < 5; i++) { |
| 79 | asm("nop"); |
| 80 | } |
| 81 | |
| 82 | /* Write to this block to initiate precharge */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 83 | *(u32 *) (CFG_SYS_SDRAM_BASE) = 0xA5A59696; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 84 | |
| 85 | /* Set RE (bit 15) in DACR */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 86 | setbits_be32(&sdram->dacr0, SDRAMC_DARCn_RE); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 87 | |
| 88 | /* Wait for at least 8 auto refresh cycles to occur */ |
| 89 | for (i = 0; i < 0x2000; i++) { |
| 90 | asm("nop"); |
| 91 | } |
| 92 | |
| 93 | /* Finish the configuration by issuing the MRS. */ |
Alison Wang | d132fe6 | 2012-03-26 21:49:06 +0000 | [diff] [blame] | 94 | setbits_be32(&sdram->dacr0, SDRAMC_DARCn_IMRS); |
TsiChung Liew | 94e3f0f | 2008-06-18 19:27:23 -0500 | [diff] [blame] | 95 | asm("nop"); |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 96 | |
| 97 | /* Write to the SDRAM Mode Register */ |
Tom Rini | bb4dd96 | 2022-11-16 13:10:37 -0500 | [diff] [blame] | 98 | *(u32 *) (CFG_SYS_SDRAM_BASE + 0x400) = 0xA5A59696; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 101 | gd->ram_size = dramsize; |
| 102 | |
| 103 | return 0; |
TsiChungLiew | b859ef1 | 2007-08-16 19:23:50 -0500 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | int testdram(void) |
| 107 | { |
| 108 | /* TODO: XXX XXX XXX */ |
| 109 | printf("DRAM test not implemented!\n"); |
| 110 | |
| 111 | return (0); |
| 112 | } |