scx200_docflash.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* linux/drivers/mtd/maps/scx200_docflash.c
  2. Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
  3. National Semiconductor SCx200 flash mapped with DOCCS
  4. */
  5. #include <linux/module.h>
  6. #include <linux/types.h>
  7. #include <linux/kernel.h>
  8. #include <linux/init.h>
  9. #include <asm/io.h>
  10. #include <linux/mtd/mtd.h>
  11. #include <linux/mtd/map.h>
  12. #include <linux/mtd/partitions.h>
  13. #include <linux/pci.h>
  14. #include <linux/scx200.h>
  15. #define NAME "scx200_docflash"
  16. MODULE_AUTHOR("Christer Weinigel <wingel@hack.org>");
  17. MODULE_DESCRIPTION("NatSemi SCx200 DOCCS Flash Driver");
  18. MODULE_LICENSE("GPL");
  19. static int probe = 0; /* Don't autoprobe */
  20. static unsigned size = 0x1000000; /* 16 MiB the whole ISA address space */
  21. static unsigned width = 8; /* Default to 8 bits wide */
  22. static char *flashtype = "cfi_probe";
  23. module_param(probe, int, 0);
  24. MODULE_PARM_DESC(probe, "Probe for a BIOS mapping");
  25. module_param(size, int, 0);
  26. MODULE_PARM_DESC(size, "Size of the flash mapping");
  27. module_param(width, int, 0);
  28. MODULE_PARM_DESC(width, "Data width of the flash mapping (8/16)");
  29. module_param(flashtype, charp, 0);
  30. MODULE_PARM_DESC(flashtype, "Type of MTD probe to do");
  31. static struct resource docmem = {
  32. .flags = IORESOURCE_MEM,
  33. .name = "NatSemi SCx200 DOCCS Flash",
  34. };
  35. static struct mtd_info *mymtd;
  36. #ifdef CONFIG_MTD_PARTITIONS
  37. static struct mtd_partition partition_info[] = {
  38. {
  39. .name = "DOCCS Boot kernel",
  40. .offset = 0,
  41. .size = 0xc0000
  42. },
  43. {
  44. .name = "DOCCS Low BIOS",
  45. .offset = 0xc0000,
  46. .size = 0x40000
  47. },
  48. {
  49. .name = "DOCCS File system",
  50. .offset = 0x100000,
  51. .size = ~0 /* calculate from flash size */
  52. },
  53. {
  54. .name = "DOCCS High BIOS",
  55. .offset = ~0, /* calculate from flash size */
  56. .size = 0x80000
  57. },
  58. };
  59. #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
  60. #endif
  61. static struct map_info scx200_docflash_map = {
  62. .name = "NatSemi SCx200 DOCCS Flash",
  63. };
  64. static int __init init_scx200_docflash(void)
  65. {
  66. unsigned u;
  67. unsigned base;
  68. unsigned ctrl;
  69. unsigned pmr;
  70. struct pci_dev *bridge;
  71. printk(KERN_DEBUG NAME ": NatSemi SCx200 DOCCS Flash Driver\n");
  72. if ((bridge = pci_get_device(PCI_VENDOR_ID_NS,
  73. PCI_DEVICE_ID_NS_SCx200_BRIDGE,
  74. NULL)) == NULL)
  75. return -ENODEV;
  76. /* check that we have found the configuration block */
  77. if (!scx200_cb_present()) {
  78. pci_dev_put(bridge);
  79. return -ENODEV;
  80. }
  81. if (probe) {
  82. /* Try to use the present flash mapping if any */
  83. pci_read_config_dword(bridge, SCx200_DOCCS_BASE, &base);
  84. pci_read_config_dword(bridge, SCx200_DOCCS_CTRL, &ctrl);
  85. pci_dev_put(bridge);
  86. pmr = inl(scx200_cb_base + SCx200_PMR);
  87. if (base == 0
  88. || (ctrl & 0x07000000) != 0x07000000
  89. || (ctrl & 0x0007ffff) == 0)
  90. return -ENODEV;
  91. size = ((ctrl&0x1fff)<<13) + (1<<13);
  92. for (u = size; u > 1; u >>= 1)
  93. ;
  94. if (u != 1)
  95. return -ENODEV;
  96. if (pmr & (1<<6))
  97. width = 16;
  98. else
  99. width = 8;
  100. docmem.start = base;
  101. docmem.end = base + size;
  102. if (request_resource(&iomem_resource, &docmem)) {
  103. printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
  104. return -ENOMEM;
  105. }
  106. } else {
  107. pci_dev_put(bridge);
  108. for (u = size; u > 1; u >>= 1)
  109. ;
  110. if (u != 1) {
  111. printk(KERN_ERR NAME ": invalid size for flash mapping\n");
  112. return -EINVAL;
  113. }
  114. if (width != 8 && width != 16) {
  115. printk(KERN_ERR NAME ": invalid bus width for flash mapping\n");
  116. return -EINVAL;
  117. }
  118. if (allocate_resource(&iomem_resource, &docmem,
  119. size,
  120. 0xc0000000, 0xffffffff,
  121. size, NULL, NULL)) {
  122. printk(KERN_ERR NAME ": unable to allocate memory for flash mapping\n");
  123. return -ENOMEM;
  124. }
  125. ctrl = 0x07000000 | ((size-1) >> 13);
  126. printk(KERN_INFO "DOCCS BASE=0x%08lx, CTRL=0x%08lx\n", (long)docmem.start, (long)ctrl);
  127. pci_write_config_dword(bridge, SCx200_DOCCS_BASE, docmem.start);
  128. pci_write_config_dword(bridge, SCx200_DOCCS_CTRL, ctrl);
  129. pmr = inl(scx200_cb_base + SCx200_PMR);
  130. if (width == 8) {
  131. pmr &= ~(1<<6);
  132. } else {
  133. pmr |= (1<<6);
  134. }
  135. outl(pmr, scx200_cb_base + SCx200_PMR);
  136. }
  137. printk(KERN_INFO NAME ": DOCCS mapped at %pR, width %d\n",
  138. &docmem, width);
  139. scx200_docflash_map.size = size;
  140. if (width == 8)
  141. scx200_docflash_map.bankwidth = 1;
  142. else
  143. scx200_docflash_map.bankwidth = 2;
  144. simple_map_init(&scx200_docflash_map);
  145. scx200_docflash_map.phys = docmem.start;
  146. scx200_docflash_map.virt = ioremap(docmem.start, scx200_docflash_map.size);
  147. if (!scx200_docflash_map.virt) {
  148. printk(KERN_ERR NAME ": failed to ioremap the flash\n");
  149. release_resource(&docmem);
  150. return -EIO;
  151. }
  152. mymtd = do_map_probe(flashtype, &scx200_docflash_map);
  153. if (!mymtd) {
  154. printk(KERN_ERR NAME ": unable to detect flash\n");
  155. iounmap(scx200_docflash_map.virt);
  156. release_resource(&docmem);
  157. return -ENXIO;
  158. }
  159. if (size < mymtd->size)
  160. printk(KERN_WARNING NAME ": warning, flash mapping is smaller than flash size\n");
  161. mymtd->owner = THIS_MODULE;
  162. #ifdef CONFIG_MTD_PARTITIONS
  163. partition_info[3].offset = mymtd->size-partition_info[3].size;
  164. partition_info[2].size = partition_info[3].offset-partition_info[2].offset;
  165. add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
  166. #else
  167. add_mtd_device(mymtd);
  168. #endif
  169. return 0;
  170. }
  171. static void __exit cleanup_scx200_docflash(void)
  172. {
  173. if (mymtd) {
  174. #ifdef CONFIG_MTD_PARTITIONS
  175. del_mtd_partitions(mymtd);
  176. #else
  177. del_mtd_device(mymtd);
  178. #endif
  179. map_destroy(mymtd);
  180. }
  181. if (scx200_docflash_map.virt) {
  182. iounmap(scx200_docflash_map.virt);
  183. release_resource(&docmem);
  184. }
  185. }
  186. module_init(init_scx200_docflash);
  187. module_exit(cleanup_scx200_docflash);
  188. /*
  189. Local variables:
  190. compile-command: "make -k -C ../../.. SUBDIRS=drivers/mtd/maps modules"
  191. c-basic-offset: 8
  192. End:
  193. */