media5200.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 struct of_device_id mpc5200_gpio_ids[] __initdata = {
  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_host *irqhost;
  44. };
  45. struct media5200_irq media5200_irq;
  46. static void media5200_irq_unmask(unsigned int virq)
  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 + irq_map[virq].hwirq);
  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(unsigned int virq)
  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 + irq_map[virq].hwirq));
  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. .typename = "Media5200 FPGA",
  68. .unmask = media5200_irq_unmask,
  69. .mask = media5200_irq_mask,
  70. .mask_ack = media5200_irq_mask,
  71. };
  72. void media5200_irq_cascade(unsigned int virq, struct irq_desc *desc)
  73. {
  74. int sub_virq, val;
  75. u32 status, enable;
  76. /* Mask off the cascaded IRQ */
  77. spin_lock(&desc->lock);
  78. desc->chip->mask(virq);
  79. spin_unlock(&desc->lock);
  80. /* Ask the FPGA for IRQ status. If 'val' is 0, then no irqs
  81. * are pending. 'ffs()' is 1 based */
  82. status = in_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE);
  83. enable = in_be32(media5200_irq.regs + MEDIA5200_IRQ_STATUS);
  84. val = ffs((status & enable) >> MEDIA5200_IRQ_SHIFT);
  85. if (val) {
  86. sub_virq = irq_linear_revmap(media5200_irq.irqhost, val - 1);
  87. /* pr_debug("%s: virq=%i s=%.8x e=%.8x hwirq=%i subvirq=%i\n",
  88. * __func__, virq, status, enable, val - 1, sub_virq);
  89. */
  90. generic_handle_irq(sub_virq);
  91. }
  92. /* Processing done; can reenable the cascade now */
  93. spin_lock(&desc->lock);
  94. desc->chip->ack(virq);
  95. if (!(desc->status & IRQ_DISABLED))
  96. desc->chip->unmask(virq);
  97. spin_unlock(&desc->lock);
  98. }
  99. static int media5200_irq_map(struct irq_host *h, unsigned int virq,
  100. irq_hw_number_t hw)
  101. {
  102. struct irq_desc *desc = get_irq_desc(virq);
  103. pr_debug("%s: h=%p, virq=%i, hwirq=%i\n", __func__, h, virq, (int)hw);
  104. set_irq_chip_data(virq, &media5200_irq);
  105. set_irq_chip_and_handler(virq, &media5200_irq_chip, handle_level_irq);
  106. set_irq_type(virq, IRQ_TYPE_LEVEL_LOW);
  107. desc->status &= ~(IRQ_TYPE_SENSE_MASK | IRQ_LEVEL);
  108. desc->status |= IRQ_TYPE_LEVEL_LOW | IRQ_LEVEL;
  109. return 0;
  110. }
  111. static int media5200_irq_xlate(struct irq_host *h, struct device_node *ct,
  112. u32 *intspec, unsigned int intsize,
  113. irq_hw_number_t *out_hwirq,
  114. unsigned int *out_flags)
  115. {
  116. if (intsize != 2)
  117. return -1;
  118. pr_debug("%s: bank=%i, number=%i\n", __func__, intspec[0], intspec[1]);
  119. *out_hwirq = intspec[1];
  120. *out_flags = IRQ_TYPE_NONE;
  121. return 0;
  122. }
  123. static struct irq_host_ops media5200_irq_ops = {
  124. .map = media5200_irq_map,
  125. .xlate = media5200_irq_xlate,
  126. };
  127. /*
  128. * Setup Media5200 IRQ mapping
  129. */
  130. static void __init media5200_init_irq(void)
  131. {
  132. struct device_node *fpga_np;
  133. int cascade_virq;
  134. /* First setup the regular MPC5200 interrupt controller */
  135. mpc52xx_init_irq();
  136. /* Now find the FPGA IRQ */
  137. fpga_np = of_find_compatible_node(NULL, NULL, "fsl,media5200-fpga");
  138. if (!fpga_np)
  139. goto out;
  140. pr_debug("%s: found fpga node: %s\n", __func__, fpga_np->full_name);
  141. media5200_irq.regs = of_iomap(fpga_np, 0);
  142. if (!media5200_irq.regs)
  143. goto out;
  144. pr_debug("%s: mapped to %p\n", __func__, media5200_irq.regs);
  145. cascade_virq = irq_of_parse_and_map(fpga_np, 0);
  146. if (!cascade_virq)
  147. goto out;
  148. pr_debug("%s: cascaded on virq=%i\n", __func__, cascade_virq);
  149. /* Disable all FPGA IRQs */
  150. out_be32(media5200_irq.regs + MEDIA5200_IRQ_ENABLE, 0);
  151. spin_lock_init(&media5200_irq.lock);
  152. media5200_irq.irqhost = irq_alloc_host(fpga_np, IRQ_HOST_MAP_LINEAR,
  153. MEDIA5200_NUM_IRQS,
  154. &media5200_irq_ops, -1);
  155. if (!media5200_irq.irqhost)
  156. goto out;
  157. pr_debug("%s: allocated irqhost\n", __func__);
  158. media5200_irq.irqhost->host_data = &media5200_irq;
  159. set_irq_data(cascade_virq, &media5200_irq);
  160. set_irq_chained_handler(cascade_virq, media5200_irq_cascade);
  161. return;
  162. out:
  163. pr_err("Could not find Media5200 FPGA; PCI interrupts will not work\n");
  164. }
  165. /*
  166. * Setup the architecture
  167. */
  168. static void __init media5200_setup_arch(void)
  169. {
  170. struct device_node *np;
  171. struct mpc52xx_gpio __iomem *gpio;
  172. u32 port_config;
  173. if (ppc_md.progress)
  174. ppc_md.progress("media5200_setup_arch()", 0);
  175. /* Map important registers from the internal memory map */
  176. mpc52xx_map_common_devices();
  177. /* Some mpc5200 & mpc5200b related configuration */
  178. mpc5200_setup_xlb_arbiter();
  179. mpc52xx_setup_pci();
  180. np = of_find_matching_node(NULL, mpc5200_gpio_ids);
  181. gpio = of_iomap(np, 0);
  182. of_node_put(np);
  183. if (!gpio) {
  184. printk(KERN_ERR "%s() failed. expect abnormal behavior\n",
  185. __func__);
  186. return;
  187. }
  188. /* Set port config */
  189. port_config = in_be32(&gpio->port_config);
  190. port_config &= ~0x03000000; /* ATA CS is on csb_4/5 */
  191. port_config |= 0x01000000;
  192. out_be32(&gpio->port_config, port_config);
  193. /* Unmap zone */
  194. iounmap(gpio);
  195. }
  196. /* list of the supported boards */
  197. static char *board[] __initdata = {
  198. "fsl,media5200",
  199. NULL
  200. };
  201. /*
  202. * Called very early, MMU is off, device-tree isn't unflattened
  203. */
  204. static int __init media5200_probe(void)
  205. {
  206. unsigned long node = of_get_flat_dt_root();
  207. int i = 0;
  208. while (board[i]) {
  209. if (of_flat_dt_is_compatible(node, board[i]))
  210. break;
  211. i++;
  212. }
  213. return (board[i] != NULL);
  214. }
  215. define_machine(media5200_platform) {
  216. .name = "media5200-platform",
  217. .probe = media5200_probe,
  218. .setup_arch = media5200_setup_arch,
  219. .init = mpc52xx_declare_of_platform_devices,
  220. .init_IRQ = media5200_init_irq,
  221. .get_irq = mpc52xx_get_irq,
  222. .restart = mpc52xx_restart,
  223. .calibrate_decr = generic_calibrate_decr,
  224. };