pci.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Atheros AR71XX/AR724X specific PCI setup code
  3. *
  4. * Copyright (C) 2011 René Bolldorf <xsecute@googlemail.com>
  5. * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
  6. * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
  7. *
  8. * Parts of this file are based on Atheros' 2.6.15 BSP
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published
  12. * by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/pci.h>
  16. #include <asm/mach-ath79/ar71xx_regs.h>
  17. #include <asm/mach-ath79/ath79.h>
  18. #include <asm/mach-ath79/irq.h>
  19. #include <asm/mach-ath79/pci.h>
  20. #include "pci.h"
  21. static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev);
  22. static const struct ath79_pci_irq *ath79_pci_irq_map __initdata;
  23. static unsigned ath79_pci_nr_irqs __initdata;
  24. static const struct ath79_pci_irq ar71xx_pci_irq_map[] __initconst = {
  25. {
  26. .slot = 17,
  27. .pin = 1,
  28. .irq = ATH79_PCI_IRQ(0),
  29. }, {
  30. .slot = 18,
  31. .pin = 1,
  32. .irq = ATH79_PCI_IRQ(1),
  33. }, {
  34. .slot = 19,
  35. .pin = 1,
  36. .irq = ATH79_PCI_IRQ(2),
  37. }
  38. };
  39. static const struct ath79_pci_irq ar724x_pci_irq_map[] __initconst = {
  40. {
  41. .slot = 0,
  42. .pin = 1,
  43. .irq = ATH79_PCI_IRQ(0),
  44. }
  45. };
  46. int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  47. {
  48. int irq = -1;
  49. int i;
  50. if (ath79_pci_nr_irqs == 0 ||
  51. ath79_pci_irq_map == NULL) {
  52. if (soc_is_ar71xx()) {
  53. ath79_pci_irq_map = ar71xx_pci_irq_map;
  54. ath79_pci_nr_irqs = ARRAY_SIZE(ar71xx_pci_irq_map);
  55. } else if (soc_is_ar724x() ||
  56. soc_is_ar9342() ||
  57. soc_is_ar9344()) {
  58. ath79_pci_irq_map = ar724x_pci_irq_map;
  59. ath79_pci_nr_irqs = ARRAY_SIZE(ar724x_pci_irq_map);
  60. } else {
  61. pr_crit("pci %s: invalid irq map\n",
  62. pci_name((struct pci_dev *) dev));
  63. return irq;
  64. }
  65. }
  66. for (i = 0; i < ath79_pci_nr_irqs; i++) {
  67. const struct ath79_pci_irq *entry;
  68. entry = &ath79_pci_irq_map[i];
  69. if (entry->slot == slot && entry->pin == pin) {
  70. irq = entry->irq;
  71. break;
  72. }
  73. }
  74. if (irq < 0)
  75. pr_crit("pci %s: no irq found for pin %u\n",
  76. pci_name((struct pci_dev *) dev), pin);
  77. else
  78. pr_info("pci %s: using irq %d for pin %u\n",
  79. pci_name((struct pci_dev *) dev), irq, pin);
  80. return irq;
  81. }
  82. int pcibios_plat_dev_init(struct pci_dev *dev)
  83. {
  84. if (ath79_pci_plat_dev_init)
  85. return ath79_pci_plat_dev_init(dev);
  86. return 0;
  87. }
  88. void __init ath79_pci_set_irq_map(unsigned nr_irqs,
  89. const struct ath79_pci_irq *map)
  90. {
  91. ath79_pci_nr_irqs = nr_irqs;
  92. ath79_pci_irq_map = map;
  93. }
  94. void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev))
  95. {
  96. ath79_pci_plat_dev_init = func;
  97. }
  98. int __init ath79_register_pci(void)
  99. {
  100. if (soc_is_ar71xx())
  101. return ar71xx_pcibios_init();
  102. if (soc_is_ar724x())
  103. return ar724x_pcibios_init(ATH79_CPU_IRQ_IP2);
  104. if (soc_is_ar9342() || soc_is_ar9344()) {
  105. u32 bootstrap;
  106. bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  107. if (bootstrap & AR934X_BOOTSTRAP_PCIE_RC)
  108. return ar724x_pcibios_init(ATH79_IP2_IRQ(0));
  109. }
  110. return -ENODEV;
  111. }