irq-vt8500.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. * arch/arm/mach-vt8500/irq.c
  3. *
  4. * Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz>
  5. * Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /*
  22. * This file is copied and modified from the original irq.c provided by
  23. * Alexey Charkov. Minor changes have been made for Device Tree Support.
  24. */
  25. #include <linux/slab.h>
  26. #include <linux/io.h>
  27. #include <linux/irq.h>
  28. #include <linux/irqchip.h>
  29. #include <linux/irqdomain.h>
  30. #include <linux/interrupt.h>
  31. #include <linux/bitops.h>
  32. #include <linux/of.h>
  33. #include <linux/of_irq.h>
  34. #include <linux/of_address.h>
  35. #include <asm/irq.h>
  36. #include <asm/exception.h>
  37. #include <asm/mach/irq.h>
  38. #define VT8500_ICPC_IRQ 0x20
  39. #define VT8500_ICPC_FIQ 0x24
  40. #define VT8500_ICDC 0x40 /* Destination Control 64*u32 */
  41. #define VT8500_ICIS 0x80 /* Interrupt status, 16*u32 */
  42. /* ICPC */
  43. #define ICPC_MASK 0x3F
  44. #define ICPC_ROTATE BIT(6)
  45. /* IC_DCTR */
  46. #define ICDC_IRQ 0x00
  47. #define ICDC_FIQ 0x01
  48. #define ICDC_DSS0 0x02
  49. #define ICDC_DSS1 0x03
  50. #define ICDC_DSS2 0x04
  51. #define ICDC_DSS3 0x05
  52. #define ICDC_DSS4 0x06
  53. #define ICDC_DSS5 0x07
  54. #define VT8500_INT_DISABLE 0
  55. #define VT8500_INT_ENABLE BIT(3)
  56. #define VT8500_TRIGGER_HIGH 0
  57. #define VT8500_TRIGGER_RISING BIT(5)
  58. #define VT8500_TRIGGER_FALLING BIT(6)
  59. #define VT8500_EDGE ( VT8500_TRIGGER_RISING \
  60. | VT8500_TRIGGER_FALLING)
  61. /* vt8500 has 1 intc, wm8505 and wm8650 have 2 */
  62. #define VT8500_INTC_MAX 2
  63. struct vt8500_irq_data {
  64. void __iomem *base; /* IO Memory base address */
  65. struct irq_domain *domain; /* Domain for this controller */
  66. };
  67. /* Global variable for accessing io-mem addresses */
  68. static struct vt8500_irq_data intc[VT8500_INTC_MAX];
  69. static u32 active_cnt = 0;
  70. static void vt8500_irq_mask(struct irq_data *d)
  71. {
  72. struct vt8500_irq_data *priv = d->domain->host_data;
  73. void __iomem *base = priv->base;
  74. void __iomem *stat_reg = base + VT8500_ICIS + (d->hwirq < 32 ? 0 : 4);
  75. u8 edge, dctr;
  76. u32 status;
  77. edge = readb(base + VT8500_ICDC + d->hwirq) & VT8500_EDGE;
  78. if (edge) {
  79. status = readl(stat_reg);
  80. status |= (1 << (d->hwirq & 0x1f));
  81. writel(status, stat_reg);
  82. } else {
  83. dctr = readb(base + VT8500_ICDC + d->hwirq);
  84. dctr &= ~VT8500_INT_ENABLE;
  85. writeb(dctr, base + VT8500_ICDC + d->hwirq);
  86. }
  87. }
  88. static void vt8500_irq_unmask(struct irq_data *d)
  89. {
  90. struct vt8500_irq_data *priv = d->domain->host_data;
  91. void __iomem *base = priv->base;
  92. u8 dctr;
  93. dctr = readb(base + VT8500_ICDC + d->hwirq);
  94. dctr |= VT8500_INT_ENABLE;
  95. writeb(dctr, base + VT8500_ICDC + d->hwirq);
  96. }
  97. static int vt8500_irq_set_type(struct irq_data *d, unsigned int flow_type)
  98. {
  99. struct vt8500_irq_data *priv = d->domain->host_data;
  100. void __iomem *base = priv->base;
  101. u8 dctr;
  102. dctr = readb(base + VT8500_ICDC + d->hwirq);
  103. dctr &= ~VT8500_EDGE;
  104. switch (flow_type) {
  105. case IRQF_TRIGGER_LOW:
  106. return -EINVAL;
  107. case IRQF_TRIGGER_HIGH:
  108. dctr |= VT8500_TRIGGER_HIGH;
  109. irq_set_handler_locked(d, handle_level_irq);
  110. break;
  111. case IRQF_TRIGGER_FALLING:
  112. dctr |= VT8500_TRIGGER_FALLING;
  113. irq_set_handler_locked(d, handle_edge_irq);
  114. break;
  115. case IRQF_TRIGGER_RISING:
  116. dctr |= VT8500_TRIGGER_RISING;
  117. irq_set_handler_locked(d, handle_edge_irq);
  118. break;
  119. }
  120. writeb(dctr, base + VT8500_ICDC + d->hwirq);
  121. return 0;
  122. }
  123. static struct irq_chip vt8500_irq_chip = {
  124. .name = "vt8500",
  125. .irq_ack = vt8500_irq_mask,
  126. .irq_mask = vt8500_irq_mask,
  127. .irq_unmask = vt8500_irq_unmask,
  128. .irq_set_type = vt8500_irq_set_type,
  129. };
  130. static void __init vt8500_init_irq_hw(void __iomem *base)
  131. {
  132. u32 i;
  133. /* Enable rotating priority for IRQ */
  134. writel(ICPC_ROTATE, base + VT8500_ICPC_IRQ);
  135. writel(0x00, base + VT8500_ICPC_FIQ);
  136. /* Disable all interrupts and route them to IRQ */
  137. for (i = 0; i < 64; i++)
  138. writeb(VT8500_INT_DISABLE | ICDC_IRQ, base + VT8500_ICDC + i);
  139. }
  140. static int vt8500_irq_map(struct irq_domain *h, unsigned int virq,
  141. irq_hw_number_t hw)
  142. {
  143. irq_set_chip_and_handler(virq, &vt8500_irq_chip, handle_level_irq);
  144. return 0;
  145. }
  146. static const struct irq_domain_ops vt8500_irq_domain_ops = {
  147. .map = vt8500_irq_map,
  148. .xlate = irq_domain_xlate_onecell,
  149. };
  150. static void __exception_irq_entry vt8500_handle_irq(struct pt_regs *regs)
  151. {
  152. u32 stat, i;
  153. int irqnr;
  154. void __iomem *base;
  155. /* Loop through each active controller */
  156. for (i=0; i<active_cnt; i++) {
  157. base = intc[i].base;
  158. irqnr = readl_relaxed(base) & 0x3F;
  159. /*
  160. Highest Priority register default = 63, so check that this
  161. is a real interrupt by checking the status register
  162. */
  163. if (irqnr == 63) {
  164. stat = readl_relaxed(base + VT8500_ICIS + 4);
  165. if (!(stat & BIT(31)))
  166. continue;
  167. }
  168. handle_domain_irq(intc[i].domain, irqnr, regs);
  169. }
  170. }
  171. static int __init vt8500_irq_init(struct device_node *node,
  172. struct device_node *parent)
  173. {
  174. int irq, i;
  175. struct device_node *np = node;
  176. if (active_cnt == VT8500_INTC_MAX) {
  177. pr_err("%s: Interrupt controllers > VT8500_INTC_MAX\n",
  178. __func__);
  179. goto out;
  180. }
  181. intc[active_cnt].base = of_iomap(np, 0);
  182. intc[active_cnt].domain = irq_domain_add_linear(node, 64,
  183. &vt8500_irq_domain_ops, &intc[active_cnt]);
  184. if (!intc[active_cnt].base) {
  185. pr_err("%s: Unable to map IO memory\n", __func__);
  186. goto out;
  187. }
  188. if (!intc[active_cnt].domain) {
  189. pr_err("%s: Unable to add irq domain!\n", __func__);
  190. goto out;
  191. }
  192. set_handle_irq(vt8500_handle_irq);
  193. vt8500_init_irq_hw(intc[active_cnt].base);
  194. pr_info("vt8500-irq: Added interrupt controller\n");
  195. active_cnt++;
  196. /* check if this is a slaved controller */
  197. if (of_irq_count(np) != 0) {
  198. /* check that we have the correct number of interrupts */
  199. if (of_irq_count(np) != 8) {
  200. pr_err("%s: Incorrect IRQ map for slaved controller\n",
  201. __func__);
  202. return -EINVAL;
  203. }
  204. for (i = 0; i < 8; i++) {
  205. irq = irq_of_parse_and_map(np, i);
  206. enable_irq(irq);
  207. }
  208. pr_info("vt8500-irq: Enabled slave->parent interrupts\n");
  209. }
  210. out:
  211. return 0;
  212. }
  213. IRQCHIP_DECLARE(vt8500_irq, "via,vt8500-intc", vt8500_irq_init);