scx200_docflash.c 5.7 KB

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