Support for Ocelot C. Still doesn't work, SR71000 support is
[linux-2.6/linux-mips.git] / drivers / mtd / devices / docprobe.c
blobe33bffbb8a6d534d4fc91bd61c0da2f48727c203
2 /* Linux driver for Disk-On-Chip devices */
3 /* Probe routines common to all DoC devices */
4 /* (c) 1999 Machine Vision Holdings, Inc. */
5 /* Author: David Woodhouse <dwmw2@infradead.org> */
6 /* $Id: docprobe.c,v 1.30 2001/10/02 15:05:13 dwmw2 Exp $ */
10 /* DOC_PASSIVE_PROBE:
11 In order to ensure that the BIOS checksum is correct at boot time, and
12 hence that the onboard BIOS extension gets executed, the DiskOnChip
13 goes into reset mode when it is read sequentially: all registers
14 return 0xff until the chip is woken up again by writing to the
15 DOCControl register.
17 Unfortunately, this means that the probe for the DiskOnChip is unsafe,
18 because one of the first things it does is write to where it thinks
19 the DOCControl register should be - which may well be shared memory
20 for another device. I've had machines which lock up when this is
21 attempted. Hence the possibility to do a passive probe, which will fail
22 to detect a chip in reset mode, but is at least guaranteed not to lock
23 the machine.
25 If you have this problem, uncomment the following line:
26 #define DOC_PASSIVE_PROBE
30 /* DOC_SINGLE_DRIVER:
31 Millennium driver has been merged into DOC2000 driver.
33 The newly-merged driver doesn't appear to work for writing. It's the
34 same with the DiskOnChip 2000 and the Millennium. If you have a
35 Millennium and you want write support to work, remove the definition
36 of DOC_SINGLE_DRIVER below to use the old doc2001-specific driver.
38 Otherwise, it's left on in the hope that it'll annoy someone with
39 a Millennium enough that they go through and work out what the
40 difference is :)
42 #define DOC_SINGLE_DRIVER
44 #include <linux/config.h>
45 #include <linux/kernel.h>
46 #include <linux/module.h>
47 #include <asm/errno.h>
48 #include <asm/io.h>
49 #include <asm/uaccess.h>
50 #include <linux/miscdevice.h>
51 #include <linux/pci.h>
52 #include <linux/delay.h>
53 #include <linux/slab.h>
54 #include <linux/sched.h>
55 #include <linux/init.h>
56 #include <linux/types.h>
58 #include <linux/mtd/mtd.h>
59 #include <linux/mtd/nand.h>
60 #include <linux/mtd/doc2000.h>
62 /* Where to look for the devices? */
63 #ifndef CONFIG_MTD_DOCPROBE_ADDRESS
64 #define CONFIG_MTD_DOCPROBE_ADDRESS 0
65 #endif
68 static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
69 MODULE_PARM(doc_config_location, "l");
72 static unsigned long __initdata doc_locations[] = {
73 #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
74 #ifdef CONFIG_MTD_DOCPROBE_HIGH
75 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
76 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
77 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
78 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
79 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
80 #else /* CONFIG_MTD_DOCPROBE_HIGH */
81 0xc8000, 0xca000, 0xcc000, 0xce000,
82 0xd0000, 0xd2000, 0xd4000, 0xd6000,
83 0xd8000, 0xda000, 0xdc000, 0xde000,
84 0xe0000, 0xe2000, 0xe4000, 0xe6000,
85 0xe8000, 0xea000, 0xec000, 0xee000,
86 #endif /* CONFIG_MTD_DOCPROBE_HIGH */
87 #elif defined(__ppc__)
88 0xe4000000,
89 #elif defined(CONFIG_MOMENCO_OCELOT)
90 0x2f000000,
91 0xff000000,
92 #elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C)
93 0xff000000,
94 #else
95 #warning Unknown architecture for DiskOnChip. No default probe locations defined
96 #endif
97 0 };
99 /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
101 static inline int __init doccheck(unsigned long potential, unsigned long physadr)
103 unsigned long window=potential;
104 unsigned char tmp, ChipID;
105 #ifndef DOC_PASSIVE_PROBE
106 unsigned char tmp2;
107 #endif
109 /* Routine copied from the Linux DOC driver */
111 #ifdef CONFIG_MTD_DOCPROBE_55AA
112 /* Check for 0x55 0xAA signature at beginning of window,
113 this is no longer true once we remove the IPL (for Millennium */
114 if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)
115 return 0;
116 #endif /* CONFIG_MTD_DOCPROBE_55AA */
118 #ifndef DOC_PASSIVE_PROBE
119 /* It's not possible to cleanly detect the DiskOnChip - the
120 * bootup procedure will put the device into reset mode, and
121 * it's not possible to talk to it without actually writing
122 * to the DOCControl register. So we store the current contents
123 * of the DOCControl register's location, in case we later decide
124 * that it's not a DiskOnChip, and want to put it back how we
125 * found it.
127 tmp2 = ReadDOC(window, DOCControl);
129 /* Reset the DiskOnChip ASIC */
130 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
131 window, DOCControl);
132 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
133 window, DOCControl);
135 /* Enable the DiskOnChip ASIC */
136 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
137 window, DOCControl);
138 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
139 window, DOCControl);
140 #endif /* !DOC_PASSIVE_PROBE */
142 ChipID = ReadDOC(window, ChipID);
144 switch (ChipID) {
145 case DOC_ChipID_Doc2k:
146 /* Check the TOGGLE bit in the ECC register */
147 tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
148 if ((ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT) != tmp)
149 return ChipID;
150 break;
152 case DOC_ChipID_DocMil:
153 /* Check the TOGGLE bit in the ECC register */
154 tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
155 if ((ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT) != tmp)
156 return ChipID;
157 break;
159 default:
160 #ifndef CONFIG_MTD_DOCPROBE_55AA
161 printk(KERN_WARNING "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
162 ChipID, physadr);
163 #endif
164 #ifndef DOC_PASSIVE_PROBE
165 /* Put back the contents of the DOCControl register, in case it's not
166 * actually a DiskOnChip.
168 WriteDOC(tmp2, window, DOCControl);
169 #endif
170 return 0;
173 printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
175 #ifndef DOC_PASSIVE_PROBE
176 /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
177 WriteDOC(tmp2, window, DOCControl);
178 #endif
179 return 0;
182 static int docfound;
184 static void __init DoC_Probe(unsigned long physadr)
186 unsigned long docptr;
187 struct DiskOnChip *this;
188 struct mtd_info *mtd;
189 int ChipID;
190 char namebuf[15];
191 char *name = namebuf;
192 char *im_funcname = NULL;
193 char *im_modname = NULL;
194 void (*initroutine)(struct mtd_info *) = NULL;
196 docptr = (unsigned long)ioremap(physadr, DOC_IOREMAP_LEN);
198 if (!docptr)
199 return;
201 if ((ChipID = doccheck(docptr, physadr))) {
202 docfound = 1;
203 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
205 if (!mtd) {
206 printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
207 iounmap((void *)docptr);
208 return;
211 this = (struct DiskOnChip *)(&mtd[1]);
213 memset((char *)mtd,0, sizeof(struct mtd_info));
214 memset((char *)this, 0, sizeof(struct DiskOnChip));
216 mtd->priv = this;
217 this->virtadr = docptr;
218 this->physadr = physadr;
219 this->ChipID = ChipID;
220 sprintf(namebuf, "with ChipID %2.2X", ChipID);
222 switch(ChipID) {
223 case DOC_ChipID_Doc2k:
224 name="2000";
225 im_funcname = "DoC2k_init";
226 im_modname = "doc2000";
227 break;
229 case DOC_ChipID_DocMil:
230 name="Millennium";
231 #ifdef DOC_SINGLE_DRIVER
232 im_funcname = "DoC2k_init";
233 im_modname = "doc2000";
234 #else
235 im_funcname = "DoCMil_init";
236 im_modname = "doc2001";
237 #endif /* DOC_SINGLE_DRIVER */
238 break;
241 if (im_funcname)
242 initroutine = inter_module_get_request(im_funcname, im_modname);
244 if (initroutine) {
245 (*initroutine)(mtd);
246 inter_module_put(im_funcname);
247 return;
249 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
251 iounmap((void *)docptr);
255 /****************************************************************************
257 * Module stuff
259 ****************************************************************************/
261 int __init init_doc(void)
263 int i;
265 if (doc_config_location) {
266 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
267 DoC_Probe(doc_config_location);
268 } else {
269 for (i=0; doc_locations[i]; i++) {
270 DoC_Probe(doc_locations[i]);
273 /* No banner message any more. Print a message if no DiskOnChip
274 found, so the user knows we at least tried. */
275 if (!docfound)
276 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
277 /* So it looks like we've been used and we get unloaded */
278 MOD_INC_USE_COUNT;
279 MOD_DEC_USE_COUNT;
280 return 0;
284 module_init(init_doc);
286 MODULE_LICENSE("GPL");
287 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
288 MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");