cgsix_obio.c revision 1.1 1 /* $NetBSD: cgsix_obio.c,v 1.1 1998/03/31 21:05:04 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 * color display (cgsix) driver; sun4 obio bus front-end.
41 */
42
43 #include "opt_uvm.h"
44
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/buf.h>
48 #include <sys/device.h>
49 #include <machine/fbio.h>
50 #include <sys/ioctl.h>
51 #include <sys/malloc.h>
52 #include <sys/mman.h>
53 #include <sys/tty.h>
54 #include <sys/conf.h>
55
56 #ifdef DEBUG
57 #include <sys/proc.h>
58 #include <sys/syslog.h>
59 #endif
60
61 #include <vm/vm.h>
62
63 #include <machine/bus.h>
64 #include <machine/autoconf.h>
65 #include <machine/pmap.h>
66 #include <machine/fbvar.h>
67 #include <machine/cpu.h>
68 #include <machine/eeprom.h>
69 #include <machine/conf.h>
70
71 #include <sparc/dev/btreg.h>
72 #include <sparc/dev/btvar.h>
73 #include <sparc/dev/sbusvar.h>
74 #include <sparc/dev/cgsixreg.h>
75 #include <sparc/dev/cgsixvar.h>
76 #include <sparc/dev/pfourreg.h>
77
78 /* autoconfiguration driver */
79 static int cgsixmatch __P((struct device *, struct cfdata *, void *));
80 static void cgsixattach __P((struct device *, struct device *, void *));
81 static int cg6_pfour_probe __P((void *, void *));
82
83 struct cfattach cgsix_obio_ca = {
84 sizeof(struct cgsix_softc), cgsixmatch, cgsixattach
85 };
86
87 /*
88 * Match a cgsix.
89 */
90 int
91 cgsixmatch(parent, cf, aux)
92 struct device *parent;
93 struct cfdata *cf;
94 void *aux;
95 {
96 union obio_attach_args *uoba = aux;
97 struct obio4_attach_args *oba;
98
99 if (uoba->uoba_isobio4 == 0)
100 return (0);
101
102 oba = &uoba->uoba_oba4;
103 return (bus_space_probe(oba->oba_bustag, 0,
104 oba->oba_paddr + CGSIX_FHC_OFFSET,
105 4, /* probe size */
106 0, /* offset */
107 0, /* flags */
108 cg6_pfour_probe, NULL));
109 }
110
111 int
112 cg6_pfour_probe(vaddr, arg)
113 void *vaddr;
114 void *arg;
115 {
116
117 return (fb_pfour_id(vaddr) == PFOUR_ID_FASTCOLOR);
118 }
119
120
121 /*
122 * Attach a display.
123 */
124 void
125 cgsixattach(parent, self, aux)
126 struct device *parent, *self;
127 void *aux;
128 {
129 struct cgsix_softc *sc = (struct cgsix_softc *)self;
130 union obio_attach_args *uoba = aux;
131 struct obio4_attach_args *oba;
132 struct eeprom *eep = (struct eeprom *)eeprom_va;
133 struct fbdevice *fb = &sc->sc_fb;
134 bus_space_handle_t bh;
135 int constype, isconsole;
136 char *name;
137 extern struct tty *fbconstty;
138
139 if (uoba->uoba_isobio4 == 0) {
140 (*cgsix_sbus_ca.ca_attach)(parent, self, aux);
141 return;
142 }
143
144 oba = &uoba->uoba_oba4;
145
146 /* Remember cookies for cgsix_mmap() */
147 sc->sc_bustag = oba->oba_bustag;
148 sc->sc_btype = (bus_type_t)0;
149 sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
150
151 fb->fb_device = &sc->sc_dev;
152 fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
153 fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
154 fb->fb_type.fb_depth = 8;
155
156 fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
157
158 /*
159 * Dunno what the PROM has mapped, though obviously it must have
160 * the video RAM mapped. Just map what we care about for ourselves
161 * (the FHC, THC, and Brooktree registers).
162 */
163 if (bus_space_map2(oba->oba_bustag, 0,
164 oba->oba_paddr + CGSIX_BT_OFFSET,
165 sizeof(*sc->sc_bt),
166 BUS_SPACE_MAP_LINEAR,
167 0, &bh) != 0) {
168 printf("%s: cannot map brooktree registers\n", self->dv_xname);
169 return;
170 }
171 sc->sc_bt = (struct bt_regs *)bh;
172
173 if (bus_space_map2(oba->oba_bustag, 0,
174 oba->oba_paddr + CGSIX_FHC_OFFSET,
175 sizeof(*sc->sc_fhc),
176 BUS_SPACE_MAP_LINEAR,
177 0, &bh) != 0) {
178 printf("%s: cannot map FHC registers\n", self->dv_xname);
179 return;
180 }
181 sc->sc_fhc = (int *)bh;
182
183 if (bus_space_map2(oba->oba_bustag, 0,
184 oba->oba_paddr + CGSIX_THC_OFFSET,
185 sizeof(*sc->sc_thc),
186 BUS_SPACE_MAP_LINEAR,
187 0, &bh) != 0) {
188 printf("%s: cannot map THC registers\n", self->dv_xname);
189 return;
190 }
191 sc->sc_thc = (struct cg6_thc *)bh;
192
193 if (bus_space_map2(oba->oba_bustag, 0,
194 oba->oba_paddr + CGSIX_TEC_OFFSET,
195 sizeof(*sc->sc_tec),
196 BUS_SPACE_MAP_LINEAR,
197 0, &bh) != 0) {
198 printf("%s: cannot map TEC registers\n", self->dv_xname);
199 return;
200 }
201 sc->sc_tec = (struct cg6_tec_xxx *)bh;
202
203
204 if (fb_pfour_id((void *)sc->sc_fhc) == PFOUR_ID_FASTCOLOR) {
205 fb->fb_flags |= FB_PFOUR;
206 name = "cgsix/p4";
207 } else
208 name = "cgsix";
209
210 constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_COLOR;
211
212 /*
213 * Assume this is the console if there's no eeprom info
214 * to be found.
215 */
216 if (eep == NULL || eep->eeConsole == constype)
217 isconsole = (fbconstty != NULL);
218 else
219 isconsole = 0;
220
221 if (isconsole && cgsix_use_rasterconsole) {
222 int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
223 if (bus_space_map2(oba->oba_bustag, 0,
224 oba->oba_paddr + CGSIX_RAM_OFFSET,
225 ramsize,
226 BUS_SPACE_MAP_LINEAR,
227 0, &bh) != 0) {
228 printf("%s: cannot map pixels\n", self->dv_xname);
229 return;
230 }
231 sc->sc_fb.fb_pixels = (caddr_t)bh;
232 }
233
234 cg6attach(sc, name, isconsole, 1);
235 }
236