xref: /netbsd-src/sys/dev/tc/px.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: px.c,v 1.1 1997/11/08 07:27:49 jonathan Exp $	*/
2 
3 /*
4  * Copyright (c) 1997 Jonathan Stone
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Jonathan Stone for
18  *      the NetBSD Project.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: px.c,v 1.1 1997/11/08 07:27:49 jonathan Exp $");
36 
37 /*
38  * px.c: placebo driver for the DEC TURBOchannel 2-d and 3-d
39  * accelerated framebuffers with PixelStamp blitter asics and i860
40  * accelerators.
41  */
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 
47 #include <dev/tc/tcvar.h>
48 #include <dev/tc/sticvar.h>
49 
50 #include <machine/autoconf.h>
51 #include <machine/cpu.h>
52 #include <machine/bus.h>
53 
54 /*
55  * hardware offsets  within PX board's TC slot.
56  */
57 #define PX_STIC_POLL_OFFSET	0x000000
58 #define PX_STAMP_OFFSET		0x0c0000	/* pixelstamp space on STIC */
59 #define PX_STIC_OFFSET		0x180000	/* STIC registers */
60 #define PX_VDAC_OFFSET		0x200000
61 #define PX_ROM_OFFSET		0x300000
62 
63 
64 struct px_softc {
65 	struct 	device sc_dv;		/* device information */
66 	tc_addr_t px_slotbase;		/* kva of slot base. */
67   	struct stic_softc px_stic;	/* address of pixelstamp and stic. */
68 };
69 
70 /*
71  * Local prototypes.
72  */
73 int	px_match __P((struct device *, struct cfdata *, void *));
74 void	px_attach __P((struct device *, struct device *, void *));
75 int	px_intr __P((void *xxx_sc));
76 void	px_vblank_ctl __P((struct px_softc *sc, int onoff));
77 void	px_blank __P((struct  px_softc *sc));
78 void	px_unblank __P((struct  px_softc *sc));
79 
80 struct cfattach px_ca = {
81 	sizeof (struct px_softc), px_match, px_attach,
82 };
83 
84 struct cfdriver px_cd = {
85 	NULL, "px", DV_DULL
86 };
87 
88 /*
89  * Match a PMAG-C pixelstamp board.
90  */
91 int
92 px_match(parent, match, aux)
93 	struct device *parent;
94 	struct cfdata *match;
95 	void *aux;
96 {
97 	struct tc_attach_args *ta = aux;
98 	void *pxaddr;
99 
100 	if (strncmp("PMAG-CA ", ta->ta_modname, TC_ROM_LLEN))
101 		return (0);
102 
103 	pxaddr = (void*)ta->ta_addr;
104 #if 0
105 	if (tc_badaddr(pxaddr + 0))
106 		return (0);
107 #endif
108 
109 	return (1);
110 }
111 
112 
113 /*
114  * Attach a PMAG-C pixelstamp graphics board.
115  */
116 void
117 px_attach(parent, self, aux)
118 	struct device *parent, *self;
119 	void *aux;
120 {
121 	struct px_softc *sc  = (struct px_softc*)self;
122 	struct tc_attach_args *ta = aux;
123 
124 	sc->px_slotbase = TC_PHYS_TO_UNCACHED(ta->ta_addr);
125 	sc->px_stic.stic_pktbuf=
126 	     (void*)(sc->px_slotbase + PX_STIC_POLL_OFFSET);
127 	sc->px_stic.stic_addr = (void*)(sc->px_slotbase + PX_STIC_OFFSET);
128 	sc->px_stic.stamp_addr = (void*)(sc->px_slotbase + PX_STAMP_OFFSET);
129 	sc->px_stic.vdac_addr = (void*)(sc->px_slotbase + PX_VDAC_OFFSET);
130 
131 
132 	/* Turn off vertical-blank interrupts, unless we're debugging. */
133 #if !defined(DIAGNOSTIC) && !defined(DEBUG)
134 	px_vblank_ctl(sc, 0);
135 #endif
136 
137 	tc_intr_establish(parent, ta->ta_cookie, TC_IPL_NONE, px_intr, sc);
138 
139 	/* driver does nothing yet, except silently dismisses interrupts. */
140 	printf(": no raster-console or X11 support.\n");
141 
142 }
143 
144 /*
145  * pixelstamp board interrupt hanlder.
146  * XXX examine pixelstamp blitter-chip packet area, and
147  * send new packets.
148  *
149  * For now, we ignore interrupts from the blitter chip or i860,
150  * and just handle vertical-retrace interrupt.
151  */
152 int
153 px_intr(xxx_sc)
154     void *xxx_sc;
155 {
156 	struct px_softc *sc = (struct px_softc *)xxx_sc;
157 
158 	volatile struct stic_regs * stic =
159 	   STICADDR(sc->px_stic.stic_addr);
160 
161 	register int intr_status = stic->ipdvint;
162 
163 	/* Clear packet-done intr so we don't interrupt again. */
164 	/* Packet interrupt? */
165 	if (intr_status & STIC_INT_P) {
166 
167 		/*
168 		 * Clear *only* packet done interrupt
169 		 */
170 		stic->ipdvint = (stic->ipdvint | STIC_INT_P_WE) &
171 		     ~(STIC_INT_E_WE | STIC_INT_V_WE | STIC_INT_P);
172 		tc_wmb();
173 
174 	}
175 	/* Vertical-retrace interrupt ? */
176 	else if (intr_status & STIC_INT_V) {
177 
178 		stic->ipdvint = (stic->ipdvint | STIC_INT_V_WE) &
179 			~(STIC_INT_E_WE | STIC_INT_P_WE | STIC_INT_V);
180 		tc_wmb();
181 
182 #ifdef notyet
183 		/* Poll for LK-201 LED status, update LEDs */
184 		lk201_led(unit);
185 #endif
186 
187 	/* Error, stray interrupt ?*/
188 	} else if (intr_status & STIC_INT_E) {
189 #if defined(DIAGNOSTIC) || 1
190 		 /* XXX not for me */
191 		printf("px_intr: stray intr INT_E, %x %x %x %x %x",
192 		       intr_status,
193 		       stic->sticsr, stic->buscsr,
194 		       stic->busadr, stic->busdat);
195 		DELAY(1000000);
196 		/*panic("px_intr: no intr condition\n");*/
197 #endif
198 	} else {
199 #if defined(DIAGNOSTIC) || 1
200 		DELAY(1000000);
201 		 /* XXX not for me */
202 		printf("px_intr:, no intr? %x %x %x %x %x",
203 		       intr_status,
204 		       stic->sticsr, stic->buscsr,
205 		       stic->busadr, stic->busdat);
206 		 DELAY(100000);
207 		/*panic("px_intr: no intr condition\n");*/
208 #endif
209 	}
210 
211 	return(0); /* XXX forme */
212 }
213 
214 
215 /*
216  * Turn vertical retrace interrupt on or off
217  */
218 void
219 px_vblank_ctl(sc, switch_on)
220 	struct px_softc	*sc;
221 	int	switch_on;
222 
223 {
224 	register volatile struct stic_regs *stic =
225 	    STICADDR(sc->px_stic.stic_addr);
226 
227 	stic->ipdvint = (switch_on) ?
228 		STIC_INT_V_WE | STIC_INT_V_EN :
229 		STIC_INT_V_WE;
230 
231 	tc_wmb();
232 }
233 
234 void
235 px_blank(sc)
236 	struct  px_softc *sc;
237 {
238 
239 }
240 
241 
242 void
243 px_unblank(sc)
244 	struct  px_softc *sc;
245 {
246 }
247