docprobe.c 10 KB

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