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