blob: ae88c223e4d3e6475d18224b06f9f34a554555ef [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>
Sam Ravnborga3ee8fa2014-04-21 21:39:35 +020012
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <asm/oplib.h>
14#include <asm/io.h>
15#include <asm/auxio.h>
16#include <asm/string.h> /* memset(), Linux has no bzero() */
David Howellsd550bbd2012-03-28 18:30:03 +010017#include <asm/cpu_type.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
Sam Ravnborga3ee8fa2014-04-21 21:39:35 +020019#include "kernel.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021/* Probe and map in the Auxiliary I/O register */
22
23/* auxio_register is not static because it is referenced
24 * in entry.S::floppy_tdone
25 */
26void __iomem *auxio_register = NULL;
27static DEFINE_SPINLOCK(auxio_lock);
28
29void __init auxio_probe(void)
30{
Andres Salomon8d125562010-10-08 14:18:11 -070031 phandle node, auxio_nd;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 struct linux_prom_registers auxregs[1];
33 struct resource r;
34
35 switch (sparc_cpu_model) {
Kristoffer Glemboc000c71272d2009-11-13 05:21:22 +000036 case sparc_leon:
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 case sun4d:
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 return;
39 default:
40 break;
41 }
42 node = prom_getchild(prom_root_node);
43 auxio_nd = prom_searchsiblings(node, "auxiliary-io");
44 if(!auxio_nd) {
45 node = prom_searchsiblings(node, "obio");
46 node = prom_getchild(node);
47 auxio_nd = prom_searchsiblings(node, "auxio");
48 if(!auxio_nd) {
49#ifdef CONFIG_PCI
50 /* There may be auxio on Ebus */
51 return;
52#else
53 if(prom_searchsiblings(node, "leds")) {
54 /* VME chassis sun4m machine, no auxio exists. */
55 return;
56 }
57 prom_printf("Cannot find auxio node, cannot continue...\n");
58 prom_halt();
59#endif
60 }
61 }
62 if(prom_getproperty(auxio_nd, "reg", (char *) auxregs, sizeof(auxregs)) <= 0)
63 return;
64 prom_apply_obio_ranges(auxregs, 0x1);
65 /* Map the register both read and write */
66 r.flags = auxregs[0].which_io & 0xF;
67 r.start = auxregs[0].phys_addr;
68 r.end = auxregs[0].phys_addr + auxregs[0].reg_size - 1;
David S. Miller454eeb22008-08-27 04:05:35 -070069 auxio_register = of_ioremap(&r, 0, auxregs[0].reg_size, "auxio");
David S. Miller6e54e952012-05-12 00:23:23 -070070 /* Fix the address on sun4m. */
71 if ((((unsigned long) auxregs[0].phys_addr) & 3) == 3)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 auxio_register += (3 - ((unsigned long)auxio_register & 3));
73
74 set_auxio(AUXIO_LED, 0);
75}
76
77unsigned char get_auxio(void)
78{
79 if(auxio_register)
80 return sbus_readb(auxio_register);
81 return 0;
82}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -080083EXPORT_SYMBOL(get_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85void set_auxio(unsigned char bits_on, unsigned char bits_off)
86{
87 unsigned char regval;
88 unsigned long flags;
89 spin_lock_irqsave(&auxio_lock, flags);
David S. Miller6e54e952012-05-12 00:23:23 -070090 switch (sparc_cpu_model) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 case sun4m:
92 if(!auxio_register)
Simon Arlottd1a78c32007-05-11 13:51:23 -070093 break; /* VME chassis sun4m, no auxio. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 regval = sbus_readb(auxio_register);
95 sbus_writeb(((regval | bits_on) & ~bits_off) | AUXIO_ORMEIN4M,
96 auxio_register);
97 break;
98 case sun4d:
99 break;
100 default:
101 panic("Can't set AUXIO register on this machine.");
Joe Perches6cb79b32011-06-03 14:45:23 +0000102 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 spin_unlock_irqrestore(&auxio_lock, flags);
104}
Sam Ravnborg6943f3d2009-01-08 16:58:05 -0800105EXPORT_SYMBOL(set_auxio);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
107/* sun4m power control register (AUXIO2) */
108
Sam Ravnborgd2aca8f2014-05-16 23:25:43 +0200109volatile u8 __iomem *auxio_power_register = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
111void __init auxio_power_probe(void)
112{
113 struct linux_prom_registers regs;
Andres Salomon8d125562010-10-08 14:18:11 -0700114 phandle node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 struct resource r;
116
117 /* Attempt to find the sun4m power control node. */
118 node = prom_getchild(prom_root_node);
119 node = prom_searchsiblings(node, "obio");
120 node = prom_getchild(node);
121 node = prom_searchsiblings(node, "power");
Andres Salomon4a3a2552010-11-11 22:42:06 -0800122 if (node == 0 || (s32)node == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 return;
124
125 /* Map the power control register. */
126 if (prom_getproperty(node, "reg", (char *)&regs, sizeof(regs)) <= 0)
127 return;
128 prom_apply_obio_ranges(&regs, 1);
129 memset(&r, 0, sizeof(r));
130 r.flags = regs.which_io & 0xF;
131 r.start = regs.phys_addr;
132 r.end = regs.phys_addr + regs.reg_size - 1;
Sam Ravnborgd2aca8f2014-05-16 23:25:43 +0200133 auxio_power_register =
134 (u8 __iomem *)of_ioremap(&r, 0, regs.reg_size, "auxpower");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* Display a quick message on the console. */
137 if (auxio_power_register)
138 printk(KERN_INFO "Power off control detected.\n");
139}