xref: /netbsd/sys/dev/sbus/xbox.c (revision 6550d01e)
1 /*	$NetBSD: xbox.c,v 1.20 2009/09/18 12:23:16 tsutsui Exp $ */
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * Sbus expansion box.
34  */
35 
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: xbox.c,v 1.20 2009/09/18 12:23:16 tsutsui Exp $");
38 
39 #include <sys/param.h>
40 #include <sys/malloc.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 
44 #include <sys/bus.h>
45 #include <dev/sbus/sbusvar.h>
46 #include <dev/sbus/xboxvar.h>
47 #include <machine/autoconf.h>
48 
49 /*
50  * Xbox registers definitions.
51  *
52  * The xbox device can operate in two mode: "opaque" and "transparent".
53  * In opaque mode, all accesses to the xbox address space are directed
54  * to the xbox itself. In transparent mode, all accesses are mapped to
55  * the SBus cards in the expansion box.
56  *
57  * To access the xbox registers in transparent mode, you must write
58  * to the "write0" register. The layout of this register appears to
59  * be as follows:
60  *
61  *	bit 31-24: xbox key (identifies device when you cascade them)
62  *	bit 23-12: offset of register to access
63  *	bit 11-0:  value to write
64  *
65  * For instance, to switch to opaque mode:
66  *	(*sc->write0_reg) = (sc->sc_key << 24) | XAC_CTL1_OFFSET;
67  *
68  * (note we're not currently using any of this)
69  */
70 #define WRITE0_OFFSET		0
71 
72 #define XAC_ERR_OFFSET		0x2000
73 #define XAC_CTL0_OFFSET		0x10000
74 #define XAC_CTL1_OFFSET		0x11000
75 #define XAC_ELUA_OFFSET		0x12000
76 #define XAC_ELLA_OFFSET		0x13000
77 #define XAC_ELE_OFFSET		0x14000
78 
79 #define XBC_ERR_OFFSET		0x42000
80 #define XBC_CTL0_OFFSET		0x50000
81 #define XBC_CTL1_OFFSET		0x51000
82 #define XBC_ELUA_OFFSET		0x52000
83 #define XBC_ELLA_OFFSET		0x53000
84 #define XBC_ELE_OFFSET		0x54000
85 
86 #define XBOX_NREG		13
87 
88 struct xbox_softc {
89 	struct device	sc_dev;		/* base device */
90 	int		sc_key;		/* this xbox's unique key */
91 };
92 
93 /* autoconfiguration driver */
94 int	xbox_match(device_t, cfdata_t, void *);
95 void	xbox_attach(device_t, device_t, void *);
96 int	xbox_print( void *, const char *);
97 
98 CFATTACH_DECL(xbox, sizeof(struct xbox_softc),
99     xbox_match, xbox_attach, NULL, NULL);
100 
101 int
102 xbox_print(void *args, const char *busname)
103 {
104 	struct xbox_attach_args *xa = args;
105 
106 	if (busname)
107 		aprint_normal("%s at %s", xa->xa_name, busname);
108 	return (UNCONF);
109 }
110 
111 int
112 xbox_match(device_t parent, cfdata_t cf, void *aux)
113 {
114 	struct sbus_attach_args *sa = aux;
115 
116 	return (strcmp("SUNW,xbox", sa->sa_name) == 0);
117 }
118 
119 /*
120  * Attach an Xbox.
121  */
122 void
123 xbox_attach(device_t parent, device_t self, void *aux)
124 {
125 	struct xbox_softc *sc = device_private(self);
126 	struct sbus_attach_args *sa = aux;
127 	int node = sa->sa_node;
128 	struct xbox_attach_args xa;
129 	char *cp;
130 
131 	sc->sc_key = prom_getpropint(node, "write0-key", -1);
132 
133 	cp = prom_getpropstring(node, "model");
134 	printf(": model %s", cp);
135 
136 	cp = prom_getpropstring(node, "child-present");
137 	if (strcmp(cp, "true") != 0) {
138 		printf(": no sbus devices\n");
139 		return;
140 	}
141 
142 	printf("\n");
143 
144 	/*
145 	 * Now pretend to be another Sbus.
146 	 */
147 	memset(&xa, 0, sizeof xa);
148 	xa.xa_name = "sbus";
149 	xa.xa_node = node;
150 	xa.xa_bustag = sa->sa_bustag;
151 	xa.xa_dmatag = sa->sa_dmatag;
152 
153 	(void) config_found(self, (void *)&xa, xbox_print);
154 }
155