1d670bd4fSSam Ravnborg /* auxio.c: Probing for the Sparc AUXIO register at boot time. 2d670bd4fSSam Ravnborg * 3d670bd4fSSam Ravnborg * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 4d670bd4fSSam Ravnborg */ 5d670bd4fSSam Ravnborg 6d670bd4fSSam Ravnborg #include <linux/stddef.h> 7d670bd4fSSam Ravnborg #include <linux/init.h> 8d670bd4fSSam Ravnborg #include <linux/spinlock.h> 9d670bd4fSSam Ravnborg #include <linux/of.h> 10d670bd4fSSam Ravnborg #include <linux/of_device.h> 11d670bd4fSSam Ravnborg #include <asm/oplib.h> 12d670bd4fSSam Ravnborg #include <asm/io.h> 13d670bd4fSSam Ravnborg #include <asm/auxio.h> 14d670bd4fSSam Ravnborg #include <asm/string.h> /* memset(), Linux has no bzero() */ 15d670bd4fSSam Ravnborg 16d670bd4fSSam Ravnborg /* Probe and map in the Auxiliary I/O register */ 17d670bd4fSSam Ravnborg 18d670bd4fSSam Ravnborg /* auxio_register is not static because it is referenced 19d670bd4fSSam Ravnborg * in entry.S::floppy_tdone 20d670bd4fSSam Ravnborg */ 21d670bd4fSSam Ravnborg void __iomem *auxio_register = NULL; 22d670bd4fSSam Ravnborg static DEFINE_SPINLOCK(auxio_lock); 23d670bd4fSSam Ravnborg 24d670bd4fSSam Ravnborg void __init auxio_probe(void) 25d670bd4fSSam Ravnborg { 26d670bd4fSSam Ravnborg int node, auxio_nd; 27d670bd4fSSam Ravnborg struct linux_prom_registers auxregs[1]; 28d670bd4fSSam Ravnborg struct resource r; 29d670bd4fSSam Ravnborg 30d670bd4fSSam Ravnborg switch (sparc_cpu_model) { 31d670bd4fSSam Ravnborg case sun4d: 32d670bd4fSSam Ravnborg case sun4: 33d670bd4fSSam Ravnborg return; 34d670bd4fSSam Ravnborg default: 35d670bd4fSSam Ravnborg break; 36d670bd4fSSam Ravnborg } 37d670bd4fSSam Ravnborg node = prom_getchild(prom_root_node); 38d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxiliary-io"); 39d670bd4fSSam Ravnborg if(!auxio_nd) { 40d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "obio"); 41d670bd4fSSam Ravnborg node = prom_getchild(node); 42d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxio"); 43d670bd4fSSam Ravnborg if(!auxio_nd) { 44d670bd4fSSam Ravnborg #ifdef CONFIG_PCI 45d670bd4fSSam Ravnborg /* There may be auxio on Ebus */ 46d670bd4fSSam Ravnborg return; 47d670bd4fSSam Ravnborg #else 48d670bd4fSSam Ravnborg if(prom_searchsiblings(node, "leds")) { 49d670bd4fSSam Ravnborg /* VME chassis sun4m machine, no auxio exists. */ 50d670bd4fSSam Ravnborg return; 51d670bd4fSSam Ravnborg } 52d670bd4fSSam Ravnborg prom_printf("Cannot find auxio node, cannot continue...\n"); 53d670bd4fSSam Ravnborg prom_halt(); 54d670bd4fSSam Ravnborg #endif 55d670bd4fSSam Ravnborg } 56d670bd4fSSam Ravnborg } 57d670bd4fSSam Ravnborg if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0) 58d670bd4fSSam Ravnborg return; 59d670bd4fSSam Ravnborg prom_apply_obio_ranges(auxregs, 0x1); 60d670bd4fSSam Ravnborg /* Map the register both read and write */ 61d670bd4fSSam Ravnborg r.flags = auxregs[0].which_io & 0xF; 62d670bd4fSSam Ravnborg r.start = auxregs[0].phys_addr; 63d670bd4fSSam Ravnborg r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1; 64d670bd4fSSam Ravnborg auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio"); 65d670bd4fSSam Ravnborg /* Fix the address on sun4m and sun4c. */ 66d670bd4fSSam Ravnborg if((((unsigned long) auxregs[0].phys_addr) & 3) == 3 || 67d670bd4fSSam Ravnborg sparc_cpu_model == sun4c) 68d670bd4fSSam Ravnborg auxio_register += (3 - ((unsigned long)auxio_register & 3)); 69d670bd4fSSam Ravnborg 70d670bd4fSSam Ravnborg set_auxio(AUXIO_LED, 0); 71d670bd4fSSam Ravnborg } 72d670bd4fSSam Ravnborg 73d670bd4fSSam Ravnborg unsigned char get_auxio(void) 74d670bd4fSSam Ravnborg { 75d670bd4fSSam Ravnborg if(auxio_register) 76d670bd4fSSam Ravnborg return sbus_readb(auxio_register); 77d670bd4fSSam Ravnborg return 0; 78d670bd4fSSam Ravnborg } 79*6943f3daSSam Ravnborg EXPORT_SYMBOL(get_auxio); 80d670bd4fSSam Ravnborg 81d670bd4fSSam Ravnborg void set_auxio(unsigned char bits_on, unsigned char bits_off) 82d670bd4fSSam Ravnborg { 83d670bd4fSSam Ravnborg unsigned char regval; 84d670bd4fSSam Ravnborg unsigned long flags; 85d670bd4fSSam Ravnborg spin_lock_irqsave(&auxio_lock, flags); 86d670bd4fSSam Ravnborg switch(sparc_cpu_model) { 87d670bd4fSSam Ravnborg case sun4c: 88d670bd4fSSam Ravnborg regval = sbus_readb(auxio_register); 89d670bd4fSSam Ravnborg sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN, 90d670bd4fSSam Ravnborg auxio_register); 91d670bd4fSSam Ravnborg break; 92d670bd4fSSam Ravnborg case sun4m: 93d670bd4fSSam Ravnborg if(!auxio_register) 94d670bd4fSSam Ravnborg break; /* VME chassis sun4m, no auxio. */ 95d670bd4fSSam Ravnborg regval = sbus_readb(auxio_register); 96d670bd4fSSam Ravnborg sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M, 97d670bd4fSSam Ravnborg auxio_register); 98d670bd4fSSam Ravnborg break; 99d670bd4fSSam Ravnborg case sun4d: 100d670bd4fSSam Ravnborg break; 101d670bd4fSSam Ravnborg default: 102d670bd4fSSam Ravnborg panic("Can't set AUXIO register on this machine."); 103d670bd4fSSam Ravnborg }; 104d670bd4fSSam Ravnborg spin_unlock_irqrestore(&auxio_lock, flags); 105d670bd4fSSam Ravnborg } 106*6943f3daSSam Ravnborg EXPORT_SYMBOL(set_auxio); 107d670bd4fSSam Ravnborg 108d670bd4fSSam Ravnborg /* sun4m power control register (AUXIO2) */ 109d670bd4fSSam Ravnborg 110d670bd4fSSam Ravnborg volatile unsigned char * auxio_power_register = NULL; 111d670bd4fSSam Ravnborg 112d670bd4fSSam Ravnborg void __init auxio_power_probe(void) 113d670bd4fSSam Ravnborg { 114d670bd4fSSam Ravnborg struct linux_prom_registers regs; 115d670bd4fSSam Ravnborg int node; 116d670bd4fSSam Ravnborg struct resource r; 117d670bd4fSSam Ravnborg 118d670bd4fSSam Ravnborg /* Attempt to find the sun4m power control node. */ 119d670bd4fSSam Ravnborg node = prom_getchild(prom_root_node); 120d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "obio"); 121d670bd4fSSam Ravnborg node = prom_getchild(node); 122d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "power"); 123d670bd4fSSam Ravnborg if (node == 0 || node == -1) 124d670bd4fSSam Ravnborg return; 125d670bd4fSSam Ravnborg 126d670bd4fSSam Ravnborg /* Map the power control register. */ 127d670bd4fSSam Ravnborg if (prom_getproperty(node, "reg", (char *)®s, sizeof(regs)) <= 0) 128d670bd4fSSam Ravnborg return; 129d670bd4fSSam Ravnborg prom_apply_obio_ranges(®s, 1); 130d670bd4fSSam Ravnborg memset(&r, 0, sizeof(r)); 131d670bd4fSSam Ravnborg r.flags = regs.which_io & 0xF; 132d670bd4fSSam Ravnborg r.start = regs.phys_addr; 133d670bd4fSSam Ravnborg r.end = regs.phys_addr + regs.reg_size - 1; 134d670bd4fSSam Ravnborg auxio_power_register = (unsigned char *) of_ioremap(&r, 0, 135d670bd4fSSam Ravnborg regs.reg_size, "auxpower"); 136d670bd4fSSam Ravnborg 137d670bd4fSSam Ravnborg /* Display a quick message on the console. */ 138d670bd4fSSam Ravnborg if (auxio_power_register) 139d670bd4fSSam Ravnborg printk(KERN_INFO "Power off control detected.\n"); 140d670bd4fSSam Ravnborg } 141