1*457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Apple Peripheral System Controller (PSC) 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * The PSC is used on the AV Macs to control IO functions not handled 61da177e4SLinus Torvalds * by the VIAs (Ethernet, DSP, SCC). 71da177e4SLinus Torvalds * 81da177e4SLinus Torvalds * TO DO: 91da177e4SLinus Torvalds * 101da177e4SLinus Torvalds * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be 111da177e4SLinus Torvalds * persisant interrupt conditions in those registers and I have no idea what 121da177e4SLinus Torvalds * they are. Granted it doesn't affect since we're not enabling any interrupts 131da177e4SLinus Torvalds * on those levels at the moment, but it would be nice to know. I have a feeling 141da177e4SLinus Torvalds * they aren't actually interrupt lines but data lines (to the DSP?) 151da177e4SLinus Torvalds */ 161da177e4SLinus Torvalds 171da177e4SLinus Torvalds #include <linux/types.h> 181da177e4SLinus Torvalds #include <linux/kernel.h> 191da177e4SLinus Torvalds #include <linux/mm.h> 201da177e4SLinus Torvalds #include <linux/delay.h> 211da177e4SLinus Torvalds #include <linux/init.h> 22ddc7fd25SGeert Uytterhoeven #include <linux/irq.h> 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds #include <asm/traps.h> 251da177e4SLinus Torvalds #include <asm/macintosh.h> 261da177e4SLinus Torvalds #include <asm/macints.h> 271da177e4SLinus Torvalds #include <asm/mac_psc.h> 281da177e4SLinus Torvalds 291da177e4SLinus Torvalds #define DEBUG_PSC 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds volatile __u8 *psc; 32a77cdaafSGeert Uytterhoeven EXPORT_SYMBOL_GPL(psc); 331da177e4SLinus Torvalds 341da177e4SLinus Torvalds /* 351da177e4SLinus Torvalds * Debugging dump, used in various places to see what's going on. 361da177e4SLinus Torvalds */ 371da177e4SLinus Torvalds 388dfbdf4aSAdrian Bunk static void psc_debug_dump(void) 391da177e4SLinus Torvalds { 401da177e4SLinus Torvalds int i; 411da177e4SLinus Torvalds 4270bc53b4SGeert Uytterhoeven if (!psc) 4370bc53b4SGeert Uytterhoeven return; 4470bc53b4SGeert Uytterhoeven 451da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 460e37a23eSFinn Thain printk(KERN_DEBUG "PSC #%d: IFR = 0x%02X IER = 0x%02X\n", 471da177e4SLinus Torvalds i >> 4, 481da177e4SLinus Torvalds (int) psc_read_byte(pIFRbase + i), 491da177e4SLinus Torvalds (int) psc_read_byte(pIERbase + i)); 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds } 521da177e4SLinus Torvalds 531da177e4SLinus Torvalds /* 541da177e4SLinus Torvalds * Try to kill all DMA channels on the PSC. Not sure how this his 551da177e4SLinus Torvalds * supposed to work; this is code lifted from macmace.c and then 561da177e4SLinus Torvalds * expanded to cover what I think are the other 7 channels. 571da177e4SLinus Torvalds */ 581da177e4SLinus Torvalds 59a4df02a2SGeert Uytterhoeven static __init void psc_dma_die_die_die(void) 601da177e4SLinus Torvalds { 611da177e4SLinus Torvalds int i; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds for (i = 0 ; i < 9 ; i++) { 641da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800); 651da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000); 661da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100); 671da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100); 681da177e4SLinus Torvalds } 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds 711da177e4SLinus Torvalds /* 721da177e4SLinus Torvalds * Initialize the PSC. For now this just involves shutting down all 731da177e4SLinus Torvalds * interrupt sources using the IERs. 741da177e4SLinus Torvalds */ 751da177e4SLinus Torvalds 761da177e4SLinus Torvalds void __init psc_init(void) 771da177e4SLinus Torvalds { 781da177e4SLinus Torvalds int i; 791da177e4SLinus Torvalds 801da177e4SLinus Torvalds if (macintosh_config->ident != MAC_MODEL_C660 811da177e4SLinus Torvalds && macintosh_config->ident != MAC_MODEL_Q840) 821da177e4SLinus Torvalds { 831da177e4SLinus Torvalds psc = NULL; 841da177e4SLinus Torvalds return; 851da177e4SLinus Torvalds } 861da177e4SLinus Torvalds 871da177e4SLinus Torvalds /* 881da177e4SLinus Torvalds * The PSC is always at the same spot, but using psc 89a34f0b31SUwe Kleine-König * keeps things consistent with the psc_xxxx functions. 901da177e4SLinus Torvalds */ 911da177e4SLinus Torvalds 921da177e4SLinus Torvalds psc = (void *) PSC_BASE; 931da177e4SLinus Torvalds 940e37a23eSFinn Thain pr_debug("PSC detected at %p\n", psc); 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds psc_dma_die_die_die(); 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds #ifdef DEBUG_PSC 991da177e4SLinus Torvalds psc_debug_dump(); 1001da177e4SLinus Torvalds #endif 1011da177e4SLinus Torvalds /* 1021da177e4SLinus Torvalds * Mask and clear all possible interrupts 1031da177e4SLinus Torvalds */ 1041da177e4SLinus Torvalds 1051da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 1061da177e4SLinus Torvalds psc_write_byte(pIERbase + i, 0x0F); 1071da177e4SLinus Torvalds psc_write_byte(pIFRbase + i, 0x0F); 1081da177e4SLinus Torvalds } 1091da177e4SLinus Torvalds } 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds /* 1121da177e4SLinus Torvalds * PSC interrupt handler. It's a lot like the VIA interrupt handler. 1131da177e4SLinus Torvalds */ 1141da177e4SLinus Torvalds 115bd0b9ac4SThomas Gleixner static void psc_irq(struct irq_desc *desc) 1169145db56SGeert Uytterhoeven { 1179145db56SGeert Uytterhoeven unsigned int offset = (unsigned int)irq_desc_get_handler_data(desc); 118625b86adSThomas Gleixner unsigned int irq = irq_desc_get_irq(desc); 1199145db56SGeert Uytterhoeven int pIFR = pIFRbase + offset; 1209145db56SGeert Uytterhoeven int pIER = pIERbase + offset; 1219145db56SGeert Uytterhoeven int irq_num; 1229145db56SGeert Uytterhoeven unsigned char irq_bit, events; 1239145db56SGeert Uytterhoeven 1249145db56SGeert Uytterhoeven events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF; 1259145db56SGeert Uytterhoeven if (!events) 1269145db56SGeert Uytterhoeven return; 1279145db56SGeert Uytterhoeven 1289145db56SGeert Uytterhoeven irq_num = irq << 3; 1299145db56SGeert Uytterhoeven irq_bit = 1; 1309145db56SGeert Uytterhoeven do { 1319145db56SGeert Uytterhoeven if (events & irq_bit) { 1329145db56SGeert Uytterhoeven psc_write_byte(pIFR, irq_bit); 1339145db56SGeert Uytterhoeven generic_handle_irq(irq_num); 1349145db56SGeert Uytterhoeven } 1359145db56SGeert Uytterhoeven irq_num++; 1369145db56SGeert Uytterhoeven irq_bit <<= 1; 1379145db56SGeert Uytterhoeven } while (events >= irq_bit); 1389145db56SGeert Uytterhoeven } 1399145db56SGeert Uytterhoeven 1409145db56SGeert Uytterhoeven /* 1419145db56SGeert Uytterhoeven * Register the PSC interrupt dispatchers for autovector interrupts 3-6. 1429145db56SGeert Uytterhoeven */ 1439145db56SGeert Uytterhoeven 1449145db56SGeert Uytterhoeven void __init psc_register_interrupts(void) 1459145db56SGeert Uytterhoeven { 14609c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_3, psc_irq, (void *)0x30); 14709c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_4, psc_irq, (void *)0x40); 14809c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_5, psc_irq, (void *)0x50); 14909c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_6, psc_irq, (void *)0x60); 1509145db56SGeert Uytterhoeven } 1511da177e4SLinus Torvalds 1521da177e4SLinus Torvalds void psc_irq_enable(int irq) { 1531da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1541da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1551da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds psc_write_byte(pIER, (1 << irq_idx) | 0x80); 1581da177e4SLinus Torvalds } 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds void psc_irq_disable(int irq) { 1611da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1621da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1631da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1641da177e4SLinus Torvalds 1651da177e4SLinus Torvalds psc_write_byte(pIER, 1 << irq_idx); 1661da177e4SLinus Torvalds } 167