]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mtd/devices/docprobe.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[linux-2.6-omap-h63xx.git] / drivers / mtd / devices / docprobe.c
1
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
7 /* $Id: docprobe.c,v 1.46 2005/11/07 11:14:25 gleixner Exp $    */
8
9
10
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.
17
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.
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
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>.
40 */
41 #define DOC_SINGLE_DRIVER
42
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>
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
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");
66
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 ##else
88 #warning Unknown architecture for DiskOnChip. No default probe locations defined
89 #endif
90         0xffffffff };
91
92 /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
93
94 static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
95 {
96         void __iomem *window=potential;
97         unsigned char tmp, tmpb, tmpc, ChipID;
98 #ifndef DOC_PASSIVE_PROBE
99         unsigned char tmp2;
100 #endif
101
102         /* Routine copied from the Linux DOC driver */
103
104 #ifdef CONFIG_MTD_DOCPROBE_55AA
105         /* Check for 0x55 0xAA signature at beginning of window,
106            this is no longer true once we remove the IPL (for Millennium */
107         if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)
108                 return 0;
109 #endif /* CONFIG_MTD_DOCPROBE_55AA */
110
111 #ifndef DOC_PASSIVE_PROBE
112         /* It's not possible to cleanly detect the DiskOnChip - the
113          * bootup procedure will put the device into reset mode, and
114          * it's not possible to talk to it without actually writing
115          * to the DOCControl register. So we store the current contents
116          * of the DOCControl register's location, in case we later decide
117          * that it's not a DiskOnChip, and want to put it back how we
118          * found it.
119          */
120         tmp2 = ReadDOC(window, DOCControl);
121
122         /* Reset the DiskOnChip ASIC */
123         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
124                  window, DOCControl);
125         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
126                  window, DOCControl);
127
128         /* Enable the DiskOnChip ASIC */
129         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
130                  window, DOCControl);
131         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
132                  window, DOCControl);
133 #endif /* !DOC_PASSIVE_PROBE */
134
135         /* We need to read the ChipID register four times. For some
136            newer DiskOnChip 2000 units, the first three reads will
137            return the DiskOnChip Millennium ident. Don't ask. */
138         ChipID = ReadDOC(window, ChipID);
139
140         switch (ChipID) {
141         case DOC_ChipID_Doc2k:
142                 /* Check the TOGGLE bit in the ECC register */
143                 tmp  = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
144                 tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
145                 tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
146                 if (tmp != tmpb && tmp == tmpc)
147                                 return ChipID;
148                 break;
149
150         case DOC_ChipID_DocMil:
151                 /* Check for the new 2000 with Millennium ASIC */
152                 ReadDOC(window, ChipID);
153                 ReadDOC(window, ChipID);
154                 if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil)
155                         ChipID = DOC_ChipID_Doc2kTSOP;
156
157                 /* Check the TOGGLE bit in the ECC register */
158                 tmp  = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
159                 tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
160                 tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
161                 if (tmp != tmpb && tmp == tmpc)
162                                 return ChipID;
163                 break;
164
165         case DOC_ChipID_DocMilPlus16:
166         case DOC_ChipID_DocMilPlus32:
167         case 0:
168                 /* Possible Millennium+, need to do more checks */
169 #ifndef DOC_PASSIVE_PROBE
170                 /* Possibly release from power down mode */
171                 for (tmp = 0; (tmp < 4); tmp++)
172                         ReadDOC(window, Mplus_Power);
173
174                 /* Reset the DiskOnChip ASIC */
175                 tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
176                         DOC_MODE_BDECT;
177                 WriteDOC(tmp, window, Mplus_DOCControl);
178                 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
179
180                 mdelay(1);
181                 /* Enable the DiskOnChip ASIC */
182                 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
183                         DOC_MODE_BDECT;
184                 WriteDOC(tmp, window, Mplus_DOCControl);
185                 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
186                 mdelay(1);
187 #endif /* !DOC_PASSIVE_PROBE */
188
189                 ChipID = ReadDOC(window, ChipID);
190
191                 switch (ChipID) {
192                 case DOC_ChipID_DocMilPlus16:
193                 case DOC_ChipID_DocMilPlus32:
194                         /* Check the TOGGLE bit in the toggle register */
195                         tmp  = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
196                         tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
197                         tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
198                         if (tmp != tmpb && tmp == tmpc)
199                                         return ChipID;
200                 default:
201                         break;
202                 }
203                 /* FALL TRHU */
204
205         default:
206
207 #ifdef CONFIG_MTD_DOCPROBE_55AA
208                 printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
209                        ChipID, physadr);
210 #endif
211 #ifndef DOC_PASSIVE_PROBE
212                 /* Put back the contents of the DOCControl register, in case it's not
213                  * actually a DiskOnChip.
214                  */
215                 WriteDOC(tmp2, window, DOCControl);
216 #endif
217                 return 0;
218         }
219
220         printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
221
222 #ifndef DOC_PASSIVE_PROBE
223         /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
224         WriteDOC(tmp2, window, DOCControl);
225 #endif
226         return 0;
227 }
228
229 static int docfound;
230
231 extern void DoC2k_init(struct mtd_info *);
232 extern void DoCMil_init(struct mtd_info *);
233 extern void DoCMilPlus_init(struct mtd_info *);
234
235 static void __init DoC_Probe(unsigned long physadr)
236 {
237         void __iomem *docptr;
238         struct DiskOnChip *this;
239         struct mtd_info *mtd;
240         int ChipID;
241         char namebuf[15];
242         char *name = namebuf;
243         void (*initroutine)(struct mtd_info *) = NULL;
244
245         docptr = ioremap(physadr, DOC_IOREMAP_LEN);
246
247         if (!docptr)
248                 return;
249
250         if ((ChipID = doccheck(docptr, physadr))) {
251                 if (ChipID == DOC_ChipID_Doc2kTSOP) {
252                         /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
253                         printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n");
254                         iounmap(docptr);
255                         return;
256                 }
257                 docfound = 1;
258                 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
259
260                 if (!mtd) {
261                         printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
262                         iounmap(docptr);
263                         return;
264                 }
265
266                 this = (struct DiskOnChip *)(&mtd[1]);
267
268                 memset((char *)mtd,0, sizeof(struct mtd_info));
269                 memset((char *)this, 0, sizeof(struct DiskOnChip));
270
271                 mtd->priv = this;
272                 this->virtadr = docptr;
273                 this->physadr = physadr;
274                 this->ChipID = ChipID;
275                 sprintf(namebuf, "with ChipID %2.2X", ChipID);
276
277                 switch(ChipID) {
278                 case DOC_ChipID_Doc2kTSOP:
279                         name="2000 TSOP";
280                         initroutine = symbol_request(DoC2k_init);
281                         break;
282
283                 case DOC_ChipID_Doc2k:
284                         name="2000";
285                         initroutine = symbol_request(DoC2k_init);
286                         break;
287
288                 case DOC_ChipID_DocMil:
289                         name="Millennium";
290 #ifdef DOC_SINGLE_DRIVER
291                         initroutine = symbol_request(DoC2k_init);
292 #else
293                         initroutine = symbol_request(DoCMil_init);
294 #endif /* DOC_SINGLE_DRIVER */
295                         break;
296
297                 case DOC_ChipID_DocMilPlus16:
298                 case DOC_ChipID_DocMilPlus32:
299                         name="MillenniumPlus";
300                         initroutine = symbol_request(DoCMilPlus_init);
301                         break;
302                 }
303
304                 if (initroutine) {
305                         (*initroutine)(mtd);
306                         symbol_put_addr(initroutine);
307                         return;
308                 }
309                 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
310                 kfree(mtd);
311         }
312         iounmap(docptr);
313 }
314
315
316 /****************************************************************************
317  *
318  * Module stuff
319  *
320  ****************************************************************************/
321
322 static int __init init_doc(void)
323 {
324         int i;
325
326         if (doc_config_location) {
327                 printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
328                 DoC_Probe(doc_config_location);
329         } else {
330                 for (i=0; (doc_locations[i] != 0xffffffff); i++) {
331                         DoC_Probe(doc_locations[i]);
332                 }
333         }
334         /* No banner message any more. Print a message if no DiskOnChip
335            found, so the user knows we at least tried. */
336         if (!docfound)
337                 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
338         return -EAGAIN;
339 }
340
341 module_init(init_doc);
342
343 MODULE_LICENSE("GPL");
344 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
345 MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");
346