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