l440gx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. #include <linux/config.h>
  16. #define PIIXE_IOBASE_RESOURCE 11
  17. #define WINDOW_ADDR 0xfff00000
  18. #define WINDOW_SIZE 0x00100000
  19. #define BUSWIDTH 1
  20. static u32 iobase;
  21. #define IOBASE iobase
  22. #define TRIBUF_PORT (IOBASE+0x37)
  23. #define VPP_PORT (IOBASE+0x28)
  24. static struct mtd_info *mymtd;
  25. /* Is this really the vpp port? */
  26. static void l440gx_set_vpp(struct map_info *map, int vpp)
  27. {
  28. unsigned long l;
  29. l = inl(VPP_PORT);
  30. if (vpp) {
  31. l |= 1;
  32. } else {
  33. l &= ~1;
  34. }
  35. outl(l, VPP_PORT);
  36. }
  37. static struct map_info l440gx_map = {
  38. .name = "L440GX BIOS",
  39. .size = WINDOW_SIZE,
  40. .bankwidth = BUSWIDTH,
  41. .phys = WINDOW_ADDR,
  42. #if 0
  43. /* FIXME verify that this is the
  44. * appripriate code for vpp enable/disable
  45. */
  46. .set_vpp = l440gx_set_vpp
  47. #endif
  48. };
  49. static int __init init_l440gx(void)
  50. {
  51. struct pci_dev *dev, *pm_dev;
  52. struct resource *pm_iobase;
  53. __u16 word;
  54. dev = pci_find_device(PCI_VENDOR_ID_INTEL,
  55. PCI_DEVICE_ID_INTEL_82371AB_0, NULL);
  56. pm_dev = pci_find_device(PCI_VENDOR_ID_INTEL,
  57. PCI_DEVICE_ID_INTEL_82371AB_3, NULL);
  58. if (!dev || !pm_dev) {
  59. printk(KERN_NOTICE "L440GX flash mapping: failed to find PIIX4 ISA bridge, cannot continue\n");
  60. return -ENODEV;
  61. }
  62. l440gx_map.virt = ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
  63. if (!l440gx_map.virt) {
  64. printk(KERN_WARNING "Failed to ioremap L440GX flash region\n");
  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. /* Allocate the resource region */
  86. if (pci_assign_resource(pm_dev, PIIXE_IOBASE_RESOURCE) != 0) {
  87. printk(KERN_WARNING "Could not allocate pm iobase resource\n");
  88. iounmap(l440gx_map.virt);
  89. return -ENXIO;
  90. }
  91. }
  92. /* Set the iobase */
  93. iobase = pm_iobase->start;
  94. pci_write_config_dword(pm_dev, 0x40, iobase | 1);
  95. /* Set XBCS# */
  96. pci_read_config_word(dev, 0x4e, &word);
  97. word |= 0x4;
  98. pci_write_config_word(dev, 0x4e, word);
  99. /* Supply write voltage to the chip */
  100. l440gx_set_vpp(&l440gx_map, 1);
  101. /* Enable the gate on the WE line */
  102. outb(inb(TRIBUF_PORT) & ~1, TRIBUF_PORT);
  103. printk(KERN_NOTICE "Enabled WE line to L440GX BIOS flash chip.\n");
  104. mymtd = do_map_probe("jedec_probe", &l440gx_map);
  105. if (!mymtd) {
  106. printk(KERN_NOTICE "JEDEC probe on BIOS chip failed. Using ROM\n");
  107. mymtd = do_map_probe("map_rom", &l440gx_map);
  108. }
  109. if (mymtd) {
  110. mymtd->owner = THIS_MODULE;
  111. add_mtd_device(mymtd);
  112. return 0;
  113. }
  114. iounmap(l440gx_map.virt);
  115. return -ENXIO;
  116. }
  117. static void __exit cleanup_l440gx(void)
  118. {
  119. del_mtd_device(mymtd);
  120. map_destroy(mymtd);
  121. iounmap(l440gx_map.virt);
  122. }
  123. module_init(init_l440gx);
  124. module_exit(cleanup_l440gx);
  125. MODULE_LICENSE("GPL");
  126. MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
  127. MODULE_DESCRIPTION("MTD map driver for BIOS chips on Intel L440GX motherboards");