psc.c 3.8 KB

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