1
0

0018-MIPS-pci-ar71xx-convert-to-OF.patch 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. From 1855ab6b1d27f5b38a648baf57ff6a534afec26d Mon Sep 17 00:00:00 2001
  2. From: John Crispin <john@phrozen.org>
  3. Date: Sat, 23 Jun 2018 15:07:23 +0200
  4. Subject: [PATCH 18/33] MIPS: pci-ar71xx: 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-ar71xx.c | 82 +++++++++++++++++++++++-----------------------
  12. 1 file changed, 41 insertions(+), 41 deletions(-)
  13. --- a/arch/mips/pci/pci-ar71xx.c
  14. +++ b/arch/mips/pci/pci-ar71xx.c
  15. @@ -18,8 +18,11 @@
  16. #include <linux/pci.h>
  17. #include <linux/pci_regs.h>
  18. #include <linux/interrupt.h>
  19. +#include <linux/irqchip/chained_irq.h>
  20. #include <linux/init.h>
  21. #include <linux/platform_device.h>
  22. +#include <linux/of_irq.h>
  23. +#include <linux/of_pci.h>
  24. #include <asm/mach-ath79/ar71xx_regs.h>
  25. #include <asm/mach-ath79/ath79.h>
  26. @@ -49,12 +52,13 @@
  27. #define AR71XX_PCI_IRQ_COUNT 5
  28. struct ar71xx_pci_controller {
  29. + struct device_node *np;
  30. void __iomem *cfg_base;
  31. int irq;
  32. - int irq_base;
  33. struct pci_controller pci_ctrl;
  34. struct resource io_res;
  35. struct resource mem_res;
  36. + struct irq_domain *domain;
  37. };
  38. /* Byte lane enable bits */
  39. @@ -228,29 +232,30 @@ static struct pci_ops ar71xx_pci_ops = {
  40. static void ar71xx_pci_irq_handler(struct irq_desc *desc)
  41. {
  42. - struct ar71xx_pci_controller *apc;
  43. void __iomem *base = ath79_reset_base;
  44. + struct irq_chip *chip = irq_desc_get_chip(desc);
  45. + struct ar71xx_pci_controller *apc = irq_desc_get_handler_data(desc);
  46. u32 pending;
  47. - apc = irq_desc_get_handler_data(desc);
  48. -
  49. + chained_irq_enter(chip, desc);
  50. pending = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_STATUS) &
  51. __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  52. if (pending & AR71XX_PCI_INT_DEV0)
  53. - generic_handle_irq(apc->irq_base + 0);
  54. + generic_handle_irq(irq_linear_revmap(apc->domain, 1));
  55. else if (pending & AR71XX_PCI_INT_DEV1)
  56. - generic_handle_irq(apc->irq_base + 1);
  57. + generic_handle_irq(irq_linear_revmap(apc->domain, 2));
  58. else if (pending & AR71XX_PCI_INT_DEV2)
  59. - generic_handle_irq(apc->irq_base + 2);
  60. + generic_handle_irq(irq_linear_revmap(apc->domain, 3));
  61. else if (pending & AR71XX_PCI_INT_CORE)
  62. - generic_handle_irq(apc->irq_base + 4);
  63. + generic_handle_irq(irq_linear_revmap(apc->domain, 4));
  64. else
  65. spurious_interrupt();
  66. + chained_irq_exit(chip, desc);
  67. }
  68. static void ar71xx_pci_irq_unmask(struct irq_data *d)
  69. @@ -261,7 +266,7 @@ static void ar71xx_pci_irq_unmask(struct
  70. u32 t;
  71. apc = irq_data_get_irq_chip_data(d);
  72. - irq = d->irq - apc->irq_base;
  73. + irq = irq_linear_revmap(apc->domain, d->irq);
  74. t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  75. __raw_writel(t | (1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  76. @@ -278,7 +283,7 @@ static void ar71xx_pci_irq_mask(struct i
  77. u32 t;
  78. apc = irq_data_get_irq_chip_data(d);
  79. - irq = d->irq - apc->irq_base;
  80. + irq = irq_linear_revmap(apc->domain, d->irq);
  81. t = __raw_readl(base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  82. __raw_writel(t & ~(1 << irq), base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  83. @@ -294,24 +299,31 @@ static struct irq_chip ar71xx_pci_irq_ch
  84. .irq_mask_ack = ar71xx_pci_irq_mask,
  85. };
  86. +static int ar71xx_pci_irq_map(struct irq_domain *d,
  87. + unsigned int irq, irq_hw_number_t hw)
  88. +{
  89. + struct ar71xx_pci_controller *apc = d->host_data;
  90. +
  91. + irq_set_chip_and_handler(irq, &ar71xx_pci_irq_chip, handle_level_irq);
  92. + irq_set_chip_data(irq, apc);
  93. +
  94. + return 0;
  95. +}
  96. +
  97. +static const struct irq_domain_ops ar71xx_pci_domain_ops = {
  98. + .xlate = irq_domain_xlate_onecell,
  99. + .map = ar71xx_pci_irq_map,
  100. +};
  101. +
  102. static void ar71xx_pci_irq_init(struct ar71xx_pci_controller *apc)
  103. {
  104. void __iomem *base = ath79_reset_base;
  105. - int i;
  106. __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_ENABLE);
  107. __raw_writel(0, base + AR71XX_RESET_REG_PCI_INT_STATUS);
  108. - BUILD_BUG_ON(ATH79_PCI_IRQ_COUNT < AR71XX_PCI_IRQ_COUNT);
  109. -
  110. - apc->irq_base = ATH79_PCI_IRQ_BASE;
  111. - for (i = apc->irq_base;
  112. - i < apc->irq_base + AR71XX_PCI_IRQ_COUNT; i++) {
  113. - irq_set_chip_and_handler(i, &ar71xx_pci_irq_chip,
  114. - handle_level_irq);
  115. - irq_set_chip_data(i, apc);
  116. - }
  117. -
  118. + apc->domain = irq_domain_add_linear(apc->np, AR71XX_PCI_IRQ_COUNT,
  119. + &ar71xx_pci_domain_ops, apc);
  120. irq_set_chained_handler_and_data(apc->irq, ar71xx_pci_irq_handler,
  121. apc);
  122. }
  123. @@ -328,6 +340,11 @@ static void ar71xx_pci_reset(void)
  124. mdelay(100);
  125. }
  126. +static const struct of_device_id ar71xx_pci_ids[] = {
  127. + { .compatible = "qca,ar7100-pci" },
  128. + {},
  129. +};
  130. +
  131. static int ar71xx_pci_probe(struct platform_device *pdev)
  132. {
  133. struct ar71xx_pci_controller *apc;
  134. @@ -348,26 +365,6 @@ static int ar71xx_pci_probe(struct platf
  135. if (apc->irq < 0)
  136. return -EINVAL;
  137. - res = platform_get_resource_byname(pdev, IORESOURCE_IO, "io_base");
  138. - if (!res)
  139. - return -EINVAL;
  140. -
  141. - apc->io_res.parent = res;
  142. - apc->io_res.name = "PCI IO space";
  143. - apc->io_res.start = res->start;
  144. - apc->io_res.end = res->end;
  145. - apc->io_res.flags = IORESOURCE_IO;
  146. -
  147. - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mem_base");
  148. - if (!res)
  149. - return -EINVAL;
  150. -
  151. - apc->mem_res.parent = res;
  152. - apc->mem_res.name = "PCI memory space";
  153. - apc->mem_res.start = res->start;
  154. - apc->mem_res.end = res->end;
  155. - apc->mem_res.flags = IORESOURCE_MEM;
  156. -
  157. ar71xx_pci_reset();
  158. /* setup COMMAND register */
  159. @@ -380,9 +377,11 @@ static int ar71xx_pci_probe(struct platf
  160. ar71xx_pci_irq_init(apc);
  161. + apc->np = pdev->dev.of_node;
  162. apc->pci_ctrl.pci_ops = &ar71xx_pci_ops;
  163. apc->pci_ctrl.mem_resource = &apc->mem_res;
  164. apc->pci_ctrl.io_resource = &apc->io_res;
  165. + pci_load_of_ranges(&apc->pci_ctrl, pdev->dev.of_node);
  166. register_pci_controller(&apc->pci_ctrl);
  167. @@ -393,6 +392,7 @@ static struct platform_driver ar71xx_pci
  168. .probe = ar71xx_pci_probe,
  169. .driver = {
  170. .name = "ar71xx-pci",
  171. + .of_match_table = of_match_ptr(ar71xx_pci_ids),
  172. },
  173. };