xref: /original-bsd/sys/sparc/sbus/bwtwo.c (revision 4463b7c2)
1 /*
2  * Copyright (c) 1992 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This software was developed by the Computer Systems Engineering group
6  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
7  * contributed to Berkeley.
8  *
9  * All advertising materials mentioning features or use of this software
10  * must display the following acknowledgement:
11  *	This product includes software developed by the University of
12  *	California, Lawrence Berkeley Laboratories.
13  *
14  * %sccs.include.redist.c%
15  *
16  *	@(#)bwtwo.c	7.2 (Berkeley) 07/21/92
17  *
18  * from: $Header: bwtwo.c,v 1.13 92/06/17 06:59:29 torek Exp $
19  */
20 
21 /*
22  * black&white display (bwtwo) driver.
23  *
24  * Does not handle interrupts, even though they can occur.
25  */
26 
27 #include "bwtwo.h"
28 
29 #include "sys/param.h"
30 #include "sys/device.h"
31 #include "sys/fbio.h"
32 #include "sys/ioctl.h"
33 #include "sys/malloc.h"
34 #include "sys/mman.h"
35 #include "sys/tty.h"
36 
37 #include "machine/autoconf.h"
38 #include "machine/pmap.h"
39 #include "machine/fbvar.h"
40 
41 #include "bwtworeg.h"
42 #include "sbusvar.h"
43 
44 /* per-display variables */
45 struct bwtwo_softc {
46 	struct	device sc_dev;		/* base device */
47 	struct	sbusdev sc_sd;		/* sbus device */
48 	struct	fbdevice sc_fb;		/* frame buffer device */
49 	volatile struct bwtworeg *sc_reg;/* control registers */
50 	caddr_t	sc_phys;		/* display RAM (phys addr) */
51 };
52 
53 /* autoconfiguration driver */
54 static void	bwtwoattach(struct device *, struct device *, void *);
55 struct cfdriver bwtwocd =
56     { NULL, "bwtwo", matchbyname, bwtwoattach,
57       DV_DULL, sizeof(struct bwtwo_softc) };
58 
59 /* XXX we do not handle frame buffer interrupts (do not know how) */
60 
61 /* frame buffer generic driver */
62 static void	bwtwounblank(struct device *);
63 static struct fbdriver bwtwofbdriver = { bwtwounblank };
64 
65 extern int fbnode;
66 extern struct tty *fbconstty;
67 extern int (*v_putc)();
68 extern int nullop();
69 static int bwtwo_cnputc();
70 static struct bwtwo_softc *bwcons;
71 
72 #define	BWTWO_MAJOR	27		/* XXX */
73 
74 /*
75  * Attach a display.  We need to notice if it is the console, too.
76  */
77 void
78 bwtwoattach(parent, self, args)
79 	struct device *parent, *self;
80 	void *args;
81 {
82 	register struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
83 	register struct sbus_attach_args *sa = args;
84 	register int node = sa->sa_ra.ra_node, ramsize;
85 	register struct bwtwo_all *p;
86 	int isconsole;
87 
88 	sc->sc_fb.fb_major = BWTWO_MAJOR;	/* XXX to be removed */
89 
90 	sc->sc_fb.fb_driver = &bwtwofbdriver;
91 	sc->sc_fb.fb_device = &sc->sc_dev;
92 	/*
93 	 * The defaults below match my screen, but are not guaranteed
94 	 * to be correct as defaults go...
95 	 */
96 	sc->sc_fb.fb_type.fb_type = FBTYPE_SUN2BW;
97 	sc->sc_fb.fb_type.fb_width = getpropint(node, "width", 1152);
98 	sc->sc_fb.fb_type.fb_height = getpropint(node, "height", 900);
99 	sc->sc_fb.fb_linebytes = getpropint(node, "linebytes", 144);
100 	ramsize = sc->sc_fb.fb_type.fb_height * sc->sc_fb.fb_linebytes;
101 	sc->sc_fb.fb_type.fb_depth = 1;
102 	sc->sc_fb.fb_type.fb_cmsize = 0;
103 	sc->sc_fb.fb_type.fb_size = ramsize;
104 	printf(": %s, %d x %d", getpropstring(node, "model"),
105 	    sc->sc_fb.fb_type.fb_width, sc->sc_fb.fb_type.fb_height);
106 
107 	/*
108 	 * When the ROM has mapped in a bwtwo display, the address
109 	 * maps only the video RAM, so in any case we have to map the
110 	 * registers ourselves.  We only need the video RAM if we are
111 	 * going to print characters via rconsole.
112 	 */
113 	isconsole = node == fbnode && fbconstty != NULL;
114 	p = (struct bwtwo_all *)sa->sa_ra.ra_paddr;
115 	if ((sc->sc_fb.fb_pixels = sa->sa_ra.ra_vaddr) == NULL && isconsole) {
116 		/* this probably cannot happen, but what the heck */
117 		sc->sc_fb.fb_pixels = mapiodev(p->ba_ram, ramsize);
118 	}
119 	sc->sc_reg = (volatile struct bwtworeg *)
120 	    mapiodev((caddr_t)&p->ba_reg, sizeof(p->ba_reg));
121 	sc->sc_phys = p->ba_ram;
122 
123 	/* Insure video is enabled */
124 	sc->sc_reg->bw_ctl |= CTL_VE;
125 
126 	if (isconsole) {
127 		printf(" (console)\n");
128 #ifdef RCONSOLE
129 		rcons_init(&sc->sc_fb);
130 #endif
131 	} else
132 		printf("\n");
133 	sbus_establish(&sc->sc_sd, &sc->sc_dev);
134 	if (node == fbnode)
135 		fb_attach(&sc->sc_fb);
136 }
137 
138 int
139 bwtwoopen(dev, flags, mode, p)
140 	dev_t dev;
141 	int flags, mode;
142 	struct proc *p;
143 {
144 	int unit = minor(dev);
145 
146 	if (unit >= bwtwocd.cd_ndevs || bwtwocd.cd_devs[unit] == NULL)
147 		return (ENXIO);
148 	return (0);
149 }
150 
151 int
152 bwtwoclose(dev, flags, mode, p)
153 	dev_t dev;
154 	int flags, mode;
155 	struct proc *p;
156 {
157 
158 	return (0);
159 }
160 
161 int
162 bwtwoioctl(dev, cmd, data, flags, p)
163 	dev_t dev;
164 	int cmd;
165 	caddr_t data;
166 	int flags;
167 	struct proc *p;
168 {
169 	struct bwtwo_softc *sc = bwtwocd.cd_devs[minor(dev)];
170 
171 	switch (cmd) {
172 
173 	case FBIOGTYPE:
174 		*(struct fbtype *)data = sc->sc_fb.fb_type;
175 		break;
176 
177 	case FBIOGVIDEO:
178 		*(int *)data = (sc->sc_reg->bw_ctl & CTL_VE) != 0;
179 		break;
180 
181 	case FBIOSVIDEO:
182 		if (*(int *)data)
183 			sc->sc_reg->bw_ctl |= CTL_VE;
184 		else
185 			sc->sc_reg->bw_ctl &= ~CTL_VE;
186 		break;
187 
188 	default:
189 		return (ENOTTY);
190 	}
191 	return (0);
192 }
193 
194 static void
195 bwtwounblank(dev)
196 	struct device *dev;
197 {
198 	struct bwtwo_softc *sc = (struct bwtwo_softc *)dev;
199 
200 	sc->sc_reg->bw_ctl |= CTL_VE;
201 }
202 
203 /*
204  * Return the address that would map the given device at the given
205  * offset, allowing for the given protection, or return -1 for error.
206  */
207 int
208 bwtwomap(dev, off, prot)
209 	dev_t dev;
210 	int off, prot;
211 {
212 	register struct bwtwo_softc *sc = bwtwocd.cd_devs[minor(dev)];
213 
214 	if (off & PGOFSET)
215 		panic("bwtwomap");
216 	if ((unsigned)off >= sc->sc_fb.fb_type.fb_size)
217 		return (-1);
218 	/*
219 	 * I turned on PMAP_NC here to disable the cache as I was
220 	 * getting horribly broken behaviour with it on.
221 	 */
222 	return ((int)sc->sc_phys + off + PMAP_OBIO + PMAP_NC);
223 }
224