l440gx.c 3.7 KB

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