bwtwo_sbus.c revision 1.5
1/*	$NetBSD: bwtwo_sbus.c,v 1.5 2001/11/13 06:58:17 lukem 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.
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. All advertising materials mentioning features or use of this software
61 *    must display the following acknowledgement:
62 *	This product includes software developed by the University of
63 *	California, Berkeley and its contributors.
64 * 4. Neither the name of the University nor the names of its contributors
65 *    may be used to endorse or promote products derived from this software
66 *    without specific prior written permission.
67 *
68 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
69 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
72 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 * SUCH DAMAGE.
79 *
80 *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
81 */
82
83/*
84 * black&white display (bwtwo) driver.
85 *
86 * Does not handle interrupts, even though they can occur.
87 *
88 * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.ORG>.
89 * Overlay plane handling hints and ideas provided by Brad Spencer.
90 */
91
92#include <sys/cdefs.h>
93__KERNEL_RCSID(0, "$NetBSD: bwtwo_sbus.c,v 1.5 2001/11/13 06:58:17 lukem Exp $");
94
95#include <sys/param.h>
96#include <sys/systm.h>
97#include <sys/device.h>
98#include <sys/ioctl.h>
99#include <sys/malloc.h>
100#include <sys/mman.h>
101#include <sys/tty.h>
102#include <sys/conf.h>
103
104#include <machine/autoconf.h>
105#include <machine/eeprom.h>
106#include <machine/conf.h>
107
108#include <dev/sbus/sbusvar.h>
109
110#include <dev/sun/fbio.h>
111#include <dev/sun/fbvar.h>
112#include <dev/sun/btreg.h>
113#include <dev/sun/bwtworeg.h>
114#include <dev/sun/bwtwovar.h>
115#include <dev/sun/pfourreg.h>
116
117/* autoconfiguration driver */
118static void	bwtwoattach_sbus (struct device *, struct device *, void *);
119static int	bwtwomatch_sbus (struct device *, struct cfdata *, void *);
120
121/* Allocate an `sbusdev' in addition to the bwtwo softc */
122struct bwtwo_sbus_softc {
123	struct bwtwo_softc bss_softc;
124	struct sbusdev bss_sd;
125};
126
127struct cfattach bwtwo_sbus_ca = {
128	sizeof(struct bwtwo_sbus_softc), bwtwomatch_sbus, bwtwoattach_sbus
129};
130
131static int	bwtwo_get_video (struct bwtwo_softc *);
132static void	bwtwo_set_video (struct bwtwo_softc *, int);
133
134/*
135 * Match a bwtwo.
136 */
137static int
138bwtwomatch_sbus(parent, cf, aux)
139	struct device *parent;
140	struct cfdata *cf;
141	void *aux;
142{
143	struct sbus_attach_args *sa = aux;
144
145	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
146}
147
148
149/*
150 * Attach a display.  We need to notice if it is the console, too.
151 */
152void
153bwtwoattach_sbus(parent, self, args)
154	struct device *parent, *self;
155	void *args;
156{
157	struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
158	struct sbusdev *sd = &((struct bwtwo_sbus_softc *)self)->bss_sd;
159	struct sbus_attach_args *sa = args;
160	struct fbdevice *fb = &sc->sc_fb;
161	bus_space_handle_t bh;
162	int isconsole, node;
163	char *name;
164
165	node = sa->sa_node;
166
167	/* Remember cookies for bwtwo_mmap() */
168	sc->sc_bustag = sa->sa_bustag;
169	sc->sc_btype = (bus_type_t)sa->sa_slot; /* Should be deprecated */
170	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
171
172	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
173	fb->fb_type.fb_depth = 1;
174	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
175
176	/*
177	 * When the ROM has mapped in a bwtwo display, the address
178	 * maps only the video RAM, hence we always map the control
179	 * registers ourselves.  We only need the video RAM if we are
180	 * going to print characters via rconsole.
181	 */
182	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
183			 sa->sa_offset + BWREG_REG,
184			 sizeof(struct fbcontrol),
185			 BUS_SPACE_MAP_LINEAR,
186			 0, &bh) != 0) {
187		printf("%s: cannot map control registers\n", self->dv_xname);
188		return;
189	}
190	sc->sc_reg = (struct fbcontrol *)bh;
191	fb->fb_pfour = NULL;
192
193	sc->sc_pixeloffset = BWREG_MEM;
194
195	isconsole = fb_is_console(node);
196	name = PROM_getpropstring(node, "model");
197
198	/* Assume `bwtwo at sbus' only happens at sun4c's */
199	sc->sc_get_video = bwtwo_get_video;
200	sc->sc_set_video = bwtwo_set_video;
201
202	if (sa->sa_npromvaddrs != 0)
203		sc->sc_fb.fb_pixels = (caddr_t)(u_long)sa->sa_promvaddrs[0];
204	if (isconsole && sc->sc_fb.fb_pixels == NULL) {
205		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
206		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
207				 sa->sa_offset + sc->sc_pixeloffset,
208				 ramsize,
209				 BUS_SPACE_MAP_LINEAR,
210				 0, &bh) != 0) {
211			printf("%s: cannot map pixels\n", self->dv_xname);
212			return;
213		}
214		sc->sc_fb.fb_pixels = (char *)bh;
215	}
216
217	sbus_establish(sd, &sc->sc_dev);
218	bwtwoattach(sc, name, isconsole);
219}
220
221static void
222bwtwo_set_video(sc, enable)
223	struct bwtwo_softc *sc;
224	int enable;
225{
226
227	if (enable)
228		/*
229		 * If the we're the console the PROM will have taken care
230		 * of the FBC_TIMING bit and video control parameters. We
231		 * simply turn on FBC_TIMING; in case other video parameters
232		 * are necessary, here is a set read from an ELC:
233		 * [0xbb,0x2b,0x4,0x14,0xae,0x3,0xa8,0x24,0x1,0x5,0xff,0x1]
234		 */
235		sc->sc_reg->fbc_ctrl |= FBC_VENAB | FBC_TIMING;
236	else
237		sc->sc_reg->fbc_ctrl &= ~FBC_VENAB;
238}
239
240static int
241bwtwo_get_video(sc)
242	struct bwtwo_softc *sc;
243{
244
245	return ((sc->sc_reg->fbc_ctrl & FBC_VENAB) != 0);
246}
247