Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2000-2003 |
| 4 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 5 | * |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 6 | * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc. |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 7 | * TsiChung Liew (Tsi-Chung.Liew@freescale.com) |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include <common.h> |
Simon Glass | 18afe10 | 2019-11-14 12:57:47 -0700 | [diff] [blame] | 12 | #include <init.h> |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 13 | #include <pci.h> |
| 14 | #include <asm/immap.h> |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 15 | #include <asm/io.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | int checkboard(void) |
| 21 | { |
| 22 | puts("Board: "); |
| 23 | puts("Freescale FireEngine 5475 EVB\n"); |
| 24 | return 0; |
| 25 | }; |
| 26 | |
Simon Glass | d35f338 | 2017-04-06 12:47:05 -0600 | [diff] [blame] | 27 | int dram_init(void) |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 28 | { |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 29 | siu_t *siu = (siu_t *) (MMAP_SIU); |
| 30 | sdram_t *sdram = (sdram_t *)(MMAP_SDRAM); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 31 | u32 dramsize, i; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 32 | #ifdef CONFIG_SYS_DRAMSZ1 |
TsiChung Liew | 4e37614 | 2008-03-17 12:09:07 -0500 | [diff] [blame] | 33 | u32 temp; |
| 34 | #endif |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 35 | |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 36 | out_be32(&siu->drv, CONFIG_SYS_SDRAM_DRVSTRENGTH); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 37 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 38 | dramsize = CONFIG_SYS_DRAMSZ * 0x100000; |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 39 | for (i = 0x13; i < 0x20; i++) { |
| 40 | if (dramsize == (1 << i)) |
| 41 | break; |
| 42 | } |
| 43 | i--; |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 44 | out_be32(&siu->cs0cfg, CONFIG_SYS_SDRAM_BASE | i); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 45 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_SYS_DRAMSZ1 |
| 47 | temp = CONFIG_SYS_DRAMSZ1 * 0x100000; |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 48 | for (i = 0x13; i < 0x20; i++) { |
| 49 | if (temp == (1 << i)) |
| 50 | break; |
| 51 | } |
| 52 | i--; |
| 53 | dramsize += temp; |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 54 | out_be32(&siu->cs1cfg, (CONFIG_SYS_SDRAM_BASE + temp) | i); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 55 | #endif |
| 56 | |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 57 | out_be32(&sdram->cfg1, CONFIG_SYS_SDRAM_CFG1); |
| 58 | out_be32(&sdram->cfg2, CONFIG_SYS_SDRAM_CFG2); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 59 | |
| 60 | /* Issue PALL */ |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 61 | out_be32(&sdram->ctrl, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 62 | |
| 63 | /* Issue LEMR */ |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 64 | out_be32(&sdram->mode, CONFIG_SYS_SDRAM_EMOD); |
| 65 | out_be32(&sdram->mode, CONFIG_SYS_SDRAM_MODE | 0x04000000); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 66 | |
| 67 | udelay(500); |
| 68 | |
| 69 | /* Issue PALL */ |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 70 | out_be32(&sdram->ctrl, CONFIG_SYS_SDRAM_CTRL | 2); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 71 | |
| 72 | /* Perform two refresh cycles */ |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 73 | out_be32(&sdram->ctrl, CONFIG_SYS_SDRAM_CTRL | 4); |
| 74 | out_be32(&sdram->ctrl, CONFIG_SYS_SDRAM_CTRL | 4); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 75 | |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 76 | out_be32(&sdram->mode, CONFIG_SYS_SDRAM_MODE); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 77 | |
Alison Wang | 027f76f | 2012-03-26 21:49:07 +0000 | [diff] [blame] | 78 | out_be32(&sdram->ctrl, |
| 79 | (CONFIG_SYS_SDRAM_CTRL & ~0x80000000) | 0x10000F00); |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 80 | |
| 81 | udelay(100); |
| 82 | |
Simon Glass | 39f90ba | 2017-03-31 08:40:25 -0600 | [diff] [blame] | 83 | gd->ram_size = dramsize; |
| 84 | |
| 85 | return 0; |
TsiChungLiew | 5b8943a | 2008-01-15 14:02:49 -0600 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | int testdram(void) |
| 89 | { |
| 90 | /* TODO: XXX XXX XXX */ |
| 91 | printf("DRAM test not implemented!\n"); |
| 92 | |
| 93 | return (0); |
| 94 | } |
| 95 | |
| 96 | #if defined(CONFIG_PCI) |
| 97 | /* |
| 98 | * Initialize PCI devices, report devices found. |
| 99 | */ |
| 100 | static struct pci_controller hose; |
| 101 | extern void pci_mcf547x_8x_init(struct pci_controller *hose); |
| 102 | |
| 103 | void pci_init_board(void) |
| 104 | { |
| 105 | pci_mcf547x_8x_init(&hose); |
| 106 | } |
| 107 | #endif /* CONFIG_PCI */ |