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