]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/incaip/incaip.c
* Add support for MIPS32 4Kc CPUs
[karo-tx-uboot.git] / board / incaip / incaip.c
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
30 static ulong max_sdram_size(void)
31 {
32         /* The only supported SDRAM data width is 16bit.
33          */
34 #define CFG_DW  2
35
36         /* The only supported number of SDRAM banks is 4.
37          */
38 #define CFG_NB  4
39
40         ulong cfgpb0 = *INCA_IP_SDRAM_MC_CFGPB0;
41         int   cols   = cfgpb0 & 0xF;
42         int   rows   = (cfgpb0 & 0xF0) >> 4;
43         ulong size   = (1 << (rows + cols)) * CFG_DW * CFG_NB;
44
45         return size;
46 }
47
48 /*
49  * Check memory range for valid RAM. A simple memory test determines
50  * the actually available RAM size between addresses `base' and
51  * `base + maxsize'. Some (not all) hardware errors are detected:
52  * - short between address lines
53  * - short between data lines
54  */
55
56 static long int dram_size(long int *base, long int maxsize)
57 {
58         volatile long int *addr;
59         ulong cnt, val;
60         ulong save[32];                 /* to make test non-destructive */
61         unsigned char i = 0;
62
63         for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
64                 addr = base + cnt;              /* pointer arith! */
65
66                 save[i++] = *addr;
67                 *addr = ~cnt;
68         }
69
70         /* write 0 to base address */
71         addr = base;
72         save[i] = *addr;
73         *addr = 0;
74
75         /* check at base address */
76         if ((val = *addr) != 0) {
77                 *addr = save[i];
78                 return (0);
79         }
80
81         for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
82                 addr = base + cnt;              /* pointer arith! */
83
84                 val = *addr;
85                 *addr = save[--i];
86
87                 if (val != (~cnt)) {
88                         return (cnt * sizeof (long));
89                 }
90         }
91         return (maxsize);
92 }
93
94 long int initdram(int board_type)
95 {
96         int   rows, cols, best_val = *INCA_IP_SDRAM_MC_CFGPB0;
97         ulong size, max_size       = 0;
98         ulong our_address;
99
100         asm volatile ("move %0, $25" : "=r" (our_address) :);
101
102                 /* Can't probe for RAM size unless we are running from Flash.
103                  */
104         if (PHYSADDR(our_address) < PHYSADDR(PHYS_FLASH_1))
105         {
106                 return max_sdram_size();
107         }
108
109         for (cols = 0x8; cols <= 0xC; cols++)
110         {
111                 for (rows = 0xB; rows <= 0xD; rows++)
112                 {
113                         *INCA_IP_SDRAM_MC_CFGPB0 = (0x14 << 8) |
114                                                    (rows << 4) | cols;
115                         size = dram_size((ulong *)CFG_SDRAM_BASE,
116                                                              max_sdram_size());
117
118                         if (size > max_size)
119                         {
120                                 best_val = *INCA_IP_SDRAM_MC_CFGPB0;
121                                 max_size = size;
122                         }
123                 }
124         }
125
126         *INCA_IP_SDRAM_MC_CFGPB0 = best_val;
127         return max_size;
128 }
129