psc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Apple Peripheral System Controller (PSC)
  3. *
  4. * The PSC is used on the AV Macs to control IO functions not handled
  5. * by the VIAs (Ethernet, DSP, SCC).
  6. *
  7. * TO DO:
  8. *
  9. * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be
  10. * persisant interrupt conditions in those registers and I have no idea what
  11. * they are. Granted it doesn't affect since we're not enabling any interrupts
  12. * on those levels at the moment, but it would be nice to know. I have a feeling
  13. * they aren't actually interrupt lines but data lines (to the DSP?)
  14. */
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #ifdef CONFIG_GENERIC_HARDIRQS
  21. #include <linux/irq.h>
  22. #endif
  23. #include <asm/traps.h>
  24. #include <asm/bootinfo.h>
  25. #include <asm/macintosh.h>
  26. #include <asm/macints.h>
  27. #include <asm/mac_psc.h>
  28. #define DEBUG_PSC
  29. int psc_present;
  30. volatile __u8 *psc;
  31. irqreturn_t psc_irq(int, void *);
  32. /*
  33. * Debugging dump, used in various places to see what's going on.
  34. */
  35. static void psc_debug_dump(void)
  36. {
  37. int i;
  38. if (!psc_present) return;
  39. for (i = 0x30 ; i < 0x70 ; i += 0x10) {
  40. printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n",
  41. i >> 4,
  42. (int) psc_read_byte(pIFRbase + i),
  43. (int) psc_read_byte(pIERbase + i));
  44. }
  45. }
  46. /*
  47. * Try to kill all DMA channels on the PSC. Not sure how this his
  48. * supposed to work; this is code lifted from macmace.c and then
  49. * expanded to cover what I think are the other 7 channels.
  50. */
  51. static void psc_dma_die_die_die(void)
  52. {
  53. int i;
  54. printk("Killing all PSC DMA channels...");
  55. for (i = 0 ; i < 9 ; i++) {
  56. psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
  57. psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
  58. psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
  59. psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
  60. }
  61. printk("done!\n");
  62. }
  63. /*
  64. * Initialize the PSC. For now this just involves shutting down all
  65. * interrupt sources using the IERs.
  66. */
  67. void __init psc_init(void)
  68. {
  69. int i;
  70. if (macintosh_config->ident != MAC_MODEL_C660
  71. && macintosh_config->ident != MAC_MODEL_Q840)
  72. {
  73. psc = NULL;
  74. psc_present = 0;
  75. return;
  76. }
  77. /*
  78. * The PSC is always at the same spot, but using psc
  79. * keeps things consistent with the psc_xxxx functions.
  80. */
  81. psc = (void *) PSC_BASE;
  82. psc_present = 1;
  83. printk("PSC detected at %p\n", psc);
  84. psc_dma_die_die_die();
  85. #ifdef DEBUG_PSC
  86. psc_debug_dump();
  87. #endif
  88. /*
  89. * Mask and clear all possible interrupts
  90. */
  91. for (i = 0x30 ; i < 0x70 ; i += 0x10) {
  92. psc_write_byte(pIERbase + i, 0x0F);
  93. psc_write_byte(pIFRbase + i, 0x0F);
  94. }
  95. }
  96. /*
  97. * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
  98. */
  99. void __init psc_register_interrupts(void)
  100. {
  101. if (request_irq(IRQ_AUTO_3, psc_irq, 0, "psc3", (void *) 0x30))
  102. pr_err("Couldn't register psc%d interrupt\n", 3);
  103. if (request_irq(IRQ_AUTO_4, psc_irq, 0, "psc4", (void *) 0x40))
  104. pr_err("Couldn't register psc%d interrupt\n", 4);
  105. if (request_irq(IRQ_AUTO_5, psc_irq, 0, "psc5", (void *) 0x50))
  106. pr_err("Couldn't register psc%d interrupt\n", 5);
  107. if (request_irq(IRQ_AUTO_6, psc_irq, 0, "psc6", (void *) 0x60))
  108. pr_err("Couldn't register psc%d interrupt\n", 6);
  109. }
  110. /*
  111. * PSC interrupt handler. It's a lot like the VIA interrupt handler.
  112. */
  113. irqreturn_t psc_irq(int irq, void *dev_id)
  114. {
  115. int pIFR = pIFRbase + ((int) dev_id);
  116. int pIER = pIERbase + ((int) dev_id);
  117. int irq_num;
  118. unsigned char irq_bit, events;
  119. #ifdef DEBUG_IRQS
  120. printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
  121. irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER));
  122. #endif
  123. events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
  124. if (!events)
  125. return IRQ_NONE;
  126. irq_num = irq << 3;
  127. irq_bit = 1;
  128. do {
  129. if (events & irq_bit) {
  130. psc_write_byte(pIFR, irq_bit);
  131. generic_handle_irq(irq_num);
  132. }
  133. irq_num++;
  134. irq_bit <<= 1;
  135. } while (events >= irq_bit);
  136. return IRQ_HANDLED;
  137. }
  138. void psc_irq_enable(int irq) {
  139. int irq_src = IRQ_SRC(irq);
  140. int irq_idx = IRQ_IDX(irq);
  141. int pIER = pIERbase + (irq_src << 4);
  142. #ifdef DEBUG_IRQUSE
  143. printk("psc_irq_enable(%d)\n", irq);
  144. #endif
  145. psc_write_byte(pIER, (1 << irq_idx) | 0x80);
  146. }
  147. void psc_irq_disable(int irq) {
  148. int irq_src = IRQ_SRC(irq);
  149. int irq_idx = IRQ_IDX(irq);
  150. int pIER = pIERbase + (irq_src << 4);
  151. #ifdef DEBUG_IRQUSE
  152. printk("psc_irq_disable(%d)\n", irq);
  153. #endif
  154. psc_write_byte(pIER, 1 << irq_idx);
  155. }
  156. void psc_irq_clear(int irq) {
  157. int irq_src = IRQ_SRC(irq);
  158. int irq_idx = IRQ_IDX(irq);
  159. int pIFR = pIERbase + (irq_src << 4);
  160. psc_write_byte(pIFR, 1 << irq_idx);
  161. }
  162. int psc_irq_pending(int irq)
  163. {
  164. int irq_src = IRQ_SRC(irq);
  165. int irq_idx = IRQ_IDX(irq);
  166. int pIFR = pIERbase + (irq_src << 4);
  167. return psc_read_byte(pIFR) & (1 << irq_idx);
  168. }