xref: /netbsd-src/sys/arch/sun2/dev/bwtwo_any.c (revision 23c8222edbfb0f0932d88a8351d3a0cf817dfb9e)
1 /*	$NetBSD: bwtwo_any.c,v 1.11 2003/12/04 12:42:54 keihan Exp $ */
2 
3 /*-
4  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe and Matthew Fredette.
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  * Copyright (c) 1992, 1993
41  *	The Regents of the University of California.  All rights reserved.
42  *
43  * This software was developed by the Computer Systems Engineering group
44  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
45  * contributed to Berkeley.
46  *
47  * All advertising materials mentioning features or use of this software
48  * must display the following acknowledgement:
49  *	This product includes software developed by the University of
50  *	California, Lawrence Berkeley Laboratory.
51  *
52  * Redistribution and use in source and binary forms, with or without
53  * modification, are permitted provided that the following conditions
54  * are met:
55  * 1. Redistributions of source code must retain the above copyright
56  *    notice, this list of conditions and the following disclaimer.
57  * 2. Redistributions in binary form must reproduce the above copyright
58  *    notice, this list of conditions and the following disclaimer in the
59  *    documentation and/or other materials provided with the distribution.
60  * 3. Neither the name of the University nor the names of its contributors
61  *    may be used to endorse or promote products derived from this software
62  *    without specific prior written permission.
63  *
64  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74  * SUCH DAMAGE.
75  *
76  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
77  */
78 
79 /*
80  * black&white display (bwtwo) driver.
81  *
82  * Does not handle interrupts, even though they can occur.
83  *
84  * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.org>.
85  * Overlay plane handling hints and ideas provided by Brad Spencer.
86  */
87 
88 #include <sys/cdefs.h>
89 __KERNEL_RCSID(0, "$NetBSD: bwtwo_any.c,v 1.11 2003/12/04 12:42:54 keihan Exp $");
90 
91 #include <sys/param.h>
92 #include <sys/systm.h>
93 #include <sys/device.h>
94 #include <sys/ioctl.h>
95 #include <sys/malloc.h>
96 #include <sys/mman.h>
97 #include <sys/tty.h>
98 #include <sys/conf.h>
99 
100 #include <machine/autoconf.h>
101 #include <sun2/sun2/control.h>
102 
103 #include <dev/sun/fbio.h>
104 #include <dev/sun/fbvar.h>
105 #include <dev/sun/btreg.h>
106 #include <sun2/dev/bwtworeg.h>
107 #include <dev/sun/bwtwovar.h>
108 
109 /* autoconfiguration driver */
110 static void	bwtwoattach_any (struct device *, struct device *, void *);
111 static int	bwtwomatch_any (struct device *, struct cfdata *, void *);
112 
113 struct bwtwosun2_softc {
114 	struct bwtwo_softc sc;
115 	bus_space_handle_t bh;
116 };
117 
118 CFATTACH_DECL(bwtwo_obio, sizeof(struct bwtwosun2_softc),
119     bwtwomatch_any, bwtwoattach_any, NULL, NULL);
120 
121 CFATTACH_DECL(bwtwo_obmem, sizeof(struct bwtwosun2_softc),
122     bwtwomatch_any, bwtwoattach_any, NULL, NULL);
123 
124 static int	bwtwo_get_video_sun2 __P((struct bwtwo_softc *));
125 static void	bwtwo_set_video_sun2 __P((struct bwtwo_softc *, int));
126 
127 extern int fbnode;
128 
129 static int
130 bwtwomatch_any(parent, cf, aux)
131 	struct device *parent;
132 	struct cfdata *cf;
133 	void *aux;
134 {
135 	struct mainbus_attach_args *ma = aux;
136 	bus_space_handle_t bh;
137 	int matched;
138 
139 	/* Make sure there is something there... */
140 	if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, sizeof(struct bwtworeg),
141 			  0, &bh))
142 		return (0);
143 	matched = (bus_space_peek_1(ma->ma_bustag, bh, 0, NULL) == 0);
144 	bus_space_unmap(ma->ma_bustag, bh, sizeof(struct bwtworeg));
145 	return (matched);
146 }
147 
148 static void
149 bwtwoattach_any(parent, self, aux)
150 	struct device *parent, *self;
151 	void *aux;
152 {
153 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)self;
154 	struct bwtwo_softc *sc = &scsun2->sc;
155 	struct mainbus_attach_args *ma = aux;
156 	struct fbdevice *fb = &sc->sc_fb;
157 	bus_space_handle_t bh;
158 	int isconsole;
159 	char *name;
160 
161 	/* Remember cookies for bwtwo_mmap() */
162 	sc->sc_bustag = ma->ma_bustag;
163 	sc->sc_paddr = ma->ma_paddr;
164 
165 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
166 	fb->fb_type.fb_depth = 1;
167 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
168 
169 	isconsole = fb_is_console(0);
170 
171 	/* A plain bwtwo */
172 	sc->sc_reg = NULL;
173 	fb->fb_pfour = NULL;
174 	name = "bwtwo";
175 	sc->sc_pixeloffset = BWREG_MEM;
176 	sc->sc_get_video = bwtwo_get_video_sun2;
177 	sc->sc_set_video = bwtwo_set_video_sun2;
178 
179 	/* Map the registers. */
180 	if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, sizeof(struct bwtworeg),
181 	    		  0, &scsun2->bh)) {
182 		printf("%s: cannot map regs\n", self->dv_xname);
183 		return;
184 	}
185 
186 	if (isconsole) {
187 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
188 		if (bus_space_map(ma->ma_bustag, ma->ma_paddr + sc->sc_pixeloffset,
189 				  ramsize,
190 				  BUS_SPACE_MAP_LINEAR, &bh) != 0) {
191 			printf("%s: cannot map pixels\n", self->dv_xname);
192 			return;
193 		}
194 		sc->sc_fb.fb_pixels = (char *)bh;
195 	}
196 
197 	bwtwoattach(sc, name, isconsole);
198 }
199 
200 static void
201 bwtwo_set_video_sun2(sc, enable)
202 	struct bwtwo_softc *sc;
203 	int enable;
204 {
205 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
206 	unsigned char cr;
207 
208 	cr = bus_space_read_1(sc->sc_bustag, scsun2->bh, 0);
209 	bus_space_write_1(sc->sc_bustag, scsun2->bh, 0, (enable ?
210 							 (cr | BW2_CR_ENABLE_VIDEO) :
211 	    						 (cr & ~BW2_CR_ENABLE_VIDEO)));
212 	return;
213 }
214 
215 static int
216 bwtwo_get_video_sun2(sc)
217 	struct bwtwo_softc *sc;
218 {
219 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
220 
221 	return ((bus_space_read_1(sc->sc_bustag, scsun2->bh, 0) & BW2_CR_ENABLE_VIDEO) != 0);
222 }
223