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