blob: 56d0f52c3e62e5d675cc7f5f28089266f2b13985 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* auxio.c: Probing for the Sparc AUXIO register at boot time.
2 *
3 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
4 */
5
6#include <linux/stddef.h>
7#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/spinlock.h>
David S. Miller454eeb22008-08-27 04:05:35 -07009#include <linux/of.h>
10#include <linux/of_device.h>
Paul Gortmaker7b64db62011-07-18 15:57:46 -040011#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <asm/oplib.h>
13#include <asm/io.h>
14#include <asm/auxio.h>
15#include <asm/string.h> /* memset(), Linux has no bzero() */
David Howellsd550bbd2012-03-28 18:30:03 +010016#include <asm/cpu_type.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18/* Probe and map in the Auxiliary I/O register */
19
20/* auxio_register is not static because it is referenced
21 * in entry.S::floppy_tdone
22 */
23void __iomem *auxio_register = NULL;
24static DEFINE_SPINLOCK(auxio_lock);
25
26void __init auxio_probe(void)
27{
Andres Salomon8d125562010-10-08 14:18:11 -070028 phandle node, auxio_nd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 struct linux_prom_registers auxregs[1];
30 struct resource r;
31
32 switch (sparc_cpu_model) {
Kristoffer Glemboc000c712009-11-13 05:21:22 +000033 case sparc_leon:
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 case sun4d:
35 case sun4:
36 return;
37 default:
38 break;
39 }
40 node = prom_getchild(prom_root_node);
41 auxio_nd = prom_searchsiblings(node, "auxiliary-io");
42 if(!auxio_nd) {
43 node = prom_searchsiblings(node, "obio");
44 node = prom_getchild(node);
45 auxio_nd = prom_searchsiblings(node, "auxio");
46 if(!auxio_nd) {
47#ifdef CONFIG_PCI
48 /* There may be auxio on Ebus */
49 return;
50#else
51 if(prom_searchsiblings(node, "leds")) {
52 /* VME chassis sun4m machine, no auxio exists. */
53 return;
54 }
55 prom_printf("Cannot find auxio node, cannot continue...\n");
56 prom_halt();
57#endif
58 }
59 }
60 if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
61 return;
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;
David S. Miller454eeb22008-08-27 04:05:35 -070067 auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 /* 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));
72
73 set_auxio(AUXIO_LED, 0);
74}
75
76unsigned char get_auxio(void)
77{
78 if(auxio_register)
79 return sbus_readb(auxio_register);
80 return 0;
81}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -080082EXPORT_SYMBOL(get_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84void set_auxio(unsigned char bits_on, unsigned char bits_off)
85{
86 unsigned char regval;
87 unsigned long flags;
88 spin_lock_irqsave(&auxio_lock, flags);
89 switch(sparc_cpu_model) {
90 case sun4c:
91 regval = sbus_readb(auxio_register);
92 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN,
93 auxio_register);
94 break;
95 case sun4m:
96 if(!auxio_register)
Simon Arlottd1a78c32007-05-11 13:51:23 -070097 break; /* VME chassis sun4m, no auxio. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 regval = sbus_readb(auxio_register);
99 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
100 auxio_register);
101 break;
102 case sun4d:
103 break;
104 default:
105 panic("Can't set AUXIO register on this machine.");
Joe Perches6cb79b32011-06-03 14:45:23 +0000106 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 spin_unlock_irqrestore(&auxio_lock, flags);
108}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800109EXPORT_SYMBOL(set_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111/* sun4m power control register (AUXIO2) */
112
113volatile unsigned char * auxio_power_register = NULL;
114
115void __init auxio_power_probe(void)
116{
117 struct linux_prom_registers regs;
Andres Salomon8d125562010-10-08 14:18:11 -0700118 phandle node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 struct resource r;
120
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");
Andres Salomon4a3a2552010-11-11 22:42:06 -0800126 if (node == 0 || (s32)node == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 return;
128
129 /* Map the power control register. */
130 if (prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)) <= 0)
131 return;
132 prom_apply_obio_ranges(&regs, 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;
David S. Miller454eeb22008-08-27 04:05:35 -0700137 auxio_power_register = (unsigned char *) of_ioremap(&r, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 regs.reg_size, "auxpower");
139
140 /* Display a quick message on the console. */
141 if (auxio_power_register)
142 printk(KERN_INFO "Power off control detected.\n");
143}