blob: f7ea8f0327199ebc8a22e9f4fe663a1794410b7c [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() */
16
17/* Probe and map in the Auxiliary I/O register */
18
19/* auxio_register is not static because it is referenced
20 * in entry.S::floppy_tdone
21 */
22void __iomem *auxio_register = NULL;
23static DEFINE_SPINLOCK(auxio_lock);
24
25void __init auxio_probe(void)
26{
Andres Salomon8d125562010-10-08 14:18:11 -070027 phandle node, auxio_nd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 struct linux_prom_registers auxregs[1];
29 struct resource r;
30
31 switch (sparc_cpu_model) {
Kristoffer Glemboc000c712009-11-13 05:21:22 +000032 case sparc_leon:
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 case sun4d:
34 case sun4:
35 return;
36 default:
37 break;
38 }
39 node = prom_getchild(prom_root_node);
40 auxio_nd = prom_searchsiblings(node, "auxiliary-io");
41 if(!auxio_nd) {
42 node = prom_searchsiblings(node, "obio");
43 node = prom_getchild(node);
44 auxio_nd = prom_searchsiblings(node, "auxio");
45 if(!auxio_nd) {
46#ifdef CONFIG_PCI
47 /* There may be auxio on Ebus */
48 return;
49#else
50 if(prom_searchsiblings(node, "leds")) {
51 /* VME chassis sun4m machine, no auxio exists. */
52 return;
53 }
54 prom_printf("Cannot find auxio node, cannot continue...\n");
55 prom_halt();
56#endif
57 }
58 }
59 if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
60 return;
61 prom_apply_obio_ranges(auxregs, 0x1);
62 /* Map the register both read and write */
63 r.flags = auxregs[0].which_io & 0xF;
64 r.start = auxregs[0].phys_addr;
65 r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1;
David S. Miller454eeb22008-08-27 04:05:35 -070066 auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 /* Fix the address on sun4m and sun4c. */
68 if((((unsigned long) auxregs[0].phys_addr) & 3) == 3 ||
69 sparc_cpu_model == sun4c)
70 auxio_register += (3 - ((unsigned long)auxio_register & 3));
71
72 set_auxio(AUXIO_LED, 0);
73}
74
75unsigned char get_auxio(void)
76{
77 if(auxio_register)
78 return sbus_readb(auxio_register);
79 return 0;
80}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -080081EXPORT_SYMBOL(get_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
83void set_auxio(unsigned char bits_on, unsigned char bits_off)
84{
85 unsigned char regval;
86 unsigned long flags;
87 spin_lock_irqsave(&auxio_lock, flags);
88 switch(sparc_cpu_model) {
89 case sun4c:
90 regval = sbus_readb(auxio_register);
91 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN,
92 auxio_register);
93 break;
94 case sun4m:
95 if(!auxio_register)
Simon Arlottd1a78c32007-05-11 13:51:23 -070096 break; /* VME chassis sun4m, no auxio. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 regval = sbus_readb(auxio_register);
98 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
99 auxio_register);
100 break;
101 case sun4d:
102 break;
103 default:
104 panic("Can't set AUXIO register on this machine.");
Joe Perches6cb79b32011-06-03 14:45:23 +0000105 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 spin_unlock_irqrestore(&auxio_lock, flags);
107}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800108EXPORT_SYMBOL(set_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110/* sun4m power control register (AUXIO2) */
111
112volatile unsigned char * auxio_power_register = NULL;
113
114void __init auxio_power_probe(void)
115{
116 struct linux_prom_registers regs;
Andres Salomon8d125562010-10-08 14:18:11 -0700117 phandle node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct resource r;
119
120 /* Attempt to find the sun4m power control node. */
121 node = prom_getchild(prom_root_node);
122 node = prom_searchsiblings(node, "obio");
123 node = prom_getchild(node);
124 node = prom_searchsiblings(node, "power");
Andres Salomon4a3a2552010-11-11 22:42:06 -0800125 if (node == 0 || (s32)node == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 return;
127
128 /* Map the power control register. */
129 if (prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)) <= 0)
130 return;
131 prom_apply_obio_ranges(&regs, 1);
132 memset(&r, 0, sizeof(r));
133 r.flags = regs.which_io & 0xF;
134 r.start = regs.phys_addr;
135 r.end = regs.phys_addr + regs.reg_size - 1;
David S. Miller454eeb22008-08-27 04:05:35 -0700136 auxio_power_register = (unsigned char *) of_ioremap(&r, 0,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 regs.reg_size, "auxpower");
138
139 /* Display a quick message on the console. */
140 if (auxio_power_register)
141 printk(KERN_INFO "Power off control detected.\n");
142}