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