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> */
9 In order to ensure that the BIOS checksum is correct at boot time, and
10 hence that the onboard BIOS extension gets executed, the DiskOnChip
11 goes into reset mode when it is read sequentially: all registers
12 return 0xff until the chip is woken up again by writing to the
15 Unfortunately, this means that the probe for the DiskOnChip is unsafe,
16 because one of the first things it does is write to where it thinks
17 the DOCControl register should be - which may well be shared memory
18 for another device. I've had machines which lock up when this is
19 attempted. Hence the possibility to do a passive probe, which will fail
20 to detect a chip in reset mode, but is at least guaranteed not to lock
23 If you have this problem, uncomment the following line:
24 #define DOC_PASSIVE_PROBE
29 Millennium driver has been merged into DOC2000 driver.
31 The old Millennium-only driver has been retained just in case there
32 are problems with the new code. If the combined driver doesn't work
33 for you, you can try the old one by undefining DOC_SINGLE_DRIVER
34 below and also enabling it in your configuration. If this fixes the
35 problems, please send a report to the MTD mailing list at
36 <linux-mtd@lists.infradead.org>.
38 #define DOC_SINGLE_DRIVER
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <asm/errno.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <linux/init.h>
47 #include <linux/types.h>
49 #include <linux/mtd/mtd.h>
50 #include <linux/mtd/nand.h>
51 #include <linux/mtd/doc2000.h>
52 #include <linux/mtd/compatmac.h>
54 /* Where to look for the devices? */
55 #ifndef CONFIG_MTD_DOCPROBE_ADDRESS
56 #define CONFIG_MTD_DOCPROBE_ADDRESS 0
60 static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
61 module_param(doc_config_location, ulong, 0);
62 MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
64 static unsigned long __initdata doc_locations[] = {
65 #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
66 #ifdef CONFIG_MTD_DOCPROBE_HIGH
67 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
68 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
69 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
70 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
71 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
72 #else /* CONFIG_MTD_DOCPROBE_HIGH */
73 0xc8000, 0xca000, 0xcc000, 0xce000,
74 0xd0000, 0xd2000, 0xd4000, 0xd6000,
75 0xd8000, 0xda000, 0xdc000, 0xde000,
76 0xe0000, 0xe2000, 0xe4000, 0xe6000,
77 0xe8000, 0xea000, 0xec000, 0xee000,
78 #endif /* CONFIG_MTD_DOCPROBE_HIGH */
79 #elif defined(__PPC__)
82 #warning Unknown architecture for DiskOnChip. No default probe locations defined
86 /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
88 static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
90 void __iomem *window=potential;
91 unsigned char tmp, tmpb, tmpc, ChipID;
92 #ifndef DOC_PASSIVE_PROBE
96 /* Routine copied from the Linux DOC driver */
98 #ifdef CONFIG_MTD_DOCPROBE_55AA
99 /* Check for 0x55 0xAA signature at beginning of window,
100 this is no longer true once we remove the IPL (for Millennium */
101 if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)
103 #endif /* CONFIG_MTD_DOCPROBE_55AA */
105 #ifndef DOC_PASSIVE_PROBE
106 /* It's not possible to cleanly detect the DiskOnChip - the
107 * bootup procedure will put the device into reset mode, and
108 * it's not possible to talk to it without actually writing
109 * to the DOCControl register. So we store the current contents
110 * of the DOCControl register's location, in case we later decide
111 * that it's not a DiskOnChip, and want to put it back how we
114 tmp2 = ReadDOC(window, DOCControl);
116 /* Reset the DiskOnChip ASIC */
117 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
119 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
122 /* Enable the DiskOnChip ASIC */
123 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
125 WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
127 #endif /* !DOC_PASSIVE_PROBE */
129 /* We need to read the ChipID register four times. For some
130 newer DiskOnChip 2000 units, the first three reads will
131 return the DiskOnChip Millennium ident. Don't ask. */
132 ChipID = ReadDOC(window, ChipID);
135 case DOC_ChipID_Doc2k:
136 /* Check the TOGGLE bit in the ECC register */
137 tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
138 tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
139 tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
140 if (tmp != tmpb && tmp == tmpc)
144 case DOC_ChipID_DocMil:
145 /* Check for the new 2000 with Millennium ASIC */
146 ReadDOC(window, ChipID);
147 ReadDOC(window, ChipID);
148 if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil)
149 ChipID = DOC_ChipID_Doc2kTSOP;
151 /* Check the TOGGLE bit in the ECC register */
152 tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
153 tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
154 tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
155 if (tmp != tmpb && tmp == tmpc)
159 case DOC_ChipID_DocMilPlus16:
160 case DOC_ChipID_DocMilPlus32:
162 /* Possible Millennium+, need to do more checks */
163 #ifndef DOC_PASSIVE_PROBE
164 /* Possibly release from power down mode */
165 for (tmp = 0; (tmp < 4); tmp++)
166 ReadDOC(window, Mplus_Power);
168 /* Reset the DiskOnChip ASIC */
169 tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
171 WriteDOC(tmp, window, Mplus_DOCControl);
172 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
175 /* Enable the DiskOnChip ASIC */
176 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
178 WriteDOC(tmp, window, Mplus_DOCControl);
179 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
181 #endif /* !DOC_PASSIVE_PROBE */
183 ChipID = ReadDOC(window, ChipID);
186 case DOC_ChipID_DocMilPlus16:
187 case DOC_ChipID_DocMilPlus32:
188 /* Check the TOGGLE bit in the toggle register */
189 tmp = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
190 tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
191 tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
192 if (tmp != tmpb && tmp == tmpc)
201 #ifdef CONFIG_MTD_DOCPROBE_55AA
202 printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
205 #ifndef DOC_PASSIVE_PROBE
206 /* Put back the contents of the DOCControl register, in case it's not
207 * actually a DiskOnChip.
209 WriteDOC(tmp2, window, DOCControl);
214 printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
216 #ifndef DOC_PASSIVE_PROBE
217 /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
218 WriteDOC(tmp2, window, DOCControl);
225 extern void DoC2k_init(struct mtd_info *);
226 extern void DoCMil_init(struct mtd_info *);
227 extern void DoCMilPlus_init(struct mtd_info *);
229 static void __init DoC_Probe(unsigned long physadr)
231 void __iomem *docptr;
232 struct DiskOnChip *this;
233 struct mtd_info *mtd;
236 char *name = namebuf;
237 void (*initroutine)(struct mtd_info *) = NULL;
239 docptr = ioremap(physadr, DOC_IOREMAP_LEN);
244 if ((ChipID = doccheck(docptr, physadr))) {
245 if (ChipID == DOC_ChipID_Doc2kTSOP) {
246 /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
247 printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n");
252 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
255 printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
260 this = (struct DiskOnChip *)(&mtd[1]);
262 memset((char *)mtd,0, sizeof(struct mtd_info));
263 memset((char *)this, 0, sizeof(struct DiskOnChip));
266 this->virtadr = docptr;
267 this->physadr = physadr;
268 this->ChipID = ChipID;
269 sprintf(namebuf, "with ChipID %2.2X", ChipID);
272 case DOC_ChipID_Doc2kTSOP:
274 initroutine = symbol_request(DoC2k_init);
277 case DOC_ChipID_Doc2k:
279 initroutine = symbol_request(DoC2k_init);
282 case DOC_ChipID_DocMil:
284 #ifdef DOC_SINGLE_DRIVER
285 initroutine = symbol_request(DoC2k_init);
287 initroutine = symbol_request(DoCMil_init);
288 #endif /* DOC_SINGLE_DRIVER */
291 case DOC_ChipID_DocMilPlus16:
292 case DOC_ChipID_DocMilPlus32:
293 name="MillenniumPlus";
294 initroutine = symbol_request(DoCMilPlus_init);
300 symbol_put_addr(initroutine);
303 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
310 /****************************************************************************
314 ****************************************************************************/
316 static int __init init_doc(void)
320 if (doc_config_location) {
321 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
322 DoC_Probe(doc_config_location);
324 for (i=0; (doc_locations[i] != 0xffffffff); i++) {
325 DoC_Probe(doc_locations[i]);
328 /* No banner message any more. Print a message if no DiskOnChip
329 found, so the user knows we at least tried. */
331 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
335 module_init(init_doc);
337 MODULE_LICENSE("GPL");
338 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
339 MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");