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) { 31*c000c712SKristoffer Glembo case sparc_leon: 32d670bd4fSSam Ravnborg case sun4d: 33d670bd4fSSam Ravnborg case sun4: 34d670bd4fSSam Ravnborg return; 35d670bd4fSSam Ravnborg default: 36d670bd4fSSam Ravnborg break; 37d670bd4fSSam Ravnborg } 38d670bd4fSSam Ravnborg node = prom_getchild(prom_root_node); 39d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxiliary-io"); 40d670bd4fSSam Ravnborg if(!auxio_nd) { 41d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "obio"); 42d670bd4fSSam Ravnborg node = prom_getchild(node); 43d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxio"); 44d670bd4fSSam Ravnborg if(!auxio_nd) { 45d670bd4fSSam Ravnborg #ifdef CONFIG_PCI 46d670bd4fSSam Ravnborg /* There may be auxio on Ebus */ 47d670bd4fSSam Ravnborg return; 48d670bd4fSSam Ravnborg #else 49d670bd4fSSam Ravnborg if(prom_searchsiblings(node, "leds")) { 50d670bd4fSSam Ravnborg /* VME chassis sun4m machine, no auxio exists. */ 51d670bd4fSSam Ravnborg return; 52d670bd4fSSam Ravnborg } 53d670bd4fSSam Ravnborg prom_printf("Cannot find auxio node, cannot continue...\n"); 54d670bd4fSSam Ravnborg prom_halt(); 55d670bd4fSSam Ravnborg #endif 56d670bd4fSSam Ravnborg } 57d670bd4fSSam Ravnborg } 58d670bd4fSSam Ravnborg if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0) 59d670bd4fSSam Ravnborg return; 60d670bd4fSSam Ravnborg prom_apply_obio_ranges(auxregs, 0x1); 61d670bd4fSSam Ravnborg /* Map the register both read and write */ 62d670bd4fSSam Ravnborg r.flags = auxregs[0].which_io & 0xF; 63d670bd4fSSam Ravnborg r.start = auxregs[0].phys_addr; 64d670bd4fSSam Ravnborg r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1; 65d670bd4fSSam Ravnborg auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio"); 66d670bd4fSSam Ravnborg /* Fix the address on sun4m and sun4c. */ 67d670bd4fSSam Ravnborg if((((unsigned long) auxregs[0].phys_addr) & 3) == 3 || 68d670bd4fSSam Ravnborg sparc_cpu_model == sun4c) 69d670bd4fSSam Ravnborg auxio_register += (3 - ((unsigned long)auxio_register & 3)); 70d670bd4fSSam Ravnborg 71d670bd4fSSam Ravnborg set_auxio(AUXIO_LED, 0); 72d670bd4fSSam Ravnborg } 73d670bd4fSSam Ravnborg 74d670bd4fSSam Ravnborg unsigned char get_auxio(void) 75d670bd4fSSam Ravnborg { 76d670bd4fSSam Ravnborg if(auxio_register) 77d670bd4fSSam Ravnborg return sbus_readb(auxio_register); 78d670bd4fSSam Ravnborg return 0; 79d670bd4fSSam Ravnborg } 806943f3daSSam Ravnborg EXPORT_SYMBOL(get_auxio); 81d670bd4fSSam Ravnborg 82d670bd4fSSam Ravnborg void set_auxio(unsigned char bits_on, unsigned char bits_off) 83d670bd4fSSam Ravnborg { 84d670bd4fSSam Ravnborg unsigned char regval; 85d670bd4fSSam Ravnborg unsigned long flags; 86d670bd4fSSam Ravnborg spin_lock_irqsave(&auxio_lock, flags); 87d670bd4fSSam Ravnborg switch(sparc_cpu_model) { 88d670bd4fSSam Ravnborg case sun4c: 89d670bd4fSSam Ravnborg regval = sbus_readb(auxio_register); 90d670bd4fSSam Ravnborg sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN, 91d670bd4fSSam Ravnborg auxio_register); 92d670bd4fSSam Ravnborg break; 93d670bd4fSSam Ravnborg case sun4m: 94d670bd4fSSam Ravnborg if(!auxio_register) 95d670bd4fSSam Ravnborg break; /* VME chassis sun4m, no auxio. */ 96d670bd4fSSam Ravnborg regval = sbus_readb(auxio_register); 97d670bd4fSSam Ravnborg sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M, 98d670bd4fSSam Ravnborg auxio_register); 99d670bd4fSSam Ravnborg break; 100d670bd4fSSam Ravnborg case sun4d: 101d670bd4fSSam Ravnborg break; 102d670bd4fSSam Ravnborg default: 103d670bd4fSSam Ravnborg panic("Can't set AUXIO register on this machine."); 104d670bd4fSSam Ravnborg }; 105d670bd4fSSam Ravnborg spin_unlock_irqrestore(&auxio_lock, flags); 106d670bd4fSSam Ravnborg } 1076943f3daSSam Ravnborg EXPORT_SYMBOL(set_auxio); 108d670bd4fSSam Ravnborg 109d670bd4fSSam Ravnborg /* sun4m power control register (AUXIO2) */ 110d670bd4fSSam Ravnborg 111d670bd4fSSam Ravnborg volatile unsigned char * auxio_power_register = NULL; 112d670bd4fSSam Ravnborg 113d670bd4fSSam Ravnborg void __init auxio_power_probe(void) 114d670bd4fSSam Ravnborg { 115d670bd4fSSam Ravnborg struct linux_prom_registers regs; 116d670bd4fSSam Ravnborg int node; 117d670bd4fSSam Ravnborg struct resource r; 118d670bd4fSSam Ravnborg 119d670bd4fSSam Ravnborg /* Attempt to find the sun4m power control node. */ 120d670bd4fSSam Ravnborg node = prom_getchild(prom_root_node); 121d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "obio"); 122d670bd4fSSam Ravnborg node = prom_getchild(node); 123d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "power"); 124d670bd4fSSam Ravnborg if (node == 0 || node == -1) 125d670bd4fSSam Ravnborg return; 126d670bd4fSSam Ravnborg 127d670bd4fSSam Ravnborg /* Map the power control register. */ 128d670bd4fSSam Ravnborg if (prom_getproperty(node, "reg", (char *)®s, sizeof(regs)) <= 0) 129d670bd4fSSam Ravnborg return; 130d670bd4fSSam Ravnborg prom_apply_obio_ranges(®s, 1); 131d670bd4fSSam Ravnborg memset(&r, 0, sizeof(r)); 132d670bd4fSSam Ravnborg r.flags = regs.which_io & 0xF; 133d670bd4fSSam Ravnborg r.start = regs.phys_addr; 134d670bd4fSSam Ravnborg r.end = regs.phys_addr + regs.reg_size - 1; 135d670bd4fSSam Ravnborg auxio_power_register = (unsigned char *) of_ioremap(&r, 0, 136d670bd4fSSam Ravnborg regs.reg_size, "auxpower"); 137d670bd4fSSam Ravnborg 138d670bd4fSSam Ravnborg /* Display a quick message on the console. */ 139d670bd4fSSam Ravnborg if (auxio_power_register) 140d670bd4fSSam Ravnborg printk(KERN_INFO "Power off control detected.\n"); 141d670bd4fSSam Ravnborg } 142