docprobe.c 9.8 KB

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