media5200.c 6.8 KB

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