tvrx.c revision 1.1.2.3 1 1.1.2.3 bouyer /* $NetBSD: tvrx.c,v 1.1.2.3 2011/02/17 11:59:39 bouyer Exp $ */
2 1.1.2.2 bouyer /* $OpenBSD: tvrx.c,v 1.1 2006/04/14 21:05:43 miod Exp $ */
3 1.1.2.2 bouyer
4 1.1.2.2 bouyer /*
5 1.1.2.2 bouyer * Copyright (c) 2006, Miodrag Vallat.
6 1.1.2.2 bouyer * All rights reserved.
7 1.1.2.2 bouyer *
8 1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
9 1.1.2.2 bouyer * modification, are permitted provided that the following conditions
10 1.1.2.2 bouyer * are met:
11 1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
15 1.1.2.2 bouyer * documentation and/or other materials provided with the distribution.
16 1.1.2.2 bouyer *
17 1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 1.1.2.2 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 1.1.2.2 bouyer * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 1.1.2.2 bouyer * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
21 1.1.2.2 bouyer * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 1.1.2.2 bouyer * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 1.1.2.2 bouyer * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 1.1.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 1.1.2.2 bouyer * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
28 1.1.2.2 bouyer *
29 1.1.2.2 bouyer */
30 1.1.2.2 bouyer
31 1.1.2.2 bouyer /*
32 1.1.2.2 bouyer * Graphics routines for the TurboVRX frame buffer
33 1.1.2.2 bouyer */
34 1.1.2.2 bouyer
35 1.1.2.2 bouyer #include <sys/param.h>
36 1.1.2.2 bouyer #include <sys/systm.h>
37 1.1.2.2 bouyer #include <sys/conf.h>
38 1.1.2.2 bouyer #include <sys/device.h>
39 1.1.2.2 bouyer #include <sys/proc.h>
40 1.1.2.2 bouyer #include <sys/ioctl.h>
41 1.1.2.2 bouyer #include <sys/bus.h>
42 1.1.2.2 bouyer #include <sys/cpu.h>
43 1.1.2.2 bouyer
44 1.1.2.2 bouyer #include <machine/autoconf.h>
45 1.1.2.2 bouyer
46 1.1.2.2 bouyer #include <hp300/dev/dioreg.h>
47 1.1.2.2 bouyer #include <hp300/dev/diovar.h>
48 1.1.2.2 bouyer #include <hp300/dev/diodevs.h>
49 1.1.2.2 bouyer
50 1.1.2.2 bouyer #include <dev/cons.h>
51 1.1.2.2 bouyer
52 1.1.2.2 bouyer #include <dev/wscons/wsconsio.h>
53 1.1.2.2 bouyer #include <dev/wscons/wsdisplayvar.h>
54 1.1.2.2 bouyer #include <dev/rasops/rasops.h>
55 1.1.2.2 bouyer
56 1.1.2.2 bouyer #include <hp300/dev/diofbreg.h>
57 1.1.2.2 bouyer #include <hp300/dev/diofbvar.h>
58 1.1.2.2 bouyer
59 1.1.2.2 bouyer struct tvrx_softc {
60 1.1.2.2 bouyer device_t sc_dev;
61 1.1.2.2 bouyer struct diofb *sc_fb;
62 1.1.2.2 bouyer struct diofb sc_fb_store;
63 1.1.2.2 bouyer int sc_scode;
64 1.1.2.2 bouyer };
65 1.1.2.2 bouyer
66 1.1.2.3 bouyer static int tvrx_match(device_t, cfdata_t, void *);
67 1.1.2.3 bouyer static void tvrx_attach(device_t, device_t, void *);
68 1.1.2.2 bouyer
69 1.1.2.2 bouyer CFATTACH_DECL_NEW(tvrx, sizeof(struct tvrx_softc),
70 1.1.2.2 bouyer tvrx_match, tvrx_attach, NULL, NULL);
71 1.1.2.2 bouyer
72 1.1.2.3 bouyer static int tvrx_reset(struct diofb *, int, struct diofbreg *);
73 1.1.2.2 bouyer
74 1.1.2.3 bouyer static int tvrx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
75 1.1.2.2 bouyer
76 1.1.2.3 bouyer static struct wsdisplay_accessops tvrx_accessops = {
77 1.1.2.2 bouyer tvrx_ioctl,
78 1.1.2.2 bouyer diofb_mmap,
79 1.1.2.2 bouyer diofb_alloc_screen,
80 1.1.2.2 bouyer diofb_free_screen,
81 1.1.2.2 bouyer diofb_show_screen,
82 1.1.2.2 bouyer NULL, /* load_font */
83 1.1.2.2 bouyer };
84 1.1.2.2 bouyer
85 1.1.2.2 bouyer /*
86 1.1.2.2 bouyer * Attachment glue
87 1.1.2.2 bouyer */
88 1.1.2.2 bouyer
89 1.1.2.2 bouyer int
90 1.1.2.2 bouyer tvrx_match(device_t parent, cfdata_t cf, void *aux)
91 1.1.2.2 bouyer {
92 1.1.2.2 bouyer struct dio_attach_args *da = aux;
93 1.1.2.2 bouyer
94 1.1.2.2 bouyer if (da->da_id != DIO_DEVICE_ID_FRAMEBUFFER ||
95 1.1.2.2 bouyer da->da_secid != DIO_DEVICE_SECID_TIGERSHARK)
96 1.1.2.3 bouyer return 0;
97 1.1.2.2 bouyer
98 1.1.2.3 bouyer return 1;
99 1.1.2.2 bouyer }
100 1.1.2.2 bouyer
101 1.1.2.2 bouyer void
102 1.1.2.2 bouyer tvrx_attach(device_t parent, device_t self, void *aux)
103 1.1.2.2 bouyer {
104 1.1.2.2 bouyer struct tvrx_softc *sc = device_private(self);
105 1.1.2.2 bouyer struct dio_attach_args *da = aux;
106 1.1.2.2 bouyer bus_space_handle_t bsh;
107 1.1.2.2 bouyer struct diofbreg *fbr;
108 1.1.2.2 bouyer
109 1.1.2.2 bouyer sc->sc_dev = self;
110 1.1.2.2 bouyer sc->sc_scode = da->da_scode;
111 1.1.2.2 bouyer if (sc->sc_scode == conscode) {
112 1.1.2.2 bouyer fbr = (struct diofbreg *)conaddr; /* already mapped */
113 1.1.2.2 bouyer sc->sc_fb = &diofb_cn;
114 1.1.2.2 bouyer } else {
115 1.1.2.2 bouyer sc->sc_fb = &sc->sc_fb_store;
116 1.1.2.2 bouyer if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
117 1.1.2.2 bouyer &bsh)) {
118 1.1.2.2 bouyer aprint_error(": can't map framebuffer\n");
119 1.1.2.2 bouyer return;
120 1.1.2.2 bouyer }
121 1.1.2.2 bouyer fbr = bus_space_vaddr(da->da_bst, bsh);
122 1.1.2.2 bouyer if (tvrx_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
123 1.1.2.2 bouyer printf(": can't map framebuffer\n");
124 1.1.2.2 bouyer return;
125 1.1.2.2 bouyer }
126 1.1.2.2 bouyer }
127 1.1.2.2 bouyer
128 1.1.2.2 bouyer diofb_end_attach(self, &tvrx_accessops, sc->sc_fb,
129 1.1.2.2 bouyer sc->sc_scode == conscode, NULL);
130 1.1.2.2 bouyer }
131 1.1.2.2 bouyer
132 1.1.2.2 bouyer /*
133 1.1.2.2 bouyer * Initialize hardware and display routines.
134 1.1.2.2 bouyer */
135 1.1.2.2 bouyer int
136 1.1.2.2 bouyer tvrx_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
137 1.1.2.2 bouyer {
138 1.1.2.2 bouyer int rc;
139 1.1.2.2 bouyer
140 1.1.2.2 bouyer if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
141 1.1.2.3 bouyer return rc;
142 1.1.2.2 bouyer
143 1.1.2.2 bouyer /*
144 1.1.2.2 bouyer * We rely on the PROM to initialize the frame buffer in the mode
145 1.1.2.2 bouyer * we expect it: cleared, overlay plane enabled and accessible
146 1.1.2.2 bouyer * at the beginning of the video memory.
147 1.1.2.2 bouyer *
148 1.1.2.2 bouyer * This is NOT the mode we would end up by simply resetting the
149 1.1.2.2 bouyer * board.
150 1.1.2.2 bouyer */
151 1.1.2.2 bouyer
152 1.1.2.2 bouyer fb->ri.ri_depth = 1;
153 1.1.2.2 bouyer fb->bmv = diofb_mono_windowmove;
154 1.1.2.2 bouyer diofb_fbsetup(fb);
155 1.1.2.2 bouyer
156 1.1.2.3 bouyer return 0;
157 1.1.2.2 bouyer }
158 1.1.2.2 bouyer
159 1.1.2.2 bouyer int
160 1.1.2.2 bouyer tvrx_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
161 1.1.2.2 bouyer {
162 1.1.2.2 bouyer struct diofb *fb = v;
163 1.1.2.2 bouyer struct wsdisplay_fbinfo *wdf;
164 1.1.2.2 bouyer
165 1.1.2.2 bouyer switch (cmd) {
166 1.1.2.2 bouyer case WSDISPLAYIO_GTYPE:
167 1.1.2.2 bouyer *(u_int *)data = WSDISPLAY_TYPE_TVRX;
168 1.1.2.2 bouyer return 0;
169 1.1.2.2 bouyer case WSDISPLAYIO_SMODE:
170 1.1.2.2 bouyer fb->mapmode = *(u_int *)data;
171 1.1.2.2 bouyer return 0;
172 1.1.2.2 bouyer case WSDISPLAYIO_GINFO:
173 1.1.2.2 bouyer wdf = (void *)data;
174 1.1.2.2 bouyer wdf->width = fb->ri.ri_width;
175 1.1.2.2 bouyer wdf->height = fb->ri.ri_height;
176 1.1.2.2 bouyer wdf->depth = fb->ri.ri_depth;
177 1.1.2.2 bouyer wdf->cmsize = 0;
178 1.1.2.2 bouyer return 0;
179 1.1.2.2 bouyer case WSDISPLAYIO_LINEBYTES:
180 1.1.2.2 bouyer *(u_int *)data = fb->ri.ri_stride;
181 1.1.2.2 bouyer return 0;
182 1.1.2.2 bouyer case WSDISPLAYIO_GETCMAP:
183 1.1.2.2 bouyer case WSDISPLAYIO_PUTCMAP:
184 1.1.2.2 bouyer /* until color support is implemented */
185 1.1.2.2 bouyer return EPASSTHROUGH;
186 1.1.2.2 bouyer case WSDISPLAYIO_GVIDEO:
187 1.1.2.2 bouyer case WSDISPLAYIO_SVIDEO:
188 1.1.2.2 bouyer /* unsupported */
189 1.1.2.2 bouyer return EPASSTHROUGH;
190 1.1.2.2 bouyer }
191 1.1.2.2 bouyer
192 1.1.2.2 bouyer return EPASSTHROUGH;
193 1.1.2.2 bouyer }
194 1.1.2.2 bouyer
195 1.1.2.2 bouyer /*
196 1.1.2.2 bouyer * Console support
197 1.1.2.2 bouyer */
198 1.1.2.2 bouyer
199 1.1.2.2 bouyer int
200 1.1.2.2 bouyer tvrxcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
201 1.1.2.2 bouyer {
202 1.1.2.2 bouyer bus_space_handle_t bsh;
203 1.1.2.2 bouyer void *va;
204 1.1.2.2 bouyer struct diofbreg *fbr;
205 1.1.2.2 bouyer struct diofb *fb = &diofb_cn;
206 1.1.2.2 bouyer int size;
207 1.1.2.2 bouyer
208 1.1.2.2 bouyer if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
209 1.1.2.2 bouyer return 1;
210 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
211 1.1.2.2 bouyer fbr = va;
212 1.1.2.2 bouyer
213 1.1.2.2 bouyer if (badaddr(va) ||
214 1.1.2.2 bouyer fbr->id != GRFHWID || fbr->fbid == GID_TIGER) {
215 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
216 1.1.2.2 bouyer return 1;
217 1.1.2.2 bouyer }
218 1.1.2.2 bouyer
219 1.1.2.2 bouyer size = DIO_SIZE(scode, va);
220 1.1.2.2 bouyer
221 1.1.2.2 bouyer bus_space_unmap(bst, bsh, PAGE_SIZE);
222 1.1.2.2 bouyer if (bus_space_map(bst, addr, size, 0, &bsh))
223 1.1.2.2 bouyer return 1;
224 1.1.2.2 bouyer va = bus_space_vaddr(bst, bsh);
225 1.1.2.2 bouyer
226 1.1.2.2 bouyer /*
227 1.1.2.2 bouyer * Initialize the framebuffer hardware.
228 1.1.2.2 bouyer */
229 1.1.2.2 bouyer conscode = scode;
230 1.1.2.2 bouyer conaddr = va;
231 1.1.2.2 bouyer tvrx_reset(fb, conscode, (struct diofbreg *)conaddr);
232 1.1.2.2 bouyer
233 1.1.2.2 bouyer /*
234 1.1.2.2 bouyer * Initialize the terminal emulator.
235 1.1.2.2 bouyer */
236 1.1.2.2 bouyer diofb_cnattach(fb);
237 1.1.2.2 bouyer return 0;
238 1.1.2.2 bouyer }
239