cia.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * linux/arch/m68k/amiga/cia.c - CIA support
  3. *
  4. * Copyright (C) 1996 Roman Zippel
  5. *
  6. * The concept of some functions bases on the original Amiga OS function
  7. *
  8. * This file is subject to the terms and conditions of the GNU General Public
  9. * License. See the file COPYING in the main directory of this archive
  10. * for more details.
  11. */
  12. #include <linux/types.h>
  13. #include <linux/kernel.h>
  14. #include <linux/sched.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/init.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/interrupt.h>
  20. #include <asm/irq.h>
  21. #include <asm/amigahw.h>
  22. #include <asm/amigaints.h>
  23. struct ciabase {
  24. volatile struct CIA *cia;
  25. unsigned char icr_mask, icr_data;
  26. unsigned short int_mask;
  27. int handler_irq, cia_irq, server_irq;
  28. char *name;
  29. } ciaa_base = {
  30. .cia = &ciaa,
  31. .int_mask = IF_PORTS,
  32. .handler_irq = IRQ_AMIGA_PORTS,
  33. .cia_irq = IRQ_AMIGA_CIAA,
  34. .name = "CIAA"
  35. }, ciab_base = {
  36. .cia = &ciab,
  37. .int_mask = IF_EXTER,
  38. .handler_irq = IRQ_AMIGA_EXTER,
  39. .cia_irq = IRQ_AMIGA_CIAB,
  40. .name = "CIAB"
  41. };
  42. /*
  43. * Cause or clear CIA interrupts, return old interrupt status.
  44. */
  45. unsigned char cia_set_irq(struct ciabase *base, unsigned char mask)
  46. {
  47. unsigned char old;
  48. old = (base->icr_data |= base->cia->icr);
  49. if (mask & CIA_ICR_SETCLR)
  50. base->icr_data |= mask;
  51. else
  52. base->icr_data &= ~mask;
  53. if (base->icr_data & base->icr_mask)
  54. amiga_custom.intreq = IF_SETCLR | base->int_mask;
  55. return old & base->icr_mask;
  56. }
  57. /*
  58. * Enable or disable CIA interrupts, return old interrupt mask,
  59. */
  60. unsigned char cia_able_irq(struct ciabase *base, unsigned char mask)
  61. {
  62. unsigned char old;
  63. old = base->icr_mask;
  64. base->icr_data |= base->cia->icr;
  65. base->cia->icr = mask;
  66. if (mask & CIA_ICR_SETCLR)
  67. base->icr_mask |= mask;
  68. else
  69. base->icr_mask &= ~mask;
  70. base->icr_mask &= CIA_ICR_ALL;
  71. if (base->icr_data & base->icr_mask)
  72. amiga_custom.intreq = IF_SETCLR | base->int_mask;
  73. return old;
  74. }
  75. static irqreturn_t cia_handler(int irq, void *dev_id)
  76. {
  77. struct ciabase *base = dev_id;
  78. int mach_irq;
  79. unsigned char ints;
  80. mach_irq = base->cia_irq;
  81. ints = cia_set_irq(base, CIA_ICR_ALL);
  82. amiga_custom.intreq = base->int_mask;
  83. for (; ints; mach_irq++, ints >>= 1) {
  84. if (ints & 1)
  85. generic_handle_irq(mach_irq);
  86. }
  87. return IRQ_HANDLED;
  88. }
  89. static void cia_irq_enable(struct irq_data *data)
  90. {
  91. unsigned int irq = data->irq;
  92. unsigned char mask;
  93. if (irq >= IRQ_AMIGA_CIAB) {
  94. mask = 1 << (irq - IRQ_AMIGA_CIAB);
  95. cia_set_irq(&ciab_base, mask);
  96. cia_able_irq(&ciab_base, CIA_ICR_SETCLR | mask);
  97. } else {
  98. mask = 1 << (irq - IRQ_AMIGA_CIAA);
  99. cia_set_irq(&ciaa_base, mask);
  100. cia_able_irq(&ciaa_base, CIA_ICR_SETCLR | mask);
  101. }
  102. }
  103. static void cia_irq_disable(struct irq_data *data)
  104. {
  105. unsigned int irq = data->irq;
  106. if (irq >= IRQ_AMIGA_CIAB)
  107. cia_able_irq(&ciab_base, 1 << (irq - IRQ_AMIGA_CIAB));
  108. else
  109. cia_able_irq(&ciaa_base, 1 << (irq - IRQ_AMIGA_CIAA));
  110. }
  111. static struct irq_chip cia_irq_chip = {
  112. .name = "cia",
  113. .irq_enable = cia_irq_enable,
  114. .irq_disable = cia_irq_disable,
  115. };
  116. /*
  117. * Override auto irq 2 & 6 and use them as general chain
  118. * for external interrupts, we link the CIA interrupt sources
  119. * into this chain.
  120. */
  121. static void auto_irq_enable(struct irq_data *data)
  122. {
  123. switch (data->irq) {
  124. case IRQ_AUTO_2:
  125. amiga_custom.intena = IF_SETCLR | IF_PORTS;
  126. break;
  127. case IRQ_AUTO_6:
  128. amiga_custom.intena = IF_SETCLR | IF_EXTER;
  129. break;
  130. }
  131. }
  132. static void auto_irq_disable(struct irq_data *data)
  133. {
  134. switch (data->irq) {
  135. case IRQ_AUTO_2:
  136. amiga_custom.intena = IF_PORTS;
  137. break;
  138. case IRQ_AUTO_6:
  139. amiga_custom.intena = IF_EXTER;
  140. break;
  141. }
  142. }
  143. static struct irq_chip auto_irq_chip = {
  144. .name = "auto",
  145. .irq_enable = auto_irq_enable,
  146. .irq_disable = auto_irq_disable,
  147. };
  148. void __init cia_init_IRQ(struct ciabase *base)
  149. {
  150. m68k_setup_irq_controller(&cia_irq_chip, handle_simple_irq,
  151. base->cia_irq, CIA_IRQS);
  152. /* clear any pending interrupt and turn off all interrupts */
  153. cia_set_irq(base, CIA_ICR_ALL);
  154. cia_able_irq(base, CIA_ICR_ALL);
  155. /* override auto int and install CIA handler */
  156. m68k_setup_irq_controller(&auto_irq_chip, handle_simple_irq,
  157. base->handler_irq, 1);
  158. m68k_irq_startup_irq(base->handler_irq);
  159. if (request_irq(base->handler_irq, cia_handler, IRQF_SHARED,
  160. base->name, base))
  161. pr_err("Couldn't register %s interrupt\n", base->name);
  162. }