11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Apple Peripheral System Controller (PSC) 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * The PSC is used on the AV Macs to control IO functions not handled 51da177e4SLinus Torvalds * by the VIAs (Ethernet, DSP, SCC). 61da177e4SLinus Torvalds * 71da177e4SLinus Torvalds * TO DO: 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * Try to figure out what's going on in pIFR5 and pIFR6. There seem to be 101da177e4SLinus Torvalds * persisant interrupt conditions in those registers and I have no idea what 111da177e4SLinus Torvalds * they are. Granted it doesn't affect since we're not enabling any interrupts 121da177e4SLinus Torvalds * on those levels at the moment, but it would be nice to know. I have a feeling 131da177e4SLinus Torvalds * they aren't actually interrupt lines but data lines (to the DSP?) 141da177e4SLinus Torvalds */ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #include <linux/types.h> 171da177e4SLinus Torvalds #include <linux/kernel.h> 181da177e4SLinus Torvalds #include <linux/mm.h> 191da177e4SLinus Torvalds #include <linux/delay.h> 201da177e4SLinus Torvalds #include <linux/init.h> 21ddc7fd25SGeert Uytterhoeven #ifdef CONFIG_GENERIC_HARDIRQS 22ddc7fd25SGeert Uytterhoeven #include <linux/irq.h> 23ddc7fd25SGeert Uytterhoeven #endif 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds #include <asm/traps.h> 261da177e4SLinus Torvalds #include <asm/bootinfo.h> 271da177e4SLinus Torvalds #include <asm/macintosh.h> 281da177e4SLinus Torvalds #include <asm/macints.h> 291da177e4SLinus Torvalds #include <asm/mac_psc.h> 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds #define DEBUG_PSC 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds int psc_present; 341da177e4SLinus Torvalds volatile __u8 *psc; 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds /* 371da177e4SLinus Torvalds * Debugging dump, used in various places to see what's going on. 381da177e4SLinus Torvalds */ 391da177e4SLinus Torvalds 408dfbdf4aSAdrian Bunk static void psc_debug_dump(void) 411da177e4SLinus Torvalds { 421da177e4SLinus Torvalds int i; 431da177e4SLinus Torvalds 441da177e4SLinus Torvalds if (!psc_present) return; 451da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 461da177e4SLinus Torvalds printk("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 598dfbdf4aSAdrian Bunk static void psc_dma_die_die_die(void) 601da177e4SLinus Torvalds { 611da177e4SLinus Torvalds int i; 621da177e4SLinus Torvalds 631da177e4SLinus Torvalds printk("Killing all PSC DMA channels..."); 641da177e4SLinus Torvalds for (i = 0 ; i < 9 ; i++) { 651da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800); 661da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000); 671da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100); 681da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100); 691da177e4SLinus Torvalds } 701da177e4SLinus Torvalds printk("done!\n"); 711da177e4SLinus Torvalds } 721da177e4SLinus Torvalds 731da177e4SLinus Torvalds /* 741da177e4SLinus Torvalds * Initialize the PSC. For now this just involves shutting down all 751da177e4SLinus Torvalds * interrupt sources using the IERs. 761da177e4SLinus Torvalds */ 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds void __init psc_init(void) 791da177e4SLinus Torvalds { 801da177e4SLinus Torvalds int i; 811da177e4SLinus Torvalds 821da177e4SLinus Torvalds if (macintosh_config->ident != MAC_MODEL_C660 831da177e4SLinus Torvalds && macintosh_config->ident != MAC_MODEL_Q840) 841da177e4SLinus Torvalds { 851da177e4SLinus Torvalds psc = NULL; 861da177e4SLinus Torvalds psc_present = 0; 871da177e4SLinus Torvalds return; 881da177e4SLinus Torvalds } 891da177e4SLinus Torvalds 901da177e4SLinus Torvalds /* 911da177e4SLinus Torvalds * The PSC is always at the same spot, but using psc 92a34f0b31SUwe Kleine-König * keeps things consistent with the psc_xxxx functions. 931da177e4SLinus Torvalds */ 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds psc = (void *) PSC_BASE; 961da177e4SLinus Torvalds psc_present = 1; 971da177e4SLinus Torvalds 981da177e4SLinus Torvalds printk("PSC detected at %p\n", psc); 991da177e4SLinus Torvalds 1001da177e4SLinus Torvalds psc_dma_die_die_die(); 1011da177e4SLinus Torvalds 1021da177e4SLinus Torvalds #ifdef DEBUG_PSC 1031da177e4SLinus Torvalds psc_debug_dump(); 1041da177e4SLinus Torvalds #endif 1051da177e4SLinus Torvalds /* 1061da177e4SLinus Torvalds * Mask and clear all possible interrupts 1071da177e4SLinus Torvalds */ 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 1101da177e4SLinus Torvalds psc_write_byte(pIERbase + i, 0x0F); 1111da177e4SLinus Torvalds psc_write_byte(pIFRbase + i, 0x0F); 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds } 1141da177e4SLinus Torvalds 1151da177e4SLinus Torvalds /* 1161da177e4SLinus Torvalds * PSC interrupt handler. It's a lot like the VIA interrupt handler. 1171da177e4SLinus Torvalds */ 1181da177e4SLinus Torvalds 119*9145db56SGeert Uytterhoeven #ifdef CONFIG_GENERIC_HARDIRQS 120*9145db56SGeert Uytterhoeven static void psc_irq(unsigned int irq, struct irq_desc *desc) 121*9145db56SGeert Uytterhoeven { 122*9145db56SGeert Uytterhoeven unsigned int offset = (unsigned int)irq_desc_get_handler_data(desc); 123*9145db56SGeert Uytterhoeven int pIFR = pIFRbase + offset; 124*9145db56SGeert Uytterhoeven int pIER = pIERbase + offset; 125*9145db56SGeert Uytterhoeven int irq_num; 126*9145db56SGeert Uytterhoeven unsigned char irq_bit, events; 127*9145db56SGeert Uytterhoeven 128*9145db56SGeert Uytterhoeven #ifdef DEBUG_IRQS 129*9145db56SGeert Uytterhoeven printk("psc_irq: irq %u pIFR = 0x%02X pIER = 0x%02X\n", 130*9145db56SGeert Uytterhoeven irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER)); 131*9145db56SGeert Uytterhoeven #endif 132*9145db56SGeert Uytterhoeven 133*9145db56SGeert Uytterhoeven events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF; 134*9145db56SGeert Uytterhoeven if (!events) 135*9145db56SGeert Uytterhoeven return; 136*9145db56SGeert Uytterhoeven 137*9145db56SGeert Uytterhoeven irq_num = irq << 3; 138*9145db56SGeert Uytterhoeven irq_bit = 1; 139*9145db56SGeert Uytterhoeven do { 140*9145db56SGeert Uytterhoeven if (events & irq_bit) { 141*9145db56SGeert Uytterhoeven psc_write_byte(pIFR, irq_bit); 142*9145db56SGeert Uytterhoeven generic_handle_irq(irq_num); 143*9145db56SGeert Uytterhoeven } 144*9145db56SGeert Uytterhoeven irq_num++; 145*9145db56SGeert Uytterhoeven irq_bit <<= 1; 146*9145db56SGeert Uytterhoeven } while (events >= irq_bit); 147*9145db56SGeert Uytterhoeven } 148*9145db56SGeert Uytterhoeven #else 149*9145db56SGeert Uytterhoeven static irqreturn_t psc_irq(int irq, void *dev_id) 1501da177e4SLinus Torvalds { 1511da177e4SLinus Torvalds int pIFR = pIFRbase + ((int) dev_id); 1521da177e4SLinus Torvalds int pIER = pIERbase + ((int) dev_id); 15367dfb153SFinn Thain int irq_num; 15467dfb153SFinn Thain unsigned char irq_bit, events; 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds #ifdef DEBUG_IRQS 1571da177e4SLinus Torvalds printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n", 1581da177e4SLinus Torvalds irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER)); 1591da177e4SLinus Torvalds #endif 1601da177e4SLinus Torvalds 1611da177e4SLinus Torvalds events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF; 1621da177e4SLinus Torvalds if (!events) 1631da177e4SLinus Torvalds return IRQ_NONE; 1641da177e4SLinus Torvalds 16567dfb153SFinn Thain irq_num = irq << 3; 16667dfb153SFinn Thain irq_bit = 1; 16767dfb153SFinn Thain do { 1681da177e4SLinus Torvalds if (events & irq_bit) { 1691da177e4SLinus Torvalds psc_write_byte(pIFR, irq_bit); 1701425df87SGeert Uytterhoeven generic_handle_irq(irq_num); 1711da177e4SLinus Torvalds } 17267dfb153SFinn Thain irq_num++; 17367dfb153SFinn Thain irq_bit <<= 1; 17467dfb153SFinn Thain } while (events >= irq_bit); 1751da177e4SLinus Torvalds return IRQ_HANDLED; 1761da177e4SLinus Torvalds } 177*9145db56SGeert Uytterhoeven #endif 178*9145db56SGeert Uytterhoeven 179*9145db56SGeert Uytterhoeven /* 180*9145db56SGeert Uytterhoeven * Register the PSC interrupt dispatchers for autovector interrupts 3-6. 181*9145db56SGeert Uytterhoeven */ 182*9145db56SGeert Uytterhoeven 183*9145db56SGeert Uytterhoeven void __init psc_register_interrupts(void) 184*9145db56SGeert Uytterhoeven { 185*9145db56SGeert Uytterhoeven #ifdef CONFIG_GENERIC_HARDIRQS 186*9145db56SGeert Uytterhoeven irq_set_chained_handler(IRQ_AUTO_3, psc_irq); 187*9145db56SGeert Uytterhoeven irq_set_handler_data(IRQ_AUTO_3, (void *)0x30); 188*9145db56SGeert Uytterhoeven irq_set_chained_handler(IRQ_AUTO_4, psc_irq); 189*9145db56SGeert Uytterhoeven irq_set_handler_data(IRQ_AUTO_4, (void *)0x40); 190*9145db56SGeert Uytterhoeven irq_set_chained_handler(IRQ_AUTO_5, psc_irq); 191*9145db56SGeert Uytterhoeven irq_set_handler_data(IRQ_AUTO_5, (void *)0x50); 192*9145db56SGeert Uytterhoeven irq_set_chained_handler(IRQ_AUTO_6, psc_irq); 193*9145db56SGeert Uytterhoeven irq_set_handler_data(IRQ_AUTO_6, (void *)0x60); 194*9145db56SGeert Uytterhoeven #else /* !CONFIG_GENERIC_HARDIRQS */ 195*9145db56SGeert Uytterhoeven if (request_irq(IRQ_AUTO_3, psc_irq, 0, "psc3", (void *) 0x30)) 196*9145db56SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 3); 197*9145db56SGeert Uytterhoeven if (request_irq(IRQ_AUTO_4, psc_irq, 0, "psc4", (void *) 0x40)) 198*9145db56SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 4); 199*9145db56SGeert Uytterhoeven if (request_irq(IRQ_AUTO_5, psc_irq, 0, "psc5", (void *) 0x50)) 200*9145db56SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 5); 201*9145db56SGeert Uytterhoeven if (request_irq(IRQ_AUTO_6, psc_irq, 0, "psc6", (void *) 0x60)) 202*9145db56SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 6); 203*9145db56SGeert Uytterhoeven #endif /* !CONFIG_GENERIC_HARDIRQS */ 204*9145db56SGeert Uytterhoeven } 2051da177e4SLinus Torvalds 2061da177e4SLinus Torvalds void psc_irq_enable(int irq) { 2071da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2081da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 2091da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE 2121da177e4SLinus Torvalds printk("psc_irq_enable(%d)\n", irq); 2131da177e4SLinus Torvalds #endif 2141da177e4SLinus Torvalds psc_write_byte(pIER, (1 << irq_idx) | 0x80); 2151da177e4SLinus Torvalds } 2161da177e4SLinus Torvalds 2171da177e4SLinus Torvalds void psc_irq_disable(int irq) { 2181da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2191da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 2201da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 2211da177e4SLinus Torvalds 2221da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE 2231da177e4SLinus Torvalds printk("psc_irq_disable(%d)\n", irq); 2241da177e4SLinus Torvalds #endif 2251da177e4SLinus Torvalds psc_write_byte(pIER, 1 << irq_idx); 2261da177e4SLinus Torvalds } 2271da177e4SLinus Torvalds 2281da177e4SLinus Torvalds void psc_irq_clear(int irq) { 2291da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2301da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 2311da177e4SLinus Torvalds int pIFR = pIERbase + (irq_src << 4); 2321da177e4SLinus Torvalds 2331da177e4SLinus Torvalds psc_write_byte(pIFR, 1 << irq_idx); 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 2361da177e4SLinus Torvalds int psc_irq_pending(int irq) 2371da177e4SLinus Torvalds { 2381da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2391da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 2401da177e4SLinus Torvalds int pIFR = pIERbase + (irq_src << 4); 2411da177e4SLinus Torvalds 2421da177e4SLinus Torvalds return psc_read_byte(pIFR) & (1 << irq_idx); 2431da177e4SLinus Torvalds } 244