4 * Copyright (C) 2007 OpenWrt.org
5 * Copyright (C) 2007 Gabor Juhos <juhosg@freemail.hu>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include <linux/init.h>
25 #include <linux/types.h>
26 #include <linux/kernel.h>
28 #include <asm/bootinfo.h>
29 #include <asm/addrspace.h>
31 #include <asm/mach-adm5120/adm5120_info.h>
32 #include <asm/mach-adm5120/adm5120_defs.h>
33 #include <asm/mach-adm5120/adm5120_switch.h>
34 #include <asm/mach-adm5120/adm5120_mpmc.h>
36 #define SWITCH_READ(r) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))
37 #define SWITCH_WRITE(r,v) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))=(v)
39 #define MPMC_READ(r) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))
40 #define MPMC_WRITE(r,v) *(u32 *)(KSEG1ADDR(ADM5120_SWITCH_BASE)+(r))=(v)
43 # define mem_dbg(f, a...) printk("mem_detect: " f, ## a)
45 # define mem_dbg(f, a...)
48 #define MEM_WR_DELAY 10000 /* 0.01 usec */
50 unsigned long adm5120_memsize
;
52 static int __init
mem_check_pattern(u8
*addr
, unsigned long offs
)
54 volatile u32
*p1
= (volatile u32
*)addr
;
55 volatile u32
*p2
= (volatile u32
*)(addr
+offs
);
58 /* save original value */
69 mem_dbg("write 0x%08lX to 0x%08lX\n", v
, (unsigned long)p1
);
72 mem_dbg("delay %d ns\n", MEM_WR_DELAY
);
73 adm5120_ndelay(MEM_WR_DELAY
);
76 mem_dbg("pattern at 0x%08lX is 0x%08lX\n", (unsigned long)p2
, u
);
78 /* restore original value */
84 static void __init
adm5120_detect_memsize(void)
90 memctrl
= SWITCH_READ(SWITCH_REG_MEMCTRL
);
91 switch (memctrl
& MEMCTRL_SDRS_MASK
) {
98 case MEMCTRL_SDRS_16M
:
106 /* disable buffers for both SDRAM banks */
107 mem_dbg("disable buffers for both banks\n");
108 MPMC_WRITE(MPMC_REG_DC0
, MPMC_READ(MPMC_REG_DC0
) & ~DC_BE
);
109 MPMC_WRITE(MPMC_REG_DC1
, MPMC_READ(MPMC_REG_DC1
) & ~DC_BE
);
111 mem_dbg("checking for %ldMB chip in 1st bank\n", maxsize
>> 20);
113 /* detect size of the 1st SDRAM bank */
114 p
= (u8
*)KSEG1ADDR(0);
115 for (size
= 2<<20; size
<= (maxsize
>> 1); size
<<= 1) {
116 if (mem_check_pattern(p
, size
)) {
117 /* mirrored address */
118 mem_dbg("mirrored data found at offset 0x%lX\n", size
);
123 mem_dbg("chip size in 1st bank is %ldMB\n", size
>> 20);
124 adm5120_memsize
= size
;
127 /* 2nd bank is not supported */
130 if ((memctrl
& MEMCTRL_SDR1_ENABLE
) == 0)
131 /* 2nd bank is disabled */
135 * some bootloaders enable 2nd bank, even if the 2nd SDRAM chip
138 mem_dbg("check presence of 2nd bank\n");
140 p
= (u8
*)KSEG1ADDR(maxsize
+size
-4);
141 if (mem_check_pattern(p
, 0)) {
142 adm5120_memsize
+= size
;
145 if (maxsize
!= size
) {
146 /* adjusting MECTRL register */
147 memctrl
&= ~(MEMCTRL_SDRS_MASK
);
150 memctrl
|= MEMCTRL_SDRS_4M
;
153 memctrl
|= MEMCTRL_SDRS_8M
;
156 memctrl
|= MEMCTRL_SDRS_16M
;
159 memctrl
|= MEMCTRL_SDRS_64M
;
162 SWITCH_WRITE(SWITCH_REG_MEMCTRL
, memctrl
);
166 /* reenable buffer for both SDRAM banks */
167 mem_dbg("enable buffers for both banks\n");
168 MPMC_WRITE(MPMC_REG_DC0
, MPMC_READ(MPMC_REG_DC0
) | DC_BE
);
169 MPMC_WRITE(MPMC_REG_DC1
, MPMC_READ(MPMC_REG_DC1
) | DC_BE
);
171 mem_dbg("%dx%ldMB memory found\n", (adm5120_memsize
== size
) ? 1 : 2 ,
175 void __init
adm5120_mem_init(void)
177 adm5120_detect_memsize();
178 add_memory_region(0, adm5120_memsize
, BOOT_MEM_RAM
);
This page took 0.056529 seconds and 5 git commands to generate.