l440gx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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_find_device(PCI_VENDOR_ID_INTEL,
  54. PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
  55. pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
  56. PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
  57. if (!dev || !pm_dev) {
  58. printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
  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. return -ENOMEM;
  65. }
  66. simple_map_init(&l440gx_map);
  67. printk(KERN_NOTICE "window_addr = 0x%08lx\n", (unsigned long)l440gx_map.virt);
  68. /* Setup the pm iobase resource
  69. * This code should move into some kind of generic bridge
  70. * driver but for the moment I'm content with getting the
  71. * allocation correct.
  72. */
  73. pm_iobase = &pm_dev->resource[PIIXE_IOBASE_RESOURCE];
  74. if (!(pm_iobase->flags & IORESOURCE_IO)) {
  75. pm_iobase->name = "pm iobase";
  76. pm_iobase->start = 0;
  77. pm_iobase->end = 63;
  78. pm_iobase->flags = IORESOURCE_IO;
  79. /* Put the current value in the resource */
  80. pci_read_config_dword(pm_dev, 0x40, &iobase);
  81. iobase &= ~1;
  82. pm_iobase->start += iobase & ~1;
  83. pm_iobase->end += iobase & ~1;
  84. /* Allocate the resource region */
  85. if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) {
  86. printk(KERN_WARNING "Could not allocate pm iobase resource\n");
  87. iounmap(l440gx_map.virt);
  88. return -ENXIO;
  89. }
  90. }
  91. /* Set the iobase */
  92. iobase = pm_iobase->start;
  93. pci_write_config_dword(pm_dev, 0x40, iobase | 1);
  94. /* Set XBCS# */
  95. pci_read_config_word(dev, 0x4e, &word);
  96. word |= 0x4;
  97. pci_write_config_word(dev, 0x4e, word);
  98. /* Supply write voltage to the chip */
  99. l440gx_set_vpp(&l440gx_map, 1);
  100. /* Enable the gate on the WE line */
  101. outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
  102. printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
  103. mymtd = do_map_probe("jedec_probe", &l440gx_map);
  104. if (!mymtd) {
  105. printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n");
  106. mymtd = do_map_probe("map_rom", &l440gx_map);
  107. }
  108. if (mymtd) {
  109. mymtd->owner = THIS_MODULE;
  110. add_mtd_device(mymtd);
  111. return 0;
  112. }
  113. iounmap(l440gx_map.virt);
  114. return -ENXIO;
  115. }
  116. static void __exit cleanup_l440gx(void)
  117. {
  118. del_mtd_device(mymtd);
  119. map_destroy(mymtd);
  120. iounmap(l440gx_map.virt);
  121. }
  122. module_init(init_l440gx);
  123. module_exit(cleanup_l440gx);
  124. MODULE_LICENSE("GPL");
  125. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  126. MODULE_DESCRIPTION("MTD map driver for BIOS chips on Intel L440GX motherboards");