blob: d8cc94ec4e504495421c5a3a558c02cdf8fff024 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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> */
6
Thomas Gleixnere5580fb2005-11-07 11:15:40 +00007/* $Id: docprobe.c,v 1.46 2005/11/07 11:14:25 gleixner Exp $ */
Linus Torvalds1da177e2005-04-16 15:20:36 -07008
9
10
11/* DOC_PASSIVE_PROBE:
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000012 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.
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000018 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 to detect a chip in reset mode, but is at least guaranteed not to lock
24 the machine.
25
26 If you have this problem, uncomment the following line:
27#define DOC_PASSIVE_PROBE
28*/
29
30
31/* DOC_SINGLE_DRIVER:
32 Millennium driver has been merged into DOC2000 driver.
33
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
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000036 for you, you can try the old one by undefining DOC_SINGLE_DRIVER
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 below and also enabling it in your configuration. If this fixes the
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000038 problems, please send a report to the MTD mailing list at
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 <linux-mtd@lists.infradead.org>.
40*/
41#define DOC_SINGLE_DRIVER
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#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>
51
52#include <linux/mtd/mtd.h>
53#include <linux/mtd/nand.h>
54#include <linux/mtd/doc2000.h>
55#include <linux/mtd/compatmac.h>
56
57/* Where to look for the devices? */
58#ifndef CONFIG_MTD_DOCPROBE_ADDRESS
59#define CONFIG_MTD_DOCPROBE_ADDRESS 0
60#endif
61
62
63static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
64module_param(doc_config_location, ulong, 0);
65MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
66
67static unsigned long __initdata doc_locations[] = {
68#if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
69#ifdef CONFIG_MTD_DOCPROBE_HIGH
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000070 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000072 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
73 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
75#else /* CONFIG_MTD_DOCPROBE_HIGH */
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000076 0xc8000, 0xca000, 0xcc000, 0xce000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 0xd0000, 0xd2000, 0xd4000, 0xd6000,
Thomas Gleixnere5580fb2005-11-07 11:15:40 +000078 0xd8000, 0xda000, 0xdc000, 0xde000,
79 0xe0000, 0xe2000, 0xe4000, 0xe6000,
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 0xe8000, 0xea000, 0xec000, 0xee000,
81#endif /* CONFIG_MTD_DOCPROBE_HIGH */
82#elif defined(__PPC__)
83 0xe4000000,
David Woodhouse440fdb52007-08-01 11:23:57 +010084#else
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#warning Unknown architecture for DiskOnChip. No default probe locations defined
86#endif
87 0xffffffff };
88
89/* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
90
91static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
92{
93 void __iomem *window=potential;
94 unsigned char tmp, tmpb, tmpc, ChipID;
95#ifndef DOC_PASSIVE_PROBE
96 unsigned char tmp2;
97#endif
98
99 /* Routine copied from the Linux DOC driver */
100
101#ifdef CONFIG_MTD_DOCPROBE_55AA
102 /* Check for 0x55 0xAA signature at beginning of window,
103 this is no longer true once we remove the IPL (for Millennium */
104 if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)
105 return 0;
106#endif /* CONFIG_MTD_DOCPROBE_55AA */
107
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000108#ifndef DOC_PASSIVE_PROBE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 /* It's not possible to cleanly detect the DiskOnChip - the
110 * bootup procedure will put the device into reset mode, and
111 * it's not possible to talk to it without actually writing
112 * to the DOCControl register. So we store the current contents
113 * of the DOCControl register's location, in case we later decide
114 * that it's not a DiskOnChip, and want to put it back how we
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000115 * found it.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 */
117 tmp2 = ReadDOC(window, DOCControl);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 /* Reset the DiskOnChip ASIC */
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000120 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 window, DOCControl);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000122 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 window, DOCControl);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /* Enable the DiskOnChip ASIC */
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000126 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 window, DOCControl);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000128 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 window, DOCControl);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000130#endif /* !DOC_PASSIVE_PROBE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* We need to read the ChipID register four times. For some
133 newer DiskOnChip 2000 units, the first three reads will
134 return the DiskOnChip Millennium ident. Don't ask. */
135 ChipID = ReadDOC(window, ChipID);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 switch (ChipID) {
138 case DOC_ChipID_Doc2k:
139 /* Check the TOGGLE bit in the ECC register */
140 tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
141 tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
142 tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
143 if (tmp != tmpb && tmp == tmpc)
144 return ChipID;
145 break;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 case DOC_ChipID_DocMil:
148 /* Check for the new 2000 with Millennium ASIC */
149 ReadDOC(window, ChipID);
150 ReadDOC(window, ChipID);
151 if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil)
152 ChipID = DOC_ChipID_Doc2kTSOP;
153
154 /* Check the TOGGLE bit in the ECC register */
155 tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
156 tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
157 tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
158 if (tmp != tmpb && tmp == tmpc)
159 return ChipID;
160 break;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 case DOC_ChipID_DocMilPlus16:
163 case DOC_ChipID_DocMilPlus32:
164 case 0:
165 /* Possible Millennium+, need to do more checks */
166#ifndef DOC_PASSIVE_PROBE
167 /* Possibly release from power down mode */
168 for (tmp = 0; (tmp < 4); tmp++)
169 ReadDOC(window, Mplus_Power);
170
171 /* Reset the DiskOnChip ASIC */
172 tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
173 DOC_MODE_BDECT;
174 WriteDOC(tmp, window, Mplus_DOCControl);
175 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 mdelay(1);
178 /* Enable the DiskOnChip ASIC */
179 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
180 DOC_MODE_BDECT;
181 WriteDOC(tmp, window, Mplus_DOCControl);
182 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
183 mdelay(1);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000184#endif /* !DOC_PASSIVE_PROBE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 ChipID = ReadDOC(window, ChipID);
187
188 switch (ChipID) {
189 case DOC_ChipID_DocMilPlus16:
190 case DOC_ChipID_DocMilPlus32:
191 /* Check the TOGGLE bit in the toggle register */
192 tmp = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
193 tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
194 tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
195 if (tmp != tmpb && tmp == tmpc)
196 return ChipID;
197 default:
198 break;
199 }
200 /* FALL TRHU */
201
202 default:
203
204#ifdef CONFIG_MTD_DOCPROBE_55AA
205 printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
206 ChipID, physadr);
207#endif
208#ifndef DOC_PASSIVE_PROBE
209 /* Put back the contents of the DOCControl register, in case it's not
210 * actually a DiskOnChip.
211 */
212 WriteDOC(tmp2, window, DOCControl);
213#endif
214 return 0;
215 }
216
217 printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
218
219#ifndef DOC_PASSIVE_PROBE
220 /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
221 WriteDOC(tmp2, window, DOCControl);
222#endif
223 return 0;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000224}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226static int docfound;
227
David Woodhouse396674e2006-05-08 17:10:11 +0100228extern void DoC2k_init(struct mtd_info *);
David Woodhouse396674e2006-05-08 17:10:11 +0100229extern void DoCMil_init(struct mtd_info *);
David Woodhouse396674e2006-05-08 17:10:11 +0100230extern void DoCMilPlus_init(struct mtd_info *);
David Woodhouse396674e2006-05-08 17:10:11 +0100231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232static void __init DoC_Probe(unsigned long physadr)
233{
234 void __iomem *docptr;
235 struct DiskOnChip *this;
236 struct mtd_info *mtd;
237 int ChipID;
238 char namebuf[15];
239 char *name = namebuf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 void (*initroutine)(struct mtd_info *) = NULL;
241
242 docptr = ioremap(physadr, DOC_IOREMAP_LEN);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 if (!docptr)
245 return;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 if ((ChipID = doccheck(docptr, physadr))) {
248 if (ChipID == DOC_ChipID_Doc2kTSOP) {
249 /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
250 printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n");
251 iounmap(docptr);
252 return;
253 }
254 docfound = 1;
255 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
256
257 if (!mtd) {
258 printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
259 iounmap(docptr);
260 return;
261 }
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 this = (struct DiskOnChip *)(&mtd[1]);
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000264
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 memset((char *)mtd,0, sizeof(struct mtd_info));
266 memset((char *)this, 0, sizeof(struct DiskOnChip));
267
268 mtd->priv = this;
269 this->virtadr = docptr;
270 this->physadr = physadr;
271 this->ChipID = ChipID;
272 sprintf(namebuf, "with ChipID %2.2X", ChipID);
273
274 switch(ChipID) {
275 case DOC_ChipID_Doc2kTSOP:
276 name="2000 TSOP";
David Woodhouseecde2632006-05-21 18:38:51 +0100277 initroutine = symbol_request(DoC2k_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 break;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case DOC_ChipID_Doc2k:
281 name="2000";
David Woodhouseecde2632006-05-21 18:38:51 +0100282 initroutine = symbol_request(DoC2k_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 break;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000284
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 case DOC_ChipID_DocMil:
286 name="Millennium";
287#ifdef DOC_SINGLE_DRIVER
David Woodhouseecde2632006-05-21 18:38:51 +0100288 initroutine = symbol_request(DoC2k_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289#else
David Woodhouseecde2632006-05-21 18:38:51 +0100290 initroutine = symbol_request(DoCMil_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291#endif /* DOC_SINGLE_DRIVER */
292 break;
293
294 case DOC_ChipID_DocMilPlus16:
295 case DOC_ChipID_DocMilPlus32:
296 name="MillenniumPlus";
David Woodhouseecde2632006-05-21 18:38:51 +0100297 initroutine = symbol_request(DoCMilPlus_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 break;
299 }
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 if (initroutine) {
302 (*initroutine)(mtd);
David Woodhouse5e535422006-05-08 14:05:05 +0100303 symbol_put_addr(initroutine);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 return;
305 }
306 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
307 kfree(mtd);
308 }
309 iounmap(docptr);
310}
311
312
313/****************************************************************************
314 *
315 * Module stuff
316 *
317 ****************************************************************************/
318
319static int __init init_doc(void)
320{
321 int i;
Thomas Gleixnere5580fb2005-11-07 11:15:40 +0000322
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 if (doc_config_location) {
324 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
325 DoC_Probe(doc_config_location);
326 } else {
327 for (i=0; (doc_locations[i] != 0xffffffff); i++) {
328 DoC_Probe(doc_locations[i]);
329 }
330 }
331 /* No banner message any more. Print a message if no DiskOnChip
332 found, so the user knows we at least tried. */
333 if (!docfound)
334 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
335 return -EAGAIN;
336}
337
338module_init(init_doc);
339
340MODULE_LICENSE("GPL");
341MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
342MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");
343