docprobe.c 10 KB

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