wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Yoo. Jonghoon, IPone, yooth@ipone.co.kr |
| 10 | * U-Boot port on RPXlite board |
| 11 | * |
| 12 | * DRAM related UPMA register values are modified. |
| 13 | * See RPXLite engineering note : 50MHz/60ns - UPM RAM WORDS |
| 14 | */ |
| 15 | |
| 16 | #include <common.h> |
| 17 | #include <mpc8xx.h> |
| 18 | |
| 19 | /* ------------------------------------------------------------------------- */ |
| 20 | |
| 21 | static long int dram_size (long int, long int *, long int); |
| 22 | |
| 23 | /* ------------------------------------------------------------------------- */ |
| 24 | |
| 25 | #define _NOT_USED_ 0xFFFFCC25 |
| 26 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 27 | const uint sdram_table[] = { |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 28 | /* |
| 29 | * Single Read. (Offset 00h in UPMA RAM) |
| 30 | */ |
| 31 | 0xCFFFCC24, 0x0FFFCC04, 0X0CAFCC04, 0X03AFCC08, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 32 | 0x3FBFCC27, /* last */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 33 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 34 | |
| 35 | /* |
| 36 | * Burst Read. (Offset 08h in UPMA RAM) |
| 37 | */ |
| 38 | 0xCFFFCC24, 0x0FFFCC04, 0x0CAFCC84, 0x03AFCC88, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 39 | 0x3FBFCC27, /* last */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 40 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 41 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 42 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 43 | |
| 44 | /* |
| 45 | * Single Write. (Offset 18h in UPMA RAM) |
| 46 | */ |
| 47 | 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC04, 0x03FFCC00, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 48 | 0x3FFFCC27, /* last */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 49 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 50 | |
| 51 | /* |
| 52 | * Burst Write. (Offset 20h in UPMA RAM) |
| 53 | */ |
| 54 | 0xCFFFCC24, 0x0FFFCC04, 0x0CFFCC80, 0x03FFCC8C, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 55 | 0x0CFFCC00, 0x33FFCC27, /* last */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 56 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 57 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 58 | _NOT_USED_, _NOT_USED_, |
| 59 | |
| 60 | /* |
| 61 | * Refresh. (Offset 30h in UPMA RAM) |
| 62 | */ |
| 63 | 0xC0FFCC24, 0x03FFCC24, 0x0FFFCC24, 0x0FFFCC24, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 64 | 0x3FFFCC27, /* last */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 65 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 66 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 67 | |
| 68 | /* |
| 69 | * Exception. (Offset 3Ch in UPMA RAM) |
| 70 | */ |
| 71 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_ |
| 72 | }; |
| 73 | |
| 74 | /* ------------------------------------------------------------------------- */ |
| 75 | |
| 76 | |
| 77 | /* |
| 78 | * Check Board Identity: |
| 79 | */ |
| 80 | |
| 81 | int checkboard (void) |
| 82 | { |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 83 | puts ("Board: RPXlite\n"); |
| 84 | return (0); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | /* ------------------------------------------------------------------------- */ |
| 88 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 89 | phys_size_t initdram (int board_type) |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 90 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 92 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 93 | long int size10; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 94 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 95 | upmconfig (UPMA, (uint *) sdram_table, |
| 96 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 97 | |
| 98 | /* Refresh clock prescalar */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 100 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 101 | memctl->memc_mar = 0x00000000; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 102 | |
| 103 | /* Map controller banks 1 to the SDRAM bank */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 105 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 106 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 107 | memctl->memc_mamr = CONFIG_SYS_MAMR_10COL & (~(MAMR_PTAE)); /* no refresh yet */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 108 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 109 | udelay (200); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 110 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 111 | /* perform SDRAM initializsation sequence */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 112 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 113 | memctl->memc_mcr = 0x80002230; /* SDRAM bank 0 - refresh twice */ |
| 114 | udelay (1); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 115 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 116 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 117 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 118 | udelay (1000); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 119 | |
| 120 | /* Check Bank 0 Memory Size |
| 121 | * try 10 column mode |
| 122 | */ |
| 123 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 124 | size10 = dram_size (CONFIG_SYS_MAMR_10COL, SDRAM_BASE_PRELIM, |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 125 | SDRAM_MAX_SIZE); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 126 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 127 | return (size10); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* ------------------------------------------------------------------------- */ |
| 131 | |
| 132 | /* |
| 133 | * Check memory range for valid RAM. A simple memory test determines |
| 134 | * the actually available RAM size between addresses `base' and |
| 135 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 136 | * - short between address lines |
| 137 | * - short between data lines |
| 138 | */ |
| 139 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 140 | static long int dram_size (long int mamr_value, long int *base, |
| 141 | long int maxsize) |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 142 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 143 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 144 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 145 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 146 | memctl->memc_mamr = mamr_value; |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 147 | |
wdenk | 87249ba | 2004-01-06 22:38:14 +0000 | [diff] [blame] | 148 | return (get_ram_size (base, maxsize)); |
wdenk | 5b1d713 | 2002-11-03 00:07:02 +0000 | [diff] [blame] | 149 | } |