pci.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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. static const struct ath79_pci_irq qca955x_pci_irq_map[] __initconst = {
  48. {
  49. .bus = 0,
  50. .slot = 0,
  51. .pin = 1,
  52. .irq = ATH79_PCI_IRQ(0),
  53. },
  54. {
  55. .bus = 1,
  56. .slot = 0,
  57. .pin = 1,
  58. .irq = ATH79_PCI_IRQ(1),
  59. },
  60. };
  61. int __init pcibios_map_irq(const struct pci_dev *dev, uint8_t slot, uint8_t pin)
  62. {
  63. int irq = -1;
  64. int i;
  65. if (ath79_pci_nr_irqs == 0 ||
  66. ath79_pci_irq_map == NULL) {
  67. if (soc_is_ar71xx()) {
  68. ath79_pci_irq_map = ar71xx_pci_irq_map;
  69. ath79_pci_nr_irqs = ARRAY_SIZE(ar71xx_pci_irq_map);
  70. } else if (soc_is_ar724x() ||
  71. soc_is_ar9342() ||
  72. soc_is_ar9344()) {
  73. ath79_pci_irq_map = ar724x_pci_irq_map;
  74. ath79_pci_nr_irqs = ARRAY_SIZE(ar724x_pci_irq_map);
  75. } else if (soc_is_qca955x()) {
  76. ath79_pci_irq_map = qca955x_pci_irq_map;
  77. ath79_pci_nr_irqs = ARRAY_SIZE(qca955x_pci_irq_map);
  78. } else {
  79. pr_crit("pci %s: invalid irq map\n",
  80. pci_name((struct pci_dev *) dev));
  81. return irq;
  82. }
  83. }
  84. for (i = 0; i < ath79_pci_nr_irqs; i++) {
  85. const struct ath79_pci_irq *entry;
  86. entry = &ath79_pci_irq_map[i];
  87. if (entry->bus == dev->bus->number &&
  88. entry->slot == slot &&
  89. entry->pin == pin) {
  90. irq = entry->irq;
  91. break;
  92. }
  93. }
  94. if (irq < 0)
  95. pr_crit("pci %s: no irq found for pin %u\n",
  96. pci_name((struct pci_dev *) dev), pin);
  97. else
  98. pr_info("pci %s: using irq %d for pin %u\n",
  99. pci_name((struct pci_dev *) dev), irq, pin);
  100. return irq;
  101. }
  102. int pcibios_plat_dev_init(struct pci_dev *dev)
  103. {
  104. if (ath79_pci_plat_dev_init)
  105. return ath79_pci_plat_dev_init(dev);
  106. return 0;
  107. }
  108. void __init ath79_pci_set_irq_map(unsigned nr_irqs,
  109. const struct ath79_pci_irq *map)
  110. {
  111. ath79_pci_nr_irqs = nr_irqs;
  112. ath79_pci_irq_map = map;
  113. }
  114. void __init ath79_pci_set_plat_dev_init(int (*func)(struct pci_dev *dev))
  115. {
  116. ath79_pci_plat_dev_init = func;
  117. }
  118. static struct platform_device *
  119. ath79_register_pci_ar71xx(void)
  120. {
  121. struct platform_device *pdev;
  122. struct resource res[4];
  123. memset(res, 0, sizeof(res));
  124. res[0].name = "cfg_base";
  125. res[0].flags = IORESOURCE_MEM;
  126. res[0].start = AR71XX_PCI_CFG_BASE;
  127. res[0].end = AR71XX_PCI_CFG_BASE + AR71XX_PCI_CFG_SIZE - 1;
  128. res[1].flags = IORESOURCE_IRQ;
  129. res[1].start = ATH79_CPU_IRQ(2);
  130. res[1].end = ATH79_CPU_IRQ(2);
  131. res[2].name = "io_base";
  132. res[2].flags = IORESOURCE_IO;
  133. res[2].start = 0;
  134. res[2].end = 0;
  135. res[3].name = "mem_base";
  136. res[3].flags = IORESOURCE_MEM;
  137. res[3].start = AR71XX_PCI_MEM_BASE;
  138. res[3].end = AR71XX_PCI_MEM_BASE + AR71XX_PCI_MEM_SIZE - 1;
  139. pdev = platform_device_register_simple("ar71xx-pci", -1,
  140. res, ARRAY_SIZE(res));
  141. return pdev;
  142. }
  143. static struct platform_device *
  144. ath79_register_pci_ar724x(int id,
  145. unsigned long cfg_base,
  146. unsigned long ctrl_base,
  147. unsigned long crp_base,
  148. unsigned long mem_base,
  149. unsigned long mem_size,
  150. unsigned long io_base,
  151. int irq)
  152. {
  153. struct platform_device *pdev;
  154. struct resource res[6];
  155. memset(res, 0, sizeof(res));
  156. res[0].name = "cfg_base";
  157. res[0].flags = IORESOURCE_MEM;
  158. res[0].start = cfg_base;
  159. res[0].end = cfg_base + AR724X_PCI_CFG_SIZE - 1;
  160. res[1].name = "ctrl_base";
  161. res[1].flags = IORESOURCE_MEM;
  162. res[1].start = ctrl_base;
  163. res[1].end = ctrl_base + AR724X_PCI_CTRL_SIZE - 1;
  164. res[2].flags = IORESOURCE_IRQ;
  165. res[2].start = irq;
  166. res[2].end = irq;
  167. res[3].name = "mem_base";
  168. res[3].flags = IORESOURCE_MEM;
  169. res[3].start = mem_base;
  170. res[3].end = mem_base + mem_size - 1;
  171. res[4].name = "io_base";
  172. res[4].flags = IORESOURCE_IO;
  173. res[4].start = io_base;
  174. res[4].end = io_base;
  175. res[5].name = "crp_base";
  176. res[5].flags = IORESOURCE_MEM;
  177. res[5].start = crp_base;
  178. res[5].end = crp_base + AR724X_PCI_CRP_SIZE - 1;
  179. pdev = platform_device_register_simple("ar724x-pci", id,
  180. res, ARRAY_SIZE(res));
  181. return pdev;
  182. }
  183. int __init ath79_register_pci(void)
  184. {
  185. struct platform_device *pdev = NULL;
  186. if (soc_is_ar71xx()) {
  187. pdev = ath79_register_pci_ar71xx();
  188. } else if (soc_is_ar724x()) {
  189. pdev = ath79_register_pci_ar724x(-1,
  190. AR724X_PCI_CFG_BASE,
  191. AR724X_PCI_CTRL_BASE,
  192. AR724X_PCI_CRP_BASE,
  193. AR724X_PCI_MEM_BASE,
  194. AR724X_PCI_MEM_SIZE,
  195. 0,
  196. ATH79_CPU_IRQ(2));
  197. } else if (soc_is_ar9342() ||
  198. soc_is_ar9344()) {
  199. u32 bootstrap;
  200. bootstrap = ath79_reset_rr(AR934X_RESET_REG_BOOTSTRAP);
  201. if ((bootstrap & AR934X_BOOTSTRAP_PCIE_RC) == 0)
  202. return -ENODEV;
  203. pdev = ath79_register_pci_ar724x(-1,
  204. AR724X_PCI_CFG_BASE,
  205. AR724X_PCI_CTRL_BASE,
  206. AR724X_PCI_CRP_BASE,
  207. AR724X_PCI_MEM_BASE,
  208. AR724X_PCI_MEM_SIZE,
  209. 0,
  210. ATH79_IP2_IRQ(0));
  211. } else if (soc_is_qca9558()) {
  212. pdev = ath79_register_pci_ar724x(0,
  213. QCA955X_PCI_CFG_BASE0,
  214. QCA955X_PCI_CTRL_BASE0,
  215. QCA955X_PCI_CRP_BASE0,
  216. QCA955X_PCI_MEM_BASE0,
  217. QCA955X_PCI_MEM_SIZE,
  218. 0,
  219. ATH79_IP2_IRQ(0));
  220. pdev = ath79_register_pci_ar724x(1,
  221. QCA955X_PCI_CFG_BASE1,
  222. QCA955X_PCI_CTRL_BASE1,
  223. QCA955X_PCI_CRP_BASE1,
  224. QCA955X_PCI_MEM_BASE1,
  225. QCA955X_PCI_MEM_SIZE,
  226. 1,
  227. ATH79_IP3_IRQ(2));
  228. } else {
  229. /* No PCI support */
  230. return -ENODEV;
  231. }
  232. if (!pdev)
  233. pr_err("unable to register PCI controller device\n");
  234. return pdev ? 0 : -ENODEV;
  235. }