psc.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #include <asm/traps.h>
  21. #include <asm/bootinfo.h>
  22. #include <asm/macintosh.h>
  23. #include <asm/macints.h>
  24. #include <asm/mac_psc.h>
  25. #define DEBUG_PSC
  26. int psc_present;
  27. volatile __u8 *psc;
  28. irqreturn_t psc_irq(int, void *, struct pt_regs *);
  29. /*
  30. * Debugging dump, used in various places to see what's going on.
  31. */
  32. void psc_debug_dump(void)
  33. {
  34. int i;
  35. if (!psc_present) return;
  36. for (i = 0x30 ; i < 0x70 ; i += 0x10) {
  37. printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n",
  38. i >> 4,
  39. (int) psc_read_byte(pIFRbase + i),
  40. (int) psc_read_byte(pIERbase + i));
  41. }
  42. }
  43. /*
  44. * Try to kill all DMA channels on the PSC. Not sure how this his
  45. * supposed to work; this is code lifted from macmace.c and then
  46. * expanded to cover what I think are the other 7 channels.
  47. */
  48. void psc_dma_die_die_die(void)
  49. {
  50. int i;
  51. printk("Killing all PSC DMA channels...");
  52. for (i = 0 ; i < 9 ; i++) {
  53. psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800);
  54. psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000);
  55. psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100);
  56. psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100);
  57. }
  58. printk("done!\n");
  59. }
  60. /*
  61. * Initialize the PSC. For now this just involves shutting down all
  62. * interrupt sources using the IERs.
  63. */
  64. void __init psc_init(void)
  65. {
  66. int i;
  67. if (macintosh_config->ident != MAC_MODEL_C660
  68. && macintosh_config->ident != MAC_MODEL_Q840)
  69. {
  70. psc = NULL;
  71. psc_present = 0;
  72. return;
  73. }
  74. /*
  75. * The PSC is always at the same spot, but using psc
  76. * keeps things consisant with the psc_xxxx functions.
  77. */
  78. psc = (void *) PSC_BASE;
  79. psc_present = 1;
  80. printk("PSC detected at %p\n", psc);
  81. psc_dma_die_die_die();
  82. #ifdef DEBUG_PSC
  83. psc_debug_dump();
  84. #endif
  85. /*
  86. * Mask and clear all possible interrupts
  87. */
  88. for (i = 0x30 ; i < 0x70 ; i += 0x10) {
  89. psc_write_byte(pIERbase + i, 0x0F);
  90. psc_write_byte(pIFRbase + i, 0x0F);
  91. }
  92. }
  93. /*
  94. * Register the PSC interrupt dispatchers for autovector interrupts 3-6.
  95. */
  96. void __init psc_register_interrupts(void)
  97. {
  98. cpu_request_irq(3, psc_irq, IRQ_FLG_LOCK, "psc3", (void *) 0x30);
  99. cpu_request_irq(4, psc_irq, IRQ_FLG_LOCK, "psc4", (void *) 0x40);
  100. cpu_request_irq(5, psc_irq, IRQ_FLG_LOCK, "psc5", (void *) 0x50);
  101. cpu_request_irq(6, psc_irq, IRQ_FLG_LOCK, "psc6", (void *) 0x60);
  102. }
  103. /*
  104. * PSC interrupt handler. It's a lot like the VIA interrupt handler.
  105. */
  106. irqreturn_t psc_irq(int irq, void *dev_id, struct pt_regs *regs)
  107. {
  108. int pIFR = pIFRbase + ((int) dev_id);
  109. int pIER = pIERbase + ((int) dev_id);
  110. int base_irq;
  111. int irq_bit,i;
  112. unsigned char events;
  113. base_irq = irq << 3;
  114. #ifdef DEBUG_IRQS
  115. printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n",
  116. irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER));
  117. #endif
  118. events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF;
  119. if (!events)
  120. return IRQ_NONE;
  121. for (i = 0, irq_bit = 1 ; i < 4 ; i++, irq_bit <<= 1) {
  122. if (events & irq_bit) {
  123. psc_write_byte(pIER, irq_bit);
  124. mac_do_irq_list(base_irq + i, regs);
  125. psc_write_byte(pIFR, irq_bit);
  126. psc_write_byte(pIER, irq_bit | 0x80);
  127. }
  128. }
  129. return IRQ_HANDLED;
  130. }
  131. void psc_irq_enable(int irq) {
  132. int irq_src = IRQ_SRC(irq);
  133. int irq_idx = IRQ_IDX(irq);
  134. int pIER = pIERbase + (irq_src << 4);
  135. #ifdef DEBUG_IRQUSE
  136. printk("psc_irq_enable(%d)\n", irq);
  137. #endif
  138. psc_write_byte(pIER, (1 << irq_idx) | 0x80);
  139. }
  140. void psc_irq_disable(int irq) {
  141. int irq_src = IRQ_SRC(irq);
  142. int irq_idx = IRQ_IDX(irq);
  143. int pIER = pIERbase + (irq_src << 4);
  144. #ifdef DEBUG_IRQUSE
  145. printk("psc_irq_disable(%d)\n", irq);
  146. #endif
  147. psc_write_byte(pIER, 1 << irq_idx);
  148. }
  149. void psc_irq_clear(int irq) {
  150. int irq_src = IRQ_SRC(irq);
  151. int irq_idx = IRQ_IDX(irq);
  152. int pIFR = pIERbase + (irq_src << 4);
  153. psc_write_byte(pIFR, 1 << irq_idx);
  154. }
  155. int psc_irq_pending(int irq)
  156. {
  157. int irq_src = IRQ_SRC(irq);
  158. int irq_idx = IRQ_IDX(irq);
  159. int pIFR = pIERbase + (irq_src << 4);
  160. return psc_read_byte(pIFR) & (1 << irq_idx);
  161. }