pci.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <linux/resource.h>
  17. #include <linux/platform_device.h>
  18. #include <asm/mach-ath79/ar71xx_regs.h>
  19. #include <asm/mach-ath79/ath79.h>
  20. #include <asm/mach-ath79/irq.h>
  21. #include "pci.h"
  22. static int (*ath79_pci_plat_dev_init)(struct pci_dev *dev);
  23. static const struct ath79_pci_irq *ath79_pci_irq_map __initdata;
  24. static unsigned ath79_pci_nr_irqs __initdata;
  25. static const struct ath79_pci_irq ar71xx_pci_irq_map[] __initconst = {
  26. {
  27. .slot = 17,
  28. .pin = 1,
  29. .irq = ATH79_PCI_IRQ(0),
  30. }, {
  31. .slot = 18,
  32. .pin = 1,
  33. .irq = ATH79_PCI_IRQ(1),
  34. }, {
  35. .slot = 19,
  36. .pin = 1,
  37. .irq = ATH79_PCI_IRQ(2),
  38. }
  39. };
  40. static const struct ath79_pci_irq ar724x_pci_irq_map[] __initconst = {
  41. {
  42. .slot = 0,
  43. .pin = 1,
  44. .irq = ATH79_PCI_IRQ(0),
  45. }
  46. };
  47. int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  48. {
  49. int irq = -1;
  50. int i;
  51. if (ath79_pci_nr_irqs == 0 ||
  52. ath79_pci_irq_map == NULL) {
  53. if (soc_is_ar71xx()) {
  54. ath79_pci_irq_map = ar71xx_pci_irq_map;
  55. ath79_pci_nr_irqs = ARRAY_SIZE(ar71xx_pci_irq_map);
  56. } else if (soc_is_ar724x() ||
  57. soc_is_ar9342() ||
  58. soc_is_ar9344()) {
  59. ath79_pci_irq_map = ar724x_pci_irq_map;
  60. ath79_pci_nr_irqs = ARRAY_SIZE(ar724x_pci_irq_map);
  61. } else {
  62. pr_crit("pci %s: invalid irq map\n",
  63. pci_name((struct pci_dev *) dev));
  64. return irq;
  65. }
  66. }
  67. for (i = 0; i < ath79_pci_nr_irqs; i++) {
  68. const struct ath79_pci_irq *entry;
  69. entry = &ath79_pci_irq_map[i];
  70. if (entry->bus == dev->bus->number &&
  71. entry->slot == slot &&
  72. entry->pin == pin) {
  73. irq = entry->irq;
  74. break;
  75. }
  76. }
  77. if (irq < 0)
  78. pr_crit("pci %s: no irq found for pin %u\n",
  79. pci_name((struct pci_dev *) dev), pin);
  80. else
  81. pr_info("pci %s: using irq %d for pin %u\n",
  82. pci_name((struct pci_dev *) dev), irq, pin);
  83. return irq;
  84. }
  85. int pcibios_plat_dev_init(struct pci_dev *dev)
  86. {
  87. if (ath79_pci_plat_dev_init)
  88. return ath79_pci_plat_dev_init(dev);
  89. return 0;
  90. }
  91. void __init ath79_pci_set_irq_map(unsigned nr_irqs,
  92. const struct ath79_pci_irq *map)
  93. {
  94. ath79_pci_nr_irqs = nr_irqs;
  95. ath79_pci_irq_map = map;
  96. }
  97. void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev))
  98. {
  99. ath79_pci_plat_dev_init = func;
  100. }
  101. static struct platform_device *
  102. ath79_register_pci_ar71xx(void)
  103. {
  104. struct platform_device *pdev;
  105. struct resource res[2];
  106. memset(res, 0, sizeof(res));
  107. res[0].name = "cfg_base";
  108. res[0].flags = IORESOURCE_MEM;
  109. res[0].start = AR71XX_PCI_CFG_BASE;
  110. res[0].end = AR71XX_PCI_CFG_BASE + AR71XX_PCI_CFG_SIZE - 1;
  111. res[1].flags = IORESOURCE_IRQ;
  112. res[1].start = ATH79_CPU_IRQ_IP2;
  113. res[1].end = ATH79_CPU_IRQ_IP2;
  114. pdev = platform_device_register_simple("ar71xx-pci", -1,
  115. res, ARRAY_SIZE(res));
  116. return pdev;
  117. }
  118. static struct platform_device *
  119. ath79_register_pci_ar724x(int id,
  120. unsigned long cfg_base,
  121. unsigned long ctrl_base,
  122. int irq)
  123. {
  124. struct platform_device *pdev;
  125. struct resource res[3];
  126. memset(res, 0, sizeof(res));
  127. res[0].name = "cfg_base";
  128. res[0].flags = IORESOURCE_MEM;
  129. res[0].start = cfg_base;
  130. res[0].end = cfg_base + AR724X_PCI_CFG_SIZE - 1;
  131. res[1].name = "ctrl_base";
  132. res[1].flags = IORESOURCE_MEM;
  133. res[1].start = ctrl_base;
  134. res[1].end = ctrl_base + AR724X_PCI_CTRL_SIZE - 1;
  135. res[2].flags = IORESOURCE_IRQ;
  136. res[2].start = irq;
  137. res[2].end = irq;
  138. pdev = platform_device_register_simple("ar724x-pci", id,
  139. res, ARRAY_SIZE(res));
  140. return pdev;
  141. }
  142. int __init ath79_register_pci(void)
  143. {
  144. struct platform_device *pdev = NULL;
  145. if (soc_is_ar71xx()) {
  146. pdev = ath79_register_pci_ar71xx();
  147. } else if (soc_is_ar724x()) {
  148. pdev = ath79_register_pci_ar724x(-1,
  149. AR724X_PCI_CFG_BASE,
  150. AR724X_PCI_CTRL_BASE,
  151. ATH79_CPU_IRQ_IP2);
  152. } else if (soc_is_ar9342() ||
  153. soc_is_ar9344()) {
  154. u32 bootstrap;
  155. bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  156. if ((bootstrap & AR934X_BOOTSTRAP_PCIE_RC) == 0)
  157. return -ENODEV;
  158. pdev = ath79_register_pci_ar724x(-1,
  159. AR724X_PCI_CFG_BASE,
  160. AR724X_PCI_CTRL_BASE,
  161. ATH79_IP2_IRQ(0));
  162. } else {
  163. /* No PCI support */
  164. return -ENODEV;
  165. }
  166. if (!pdev)
  167. pr_err("unable to register PCI controller device\n");
  168. return pdev ? 0 : -ENODEV;
  169. }