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>
12 #include <asm/oplib.h>
14 #include <asm/auxio.h>
15 #include <asm/string.h> /* memset(), Linux has no bzero() */
16 #include <asm/cpu_type.h>
18 /* Probe and map in the Auxiliary I/O register */
20 /* auxio_register is not static because it is referenced
21 * in entry.S::floppy_tdone
23 void __iomem *auxio_register = NULL;
24 static DEFINE_SPINLOCK(auxio_lock);
26 void __init auxio_probe(void)
28 phandle node, auxio_nd;
29 struct linux_prom_registers auxregs[1];
32 switch (sparc_cpu_model) {
40 node = prom_getchild(prom_root_node);
41 auxio_nd = prom_searchsiblings(node, "auxiliary-io");
43 node = prom_searchsiblings(node, "obio");
44 node = prom_getchild(node);
45 auxio_nd = prom_searchsiblings(node, "auxio");
48 /* There may be auxio on Ebus */
51 if(prom_searchsiblings(node, "leds")) {
52 /* VME chassis sun4m machine, no auxio exists. */
55 prom_printf("Cannot find auxio node, cannot continue...\n");
60 if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
62 prom_apply_obio_ranges(auxregs, 0x1);
63 /* Map the register both read and write */
64 r.flags = auxregs[0].which_io & 0xF;
65 r.start = auxregs[0].phys_addr;
66 r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1;
67 auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
68 /* Fix the address on sun4m and sun4c. */
69 if((((unsigned long) auxregs[0].phys_addr) & 3) == 3 ||
70 sparc_cpu_model == sun4c)
71 auxio_register += (3 - ((unsigned long)auxio_register & 3));
73 set_auxio(AUXIO_LED, 0);
76 unsigned char get_auxio(void)
79 return sbus_readb(auxio_register);
82 EXPORT_SYMBOL(get_auxio);
84 void set_auxio(unsigned char bits_on, unsigned char bits_off)
88 spin_lock_irqsave(&auxio_lock, flags);
89 switch(sparc_cpu_model) {
91 regval = sbus_readb(auxio_register);
92 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN,
97 break; /* VME chassis sun4m, no auxio. */
98 regval = sbus_readb(auxio_register);
99 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
105 panic("Can't set AUXIO register on this machine.");
107 spin_unlock_irqrestore(&auxio_lock, flags);
109 EXPORT_SYMBOL(set_auxio);
111 /* sun4m power control register (AUXIO2) */
113 volatile unsigned char * auxio_power_register = NULL;
115 void __init auxio_power_probe(void)
117 struct linux_prom_registers regs;
121 /* Attempt to find the sun4m power control node. */
122 node = prom_getchild(prom_root_node);
123 node = prom_searchsiblings(node, "obio");
124 node = prom_getchild(node);
125 node = prom_searchsiblings(node, "power");
126 if (node == 0 || (s32)node == -1)
129 /* Map the power control register. */
130 if (prom_getproperty(node, "reg", (char *)®s, sizeof(regs)) <= 0)
132 prom_apply_obio_ranges(®s, 1);
133 memset(&r, 0, sizeof(r));
134 r.flags = regs.which_io & 0xF;
135 r.start = regs.phys_addr;
136 r.end = regs.phys_addr + regs.reg_size - 1;
137 auxio_power_register = (unsigned char *) of_ioremap(&r, 0,
138 regs.reg_size, "auxpower");
140 /* Display a quick message on the console. */
141 if (auxio_power_register)
142 printk(KERN_INFO "Power off control detected.\n");