media5200.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for 'media5200-platform' compatible boards.
  4. *
  5. * Copyright (C) 2008 Secret Lab Technologies Ltd.
  6. *
  7. * Description:
  8. * This code implements support for the Freescape Media5200 platform
  9. * (built around the MPC5200 SoC).
  10. *
  11. * Notable characteristic of the Media5200 is the presence of an FPGA
  12. * that has all external IRQ lines routed through it. This file implements
  13. * a cascaded interrupt controller driver which attaches itself to the
  14. * Virtual IRQ subsystem after the primary mpc5200 interrupt controller
  15. * is initialized.
  16. */
  17. #undef DEBUG
  18. #include <linux/irq.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/io.h>
  21. #include <linux/of_address.h>
  22. #include <linux/of_irq.h>
  23. #include <asm/time.h>
  24. #include <asm/machdep.h>
  25. #include <asm/mpc52xx.h>
  26. static const struct of_device_id mpc5200_gpio_ids[] __initconst = {
  27. { .compatible = "fsl,mpc5200-gpio", },
  28. { .compatible = "mpc5200-gpio", },
  29. {}
  30. };
  31. /* FPGA register set */
  32. #define MEDIA5200_IRQ_ENABLE (0x40c)
  33. #define MEDIA5200_IRQ_STATUS (0x410)
  34. #define MEDIA5200_NUM_IRQS (6)
  35. #define MEDIA5200_IRQ_SHIFT (32 - MEDIA5200_NUM_IRQS)
  36. struct media5200_irq {
  37. void __iomem *regs;
  38. spinlock_t lock;
  39. struct irq_domain *irqhost;
  40. };
  41. struct media5200_irq media5200_irq;
  42. static void media5200_irq_unmask(struct irq_data *d)
  43. {
  44. unsigned long flags;
  45. u32 val;
  46. spin_lock_irqsave(&media5200_irq.lock, flags);
  47. val = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE);
  48. val |= 1 << (MEDIA5200_IRQ_SHIFT + irqd_to_hwirq(d));
  49. out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, val);
  50. spin_unlock_irqrestore(&media5200_irq.lock, flags);
  51. }
  52. static void media5200_irq_mask(struct irq_data *d)
  53. {
  54. unsigned long flags;
  55. u32 val;
  56. spin_lock_irqsave(&media5200_irq.lock, flags);
  57. val = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE);
  58. val &= ~(1 << (MEDIA5200_IRQ_SHIFT + irqd_to_hwirq(d)));
  59. out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, val);
  60. spin_unlock_irqrestore(&media5200_irq.lock, flags);
  61. }
  62. static struct irq_chip media5200_irq_chip = {
  63. .name = "Media5200 FPGA",
  64. .irq_unmask = media5200_irq_unmask,
  65. .irq_mask = media5200_irq_mask,
  66. .irq_mask_ack = media5200_irq_mask,
  67. };
  68. static void media5200_irq_cascade(struct irq_desc *desc)
  69. {
  70. struct irq_chip *chip = irq_desc_get_chip(desc);
  71. int val;
  72. u32 status, enable;
  73. /* Mask off the cascaded IRQ */
  74. raw_spin_lock(&desc->lock);
  75. chip->irq_mask(&desc->irq_data);
  76. raw_spin_unlock(&desc->lock);
  77. /* Ask the FPGA for IRQ status. If 'val' is 0, then no irqs
  78. * are pending. 'ffs()' is 1 based */
  79. status = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE);
  80. enable = in_be32(media5200_irq.regs + MEDIA5200_IRQ_STATUS);
  81. val = ffs((status & enable) >> MEDIA5200_IRQ_SHIFT);
  82. if (val) {
  83. generic_handle_domain_irq(media5200_irq.irqhost, val - 1);
  84. /* pr_debug("%s: virq=%i s=%.8x e=%.8x hwirq=%i\n",
  85. * __func__, virq, status, enable, val - 1);
  86. */
  87. }
  88. /* Processing done; can reenable the cascade now */
  89. raw_spin_lock(&desc->lock);
  90. chip->irq_ack(&desc->irq_data);
  91. if (!irqd_irq_disabled(&desc->irq_data))
  92. chip->irq_unmask(&desc->irq_data);
  93. raw_spin_unlock(&desc->lock);
  94. }
  95. static int media5200_irq_map(struct irq_domain *h, unsigned int virq,
  96. irq_hw_number_t hw)
  97. {
  98. pr_debug("%s: h=%p, virq=%i, hwirq=%i\n", __func__, h, virq, (int)hw);
  99. irq_set_chip_data(virq, &media5200_irq);
  100. irq_set_chip_and_handler(virq, &media5200_irq_chip, handle_level_irq);
  101. irq_set_status_flags(virq, IRQ_LEVEL);
  102. return 0;
  103. }
  104. static int media5200_irq_xlate(struct irq_domain *h, struct device_node *ct,
  105. const u32 *intspec, unsigned int intsize,
  106. irq_hw_number_t *out_hwirq,
  107. unsigned int *out_flags)
  108. {
  109. if (intsize != 2)
  110. return -1;
  111. pr_debug("%s: bank=%i, number=%i\n", __func__, intspec[0], intspec[1]);
  112. *out_hwirq = intspec[1];
  113. *out_flags = IRQ_TYPE_NONE;
  114. return 0;
  115. }
  116. static const struct irq_domain_ops media5200_irq_ops = {
  117. .map = media5200_irq_map,
  118. .xlate = media5200_irq_xlate,
  119. };
  120. /*
  121. * Setup Media5200 IRQ mapping
  122. */
  123. static void __init media5200_init_irq(void)
  124. {
  125. struct device_node *fpga_np;
  126. int cascade_virq;
  127. /* First setup the regular MPC5200 interrupt controller */
  128. mpc52xx_init_irq();
  129. /* Now find the FPGA IRQ */
  130. fpga_np = of_find_compatible_node(NULL, NULL, "fsl,media5200-fpga");
  131. if (!fpga_np)
  132. goto out;
  133. pr_debug("%s: found fpga node: %pOF\n", __func__, fpga_np);
  134. media5200_irq.regs = of_iomap(fpga_np, 0);
  135. if (!media5200_irq.regs)
  136. goto out;
  137. pr_debug("%s: mapped to %p\n", __func__, media5200_irq.regs);
  138. cascade_virq = irq_of_parse_and_map(fpga_np, 0);
  139. if (!cascade_virq)
  140. goto out;
  141. pr_debug("%s: cascaded on virq=%i\n", __func__, cascade_virq);
  142. /* Disable all FPGA IRQs */
  143. out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, 0);
  144. spin_lock_init(&media5200_irq.lock);
  145. media5200_irq.irqhost = irq_domain_add_linear(fpga_np,
  146. MEDIA5200_NUM_IRQS, &media5200_irq_ops, &media5200_irq);
  147. if (!media5200_irq.irqhost)
  148. goto out;
  149. pr_debug("%s: allocated irqhost\n", __func__);
  150. of_node_put(fpga_np);
  151. irq_set_handler_data(cascade_virq, &media5200_irq);
  152. irq_set_chained_handler(cascade_virq, media5200_irq_cascade);
  153. return;
  154. out:
  155. pr_err("Could not find Media5200 FPGA; PCI interrupts will not work\n");
  156. of_node_put(fpga_np);
  157. }
  158. /*
  159. * Setup the architecture
  160. */
  161. static void __init media5200_setup_arch(void)
  162. {
  163. struct device_node *np;
  164. struct mpc52xx_gpio __iomem *gpio;
  165. u32 port_config;
  166. if (ppc_md.progress)
  167. ppc_md.progress("media5200_setup_arch()", 0);
  168. /* Map important registers from the internal memory map */
  169. mpc52xx_map_common_devices();
  170. /* Some mpc5200 & mpc5200b related configuration */
  171. mpc5200_setup_xlb_arbiter();
  172. np = of_find_matching_node(NULL, mpc5200_gpio_ids);
  173. gpio = of_iomap(np, 0);
  174. of_node_put(np);
  175. if (!gpio) {
  176. printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
  177. __func__);
  178. return;
  179. }
  180. /* Set port config */
  181. port_config = in_be32(&gpio->port_config);
  182. port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
  183. port_config |= 0x01000000;
  184. out_be32(&gpio->port_config, port_config);
  185. /* Unmap zone */
  186. iounmap(gpio);
  187. }
  188. /* list of the supported boards */
  189. static const char * const board[] __initconst = {
  190. "fsl,media5200",
  191. NULL
  192. };
  193. /*
  194. * Called very early, MMU is off, device-tree isn't unflattened
  195. */
  196. static int __init media5200_probe(void)
  197. {
  198. return of_device_compatible_match(of_root, board);
  199. }
  200. define_machine(media5200_platform) {
  201. .name = "media5200-platform",
  202. .probe = media5200_probe,
  203. .setup_arch = media5200_setup_arch,
  204. .discover_phbs = mpc52xx_setup_pci,
  205. .init = mpc52xx_declare_of_platform_devices,
  206. .init_IRQ = media5200_init_irq,
  207. .get_irq = mpc52xx_get_irq,
  208. .restart = mpc52xx_restart,
  209. .calibrate_decr = generic_calibrate_decr,
  210. };