cgsix_sbus.c revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: cgsix_sbus.c,v 1.2.2.2 2000/11/20 22:35:48 bouyer Exp $ */
2 1.2.2.2 bouyer
3 1.2.2.2 bouyer /*-
4 1.2.2.2 bouyer * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.2.2.2 bouyer * All rights reserved.
6 1.2.2.2 bouyer *
7 1.2.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.2.2.2 bouyer * by Paul Kranenburg.
9 1.2.2.2 bouyer *
10 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.2.2.2 bouyer * are met:
13 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.2.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.2.2.2 bouyer * must display the following acknowledgement:
20 1.2.2.2 bouyer * This product includes software developed by the NetBSD
21 1.2.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.2.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.2.2.2 bouyer *
26 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.2.2.2 bouyer */
38 1.2.2.2 bouyer
39 1.2.2.2 bouyer /*
40 1.2.2.2 bouyer * color display (cgsix) driver; Sbus bus front-end.
41 1.2.2.2 bouyer */
42 1.2.2.2 bouyer
43 1.2.2.2 bouyer #include <sys/param.h>
44 1.2.2.2 bouyer #include <sys/systm.h>
45 1.2.2.2 bouyer #include <sys/buf.h>
46 1.2.2.2 bouyer #include <sys/device.h>
47 1.2.2.2 bouyer #include <sys/ioctl.h>
48 1.2.2.2 bouyer #include <sys/malloc.h>
49 1.2.2.2 bouyer #include <sys/mman.h>
50 1.2.2.2 bouyer #include <sys/tty.h>
51 1.2.2.2 bouyer #include <sys/conf.h>
52 1.2.2.2 bouyer
53 1.2.2.2 bouyer #ifdef DEBUG
54 1.2.2.2 bouyer #include <sys/proc.h>
55 1.2.2.2 bouyer #include <sys/syslog.h>
56 1.2.2.2 bouyer #endif
57 1.2.2.2 bouyer
58 1.2.2.2 bouyer #include <machine/bus.h>
59 1.2.2.2 bouyer #include <machine/autoconf.h>
60 1.2.2.2 bouyer
61 1.2.2.2 bouyer #include <dev/sbus/sbusvar.h>
62 1.2.2.2 bouyer
63 1.2.2.2 bouyer #include <dev/sun/fbio.h>
64 1.2.2.2 bouyer #include <dev/sun/fbvar.h>
65 1.2.2.2 bouyer #include <dev/sun/btreg.h>
66 1.2.2.2 bouyer #include <dev/sun/btvar.h>
67 1.2.2.2 bouyer #include <dev/sun/cgsixreg.h>
68 1.2.2.2 bouyer #include <dev/sun/cgsixvar.h>
69 1.2.2.2 bouyer
70 1.2.2.2 bouyer /* autoconfiguration driver */
71 1.2.2.2 bouyer static int cgsixmatch __P((struct device *, struct cfdata *, void *));
72 1.2.2.2 bouyer static void cgsixattach __P((struct device *, struct device *, void *));
73 1.2.2.2 bouyer
74 1.2.2.2 bouyer /* Allocate an `sbusdev' in addition to the cgsix softc */
75 1.2.2.2 bouyer struct cgsix_sbus_softc {
76 1.2.2.2 bouyer struct cgsix_softc bss_softc;
77 1.2.2.2 bouyer struct sbusdev bss_sd;
78 1.2.2.2 bouyer };
79 1.2.2.2 bouyer
80 1.2.2.2 bouyer struct cfattach cgsix_sbus_ca = {
81 1.2.2.2 bouyer sizeof(struct cgsix_sbus_softc), cgsixmatch, cgsixattach
82 1.2.2.2 bouyer };
83 1.2.2.2 bouyer
84 1.2.2.2 bouyer
85 1.2.2.2 bouyer /*
86 1.2.2.2 bouyer * Match a cgsix.
87 1.2.2.2 bouyer */
88 1.2.2.2 bouyer int
89 1.2.2.2 bouyer cgsixmatch(parent, cf, aux)
90 1.2.2.2 bouyer struct device *parent;
91 1.2.2.2 bouyer struct cfdata *cf;
92 1.2.2.2 bouyer void *aux;
93 1.2.2.2 bouyer {
94 1.2.2.2 bouyer struct sbus_attach_args *sa = aux;
95 1.2.2.2 bouyer
96 1.2.2.2 bouyer return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
97 1.2.2.2 bouyer }
98 1.2.2.2 bouyer
99 1.2.2.2 bouyer
100 1.2.2.2 bouyer /*
101 1.2.2.2 bouyer * Attach a cgsix.
102 1.2.2.2 bouyer */
103 1.2.2.2 bouyer void
104 1.2.2.2 bouyer cgsixattach(parent, self, aux)
105 1.2.2.2 bouyer struct device *parent, *self;
106 1.2.2.2 bouyer void *aux;
107 1.2.2.2 bouyer {
108 1.2.2.2 bouyer struct cgsix_softc *sc = (struct cgsix_softc *)self;
109 1.2.2.2 bouyer struct sbusdev *sd = &((struct cgsix_sbus_softc *)self)->bss_sd;
110 1.2.2.2 bouyer struct sbus_attach_args *sa = aux;
111 1.2.2.2 bouyer struct fbdevice *fb = &sc->sc_fb;
112 1.2.2.2 bouyer int node, isconsole;
113 1.2.2.2 bouyer char *name;
114 1.2.2.2 bouyer bus_space_handle_t bh;
115 1.2.2.2 bouyer
116 1.2.2.2 bouyer /* Remember cookies for cgsix_mmap() */
117 1.2.2.2 bouyer sc->sc_bustag = sa->sa_bustag;
118 1.2.2.2 bouyer sc->sc_btype = (bus_type_t)sa->sa_slot;
119 1.2.2.2 bouyer sc->sc_paddr = (bus_addr_t)sa->sa_offset;
120 1.2.2.2 bouyer
121 1.2.2.2 bouyer node = sa->sa_node;
122 1.2.2.2 bouyer
123 1.2.2.2 bouyer fb->fb_device = &sc->sc_dev;
124 1.2.2.2 bouyer fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
125 1.2.2.2 bouyer fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
126 1.2.2.2 bouyer fb->fb_type.fb_depth = 8;
127 1.2.2.2 bouyer
128 1.2.2.2 bouyer fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
129 1.2.2.2 bouyer
130 1.2.2.2 bouyer /*
131 1.2.2.2 bouyer * Dunno what the PROM has mapped, though obviously it must have
132 1.2.2.2 bouyer * the video RAM mapped. Just map what we care about for ourselves
133 1.2.2.2 bouyer * (the FHC, THC, and Brooktree registers).
134 1.2.2.2 bouyer */
135 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
136 1.2.2.2 bouyer sa->sa_offset + CGSIX_BT_OFFSET,
137 1.2.2.2 bouyer sizeof(*sc->sc_bt),
138 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
139 1.2.2.2 bouyer 0, &bh) != 0) {
140 1.2.2.2 bouyer printf("%s: cannot map brooktree registers\n", self->dv_xname);
141 1.2.2.2 bouyer return;
142 1.2.2.2 bouyer }
143 1.2.2.2 bouyer sc->sc_bt = (struct bt_regs *)bh;
144 1.2.2.2 bouyer
145 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
146 1.2.2.2 bouyer sa->sa_offset + CGSIX_FHC_OFFSET,
147 1.2.2.2 bouyer sizeof(*sc->sc_fhc),
148 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
149 1.2.2.2 bouyer 0, &bh) != 0) {
150 1.2.2.2 bouyer printf("%s: cannot map FHC registers\n", self->dv_xname);
151 1.2.2.2 bouyer return;
152 1.2.2.2 bouyer }
153 1.2.2.2 bouyer sc->sc_fhc = (int *)bh;
154 1.2.2.2 bouyer
155 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
156 1.2.2.2 bouyer sa->sa_offset + CGSIX_THC_OFFSET,
157 1.2.2.2 bouyer sizeof(*sc->sc_thc),
158 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
159 1.2.2.2 bouyer 0, &bh) != 0) {
160 1.2.2.2 bouyer printf("%s: cannot map THC registers\n", self->dv_xname);
161 1.2.2.2 bouyer return;
162 1.2.2.2 bouyer }
163 1.2.2.2 bouyer sc->sc_thc = (struct cg6_thc *)bh;
164 1.2.2.2 bouyer
165 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
166 1.2.2.2 bouyer sa->sa_offset + CGSIX_TEC_OFFSET,
167 1.2.2.2 bouyer sizeof(*sc->sc_tec),
168 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
169 1.2.2.2 bouyer 0, &bh) != 0) {
170 1.2.2.2 bouyer printf("%s: cannot map TEC registers\n", self->dv_xname);
171 1.2.2.2 bouyer return;
172 1.2.2.2 bouyer }
173 1.2.2.2 bouyer sc->sc_tec = (struct cg6_tec_xxx *)bh;
174 1.2.2.2 bouyer
175 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
176 1.2.2.2 bouyer sa->sa_offset + CGSIX_FBC_OFFSET,
177 1.2.2.2 bouyer sizeof(*sc->sc_fbc),
178 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
179 1.2.2.2 bouyer 0, &bh) != 0) {
180 1.2.2.2 bouyer printf("%s: cannot map FBC registers\n", self->dv_xname);
181 1.2.2.2 bouyer return;
182 1.2.2.2 bouyer }
183 1.2.2.2 bouyer sc->sc_fbc = (struct cg6_fbc *)bh;
184 1.2.2.2 bouyer
185 1.2.2.2 bouyer sbus_establish(sd, &sc->sc_dev);
186 1.2.2.2 bouyer name = getpropstring(node, "model");
187 1.2.2.2 bouyer
188 1.2.2.2 bouyer isconsole = fb_is_console(node);
189 1.2.2.2 bouyer if (isconsole && cgsix_use_rasterconsole) {
190 1.2.2.2 bouyer int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
191 1.2.2.2 bouyer if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
192 1.2.2.2 bouyer sa->sa_offset + CGSIX_RAM_OFFSET,
193 1.2.2.2 bouyer ramsize,
194 1.2.2.2 bouyer BUS_SPACE_MAP_LINEAR,
195 1.2.2.2 bouyer 0, &bh) != 0) {
196 1.2.2.2 bouyer printf("%s: cannot map pixels\n", self->dv_xname);
197 1.2.2.2 bouyer return;
198 1.2.2.2 bouyer }
199 1.2.2.2 bouyer sc->sc_fb.fb_pixels = (caddr_t)bh;
200 1.2.2.2 bouyer }
201 1.2.2.2 bouyer
202 1.2.2.2 bouyer cg6attach(sc, name, isconsole);
203 1.2.2.2 bouyer }
204