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> 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include <asm/traps.h> 231da177e4SLinus Torvalds #include <asm/bootinfo.h> 241da177e4SLinus Torvalds #include <asm/macintosh.h> 251da177e4SLinus Torvalds #include <asm/macints.h> 261da177e4SLinus Torvalds #include <asm/mac_psc.h> 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds #define DEBUG_PSC 291da177e4SLinus Torvalds 301da177e4SLinus Torvalds int psc_present; 311da177e4SLinus Torvalds volatile __u8 *psc; 321da177e4SLinus Torvalds 332850bc27SAl Viro irqreturn_t psc_irq(int, void *); 341da177e4SLinus Torvalds 351da177e4SLinus Torvalds /* 361da177e4SLinus Torvalds * Debugging dump, used in various places to see what's going on. 371da177e4SLinus Torvalds */ 381da177e4SLinus Torvalds 398dfbdf4aSAdrian Bunk static void psc_debug_dump(void) 401da177e4SLinus Torvalds { 411da177e4SLinus Torvalds int i; 421da177e4SLinus Torvalds 431da177e4SLinus Torvalds if (!psc_present) return; 441da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 451da177e4SLinus Torvalds printk("PSC #%d: IFR = 0x%02X IER = 0x%02X\n", 461da177e4SLinus Torvalds i >> 4, 471da177e4SLinus Torvalds (int) psc_read_byte(pIFRbase + i), 481da177e4SLinus Torvalds (int) psc_read_byte(pIERbase + i)); 491da177e4SLinus Torvalds } 501da177e4SLinus Torvalds } 511da177e4SLinus Torvalds 521da177e4SLinus Torvalds /* 531da177e4SLinus Torvalds * Try to kill all DMA channels on the PSC. Not sure how this his 541da177e4SLinus Torvalds * supposed to work; this is code lifted from macmace.c and then 551da177e4SLinus Torvalds * expanded to cover what I think are the other 7 channels. 561da177e4SLinus Torvalds */ 571da177e4SLinus Torvalds 588dfbdf4aSAdrian Bunk static void psc_dma_die_die_die(void) 591da177e4SLinus Torvalds { 601da177e4SLinus Torvalds int i; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds printk("Killing all PSC DMA channels..."); 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 printk("done!\n"); 701da177e4SLinus Torvalds } 711da177e4SLinus Torvalds 721da177e4SLinus Torvalds /* 731da177e4SLinus Torvalds * Initialize the PSC. For now this just involves shutting down all 741da177e4SLinus Torvalds * interrupt sources using the IERs. 751da177e4SLinus Torvalds */ 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds void __init psc_init(void) 781da177e4SLinus Torvalds { 791da177e4SLinus Torvalds int i; 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds if (macintosh_config->ident != MAC_MODEL_C660 821da177e4SLinus Torvalds && macintosh_config->ident != MAC_MODEL_Q840) 831da177e4SLinus Torvalds { 841da177e4SLinus Torvalds psc = NULL; 851da177e4SLinus Torvalds psc_present = 0; 861da177e4SLinus Torvalds return; 871da177e4SLinus Torvalds } 881da177e4SLinus Torvalds 891da177e4SLinus Torvalds /* 901da177e4SLinus Torvalds * The PSC is always at the same spot, but using psc 91*a34f0b31SUwe Kleine-König * keeps things consistent with the psc_xxxx functions. 921da177e4SLinus Torvalds */ 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds psc = (void *) PSC_BASE; 951da177e4SLinus Torvalds psc_present = 1; 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds printk("PSC detected at %p\n", psc); 981da177e4SLinus Torvalds 991da177e4SLinus Torvalds psc_dma_die_die_die(); 1001da177e4SLinus Torvalds 1011da177e4SLinus Torvalds #ifdef DEBUG_PSC 1021da177e4SLinus Torvalds psc_debug_dump(); 1031da177e4SLinus Torvalds #endif 1041da177e4SLinus Torvalds /* 1051da177e4SLinus Torvalds * Mask and clear all possible interrupts 1061da177e4SLinus Torvalds */ 1071da177e4SLinus Torvalds 1081da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 1091da177e4SLinus Torvalds psc_write_byte(pIERbase + i, 0x0F); 1101da177e4SLinus Torvalds psc_write_byte(pIFRbase + i, 0x0F); 1111da177e4SLinus Torvalds } 1121da177e4SLinus Torvalds } 1131da177e4SLinus Torvalds 1141da177e4SLinus Torvalds /* 1151da177e4SLinus Torvalds * Register the PSC interrupt dispatchers for autovector interrupts 3-6. 1161da177e4SLinus Torvalds */ 1171da177e4SLinus Torvalds 1181da177e4SLinus Torvalds void __init psc_register_interrupts(void) 1191da177e4SLinus Torvalds { 12092c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_3, psc_irq, 0, "psc3", (void *) 0x30)) 12192c3dd15SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 3); 12292c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_4, psc_irq, 0, "psc4", (void *) 0x40)) 12392c3dd15SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 4); 12492c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_5, psc_irq, 0, "psc5", (void *) 0x50)) 12592c3dd15SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 5); 12692c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_6, psc_irq, 0, "psc6", (void *) 0x60)) 12792c3dd15SGeert Uytterhoeven pr_err("Couldn't register psc%d interrupt\n", 6); 1281da177e4SLinus Torvalds } 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* 1311da177e4SLinus Torvalds * PSC interrupt handler. It's a lot like the VIA interrupt handler. 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds 1342850bc27SAl Viro irqreturn_t psc_irq(int irq, void *dev_id) 1351da177e4SLinus Torvalds { 1361da177e4SLinus Torvalds int pIFR = pIFRbase + ((int) dev_id); 1371da177e4SLinus Torvalds int pIER = pIERbase + ((int) dev_id); 13867dfb153SFinn Thain int irq_num; 13967dfb153SFinn Thain unsigned char irq_bit, events; 1401da177e4SLinus Torvalds 1411da177e4SLinus Torvalds #ifdef DEBUG_IRQS 1421da177e4SLinus Torvalds printk("psc_irq: irq %d pIFR = 0x%02X pIER = 0x%02X\n", 1431da177e4SLinus Torvalds irq, (int) psc_read_byte(pIFR), (int) psc_read_byte(pIER)); 1441da177e4SLinus Torvalds #endif 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF; 1471da177e4SLinus Torvalds if (!events) 1481da177e4SLinus Torvalds return IRQ_NONE; 1491da177e4SLinus Torvalds 15067dfb153SFinn Thain irq_num = irq << 3; 15167dfb153SFinn Thain irq_bit = 1; 15267dfb153SFinn Thain do { 1531da177e4SLinus Torvalds if (events & irq_bit) { 1541da177e4SLinus Torvalds psc_write_byte(pIFR, irq_bit); 15567dfb153SFinn Thain m68k_handle_int(irq_num); 1561da177e4SLinus Torvalds } 15767dfb153SFinn Thain irq_num++; 15867dfb153SFinn Thain irq_bit <<= 1; 15967dfb153SFinn Thain } while (events >= irq_bit); 1601da177e4SLinus Torvalds return IRQ_HANDLED; 1611da177e4SLinus Torvalds } 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds void psc_irq_enable(int irq) { 1641da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1651da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1661da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE 1691da177e4SLinus Torvalds printk("psc_irq_enable(%d)\n", irq); 1701da177e4SLinus Torvalds #endif 1711da177e4SLinus Torvalds psc_write_byte(pIER, (1 << irq_idx) | 0x80); 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds void psc_irq_disable(int irq) { 1751da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1761da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1771da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1781da177e4SLinus Torvalds 1791da177e4SLinus Torvalds #ifdef DEBUG_IRQUSE 1801da177e4SLinus Torvalds printk("psc_irq_disable(%d)\n", irq); 1811da177e4SLinus Torvalds #endif 1821da177e4SLinus Torvalds psc_write_byte(pIER, 1 << irq_idx); 1831da177e4SLinus Torvalds } 1841da177e4SLinus Torvalds 1851da177e4SLinus Torvalds void psc_irq_clear(int irq) { 1861da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1871da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1881da177e4SLinus Torvalds int pIFR = pIERbase + (irq_src << 4); 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds psc_write_byte(pIFR, 1 << irq_idx); 1911da177e4SLinus Torvalds } 1921da177e4SLinus Torvalds 1931da177e4SLinus Torvalds int psc_irq_pending(int irq) 1941da177e4SLinus Torvalds { 1951da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1961da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1971da177e4SLinus Torvalds int pIFR = pIERbase + (irq_src << 4); 1981da177e4SLinus Torvalds 1991da177e4SLinus Torvalds return psc_read_byte(pIFR) & (1 << irq_idx); 2001da177e4SLinus Torvalds } 201