1 // SPDX-License-Identifier: GPL-2.0
2 /* auxio.c: Probing for the Sparc AUXIO register at boot time.
4 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 #include <linux/stddef.h>
8 #include <linux/init.h>
9 #include <linux/spinlock.h>
11 #include <linux/of_device.h>
12 #include <linux/export.h>
14 #include <asm/oplib.h>
16 #include <asm/auxio.h>
17 #include <asm/string.h> /* memset(), Linux has no bzero() */
18 #include <asm/cpu_type.h>
22 /* Probe and map in the Auxiliary I/O register */
24 /* auxio_register is not static because it is referenced
25 * in entry.S::floppy_tdone
27 void __iomem
*auxio_register
= NULL
;
28 static DEFINE_SPINLOCK(auxio_lock
);
30 void __init
auxio_probe(void)
32 phandle node
, auxio_nd
;
33 struct linux_prom_registers auxregs
[1];
36 switch (sparc_cpu_model
) {
43 node
= prom_getchild(prom_root_node
);
44 auxio_nd
= prom_searchsiblings(node
, "auxiliary-io");
46 node
= prom_searchsiblings(node
, "obio");
47 node
= prom_getchild(node
);
48 auxio_nd
= prom_searchsiblings(node
, "auxio");
51 /* There may be auxio on Ebus */
54 if(prom_searchsiblings(node
, "leds")) {
55 /* VME chassis sun4m machine, no auxio exists. */
58 prom_printf("Cannot find auxio node, cannot continue...\n");
63 if(prom_getproperty(auxio_nd
, "reg", (char *) auxregs
, sizeof(auxregs
)) <= 0)
65 prom_apply_obio_ranges(auxregs
, 0x1);
66 /* Map the register both read and write */
67 r
.flags
= auxregs
[0].which_io
& 0xF;
68 r
.start
= auxregs
[0].phys_addr
;
69 r
.end
= auxregs
[0].phys_addr
+ auxregs
[0].reg_size
- 1;
70 auxio_register
= of_ioremap(&r
, 0, auxregs
[0].reg_size
, "auxio");
71 /* Fix the address on sun4m. */
72 if ((((unsigned long) auxregs
[0].phys_addr
) & 3) == 3)
73 auxio_register
+= (3 - ((unsigned long)auxio_register
& 3));
75 set_auxio(AUXIO_LED
, 0);
78 unsigned char get_auxio(void)
81 return sbus_readb(auxio_register
);
84 EXPORT_SYMBOL(get_auxio
);
86 void set_auxio(unsigned char bits_on
, unsigned char bits_off
)
90 spin_lock_irqsave(&auxio_lock
, flags
);
91 switch (sparc_cpu_model
) {
94 break; /* VME chassis sun4m, no auxio. */
95 regval
= sbus_readb(auxio_register
);
96 sbus_writeb(((regval
| bits_on
) & ~bits_off
) | AUXIO_ORMEIN4M
,
102 panic("Can't set AUXIO register on this machine.");
104 spin_unlock_irqrestore(&auxio_lock
, flags
);
106 EXPORT_SYMBOL(set_auxio
);
108 /* sun4m power control register (AUXIO2) */
110 volatile u8 __iomem
*auxio_power_register
= NULL
;
112 void __init
auxio_power_probe(void)
114 struct linux_prom_registers regs
;
118 /* Attempt to find the sun4m power control node. */
119 node
= prom_getchild(prom_root_node
);
120 node
= prom_searchsiblings(node
, "obio");
121 node
= prom_getchild(node
);
122 node
= prom_searchsiblings(node
, "power");
123 if (node
== 0 || (s32
)node
== -1)
126 /* Map the power control register. */
127 if (prom_getproperty(node
, "reg", (char *)®s
, sizeof(regs
)) <= 0)
129 prom_apply_obio_ranges(®s
, 1);
130 memset(&r
, 0, sizeof(r
));
131 r
.flags
= regs
.which_io
& 0xF;
132 r
.start
= regs
.phys_addr
;
133 r
.end
= regs
.phys_addr
+ regs
.reg_size
- 1;
134 auxio_power_register
=
135 (u8 __iomem
*)of_ioremap(&r
, 0, regs
.reg_size
, "auxpower");
137 /* Display a quick message on the console. */
138 if (auxio_power_register
)
139 printk(KERN_INFO
"Power off control detected.\n");