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 #include <linux/irq.h> 221da177e4SLinus Torvalds 231da177e4SLinus Torvalds #include <asm/traps.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 volatile __u8 *psc; 31a77cdaafSGeert Uytterhoeven EXPORT_SYMBOL_GPL(psc); 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds /* 341da177e4SLinus Torvalds * Debugging dump, used in various places to see what's going on. 351da177e4SLinus Torvalds */ 361da177e4SLinus Torvalds 378dfbdf4aSAdrian Bunk static void psc_debug_dump(void) 381da177e4SLinus Torvalds { 391da177e4SLinus Torvalds int i; 401da177e4SLinus Torvalds 4170bc53b4SGeert Uytterhoeven if (!psc) 4270bc53b4SGeert Uytterhoeven return; 4370bc53b4SGeert Uytterhoeven 441da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 45*0e37a23eSFinn Thain printk(KERN_DEBUG "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 58a4df02a2SGeert Uytterhoeven static __init void psc_dma_die_die_die(void) 591da177e4SLinus Torvalds { 601da177e4SLinus Torvalds int i; 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds for (i = 0 ; i < 9 ; i++) { 631da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x8800); 641da177e4SLinus Torvalds psc_write_word(PSC_CTL_BASE + (i << 4), 0x1000); 651da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5), 0x1100); 661da177e4SLinus Torvalds psc_write_word(PSC_CMD_BASE + (i << 5) + 0x10, 0x1100); 671da177e4SLinus Torvalds } 681da177e4SLinus Torvalds } 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds /* 711da177e4SLinus Torvalds * Initialize the PSC. For now this just involves shutting down all 721da177e4SLinus Torvalds * interrupt sources using the IERs. 731da177e4SLinus Torvalds */ 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds void __init psc_init(void) 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds int i; 781da177e4SLinus Torvalds 791da177e4SLinus Torvalds if (macintosh_config->ident != MAC_MODEL_C660 801da177e4SLinus Torvalds && macintosh_config->ident != MAC_MODEL_Q840) 811da177e4SLinus Torvalds { 821da177e4SLinus Torvalds psc = NULL; 831da177e4SLinus Torvalds return; 841da177e4SLinus Torvalds } 851da177e4SLinus Torvalds 861da177e4SLinus Torvalds /* 871da177e4SLinus Torvalds * The PSC is always at the same spot, but using psc 88a34f0b31SUwe Kleine-König * keeps things consistent with the psc_xxxx functions. 891da177e4SLinus Torvalds */ 901da177e4SLinus Torvalds 911da177e4SLinus Torvalds psc = (void *) PSC_BASE; 921da177e4SLinus Torvalds 93*0e37a23eSFinn Thain pr_debug("PSC detected at %p\n", psc); 941da177e4SLinus Torvalds 951da177e4SLinus Torvalds psc_dma_die_die_die(); 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds #ifdef DEBUG_PSC 981da177e4SLinus Torvalds psc_debug_dump(); 991da177e4SLinus Torvalds #endif 1001da177e4SLinus Torvalds /* 1011da177e4SLinus Torvalds * Mask and clear all possible interrupts 1021da177e4SLinus Torvalds */ 1031da177e4SLinus Torvalds 1041da177e4SLinus Torvalds for (i = 0x30 ; i < 0x70 ; i += 0x10) { 1051da177e4SLinus Torvalds psc_write_byte(pIERbase + i, 0x0F); 1061da177e4SLinus Torvalds psc_write_byte(pIFRbase + i, 0x0F); 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds } 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds /* 1111da177e4SLinus Torvalds * PSC interrupt handler. It's a lot like the VIA interrupt handler. 1121da177e4SLinus Torvalds */ 1131da177e4SLinus Torvalds 114bd0b9ac4SThomas Gleixner static void psc_irq(struct irq_desc *desc) 1159145db56SGeert Uytterhoeven { 1169145db56SGeert Uytterhoeven unsigned int offset = (unsigned int)irq_desc_get_handler_data(desc); 117625b86adSThomas Gleixner unsigned int irq = irq_desc_get_irq(desc); 1189145db56SGeert Uytterhoeven int pIFR = pIFRbase + offset; 1199145db56SGeert Uytterhoeven int pIER = pIERbase + offset; 1209145db56SGeert Uytterhoeven int irq_num; 1219145db56SGeert Uytterhoeven unsigned char irq_bit, events; 1229145db56SGeert Uytterhoeven 1239145db56SGeert Uytterhoeven events = psc_read_byte(pIFR) & psc_read_byte(pIER) & 0xF; 1249145db56SGeert Uytterhoeven if (!events) 1259145db56SGeert Uytterhoeven return; 1269145db56SGeert Uytterhoeven 1279145db56SGeert Uytterhoeven irq_num = irq << 3; 1289145db56SGeert Uytterhoeven irq_bit = 1; 1299145db56SGeert Uytterhoeven do { 1309145db56SGeert Uytterhoeven if (events & irq_bit) { 1319145db56SGeert Uytterhoeven psc_write_byte(pIFR, irq_bit); 1329145db56SGeert Uytterhoeven generic_handle_irq(irq_num); 1339145db56SGeert Uytterhoeven } 1349145db56SGeert Uytterhoeven irq_num++; 1359145db56SGeert Uytterhoeven irq_bit <<= 1; 1369145db56SGeert Uytterhoeven } while (events >= irq_bit); 1379145db56SGeert Uytterhoeven } 1389145db56SGeert Uytterhoeven 1399145db56SGeert Uytterhoeven /* 1409145db56SGeert Uytterhoeven * Register the PSC interrupt dispatchers for autovector interrupts 3-6. 1419145db56SGeert Uytterhoeven */ 1429145db56SGeert Uytterhoeven 1439145db56SGeert Uytterhoeven void __init psc_register_interrupts(void) 1449145db56SGeert Uytterhoeven { 14509c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_3, psc_irq, (void *)0x30); 14609c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_4, psc_irq, (void *)0x40); 14709c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_5, psc_irq, (void *)0x50); 14809c5cb94SThomas Gleixner irq_set_chained_handler_and_data(IRQ_AUTO_6, psc_irq, (void *)0x60); 1499145db56SGeert Uytterhoeven } 1501da177e4SLinus Torvalds 1511da177e4SLinus Torvalds void psc_irq_enable(int irq) { 1521da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1531da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1541da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1551da177e4SLinus Torvalds 1561da177e4SLinus Torvalds psc_write_byte(pIER, (1 << irq_idx) | 0x80); 1571da177e4SLinus Torvalds } 1581da177e4SLinus Torvalds 1591da177e4SLinus Torvalds void psc_irq_disable(int irq) { 1601da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1611da177e4SLinus Torvalds int irq_idx = IRQ_IDX(irq); 1621da177e4SLinus Torvalds int pIER = pIERbase + (irq_src << 4); 1631da177e4SLinus Torvalds 1641da177e4SLinus Torvalds psc_write_byte(pIER, 1 << irq_idx); 1651da177e4SLinus Torvalds } 166