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