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