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