Merge git://git.infradead.org/mtd-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / mips / kernel / spram.c
blob6ddb507a87ef68faaf7e54b56e9698c874aafd22
1 /*
2 * MIPS SPRAM support
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
9 * Copyright (C) 2007, 2008 MIPS Technologies, Inc.
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/ptrace.h>
14 #include <linux/stddef.h>
16 #include <asm/cpu.h>
17 #include <asm/fpu.h>
18 #include <asm/mipsregs.h>
19 #include <asm/system.h>
20 #include <asm/r4kcache.h>
21 #include <asm/hazards.h>
24 * These definitions are correct for the 24K/34K/74K SPRAM sample
25 * implementation. The 4KS interpreted the tags differently...
27 #define SPRAM_TAG0_ENABLE 0x00000080
28 #define SPRAM_TAG0_PA_MASK 0xfffff000
29 #define SPRAM_TAG1_SIZE_MASK 0xfffff000
31 #define SPRAM_TAG_STRIDE 8
33 #define ERRCTL_SPRAM (1 << 28)
35 /* errctl access */
36 #define read_c0_errctl(x) read_c0_ecc(x)
37 #define write_c0_errctl(x) write_c0_ecc(x)
40 * Different semantics to the set_c0_* function built by __BUILD_SET_C0
42 static __cpuinit unsigned int bis_c0_errctl(unsigned int set)
44 unsigned int res;
45 res = read_c0_errctl();
46 write_c0_errctl(res | set);
47 return res;
50 static __cpuinit void ispram_store_tag(unsigned int offset, unsigned int data)
52 unsigned int errctl;
54 /* enable SPRAM tag access */
55 errctl = bis_c0_errctl(ERRCTL_SPRAM);
56 ehb();
58 write_c0_taglo(data);
59 ehb();
61 cache_op(Index_Store_Tag_I, CKSEG0|offset);
62 ehb();
64 write_c0_errctl(errctl);
65 ehb();
69 static __cpuinit unsigned int ispram_load_tag(unsigned int offset)
71 unsigned int data;
72 unsigned int errctl;
74 /* enable SPRAM tag access */
75 errctl = bis_c0_errctl(ERRCTL_SPRAM);
76 ehb();
77 cache_op(Index_Load_Tag_I, CKSEG0 | offset);
78 ehb();
79 data = read_c0_taglo();
80 ehb();
81 write_c0_errctl(errctl);
82 ehb();
84 return data;
87 static __cpuinit void dspram_store_tag(unsigned int offset, unsigned int data)
89 unsigned int errctl;
91 /* enable SPRAM tag access */
92 errctl = bis_c0_errctl(ERRCTL_SPRAM);
93 ehb();
94 write_c0_dtaglo(data);
95 ehb();
96 cache_op(Index_Store_Tag_D, CKSEG0 | offset);
97 ehb();
98 write_c0_errctl(errctl);
99 ehb();
103 static __cpuinit unsigned int dspram_load_tag(unsigned int offset)
105 unsigned int data;
106 unsigned int errctl;
108 errctl = bis_c0_errctl(ERRCTL_SPRAM);
109 ehb();
110 cache_op(Index_Load_Tag_D, CKSEG0 | offset);
111 ehb();
112 data = read_c0_dtaglo();
113 ehb();
114 write_c0_errctl(errctl);
115 ehb();
117 return data;
120 static __cpuinit void probe_spram(char *type,
121 unsigned int base,
122 unsigned int (*read)(unsigned int),
123 void (*write)(unsigned int, unsigned int))
125 unsigned int firstsize = 0, lastsize = 0;
126 unsigned int firstpa = 0, lastpa = 0, pa = 0;
127 unsigned int offset = 0;
128 unsigned int size, tag0, tag1;
129 unsigned int enabled;
130 int i;
133 * The limit is arbitrary but avoids the loop running away if
134 * the SPRAM tags are implemented differently
137 for (i = 0; i < 8; i++) {
138 tag0 = read(offset);
139 tag1 = read(offset+SPRAM_TAG_STRIDE);
140 pr_debug("DBG %s%d: tag0=%08x tag1=%08x\n",
141 type, i, tag0, tag1);
143 size = tag1 & SPRAM_TAG1_SIZE_MASK;
145 if (size == 0)
146 break;
148 if (i != 0) {
149 /* tags may repeat... */
150 if ((pa == firstpa && size == firstsize) ||
151 (pa == lastpa && size == lastsize))
152 break;
155 /* Align base with size */
156 base = (base + size - 1) & ~(size-1);
158 /* reprogram the base address base address and enable */
159 tag0 = (base & SPRAM_TAG0_PA_MASK) | SPRAM_TAG0_ENABLE;
160 write(offset, tag0);
162 base += size;
164 /* reread the tag */
165 tag0 = read(offset);
166 pa = tag0 & SPRAM_TAG0_PA_MASK;
167 enabled = tag0 & SPRAM_TAG0_ENABLE;
169 if (i == 0) {
170 firstpa = pa;
171 firstsize = size;
174 lastpa = pa;
175 lastsize = size;
177 if (strcmp(type, "DSPRAM") == 0) {
178 unsigned int *vp = (unsigned int *)(CKSEG1 | pa);
179 unsigned int v;
180 #define TDAT 0x5a5aa5a5
181 vp[0] = TDAT;
182 vp[1] = ~TDAT;
184 mb();
186 v = vp[0];
187 if (v != TDAT)
188 printk(KERN_ERR "vp=%p wrote=%08x got=%08x\n",
189 vp, TDAT, v);
190 v = vp[1];
191 if (v != ~TDAT)
192 printk(KERN_ERR "vp=%p wrote=%08x got=%08x\n",
193 vp+1, ~TDAT, v);
196 pr_info("%s%d: PA=%08x,Size=%08x%s\n",
197 type, i, pa, size, enabled ? ",enabled" : "");
198 offset += 2 * SPRAM_TAG_STRIDE;
202 __cpuinit void spram_config(void)
204 struct cpuinfo_mips *c = &current_cpu_data;
205 unsigned int config0;
207 switch (c->cputype) {
208 case CPU_24K:
209 case CPU_34K:
210 case CPU_74K:
211 config0 = read_c0_config();
212 /* FIXME: addresses are Malta specific */
213 if (config0 & (1<<24)) {
214 probe_spram("ISPRAM", 0x1c000000,
215 &ispram_load_tag, &ispram_store_tag);
217 if (config0 & (1<<23))
218 probe_spram("DSPRAM", 0x1c100000,
219 &dspram_load_tag, &dspram_store_tag);