MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / drivers / mtd / devices / docprobe.c
blob58396ac44c409b92a40943f3b6e6afeefaf4ba76
2 /* Linux driver for Disk-On-Chip devices */
3 /* Probe routines common to all DoC devices */
4 /* (C) 1999 Machine Vision Holdings, Inc. */
5 /* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> */
7 /* $Id: docprobe.c,v 1.46 2005/11/07 11:14:25 gleixner Exp $ */
11 /* DOC_PASSIVE_PROBE:
12 In order to ensure that the BIOS checksum is correct at boot time, and
13 hence that the onboard BIOS extension gets executed, the DiskOnChip
14 goes into reset mode when it is read sequentially: all registers
15 return 0xff until the chip is woken up again by writing to the
16 DOCControl register.
18 Unfortunately, this means that the probe for the DiskOnChip is unsafe,
19 because one of the first things it does is write to where it thinks
20 the DOCControl register should be - which may well be shared memory
21 for another device. I've had machines which lock up when this is
22 attempted. Hence the possibility to do a passive probe, which will fail
23 to detect a chip in reset mode, but is at least guaranteed not to lock
24 the machine.
26 If you have this problem, uncomment the following line:
27 #define DOC_PASSIVE_PROBE
31 /* DOC_SINGLE_DRIVER:
32 Millennium driver has been merged into DOC2000 driver.
34 The old Millennium-only driver has been retained just in case there
35 are problems with the new code. If the combined driver doesn't work
36 for you, you can try the old one by undefining DOC_SINGLE_DRIVER
37 below and also enabling it in your configuration. If this fixes the
38 problems, please send a report to the MTD mailing list at
39 <linux-mtd@lists.infradead.org>.
41 #define DOC_SINGLE_DRIVER
43 #include <linux/kernel.h>
44 #include <linux/module.h>
45 #include <asm/errno.h>
46 #include <asm/io.h>
47 #include <linux/delay.h>
48 #include <linux/slab.h>
49 #include <linux/init.h>
50 #include <linux/types.h>
52 #include <linux/mtd/mtd.h>
53 #include <linux/mtd/nand.h>
54 #include <linux/mtd/doc2000.h>
55 #include <linux/mtd/compatmac.h>
57 /* Where to look for the devices? */
58 #ifndef CONFIG_MTD_DOCPROBE_ADDRESS
59 #define CONFIG_MTD_DOCPROBE_ADDRESS 0
60 #endif
63 static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
64 module_param(doc_config_location, ulong, 0);
65 MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
67 static unsigned long __initdata doc_locations[] = {
68 #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
69 #ifdef CONFIG_MTD_DOCPROBE_HIGH
70 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
71 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
72 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
73 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
74 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
75 #else /* CONFIG_MTD_DOCPROBE_HIGH */
76 0xc8000, 0xca000, 0xcc000, 0xce000,
77 0xd0000, 0xd2000, 0xd4000, 0xd6000,
78 0xd8000, 0xda000, 0xdc000, 0xde000,
79 0xe0000, 0xe2000, 0xe4000, 0xe6000,
80 0xe8000, 0xea000, 0xec000, 0xee000,
81 #endif /* CONFIG_MTD_DOCPROBE_HIGH */
82 #elif defined(__PPC__)
83 0xe4000000,
84 #elif defined(CONFIG_MOMENCO_OCELOT)
85 0x2f000000,
86 0xff000000,
87 #elif defined(CONFIG_MOMENCO_OCELOT_G) || defined (CONFIG_MOMENCO_OCELOT_C)
88 0xff000000,
89 #elif defined(CONFIG_SH_SECUREEDGE5410)
90 0x00000000,
91 0x04000000,
92 #elif defined(CONFIG_MACH_ESS710) || defined(CONFIG_MACH_SE5100)
93 0x50000000,
94 #else
95 #warning Unknown architecture for DiskOnChip. No default probe locations defined
96 #endif
97 0xffffffff };
99 /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
101 static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
103 void __iomem *window=potential;
104 unsigned char tmp, tmpb, tmpc, 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 /* We need to read the ChipID register four times. For some
143 newer DiskOnChip 2000 units, the first three reads will
144 return the DiskOnChip Millennium ident. Don't ask. */
145 ChipID = ReadDOC(window, ChipID);
147 switch (ChipID) {
148 case DOC_ChipID_Doc2k:
149 /* Check the TOGGLE bit in the ECC register */
150 tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
151 tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
152 tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
153 if (tmp != tmpb && tmp == tmpc)
154 return ChipID;
155 break;
157 case DOC_ChipID_DocMil:
158 /* Check for the new 2000 with Millennium ASIC */
159 ReadDOC(window, ChipID);
160 ReadDOC(window, ChipID);
161 if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil)
162 ChipID = DOC_ChipID_Doc2kTSOP;
164 /* Check the TOGGLE bit in the ECC register */
165 tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
166 tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
167 tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
168 if (tmp != tmpb && tmp == tmpc)
169 return ChipID;
170 break;
172 case DOC_ChipID_DocMilPlus16:
173 case DOC_ChipID_DocMilPlus32:
174 case 0:
175 /* Possible Millennium+, need to do more checks */
176 #ifndef DOC_PASSIVE_PROBE
177 /* Possibly release from power down mode */
178 for (tmp = 0; (tmp < 4); tmp++)
179 ReadDOC(window, Mplus_Power);
181 /* Reset the DiskOnChip ASIC */
182 tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
183 DOC_MODE_BDECT;
184 WriteDOC(tmp, window, Mplus_DOCControl);
185 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
187 mdelay(1);
188 /* Enable the DiskOnChip ASIC */
189 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
190 DOC_MODE_BDECT;
191 WriteDOC(tmp, window, Mplus_DOCControl);
192 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
193 mdelay(1);
194 #endif /* !DOC_PASSIVE_PROBE */
196 ChipID = ReadDOC(window, ChipID);
198 switch (ChipID) {
199 case DOC_ChipID_DocMilPlus16:
200 case DOC_ChipID_DocMilPlus32:
201 /* Check the TOGGLE bit in the toggle register */
202 tmp = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
203 tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
204 tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
205 if (tmp != tmpb && tmp == tmpc)
206 return ChipID;
207 default:
208 break;
210 /* FALL TRHU */
212 default:
214 #ifdef CONFIG_MTD_DOCPROBE_55AA
215 printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
216 ChipID, physadr);
217 #endif
218 #ifndef DOC_PASSIVE_PROBE
219 /* Put back the contents of the DOCControl register, in case it's not
220 * actually a DiskOnChip.
222 WriteDOC(tmp2, window, DOCControl);
223 #endif
224 return 0;
227 printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
229 #ifndef DOC_PASSIVE_PROBE
230 /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
231 WriteDOC(tmp2, window, DOCControl);
232 #endif
233 return 0;
236 static int docfound;
238 extern void DoC2k_init(struct mtd_info *);
239 extern void DoCMil_init(struct mtd_info *);
240 extern void DoCMilPlus_init(struct mtd_info *);
242 static void __init DoC_Probe(unsigned long physadr)
244 void __iomem *docptr;
245 struct DiskOnChip *this;
246 struct mtd_info *mtd;
247 int ChipID;
248 char namebuf[15];
249 char *name = namebuf;
250 void (*initroutine)(struct mtd_info *) = NULL;
252 docptr = ioremap(physadr, DOC_IOREMAP_LEN);
254 if (!docptr)
255 return;
257 if ((ChipID = doccheck(docptr, physadr))) {
258 if (ChipID == DOC_ChipID_Doc2kTSOP) {
259 /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
260 printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n");
261 iounmap(docptr);
262 return;
264 docfound = 1;
265 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
267 if (!mtd) {
268 printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
269 iounmap(docptr);
270 return;
273 this = (struct DiskOnChip *)(&mtd[1]);
275 memset((char *)mtd,0, sizeof(struct mtd_info));
276 memset((char *)this, 0, sizeof(struct DiskOnChip));
278 mtd->priv = this;
279 this->virtadr = docptr;
280 this->physadr = physadr;
281 this->ChipID = ChipID;
282 sprintf(namebuf, "with ChipID %2.2X", ChipID);
284 switch(ChipID) {
285 case DOC_ChipID_Doc2kTSOP:
286 name="2000 TSOP";
287 initroutine = symbol_request(DoC2k_init);
288 break;
290 case DOC_ChipID_Doc2k:
291 name="2000";
292 initroutine = symbol_request(DoC2k_init);
293 break;
295 case DOC_ChipID_DocMil:
296 name="Millennium";
297 #ifdef DOC_SINGLE_DRIVER
298 initroutine = symbol_request(DoC2k_init);
299 #else
300 initroutine = symbol_request(DoCMil_init);
301 #endif /* DOC_SINGLE_DRIVER */
302 break;
304 case DOC_ChipID_DocMilPlus16:
305 case DOC_ChipID_DocMilPlus32:
306 name="MillenniumPlus";
307 initroutine = symbol_request(DoCMilPlus_init);
308 break;
311 if (initroutine) {
312 (*initroutine)(mtd);
313 symbol_put_addr(initroutine);
314 return;
316 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
317 kfree(mtd);
319 iounmap(docptr);
323 /****************************************************************************
325 * Module stuff
327 ****************************************************************************/
329 static int __init init_doc(void)
331 int i;
333 if (doc_config_location) {
334 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
335 DoC_Probe(doc_config_location);
336 } else {
337 for (i=0; (doc_locations[i] != 0xffffffff); i++) {
338 DoC_Probe(doc_locations[i]);
341 /* No banner message any more. Print a message if no DiskOnChip
342 found, so the user knows we at least tried. */
343 if (!docfound)
344 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
345 return -EAGAIN;
348 module_init(init_doc);
350 MODULE_LICENSE("GPL");
351 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
352 MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");