fixup-lemote2f.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2008 Lemote Technology
  4. * Copyright (C) 2004 ICT CAS
  5. * Author: Li xiaoyu, [email protected]
  6. *
  7. * Copyright (C) 2007 Lemote, Inc.
  8. * Author: Fuxin Zhang, [email protected]
  9. */
  10. #include <linux/init.h>
  11. #include <linux/pci.h>
  12. #include <loongson.h>
  13. #include <cs5536/cs5536.h>
  14. #include <cs5536/cs5536_pci.h>
  15. /* PCI interrupt pins
  16. *
  17. * These should not be changed, or you should consider loongson2f interrupt
  18. * register and your pci card dispatch
  19. */
  20. #define PCIA 4
  21. #define PCIB 5
  22. #define PCIC 6
  23. #define PCID 7
  24. /* all the pci device has the PCIA pin, check the datasheet. */
  25. static char irq_tab[][5] = {
  26. /* INTA INTB INTC INTD */
  27. {0, 0, 0, 0, 0}, /* 11: Unused */
  28. {0, 0, 0, 0, 0}, /* 12: Unused */
  29. {0, 0, 0, 0, 0}, /* 13: Unused */
  30. {0, 0, 0, 0, 0}, /* 14: Unused */
  31. {0, 0, 0, 0, 0}, /* 15: Unused */
  32. {0, 0, 0, 0, 0}, /* 16: Unused */
  33. {0, PCIA, 0, 0, 0}, /* 17: RTL8110-0 */
  34. {0, PCIB, 0, 0, 0}, /* 18: RTL8110-1 */
  35. {0, PCIC, 0, 0, 0}, /* 19: SiI3114 */
  36. {0, PCID, 0, 0, 0}, /* 20: 3-ports nec usb */
  37. {0, PCIA, PCIB, PCIC, PCID}, /* 21: PCI-SLOT */
  38. {0, 0, 0, 0, 0}, /* 22: Unused */
  39. {0, 0, 0, 0, 0}, /* 23: Unused */
  40. {0, 0, 0, 0, 0}, /* 24: Unused */
  41. {0, 0, 0, 0, 0}, /* 25: Unused */
  42. {0, 0, 0, 0, 0}, /* 26: Unused */
  43. {0, 0, 0, 0, 0}, /* 27: Unused */
  44. };
  45. int pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  46. {
  47. int virq;
  48. if ((PCI_SLOT(dev->devfn) != PCI_IDSEL_CS5536)
  49. && (PCI_SLOT(dev->devfn) < 32)) {
  50. virq = irq_tab[slot][pin];
  51. printk(KERN_INFO "slot: %d, pin: %d, irq: %d\n", slot, pin,
  52. virq + LOONGSON_IRQ_BASE);
  53. if (virq != 0)
  54. return LOONGSON_IRQ_BASE + virq;
  55. else
  56. return 0;
  57. } else if (PCI_SLOT(dev->devfn) == PCI_IDSEL_CS5536) { /* cs5536 */
  58. switch (PCI_FUNC(dev->devfn)) {
  59. case 2:
  60. pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
  61. CS5536_IDE_INTR);
  62. return CS5536_IDE_INTR; /* for IDE */
  63. case 3:
  64. pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
  65. CS5536_ACC_INTR);
  66. return CS5536_ACC_INTR; /* for AUDIO */
  67. case 4: /* for OHCI */
  68. case 5: /* for EHCI */
  69. case 6: /* for UDC */
  70. case 7: /* for OTG */
  71. pci_write_config_byte(dev, PCI_INTERRUPT_LINE,
  72. CS5536_USB_INTR);
  73. return CS5536_USB_INTR;
  74. }
  75. return dev->irq;
  76. } else {
  77. printk(KERN_INFO "strange PCI slot number.\n");
  78. return 0;
  79. }
  80. }
  81. /* Do platform specific device initialization at pci_enable_device() time */
  82. int pcibios_plat_dev_init(struct pci_dev *dev)
  83. {
  84. return 0;
  85. }
  86. /* CS5536 SPEC. fixup */
  87. static void loongson_cs5536_isa_fixup(struct pci_dev *pdev)
  88. {
  89. /* the uart1 and uart2 interrupt in PIC is enabled as default */
  90. pci_write_config_dword(pdev, PCI_UART1_INT_REG, 1);
  91. pci_write_config_dword(pdev, PCI_UART2_INT_REG, 1);
  92. }
  93. static void loongson_cs5536_ide_fixup(struct pci_dev *pdev)
  94. {
  95. /* setting the mutex pin as IDE function */
  96. pci_write_config_dword(pdev, PCI_IDE_CFG_REG,
  97. CS5536_IDE_FLASH_SIGNATURE);
  98. }
  99. static void loongson_cs5536_acc_fixup(struct pci_dev *pdev)
  100. {
  101. /* enable the AUDIO interrupt in PIC */
  102. pci_write_config_dword(pdev, PCI_ACC_INT_REG, 1);
  103. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xc0);
  104. }
  105. static void loongson_cs5536_ohci_fixup(struct pci_dev *pdev)
  106. {
  107. /* enable the OHCI interrupt in PIC */
  108. /* THE OHCI, EHCI, UDC, OTG are shared with interrupt in PIC */
  109. pci_write_config_dword(pdev, PCI_OHCI_INT_REG, 1);
  110. }
  111. static void loongson_cs5536_ehci_fixup(struct pci_dev *pdev)
  112. {
  113. u32 hi, lo;
  114. /* Serial short detect enable */
  115. _rdmsr(USB_MSR_REG(USB_CONFIG), &hi, &lo);
  116. _wrmsr(USB_MSR_REG(USB_CONFIG), (1 << 1) | (1 << 3), lo);
  117. /* setting the USB2.0 micro frame length */
  118. pci_write_config_dword(pdev, PCI_EHCI_FLADJ_REG, 0x2000);
  119. }
  120. static void loongson_nec_fixup(struct pci_dev *pdev)
  121. {
  122. unsigned int val;
  123. pci_read_config_dword(pdev, 0xe0, &val);
  124. /* Only 2 port be used */
  125. pci_write_config_dword(pdev, 0xe0, (val & ~3) | 0x2);
  126. }
  127. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA,
  128. loongson_cs5536_isa_fixup);
  129. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_OHC,
  130. loongson_cs5536_ohci_fixup);
  131. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_EHC,
  132. loongson_cs5536_ehci_fixup);
  133. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_AUDIO,
  134. loongson_cs5536_acc_fixup);
  135. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_IDE,
  136. loongson_cs5536_ide_fixup);
  137. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_USB,
  138. loongson_nec_fixup);