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