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