agten.c revision 1.6.4.3 1 1.6.4.3 yamt /* $NetBSD: agten.c,v 1.6.4.3 2007/10/27 11:34:05 yamt Exp $ */
2 1.6.4.2 yamt
3 1.6.4.2 yamt /*-
4 1.6.4.2 yamt * Copyright (c) 2007 Michael Lorenz
5 1.6.4.2 yamt * All rights reserved.
6 1.6.4.2 yamt *
7 1.6.4.2 yamt * Redistribution and use in source and binary forms, with or without
8 1.6.4.2 yamt * modification, are permitted provided that the following conditions
9 1.6.4.2 yamt * are met:
10 1.6.4.2 yamt * 1. Redistributions of source code must retain the above copyright
11 1.6.4.2 yamt * notice, this list of conditions and the following disclaimer.
12 1.6.4.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
13 1.6.4.2 yamt * notice, this list of conditions and the following disclaimer in the
14 1.6.4.2 yamt * documentation and/or other materials provided with the distribution.
15 1.6.4.2 yamt * 3. Neither the name of The NetBSD Foundation nor the names of its
16 1.6.4.2 yamt * contributors may be used to endorse or promote products derived
17 1.6.4.2 yamt * from this software without specific prior written permission.
18 1.6.4.2 yamt *
19 1.6.4.2 yamt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.6.4.2 yamt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.6.4.2 yamt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.6.4.2 yamt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.6.4.2 yamt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.6.4.2 yamt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.6.4.2 yamt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.6.4.2 yamt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.6.4.2 yamt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.6.4.2 yamt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.6.4.2 yamt * POSSIBILITY OF SUCH DAMAGE.
30 1.6.4.2 yamt */
31 1.6.4.2 yamt
32 1.6.4.2 yamt #include <sys/cdefs.h>
33 1.6.4.3 yamt __KERNEL_RCSID(0, "$NetBSD: agten.c,v 1.6.4.3 2007/10/27 11:34:05 yamt Exp $");
34 1.6.4.2 yamt
35 1.6.4.2 yamt /*
36 1.6.4.2 yamt * a driver for the Fujitsu AG-10e SBus framebuffer
37 1.6.4.2 yamt *
38 1.6.4.2 yamt * this thing is Frankenstein's Monster among graphics boards.
39 1.6.4.2 yamt * it contains three graphics chips:
40 1.6.4.2 yamt * a GLint - 24bit stuff, double-buffered
41 1.6.4.2 yamt * an Imagine 128 which provides an 8bit overlay
42 1.6.4.2 yamt * a Weitek P9100 which provides WIDs
43 1.6.4.2 yamt * so here we need to mess only with the P9100 and the I128 - for X we just
44 1.6.4.2 yamt * hide the overlay and let the Xserver mess with the GLint
45 1.6.4.2 yamt */
46 1.6.4.2 yamt
47 1.6.4.2 yamt #include <sys/param.h>
48 1.6.4.2 yamt #include <sys/systm.h>
49 1.6.4.2 yamt #include <sys/kernel.h>
50 1.6.4.2 yamt #include <sys/device.h>
51 1.6.4.2 yamt #include <sys/proc.h>
52 1.6.4.2 yamt #include <sys/mutex.h>
53 1.6.4.2 yamt #include <sys/ioctl.h>
54 1.6.4.2 yamt #include <sys/kernel.h>
55 1.6.4.2 yamt #include <sys/systm.h>
56 1.6.4.2 yamt #include <sys/conf.h>
57 1.6.4.2 yamt
58 1.6.4.2 yamt #include <dev/sun/fbio.h>
59 1.6.4.2 yamt #include <dev/sun/fbvar.h>
60 1.6.4.2 yamt #include <dev/sun/btreg.h>
61 1.6.4.2 yamt #include <dev/sun/btvar.h>
62 1.6.4.2 yamt
63 1.6.4.3 yamt #include <sys/bus.h>
64 1.6.4.2 yamt #include <machine/autoconf.h>
65 1.6.4.2 yamt
66 1.6.4.2 yamt #include <dev/sbus/sbusvar.h>
67 1.6.4.2 yamt
68 1.6.4.2 yamt #include <dev/wscons/wsconsio.h>
69 1.6.4.2 yamt #include <dev/wscons/wsdisplayvar.h>
70 1.6.4.2 yamt #include <dev/rasops/rasops.h>
71 1.6.4.2 yamt #include <dev/wsfont/wsfont.h>
72 1.6.4.2 yamt
73 1.6.4.2 yamt #include <dev/wscons/wsdisplay_vconsvar.h>
74 1.6.4.2 yamt
75 1.6.4.2 yamt #include <dev/sbus/p9100reg.h>
76 1.6.4.2 yamt #include <dev/ic/ibm561reg.h>
77 1.6.4.2 yamt #include <dev/ic/i128reg.h>
78 1.6.4.2 yamt #include <dev/ic/i128var.h>
79 1.6.4.2 yamt
80 1.6.4.2 yamt #include "opt_agten.h"
81 1.6.4.2 yamt
82 1.6.4.2 yamt static int agten_match(struct device *, struct cfdata *, void *);
83 1.6.4.2 yamt static void agten_attach(struct device *, struct device *, void *);
84 1.6.4.2 yamt
85 1.6.4.2 yamt static int agten_ioctl(void *, void *, u_long, void *, int, struct lwp *);
86 1.6.4.2 yamt static paddr_t agten_mmap(void *, void *, off_t, int);
87 1.6.4.2 yamt static void agten_init_screen(void *, struct vcons_screen *, int, long *);
88 1.6.4.2 yamt
89 1.6.4.2 yamt struct agten_softc {
90 1.6.4.2 yamt struct device sc_dev; /* base device */
91 1.6.4.2 yamt struct sbusdev sc_sd; /* sbus device */
92 1.6.4.2 yamt struct fbdevice sc_fb; /* frame buffer device */
93 1.6.4.2 yamt
94 1.6.4.2 yamt struct vcons_screen sc_console_screen;
95 1.6.4.2 yamt struct wsscreen_descr sc_defaultscreen_descr;
96 1.6.4.2 yamt const struct wsscreen_descr *sc_screens[1];
97 1.6.4.2 yamt struct wsscreen_list sc_screenlist;
98 1.6.4.2 yamt
99 1.6.4.2 yamt bus_space_tag_t sc_bustag;
100 1.6.4.2 yamt
101 1.6.4.2 yamt bus_space_handle_t sc_i128_fbh;
102 1.6.4.2 yamt bus_size_t sc_i128_fbsz;
103 1.6.4.2 yamt bus_space_handle_t sc_i128_regh;
104 1.6.4.2 yamt bus_space_handle_t sc_p9100_regh;
105 1.6.4.2 yamt bus_addr_t sc_glint_fb;
106 1.6.4.2 yamt bus_addr_t sc_glint_regs;
107 1.6.4.2 yamt uint32_t sc_glint_fbsz;
108 1.6.4.2 yamt
109 1.6.4.2 yamt uint32_t sc_width;
110 1.6.4.2 yamt uint32_t sc_height; /* panel width / height */
111 1.6.4.2 yamt uint32_t sc_stride;
112 1.6.4.2 yamt uint32_t sc_depth;
113 1.6.4.2 yamt
114 1.6.4.2 yamt int sc_cursor_x;
115 1.6.4.2 yamt int sc_cursor_y;
116 1.6.4.2 yamt int sc_video; /* video output enabled */
117 1.6.4.2 yamt
118 1.6.4.2 yamt /* some /dev/fb* stuff */
119 1.6.4.2 yamt int sc_fb_is_open;
120 1.6.4.2 yamt
121 1.6.4.2 yamt union bt_cmap sc_cmap; /* Brooktree color map */
122 1.6.4.2 yamt
123 1.6.4.2 yamt int sc_mode;
124 1.6.4.2 yamt uint32_t sc_bg;
125 1.6.4.2 yamt struct vcons_data vd;
126 1.6.4.2 yamt };
127 1.6.4.2 yamt
128 1.6.4.2 yamt CFATTACH_DECL(agten, sizeof(struct agten_softc),
129 1.6.4.2 yamt agten_match, agten_attach, NULL, NULL);
130 1.6.4.2 yamt
131 1.6.4.2 yamt
132 1.6.4.2 yamt static int agten_putcmap(struct agten_softc *, struct wsdisplay_cmap *);
133 1.6.4.2 yamt static int agten_getcmap(struct agten_softc *, struct wsdisplay_cmap *);
134 1.6.4.2 yamt static int agten_putpalreg(struct agten_softc *, uint8_t, uint8_t,
135 1.6.4.2 yamt uint8_t, uint8_t);
136 1.6.4.2 yamt static void agten_init(struct agten_softc *);
137 1.6.4.2 yamt static void agten_gfx(struct agten_softc *);
138 1.6.4.2 yamt static void agten_set_video(struct agten_softc *, int);
139 1.6.4.2 yamt static int agten_get_video(struct agten_softc *);
140 1.6.4.2 yamt
141 1.6.4.2 yamt static void agten_copycols(void *, int, int, int, int);
142 1.6.4.2 yamt static void agten_erasecols(void *, int, int, int, long);
143 1.6.4.2 yamt static void agten_copyrows(void *, int, int, int);
144 1.6.4.2 yamt static void agten_eraserows(void *, int, int, long);
145 1.6.4.2 yamt
146 1.6.4.2 yamt static void agten_move_cursor(struct agten_softc *, int, int);
147 1.6.4.2 yamt static int agten_do_cursor(struct agten_softc *sc,
148 1.6.4.2 yamt struct wsdisplay_cursor *);
149 1.6.4.2 yamt static int agten_do_sun_cursor(struct agten_softc *sc,
150 1.6.4.2 yamt struct fbcursor *);
151 1.6.4.2 yamt
152 1.6.4.2 yamt static uint16_t util_interleave(uint8_t, uint8_t);
153 1.6.4.2 yamt static uint16_t util_interleave_lin(uint8_t, uint8_t);
154 1.6.4.2 yamt
155 1.6.4.2 yamt extern const u_char rasops_cmap[768];
156 1.6.4.2 yamt
157 1.6.4.2 yamt struct wsdisplay_accessops agten_accessops = {
158 1.6.4.2 yamt agten_ioctl,
159 1.6.4.2 yamt agten_mmap,
160 1.6.4.2 yamt NULL, /* alloc_screen */
161 1.6.4.2 yamt NULL, /* free_screen */
162 1.6.4.2 yamt NULL, /* show_screen */
163 1.6.4.2 yamt NULL, /* load_font */
164 1.6.4.2 yamt NULL, /* pollc */
165 1.6.4.2 yamt NULL /* scroll */
166 1.6.4.2 yamt };
167 1.6.4.2 yamt
168 1.6.4.2 yamt /* /dev/fb* stuff */
169 1.6.4.2 yamt extern struct cfdriver agten_cd;
170 1.6.4.2 yamt
171 1.6.4.2 yamt static int agten_fb_open(dev_t, int, int, struct lwp *);
172 1.6.4.2 yamt static int agten_fb_close(dev_t, int, int, struct lwp *);
173 1.6.4.2 yamt static int agten_fb_ioctl(dev_t, u_long, void *, int, struct lwp *);
174 1.6.4.2 yamt static paddr_t agten_fb_mmap(dev_t, off_t, int);
175 1.6.4.2 yamt static void agten_fb_unblank(struct device *);
176 1.6.4.2 yamt
177 1.6.4.2 yamt static struct fbdriver agtenfbdriver = {
178 1.6.4.2 yamt agten_fb_unblank, agten_fb_open, agten_fb_close, agten_fb_ioctl,
179 1.6.4.2 yamt nopoll, agten_fb_mmap, nokqfilter
180 1.6.4.2 yamt };
181 1.6.4.2 yamt
182 1.6.4.2 yamt static inline void
183 1.6.4.2 yamt agten_write_dac(struct agten_softc *sc, int reg, uint8_t val)
184 1.6.4.2 yamt {
185 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
186 1.6.4.2 yamt 0x200 + (reg << 2), (uint32_t)val << 16);
187 1.6.4.2 yamt }
188 1.6.4.2 yamt
189 1.6.4.2 yamt static inline void
190 1.6.4.2 yamt agten_write_idx(struct agten_softc *sc, int offset)
191 1.6.4.2 yamt {
192 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
193 1.6.4.2 yamt 0x200 + (IBM561_ADDR_LOW << 2), (offset & 0xff) << 16);
194 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh,
195 1.6.4.2 yamt 0x200 + (IBM561_ADDR_HIGH << 2), ((offset >> 8) & 0xff) << 16);
196 1.6.4.2 yamt }
197 1.6.4.2 yamt
198 1.6.4.2 yamt static inline void
199 1.6.4.2 yamt agten_write_dac_10(struct agten_softc *sc, int reg, uint16_t val)
200 1.6.4.2 yamt {
201 1.6.4.2 yamt agten_write_dac(sc, reg, (val >> 2) & 0xff);
202 1.6.4.2 yamt agten_write_dac(sc, reg, (val & 0x3) << 6);
203 1.6.4.2 yamt }
204 1.6.4.2 yamt
205 1.6.4.2 yamt static int
206 1.6.4.2 yamt agten_match(struct device *dev, struct cfdata *cf, void *aux)
207 1.6.4.2 yamt {
208 1.6.4.2 yamt struct sbus_attach_args *sa = aux;
209 1.6.4.2 yamt
210 1.6.4.2 yamt if (strcmp("PFU,aga", sa->sa_name) == 0)
211 1.6.4.2 yamt return 100;
212 1.6.4.2 yamt return 0;
213 1.6.4.2 yamt }
214 1.6.4.2 yamt
215 1.6.4.2 yamt static void
216 1.6.4.2 yamt agten_attach(struct device *parent, struct device *dev, void *aux)
217 1.6.4.2 yamt {
218 1.6.4.2 yamt struct agten_softc *sc = (struct agten_softc *)dev;
219 1.6.4.2 yamt struct sbus_attach_args *sa = aux;
220 1.6.4.2 yamt struct fbdevice *fb = &sc->sc_fb;
221 1.6.4.2 yamt struct wsemuldisplaydev_attach_args aa;
222 1.6.4.2 yamt struct rasops_info *ri;
223 1.6.4.2 yamt long defattr;
224 1.6.4.2 yamt uint32_t reg;
225 1.6.4.2 yamt int node = sa->sa_node;
226 1.6.4.2 yamt int console;
227 1.6.4.2 yamt
228 1.6.4.2 yamt sc->sc_defaultscreen_descr = (struct wsscreen_descr){
229 1.6.4.2 yamt "default",
230 1.6.4.2 yamt 0, 0,
231 1.6.4.2 yamt NULL,
232 1.6.4.2 yamt 8, 16,
233 1.6.4.2 yamt WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
234 1.6.4.2 yamt NULL
235 1.6.4.2 yamt };
236 1.6.4.2 yamt sc->sc_screens[0] = &sc->sc_defaultscreen_descr;
237 1.6.4.2 yamt sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens};
238 1.6.4.2 yamt sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
239 1.6.4.2 yamt sc->sc_fb_is_open = 0;
240 1.6.4.2 yamt sc->sc_video = -1;
241 1.6.4.2 yamt sc->sc_bustag = sa->sa_bustag;
242 1.6.4.2 yamt
243 1.6.4.2 yamt reg = prom_getpropint(node, "i128_fb_physaddr", -1);
244 1.6.4.2 yamt sc->sc_i128_fbsz = prom_getpropint(node, "i128_fb_size", -1);
245 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
246 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
247 1.6.4.2 yamt sc->sc_i128_fbsz, BUS_SPACE_MAP_LINEAR, &sc->sc_i128_fbh) != 0) {
248 1.6.4.2 yamt
249 1.6.4.2 yamt aprint_error("%s: unable to map the framebuffer\n",
250 1.6.4.2 yamt dev->dv_xname);
251 1.6.4.2 yamt return;
252 1.6.4.2 yamt }
253 1.6.4.2 yamt fb->fb_pixels = bus_space_vaddr(sc->sc_bustag, sc->sc_i128_fbh);
254 1.6.4.2 yamt
255 1.6.4.2 yamt reg = prom_getpropint(node, "i128_reg_physaddr", -1);
256 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
257 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
258 1.6.4.2 yamt 0x10000, 0, &sc->sc_i128_regh) != 0) {
259 1.6.4.2 yamt
260 1.6.4.2 yamt aprint_error("%s: unable to map I128 registers\n",
261 1.6.4.2 yamt dev->dv_xname);
262 1.6.4.2 yamt return;
263 1.6.4.2 yamt }
264 1.6.4.2 yamt
265 1.6.4.2 yamt reg = prom_getpropint(node, "p9100_reg_physaddr", -1);
266 1.6.4.2 yamt if (sbus_bus_map(sc->sc_bustag,
267 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg,
268 1.6.4.2 yamt 0x8000, 0, &sc->sc_p9100_regh) != 0) {
269 1.6.4.2 yamt
270 1.6.4.2 yamt aprint_error("%s: unable to map P9100 registers\n",
271 1.6.4.2 yamt dev->dv_xname);
272 1.6.4.2 yamt return;
273 1.6.4.2 yamt }
274 1.6.4.2 yamt
275 1.6.4.2 yamt reg = prom_getpropint(node, "glint_fb0_physaddr", -1);
276 1.6.4.2 yamt sc->sc_glint_fb = sbus_bus_addr(sc->sc_bustag,
277 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
278 1.6.4.3 yamt sc->sc_glint_fbsz = prom_getpropint(node, "glint_lb_size", -1);
279 1.6.4.2 yamt reg = prom_getpropint(node, "glint_reg_physaddr", -1);
280 1.6.4.2 yamt sc->sc_glint_regs = sbus_bus_addr(sc->sc_bustag,
281 1.6.4.2 yamt sa->sa_reg[0].oa_space, sa->sa_reg[0].oa_base + reg);
282 1.6.4.2 yamt
283 1.6.4.2 yamt sbus_establish(&sc->sc_sd, &sc->sc_dev);
284 1.6.4.3 yamt
285 1.6.4.2 yamt #if 0
286 1.6.4.2 yamt bus_intr_establish(sc->sc_bustag, sa->sa_pri, IPL_BIO,
287 1.6.4.2 yamt agten_intr, sc);
288 1.6.4.2 yamt #endif
289 1.6.4.2 yamt
290 1.6.4.3 yamt sc->sc_width = prom_getpropint(node, "ffb_width", 1152);
291 1.6.4.3 yamt sc->sc_height = prom_getpropint(node, "ffb_height", 900);
292 1.6.4.2 yamt sc->sc_depth = prom_getpropint(node, "ffb_depth", 8);
293 1.6.4.2 yamt sc->sc_stride = sc->sc_width * (sc->sc_depth >> 3);
294 1.6.4.2 yamt
295 1.6.4.3 yamt printf(": %dx%d\n", sc->sc_width, sc->sc_height);
296 1.6.4.2 yamt agten_init(sc);
297 1.6.4.2 yamt
298 1.6.4.2 yamt console = fb_is_console(node);
299 1.6.4.2 yamt
300 1.6.4.2 yamt vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr,
301 1.6.4.2 yamt &agten_accessops);
302 1.6.4.2 yamt sc->vd.init_screen = agten_init_screen;
303 1.6.4.2 yamt
304 1.6.4.2 yamt ri = &sc->sc_console_screen.scr_ri;
305 1.6.4.2 yamt
306 1.6.4.2 yamt if (console) {
307 1.6.4.2 yamt vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1,
308 1.6.4.2 yamt &defattr);
309 1.6.4.2 yamt sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
310 1.6.4.2 yamt
311 1.6.4.2 yamt sc->sc_defaultscreen_descr.textops = &ri->ri_ops;
312 1.6.4.2 yamt sc->sc_defaultscreen_descr.capabilities = ri->ri_caps;
313 1.6.4.2 yamt sc->sc_defaultscreen_descr.nrows = ri->ri_rows;
314 1.6.4.2 yamt sc->sc_defaultscreen_descr.ncols = ri->ri_cols;
315 1.6.4.2 yamt wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0,
316 1.6.4.2 yamt defattr);
317 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0,
318 1.6.4.2 yamt sc->sc_width, sc->sc_height,
319 1.6.4.2 yamt ri->ri_devcmap[(defattr >> 16) & 0xff]);
320 1.6.4.2 yamt } else {
321 1.6.4.2 yamt /*
322 1.6.4.2 yamt * since we're not the console we can postpone the rest
323 1.6.4.2 yamt * until someone actually allocates a screen for us
324 1.6.4.2 yamt */
325 1.6.4.2 yamt }
326 1.6.4.2 yamt
327 1.6.4.2 yamt /* Initialize the default color map. */
328 1.6.4.2 yamt
329 1.6.4.2 yamt aa.console = console;
330 1.6.4.2 yamt aa.scrdata = &sc->sc_screenlist;
331 1.6.4.2 yamt aa.accessops = &agten_accessops;
332 1.6.4.2 yamt aa.accesscookie = &sc->vd;
333 1.6.4.2 yamt
334 1.6.4.2 yamt config_found(&sc->sc_dev, &aa, wsemuldisplaydevprint);
335 1.6.4.2 yamt
336 1.6.4.2 yamt fb->fb_driver = &agtenfbdriver;
337 1.6.4.2 yamt fb->fb_device = &sc->sc_dev;
338 1.6.4.2 yamt fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
339 1.6.4.2 yamt fb->fb_type.fb_type = FBTYPE_AG10E;
340 1.6.4.2 yamt fb->fb_type.fb_cmsize = 256; /* doesn't matter, we're always 24bit */
341 1.6.4.2 yamt fb->fb_type.fb_size = sc->sc_glint_fbsz;
342 1.6.4.2 yamt fb->fb_type.fb_width = sc->sc_width;
343 1.6.4.2 yamt fb->fb_type.fb_height = sc->sc_height;
344 1.6.4.2 yamt fb->fb_type.fb_depth = 32;
345 1.6.4.2 yamt fb->fb_linebytes = sc->sc_stride;
346 1.6.4.2 yamt fb_attach(fb, console);
347 1.6.4.2 yamt agten_set_video(sc, 1); /* make sure video's on */
348 1.6.4.2 yamt }
349 1.6.4.2 yamt
350 1.6.4.2 yamt static int
351 1.6.4.2 yamt agten_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
352 1.6.4.2 yamt struct lwp *l)
353 1.6.4.2 yamt {
354 1.6.4.2 yamt struct vcons_data *vd = v;
355 1.6.4.2 yamt struct agten_softc *sc = vd->cookie;
356 1.6.4.2 yamt struct wsdisplay_fbinfo *wdf;
357 1.6.4.2 yamt struct vcons_screen *ms = vd->active;
358 1.6.4.2 yamt
359 1.6.4.2 yamt switch (cmd) {
360 1.6.4.2 yamt
361 1.6.4.2 yamt case WSDISPLAYIO_GTYPE:
362 1.6.4.2 yamt *(u_int *)data = WSDISPLAY_TYPE_AG10;
363 1.6.4.2 yamt return 0;
364 1.6.4.2 yamt
365 1.6.4.2 yamt case WSDISPLAYIO_GINFO:
366 1.6.4.2 yamt if (ms == NULL)
367 1.6.4.2 yamt return ENODEV;
368 1.6.4.2 yamt wdf = (void *)data;
369 1.6.4.2 yamt wdf->height = ms->scr_ri.ri_height;
370 1.6.4.2 yamt wdf->width = ms->scr_ri.ri_width;
371 1.6.4.2 yamt wdf->depth = 32;
372 1.6.4.2 yamt wdf->cmsize = 256;
373 1.6.4.2 yamt return 0;
374 1.6.4.2 yamt
375 1.6.4.2 yamt case WSDISPLAYIO_GVIDEO:
376 1.6.4.2 yamt *(int *)data = sc->sc_video;
377 1.6.4.2 yamt return 0;
378 1.6.4.2 yamt
379 1.6.4.2 yamt case WSDISPLAYIO_SVIDEO:
380 1.6.4.2 yamt agten_set_video(sc, *(int *)data);
381 1.6.4.2 yamt return 0;
382 1.6.4.2 yamt
383 1.6.4.2 yamt case WSDISPLAYIO_GETCMAP:
384 1.6.4.2 yamt return agten_getcmap(sc,
385 1.6.4.2 yamt (struct wsdisplay_cmap *)data);
386 1.6.4.2 yamt
387 1.6.4.2 yamt case WSDISPLAYIO_PUTCMAP:
388 1.6.4.2 yamt return agten_putcmap(sc,
389 1.6.4.2 yamt (struct wsdisplay_cmap *)data);
390 1.6.4.2 yamt
391 1.6.4.2 yamt case WSDISPLAYIO_LINEBYTES:
392 1.6.4.2 yamt *(u_int *)data = sc->sc_stride << 2;
393 1.6.4.2 yamt return 0;
394 1.6.4.2 yamt
395 1.6.4.2 yamt case WSDISPLAYIO_SMODE:
396 1.6.4.2 yamt {
397 1.6.4.2 yamt int new_mode = *(int*)data;
398 1.6.4.2 yamt if (new_mode != sc->sc_mode) {
399 1.6.4.2 yamt sc->sc_mode = new_mode;
400 1.6.4.2 yamt if(new_mode == WSDISPLAYIO_MODE_EMUL) {
401 1.6.4.2 yamt agten_init(sc);
402 1.6.4.2 yamt vcons_redraw_screen(ms);
403 1.6.4.2 yamt } else {
404 1.6.4.2 yamt agten_gfx(sc);
405 1.6.4.2 yamt }
406 1.6.4.2 yamt }
407 1.6.4.2 yamt }
408 1.6.4.2 yamt return 0;
409 1.6.4.2 yamt
410 1.6.4.2 yamt case WSDISPLAYIO_GCURPOS:
411 1.6.4.2 yamt {
412 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
413 1.6.4.2 yamt
414 1.6.4.2 yamt cp->x = sc->sc_cursor_x;
415 1.6.4.2 yamt cp->y = sc->sc_cursor_y;
416 1.6.4.2 yamt }
417 1.6.4.2 yamt return 0;
418 1.6.4.2 yamt
419 1.6.4.2 yamt case WSDISPLAYIO_SCURPOS:
420 1.6.4.2 yamt {
421 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
422 1.6.4.2 yamt
423 1.6.4.2 yamt agten_move_cursor(sc, cp->x, cp->y);
424 1.6.4.2 yamt }
425 1.6.4.2 yamt return 0;
426 1.6.4.2 yamt
427 1.6.4.2 yamt case WSDISPLAYIO_GCURMAX:
428 1.6.4.2 yamt {
429 1.6.4.2 yamt struct wsdisplay_curpos *cp = (void *)data;
430 1.6.4.2 yamt
431 1.6.4.2 yamt cp->x = 64;
432 1.6.4.2 yamt cp->y = 64;
433 1.6.4.2 yamt }
434 1.6.4.2 yamt return 0;
435 1.6.4.2 yamt
436 1.6.4.2 yamt case WSDISPLAYIO_SCURSOR:
437 1.6.4.2 yamt {
438 1.6.4.2 yamt struct wsdisplay_cursor *cursor = (void *)data;
439 1.6.4.2 yamt
440 1.6.4.2 yamt return agten_do_cursor(sc, cursor);
441 1.6.4.2 yamt }
442 1.6.4.2 yamt }
443 1.6.4.2 yamt return EPASSTHROUGH;
444 1.6.4.2 yamt }
445 1.6.4.2 yamt
446 1.6.4.2 yamt static paddr_t
447 1.6.4.2 yamt agten_mmap(void *v, void *vs, off_t offset, int prot)
448 1.6.4.2 yamt {
449 1.6.4.2 yamt struct vcons_data *vd = v;
450 1.6.4.2 yamt struct agten_softc *sc = vd->cookie;
451 1.6.4.2 yamt
452 1.6.4.2 yamt if (offset < sc->sc_glint_fbsz)
453 1.6.4.2 yamt return bus_space_mmap(sc->sc_bustag, sc->sc_glint_fb, offset,
454 1.6.4.2 yamt prot, BUS_SPACE_MAP_LINEAR);
455 1.6.4.2 yamt return -1;
456 1.6.4.2 yamt }
457 1.6.4.2 yamt
458 1.6.4.2 yamt static void
459 1.6.4.2 yamt agten_init_screen(void *cookie, struct vcons_screen *scr,
460 1.6.4.2 yamt int existing, long *defattr)
461 1.6.4.2 yamt {
462 1.6.4.2 yamt struct agten_softc *sc = cookie;
463 1.6.4.2 yamt struct rasops_info *ri = &scr->scr_ri;
464 1.6.4.2 yamt
465 1.6.4.2 yamt ri->ri_depth = sc->sc_depth;
466 1.6.4.2 yamt ri->ri_width = sc->sc_width;
467 1.6.4.2 yamt ri->ri_height = sc->sc_height;
468 1.6.4.2 yamt ri->ri_stride = sc->sc_stride;
469 1.6.4.2 yamt ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
470 1.6.4.2 yamt
471 1.6.4.2 yamt ri->ri_bits = (char *)sc->sc_fb.fb_pixels;
472 1.6.4.2 yamt
473 1.6.4.2 yamt if (existing) {
474 1.6.4.2 yamt ri->ri_flg |= RI_CLEAR;
475 1.6.4.2 yamt }
476 1.6.4.2 yamt
477 1.6.4.2 yamt rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8);
478 1.6.4.2 yamt ri->ri_caps = WSSCREEN_WSCOLORS;
479 1.6.4.2 yamt
480 1.6.4.2 yamt rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
481 1.6.4.2 yamt sc->sc_width / ri->ri_font->fontwidth);
482 1.6.4.2 yamt
483 1.6.4.2 yamt ri->ri_hw = scr;
484 1.6.4.2 yamt ri->ri_ops.copyrows = agten_copyrows;
485 1.6.4.2 yamt ri->ri_ops.eraserows = agten_eraserows;
486 1.6.4.2 yamt ri->ri_ops.copycols = agten_copycols;
487 1.6.4.2 yamt ri->ri_ops.erasecols = agten_erasecols;
488 1.6.4.2 yamt
489 1.6.4.2 yamt }
490 1.6.4.2 yamt
491 1.6.4.2 yamt static int
492 1.6.4.2 yamt agten_putcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
493 1.6.4.2 yamt {
494 1.6.4.2 yamt u_int index = cm->index;
495 1.6.4.2 yamt u_int count = cm->count;
496 1.6.4.2 yamt int i, error;
497 1.6.4.2 yamt u_char rbuf[256], gbuf[256], bbuf[256];
498 1.6.4.2 yamt u_char *r, *g, *b;
499 1.6.4.2 yamt
500 1.6.4.2 yamt if (cm->index >= 256 || cm->count > 256 ||
501 1.6.4.2 yamt (cm->index + cm->count) > 256)
502 1.6.4.2 yamt return EINVAL;
503 1.6.4.2 yamt error = copyin(cm->red, &rbuf[index], count);
504 1.6.4.2 yamt if (error)
505 1.6.4.2 yamt return error;
506 1.6.4.2 yamt error = copyin(cm->green, &gbuf[index], count);
507 1.6.4.2 yamt if (error)
508 1.6.4.2 yamt return error;
509 1.6.4.2 yamt error = copyin(cm->blue, &bbuf[index], count);
510 1.6.4.2 yamt if (error)
511 1.6.4.2 yamt return error;
512 1.6.4.2 yamt
513 1.6.4.2 yamt r = &rbuf[index];
514 1.6.4.2 yamt g = &gbuf[index];
515 1.6.4.2 yamt b = &bbuf[index];
516 1.6.4.2 yamt
517 1.6.4.2 yamt for (i = 0; i < count; i++) {
518 1.6.4.2 yamt agten_putpalreg(sc, index, *r, *g, *b);
519 1.6.4.2 yamt index++;
520 1.6.4.2 yamt r++, g++, b++;
521 1.6.4.2 yamt }
522 1.6.4.2 yamt return 0;
523 1.6.4.2 yamt }
524 1.6.4.2 yamt
525 1.6.4.2 yamt static int
526 1.6.4.2 yamt agten_getcmap(struct agten_softc *sc, struct wsdisplay_cmap *cm)
527 1.6.4.2 yamt {
528 1.6.4.2 yamt u_int index = cm->index;
529 1.6.4.2 yamt u_int count = cm->count;
530 1.6.4.2 yamt int error, i;
531 1.6.4.2 yamt uint8_t red[256], green[256], blue[256];
532 1.6.4.2 yamt
533 1.6.4.2 yamt if (index >= 255 || count > 256 || index + count > 256)
534 1.6.4.2 yamt return EINVAL;
535 1.6.4.2 yamt
536 1.6.4.2 yamt i = index;
537 1.6.4.2 yamt while (i < (index + count)) {
538 1.6.4.2 yamt red[i] = sc->sc_cmap.cm_map[i][0];
539 1.6.4.2 yamt green[i] = sc->sc_cmap.cm_map[i][1];
540 1.6.4.2 yamt blue[i] = sc->sc_cmap.cm_map[i][2];
541 1.6.4.2 yamt i++;
542 1.6.4.2 yamt }
543 1.6.4.2 yamt error = copyout(&red[index], cm->red, count);
544 1.6.4.2 yamt if (error)
545 1.6.4.2 yamt return error;
546 1.6.4.2 yamt error = copyout(&green[index], cm->green, count);
547 1.6.4.2 yamt if (error)
548 1.6.4.2 yamt return error;
549 1.6.4.2 yamt error = copyout(&blue[index], cm->blue, count);
550 1.6.4.2 yamt if (error)
551 1.6.4.2 yamt return error;
552 1.6.4.2 yamt
553 1.6.4.2 yamt return 0;
554 1.6.4.2 yamt }
555 1.6.4.2 yamt
556 1.6.4.2 yamt static int
557 1.6.4.2 yamt agten_putpalreg(struct agten_softc *sc, uint8_t idx, uint8_t r, uint8_t g,
558 1.6.4.2 yamt uint8_t b)
559 1.6.4.2 yamt {
560 1.6.4.2 yamt
561 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][0] = r;
562 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][1] = g;
563 1.6.4.2 yamt sc->sc_cmap.cm_map[idx][2] = b;
564 1.6.4.2 yamt agten_write_idx(sc, IBM561_CMAP_TABLE + idx);
565 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, r);
566 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, g);
567 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, b);
568 1.6.4.2 yamt return 0;
569 1.6.4.2 yamt }
570 1.6.4.2 yamt
571 1.6.4.2 yamt static void
572 1.6.4.2 yamt agten_init(struct agten_softc *sc)
573 1.6.4.2 yamt {
574 1.6.4.2 yamt int i, j;
575 1.6.4.2 yamt uint32_t src, srcw;
576 1.6.4.2 yamt volatile uint32_t junk;
577 1.6.4.2 yamt
578 1.6.4.2 yamt /* first we set up the colour map */
579 1.6.4.2 yamt j = 0;
580 1.6.4.2 yamt for (i = 0; i < 256; i++) {
581 1.6.4.2 yamt
582 1.6.4.2 yamt agten_putpalreg(sc, i, rasops_cmap[j], rasops_cmap[j + 1],
583 1.6.4.2 yamt rasops_cmap[j + 2]);
584 1.6.4.2 yamt j += 3;
585 1.6.4.2 yamt }
586 1.6.4.2 yamt
587 1.6.4.2 yamt /* then we set up a linear LUT for 24bit colour */
588 1.6.4.2 yamt agten_write_idx(sc, IBM561_CMAP_TABLE + 256);
589 1.6.4.2 yamt for (i = 0; i < 256; i++) {
590 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
591 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
592 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, i);
593 1.6.4.2 yamt }
594 1.6.4.2 yamt
595 1.6.4.2 yamt /* and the linear gamma maps */
596 1.6.4.2 yamt agten_write_idx(sc, IBM561_RED_GAMMA_TABLE);
597 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
598 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
599 1.6.4.2 yamt agten_write_idx(sc, IBM561_GREEN_GAMMA_TABLE);
600 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
601 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
602 1.6.4.2 yamt agten_write_idx(sc, IBM561_BLUE_GAMMA_TABLE);
603 1.6.4.2 yamt for (i = 0; i < 0x3ff; i+= 4)
604 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_GAMMA, i);
605 1.6.4.2 yamt
606 1.6.4.2 yamt /* enable outouts, RGB mode */
607 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG3);
608 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, 0x41);
609 1.6.4.2 yamt
610 1.6.4.2 yamt /* MUX 4:1 basic, 8bit overlay, 8bit WIDs */
611 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG1);
612 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, 0x2c);
613 1.6.4.2 yamt
614 1.6.4.2 yamt /* use internal PLL, enable video output */
615 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG2);
616 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, CR2_ENABLE_CLC | CR2_PLL_REF_SELECT |
617 1.6.4.2 yamt CR2_PIXEL_CLOCK_SELECT | CR2_ENABLE_RGB_OUTPUT);
618 1.6.4.2 yamt
619 1.6.4.2 yamt /* now set up some window attributes */
620 1.6.4.2 yamt
621 1.6.4.2 yamt /*
622 1.6.4.2 yamt * direct colour, 24 bit, transparency off, LUT from 0x100
623 1.6.4.2 yamt * we need to use direct colour and a linear LUT because for some
624 1.6.4.2 yamt * reason true color mode gives messed up colours
625 1.6.4.2 yamt */
626 1.6.4.2 yamt agten_write_idx(sc, IBM561_FB_WINTYPE);
627 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x134);
628 1.6.4.2 yamt
629 1.6.4.2 yamt /* use gamma LUTs, no crosshair, 0 is transparent */
630 1.6.4.2 yamt agten_write_idx(sc, IBM561_AUXFB_WINTYPE);
631 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_FB_WAT, 0x0);
632 1.6.4.2 yamt
633 1.6.4.2 yamt /* overlay is 8 bit, opaque */
634 1.6.4.2 yamt agten_write_idx(sc, IBM561_OL_WINTYPE);
635 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x00);
636 1.6.4.2 yamt
637 1.6.4.2 yamt /* now we fill the WID fb with zeroes */
638 1.6.4.2 yamt src = 0;
639 1.6.4.2 yamt srcw = sc->sc_width << 16 | sc->sc_height;
640 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, FOREGROUND_COLOR,
641 1.6.4.2 yamt 0x0);
642 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, BACKGROUND_COLOR,
643 1.6.4.2 yamt 0x0);
644 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RASTER_OP, ROP_PAT);
645 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, COORD_INDEX, 0);
646 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, src);
647 1.6.4.2 yamt bus_space_write_4(sc->sc_bustag, sc->sc_p9100_regh, RECT_RTW_XY, srcw);
648 1.6.4.2 yamt junk = bus_space_read_4(sc->sc_bustag, sc->sc_p9100_regh, COMMAND_QUAD);
649 1.6.4.2 yamt
650 1.6.4.2 yamt /* initialize the cursor registers */
651 1.6.4.2 yamt
652 1.6.4.2 yamt /* initialize the Imagine 128 */
653 1.6.4.2 yamt i128_init(sc->sc_bustag, sc->sc_i128_regh, sc->sc_stride, 8);
654 1.6.4.2 yamt }
655 1.6.4.2 yamt
656 1.6.4.2 yamt static void
657 1.6.4.2 yamt agten_gfx(struct agten_softc *sc)
658 1.6.4.2 yamt {
659 1.6.4.2 yamt /* enable overlay transparency on colour 0x00 */
660 1.6.4.2 yamt agten_write_idx(sc, IBM561_OL_WINTYPE);
661 1.6.4.2 yamt agten_write_dac_10(sc, IBM561_CMD_FB_WAT, 0x01);
662 1.6.4.2 yamt
663 1.6.4.2 yamt /* then blit the overlay full of 0x00 */
664 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, 0, 0, sc->sc_width,
665 1.6.4.2 yamt sc->sc_height, 0);
666 1.6.4.2 yamt
667 1.6.4.2 yamt /* ... so we can see the 24bit framebuffer */
668 1.6.4.2 yamt }
669 1.6.4.2 yamt
670 1.6.4.2 yamt static void
671 1.6.4.2 yamt agten_set_video(struct agten_softc *sc, int flag)
672 1.6.4.2 yamt {
673 1.6.4.2 yamt uint8_t reg =
674 1.6.4.2 yamt CR2_ENABLE_CLC | CR2_PLL_REF_SELECT | CR2_PIXEL_CLOCK_SELECT;
675 1.6.4.2 yamt
676 1.6.4.2 yamt if (flag == sc->sc_video)
677 1.6.4.2 yamt return;
678 1.6.4.2 yamt
679 1.6.4.2 yamt agten_write_idx(sc, IBM561_CONFIG_REG2);
680 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, flag ? reg | CR2_ENABLE_RGB_OUTPUT :
681 1.6.4.2 yamt reg);
682 1.6.4.2 yamt
683 1.6.4.2 yamt sc->sc_video = flag;
684 1.6.4.2 yamt }
685 1.6.4.2 yamt
686 1.6.4.2 yamt static int
687 1.6.4.2 yamt agten_get_video(struct agten_softc *sc)
688 1.6.4.2 yamt {
689 1.6.4.2 yamt
690 1.6.4.2 yamt return sc->sc_video;
691 1.6.4.2 yamt }
692 1.6.4.2 yamt
693 1.6.4.2 yamt static void
694 1.6.4.2 yamt agten_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
695 1.6.4.2 yamt {
696 1.6.4.2 yamt struct rasops_info *ri = cookie;
697 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
698 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
699 1.6.4.2 yamt int32_t xs, xd, y, width, height;
700 1.6.4.2 yamt
701 1.6.4.2 yamt xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
702 1.6.4.2 yamt xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
703 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
704 1.6.4.2 yamt width = ri->ri_font->fontwidth * ncols;
705 1.6.4.2 yamt height = ri->ri_font->fontheight;
706 1.6.4.2 yamt i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, xs, y, xd, y, width,
707 1.6.4.2 yamt height, CR_COPY);
708 1.6.4.2 yamt }
709 1.6.4.2 yamt
710 1.6.4.2 yamt static void
711 1.6.4.2 yamt agten_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
712 1.6.4.2 yamt {
713 1.6.4.2 yamt struct rasops_info *ri = cookie;
714 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
715 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
716 1.6.4.2 yamt int32_t x, y, width, height, bg;
717 1.6.4.2 yamt
718 1.6.4.2 yamt x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
719 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
720 1.6.4.2 yamt width = ri->ri_font->fontwidth * ncols;
721 1.6.4.2 yamt height = ri->ri_font->fontheight;
722 1.6.4.2 yamt bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
723 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
724 1.6.4.2 yamt }
725 1.6.4.2 yamt
726 1.6.4.2 yamt static void
727 1.6.4.2 yamt agten_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
728 1.6.4.2 yamt {
729 1.6.4.2 yamt struct rasops_info *ri = cookie;
730 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
731 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
732 1.6.4.2 yamt int32_t x, ys, yd, width, height;
733 1.6.4.2 yamt
734 1.6.4.2 yamt x = ri->ri_xorigin;
735 1.6.4.2 yamt ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
736 1.6.4.2 yamt yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
737 1.6.4.2 yamt width = ri->ri_emuwidth;
738 1.6.4.2 yamt height = ri->ri_font->fontheight * nrows;
739 1.6.4.2 yamt i128_bitblt(sc->sc_bustag, sc->sc_i128_regh, x, ys, x, yd, width,
740 1.6.4.2 yamt height, CR_COPY);
741 1.6.4.2 yamt }
742 1.6.4.2 yamt
743 1.6.4.2 yamt static void
744 1.6.4.2 yamt agten_eraserows(void *cookie, int row, int nrows, long fillattr)
745 1.6.4.2 yamt {
746 1.6.4.2 yamt struct rasops_info *ri = cookie;
747 1.6.4.2 yamt struct vcons_screen *scr = ri->ri_hw;
748 1.6.4.2 yamt struct agten_softc *sc = scr->scr_cookie;
749 1.6.4.2 yamt int32_t x, y, width, height, bg;
750 1.6.4.2 yamt
751 1.6.4.2 yamt if ((row == 0) && (nrows == ri->ri_rows)) {
752 1.6.4.2 yamt x = y = 0;
753 1.6.4.2 yamt width = ri->ri_width;
754 1.6.4.2 yamt height = ri->ri_height;
755 1.6.4.2 yamt } else {
756 1.6.4.2 yamt x = ri->ri_xorigin;
757 1.6.4.2 yamt y = ri->ri_yorigin + ri->ri_font->fontheight * row;
758 1.6.4.2 yamt width = ri->ri_emuwidth;
759 1.6.4.2 yamt height = ri->ri_font->fontheight * nrows;
760 1.6.4.2 yamt }
761 1.6.4.2 yamt bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
762 1.6.4.2 yamt i128_rectfill(sc->sc_bustag, sc->sc_i128_regh, x, y, width, height, bg);
763 1.6.4.2 yamt }
764 1.6.4.2 yamt
765 1.6.4.2 yamt static void
766 1.6.4.2 yamt agten_move_cursor(struct agten_softc *sc, int x, int y)
767 1.6.4.2 yamt {
768 1.6.4.2 yamt
769 1.6.4.2 yamt sc->sc_cursor_x = x;
770 1.6.4.2 yamt sc->sc_cursor_y = y;
771 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_X_REG);
772 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, x & 0xff);
773 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (x >> 8) & 0xff);
774 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, y & 0xff);
775 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (y >> 8) & 0xff);
776 1.6.4.2 yamt }
777 1.6.4.2 yamt
778 1.6.4.2 yamt static int
779 1.6.4.2 yamt agten_do_cursor(struct agten_softc *sc, struct wsdisplay_cursor *cur)
780 1.6.4.2 yamt {
781 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
782 1.6.4.2 yamt
783 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURS_CNTL_REG);
784 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->enable ?
785 1.6.4.2 yamt CURS_ENABLE : 0);
786 1.6.4.2 yamt }
787 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
788 1.6.4.2 yamt
789 1.6.4.2 yamt agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
790 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.x);
791 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.y);
792 1.6.4.2 yamt }
793 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
794 1.6.4.2 yamt
795 1.6.4.2 yamt agten_move_cursor(sc, cur->pos.x, cur->pos.y);
796 1.6.4.2 yamt }
797 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
798 1.6.4.2 yamt int i;
799 1.6.4.2 yamt
800 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
801 1.6.4.2 yamt for (i = 0; i < cur->cmap.count; i++) {
802 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
803 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
804 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
805 1.6.4.2 yamt }
806 1.6.4.2 yamt }
807 1.6.4.2 yamt if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
808 1.6.4.2 yamt int i;
809 1.6.4.2 yamt uint16_t tmp;
810 1.6.4.2 yamt
811 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_BITMAP);
812 1.6.4.2 yamt for (i = 0; i < 512; i++) {
813 1.6.4.2 yamt tmp = util_interleave(cur->mask[i], cur->image[i]);
814 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
815 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
816 1.6.4.2 yamt }
817 1.6.4.2 yamt }
818 1.6.4.2 yamt return 0;
819 1.6.4.2 yamt }
820 1.6.4.2 yamt
821 1.6.4.2 yamt static int
822 1.6.4.2 yamt agten_do_sun_cursor(struct agten_softc *sc, struct fbcursor *cur)
823 1.6.4.2 yamt {
824 1.6.4.2 yamt if (cur->set & FB_CUR_SETCUR) {
825 1.6.4.2 yamt
826 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURS_CNTL_REG);
827 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->enable ?
828 1.6.4.2 yamt CURS_ENABLE : 0);
829 1.6.4.2 yamt }
830 1.6.4.2 yamt if (cur->set & FB_CUR_SETHOT) {
831 1.6.4.2 yamt
832 1.6.4.2 yamt agten_write_idx(sc, IBM561_HOTSPOT_X_REG);
833 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.x);
834 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, cur->hot.y);
835 1.6.4.2 yamt }
836 1.6.4.2 yamt if (cur->set & FB_CUR_SETPOS) {
837 1.6.4.2 yamt
838 1.6.4.2 yamt agten_move_cursor(sc, cur->pos.x, cur->pos.y);
839 1.6.4.2 yamt }
840 1.6.4.2 yamt if (cur->set & FB_CUR_SETCMAP) {
841 1.6.4.2 yamt int i;
842 1.6.4.2 yamt
843 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_LUT + cur->cmap.index + 2);
844 1.6.4.2 yamt for (i = 0; i < cur->cmap.count; i++) {
845 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.red[i]);
846 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.green[i]);
847 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD_CMAP, cur->cmap.blue[i]);
848 1.6.4.2 yamt }
849 1.6.4.2 yamt }
850 1.6.4.2 yamt if (cur->set & FB_CUR_SETSHAPE) {
851 1.6.4.2 yamt int i;
852 1.6.4.2 yamt uint16_t tmp;
853 1.6.4.2 yamt
854 1.6.4.2 yamt agten_write_idx(sc, IBM561_CURSOR_BITMAP);
855 1.6.4.2 yamt for (i = 0; i < 512; i++) {
856 1.6.4.2 yamt tmp = util_interleave_lin(cur->mask[i], cur->image[i]);
857 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, (tmp >> 8) & 0xff);
858 1.6.4.2 yamt agten_write_dac(sc, IBM561_CMD, tmp & 0xff);
859 1.6.4.2 yamt }
860 1.6.4.2 yamt }
861 1.6.4.2 yamt return 0;
862 1.6.4.2 yamt }
863 1.6.4.2 yamt
864 1.6.4.2 yamt uint16_t
865 1.6.4.2 yamt util_interleave(uint8_t b1, uint8_t b2)
866 1.6.4.2 yamt {
867 1.6.4.2 yamt int i;
868 1.6.4.2 yamt uint16_t ret = 0;
869 1.6.4.2 yamt uint16_t mask = 0x8000;
870 1.6.4.2 yamt uint8_t mask8 = 0x01;
871 1.6.4.2 yamt
872 1.6.4.2 yamt for (i = 0; i < 8; i++) {
873 1.6.4.2 yamt if (b1 & mask8)
874 1.6.4.2 yamt ret |= mask;
875 1.6.4.2 yamt mask = mask >> 1;
876 1.6.4.2 yamt if (b2 & mask8)
877 1.6.4.2 yamt ret |= mask;
878 1.6.4.2 yamt mask = mask >> 1;
879 1.6.4.2 yamt mask8 = mask8 << 1;
880 1.6.4.2 yamt }
881 1.6.4.2 yamt return ret;
882 1.6.4.2 yamt }
883 1.6.4.2 yamt
884 1.6.4.2 yamt uint16_t
885 1.6.4.2 yamt util_interleave_lin(uint8_t b1, uint8_t b2)
886 1.6.4.2 yamt {
887 1.6.4.2 yamt int i;
888 1.6.4.2 yamt uint16_t ret = 0;
889 1.6.4.2 yamt uint16_t mask = 0x8000;
890 1.6.4.2 yamt uint8_t mask8 = 0x80;
891 1.6.4.2 yamt
892 1.6.4.2 yamt for (i = 0; i < 8; i++) {
893 1.6.4.2 yamt if (b1 & mask8)
894 1.6.4.2 yamt ret |= mask;
895 1.6.4.2 yamt mask = mask >> 1;
896 1.6.4.2 yamt if (b2 & mask8)
897 1.6.4.2 yamt ret |= mask;
898 1.6.4.2 yamt mask = mask >> 1;
899 1.6.4.2 yamt mask8 = mask8 >> 1;
900 1.6.4.2 yamt }
901 1.6.4.2 yamt return ret;
902 1.6.4.2 yamt }
903 1.6.4.2 yamt
904 1.6.4.2 yamt /* and now the /dev/fb* stuff */
905 1.6.4.2 yamt static void
906 1.6.4.2 yamt agten_fb_unblank(struct device *dev)
907 1.6.4.2 yamt {
908 1.6.4.2 yamt struct agten_softc *sc = (void *)dev;
909 1.6.4.2 yamt
910 1.6.4.2 yamt agten_init(sc);
911 1.6.4.2 yamt agten_set_video(sc, 1);
912 1.6.4.2 yamt }
913 1.6.4.2 yamt
914 1.6.4.2 yamt static int
915 1.6.4.2 yamt agten_fb_open(dev_t dev, int flags, int mode, struct lwp *l)
916 1.6.4.2 yamt {
917 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
918 1.6.4.2 yamt int unit = minor(dev);
919 1.6.4.2 yamt
920 1.6.4.2 yamt if (unit >= agten_cd.cd_ndevs || agten_cd.cd_devs[unit] == NULL)
921 1.6.4.2 yamt return (ENXIO);
922 1.6.4.2 yamt if (sc->sc_fb_is_open)
923 1.6.4.2 yamt return 0;
924 1.6.4.2 yamt
925 1.6.4.2 yamt sc->sc_fb_is_open++;
926 1.6.4.2 yamt agten_gfx(sc);
927 1.6.4.2 yamt
928 1.6.4.2 yamt return (0);
929 1.6.4.2 yamt }
930 1.6.4.2 yamt
931 1.6.4.2 yamt static int
932 1.6.4.2 yamt agten_fb_close(dev_t dev, int flags, int mode, struct lwp *l)
933 1.6.4.2 yamt {
934 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
935 1.6.4.2 yamt
936 1.6.4.2 yamt sc->sc_fb_is_open--;
937 1.6.4.2 yamt if (sc->sc_fb_is_open < 0)
938 1.6.4.2 yamt sc->sc_fb_is_open = 0;
939 1.6.4.2 yamt
940 1.6.4.2 yamt if (sc->sc_fb_is_open == 0) {
941 1.6.4.2 yamt agten_init(sc);
942 1.6.4.2 yamt vcons_redraw_screen(sc->vd.active);
943 1.6.4.2 yamt }
944 1.6.4.2 yamt
945 1.6.4.2 yamt return (0);
946 1.6.4.2 yamt }
947 1.6.4.2 yamt
948 1.6.4.2 yamt static int
949 1.6.4.2 yamt agten_fb_ioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
950 1.6.4.2 yamt {
951 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
952 1.6.4.2 yamt struct fbgattr *fba;
953 1.6.4.2 yamt int error;
954 1.6.4.2 yamt
955 1.6.4.2 yamt switch (cmd) {
956 1.6.4.2 yamt
957 1.6.4.2 yamt case FBIOGTYPE:
958 1.6.4.2 yamt *(struct fbtype *)data = sc->sc_fb.fb_type;
959 1.6.4.2 yamt break;
960 1.6.4.2 yamt
961 1.6.4.2 yamt case FBIOGATTR:
962 1.6.4.2 yamt fba = (struct fbgattr *)data;
963 1.6.4.2 yamt fba->real_type = sc->sc_fb.fb_type.fb_type;
964 1.6.4.2 yamt fba->owner = 0; /* XXX ??? */
965 1.6.4.2 yamt fba->fbtype = sc->sc_fb.fb_type;
966 1.6.4.2 yamt fba->sattr.flags = 0;
967 1.6.4.2 yamt fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
968 1.6.4.2 yamt fba->sattr.dev_specific[0] = -1;
969 1.6.4.2 yamt fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
970 1.6.4.2 yamt fba->emu_types[1] = -1;
971 1.6.4.2 yamt break;
972 1.6.4.2 yamt
973 1.6.4.2 yamt case FBIOGETCMAP:
974 1.6.4.2 yamt #define p ((struct fbcmap *)data)
975 1.6.4.2 yamt return (bt_getcmap(p, &sc->sc_cmap, 256, 1));
976 1.6.4.2 yamt
977 1.6.4.2 yamt case FBIOPUTCMAP:
978 1.6.4.2 yamt /* copy to software map */
979 1.6.4.2 yamt error = bt_putcmap(p, &sc->sc_cmap, 256, 1);
980 1.6.4.2 yamt if (error)
981 1.6.4.2 yamt return (error);
982 1.6.4.2 yamt /* now blast them into the chip */
983 1.6.4.2 yamt /* don't bother - we're 24bit */
984 1.6.4.2 yamt #undef p
985 1.6.4.2 yamt break;
986 1.6.4.2 yamt
987 1.6.4.2 yamt case FBIOGVIDEO:
988 1.6.4.2 yamt *(int *)data = agten_get_video(sc);
989 1.6.4.2 yamt break;
990 1.6.4.2 yamt
991 1.6.4.2 yamt case FBIOSVIDEO:
992 1.6.4.2 yamt agten_set_video(sc, *(int *)data);
993 1.6.4.2 yamt break;
994 1.6.4.2 yamt
995 1.6.4.2 yamt /* these are for both FBIOSCURSOR and FBIOGCURSOR */
996 1.6.4.2 yamt #define p ((struct fbcursor *)data)
997 1.6.4.2 yamt #define pc (&sc->sc_cursor)
998 1.6.4.2 yamt
999 1.6.4.2 yamt case FBIOGCURSOR:
1000 1.6.4.2 yamt /* does anyone use this ioctl?! */
1001 1.6.4.2 yamt p->set = FB_CUR_SETALL; /* close enough, anyway */
1002 1.6.4.2 yamt p->enable = 1;
1003 1.6.4.2 yamt p->pos.x = sc->sc_cursor_x;
1004 1.6.4.2 yamt p->pos.y = sc->sc_cursor_y;
1005 1.6.4.2 yamt p->size.x = 64;
1006 1.6.4.2 yamt p->size.y = 64;
1007 1.6.4.2 yamt break;
1008 1.6.4.2 yamt
1009 1.6.4.2 yamt case FBIOSCURSOR:
1010 1.6.4.2 yamt agten_do_sun_cursor(sc, p);
1011 1.6.4.2 yamt break;
1012 1.6.4.2 yamt
1013 1.6.4.2 yamt #undef p
1014 1.6.4.2 yamt #undef cc
1015 1.6.4.2 yamt
1016 1.6.4.2 yamt case FBIOGCURPOS:
1017 1.6.4.2 yamt {
1018 1.6.4.2 yamt struct fbcurpos *cp = (struct fbcurpos *)data;
1019 1.6.4.2 yamt cp->x = sc->sc_cursor_x;
1020 1.6.4.2 yamt cp->y = sc->sc_cursor_y;
1021 1.6.4.2 yamt }
1022 1.6.4.2 yamt break;
1023 1.6.4.2 yamt
1024 1.6.4.2 yamt case FBIOSCURPOS:
1025 1.6.4.2 yamt {
1026 1.6.4.2 yamt struct fbcurpos *cp = (struct fbcurpos *)data;
1027 1.6.4.2 yamt agten_move_cursor(sc, cp->x, cp->y);
1028 1.6.4.2 yamt }
1029 1.6.4.2 yamt break;
1030 1.6.4.2 yamt
1031 1.6.4.2 yamt case FBIOGCURMAX:
1032 1.6.4.2 yamt /* max cursor size is 64x64 */
1033 1.6.4.2 yamt ((struct fbcurpos *)data)->x = 64;
1034 1.6.4.2 yamt ((struct fbcurpos *)data)->y = 64;
1035 1.6.4.2 yamt break;
1036 1.6.4.2 yamt
1037 1.6.4.2 yamt default:
1038 1.6.4.2 yamt return (ENOTTY);
1039 1.6.4.2 yamt }
1040 1.6.4.2 yamt return (0);
1041 1.6.4.2 yamt }
1042 1.6.4.2 yamt
1043 1.6.4.2 yamt static paddr_t
1044 1.6.4.2 yamt agten_fb_mmap(dev_t dev, off_t off, int prot)
1045 1.6.4.2 yamt {
1046 1.6.4.2 yamt struct agten_softc *sc = agten_cd.cd_devs[minor(dev)];
1047 1.6.4.2 yamt
1048 1.6.4.2 yamt /*
1049 1.6.4.2 yamt * mappings are subject to change
1050 1.6.4.2 yamt * for now we put the framebuffer at offset 0 and the GLint registers
1051 1.6.4.2 yamt * right after that. We may want to expose more register ranges and
1052 1.6.4.2 yamt * probably will want to map the 2nd framebuffer as well
1053 1.6.4.2 yamt */
1054 1.6.4.2 yamt
1055 1.6.4.2 yamt if (off < 0)
1056 1.6.4.2 yamt return EINVAL;
1057 1.6.4.2 yamt
1058 1.6.4.2 yamt if (off >= sc->sc_glint_fbsz + 0x10000)
1059 1.6.4.2 yamt return EINVAL;
1060 1.6.4.2 yamt
1061 1.6.4.2 yamt if (off < sc->sc_glint_fbsz) {
1062 1.6.4.2 yamt return (bus_space_mmap(sc->sc_bustag,
1063 1.6.4.2 yamt sc->sc_glint_fb,
1064 1.6.4.2 yamt off,
1065 1.6.4.2 yamt prot,
1066 1.6.4.2 yamt BUS_SPACE_MAP_LINEAR));
1067 1.6.4.2 yamt }
1068 1.6.4.2 yamt
1069 1.6.4.2 yamt off -= sc->sc_glint_fbsz;
1070 1.6.4.2 yamt if (off < 0x10000) {
1071 1.6.4.2 yamt return (bus_space_mmap(sc->sc_bustag,
1072 1.6.4.2 yamt sc->sc_glint_regs,
1073 1.6.4.2 yamt off,
1074 1.6.4.2 yamt prot,
1075 1.6.4.2 yamt BUS_SPACE_MAP_LINEAR));
1076 1.6.4.2 yamt }
1077 1.6.4.2 yamt return EINVAL;
1078 1.6.4.2 yamt }
1079