xref: /netbsd-src/sys/dev/sbus/xbox.c (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: xbox.c,v 1.15 2008/04/28 20:23:57 martin 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.15 2008/04/28 20:23:57 martin 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(struct device *, struct cfdata *, void *);
95 void	xbox_attach(struct device *, struct device *, 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(args, busname)
103 	void *args;
104 	const char *busname;
105 {
106 	struct xbox_attach_args *xa = args;
107 
108 	if (busname)
109 		aprint_normal("%s at %s", xa->xa_name, busname);
110 	return (UNCONF);
111 }
112 
113 int
114 xbox_match(parent, cf, aux)
115 	struct device *parent;
116 	struct cfdata *cf;
117 	void *aux;
118 {
119 	struct sbus_attach_args *sa = aux;
120 
121 	return (strcmp("SUNW,xbox", sa->sa_name) == 0);
122 }
123 
124 /*
125  * Attach an Xbox.
126  */
127 void
128 xbox_attach(parent, self, aux)
129 	struct device *parent;
130 	struct device *self;
131 	void *aux;
132 {
133 	struct xbox_softc *sc = (struct xbox_softc *)self;
134 	struct sbus_attach_args *sa = aux;
135 	int node = sa->sa_node;
136 	struct xbox_attach_args xa;
137 	char *cp;
138 
139 	sc->sc_key = prom_getpropint(node, "write0-key", -1);
140 
141 	cp = prom_getpropstring(node, "model");
142 	printf(": model %s", cp);
143 
144 	cp = prom_getpropstring(node, "child-present");
145 	if (strcmp(cp, "true") != 0) {
146 		printf(": no sbus devices\n");
147 		return;
148 	}
149 
150 	printf("\n");
151 
152 	/*
153 	 * Now pretend to be another Sbus.
154 	 */
155 	bzero(&xa, sizeof xa);
156 	xa.xa_name = "sbus";
157 	xa.xa_node = node;
158 	xa.xa_bustag = sa->sa_bustag;
159 	xa.xa_dmatag = sa->sa_dmatag;
160 
161 	(void) config_found(&sc->sc_dev, (void *)&xa, xbox_print);
162 }
163