]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/mtd/devices/docprobe.c
6e5d811ae83af8dc23f06ef660e23810e09c2663
[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
8 /* DOC_PASSIVE_PROBE:
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
13    DOCControl register.
14
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
21    the machine.
22
23    If you have this problem, uncomment the following line:
24 #define DOC_PASSIVE_PROBE
25 */
26
27
28 /* DOC_SINGLE_DRIVER:
29    Millennium driver has been merged into DOC2000 driver.
30
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>.
37 */
38 #define DOC_SINGLE_DRIVER
39
40 #include <linux/kernel.h>
41 #include <linux/module.h>
42 #include <asm/errno.h>
43 #include <asm/io.h>
44 #include <linux/delay.h>
45 #include <linux/slab.h>
46 #include <linux/init.h>
47 #include <linux/types.h>
48
49 #include <linux/mtd/mtd.h>
50 #include <linux/mtd/nand.h>
51 #include <linux/mtd/doc2000.h>
52 #include <linux/mtd/compatmac.h>
53
54 /* Where to look for the devices? */
55 #ifndef CONFIG_MTD_DOCPROBE_ADDRESS
56 #define CONFIG_MTD_DOCPROBE_ADDRESS 0
57 #endif
58
59
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");
63
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__)
80         0xe4000000,
81 #else
82 #warning Unknown architecture for DiskOnChip. No default probe locations defined
83 #endif
84         0xffffffff };
85
86 /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
87
88 static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
89 {
90         void __iomem *window=potential;
91         unsigned char tmp, tmpb, tmpc, ChipID;
92 #ifndef DOC_PASSIVE_PROBE
93         unsigned char tmp2;
94 #endif
95
96         /* Routine copied from the Linux DOC driver */
97
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)
102                 return 0;
103 #endif /* CONFIG_MTD_DOCPROBE_55AA */
104
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
112          * found it.
113          */
114         tmp2 = ReadDOC(window, DOCControl);
115
116         /* Reset the DiskOnChip ASIC */
117         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
118                  window, DOCControl);
119         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
120                  window, DOCControl);
121
122         /* Enable the DiskOnChip ASIC */
123         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
124                  window, DOCControl);
125         WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
126                  window, DOCControl);
127 #endif /* !DOC_PASSIVE_PROBE */
128
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);
133
134         switch (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)
141                                 return ChipID;
142                 break;
143
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;
150
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)
156                                 return ChipID;
157                 break;
158
159         case DOC_ChipID_DocMilPlus16:
160         case DOC_ChipID_DocMilPlus32:
161         case 0:
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);
167
168                 /* Reset the DiskOnChip ASIC */
169                 tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
170                         DOC_MODE_BDECT;
171                 WriteDOC(tmp, window, Mplus_DOCControl);
172                 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
173
174                 mdelay(1);
175                 /* Enable the DiskOnChip ASIC */
176                 tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
177                         DOC_MODE_BDECT;
178                 WriteDOC(tmp, window, Mplus_DOCControl);
179                 WriteDOC(~tmp, window, Mplus_CtrlConfirm);
180                 mdelay(1);
181 #endif /* !DOC_PASSIVE_PROBE */
182
183                 ChipID = ReadDOC(window, ChipID);
184
185                 switch (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)
193                                         return ChipID;
194                 default:
195                         break;
196                 }
197                 /* FALL TRHU */
198
199         default:
200
201 #ifdef CONFIG_MTD_DOCPROBE_55AA
202                 printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
203                        ChipID, physadr);
204 #endif
205 #ifndef DOC_PASSIVE_PROBE
206                 /* Put back the contents of the DOCControl register, in case it's not
207                  * actually a DiskOnChip.
208                  */
209                 WriteDOC(tmp2, window, DOCControl);
210 #endif
211                 return 0;
212         }
213
214         printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
215
216 #ifndef DOC_PASSIVE_PROBE
217         /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
218         WriteDOC(tmp2, window, DOCControl);
219 #endif
220         return 0;
221 }
222
223 static int docfound;
224
225 extern void DoC2k_init(struct mtd_info *);
226 extern void DoCMil_init(struct mtd_info *);
227 extern void DoCMilPlus_init(struct mtd_info *);
228
229 static void __init DoC_Probe(unsigned long physadr)
230 {
231         void __iomem *docptr;
232         struct DiskOnChip *this;
233         struct mtd_info *mtd;
234         int ChipID;
235         char namebuf[15];
236         char *name = namebuf;
237         void (*initroutine)(struct mtd_info *) = NULL;
238
239         docptr = ioremap(physadr, DOC_IOREMAP_LEN);
240
241         if (!docptr)
242                 return;
243
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");
248                         iounmap(docptr);
249                         return;
250                 }
251                 docfound = 1;
252                 mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
253
254                 if (!mtd) {
255                         printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
256                         iounmap(docptr);
257                         return;
258                 }
259
260                 this = (struct DiskOnChip *)(&mtd[1]);
261
262                 memset((char *)mtd,0, sizeof(struct mtd_info));
263                 memset((char *)this, 0, sizeof(struct DiskOnChip));
264
265                 mtd->priv = this;
266                 this->virtadr = docptr;
267                 this->physadr = physadr;
268                 this->ChipID = ChipID;
269                 sprintf(namebuf, "with ChipID %2.2X", ChipID);
270
271                 switch(ChipID) {
272                 case DOC_ChipID_Doc2kTSOP:
273                         name="2000 TSOP";
274                         initroutine = symbol_request(DoC2k_init);
275                         break;
276
277                 case DOC_ChipID_Doc2k:
278                         name="2000";
279                         initroutine = symbol_request(DoC2k_init);
280                         break;
281
282                 case DOC_ChipID_DocMil:
283                         name="Millennium";
284 #ifdef DOC_SINGLE_DRIVER
285                         initroutine = symbol_request(DoC2k_init);
286 #else
287                         initroutine = symbol_request(DoCMil_init);
288 #endif /* DOC_SINGLE_DRIVER */
289                         break;
290
291                 case DOC_ChipID_DocMilPlus16:
292                 case DOC_ChipID_DocMilPlus32:
293                         name="MillenniumPlus";
294                         initroutine = symbol_request(DoCMilPlus_init);
295                         break;
296                 }
297
298                 if (initroutine) {
299                         (*initroutine)(mtd);
300                         symbol_put_addr(initroutine);
301                         return;
302                 }
303                 printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
304                 kfree(mtd);
305         }
306         iounmap(docptr);
307 }
308
309
310 /****************************************************************************
311  *
312  * Module stuff
313  *
314  ****************************************************************************/
315
316 static int __init init_doc(void)
317 {
318         int i;
319
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);
323         } else {
324                 for (i=0; (doc_locations[i] != 0xffffffff); i++) {
325                         DoC_Probe(doc_locations[i]);
326                 }
327         }
328         /* No banner message any more. Print a message if no DiskOnChip
329            found, so the user knows we at least tried. */
330         if (!docfound)
331                 printk(KERN_INFO "No recognised DiskOnChip devices found\n");
332         return -EAGAIN;
333 }
334
335 module_init(init_doc);
336
337 MODULE_LICENSE("GPL");
338 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
339 MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");
340