cp_intc.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * TI Common Platform Interrupt Controller (cp_intc) driver
  3. *
  4. * Author: Steve Chen <schen@mvista.com>
  5. * Copyright (C) 2008-2009, MontaVista Software, Inc. <source@mvista.com>
  6. *
  7. * This file is licensed under the terms of the GNU General Public License
  8. * version 2. This program is licensed "as is" without any warranty of any
  9. * kind, whether express or implied.
  10. */
  11. #include <linux/export.h>
  12. #include <linux/init.h>
  13. #include <linux/irq.h>
  14. #include <linux/irqdomain.h>
  15. #include <linux/io.h>
  16. #include <mach/common.h>
  17. #include <mach/cp_intc.h>
  18. static inline unsigned int cp_intc_read(unsigned offset)
  19. {
  20. return __raw_readl(davinci_intc_base + offset);
  21. }
  22. static inline void cp_intc_write(unsigned long value, unsigned offset)
  23. {
  24. __raw_writel(value, davinci_intc_base + offset);
  25. }
  26. static void cp_intc_ack_irq(struct irq_data *d)
  27. {
  28. cp_intc_write(d->hwirq, CP_INTC_SYS_STAT_IDX_CLR);
  29. }
  30. /* Disable interrupt */
  31. static void cp_intc_mask_irq(struct irq_data *d)
  32. {
  33. /* XXX don't know why we need to disable nIRQ here... */
  34. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_CLR);
  35. cp_intc_write(d->hwirq, CP_INTC_SYS_ENABLE_IDX_CLR);
  36. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET);
  37. }
  38. /* Enable interrupt */
  39. static void cp_intc_unmask_irq(struct irq_data *d)
  40. {
  41. cp_intc_write(d->hwirq, CP_INTC_SYS_ENABLE_IDX_SET);
  42. }
  43. static int cp_intc_set_irq_type(struct irq_data *d, unsigned int flow_type)
  44. {
  45. unsigned reg = BIT_WORD(d->hwirq);
  46. unsigned mask = BIT_MASK(d->hwirq);
  47. unsigned polarity = cp_intc_read(CP_INTC_SYS_POLARITY(reg));
  48. unsigned type = cp_intc_read(CP_INTC_SYS_TYPE(reg));
  49. switch (flow_type) {
  50. case IRQ_TYPE_EDGE_RISING:
  51. polarity |= mask;
  52. type |= mask;
  53. break;
  54. case IRQ_TYPE_EDGE_FALLING:
  55. polarity &= ~mask;
  56. type |= mask;
  57. break;
  58. case IRQ_TYPE_LEVEL_HIGH:
  59. polarity |= mask;
  60. type &= ~mask;
  61. break;
  62. case IRQ_TYPE_LEVEL_LOW:
  63. polarity &= ~mask;
  64. type &= ~mask;
  65. break;
  66. default:
  67. return -EINVAL;
  68. }
  69. cp_intc_write(polarity, CP_INTC_SYS_POLARITY(reg));
  70. cp_intc_write(type, CP_INTC_SYS_TYPE(reg));
  71. return 0;
  72. }
  73. /*
  74. * Faking this allows us to to work with suspend functions of
  75. * generic drivers which call {enable|disable}_irq_wake for
  76. * wake up interrupt sources (eg RTC on DA850).
  77. */
  78. static int cp_intc_set_wake(struct irq_data *d, unsigned int on)
  79. {
  80. return 0;
  81. }
  82. static struct irq_chip cp_intc_irq_chip = {
  83. .name = "cp_intc",
  84. .irq_ack = cp_intc_ack_irq,
  85. .irq_mask = cp_intc_mask_irq,
  86. .irq_unmask = cp_intc_unmask_irq,
  87. .irq_set_type = cp_intc_set_irq_type,
  88. .irq_set_wake = cp_intc_set_wake,
  89. };
  90. static struct irq_domain *cp_intc_domain;
  91. static int cp_intc_host_map(struct irq_domain *h, unsigned int virq,
  92. irq_hw_number_t hw)
  93. {
  94. pr_debug("cp_intc_host_map(%d, 0x%lx)\n", virq, hw);
  95. irq_set_chip(virq, &cp_intc_irq_chip);
  96. set_irq_flags(virq, IRQF_VALID | IRQF_PROBE);
  97. irq_set_handler(virq, handle_edge_irq);
  98. return 0;
  99. }
  100. static const struct irq_domain_ops cp_intc_host_ops = {
  101. .map = cp_intc_host_map,
  102. .xlate = irq_domain_xlate_onetwocell,
  103. };
  104. int __init __cp_intc_init(struct device_node *node)
  105. {
  106. u32 num_irq = davinci_soc_info.intc_irq_num;
  107. u8 *irq_prio = davinci_soc_info.intc_irq_prios;
  108. u32 *host_map = davinci_soc_info.intc_host_map;
  109. unsigned num_reg = BITS_TO_LONGS(num_irq);
  110. int i, irq_base;
  111. davinci_intc_type = DAVINCI_INTC_TYPE_CP_INTC;
  112. davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_8K);
  113. if (WARN_ON(!davinci_intc_base))
  114. return -EINVAL;
  115. cp_intc_write(0, CP_INTC_GLOBAL_ENABLE);
  116. /* Disable all host interrupts */
  117. cp_intc_write(0, CP_INTC_HOST_ENABLE(0));
  118. /* Disable system interrupts */
  119. for (i = 0; i < num_reg; i++)
  120. cp_intc_write(~0, CP_INTC_SYS_ENABLE_CLR(i));
  121. /* Set to normal mode, no nesting, no priority hold */
  122. cp_intc_write(0, CP_INTC_CTRL);
  123. cp_intc_write(0, CP_INTC_HOST_CTRL);
  124. /* Clear system interrupt status */
  125. for (i = 0; i < num_reg; i++)
  126. cp_intc_write(~0, CP_INTC_SYS_STAT_CLR(i));
  127. /* Enable nIRQ (what about nFIQ?) */
  128. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET);
  129. /*
  130. * Priority is determined by host channel: lower channel number has
  131. * higher priority i.e. channel 0 has highest priority and channel 31
  132. * had the lowest priority.
  133. */
  134. num_reg = (num_irq + 3) >> 2; /* 4 channels per register */
  135. if (irq_prio) {
  136. unsigned j, k;
  137. u32 val;
  138. for (k = i = 0; i < num_reg; i++) {
  139. for (val = j = 0; j < 4; j++, k++) {
  140. val >>= 8;
  141. if (k < num_irq)
  142. val |= irq_prio[k] << 24;
  143. }
  144. cp_intc_write(val, CP_INTC_CHAN_MAP(i));
  145. }
  146. } else {
  147. /*
  148. * Default everything to channel 15 if priority not specified.
  149. * Note that channel 0-1 are mapped to nFIQ and channels 2-31
  150. * are mapped to nIRQ.
  151. */
  152. for (i = 0; i < num_reg; i++)
  153. cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i));
  154. }
  155. if (host_map)
  156. for (i = 0; host_map[i] != -1; i++)
  157. cp_intc_write(host_map[i], CP_INTC_HOST_MAP(i));
  158. irq_base = irq_alloc_descs(-1, 0, num_irq, 0);
  159. if (irq_base < 0) {
  160. pr_warn("Couldn't allocate IRQ numbers\n");
  161. irq_base = 0;
  162. }
  163. /* create a legacy host */
  164. cp_intc_domain = irq_domain_add_legacy(node, num_irq,
  165. irq_base, 0, &cp_intc_host_ops, NULL);
  166. if (!cp_intc_domain) {
  167. pr_err("cp_intc: failed to allocate irq host!\n");
  168. return -EINVAL;
  169. }
  170. /* Enable global interrupt */
  171. cp_intc_write(1, CP_INTC_GLOBAL_ENABLE);
  172. return 0;
  173. }
  174. void __init cp_intc_init(void)
  175. {
  176. __cp_intc_init(NULL);
  177. }