fixup-malta.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/init.h>
  3. #include <linux/pci.h>
  4. #include <asm/mips-boards/piix4.h>
  5. /* PCI interrupt pins */
  6. #define PCIA 1
  7. #define PCIB 2
  8. #define PCIC 3
  9. #define PCID 4
  10. /* This table is filled in by interrogating the PIIX4 chip */
  11. static char pci_irq[5] = {
  12. };
  13. static char irq_tab[][5] = {
  14. /* INTA INTB INTC INTD */
  15. {0, 0, 0, 0, 0 }, /* 0: GT64120 PCI bridge */
  16. {0, 0, 0, 0, 0 }, /* 1: Unused */
  17. {0, 0, 0, 0, 0 }, /* 2: Unused */
  18. {0, 0, 0, 0, 0 }, /* 3: Unused */
  19. {0, 0, 0, 0, 0 }, /* 4: Unused */
  20. {0, 0, 0, 0, 0 }, /* 5: Unused */
  21. {0, 0, 0, 0, 0 }, /* 6: Unused */
  22. {0, 0, 0, 0, 0 }, /* 7: Unused */
  23. {0, 0, 0, 0, 0 }, /* 8: Unused */
  24. {0, 0, 0, 0, 0 }, /* 9: Unused */
  25. {0, 0, 0, 0, PCID }, /* 10: PIIX4 USB */
  26. {0, PCIB, 0, 0, 0 }, /* 11: AMD 79C973 Ethernet */
  27. {0, PCIC, 0, 0, 0 }, /* 12: Crystal 4281 Sound */
  28. {0, 0, 0, 0, 0 }, /* 13: Unused */
  29. {0, 0, 0, 0, 0 }, /* 14: Unused */
  30. {0, 0, 0, 0, 0 }, /* 15: Unused */
  31. {0, 0, 0, 0, 0 }, /* 16: Unused */
  32. {0, 0, 0, 0, 0 }, /* 17: Bonito/SOC-it PCI Bridge*/
  33. {0, PCIA, PCIB, PCIC, PCID }, /* 18: PCI Slot 1 */
  34. {0, PCIB, PCIC, PCID, PCIA }, /* 19: PCI Slot 2 */
  35. {0, PCIC, PCID, PCIA, PCIB }, /* 20: PCI Slot 3 */
  36. {0, PCID, PCIA, PCIB, PCIC } /* 21: PCI Slot 4 */
  37. };
  38. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  39. {
  40. int virq;
  41. virq = irq_tab[slot][pin];
  42. return pci_irq[virq];
  43. }
  44. /* Do platform specific device initialization at pci_enable_device() time */
  45. int pcibios_plat_dev_init(struct pci_dev *dev)
  46. {
  47. return 0;
  48. }
  49. static void malta_piix_func3_base_fixup(struct pci_dev *dev)
  50. {
  51. /* Set a sane PM I/O base address */
  52. pci_write_config_word(dev, PIIX4_FUNC3_PMBA, 0x1000);
  53. /* Enable access to the PM I/O region */
  54. pci_write_config_byte(dev, PIIX4_FUNC3_PMREGMISC,
  55. PIIX4_FUNC3_PMREGMISC_EN);
  56. }
  57. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3,
  58. malta_piix_func3_base_fixup);
  59. static void malta_piix_func0_fixup(struct pci_dev *pdev)
  60. {
  61. unsigned char reg_val;
  62. u32 reg_val32;
  63. u16 reg_val16;
  64. /* PIIX PIRQC[A:D] irq mappings */
  65. static int piixirqmap[PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MAX] = {
  66. 0, 0, 0, 3,
  67. 4, 5, 6, 7,
  68. 0, 9, 10, 11,
  69. 12, 0, 14, 15
  70. };
  71. int i;
  72. /* Interrogate PIIX4 to get PCI IRQ mapping */
  73. for (i = 0; i <= 3; i++) {
  74. pci_read_config_byte(pdev, PIIX4_FUNC0_PIRQRC+i, &reg_val);
  75. if (reg_val & PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_DISABLE)
  76. pci_irq[PCIA+i] = 0; /* Disabled */
  77. else
  78. pci_irq[PCIA+i] = piixirqmap[reg_val &
  79. PIIX4_FUNC0_PIRQRC_IRQ_ROUTING_MASK];
  80. }
  81. /* Done by YAMON 2.00 onwards */
  82. if (PCI_SLOT(pdev->devfn) == 10) {
  83. /*
  84. * Set top of main memory accessible by ISA or DMA
  85. * devices to 16 Mb.
  86. */
  87. pci_read_config_byte(pdev, PIIX4_FUNC0_TOM, &reg_val);
  88. pci_write_config_byte(pdev, PIIX4_FUNC0_TOM, reg_val |
  89. PIIX4_FUNC0_TOM_TOP_OF_MEMORY_MASK);
  90. }
  91. /* Mux SERIRQ to its pin */
  92. pci_read_config_dword(pdev, PIIX4_FUNC0_GENCFG, &reg_val32);
  93. pci_write_config_dword(pdev, PIIX4_FUNC0_GENCFG,
  94. reg_val32 | PIIX4_FUNC0_GENCFG_SERIRQ);
  95. /* Enable SERIRQ */
  96. pci_read_config_byte(pdev, PIIX4_FUNC0_SERIRQC, &reg_val);
  97. reg_val |= PIIX4_FUNC0_SERIRQC_EN | PIIX4_FUNC0_SERIRQC_CONT;
  98. pci_write_config_byte(pdev, PIIX4_FUNC0_SERIRQC, reg_val);
  99. /* Enable response to special cycles */
  100. pci_read_config_word(pdev, PCI_COMMAND, &reg_val16);
  101. pci_write_config_word(pdev, PCI_COMMAND,
  102. reg_val16 | PCI_COMMAND_SPECIAL);
  103. }
  104. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
  105. malta_piix_func0_fixup);
  106. static void malta_piix_func1_fixup(struct pci_dev *pdev)
  107. {
  108. unsigned char reg_val;
  109. /* Done by YAMON 2.02 onwards */
  110. if (PCI_SLOT(pdev->devfn) == 10) {
  111. /*
  112. * IDE Decode enable.
  113. */
  114. pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
  115. &reg_val);
  116. pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_PRIMARY_HI,
  117. reg_val|PIIX4_FUNC1_IDETIM_PRIMARY_HI_IDE_DECODE_EN);
  118. pci_read_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
  119. &reg_val);
  120. pci_write_config_byte(pdev, PIIX4_FUNC1_IDETIM_SECONDARY_HI,
  121. reg_val|PIIX4_FUNC1_IDETIM_SECONDARY_HI_IDE_DECODE_EN);
  122. }
  123. }
  124. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB,
  125. malta_piix_func1_fixup);
  126. /* Enable PCI 2.1 compatibility in PIIX4 */
  127. static void quirk_dlcsetup(struct pci_dev *dev)
  128. {
  129. u8 odlc, ndlc;
  130. (void) pci_read_config_byte(dev, PIIX4_FUNC0_DLC, &odlc);
  131. /* Enable passive releases and delayed transaction */
  132. ndlc = odlc | PIIX4_FUNC0_DLC_USBPR_EN |
  133. PIIX4_FUNC0_DLC_PASSIVE_RELEASE_EN |
  134. PIIX4_FUNC0_DLC_DELAYED_TRANSACTION_EN;
  135. (void) pci_write_config_byte(dev, PIIX4_FUNC0_DLC, ndlc);
  136. }
  137. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_0,
  138. quirk_dlcsetup);