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