1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2d670bd4fSSam Ravnborg /* auxio.c: Probing for the Sparc AUXIO register at boot time. 3d670bd4fSSam Ravnborg * 4d670bd4fSSam Ravnborg * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 5d670bd4fSSam Ravnborg */ 6d670bd4fSSam Ravnborg 7d670bd4fSSam Ravnborg #include <linux/stddef.h> 8d670bd4fSSam Ravnborg #include <linux/init.h> 9d670bd4fSSam Ravnborg #include <linux/spinlock.h> 10d670bd4fSSam Ravnborg #include <linux/of.h> 11d670bd4fSSam Ravnborg #include <linux/of_device.h> 127b64db60SPaul Gortmaker #include <linux/export.h> 13a3ee8faaSSam Ravnborg 14d670bd4fSSam Ravnborg #include <asm/oplib.h> 15d670bd4fSSam Ravnborg #include <asm/io.h> 16d670bd4fSSam Ravnborg #include <asm/auxio.h> 17d670bd4fSSam Ravnborg #include <asm/string.h> /* memset(), Linux has no bzero() */ 18d550bbd4SDavid Howells #include <asm/cpu_type.h> 19d670bd4fSSam Ravnborg 20a3ee8faaSSam Ravnborg #include "kernel.h" 21a3ee8faaSSam Ravnborg 22d670bd4fSSam Ravnborg /* Probe and map in the Auxiliary I/O register */ 23d670bd4fSSam Ravnborg 24d670bd4fSSam Ravnborg /* auxio_register is not static because it is referenced 25d670bd4fSSam Ravnborg * in entry.S::floppy_tdone 26d670bd4fSSam Ravnborg */ 27d670bd4fSSam Ravnborg void __iomem *auxio_register = NULL; 28d670bd4fSSam Ravnborg static DEFINE_SPINLOCK(auxio_lock); 29d670bd4fSSam Ravnborg 30d670bd4fSSam Ravnborg void __init auxio_probe(void) 31d670bd4fSSam Ravnborg { 328d125562SAndres Salomon phandle node, auxio_nd; 33d670bd4fSSam Ravnborg struct linux_prom_registers auxregs[1]; 34d670bd4fSSam Ravnborg struct resource r; 35d670bd4fSSam Ravnborg 36d670bd4fSSam Ravnborg switch (sparc_cpu_model) { 37c000c712SKristoffer Glembo case sparc_leon: 38d670bd4fSSam Ravnborg case sun4d: 39d670bd4fSSam Ravnborg return; 40d670bd4fSSam Ravnborg default: 41d670bd4fSSam Ravnborg break; 42d670bd4fSSam Ravnborg } 43d670bd4fSSam Ravnborg node = prom_getchild(prom_root_node); 44d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxiliary-io"); 45d670bd4fSSam Ravnborg if(!auxio_nd) { 46d670bd4fSSam Ravnborg node = prom_searchsiblings(node, "obio"); 47d670bd4fSSam Ravnborg node = prom_getchild(node); 48d670bd4fSSam Ravnborg auxio_nd = prom_searchsiblings(node, "auxio"); 49d670bd4fSSam Ravnborg if(!auxio_nd) { 50d670bd4fSSam Ravnborg #ifdef CONFIG_PCI 51d670bd4fSSam Ravnborg /* There may be auxio on Ebus */ 52d670bd4fSSam Ravnborg return; 53d670bd4fSSam Ravnborg #else 54d670bd4fSSam Ravnborg if(prom_searchsiblings(node, "leds")) { 55d670bd4fSSam Ravnborg /* VME chassis sun4m machine, no auxio exists. */ 56d670bd4fSSam Ravnborg return; 57d670bd4fSSam Ravnborg } 58d670bd4fSSam Ravnborg prom_printf("Cannot find auxio node, cannot continue...\n"); 59d670bd4fSSam Ravnborg prom_halt(); 60d670bd4fSSam Ravnborg #endif 61d670bd4fSSam Ravnborg } 62d670bd4fSSam Ravnborg } 63d670bd4fSSam Ravnborg if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0) 64d670bd4fSSam Ravnborg return; 65d670bd4fSSam Ravnborg prom_apply_obio_ranges(auxregs, 0x1); 66d670bd4fSSam Ravnborg /* Map the register both read and write */ 67d670bd4fSSam Ravnborg r.flags = auxregs[0].which_io & 0xF; 68d670bd4fSSam Ravnborg r.start = auxregs[0].phys_addr; 69d670bd4fSSam Ravnborg r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1; 70d670bd4fSSam Ravnborg auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio"); 716e54e950SDavid S. Miller /* Fix the address on sun4m. */ 726e54e950SDavid S. Miller if ((((unsigned long) auxregs[0].phys_addr) & 3) == 3) 73d670bd4fSSam Ravnborg auxio_register += (3 - ((unsigned long)auxio_register & 3)); 74d670bd4fSSam Ravnborg 75d670bd4fSSam Ravnborg set_auxio(AUXIO_LED, 0); 76d670bd4fSSam Ravnborg } 77d670bd4fSSam Ravnborg 78d670bd4fSSam Ravnborg unsigned char get_auxio(void) 79d670bd4fSSam Ravnborg { 80d670bd4fSSam Ravnborg if(auxio_register) 81d670bd4fSSam Ravnborg return sbus_readb(auxio_register); 82d670bd4fSSam Ravnborg return 0; 83d670bd4fSSam Ravnborg } 846943f3daSSam Ravnborg EXPORT_SYMBOL(get_auxio); 85d670bd4fSSam Ravnborg 86d670bd4fSSam Ravnborg void set_auxio(unsigned char bits_on, unsigned char bits_off) 87d670bd4fSSam Ravnborg { 88d670bd4fSSam Ravnborg unsigned char regval; 89d670bd4fSSam Ravnborg unsigned long flags; 90d670bd4fSSam Ravnborg spin_lock_irqsave(&auxio_lock, flags); 91d670bd4fSSam Ravnborg switch (sparc_cpu_model) { 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."); 1036cb79b3fSJoe Perches } 104d670bd4fSSam Ravnborg spin_unlock_irqrestore(&auxio_lock, flags); 105d670bd4fSSam Ravnborg } 1066943f3daSSam Ravnborg EXPORT_SYMBOL(set_auxio); 107d670bd4fSSam Ravnborg 108d670bd4fSSam Ravnborg /* sun4m power control register (AUXIO2) */ 109d670bd4fSSam Ravnborg 110d2aca8f9SSam Ravnborg volatile u8 __iomem *auxio_power_register = NULL; 111d670bd4fSSam Ravnborg 112d670bd4fSSam Ravnborg void __init auxio_power_probe(void) 113d670bd4fSSam Ravnborg { 114d670bd4fSSam Ravnborg struct linux_prom_registers regs; 1158d125562SAndres Salomon phandle 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"); 1234a3a2552SAndres Salomon if (node == 0 || (s32)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; 134d2aca8f9SSam Ravnborg auxio_power_register = 135d2aca8f9SSam Ravnborg (u8 __iomem *)of_ioremap(&r, 0, 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