docprobe.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /* Linux driver for Disk-On-Chip devices */
  2. /* Probe routines common to all DoC devices */
  3. /* (C) 1999 Machine Vision Holdings, Inc. */
  4. /* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> */
  5. /* $Id: docprobe.c,v 1.46 2005/11/07 11:14:25 gleixner Exp $ */
  6. /* DOC_PASSIVE_PROBE:
  7. In order to ensure that the BIOS checksum is correct at boot time, and
  8. hence that the onboard BIOS extension gets executed, the DiskOnChip
  9. goes into reset mode when it is read sequentially: all registers
  10. return 0xff until the chip is woken up again by writing to the
  11. DOCControl register.
  12. Unfortunately, this means that the probe for the DiskOnChip is unsafe,
  13. because one of the first things it does is write to where it thinks
  14. the DOCControl register should be - which may well be shared memory
  15. for another device. I've had machines which lock up when this is
  16. attempted. Hence the possibility to do a passive probe, which will fail
  17. to detect a chip in reset mode, but is at least guaranteed not to lock
  18. the machine.
  19. If you have this problem, uncomment the following line:
  20. #define DOC_PASSIVE_PROBE
  21. */
  22. /* DOC_SINGLE_DRIVER:
  23. Millennium driver has been merged into DOC2000 driver.
  24. The old Millennium-only driver has been retained just in case there
  25. are problems with the new code. If the combined driver doesn't work
  26. for you, you can try the old one by undefining DOC_SINGLE_DRIVER
  27. below and also enabling it in your configuration. If this fixes the
  28. problems, please send a report to the MTD mailing list at
  29. <linux-mtd@lists.infradead.org>.
  30. */
  31. #define DOC_SINGLE_DRIVER
  32. #include <linux/kernel.h>
  33. #include <linux/module.h>
  34. #include <asm/errno.h>
  35. #include <asm/io.h>
  36. #include <linux/delay.h>
  37. #include <linux/slab.h>
  38. #include <linux/init.h>
  39. #include <linux/types.h>
  40. #include <linux/mtd/mtd.h>
  41. #include <linux/mtd/nand.h>
  42. #include <linux/mtd/doc2000.h>
  43. #include <linux/mtd/compatmac.h>
  44. /* Where to look for the devices? */
  45. #ifndef CONFIG_MTD_DOCPROBE_ADDRESS
  46. #define CONFIG_MTD_DOCPROBE_ADDRESS 0
  47. #endif
  48. static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS;
  49. module_param(doc_config_location, ulong, 0);
  50. MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip");
  51. static unsigned long __initdata doc_locations[] = {
  52. #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__)
  53. #ifdef CONFIG_MTD_DOCPROBE_HIGH
  54. 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000,
  55. 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000,
  56. 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000,
  57. 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000,
  58. 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000,
  59. #else /* CONFIG_MTD_DOCPROBE_HIGH */
  60. 0xc8000, 0xca000, 0xcc000, 0xce000,
  61. 0xd0000, 0xd2000, 0xd4000, 0xd6000,
  62. 0xd8000, 0xda000, 0xdc000, 0xde000,
  63. 0xe0000, 0xe2000, 0xe4000, 0xe6000,
  64. 0xe8000, 0xea000, 0xec000, 0xee000,
  65. #endif /* CONFIG_MTD_DOCPROBE_HIGH */
  66. #elif defined(__PPC__)
  67. 0xe4000000,
  68. #else
  69. #warning Unknown architecture for DiskOnChip. No default probe locations defined
  70. #endif
  71. 0xffffffff };
  72. /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */
  73. static inline int __init doccheck(void __iomem *potential, unsigned long physadr)
  74. {
  75. void __iomem *window=potential;
  76. unsigned char tmp, tmpb, tmpc, ChipID;
  77. #ifndef DOC_PASSIVE_PROBE
  78. unsigned char tmp2;
  79. #endif
  80. /* Routine copied from the Linux DOC driver */
  81. #ifdef CONFIG_MTD_DOCPROBE_55AA
  82. /* Check for 0x55 0xAA signature at beginning of window,
  83. this is no longer true once we remove the IPL (for Millennium */
  84. if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa)
  85. return 0;
  86. #endif /* CONFIG_MTD_DOCPROBE_55AA */
  87. #ifndef DOC_PASSIVE_PROBE
  88. /* It's not possible to cleanly detect the DiskOnChip - the
  89. * bootup procedure will put the device into reset mode, and
  90. * it's not possible to talk to it without actually writing
  91. * to the DOCControl register. So we store the current contents
  92. * of the DOCControl register's location, in case we later decide
  93. * that it's not a DiskOnChip, and want to put it back how we
  94. * found it.
  95. */
  96. tmp2 = ReadDOC(window, DOCControl);
  97. /* Reset the DiskOnChip ASIC */
  98. WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
  99. window, DOCControl);
  100. WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET,
  101. window, DOCControl);
  102. /* Enable the DiskOnChip ASIC */
  103. WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
  104. window, DOCControl);
  105. WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL,
  106. window, DOCControl);
  107. #endif /* !DOC_PASSIVE_PROBE */
  108. /* We need to read the ChipID register four times. For some
  109. newer DiskOnChip 2000 units, the first three reads will
  110. return the DiskOnChip Millennium ident. Don't ask. */
  111. ChipID = ReadDOC(window, ChipID);
  112. switch (ChipID) {
  113. case DOC_ChipID_Doc2k:
  114. /* Check the TOGGLE bit in the ECC register */
  115. tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
  116. tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
  117. tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT;
  118. if (tmp != tmpb && tmp == tmpc)
  119. return ChipID;
  120. break;
  121. case DOC_ChipID_DocMil:
  122. /* Check for the new 2000 with Millennium ASIC */
  123. ReadDOC(window, ChipID);
  124. ReadDOC(window, ChipID);
  125. if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil)
  126. ChipID = DOC_ChipID_Doc2kTSOP;
  127. /* Check the TOGGLE bit in the ECC register */
  128. tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
  129. tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
  130. tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT;
  131. if (tmp != tmpb && tmp == tmpc)
  132. return ChipID;
  133. break;
  134. case DOC_ChipID_DocMilPlus16:
  135. case DOC_ChipID_DocMilPlus32:
  136. case 0:
  137. /* Possible Millennium+, need to do more checks */
  138. #ifndef DOC_PASSIVE_PROBE
  139. /* Possibly release from power down mode */
  140. for (tmp = 0; (tmp < 4); tmp++)
  141. ReadDOC(window, Mplus_Power);
  142. /* Reset the DiskOnChip ASIC */
  143. tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
  144. DOC_MODE_BDECT;
  145. WriteDOC(tmp, window, Mplus_DOCControl);
  146. WriteDOC(~tmp, window, Mplus_CtrlConfirm);
  147. mdelay(1);
  148. /* Enable the DiskOnChip ASIC */
  149. tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT |
  150. DOC_MODE_BDECT;
  151. WriteDOC(tmp, window, Mplus_DOCControl);
  152. WriteDOC(~tmp, window, Mplus_CtrlConfirm);
  153. mdelay(1);
  154. #endif /* !DOC_PASSIVE_PROBE */
  155. ChipID = ReadDOC(window, ChipID);
  156. switch (ChipID) {
  157. case DOC_ChipID_DocMilPlus16:
  158. case DOC_ChipID_DocMilPlus32:
  159. /* Check the TOGGLE bit in the toggle register */
  160. tmp = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
  161. tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
  162. tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT;
  163. if (tmp != tmpb && tmp == tmpc)
  164. return ChipID;
  165. default:
  166. break;
  167. }
  168. /* FALL TRHU */
  169. default:
  170. #ifdef CONFIG_MTD_DOCPROBE_55AA
  171. printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n",
  172. ChipID, physadr);
  173. #endif
  174. #ifndef DOC_PASSIVE_PROBE
  175. /* Put back the contents of the DOCControl register, in case it's not
  176. * actually a DiskOnChip.
  177. */
  178. WriteDOC(tmp2, window, DOCControl);
  179. #endif
  180. return 0;
  181. }
  182. printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n");
  183. #ifndef DOC_PASSIVE_PROBE
  184. /* Put back the contents of the DOCControl register: it's not a DiskOnChip */
  185. WriteDOC(tmp2, window, DOCControl);
  186. #endif
  187. return 0;
  188. }
  189. static int docfound;
  190. extern void DoC2k_init(struct mtd_info *);
  191. extern void DoCMil_init(struct mtd_info *);
  192. extern void DoCMilPlus_init(struct mtd_info *);
  193. static void __init DoC_Probe(unsigned long physadr)
  194. {
  195. void __iomem *docptr;
  196. struct DiskOnChip *this;
  197. struct mtd_info *mtd;
  198. int ChipID;
  199. char namebuf[15];
  200. char *name = namebuf;
  201. void (*initroutine)(struct mtd_info *) = NULL;
  202. docptr = ioremap(physadr, DOC_IOREMAP_LEN);
  203. if (!docptr)
  204. return;
  205. if ((ChipID = doccheck(docptr, physadr))) {
  206. if (ChipID == DOC_ChipID_Doc2kTSOP) {
  207. /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */
  208. printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n");
  209. iounmap(docptr);
  210. return;
  211. }
  212. docfound = 1;
  213. mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL);
  214. if (!mtd) {
  215. printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n");
  216. iounmap(docptr);
  217. return;
  218. }
  219. this = (struct DiskOnChip *)(&mtd[1]);
  220. memset((char *)mtd,0, sizeof(struct mtd_info));
  221. memset((char *)this, 0, sizeof(struct DiskOnChip));
  222. mtd->priv = this;
  223. this->virtadr = docptr;
  224. this->physadr = physadr;
  225. this->ChipID = ChipID;
  226. sprintf(namebuf, "with ChipID %2.2X", ChipID);
  227. switch(ChipID) {
  228. case DOC_ChipID_Doc2kTSOP:
  229. name="2000 TSOP";
  230. initroutine = symbol_request(DoC2k_init);
  231. break;
  232. case DOC_ChipID_Doc2k:
  233. name="2000";
  234. initroutine = symbol_request(DoC2k_init);
  235. break;
  236. case DOC_ChipID_DocMil:
  237. name="Millennium";
  238. #ifdef DOC_SINGLE_DRIVER
  239. initroutine = symbol_request(DoC2k_init);
  240. #else
  241. initroutine = symbol_request(DoCMil_init);
  242. #endif /* DOC_SINGLE_DRIVER */
  243. break;
  244. case DOC_ChipID_DocMilPlus16:
  245. case DOC_ChipID_DocMilPlus32:
  246. name="MillenniumPlus";
  247. initroutine = symbol_request(DoCMilPlus_init);
  248. break;
  249. }
  250. if (initroutine) {
  251. (*initroutine)(mtd);
  252. symbol_put_addr(initroutine);
  253. return;
  254. }
  255. printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr);
  256. kfree(mtd);
  257. }
  258. iounmap(docptr);
  259. }
  260. /****************************************************************************
  261. *
  262. * Module stuff
  263. *
  264. ****************************************************************************/
  265. static int __init init_doc(void)
  266. {
  267. int i;
  268. if (doc_config_location) {
  269. printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location);
  270. DoC_Probe(doc_config_location);
  271. } else {
  272. for (i=0; (doc_locations[i] != 0xffffffff); i++) {
  273. DoC_Probe(doc_locations[i]);
  274. }
  275. }
  276. /* No banner message any more. Print a message if no DiskOnChip
  277. found, so the user knows we at least tried. */
  278. if (!docfound)
  279. printk(KERN_INFO "No recognised DiskOnChip devices found\n");
  280. return -EAGAIN;
  281. }
  282. module_init(init_doc);
  283. MODULE_LICENSE("GPL");
  284. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  285. MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices");