wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <command.h> |
| 26 | #include <asm/addrspace.h> |
| 27 | #include <asm/inca-ip.h> |
| 28 | |
| 29 | |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 30 | extern uint incaip_get_cpuclk(void); |
| 31 | |
wdenk | c021880 | 2003-03-27 12:09:35 +0000 | [diff] [blame] | 32 | static ulong max_sdram_size(void) |
| 33 | { |
| 34 | /* The only supported SDRAM data width is 16bit. |
| 35 | */ |
| 36 | #define CFG_DW 2 |
| 37 | |
| 38 | /* The only supported number of SDRAM banks is 4. |
| 39 | */ |
| 40 | #define CFG_NB 4 |
| 41 | |
| 42 | ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0; |
| 43 | int cols = cfgpb0 & 0xF; |
| 44 | int rows = (cfgpb0 & 0xF0) >> 4; |
| 45 | ulong size = (1 << (rows + cols)) * CFG_DW * CFG_NB; |
| 46 | |
| 47 | return size; |
| 48 | } |
| 49 | |
| 50 | /* |
| 51 | * Check memory range for valid RAM. A simple memory test determines |
| 52 | * the actually available RAM size between addresses `base' and |
| 53 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 54 | * - short between address lines |
| 55 | * - short between data lines |
| 56 | */ |
| 57 | |
| 58 | static long int dram_size(long int *base, long int maxsize) |
| 59 | { |
| 60 | volatile long int *addr; |
| 61 | ulong cnt, val; |
| 62 | ulong save[32]; /* to make test non-destructive */ |
| 63 | unsigned char i = 0; |
| 64 | |
| 65 | for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) { |
| 66 | addr = base + cnt; /* pointer arith! */ |
| 67 | |
| 68 | save[i++] = *addr; |
| 69 | *addr = ~cnt; |
| 70 | } |
| 71 | |
| 72 | /* write 0 to base address */ |
| 73 | addr = base; |
| 74 | save[i] = *addr; |
| 75 | *addr = 0; |
| 76 | |
| 77 | /* check at base address */ |
| 78 | if ((val = *addr) != 0) { |
| 79 | *addr = save[i]; |
| 80 | return (0); |
| 81 | } |
| 82 | |
| 83 | for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) { |
| 84 | addr = base + cnt; /* pointer arith! */ |
| 85 | |
| 86 | val = *addr; |
| 87 | *addr = save[--i]; |
| 88 | |
| 89 | if (val != (~cnt)) { |
| 90 | return (cnt * sizeof (long)); |
| 91 | } |
| 92 | } |
| 93 | return (maxsize); |
| 94 | } |
| 95 | |
| 96 | long int initdram(int board_type) |
| 97 | { |
| 98 | int rows, cols, best_val = *INCA_IP_SDRAM_MC_CFGPB0; |
| 99 | ulong size, max_size = 0; |
| 100 | ulong our_address; |
| 101 | |
| 102 | asm volatile ("move %0, $25" : "=r" (our_address) :); |
| 103 | |
| 104 | /* Can't probe for RAM size unless we are running from Flash. |
| 105 | */ |
| 106 | if (PHYSADDR(our_address) < PHYSADDR(PHYS_FLASH_1)) |
| 107 | { |
| 108 | return max_sdram_size(); |
| 109 | } |
| 110 | |
| 111 | for (cols = 0x8; cols <= 0xC; cols++) |
| 112 | { |
| 113 | for (rows = 0xB; rows <= 0xD; rows++) |
| 114 | { |
| 115 | *INCA_IP_SDRAM_MC_CFGPB0 = (0x14 << 8) | |
| 116 | (rows << 4) | cols; |
| 117 | size = dram_size((ulong *)CFG_SDRAM_BASE, |
| 118 | max_sdram_size()); |
| 119 | |
| 120 | if (size > max_size) |
| 121 | { |
| 122 | best_val = *INCA_IP_SDRAM_MC_CFGPB0; |
| 123 | max_size = size; |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | *INCA_IP_SDRAM_MC_CFGPB0 = best_val; |
| 129 | return max_size; |
| 130 | } |
| 131 | |
wdenk | 85ec0bc | 2003-03-31 16:34:49 +0000 | [diff] [blame] | 132 | int checkboard (void) |
| 133 | { |
| 134 | |
| 135 | unsigned long chipid = *INCA_IP_WDT_CHIPID; |
| 136 | int part_num; |
| 137 | |
| 138 | puts ("Board: INCA-IP "); |
| 139 | part_num = (chipid >> 12) & 0xffff; |
| 140 | switch (part_num) { |
| 141 | case 0xc0: |
| 142 | printf ("Standard Version, "); |
| 143 | break; |
| 144 | case 0xc1: |
| 145 | printf ("Basic Version, "); |
| 146 | break; |
| 147 | default: |
| 148 | printf ("Unknown Part Number 0x%x ", part_num); |
| 149 | break; |
| 150 | } |
| 151 | |
| 152 | printf ("Chip V1.%ld, ", (chipid >> 28)); |
| 153 | |
| 154 | printf("CPU Speed %d MHz\n", incaip_get_cpuclk()/1000000); |
| 155 | |
| 156 | return 0; |
| 157 | } |