l440gx.c 4.0 KB

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