1 /* auxio.c: Probing for the Sparc AUXIO register at boot time.
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
6 #include <linux/stddef.h>
7 #include <linux/init.h>
8 #include <linux/spinlock.h>
10 #include <linux/of_device.h>
11 #include <linux/export.h>
13 #include <asm/oplib.h>
15 #include <asm/auxio.h>
16 #include <asm/string.h> /* memset(), Linux has no bzero() */
17 #include <asm/cpu_type.h>
21 /* Probe and map in the Auxiliary I/O register */
23 /* auxio_register is not static because it is referenced
24 * in entry.S::floppy_tdone
26 void __iomem *auxio_register = NULL;
27 static DEFINE_SPINLOCK(auxio_lock);
29 void __init auxio_probe(void)
31 phandle node, auxio_nd;
32 struct linux_prom_registers auxregs[1];
35 switch (sparc_cpu_model) {
42 node = prom_getchild(prom_root_node);
43 auxio_nd = prom_searchsiblings(node, "auxiliary-io");
45 node = prom_searchsiblings(node, "obio");
46 node = prom_getchild(node);
47 auxio_nd = prom_searchsiblings(node, "auxio");
50 /* There may be auxio on Ebus */
53 if(prom_searchsiblings(node, "leds")) {
54 /* VME chassis sun4m machine, no auxio exists. */
57 prom_printf("Cannot find auxio node, cannot continue...\n");
62 if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
64 prom_apply_obio_ranges(auxregs, 0x1);
65 /* Map the register both read and write */
66 r.flags = auxregs[0].which_io & 0xF;
67 r.start = auxregs[0].phys_addr;
68 r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1;
69 auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
70 /* Fix the address on sun4m. */
71 if ((((unsigned long) auxregs[0].phys_addr) & 3) == 3)
72 auxio_register += (3 - ((unsigned long)auxio_register & 3));
74 set_auxio(AUXIO_LED, 0);
77 unsigned char get_auxio(void)
80 return sbus_readb(auxio_register);
83 EXPORT_SYMBOL(get_auxio);
85 void set_auxio(unsigned char bits_on, unsigned char bits_off)
89 spin_lock_irqsave(&auxio_lock, flags);
90 switch (sparc_cpu_model) {
93 break; /* VME chassis sun4m, no auxio. */
94 regval = sbus_readb(auxio_register);
95 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
101 panic("Can't set AUXIO register on this machine.");
103 spin_unlock_irqrestore(&auxio_lock, flags);
105 EXPORT_SYMBOL(set_auxio);
107 /* sun4m power control register (AUXIO2) */
109 volatile u8 __iomem *auxio_power_register = NULL;
111 void __init auxio_power_probe(void)
113 struct linux_prom_registers regs;
117 /* Attempt to find the sun4m power control node. */
118 node = prom_getchild(prom_root_node);
119 node = prom_searchsiblings(node, "obio");
120 node = prom_getchild(node);
121 node = prom_searchsiblings(node, "power");
122 if (node == 0 || (s32)node == -1)
125 /* Map the power control register. */
126 if (prom_getproperty(node, "reg", (char *)®s, sizeof(regs)) <= 0)
128 prom_apply_obio_ranges(®s, 1);
129 memset(&r, 0, sizeof(r));
130 r.flags = regs.which_io & 0xF;
131 r.start = regs.phys_addr;
132 r.end = regs.phys_addr + regs.reg_size - 1;
133 auxio_power_register =
134 (u8 __iomem *)of_ioremap(&r, 0, regs.reg_size, "auxpower");
136 /* Display a quick message on the console. */
137 if (auxio_power_register)
138 printk(KERN_INFO "Power off control detected.\n");