cp_intc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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/init.h>
  12. #include <linux/irq.h>
  13. #include <linux/io.h>
  14. #include <mach/common.h>
  15. #include <mach/cp_intc.h>
  16. static inline unsigned int cp_intc_read(unsigned offset)
  17. {
  18. return __raw_readl(davinci_intc_base + offset);
  19. }
  20. static inline void cp_intc_write(unsigned long value, unsigned offset)
  21. {
  22. __raw_writel(value, davinci_intc_base + offset);
  23. }
  24. static void cp_intc_ack_irq(struct irq_data *d)
  25. {
  26. cp_intc_write(d->irq, CP_INTC_SYS_STAT_IDX_CLR);
  27. }
  28. /* Disable interrupt */
  29. static void cp_intc_mask_irq(struct irq_data *d)
  30. {
  31. /* XXX don't know why we need to disable nIRQ here... */
  32. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_CLR);
  33. cp_intc_write(d->irq, CP_INTC_SYS_ENABLE_IDX_CLR);
  34. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET);
  35. }
  36. /* Enable interrupt */
  37. static void cp_intc_unmask_irq(struct irq_data *d)
  38. {
  39. cp_intc_write(d->irq, CP_INTC_SYS_ENABLE_IDX_SET);
  40. }
  41. static int cp_intc_set_irq_type(struct irq_data *d, unsigned int flow_type)
  42. {
  43. unsigned reg = BIT_WORD(d->irq);
  44. unsigned mask = BIT_MASK(d->irq);
  45. unsigned polarity = cp_intc_read(CP_INTC_SYS_POLARITY(reg));
  46. unsigned type = cp_intc_read(CP_INTC_SYS_TYPE(reg));
  47. switch (flow_type) {
  48. case IRQ_TYPE_EDGE_RISING:
  49. polarity |= mask;
  50. type |= mask;
  51. break;
  52. case IRQ_TYPE_EDGE_FALLING:
  53. polarity &= ~mask;
  54. type |= mask;
  55. break;
  56. case IRQ_TYPE_LEVEL_HIGH:
  57. polarity |= mask;
  58. type &= ~mask;
  59. break;
  60. case IRQ_TYPE_LEVEL_LOW:
  61. polarity &= ~mask;
  62. type &= ~mask;
  63. break;
  64. default:
  65. return -EINVAL;
  66. }
  67. cp_intc_write(polarity, CP_INTC_SYS_POLARITY(reg));
  68. cp_intc_write(type, CP_INTC_SYS_TYPE(reg));
  69. return 0;
  70. }
  71. /*
  72. * Faking this allows us to to work with suspend functions of
  73. * generic drivers which call {enable|disable}_irq_wake for
  74. * wake up interrupt sources (eg RTC on DA850).
  75. */
  76. static int cp_intc_set_wake(struct irq_data *d, unsigned int on)
  77. {
  78. return 0;
  79. }
  80. static struct irq_chip cp_intc_irq_chip = {
  81. .name = "cp_intc",
  82. .irq_ack = cp_intc_ack_irq,
  83. .irq_mask = cp_intc_mask_irq,
  84. .irq_unmask = cp_intc_unmask_irq,
  85. .irq_set_type = cp_intc_set_irq_type,
  86. .irq_set_wake = cp_intc_set_wake,
  87. };
  88. void __init cp_intc_init(void)
  89. {
  90. unsigned long num_irq = davinci_soc_info.intc_irq_num;
  91. u8 *irq_prio = davinci_soc_info.intc_irq_prios;
  92. u32 *host_map = davinci_soc_info.intc_host_map;
  93. unsigned num_reg = BITS_TO_LONGS(num_irq);
  94. int i;
  95. davinci_intc_type = DAVINCI_INTC_TYPE_CP_INTC;
  96. davinci_intc_base = ioremap(davinci_soc_info.intc_base, SZ_8K);
  97. if (WARN_ON(!davinci_intc_base))
  98. return;
  99. cp_intc_write(0, CP_INTC_GLOBAL_ENABLE);
  100. /* Disable all host interrupts */
  101. cp_intc_write(0, CP_INTC_HOST_ENABLE(0));
  102. /* Disable system interrupts */
  103. for (i = 0; i < num_reg; i++)
  104. cp_intc_write(~0, CP_INTC_SYS_ENABLE_CLR(i));
  105. /* Set to normal mode, no nesting, no priority hold */
  106. cp_intc_write(0, CP_INTC_CTRL);
  107. cp_intc_write(0, CP_INTC_HOST_CTRL);
  108. /* Clear system interrupt status */
  109. for (i = 0; i < num_reg; i++)
  110. cp_intc_write(~0, CP_INTC_SYS_STAT_CLR(i));
  111. /* Enable nIRQ (what about nFIQ?) */
  112. cp_intc_write(1, CP_INTC_HOST_ENABLE_IDX_SET);
  113. /*
  114. * Priority is determined by host channel: lower channel number has
  115. * higher priority i.e. channel 0 has highest priority and channel 31
  116. * had the lowest priority.
  117. */
  118. num_reg = (num_irq + 3) >> 2; /* 4 channels per register */
  119. if (irq_prio) {
  120. unsigned j, k;
  121. u32 val;
  122. for (k = i = 0; i < num_reg; i++) {
  123. for (val = j = 0; j < 4; j++, k++) {
  124. val >>= 8;
  125. if (k < num_irq)
  126. val |= irq_prio[k] << 24;
  127. }
  128. cp_intc_write(val, CP_INTC_CHAN_MAP(i));
  129. }
  130. } else {
  131. /*
  132. * Default everything to channel 15 if priority not specified.
  133. * Note that channel 0-1 are mapped to nFIQ and channels 2-31
  134. * are mapped to nIRQ.
  135. */
  136. for (i = 0; i < num_reg; i++)
  137. cp_intc_write(0x0f0f0f0f, CP_INTC_CHAN_MAP(i));
  138. }
  139. if (host_map)
  140. for (i = 0; host_map[i] != -1; i++)
  141. cp_intc_write(host_map[i], CP_INTC_HOST_MAP(i));
  142. /* Set up genirq dispatching for cp_intc */
  143. for (i = 0; i < num_irq; i++) {
  144. irq_set_chip(i, &cp_intc_irq_chip);
  145. set_irq_flags(i, IRQF_VALID | IRQF_PROBE);
  146. irq_set_handler(i, handle_edge_irq);
  147. }
  148. /* Enable global interrupt */
  149. cp_intc_write(1, CP_INTC_GLOBAL_ENABLE);
  150. }