l440gx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * BIOS Flash chip on Intel 440GX board.
  3. *
  4. * Bugs this currently does not work under linuxBIOS.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/pci.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. #define PIIXE_IOBASE_RESOURCE 11
  14. #define WINDOW_ADDR 0xfff00000
  15. #define WINDOW_SIZE 0x00100000
  16. #define BUSWIDTH 1
  17. static u32 iobase;
  18. #define IOBASE iobase
  19. #define TRIBUF_PORT (IOBASE+0x37)
  20. #define VPP_PORT (IOBASE+0x28)
  21. static struct mtd_info *mymtd;
  22. /* Is this really the vpp port? */
  23. static void l440gx_set_vpp(struct map_info *map, int vpp)
  24. {
  25. unsigned long l;
  26. l = inl(VPP_PORT);
  27. if (vpp) {
  28. l |= 1;
  29. } else {
  30. l &= ~1;
  31. }
  32. outl(l, VPP_PORT);
  33. }
  34. static struct map_info l440gx_map = {
  35. .name = "L440GX BIOS",
  36. .size = WINDOW_SIZE,
  37. .bankwidth = BUSWIDTH,
  38. .phys = WINDOW_ADDR,
  39. #if 0
  40. /* FIXME verify that this is the
  41. * appripriate code for vpp enable/disable
  42. */
  43. .set_vpp = l440gx_set_vpp
  44. #endif
  45. };
  46. static int __init init_l440gx(void)
  47. {
  48. struct pci_dev *dev, *pm_dev;
  49. struct resource *pm_iobase;
  50. __u16 word;
  51. dev = pci_get_device(PCI_VENDOR_ID_INTEL,
  52. PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
  53. pm_dev = pci_get_device(PCI_VENDOR_ID_INTEL,
  54. PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
  55. pci_dev_put(dev);
  56. if (!dev || !pm_dev) {
  57. printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
  58. pci_dev_put(pm_dev);
  59. return -ENODEV;
  60. }
  61. l440gx_map.virt = ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
  62. if (!l440gx_map.virt) {
  63. printk(KERN_WARNING "Failed to ioremap L440GX flash region\n");
  64. pci_dev_put(pm_dev);
  65. return -ENOMEM;
  66. }
  67. simple_map_init(&l440gx_map);
  68. printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.virt);
  69. /* Setup the pm iobase resource
  70. * This code should move into some kind of generic bridge
  71. * driver but for the moment I'm content with getting the
  72. * allocation correct.
  73. */
  74. pm_iobase = &pm_dev->resource[PIIXE_IOBASE_RESOURCE];
  75. if (!(pm_iobase->flags & IORESOURCE_IO)) {
  76. pm_iobase->name = "pm iobase";
  77. pm_iobase->start = 0;
  78. pm_iobase->end = 63;
  79. pm_iobase->flags = IORESOURCE_IO;
  80. /* Put the current value in the resource */
  81. pci_read_config_dword(pm_dev, 0x40, &iobase);
  82. iobase &= ~1;
  83. pm_iobase->start += iobase & ~1;
  84. pm_iobase->end += iobase & ~1;
  85. pci_dev_put(pm_dev);
  86. /* Allocate the resource region */
  87. if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) {
  88. pci_dev_put(dev);
  89. pci_dev_put(pm_dev);
  90. printk(KERN_WARNING "Could not allocate pm iobase resource\n");
  91. iounmap(l440gx_map.virt);
  92. return -ENXIO;
  93. }
  94. }
  95. /* Set the iobase */
  96. iobase = pm_iobase->start;
  97. pci_write_config_dword(pm_dev, 0x40, iobase | 1);
  98. /* Set XBCS# */
  99. pci_read_config_word(dev, 0x4e, &word);
  100. word |= 0x4;
  101. pci_write_config_word(dev, 0x4e, word);
  102. /* Supply write voltage to the chip */
  103. l440gx_set_vpp(&l440gx_map, 1);
  104. /* Enable the gate on the WE line */
  105. outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
  106. printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
  107. mymtd = do_map_probe("jedec_probe", &l440gx_map);
  108. if (!mymtd) {
  109. printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n");
  110. mymtd = do_map_probe("map_rom", &l440gx_map);
  111. }
  112. if (mymtd) {
  113. mymtd->owner = THIS_MODULE;
  114. mtd_device_register(mymtd, NULL, 0);
  115. return 0;
  116. }
  117. iounmap(l440gx_map.virt);
  118. return -ENXIO;
  119. }
  120. static void __exit cleanup_l440gx(void)
  121. {
  122. mtd_device_unregister(mymtd);
  123. map_destroy(mymtd);
  124. iounmap(l440gx_map.virt);
  125. }
  126. module_init(init_l440gx);
  127. module_exit(cleanup_l440gx);
  128. MODULE_LICENSE("GPL");
  129. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  130. MODULE_DESCRIPTION("MTD map driver for BIOS chips on Intel L440GX motherboards");