1
0

0020-MIPS-pci-ar724x-convert-to-OF.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. From a522ee0199d5d3ea114ca2e211f6ac398d3e8e0b Mon Sep 17 00:00:00 2001
  2. From: John Crispin <john@phrozen.org>
  3. Date: Sat, 23 Jun 2018 15:07:37 +0200
  4. Subject: [PATCH 20/33] MIPS: pci-ar724x: convert to OF
  5. With the ath79 target getting converted to pure OF, we can drop all the
  6. platform data code and add the missing OF bits to the driver. We also add
  7. a irq domain for the PCI/e controllers cascade, thus making it usable from
  8. dts files.
  9. Signed-off-by: John Crispin <john@phrozen.org>
  10. ---
  11. arch/mips/pci/pci-ar724x.c | 88 ++++++++++++++++++++++------------------------
  12. 1 file changed, 42 insertions(+), 46 deletions(-)
  13. --- a/arch/mips/pci/pci-ar724x.c
  14. +++ b/arch/mips/pci/pci-ar724x.c
  15. @@ -14,8 +14,11 @@
  16. #include <linux/init.h>
  17. #include <linux/delay.h>
  18. #include <linux/platform_device.h>
  19. +#include <linux/irqchip/chained_irq.h>
  20. #include <asm/mach-ath79/ath79.h>
  21. #include <asm/mach-ath79/ar71xx_regs.h>
  22. +#include <linux/of_irq.h>
  23. +#include <linux/of_pci.h>
  24. #define AR724X_PCI_REG_APP 0x00
  25. #define AR724X_PCI_REG_RESET 0x18
  26. @@ -45,17 +48,20 @@ struct ar724x_pci_controller {
  27. void __iomem *crp_base;
  28. int irq;
  29. - int irq_base;
  30. bool link_up;
  31. bool bar0_is_cached;
  32. u32 bar0_value;
  33. + struct device_node *np;
  34. struct pci_controller pci_controller;
  35. + struct irq_domain *domain;
  36. struct resource io_res;
  37. struct resource mem_res;
  38. };
  39. +static struct irq_chip ar724x_pci_irq_chip;
  40. +
  41. static inline bool ar724x_pci_check_link(struct ar724x_pci_controller *apc)
  42. {
  43. u32 reset;
  44. @@ -231,35 +237,31 @@ static struct pci_ops ar724x_pci_ops = {
  45. static void ar724x_pci_irq_handler(struct irq_desc *desc)
  46. {
  47. - struct ar724x_pci_controller *apc;
  48. - void __iomem *base;
  49. + struct irq_chip *chip = irq_desc_get_chip(desc);
  50. + struct ar724x_pci_controller *apc = irq_desc_get_handler_data(desc);
  51. u32 pending;
  52. - apc = irq_desc_get_handler_data(desc);
  53. - base = apc->ctrl_base;
  54. -
  55. - pending = __raw_readl(base + AR724X_PCI_REG_INT_STATUS) &
  56. - __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  57. + chained_irq_enter(chip, desc);
  58. + pending = __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_STATUS) &
  59. + __raw_readl(apc->ctrl_base + AR724X_PCI_REG_INT_MASK);
  60. if (pending & AR724X_PCI_INT_DEV0)
  61. - generic_handle_irq(apc->irq_base + 0);
  62. -
  63. + generic_handle_irq(irq_linear_revmap(apc->domain, 1));
  64. else
  65. spurious_interrupt();
  66. + chained_irq_exit(chip, desc);
  67. }
  68. static void ar724x_pci_irq_unmask(struct irq_data *d)
  69. {
  70. struct ar724x_pci_controller *apc;
  71. void __iomem *base;
  72. - int offset;
  73. u32 t;
  74. apc = irq_data_get_irq_chip_data(d);
  75. base = apc->ctrl_base;
  76. - offset = apc->irq_base - d->irq;
  77. - switch (offset) {
  78. + switch (irq_linear_revmap(apc->domain, d->irq)) {
  79. case 0:
  80. t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  81. __raw_writel(t | AR724X_PCI_INT_DEV0,
  82. @@ -273,14 +275,12 @@ static void ar724x_pci_irq_mask(struct i
  83. {
  84. struct ar724x_pci_controller *apc;
  85. void __iomem *base;
  86. - int offset;
  87. u32 t;
  88. apc = irq_data_get_irq_chip_data(d);
  89. base = apc->ctrl_base;
  90. - offset = apc->irq_base - d->irq;
  91. - switch (offset) {
  92. + switch (irq_linear_revmap(apc->domain, d->irq)) {
  93. case 0:
  94. t = __raw_readl(base + AR724X_PCI_REG_INT_MASK);
  95. __raw_writel(t & ~AR724X_PCI_INT_DEV0,
  96. @@ -305,26 +305,34 @@ static struct irq_chip ar724x_pci_irq_ch
  97. .irq_mask_ack = ar724x_pci_irq_mask,
  98. };
  99. +static int ar724x_pci_irq_map(struct irq_domain *d,
  100. + unsigned int irq, irq_hw_number_t hw)
  101. +{
  102. + struct ar724x_pci_controller *apc = d->host_data;
  103. +
  104. + irq_set_chip_and_handler(irq, &ar724x_pci_irq_chip, handle_level_irq);
  105. + irq_set_chip_data(irq, apc);
  106. +
  107. + return 0;
  108. +}
  109. +
  110. +static const struct irq_domain_ops ar724x_pci_domain_ops = {
  111. + .xlate = irq_domain_xlate_onecell,
  112. + .map = ar724x_pci_irq_map,
  113. +};
  114. +
  115. static void ar724x_pci_irq_init(struct ar724x_pci_controller *apc,
  116. int id)
  117. {
  118. void __iomem *base;
  119. - int i;
  120. base = apc->ctrl_base;
  121. __raw_writel(0, base + AR724X_PCI_REG_INT_MASK);
  122. __raw_writel(0, base + AR724X_PCI_REG_INT_STATUS);
  123. - apc->irq_base = ATH79_PCI_IRQ_BASE + (id * AR724X_PCI_IRQ_COUNT);
  124. -
  125. - for (i = apc->irq_base;
  126. - i < apc->irq_base + AR724X_PCI_IRQ_COUNT; i++) {
  127. - irq_set_chip_and_handler(i, &ar724x_pci_irq_chip,
  128. - handle_level_irq);
  129. - irq_set_chip_data(i, apc);
  130. - }
  131. -
  132. + apc->domain = irq_domain_add_linear(apc->np, 2,
  133. + &ar724x_pci_domain_ops, apc);
  134. irq_set_chained_handler_and_data(apc->irq, ar724x_pci_irq_handler,
  135. apc);
  136. }
  137. @@ -394,29 +402,11 @@ static int ar724x_pci_probe(struct platf
  138. if (apc->irq < 0)
  139. return -EINVAL;
  140. - res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
  141. - if (!res)
  142. - return -EINVAL;
  143. -
  144. - apc->io_res.parent = res;
  145. - apc->io_res.name = "PCI IO space";
  146. - apc->io_res.start = res->start;
  147. - apc->io_res.end = res->end;
  148. - apc->io_res.flags = IORESOURCE_IO;
  149. -
  150. - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
  151. - if (!res)
  152. - return -EINVAL;
  153. -
  154. - apc->mem_res.parent = res;
  155. - apc->mem_res.name = "PCI memory space";
  156. - apc->mem_res.start = res->start;
  157. - apc->mem_res.end = res->end;
  158. - apc->mem_res.flags = IORESOURCE_MEM;
  159. -
  160. + apc->np = pdev->dev.of_node;
  161. apc->pci_controller.pci_ops = &ar724x_pci_ops;
  162. apc->pci_controller.io_resource = &apc->io_res;
  163. apc->pci_controller.mem_resource = &apc->mem_res;
  164. + pci_load_of_ranges(&apc->pci_controller, pdev->dev.of_node);
  165. /*
  166. * Do the full PCIE Root Complex Initialization Sequence if the PCIe
  167. @@ -438,10 +428,16 @@ static int ar724x_pci_probe(struct platf
  168. return 0;
  169. }
  170. +static const struct of_device_id ar724x_pci_ids[] = {
  171. + { .compatible = "qcom,ar7240-pci" },
  172. + {},
  173. +};
  174. +
  175. static struct platform_driver ar724x_pci_driver = {
  176. .probe = ar724x_pci_probe,
  177. .driver = {
  178. .name = "ar724x-pci",
  179. + .of_match_table = of_match_ptr(ar724x_pci_ids),
  180. },
  181. };