unichromefb.c revision 1.4.4.2 1 1.4.4.2 rpaulo /* $NetBSD: unichromefb.c,v 1.4.4.2 2006/09/09 02:52:19 rpaulo Exp $ */
2 1.4.4.2 rpaulo
3 1.4.4.2 rpaulo /*-
4 1.4.4.2 rpaulo * Copyright (c) 2006 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.4.4.2 rpaulo * All rights reserved.
6 1.4.4.2 rpaulo *
7 1.4.4.2 rpaulo * Redistribution and use in source and binary forms, with or without
8 1.4.4.2 rpaulo * modification, are permitted provided that the following conditions
9 1.4.4.2 rpaulo * are met:
10 1.4.4.2 rpaulo * 1. Redistributions of source code must retain the above copyright
11 1.4.4.2 rpaulo * notice, this list of conditions and the following disclaimer.
12 1.4.4.2 rpaulo * 2. Redistributions in binary form must reproduce the above copyright
13 1.4.4.2 rpaulo * notice, this list of conditions and the following disclaimer in the
14 1.4.4.2 rpaulo * documentation and/or other materials provided with the distribution.
15 1.4.4.2 rpaulo * 3. All advertising materials mentioning features or use of this software
16 1.4.4.2 rpaulo * must display the following acknowledgement:
17 1.4.4.2 rpaulo * This product includes software developed by Jared D. McNeill.
18 1.4.4.2 rpaulo * 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.4.4.2 rpaulo * contributors may be used to endorse or promote products derived
20 1.4.4.2 rpaulo * from this software without specific prior written permission.
21 1.4.4.2 rpaulo *
22 1.4.4.2 rpaulo * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.4.4.2 rpaulo * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.4.4.2 rpaulo * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.4.4.2 rpaulo * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.4.4.2 rpaulo * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.4.4.2 rpaulo * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.4.4.2 rpaulo * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.4.4.2 rpaulo * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.4.4.2 rpaulo * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.4.4.2 rpaulo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.4.4.2 rpaulo * POSSIBILITY OF SUCH DAMAGE.
33 1.4.4.2 rpaulo */
34 1.4.4.2 rpaulo
35 1.4.4.2 rpaulo /*
36 1.4.4.2 rpaulo * Copyright 1998-2006 VIA Technologies, Inc. All Rights Reserved.
37 1.4.4.2 rpaulo * Copyright 2001-2006 S3 Graphics, Inc. All Rights Reserved.
38 1.4.4.2 rpaulo *
39 1.4.4.2 rpaulo * Permission is hereby granted, free of charge, to any person obtaining a
40 1.4.4.2 rpaulo * copy of this software and associated documentation files (the "Software"),
41 1.4.4.2 rpaulo * to deal in the Software without restriction, including without limitation
42 1.4.4.2 rpaulo * the rights to use, copy, modify, merge, publish, distribute, sub license,
43 1.4.4.2 rpaulo * and/or sell copies of the Software, and to permit persons to whom the
44 1.4.4.2 rpaulo * Software is furnished to do so, subject to the following conditions:
45 1.4.4.2 rpaulo *
46 1.4.4.2 rpaulo * The above copyright notice and this permission notice (including the
47 1.4.4.2 rpaulo * next paragraph) shall be included in all copies or substantial portions
48 1.4.4.2 rpaulo * of the Software.
49 1.4.4.2 rpaulo *
50 1.4.4.2 rpaulo * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
51 1.4.4.2 rpaulo * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
52 1.4.4.2 rpaulo * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
53 1.4.4.2 rpaulo * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
54 1.4.4.2 rpaulo * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
55 1.4.4.2 rpaulo * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
56 1.4.4.2 rpaulo * DEALINGS IN THE SOFTWARE.
57 1.4.4.2 rpaulo */
58 1.4.4.2 rpaulo
59 1.4.4.2 rpaulo #include <sys/cdefs.h>
60 1.4.4.2 rpaulo __KERNEL_RCSID(0, "$NetBSD: unichromefb.c,v 1.4.4.2 2006/09/09 02:52:19 rpaulo Exp $");
61 1.4.4.2 rpaulo
62 1.4.4.2 rpaulo #include <sys/param.h>
63 1.4.4.2 rpaulo #include <sys/systm.h>
64 1.4.4.2 rpaulo #include <sys/device.h>
65 1.4.4.2 rpaulo #include <sys/malloc.h>
66 1.4.4.2 rpaulo
67 1.4.4.2 rpaulo #include <machine/bus.h>
68 1.4.4.2 rpaulo
69 1.4.4.2 rpaulo #include <dev/pci/pcivar.h>
70 1.4.4.2 rpaulo #include <dev/pci/pcireg.h>
71 1.4.4.2 rpaulo #include <dev/pci/pcidevs.h>
72 1.4.4.2 rpaulo
73 1.4.4.2 rpaulo #include <dev/wscons/wsdisplayvar.h>
74 1.4.4.2 rpaulo #include <dev/wscons/wsconsio.h>
75 1.4.4.2 rpaulo #include <dev/wsfont/wsfont.h>
76 1.4.4.2 rpaulo #include <dev/rasops/rasops.h>
77 1.4.4.2 rpaulo #include <dev/wscons/wsdisplay_vconsvar.h>
78 1.4.4.2 rpaulo
79 1.4.4.2 rpaulo #include <dev/pci/unichromereg.h>
80 1.4.4.2 rpaulo #include <dev/pci/unichromemode.h>
81 1.4.4.2 rpaulo #include <dev/pci/unichromehw.h>
82 1.4.4.2 rpaulo #include <dev/pci/unichromeconfig.h>
83 1.4.4.2 rpaulo #include <dev/pci/unichromeaccel.h>
84 1.4.4.2 rpaulo
85 1.4.4.2 rpaulo #include "vga.h"
86 1.4.4.2 rpaulo
87 1.4.4.2 rpaulo #if NVGA > 0
88 1.4.4.2 rpaulo #include <dev/ic/mc6845reg.h>
89 1.4.4.2 rpaulo #include <dev/ic/pcdisplayvar.h>
90 1.4.4.2 rpaulo #include <dev/ic/vgareg.h>
91 1.4.4.2 rpaulo #include <dev/ic/vgavar.h>
92 1.4.4.2 rpaulo #endif
93 1.4.4.2 rpaulo
94 1.4.4.2 rpaulo /* XXX */
95 1.4.4.2 rpaulo #define UNICHROMEFB_DEPTH 16
96 1.4.4.2 rpaulo #define UNICHROMEFB_MODE VIA_RES_1280X1024
97 1.4.4.2 rpaulo #define UNICHROMEFB_WIDTH 1280
98 1.4.4.2 rpaulo #define UNICHROMEFB_HEIGHT 1024
99 1.4.4.2 rpaulo
100 1.4.4.2 rpaulo struct unichromefb_softc {
101 1.4.4.2 rpaulo struct device sc_dev;
102 1.4.4.2 rpaulo struct vcons_data sc_vd;
103 1.4.4.2 rpaulo void * sc_fbbase;
104 1.4.4.2 rpaulo unsigned int sc_fbaddr;
105 1.4.4.2 rpaulo unsigned int sc_fbsize;
106 1.4.4.2 rpaulo
107 1.4.4.2 rpaulo bus_space_tag_t sc_iot;
108 1.4.4.2 rpaulo bus_space_handle_t sc_ioh;
109 1.4.4.2 rpaulo
110 1.4.4.2 rpaulo bus_space_tag_t sc_memt;
111 1.4.4.2 rpaulo bus_space_handle_t sc_memh;
112 1.4.4.2 rpaulo
113 1.4.4.2 rpaulo int sc_width;
114 1.4.4.2 rpaulo int sc_height;
115 1.4.4.2 rpaulo int sc_depth;
116 1.4.4.2 rpaulo int sc_stride;
117 1.4.4.2 rpaulo
118 1.4.4.2 rpaulo int sc_wsmode;
119 1.4.4.2 rpaulo
120 1.4.4.2 rpaulo int sc_accel;
121 1.4.4.2 rpaulo };
122 1.4.4.2 rpaulo
123 1.4.4.2 rpaulo static int unichromefb_match(struct device *, struct cfdata *, void *);
124 1.4.4.2 rpaulo static void unichromefb_attach(struct device *, struct device *, void *);
125 1.4.4.2 rpaulo
126 1.4.4.2 rpaulo struct wsscreen_descr unichromefb_stdscreen = {
127 1.4.4.2 rpaulo "fb",
128 1.4.4.2 rpaulo 0, 0,
129 1.4.4.2 rpaulo NULL,
130 1.4.4.2 rpaulo 8, 16,
131 1.4.4.2 rpaulo };
132 1.4.4.2 rpaulo
133 1.4.4.2 rpaulo static int unichromefb_ioctl(void *, void *, u_long, caddr_t, int,
134 1.4.4.2 rpaulo struct lwp *);
135 1.4.4.2 rpaulo static paddr_t unichromefb_mmap(void *, void *, off_t, int);
136 1.4.4.2 rpaulo
137 1.4.4.2 rpaulo static void unichromefb_init_screen(void *, struct vcons_screen *,
138 1.4.4.2 rpaulo int, long *);
139 1.4.4.2 rpaulo
140 1.4.4.2 rpaulo /* hardware access */
141 1.4.4.2 rpaulo static uint8_t uni_rd(struct unichromefb_softc *, int, uint8_t);
142 1.4.4.2 rpaulo static void uni_wr(struct unichromefb_softc *, int, uint8_t, uint8_t);
143 1.4.4.2 rpaulo static void uni_wr_mask(struct unichromefb_softc *, int, uint8_t,
144 1.4.4.2 rpaulo uint8_t, uint8_t);
145 1.4.4.2 rpaulo static void uni_wr_x(struct unichromefb_softc *, struct io_reg *, int);
146 1.4.4.2 rpaulo static void uni_wr_dac(struct unichromefb_softc *, uint8_t, uint8_t,
147 1.4.4.2 rpaulo uint8_t, uint8_t);
148 1.4.4.2 rpaulo
149 1.4.4.2 rpaulo /* helpers */
150 1.4.4.2 rpaulo static struct VideoModeTable * uni_getmode(int);
151 1.4.4.2 rpaulo static void uni_setmode(struct unichromefb_softc *, int, int);
152 1.4.4.2 rpaulo static void uni_crt_lock(struct unichromefb_softc *);
153 1.4.4.2 rpaulo static void uni_crt_unlock(struct unichromefb_softc *);
154 1.4.4.2 rpaulo static void uni_crt_enable(struct unichromefb_softc *);
155 1.4.4.2 rpaulo static void uni_crt_disable(struct unichromefb_softc *);
156 1.4.4.2 rpaulo static void uni_screen_enable(struct unichromefb_softc *);
157 1.4.4.2 rpaulo static void uni_screen_disable(struct unichromefb_softc *);
158 1.4.4.2 rpaulo static void uni_set_start(struct unichromefb_softc *);
159 1.4.4.2 rpaulo static void uni_set_crtc(struct unichromefb_softc *,
160 1.4.4.2 rpaulo struct crt_mode_table *, int, int, int);
161 1.4.4.2 rpaulo static void uni_load_crtc(struct unichromefb_softc *, struct display_timing,
162 1.4.4.2 rpaulo int);
163 1.4.4.2 rpaulo static void uni_load_reg(struct unichromefb_softc *, int, int,
164 1.4.4.2 rpaulo struct io_register *, int);
165 1.4.4.2 rpaulo static void uni_fix_crtc(struct unichromefb_softc *);
166 1.4.4.2 rpaulo static void uni_load_offset(struct unichromefb_softc *, int, int, int);
167 1.4.4.2 rpaulo static void uni_load_fetchcnt(struct unichromefb_softc *, int, int, int);
168 1.4.4.2 rpaulo static void uni_load_fifo(struct unichromefb_softc *, int, int, int);
169 1.4.4.2 rpaulo static void uni_set_depth(struct unichromefb_softc *, int, int);
170 1.4.4.2 rpaulo static uint32_t uni_get_clkval(struct unichromefb_softc *, int);
171 1.4.4.2 rpaulo static void uni_set_vclk(struct unichromefb_softc *, uint32_t, int);
172 1.4.4.2 rpaulo static void uni_init_dac(struct unichromefb_softc *, int);
173 1.4.4.2 rpaulo static void uni_init_accel(struct unichromefb_softc *);
174 1.4.4.2 rpaulo static void uni_set_accel_depth(struct unichromefb_softc *);
175 1.4.4.2 rpaulo
176 1.4.4.2 rpaulo /* graphics ops */
177 1.4.4.2 rpaulo static void uni_wait_idle(struct unichromefb_softc *);
178 1.4.4.2 rpaulo static void uni_fillrect(struct unichromefb_softc *,
179 1.4.4.2 rpaulo int, int, int, int, int);
180 1.4.4.2 rpaulo static void uni_rectinvert(struct unichromefb_softc *,
181 1.4.4.2 rpaulo int, int, int, int);
182 1.4.4.2 rpaulo static void uni_bitblit(struct unichromefb_softc *, int, int, int, int,
183 1.4.4.2 rpaulo int, int);
184 1.4.4.2 rpaulo static void uni_setup_mono(struct unichromefb_softc *, int, int, int,
185 1.4.4.2 rpaulo int, uint32_t, uint32_t);
186 1.4.4.2 rpaulo #if notyet
187 1.4.4.2 rpaulo static void uni_cursor_show(struct unichromefb_softc *);
188 1.4.4.2 rpaulo static void uni_cursor_hide(struct unichromefb_softc *);
189 1.4.4.2 rpaulo #endif
190 1.4.4.2 rpaulo
191 1.4.4.2 rpaulo /* rasops glue */
192 1.4.4.2 rpaulo static void uni_copycols(void *, int, int, int, int);
193 1.4.4.2 rpaulo static void uni_copyrows(void *, int, int, int);
194 1.4.4.2 rpaulo static void uni_erasecols(void *, int, int, int, long);
195 1.4.4.2 rpaulo static void uni_eraserows(void *, int, int, long);
196 1.4.4.2 rpaulo static void uni_cursor(void *, int, int, int);
197 1.4.4.2 rpaulo static void uni_putchar(void *, int, int, u_int, long);
198 1.4.4.2 rpaulo
199 1.4.4.2 rpaulo struct wsdisplay_accessops unichromefb_accessops = {
200 1.4.4.2 rpaulo unichromefb_ioctl,
201 1.4.4.2 rpaulo unichromefb_mmap,
202 1.4.4.2 rpaulo NULL,
203 1.4.4.2 rpaulo NULL,
204 1.4.4.2 rpaulo NULL,
205 1.4.4.2 rpaulo NULL,
206 1.4.4.2 rpaulo };
207 1.4.4.2 rpaulo
208 1.4.4.2 rpaulo static struct vcons_screen unichromefb_console_screen;
209 1.4.4.2 rpaulo
210 1.4.4.2 rpaulo const struct wsscreen_descr *_unichromefb_scrlist[] = {
211 1.4.4.2 rpaulo &unichromefb_stdscreen,
212 1.4.4.2 rpaulo };
213 1.4.4.2 rpaulo
214 1.4.4.2 rpaulo struct wsscreen_list unichromefb_screenlist = {
215 1.4.4.2 rpaulo sizeof(_unichromefb_scrlist) / sizeof(struct wsscreen_descr *),
216 1.4.4.2 rpaulo _unichromefb_scrlist
217 1.4.4.2 rpaulo };
218 1.4.4.2 rpaulo
219 1.4.4.2 rpaulo CFATTACH_DECL(unichromefb, sizeof(struct unichromefb_softc),
220 1.4.4.2 rpaulo unichromefb_match, unichromefb_attach, NULL, NULL);
221 1.4.4.2 rpaulo
222 1.4.4.2 rpaulo static int
223 1.4.4.2 rpaulo unichromefb_match(struct device *parent, struct cfdata *match, void *opaque)
224 1.4.4.2 rpaulo {
225 1.4.4.2 rpaulo struct pci_attach_args *pa;
226 1.4.4.2 rpaulo
227 1.4.4.2 rpaulo pa = (struct pci_attach_args *)opaque;
228 1.4.4.2 rpaulo
229 1.4.4.2 rpaulo if (PCI_CLASS(pa->pa_class) != PCI_CLASS_DISPLAY ||
230 1.4.4.2 rpaulo PCI_SUBCLASS(pa->pa_class) != PCI_SUBCLASS_DISPLAY_VGA)
231 1.4.4.2 rpaulo return 0;
232 1.4.4.2 rpaulo
233 1.4.4.2 rpaulo if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_VIATECH)
234 1.4.4.2 rpaulo return 0;
235 1.4.4.2 rpaulo
236 1.4.4.2 rpaulo switch (PCI_PRODUCT(pa->pa_id)) {
237 1.4.4.2 rpaulo case PCI_PRODUCT_VIATECH_VT3314_IG:
238 1.4.4.2 rpaulo return 10; /* beat vga(4) */
239 1.4.4.2 rpaulo }
240 1.4.4.2 rpaulo
241 1.4.4.2 rpaulo return 0;
242 1.4.4.2 rpaulo }
243 1.4.4.2 rpaulo
244 1.4.4.2 rpaulo static void
245 1.4.4.2 rpaulo unichromefb_attach(struct device *parent, struct device *self, void *opaque)
246 1.4.4.2 rpaulo {
247 1.4.4.2 rpaulo struct unichromefb_softc *sc;
248 1.4.4.2 rpaulo struct pci_attach_args *pa;
249 1.4.4.2 rpaulo struct rasops_info *ri;
250 1.4.4.2 rpaulo struct wsemuldisplaydev_attach_args aa;
251 1.4.4.2 rpaulo bus_space_handle_t ap_memh;
252 1.4.4.2 rpaulo uint8_t val;
253 1.4.4.2 rpaulo bus_addr_t mmiobase;
254 1.4.4.2 rpaulo bus_size_t mmiosize;
255 1.4.4.2 rpaulo long defattr;
256 1.4.4.2 rpaulo
257 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)self;
258 1.4.4.2 rpaulo pa = (struct pci_attach_args *)opaque;
259 1.4.4.2 rpaulo
260 1.4.4.2 rpaulo sc->sc_width = UNICHROMEFB_WIDTH;
261 1.4.4.2 rpaulo sc->sc_height = UNICHROMEFB_HEIGHT;
262 1.4.4.2 rpaulo sc->sc_depth = UNICHROMEFB_DEPTH;
263 1.4.4.2 rpaulo sc->sc_stride = sc->sc_width * (sc->sc_depth / 8);
264 1.4.4.2 rpaulo
265 1.4.4.2 rpaulo sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
266 1.4.4.2 rpaulo
267 1.4.4.2 rpaulo sc->sc_iot = pa->pa_iot;
268 1.4.4.2 rpaulo
269 1.4.4.2 rpaulo #if NVGA > 0
270 1.4.4.2 rpaulo /* XXX vga_cnattach claims the I/O registers that we need;
271 1.4.4.2 rpaulo * we need to nuke it here so we can take over.
272 1.4.4.2 rpaulo */
273 1.4.4.2 rpaulo vga_cndetach();
274 1.4.4.2 rpaulo #endif
275 1.4.4.2 rpaulo
276 1.4.4.2 rpaulo if (bus_space_map(sc->sc_iot, VIA_REGBASE, 0x20, 0, &sc->sc_ioh)) {
277 1.4.4.2 rpaulo aprint_error(": failed to map I/O registers\n");
278 1.4.4.2 rpaulo return;
279 1.4.4.2 rpaulo }
280 1.4.4.2 rpaulo
281 1.4.4.2 rpaulo sc->sc_memt = pa->pa_memt;
282 1.4.4.2 rpaulo val = uni_rd(sc, VIASR, SR30);
283 1.4.4.2 rpaulo sc->sc_fbaddr = val << 24;
284 1.4.4.2 rpaulo val = uni_rd(sc, VIASR, SR39);
285 1.4.4.2 rpaulo sc->sc_fbsize = val * (4*1024*1024);
286 1.4.4.2 rpaulo if (sc->sc_fbsize < 16*1024*1024 || sc->sc_fbsize > 64*1024*1024)
287 1.4.4.2 rpaulo sc->sc_fbsize = 16*1024*1024;
288 1.4.4.2 rpaulo if (bus_space_map(sc->sc_memt, sc->sc_fbaddr, sc->sc_fbsize,
289 1.4.4.2 rpaulo BUS_SPACE_MAP_LINEAR, &ap_memh)) {
290 1.4.4.2 rpaulo aprint_error(": failed to map aperture at 0x%08x/0x%x\n",
291 1.4.4.2 rpaulo sc->sc_fbaddr, sc->sc_fbsize);
292 1.4.4.2 rpaulo return;
293 1.4.4.2 rpaulo }
294 1.4.4.2 rpaulo sc->sc_fbbase = (caddr_t)bus_space_vaddr(sc->sc_memt, ap_memh);
295 1.4.4.2 rpaulo
296 1.4.4.2 rpaulo if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_MEM, 0,
297 1.4.4.2 rpaulo &sc->sc_memt, &sc->sc_memh, &mmiobase, &mmiosize)) {
298 1.4.4.2 rpaulo sc->sc_accel = 0;
299 1.4.4.2 rpaulo aprint_error(": failed to map MMIO registers\n");
300 1.4.4.2 rpaulo } else {
301 1.4.4.2 rpaulo sc->sc_accel = 1;
302 1.4.4.2 rpaulo }
303 1.4.4.2 rpaulo
304 1.4.4.2 rpaulo aprint_naive("\n");
305 1.4.4.2 rpaulo aprint_normal(": VIA UniChrome frame buffer\n");
306 1.4.4.2 rpaulo
307 1.4.4.2 rpaulo if (sc->sc_accel)
308 1.4.4.2 rpaulo aprint_normal("%s: MMIO @0x%08x/0x%x\n",
309 1.4.4.2 rpaulo sc->sc_dev.dv_xname, (uint32_t)mmiobase,
310 1.4.4.2 rpaulo (uint32_t)mmiosize);
311 1.4.4.2 rpaulo
312 1.4.4.2 rpaulo ri = &unichromefb_console_screen.scr_ri;
313 1.4.4.2 rpaulo memset(ri, 0, sizeof(struct rasops_info));
314 1.4.4.2 rpaulo
315 1.4.4.2 rpaulo vcons_init(&sc->sc_vd, sc, &unichromefb_stdscreen,
316 1.4.4.2 rpaulo &unichromefb_accessops);
317 1.4.4.2 rpaulo sc->sc_vd.init_screen = unichromefb_init_screen;
318 1.4.4.2 rpaulo
319 1.4.4.2 rpaulo uni_setmode(sc, UNICHROMEFB_MODE, sc->sc_depth);
320 1.4.4.2 rpaulo
321 1.4.4.2 rpaulo uni_init_dac(sc, IGA1);
322 1.4.4.2 rpaulo if (sc->sc_accel) {
323 1.4.4.2 rpaulo uni_init_accel(sc);
324 1.4.4.2 rpaulo uni_fillrect(sc, 0, 0, sc->sc_width, sc->sc_height, 0);
325 1.4.4.2 rpaulo }
326 1.4.4.2 rpaulo
327 1.4.4.2 rpaulo aprint_normal("%s: FB @0x%08x (%dx%dx%d)\n", sc->sc_dev.dv_xname,
328 1.4.4.2 rpaulo sc->sc_fbaddr, sc->sc_width, sc->sc_height, sc->sc_depth);
329 1.4.4.2 rpaulo
330 1.4.4.2 rpaulo unichromefb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
331 1.4.4.2 rpaulo vcons_init_screen(&sc->sc_vd, &unichromefb_console_screen, 1, &defattr);
332 1.4.4.2 rpaulo
333 1.4.4.2 rpaulo unichromefb_stdscreen.ncols = ri->ri_cols;
334 1.4.4.2 rpaulo unichromefb_stdscreen.nrows = ri->ri_rows;
335 1.4.4.2 rpaulo unichromefb_stdscreen.textops = &ri->ri_ops;
336 1.4.4.2 rpaulo unichromefb_stdscreen.capabilities = ri->ri_caps;
337 1.4.4.2 rpaulo unichromefb_stdscreen.modecookie = NULL;
338 1.4.4.2 rpaulo
339 1.4.4.2 rpaulo wsdisplay_cnattach(&unichromefb_stdscreen, ri, 0, 0, defattr);
340 1.4.4.2 rpaulo
341 1.4.4.2 rpaulo aa.console = 1; /* XXX */
342 1.4.4.2 rpaulo aa.scrdata = &unichromefb_screenlist;
343 1.4.4.2 rpaulo aa.accessops = &unichromefb_accessops;
344 1.4.4.2 rpaulo aa.accesscookie = &sc->sc_vd;
345 1.4.4.2 rpaulo
346 1.4.4.2 rpaulo config_found(self, &aa, wsemuldisplaydevprint);
347 1.4.4.2 rpaulo
348 1.4.4.2 rpaulo return;
349 1.4.4.2 rpaulo }
350 1.4.4.2 rpaulo
351 1.4.4.2 rpaulo static int
352 1.4.4.2 rpaulo unichromefb_ioctl(void *v, void *vs, u_long cmd, caddr_t data, int flag,
353 1.4.4.2 rpaulo struct lwp *l)
354 1.4.4.2 rpaulo {
355 1.4.4.2 rpaulo struct vcons_data *vd;
356 1.4.4.2 rpaulo struct unichromefb_softc *sc;
357 1.4.4.2 rpaulo struct wsdisplay_fbinfo *fb;
358 1.4.4.2 rpaulo
359 1.4.4.2 rpaulo vd = (struct vcons_data *)v;
360 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)vd->cookie;
361 1.4.4.2 rpaulo
362 1.4.4.2 rpaulo switch (cmd) {
363 1.4.4.2 rpaulo case WSDISPLAYIO_GTYPE:
364 1.4.4.2 rpaulo *(u_int *)data = WSDISPLAY_TYPE_PCIMISC;
365 1.4.4.2 rpaulo return 0;
366 1.4.4.2 rpaulo case WSDISPLAYIO_GINFO:
367 1.4.4.2 rpaulo if (vd->active != NULL) {
368 1.4.4.2 rpaulo fb = (struct wsdisplay_fbinfo *)data;
369 1.4.4.2 rpaulo fb->width = sc->sc_width;
370 1.4.4.2 rpaulo fb->height = sc->sc_height;
371 1.4.4.2 rpaulo fb->depth = sc->sc_depth;
372 1.4.4.2 rpaulo fb->cmsize = 256;
373 1.4.4.2 rpaulo return 0;
374 1.4.4.2 rpaulo } else
375 1.4.4.2 rpaulo return ENODEV;
376 1.4.4.2 rpaulo case WSDISPLAYIO_GVIDEO:
377 1.4.4.2 rpaulo return ENODEV;
378 1.4.4.2 rpaulo case WSDISPLAYIO_SVIDEO:
379 1.4.4.2 rpaulo return ENODEV;
380 1.4.4.2 rpaulo case WSDISPLAYIO_GETCMAP:
381 1.4.4.2 rpaulo return EINVAL;
382 1.4.4.2 rpaulo case WSDISPLAYIO_PUTCMAP:
383 1.4.4.2 rpaulo return EINVAL;
384 1.4.4.2 rpaulo case WSDISPLAYIO_LINEBYTES:
385 1.4.4.2 rpaulo *(u_int *)data = sc->sc_stride;
386 1.4.4.2 rpaulo return 0;
387 1.4.4.2 rpaulo case WSDISPLAYIO_SMODE:
388 1.4.4.2 rpaulo {
389 1.4.4.2 rpaulo int new_mode = *(int *)data;
390 1.4.4.2 rpaulo if (new_mode != sc->sc_wsmode) {
391 1.4.4.2 rpaulo sc->sc_wsmode = new_mode;
392 1.4.4.2 rpaulo if (new_mode == WSDISPLAYIO_MODE_EMUL)
393 1.4.4.2 rpaulo vcons_redraw_screen(vd->active);
394 1.4.4.2 rpaulo }
395 1.4.4.2 rpaulo }
396 1.4.4.2 rpaulo return 0;
397 1.4.4.2 rpaulo case WSDISPLAYIO_SSPLASH:
398 1.4.4.2 rpaulo return ENODEV;
399 1.4.4.2 rpaulo case WSDISPLAYIO_SPROGRESS:
400 1.4.4.2 rpaulo return ENODEV;
401 1.4.4.2 rpaulo }
402 1.4.4.2 rpaulo
403 1.4.4.2 rpaulo return EPASSTHROUGH;
404 1.4.4.2 rpaulo }
405 1.4.4.2 rpaulo
406 1.4.4.2 rpaulo static paddr_t
407 1.4.4.2 rpaulo unichromefb_mmap(void *v, void *vs, off_t offset, int prot)
408 1.4.4.2 rpaulo {
409 1.4.4.2 rpaulo return -1;
410 1.4.4.2 rpaulo }
411 1.4.4.2 rpaulo
412 1.4.4.2 rpaulo static void
413 1.4.4.2 rpaulo unichromefb_init_screen(void *c, struct vcons_screen *scr, int existing,
414 1.4.4.2 rpaulo long *defattr)
415 1.4.4.2 rpaulo {
416 1.4.4.2 rpaulo struct unichromefb_softc *sc;
417 1.4.4.2 rpaulo struct rasops_info *ri;
418 1.4.4.2 rpaulo
419 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)c;
420 1.4.4.2 rpaulo ri = &scr->scr_ri;
421 1.4.4.2 rpaulo ri->ri_flg = RI_CENTER;
422 1.4.4.2 rpaulo ri->ri_depth = sc->sc_depth;
423 1.4.4.2 rpaulo ri->ri_width = sc->sc_width;
424 1.4.4.2 rpaulo ri->ri_height = sc->sc_height;
425 1.4.4.2 rpaulo ri->ri_stride = sc->sc_stride;
426 1.4.4.2 rpaulo ri->ri_bits = sc->sc_fbbase;
427 1.4.4.2 rpaulo if (existing)
428 1.4.4.2 rpaulo ri->ri_flg |= RI_CLEAR;
429 1.4.4.2 rpaulo
430 1.4.4.2 rpaulo switch (ri->ri_depth) {
431 1.4.4.2 rpaulo case 32:
432 1.4.4.2 rpaulo ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
433 1.4.4.2 rpaulo ri->ri_rpos = 16;
434 1.4.4.2 rpaulo ri->ri_gpos = 8;
435 1.4.4.2 rpaulo ri->ri_bpos = 0;
436 1.4.4.2 rpaulo break;
437 1.4.4.2 rpaulo case 16:
438 1.4.4.2 rpaulo ri->ri_rnum = 5;
439 1.4.4.2 rpaulo ri->ri_gnum = 6;
440 1.4.4.2 rpaulo ri->ri_bnum = 5;
441 1.4.4.2 rpaulo ri->ri_rpos = 11;
442 1.4.4.2 rpaulo ri->ri_gpos = 5;
443 1.4.4.2 rpaulo ri->ri_bpos = 0;
444 1.4.4.2 rpaulo break;
445 1.4.4.2 rpaulo }
446 1.4.4.2 rpaulo
447 1.4.4.2 rpaulo rasops_init(ri, sc->sc_height / 16, sc->sc_width / 8);
448 1.4.4.2 rpaulo ri->ri_caps = WSSCREEN_WSCOLORS;
449 1.4.4.2 rpaulo rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
450 1.4.4.2 rpaulo sc->sc_width / ri->ri_font->fontwidth);
451 1.4.4.2 rpaulo
452 1.4.4.2 rpaulo ri->ri_hw = scr;
453 1.4.4.2 rpaulo if (sc->sc_accel) {
454 1.4.4.2 rpaulo ri->ri_ops.copyrows = uni_copyrows;
455 1.4.4.2 rpaulo ri->ri_ops.copycols = uni_copycols;
456 1.4.4.2 rpaulo ri->ri_ops.eraserows = uni_eraserows;
457 1.4.4.2 rpaulo ri->ri_ops.erasecols = uni_erasecols;
458 1.4.4.2 rpaulo ri->ri_ops.cursor = uni_cursor;
459 1.4.4.2 rpaulo ri->ri_ops.putchar = uni_putchar;
460 1.4.4.2 rpaulo }
461 1.4.4.2 rpaulo
462 1.4.4.2 rpaulo return;
463 1.4.4.2 rpaulo }
464 1.4.4.2 rpaulo
465 1.4.4.2 rpaulo /*
466 1.4.4.2 rpaulo * hardware access
467 1.4.4.2 rpaulo */
468 1.4.4.2 rpaulo static uint8_t
469 1.4.4.2 rpaulo uni_rd(struct unichromefb_softc *sc, int off, uint8_t idx)
470 1.4.4.2 rpaulo {
471 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, idx);
472 1.4.4.2 rpaulo return bus_space_read_1(sc->sc_iot, sc->sc_ioh, off + 1);
473 1.4.4.2 rpaulo }
474 1.4.4.2 rpaulo
475 1.4.4.2 rpaulo static void
476 1.4.4.2 rpaulo uni_wr(struct unichromefb_softc *sc, int off, uint8_t idx, uint8_t val)
477 1.4.4.2 rpaulo {
478 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, idx);
479 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, off + 1, val);
480 1.4.4.2 rpaulo }
481 1.4.4.2 rpaulo
482 1.4.4.2 rpaulo static void
483 1.4.4.2 rpaulo uni_wr_mask(struct unichromefb_softc *sc, int off, uint8_t idx,
484 1.4.4.2 rpaulo uint8_t val, uint8_t mask)
485 1.4.4.2 rpaulo {
486 1.4.4.2 rpaulo uint8_t tmp;
487 1.4.4.2 rpaulo
488 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, off, idx);
489 1.4.4.2 rpaulo tmp = bus_space_read_1(sc->sc_iot, sc->sc_ioh, off + 1);
490 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, off + 1,
491 1.4.4.2 rpaulo ((val & mask) | (tmp & ~mask)));
492 1.4.4.2 rpaulo }
493 1.4.4.2 rpaulo
494 1.4.4.2 rpaulo static void
495 1.4.4.2 rpaulo uni_wr_dac(struct unichromefb_softc *sc, uint8_t idx,
496 1.4.4.2 rpaulo uint8_t r, uint8_t g, uint8_t b)
497 1.4.4.2 rpaulo {
498 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, LUT_INDEX_WRITE, idx);
499 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, LUT_DATA, r);
500 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, LUT_DATA, g);
501 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, LUT_DATA, b);
502 1.4.4.2 rpaulo }
503 1.4.4.2 rpaulo
504 1.4.4.2 rpaulo static void
505 1.4.4.2 rpaulo uni_wr_x(struct unichromefb_softc *sc, struct io_reg *tbl, int num)
506 1.4.4.2 rpaulo {
507 1.4.4.2 rpaulo int i;
508 1.4.4.2 rpaulo uint8_t tmp;
509 1.4.4.2 rpaulo
510 1.4.4.2 rpaulo for (i = 0; i < num; i++) {
511 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, tbl[i].port,
512 1.4.4.2 rpaulo tbl[i].index);
513 1.4.4.2 rpaulo tmp = bus_space_read_1(sc->sc_iot, sc->sc_iot,
514 1.4.4.2 rpaulo tbl[i].port + 1);
515 1.4.4.2 rpaulo tmp = (tmp & (~tbl[i].mask)) | tbl[i].value;
516 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, tbl[i].index + 1,
517 1.4.4.2 rpaulo tmp);
518 1.4.4.2 rpaulo }
519 1.4.4.2 rpaulo }
520 1.4.4.2 rpaulo
521 1.4.4.2 rpaulo /*
522 1.4.4.2 rpaulo * helpers
523 1.4.4.2 rpaulo */
524 1.4.4.2 rpaulo static struct VideoModeTable *
525 1.4.4.2 rpaulo uni_getmode(int mode)
526 1.4.4.2 rpaulo {
527 1.4.4.2 rpaulo int i;
528 1.4.4.2 rpaulo
529 1.4.4.2 rpaulo for (i = 0; i < NUM_TOTAL_MODETABLE; i++)
530 1.4.4.2 rpaulo if (CLE266Modes[i].ModeIndex == mode)
531 1.4.4.2 rpaulo return &CLE266Modes[i];
532 1.4.4.2 rpaulo
533 1.4.4.2 rpaulo return NULL;
534 1.4.4.2 rpaulo }
535 1.4.4.2 rpaulo
536 1.4.4.2 rpaulo static void
537 1.4.4.2 rpaulo uni_setmode(struct unichromefb_softc *sc, int idx, int bpp)
538 1.4.4.2 rpaulo {
539 1.4.4.2 rpaulo struct VideoModeTable *vtbl;
540 1.4.4.2 rpaulo struct crt_mode_table *crt;
541 1.4.4.2 rpaulo int i;
542 1.4.4.2 rpaulo
543 1.4.4.2 rpaulo /* XXX */
544 1.4.4.2 rpaulo vtbl = uni_getmode(idx);
545 1.4.4.2 rpaulo if (vtbl == NULL)
546 1.4.4.2 rpaulo panic("%s: unsupported mode: %d\n", sc->sc_dev.dv_xname, idx);
547 1.4.4.2 rpaulo
548 1.4.4.2 rpaulo crt = vtbl->crtc;
549 1.4.4.2 rpaulo
550 1.4.4.2 rpaulo uni_screen_disable(sc);
551 1.4.4.2 rpaulo
552 1.4.4.2 rpaulo (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAStatus);
553 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAAR, 0);
554 1.4.4.2 rpaulo
555 1.4.4.2 rpaulo /* XXX assume CN900 for now */
556 1.4.4.2 rpaulo uni_wr_x(sc, CN900_ModeXregs, NUM_TOTAL_CN900_ModeXregs);
557 1.4.4.2 rpaulo
558 1.4.4.2 rpaulo uni_crt_disable(sc);
559 1.4.4.2 rpaulo
560 1.4.4.2 rpaulo /* Fill VPIT params */
561 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc, VPIT.Misc);
562 1.4.4.2 rpaulo
563 1.4.4.2 rpaulo /* Write sequencer */
564 1.4.4.2 rpaulo for (i = 1; i <= StdSR; i++) {
565 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIASR, i);
566 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIASR + 1,
567 1.4.4.2 rpaulo VPIT.SR[i - 1]);
568 1.4.4.2 rpaulo }
569 1.4.4.2 rpaulo
570 1.4.4.2 rpaulo uni_set_start(sc);
571 1.4.4.2 rpaulo
572 1.4.4.2 rpaulo uni_set_crtc(sc, crt, idx, bpp / 8, IGA1);
573 1.4.4.2 rpaulo
574 1.4.4.2 rpaulo for (i = 0; i < StdGR; i++) {
575 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAGR, i);
576 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAGR + 1,
577 1.4.4.2 rpaulo VPIT.GR[i]);
578 1.4.4.2 rpaulo }
579 1.4.4.2 rpaulo
580 1.4.4.2 rpaulo for (i = 0; i < StdAR; i++) {
581 1.4.4.2 rpaulo (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAStatus);
582 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAAR, i);
583 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAAR,
584 1.4.4.2 rpaulo VPIT.AR[i]);
585 1.4.4.2 rpaulo }
586 1.4.4.2 rpaulo
587 1.4.4.2 rpaulo (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIAStatus);
588 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAAR, 0x20);
589 1.4.4.2 rpaulo
590 1.4.4.2 rpaulo uni_set_crtc(sc, crt, idx, bpp / 8, IGA1);
591 1.4.4.2 rpaulo /* set crt output path */
592 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR16, 0x00, BIT6);
593 1.4.4.2 rpaulo
594 1.4.4.2 rpaulo uni_crt_enable(sc);
595 1.4.4.2 rpaulo uni_screen_enable(sc);
596 1.4.4.2 rpaulo
597 1.4.4.2 rpaulo return;
598 1.4.4.2 rpaulo }
599 1.4.4.2 rpaulo
600 1.4.4.2 rpaulo static void
601 1.4.4.2 rpaulo uni_crt_lock(struct unichromefb_softc *sc)
602 1.4.4.2 rpaulo {
603 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR11, BIT7, BIT7);
604 1.4.4.2 rpaulo }
605 1.4.4.2 rpaulo
606 1.4.4.2 rpaulo static void
607 1.4.4.2 rpaulo uni_crt_unlock(struct unichromefb_softc *sc)
608 1.4.4.2 rpaulo {
609 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR11, 0, BIT7);
610 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR47, 0, BIT0);
611 1.4.4.2 rpaulo }
612 1.4.4.2 rpaulo
613 1.4.4.2 rpaulo static void
614 1.4.4.2 rpaulo uni_crt_enable(struct unichromefb_softc *sc)
615 1.4.4.2 rpaulo {
616 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR36, 0, BIT5+BIT4);
617 1.4.4.2 rpaulo }
618 1.4.4.2 rpaulo
619 1.4.4.2 rpaulo static void
620 1.4.4.2 rpaulo uni_crt_disable(struct unichromefb_softc *sc)
621 1.4.4.2 rpaulo {
622 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR36, BIT5+BIT4, BIT5+BIT4);
623 1.4.4.2 rpaulo }
624 1.4.4.2 rpaulo
625 1.4.4.2 rpaulo static void
626 1.4.4.2 rpaulo uni_screen_enable(struct unichromefb_softc *sc)
627 1.4.4.2 rpaulo {
628 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR01, 0, BIT5);
629 1.4.4.2 rpaulo }
630 1.4.4.2 rpaulo
631 1.4.4.2 rpaulo static void
632 1.4.4.2 rpaulo uni_screen_disable(struct unichromefb_softc *sc)
633 1.4.4.2 rpaulo {
634 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR01, 0x20, BIT5);
635 1.4.4.2 rpaulo }
636 1.4.4.2 rpaulo
637 1.4.4.2 rpaulo static void
638 1.4.4.2 rpaulo uni_set_start(struct unichromefb_softc *sc)
639 1.4.4.2 rpaulo {
640 1.4.4.2 rpaulo uni_crt_unlock(sc);
641 1.4.4.2 rpaulo
642 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR0C, 0x00);
643 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR0D, 0x00);
644 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR34, 0x00);
645 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR48, 0x00, BIT0 + BIT1);
646 1.4.4.2 rpaulo
647 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR62, 0x00);
648 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR63, 0x00);
649 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR64, 0x00);
650 1.4.4.2 rpaulo uni_wr(sc, VIACR, CRA3, 0x00);
651 1.4.4.2 rpaulo
652 1.4.4.2 rpaulo uni_crt_lock(sc);
653 1.4.4.2 rpaulo }
654 1.4.4.2 rpaulo
655 1.4.4.2 rpaulo static void
656 1.4.4.2 rpaulo uni_set_crtc(struct unichromefb_softc *sc, struct crt_mode_table *ctbl,
657 1.4.4.2 rpaulo int mode, int bpp_byte, int iga)
658 1.4.4.2 rpaulo {
659 1.4.4.2 rpaulo struct VideoModeTable *vtbl;
660 1.4.4.2 rpaulo struct display_timing crtreg;
661 1.4.4.2 rpaulo int i;
662 1.4.4.2 rpaulo int index;
663 1.4.4.2 rpaulo int haddr, vaddr;
664 1.4.4.2 rpaulo uint8_t val;
665 1.4.4.2 rpaulo uint32_t pll_d_n;
666 1.4.4.2 rpaulo
667 1.4.4.2 rpaulo index = 0;
668 1.4.4.2 rpaulo
669 1.4.4.2 rpaulo vtbl = uni_getmode(mode);
670 1.4.4.2 rpaulo for (i = 0; i < vtbl->mode_array; i++) {
671 1.4.4.2 rpaulo index = i;
672 1.4.4.2 rpaulo if (ctbl[i].refresh_rate == 60)
673 1.4.4.2 rpaulo break;
674 1.4.4.2 rpaulo }
675 1.4.4.2 rpaulo
676 1.4.4.2 rpaulo crtreg = ctbl[index].crtc;
677 1.4.4.2 rpaulo
678 1.4.4.2 rpaulo haddr = crtreg.hor_addr;
679 1.4.4.2 rpaulo vaddr = crtreg.ver_addr;
680 1.4.4.2 rpaulo
681 1.4.4.2 rpaulo val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIARMisc);
682 1.4.4.2 rpaulo if (ctbl[index].h_sync_polarity == NEGATIVE) {
683 1.4.4.2 rpaulo if (ctbl[index].v_sync_polarity == NEGATIVE)
684 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc,
685 1.4.4.2 rpaulo (val & (~(BIT6+BIT7))) | (BIT6+BIT7));
686 1.4.4.2 rpaulo else
687 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc,
688 1.4.4.2 rpaulo (val & (~(BIT6+BIT7))) | (BIT6));
689 1.4.4.2 rpaulo } else {
690 1.4.4.2 rpaulo if (ctbl[index].v_sync_polarity == NEGATIVE)
691 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc,
692 1.4.4.2 rpaulo (val & (~(BIT6+BIT7))) | (BIT7));
693 1.4.4.2 rpaulo else
694 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc,
695 1.4.4.2 rpaulo (val & (~(BIT6+BIT7))));
696 1.4.4.2 rpaulo }
697 1.4.4.2 rpaulo
698 1.4.4.2 rpaulo if (iga == IGA1) {
699 1.4.4.2 rpaulo uni_crt_unlock(sc);
700 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR09, 0x00);
701 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR11, 0x00, BIT4+BIT5+BIT6);
702 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR17, 0x00, BIT7);
703 1.4.4.2 rpaulo }
704 1.4.4.2 rpaulo
705 1.4.4.2 rpaulo uni_load_crtc(sc, crtreg, iga);
706 1.4.4.2 rpaulo uni_fix_crtc(sc);
707 1.4.4.2 rpaulo uni_crt_lock(sc);
708 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR17, 0x80, BIT7);
709 1.4.4.2 rpaulo
710 1.4.4.2 rpaulo uni_load_offset(sc, haddr, bpp_byte, iga);
711 1.4.4.2 rpaulo uni_load_fetchcnt(sc, haddr, bpp_byte, iga);
712 1.4.4.2 rpaulo uni_load_fifo(sc, iga, haddr, vaddr);
713 1.4.4.2 rpaulo
714 1.4.4.2 rpaulo uni_set_depth(sc, bpp_byte, iga);
715 1.4.4.2 rpaulo pll_d_n = uni_get_clkval(sc, ctbl[index].clk);
716 1.4.4.2 rpaulo uni_set_vclk(sc, pll_d_n, iga);
717 1.4.4.2 rpaulo }
718 1.4.4.2 rpaulo
719 1.4.4.2 rpaulo static void
720 1.4.4.2 rpaulo uni_load_crtc(struct unichromefb_softc *sc,
721 1.4.4.2 rpaulo struct display_timing device_timing, int iga)
722 1.4.4.2 rpaulo {
723 1.4.4.2 rpaulo int regnum, val;
724 1.4.4.2 rpaulo struct io_register *reg;
725 1.4.4.2 rpaulo int i;
726 1.4.4.2 rpaulo
727 1.4.4.2 rpaulo regnum = val = 0;
728 1.4.4.2 rpaulo reg = NULL;
729 1.4.4.2 rpaulo
730 1.4.4.2 rpaulo uni_crt_unlock(sc);
731 1.4.4.2 rpaulo
732 1.4.4.2 rpaulo for (i = 0; i < 12; i++) {
733 1.4.4.2 rpaulo switch (iga) {
734 1.4.4.2 rpaulo case IGA1:
735 1.4.4.2 rpaulo switch (i) {
736 1.4.4.2 rpaulo case H_TOTAL_INDEX:
737 1.4.4.2 rpaulo val = IGA1_HOR_TOTAL_FORMULA(
738 1.4.4.2 rpaulo device_timing.hor_total);
739 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_total.reg_num;
740 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_total.reg;
741 1.4.4.2 rpaulo break;
742 1.4.4.2 rpaulo case H_ADDR_INDEX:
743 1.4.4.2 rpaulo val = IGA1_HOR_ADDR_FORMULA(
744 1.4.4.2 rpaulo device_timing.hor_addr);
745 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_addr.reg_num;
746 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_addr.reg;
747 1.4.4.2 rpaulo break;
748 1.4.4.2 rpaulo case H_BLANK_START_INDEX:
749 1.4.4.2 rpaulo val = IGA1_HOR_BLANK_START_FORMULA(
750 1.4.4.2 rpaulo device_timing.hor_blank_start);
751 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_blank_start.reg_num;
752 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_blank_start.reg;
753 1.4.4.2 rpaulo break;
754 1.4.4.2 rpaulo case H_BLANK_END_INDEX:
755 1.4.4.2 rpaulo val = IGA1_HOR_BLANK_END_FORMULA(
756 1.4.4.2 rpaulo device_timing.hor_blank_start,
757 1.4.4.2 rpaulo device_timing.hor_blank_end);
758 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_blank_end.reg_num;
759 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_blank_end.reg;
760 1.4.4.2 rpaulo break;
761 1.4.4.2 rpaulo case H_SYNC_START_INDEX:
762 1.4.4.2 rpaulo val = IGA1_HOR_SYNC_START_FORMULA(
763 1.4.4.2 rpaulo device_timing.hor_sync_start);
764 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_sync_start.reg_num;
765 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_sync_start.reg;
766 1.4.4.2 rpaulo break;
767 1.4.4.2 rpaulo case H_SYNC_END_INDEX:
768 1.4.4.2 rpaulo val = IGA1_HOR_SYNC_END_FORMULA(
769 1.4.4.2 rpaulo device_timing.hor_sync_start,
770 1.4.4.2 rpaulo device_timing.hor_sync_end);
771 1.4.4.2 rpaulo regnum = iga1_crtc_reg.hor_sync_end.reg_num;
772 1.4.4.2 rpaulo reg = iga1_crtc_reg.hor_sync_end.reg;
773 1.4.4.2 rpaulo break;
774 1.4.4.2 rpaulo case V_TOTAL_INDEX:
775 1.4.4.2 rpaulo val = IGA1_VER_TOTAL_FORMULA(
776 1.4.4.2 rpaulo device_timing.ver_total);
777 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_total.reg_num;
778 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_total.reg;
779 1.4.4.2 rpaulo break;
780 1.4.4.2 rpaulo case V_ADDR_INDEX:
781 1.4.4.2 rpaulo val = IGA1_VER_ADDR_FORMULA(
782 1.4.4.2 rpaulo device_timing.ver_addr);
783 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_addr.reg_num;
784 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_addr.reg;
785 1.4.4.2 rpaulo break;
786 1.4.4.2 rpaulo case V_BLANK_START_INDEX:
787 1.4.4.2 rpaulo val = IGA1_VER_BLANK_START_FORMULA(
788 1.4.4.2 rpaulo device_timing.ver_blank_start);
789 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_blank_start.reg_num;
790 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_blank_start.reg;
791 1.4.4.2 rpaulo break;
792 1.4.4.2 rpaulo case V_BLANK_END_INDEX:
793 1.4.4.2 rpaulo val = IGA1_VER_BLANK_END_FORMULA(
794 1.4.4.2 rpaulo device_timing.ver_blank_start,
795 1.4.4.2 rpaulo device_timing.ver_blank_end);
796 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_blank_end.reg_num;
797 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_blank_end.reg;
798 1.4.4.2 rpaulo break;
799 1.4.4.2 rpaulo case V_SYNC_START_INDEX:
800 1.4.4.2 rpaulo val = IGA1_VER_SYNC_START_FORMULA(
801 1.4.4.2 rpaulo device_timing.ver_sync_start);
802 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_sync_start.reg_num;
803 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_sync_start.reg;
804 1.4.4.2 rpaulo break;
805 1.4.4.2 rpaulo case V_SYNC_END_INDEX:
806 1.4.4.2 rpaulo val = IGA1_VER_SYNC_END_FORMULA(
807 1.4.4.2 rpaulo device_timing.ver_sync_start,
808 1.4.4.2 rpaulo device_timing.ver_sync_end);
809 1.4.4.2 rpaulo regnum = iga1_crtc_reg.ver_sync_end.reg_num;
810 1.4.4.2 rpaulo reg = iga1_crtc_reg.ver_sync_end.reg;
811 1.4.4.2 rpaulo break;
812 1.4.4.2 rpaulo default:
813 1.4.4.2 rpaulo printf("%s: unknown index %d while setting up CRTC\n",
814 1.4.4.2 rpaulo sc->sc_dev.dv_xname, i);
815 1.4.4.2 rpaulo break;
816 1.4.4.2 rpaulo }
817 1.4.4.2 rpaulo break;
818 1.4.4.2 rpaulo case IGA2:
819 1.4.4.2 rpaulo printf("%s: %s: IGA2 not supported\n",
820 1.4.4.2 rpaulo sc->sc_dev.dv_xname, __func__);
821 1.4.4.2 rpaulo break;
822 1.4.4.2 rpaulo }
823 1.4.4.2 rpaulo
824 1.4.4.2 rpaulo uni_load_reg(sc, val, regnum, reg, VIACR);
825 1.4.4.2 rpaulo }
826 1.4.4.2 rpaulo
827 1.4.4.2 rpaulo uni_crt_lock(sc);
828 1.4.4.2 rpaulo }
829 1.4.4.2 rpaulo
830 1.4.4.2 rpaulo static void
831 1.4.4.2 rpaulo uni_load_reg(struct unichromefb_softc *sc, int timing, int regnum,
832 1.4.4.2 rpaulo struct io_register *reg, int type)
833 1.4.4.2 rpaulo {
834 1.4.4.2 rpaulo int regmask, bitnum, data;
835 1.4.4.2 rpaulo int i, j;
836 1.4.4.2 rpaulo int shift_next_reg;
837 1.4.4.2 rpaulo int startidx, endidx, cridx;
838 1.4.4.2 rpaulo uint16_t getbit;
839 1.4.4.2 rpaulo
840 1.4.4.2 rpaulo bitnum = 0;
841 1.4.4.2 rpaulo
842 1.4.4.2 rpaulo for (i = 0; i < regnum; i++) {
843 1.4.4.2 rpaulo regmask = data = 0;
844 1.4.4.2 rpaulo startidx = reg[i].start_bit;
845 1.4.4.2 rpaulo endidx = reg[i].end_bit;
846 1.4.4.2 rpaulo cridx = reg[i].io_addr;
847 1.4.4.2 rpaulo
848 1.4.4.2 rpaulo shift_next_reg = bitnum;
849 1.4.4.2 rpaulo
850 1.4.4.2 rpaulo for (j = startidx; j <= endidx; j++) {
851 1.4.4.2 rpaulo regmask = regmask | (BIT0 << j);
852 1.4.4.2 rpaulo getbit = (timing & (BIT0 << bitnum));
853 1.4.4.2 rpaulo data = data | ((getbit >> shift_next_reg) << startidx);
854 1.4.4.2 rpaulo ++bitnum;
855 1.4.4.2 rpaulo }
856 1.4.4.2 rpaulo
857 1.4.4.2 rpaulo if (type == VIACR)
858 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, cridx, data, regmask);
859 1.4.4.2 rpaulo else
860 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, cridx, data, regmask);
861 1.4.4.2 rpaulo }
862 1.4.4.2 rpaulo
863 1.4.4.2 rpaulo return;
864 1.4.4.2 rpaulo }
865 1.4.4.2 rpaulo
866 1.4.4.2 rpaulo static void
867 1.4.4.2 rpaulo uni_fix_crtc(struct unichromefb_softc *sc)
868 1.4.4.2 rpaulo {
869 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR03, 0x80, BIT7);
870 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR18, 0xff);
871 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR07, 0x10, BIT4);
872 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR09, 0x40, BIT6);
873 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR35, 0x10, BIT4);
874 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR33, 0x06, BIT0+BIT1+BIT2);
875 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR17, 0xe3);
876 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR08, 0x00);
877 1.4.4.2 rpaulo uni_wr(sc, VIACR, CR14, 0x00);
878 1.4.4.2 rpaulo
879 1.4.4.2 rpaulo return;
880 1.4.4.2 rpaulo }
881 1.4.4.2 rpaulo
882 1.4.4.2 rpaulo static void
883 1.4.4.2 rpaulo uni_load_offset(struct unichromefb_softc *sc, int haddr, int bpp, int iga)
884 1.4.4.2 rpaulo {
885 1.4.4.2 rpaulo
886 1.4.4.2 rpaulo switch (iga) {
887 1.4.4.2 rpaulo case IGA1:
888 1.4.4.2 rpaulo uni_load_reg(sc,
889 1.4.4.2 rpaulo IGA1_OFFSET_FORMULA(haddr, bpp),
890 1.4.4.2 rpaulo offset_reg.iga1_offset_reg.reg_num,
891 1.4.4.2 rpaulo offset_reg.iga1_offset_reg.reg,
892 1.4.4.2 rpaulo VIACR);
893 1.4.4.2 rpaulo break;
894 1.4.4.2 rpaulo default:
895 1.4.4.2 rpaulo printf("%s: %s: only IGA1 is supported\n", sc->sc_dev.dv_xname,
896 1.4.4.2 rpaulo __func__);
897 1.4.4.2 rpaulo break;
898 1.4.4.2 rpaulo }
899 1.4.4.2 rpaulo
900 1.4.4.2 rpaulo return;
901 1.4.4.2 rpaulo }
902 1.4.4.2 rpaulo
903 1.4.4.2 rpaulo static void
904 1.4.4.2 rpaulo uni_load_fetchcnt(struct unichromefb_softc *sc, int haddr, int bpp, int iga)
905 1.4.4.2 rpaulo {
906 1.4.4.2 rpaulo
907 1.4.4.2 rpaulo switch (iga) {
908 1.4.4.2 rpaulo case IGA1:
909 1.4.4.2 rpaulo uni_load_reg(sc,
910 1.4.4.2 rpaulo IGA1_FETCH_COUNT_FORMULA(haddr, bpp),
911 1.4.4.2 rpaulo fetch_count_reg.iga1_fetch_count_reg.reg_num,
912 1.4.4.2 rpaulo fetch_count_reg.iga1_fetch_count_reg.reg,
913 1.4.4.2 rpaulo VIASR);
914 1.4.4.2 rpaulo break;
915 1.4.4.2 rpaulo default:
916 1.4.4.2 rpaulo printf("%s: %s: only IGA1 is supported\n", sc->sc_dev.dv_xname,
917 1.4.4.2 rpaulo __func__);
918 1.4.4.2 rpaulo break;
919 1.4.4.2 rpaulo }
920 1.4.4.2 rpaulo
921 1.4.4.2 rpaulo return;
922 1.4.4.2 rpaulo }
923 1.4.4.2 rpaulo
924 1.4.4.2 rpaulo static void
925 1.4.4.2 rpaulo uni_load_fifo(struct unichromefb_softc *sc, int iga, int horact, int veract)
926 1.4.4.2 rpaulo {
927 1.4.4.2 rpaulo int val, regnum;
928 1.4.4.2 rpaulo struct io_register *reg;
929 1.4.4.2 rpaulo int iga1_fifo_max_depth, iga1_fifo_threshold;
930 1.4.4.2 rpaulo int iga1_fifo_high_threshold, iga1_display_queue_expire_num;
931 1.4.4.2 rpaulo
932 1.4.4.2 rpaulo reg = NULL;
933 1.4.4.2 rpaulo iga1_fifo_max_depth = iga1_fifo_threshold = 0;
934 1.4.4.2 rpaulo iga1_fifo_high_threshold = iga1_display_queue_expire_num = 0;
935 1.4.4.2 rpaulo
936 1.4.4.2 rpaulo switch (iga) {
937 1.4.4.2 rpaulo case IGA1:
938 1.4.4.2 rpaulo /* XXX if (type == CN900) { */
939 1.4.4.2 rpaulo iga1_fifo_max_depth = CN900_IGA1_FIFO_MAX_DEPTH;
940 1.4.4.2 rpaulo iga1_fifo_threshold = CN900_IGA1_FIFO_THRESHOLD;
941 1.4.4.2 rpaulo iga1_fifo_high_threshold = CN900_IGA1_FIFO_HIGH_THRESHOLD;
942 1.4.4.2 rpaulo if (horact > 1280 && veract > 1024)
943 1.4.4.2 rpaulo iga1_display_queue_expire_num = 16;
944 1.4.4.2 rpaulo else
945 1.4.4.2 rpaulo iga1_display_queue_expire_num =
946 1.4.4.2 rpaulo CN900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
947 1.4.4.2 rpaulo /* XXX } */
948 1.4.4.2 rpaulo
949 1.4.4.2 rpaulo /* set display FIFO depth select */
950 1.4.4.2 rpaulo val = IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth);
951 1.4.4.2 rpaulo regnum =
952 1.4.4.2 rpaulo display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg_num;
953 1.4.4.2 rpaulo reg = display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg;
954 1.4.4.2 rpaulo uni_load_reg(sc, val, regnum, reg, VIASR);
955 1.4.4.2 rpaulo
956 1.4.4.2 rpaulo /* set display FIFO threshold select */
957 1.4.4.2 rpaulo val = IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold);
958 1.4.4.2 rpaulo regnum = fifo_threshold_select_reg.iga1_fifo_threshold_select_reg.reg_num;
959 1.4.4.2 rpaulo reg = fifo_threshold_select_reg.iga1_fifo_threshold_select_reg.reg;
960 1.4.4.2 rpaulo uni_load_reg(sc, val, regnum, reg, VIASR);
961 1.4.4.2 rpaulo
962 1.4.4.2 rpaulo /* set display FIFO high threshold select */
963 1.4.4.2 rpaulo val = IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold);
964 1.4.4.2 rpaulo regnum = fifo_high_threshold_select_reg.iga1_fifo_high_threshold_select_reg.reg_num;
965 1.4.4.2 rpaulo reg = fifo_high_threshold_select_reg.iga1_fifo_high_threshold_select_reg.reg;
966 1.4.4.2 rpaulo uni_load_reg(sc, val, regnum, reg, VIASR);
967 1.4.4.2 rpaulo
968 1.4.4.2 rpaulo /* set display queue expire num */
969 1.4.4.2 rpaulo val = IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA(iga1_display_queue_expire_num);
970 1.4.4.2 rpaulo regnum = display_queue_expire_num_reg.iga1_display_queue_expire_num_reg.reg_num;
971 1.4.4.2 rpaulo reg = display_queue_expire_num_reg.iga1_display_queue_expire_num_reg.reg;
972 1.4.4.2 rpaulo uni_load_reg(sc, val, regnum, reg, VIASR);
973 1.4.4.2 rpaulo
974 1.4.4.2 rpaulo break;
975 1.4.4.2 rpaulo default:
976 1.4.4.2 rpaulo printf("%s: %s: only IGA1 is supported\n", sc->sc_dev.dv_xname,
977 1.4.4.2 rpaulo __func__);
978 1.4.4.2 rpaulo break;
979 1.4.4.2 rpaulo }
980 1.4.4.2 rpaulo
981 1.4.4.2 rpaulo return;
982 1.4.4.2 rpaulo }
983 1.4.4.2 rpaulo
984 1.4.4.2 rpaulo static void
985 1.4.4.2 rpaulo uni_set_depth(struct unichromefb_softc *sc, int bpp, int iga)
986 1.4.4.2 rpaulo {
987 1.4.4.2 rpaulo switch (iga) {
988 1.4.4.2 rpaulo case IGA1:
989 1.4.4.2 rpaulo switch (bpp) {
990 1.4.4.2 rpaulo case MODE_32BPP:
991 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR15, 0xae, 0xfe);
992 1.4.4.2 rpaulo break;
993 1.4.4.2 rpaulo case MODE_16BPP:
994 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR15, 0xb6, 0xfe);
995 1.4.4.2 rpaulo break;
996 1.4.4.2 rpaulo case MODE_8BPP:
997 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR15, 0x22, 0xfe);
998 1.4.4.2 rpaulo break;
999 1.4.4.2 rpaulo default:
1000 1.4.4.2 rpaulo printf("%s: %s: mode (%d) unsupported\n",
1001 1.4.4.2 rpaulo sc->sc_dev.dv_xname, __func__, bpp);
1002 1.4.4.2 rpaulo }
1003 1.4.4.2 rpaulo break;
1004 1.4.4.2 rpaulo default:
1005 1.4.4.2 rpaulo printf("%s: %s: only IGA1 is supported\n", sc->sc_dev.dv_xname,
1006 1.4.4.2 rpaulo __func__);
1007 1.4.4.2 rpaulo break;
1008 1.4.4.2 rpaulo }
1009 1.4.4.2 rpaulo }
1010 1.4.4.2 rpaulo
1011 1.4.4.2 rpaulo static uint32_t
1012 1.4.4.2 rpaulo uni_get_clkval(struct unichromefb_softc *sc, int clk)
1013 1.4.4.2 rpaulo {
1014 1.4.4.2 rpaulo int i;
1015 1.4.4.2 rpaulo
1016 1.4.4.2 rpaulo for (i = 0; i < NUM_TOTAL_PLL_TABLE; i++) {
1017 1.4.4.2 rpaulo if (clk == pll_value[i].clk) {
1018 1.4.4.2 rpaulo /* XXX only CN900 supported for now */
1019 1.4.4.2 rpaulo return pll_value[i].k800_pll;
1020 1.4.4.2 rpaulo }
1021 1.4.4.2 rpaulo }
1022 1.4.4.2 rpaulo
1023 1.4.4.2 rpaulo aprint_error("%s: can't find matching PLL value\n",
1024 1.4.4.2 rpaulo sc->sc_dev.dv_xname);
1025 1.4.4.2 rpaulo
1026 1.4.4.2 rpaulo return 0;
1027 1.4.4.2 rpaulo }
1028 1.4.4.2 rpaulo
1029 1.4.4.2 rpaulo static void
1030 1.4.4.2 rpaulo uni_set_vclk(struct unichromefb_softc *sc, uint32_t clk, int iga)
1031 1.4.4.2 rpaulo {
1032 1.4.4.2 rpaulo uint8_t val;
1033 1.4.4.2 rpaulo
1034 1.4.4.2 rpaulo /* hardware reset on */
1035 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR17, 0x00, BIT7);
1036 1.4.4.2 rpaulo
1037 1.4.4.2 rpaulo switch (iga) {
1038 1.4.4.2 rpaulo case IGA1:
1039 1.4.4.2 rpaulo /* XXX only CN900 is supported */
1040 1.4.4.2 rpaulo uni_wr(sc, VIASR, SR44, clk / 0x10000);
1041 1.4.4.2 rpaulo uni_wr(sc, VIASR, SR45, (clk & 0xffff) / 0x100);
1042 1.4.4.2 rpaulo uni_wr(sc, VIASR, SR46, clk % 0x100);
1043 1.4.4.2 rpaulo break;
1044 1.4.4.2 rpaulo default:
1045 1.4.4.2 rpaulo printf("%s: %s: only IGA1 is supported\n", sc->sc_dev.dv_xname,
1046 1.4.4.2 rpaulo __func__);
1047 1.4.4.2 rpaulo break;
1048 1.4.4.2 rpaulo }
1049 1.4.4.2 rpaulo
1050 1.4.4.2 rpaulo /* hardware reset off */
1051 1.4.4.2 rpaulo uni_wr_mask(sc, VIACR, CR17, 0x80, BIT7);
1052 1.4.4.2 rpaulo
1053 1.4.4.2 rpaulo /* reset pll */
1054 1.4.4.2 rpaulo switch (iga) {
1055 1.4.4.2 rpaulo case IGA1:
1056 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR40, 0x02, BIT1);
1057 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR40, 0x00, BIT1);
1058 1.4.4.2 rpaulo break;
1059 1.4.4.2 rpaulo }
1060 1.4.4.2 rpaulo
1061 1.4.4.2 rpaulo /* good to go */
1062 1.4.4.2 rpaulo val = bus_space_read_1(sc->sc_iot, sc->sc_ioh, VIARMisc);
1063 1.4.4.2 rpaulo val |= (BIT2+BIT3);
1064 1.4.4.2 rpaulo bus_space_write_1(sc->sc_iot, sc->sc_ioh, VIAWMisc, val);
1065 1.4.4.2 rpaulo
1066 1.4.4.2 rpaulo return;
1067 1.4.4.2 rpaulo }
1068 1.4.4.2 rpaulo
1069 1.4.4.2 rpaulo static void
1070 1.4.4.2 rpaulo uni_init_dac(struct unichromefb_softc *sc, int iga)
1071 1.4.4.2 rpaulo {
1072 1.4.4.2 rpaulo int i;
1073 1.4.4.2 rpaulo
1074 1.4.4.2 rpaulo /* XXX only IGA1 for now */
1075 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR1A, 0x00, BIT0);
1076 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR18, 0x00, BIT7+BIT6);
1077 1.4.4.2 rpaulo for (i = 0; i < 256; i++)
1078 1.4.4.2 rpaulo uni_wr_dac(sc, i,
1079 1.4.4.2 rpaulo palLUT_table[i].red, palLUT_table[i].green, palLUT_table[i].blue);
1080 1.4.4.2 rpaulo
1081 1.4.4.2 rpaulo uni_wr_mask(sc, VIASR, SR18, 0xc0, BIT7+BIT6);
1082 1.4.4.2 rpaulo
1083 1.4.4.2 rpaulo return;
1084 1.4.4.2 rpaulo }
1085 1.4.4.2 rpaulo
1086 1.4.4.2 rpaulo static void
1087 1.4.4.2 rpaulo uni_init_accel(struct unichromefb_softc *sc)
1088 1.4.4.2 rpaulo {
1089 1.4.4.2 rpaulo
1090 1.4.4.2 rpaulo /* init 2D engine regs to reset 2D engine */
1091 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GEMODE, 0);
1092 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCPOS, 0);
1093 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTPOS, 0);
1094 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DIMENSION, 0);
1095 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PATADDR, 0);
1096 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_FGCOLOR, 0);
1097 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_BGCOLOR, 0);
1098 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_CLIPTL, 0);
1099 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_CLIPBR, 0);
1100 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_OFFSET, 0);
1101 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_KEYCONTROL, 0);
1102 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1103 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1104 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, 0);
1105 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_MONOPAT1, 0);
1106 1.4.4.2 rpaulo
1107 1.4.4.2 rpaulo /* init AGP and VQ registers */
1108 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSET, 0x00100000);
1109 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x00000000);
1110 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x00333004);
1111 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x60000000);
1112 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x61000000);
1113 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x62000000);
1114 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x63000000);
1115 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x64000000);
1116 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x7d000000);
1117 1.4.4.2 rpaulo
1118 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSET, 0xfe020000);
1119 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x00000000);
1120 1.4.4.2 rpaulo
1121 1.4.4.2 rpaulo /* disable VQ */
1122 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSET, 0x00fe0000);
1123 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x00000004);
1124 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x40008c0f);
1125 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x44000000);
1126 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x45080c04);
1127 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_TRANSPACE, 0x46800408);
1128 1.4.4.2 rpaulo
1129 1.4.4.2 rpaulo uni_set_accel_depth(sc);
1130 1.4.4.2 rpaulo
1131 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1132 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1133 1.4.4.2 rpaulo
1134 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, VIA_PITCH_ENABLE |
1135 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) |
1136 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) << 16)));
1137 1.4.4.2 rpaulo
1138 1.4.4.2 rpaulo return;
1139 1.4.4.2 rpaulo }
1140 1.4.4.2 rpaulo
1141 1.4.4.2 rpaulo static void
1142 1.4.4.2 rpaulo uni_set_accel_depth(struct unichromefb_softc *sc)
1143 1.4.4.2 rpaulo {
1144 1.4.4.2 rpaulo uint32_t gemode;
1145 1.4.4.2 rpaulo
1146 1.4.4.2 rpaulo gemode = MMIO_IN32(0x04) & 0xfffffcff;
1147 1.4.4.2 rpaulo
1148 1.4.4.2 rpaulo switch (sc->sc_depth) {
1149 1.4.4.2 rpaulo case 32:
1150 1.4.4.2 rpaulo gemode |= VIA_GEM_32bpp;
1151 1.4.4.2 rpaulo break;
1152 1.4.4.2 rpaulo case 16:
1153 1.4.4.2 rpaulo gemode |= VIA_GEM_16bpp;
1154 1.4.4.2 rpaulo break;
1155 1.4.4.2 rpaulo default:
1156 1.4.4.2 rpaulo gemode |= VIA_GEM_8bpp;
1157 1.4.4.2 rpaulo break;
1158 1.4.4.2 rpaulo }
1159 1.4.4.2 rpaulo
1160 1.4.4.2 rpaulo /* set colour depth and pitch */
1161 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GEMODE, gemode);
1162 1.4.4.2 rpaulo
1163 1.4.4.2 rpaulo return;
1164 1.4.4.2 rpaulo }
1165 1.4.4.2 rpaulo
1166 1.4.4.2 rpaulo static void
1167 1.4.4.2 rpaulo uni_wait_idle(struct unichromefb_softc *sc)
1168 1.4.4.2 rpaulo {
1169 1.4.4.2 rpaulo int loop = 0;
1170 1.4.4.2 rpaulo
1171 1.4.4.2 rpaulo while (!(MMIO_IN32(VIA_REG_STATUS) & VIA_VR_QUEUE_BUSY) &&
1172 1.4.4.2 rpaulo (loop++ < MAXLOOP))
1173 1.4.4.2 rpaulo ;
1174 1.4.4.2 rpaulo
1175 1.4.4.2 rpaulo while ((MMIO_IN32(VIA_REG_STATUS) &
1176 1.4.4.2 rpaulo (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)) &&
1177 1.4.4.2 rpaulo (loop++ < MAXLOOP))
1178 1.4.4.2 rpaulo ;
1179 1.4.4.2 rpaulo
1180 1.4.4.2 rpaulo if (loop >= MAXLOOP)
1181 1.4.4.2 rpaulo aprint_error("%s: engine stall\n", sc->sc_dev.dv_xname);
1182 1.4.4.2 rpaulo
1183 1.4.4.2 rpaulo return;
1184 1.4.4.2 rpaulo }
1185 1.4.4.2 rpaulo
1186 1.4.4.2 rpaulo static void
1187 1.4.4.2 rpaulo uni_fillrect(struct unichromefb_softc *sc, int x, int y, int width,
1188 1.4.4.2 rpaulo int height, int colour)
1189 1.4.4.2 rpaulo {
1190 1.4.4.2 rpaulo
1191 1.4.4.2 rpaulo uni_wait_idle(sc);
1192 1.4.4.2 rpaulo
1193 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCPOS, 0);
1194 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1195 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1196 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, VIA_PITCH_ENABLE |
1197 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) |
1198 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) << 16)));
1199 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTPOS, ((y << 16) | x));
1200 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DIMENSION,
1201 1.4.4.2 rpaulo (((height - 1) << 16) | (width - 1)));
1202 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_FGCOLOR, colour);
1203 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GECMD, (0x01 | 0x2000 | 0xf0 << 24));
1204 1.4.4.2 rpaulo
1205 1.4.4.2 rpaulo return;
1206 1.4.4.2 rpaulo }
1207 1.4.4.2 rpaulo
1208 1.4.4.2 rpaulo static void
1209 1.4.4.2 rpaulo uni_rectinvert(struct unichromefb_softc *sc, int x, int y, int width,
1210 1.4.4.2 rpaulo int height)
1211 1.4.4.2 rpaulo {
1212 1.4.4.2 rpaulo
1213 1.4.4.2 rpaulo uni_wait_idle(sc);
1214 1.4.4.2 rpaulo
1215 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCPOS, 0);
1216 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1217 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1218 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, VIA_PITCH_ENABLE |
1219 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) |
1220 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) << 16)));
1221 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTPOS, ((y << 16) | x));
1222 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DIMENSION,
1223 1.4.4.2 rpaulo (((height - 1) << 16) | (width - 1)));
1224 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GECMD, (0x01 | 0x2000 | 0x55 << 24));
1225 1.4.4.2 rpaulo
1226 1.4.4.2 rpaulo return;
1227 1.4.4.2 rpaulo }
1228 1.4.4.2 rpaulo
1229 1.4.4.2 rpaulo static void
1230 1.4.4.2 rpaulo uni_bitblit(struct unichromefb_softc *sc, int xs, int ys, int xd, int yd, int width, int height)
1231 1.4.4.2 rpaulo {
1232 1.4.4.2 rpaulo uint32_t dir;
1233 1.4.4.2 rpaulo
1234 1.4.4.2 rpaulo dir = 0;
1235 1.4.4.2 rpaulo
1236 1.4.4.2 rpaulo if (ys < yd) {
1237 1.4.4.2 rpaulo yd += height - 1;
1238 1.4.4.2 rpaulo ys += height - 1;
1239 1.4.4.2 rpaulo dir |= 0x4000;
1240 1.4.4.2 rpaulo }
1241 1.4.4.2 rpaulo
1242 1.4.4.2 rpaulo if (xs < xd) {
1243 1.4.4.2 rpaulo xd += width - 1;
1244 1.4.4.2 rpaulo xs += width - 1;
1245 1.4.4.2 rpaulo dir |= 0x8000;
1246 1.4.4.2 rpaulo }
1247 1.4.4.2 rpaulo
1248 1.4.4.2 rpaulo uni_wait_idle(sc);
1249 1.4.4.2 rpaulo
1250 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1251 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1252 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, VIA_PITCH_ENABLE |
1253 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) |
1254 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) << 16)));
1255 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCPOS, ys << 16 | xs);
1256 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTPOS, yd << 16 | xd);
1257 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DIMENSION, ((height - 1) << 16) | (width - 1));
1258 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GECMD, (0x01 | dir | (0xcc << 24)));
1259 1.4.4.2 rpaulo
1260 1.4.4.2 rpaulo return;
1261 1.4.4.2 rpaulo }
1262 1.4.4.2 rpaulo
1263 1.4.4.2 rpaulo static void
1264 1.4.4.2 rpaulo uni_setup_mono(struct unichromefb_softc *sc, int xd, int yd, int width, int height,
1265 1.4.4.2 rpaulo uint32_t fg, uint32_t bg)
1266 1.4.4.2 rpaulo {
1267 1.4.4.2 rpaulo
1268 1.4.4.2 rpaulo uni_wait_idle(sc);
1269 1.4.4.2 rpaulo
1270 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCBASE, 0);
1271 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTBASE, 0);
1272 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_PITCH, VIA_PITCH_ENABLE |
1273 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) |
1274 1.4.4.2 rpaulo (((sc->sc_width * sc->sc_depth >> 3) >> 3) << 16)));
1275 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_SRCPOS, 0);
1276 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DSTPOS, (yd << 16) | xd);
1277 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_DIMENSION, ((height - 1) << 16) | (width - 1));
1278 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_FGCOLOR, fg);
1279 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_BGCOLOR, bg);
1280 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_GECMD, 0xcc020142);
1281 1.4.4.2 rpaulo
1282 1.4.4.2 rpaulo return;
1283 1.4.4.2 rpaulo }
1284 1.4.4.2 rpaulo
1285 1.4.4.2 rpaulo #if notyet
1286 1.4.4.2 rpaulo static void
1287 1.4.4.2 rpaulo uni_cursor_show(struct unichromefb_softc *sc)
1288 1.4.4.2 rpaulo {
1289 1.4.4.2 rpaulo uint32_t val;
1290 1.4.4.2 rpaulo
1291 1.4.4.2 rpaulo val = MMIO_IN32(VIA_REG_CURSOR_MODE);
1292 1.4.4.2 rpaulo val |= 1;
1293 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_CURSOR_MODE, val);
1294 1.4.4.2 rpaulo
1295 1.4.4.2 rpaulo return;
1296 1.4.4.2 rpaulo }
1297 1.4.4.2 rpaulo
1298 1.4.4.2 rpaulo static void
1299 1.4.4.2 rpaulo uni_cursor_hide(struct unichromefb_softc *sc)
1300 1.4.4.2 rpaulo {
1301 1.4.4.2 rpaulo uint32_t val;
1302 1.4.4.2 rpaulo
1303 1.4.4.2 rpaulo val = MMIO_IN32(VIA_REG_CURSOR_MODE);
1304 1.4.4.2 rpaulo val &= 0xfffffffe;
1305 1.4.4.2 rpaulo MMIO_OUT32(VIA_REG_CURSOR_MODE, val);
1306 1.4.4.2 rpaulo
1307 1.4.4.2 rpaulo return;
1308 1.4.4.2 rpaulo }
1309 1.4.4.2 rpaulo #endif
1310 1.4.4.2 rpaulo
1311 1.4.4.2 rpaulo /*
1312 1.4.4.2 rpaulo * rasops glue
1313 1.4.4.2 rpaulo */
1314 1.4.4.2 rpaulo static void
1315 1.4.4.2 rpaulo uni_copycols(void *opaque, int row, int srccol, int dstcol, int ncols)
1316 1.4.4.2 rpaulo {
1317 1.4.4.2 rpaulo struct rasops_info *ri;
1318 1.4.4.2 rpaulo struct vcons_screen *scr;
1319 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1320 1.4.4.2 rpaulo int xs, xd, y, width, height;
1321 1.4.4.2 rpaulo
1322 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1323 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1324 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1325 1.4.4.2 rpaulo
1326 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1327 1.4.4.2 rpaulo xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
1328 1.4.4.2 rpaulo xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
1329 1.4.4.2 rpaulo y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1330 1.4.4.2 rpaulo width = ri->ri_font->fontwidth * ncols;
1331 1.4.4.2 rpaulo height = ri->ri_font->fontheight;
1332 1.4.4.2 rpaulo uni_bitblit(sc, xs, y, xd, y, width, height);
1333 1.4.4.2 rpaulo }
1334 1.4.4.2 rpaulo
1335 1.4.4.2 rpaulo return;
1336 1.4.4.2 rpaulo }
1337 1.4.4.2 rpaulo
1338 1.4.4.2 rpaulo static void
1339 1.4.4.2 rpaulo uni_copyrows(void *opaque, int srcrow, int dstrow, int nrows)
1340 1.4.4.2 rpaulo {
1341 1.4.4.2 rpaulo struct rasops_info *ri;
1342 1.4.4.2 rpaulo struct vcons_screen *scr;
1343 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1344 1.4.4.2 rpaulo int x, ys, yd, width, height;
1345 1.4.4.2 rpaulo
1346 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1347 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1348 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1349 1.4.4.2 rpaulo
1350 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1351 1.4.4.2 rpaulo x = ri->ri_xorigin;
1352 1.4.4.2 rpaulo ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
1353 1.4.4.2 rpaulo yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
1354 1.4.4.2 rpaulo width = ri->ri_emuwidth;
1355 1.4.4.2 rpaulo height = ri->ri_font->fontheight * nrows;
1356 1.4.4.2 rpaulo uni_bitblit(sc, x, ys, x, yd, width, height);
1357 1.4.4.2 rpaulo }
1358 1.4.4.2 rpaulo
1359 1.4.4.2 rpaulo return;
1360 1.4.4.2 rpaulo }
1361 1.4.4.2 rpaulo
1362 1.4.4.2 rpaulo static void
1363 1.4.4.2 rpaulo uni_erasecols(void *opaque, int row, int startcol, int ncols, long fillattr)
1364 1.4.4.2 rpaulo {
1365 1.4.4.2 rpaulo struct rasops_info *ri;
1366 1.4.4.2 rpaulo struct vcons_screen *scr;
1367 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1368 1.4.4.2 rpaulo int x, y, width, height, fg, bg, ul;
1369 1.4.4.2 rpaulo
1370 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1371 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1372 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1373 1.4.4.2 rpaulo
1374 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1375 1.4.4.2 rpaulo x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
1376 1.4.4.2 rpaulo y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1377 1.4.4.2 rpaulo width = ri->ri_font->fontwidth * ncols;
1378 1.4.4.2 rpaulo height = ri->ri_font->fontheight;
1379 1.4.4.2 rpaulo rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1380 1.4.4.2 rpaulo uni_fillrect(sc, x, y, width, height, ri->ri_devcmap[bg]);
1381 1.4.4.2 rpaulo }
1382 1.4.4.2 rpaulo
1383 1.4.4.2 rpaulo return;
1384 1.4.4.2 rpaulo }
1385 1.4.4.2 rpaulo
1386 1.4.4.2 rpaulo static void
1387 1.4.4.2 rpaulo uni_eraserows(void *opaque, int row, int nrows, long fillattr)
1388 1.4.4.2 rpaulo {
1389 1.4.4.2 rpaulo struct rasops_info *ri;
1390 1.4.4.2 rpaulo struct vcons_screen *scr;
1391 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1392 1.4.4.2 rpaulo int x, y, width, height, fg, bg, ul;
1393 1.4.4.2 rpaulo
1394 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1395 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1396 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1397 1.4.4.2 rpaulo
1398 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1399 1.4.4.2 rpaulo rasops_unpack_attr(fillattr, &fg, &bg, &ul);
1400 1.4.4.2 rpaulo if ((row == 0) && (nrows == ri->ri_rows)) {
1401 1.4.4.2 rpaulo /* clear the whole screen */
1402 1.4.4.2 rpaulo uni_fillrect(sc, 0, 0, ri->ri_width,
1403 1.4.4.2 rpaulo ri->ri_height, ri->ri_devcmap[bg]);
1404 1.4.4.2 rpaulo } else {
1405 1.4.4.2 rpaulo x = ri->ri_xorigin;
1406 1.4.4.2 rpaulo y = ri->ri_yorigin + ri->ri_font->fontheight * row;
1407 1.4.4.2 rpaulo width = ri->ri_emuwidth;
1408 1.4.4.2 rpaulo height = ri->ri_font->fontheight * nrows;
1409 1.4.4.2 rpaulo uni_fillrect(sc, x, y, width, height,
1410 1.4.4.2 rpaulo ri->ri_devcmap[bg]);
1411 1.4.4.2 rpaulo }
1412 1.4.4.2 rpaulo }
1413 1.4.4.2 rpaulo
1414 1.4.4.2 rpaulo return;
1415 1.4.4.2 rpaulo }
1416 1.4.4.2 rpaulo
1417 1.4.4.2 rpaulo static void
1418 1.4.4.2 rpaulo uni_cursor(void *opaque, int on, int row, int col)
1419 1.4.4.2 rpaulo {
1420 1.4.4.2 rpaulo struct rasops_info *ri;
1421 1.4.4.2 rpaulo struct vcons_screen *scr;
1422 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1423 1.4.4.2 rpaulo int x, y, wi, he;
1424 1.4.4.2 rpaulo
1425 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1426 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1427 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1428 1.4.4.2 rpaulo
1429 1.4.4.2 rpaulo uni_wait_idle(sc);
1430 1.4.4.2 rpaulo
1431 1.4.4.2 rpaulo wi = ri->ri_font->fontwidth;
1432 1.4.4.2 rpaulo he = ri->ri_font->fontheight;
1433 1.4.4.2 rpaulo
1434 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1435 1.4.4.2 rpaulo x = ri->ri_ccol * wi + ri->ri_xorigin;
1436 1.4.4.2 rpaulo y = ri->ri_crow * he + ri->ri_yorigin;
1437 1.4.4.2 rpaulo if (ri->ri_flg & RI_CURSOR) {
1438 1.4.4.2 rpaulo uni_rectinvert(sc, x, y, wi, he);
1439 1.4.4.2 rpaulo ri->ri_flg &= ~RI_CURSOR;
1440 1.4.4.2 rpaulo }
1441 1.4.4.2 rpaulo ri->ri_crow = row;
1442 1.4.4.2 rpaulo ri->ri_ccol = col;
1443 1.4.4.2 rpaulo if (on) {
1444 1.4.4.2 rpaulo x = ri->ri_ccol * wi + ri->ri_xorigin;
1445 1.4.4.2 rpaulo y = ri->ri_crow * he + ri->ri_yorigin;
1446 1.4.4.2 rpaulo uni_rectinvert(sc, x, y, wi, he);
1447 1.4.4.2 rpaulo ri->ri_flg |= RI_CURSOR;
1448 1.4.4.2 rpaulo }
1449 1.4.4.2 rpaulo } else {
1450 1.4.4.2 rpaulo ri->ri_flg &= ~RI_CURSOR;
1451 1.4.4.2 rpaulo ri->ri_crow = row;
1452 1.4.4.2 rpaulo ri->ri_ccol = col;
1453 1.4.4.2 rpaulo }
1454 1.4.4.2 rpaulo
1455 1.4.4.2 rpaulo return;
1456 1.4.4.2 rpaulo }
1457 1.4.4.2 rpaulo
1458 1.4.4.2 rpaulo static void
1459 1.4.4.2 rpaulo uni_putchar(void *opaque, int row, int col, u_int c, long attr)
1460 1.4.4.2 rpaulo {
1461 1.4.4.2 rpaulo struct rasops_info *ri;
1462 1.4.4.2 rpaulo struct vcons_screen *scr;
1463 1.4.4.2 rpaulo struct unichromefb_softc *sc;
1464 1.4.4.2 rpaulo
1465 1.4.4.2 rpaulo ri = (struct rasops_info *)opaque;
1466 1.4.4.2 rpaulo scr = (struct vcons_screen *)ri->ri_hw;
1467 1.4.4.2 rpaulo sc = (struct unichromefb_softc *)scr->scr_cookie;
1468 1.4.4.2 rpaulo
1469 1.4.4.2 rpaulo if (sc->sc_wsmode == WSDISPLAYIO_MODE_EMUL) {
1470 1.4.4.2 rpaulo uint32_t *data;
1471 1.4.4.2 rpaulo int fg, bg, ul, uc, i;
1472 1.4.4.2 rpaulo int x, y, wi, he;
1473 1.4.4.2 rpaulo
1474 1.4.4.2 rpaulo wi = ri->ri_font->fontwidth;
1475 1.4.4.2 rpaulo he = ri->ri_font->fontheight;
1476 1.4.4.2 rpaulo
1477 1.4.4.2 rpaulo if (!CHAR_IN_FONT(c, ri->ri_font))
1478 1.4.4.2 rpaulo return;
1479 1.4.4.2 rpaulo
1480 1.4.4.2 rpaulo rasops_unpack_attr(attr, &fg, &bg, &ul);
1481 1.4.4.2 rpaulo x = ri->ri_xorigin + col * wi;
1482 1.4.4.2 rpaulo y = ri->ri_yorigin + row * he;
1483 1.4.4.2 rpaulo if (c == 0x20)
1484 1.4.4.2 rpaulo uni_fillrect(sc, x, y, wi, he, ri->ri_devcmap[bg]);
1485 1.4.4.2 rpaulo else {
1486 1.4.4.2 rpaulo uc = c - ri->ri_font->firstchar;
1487 1.4.4.2 rpaulo data = (uint32_t *)((uint8_t *)ri->ri_font->data +
1488 1.4.4.2 rpaulo uc * ri->ri_fontscale);
1489 1.4.4.2 rpaulo uni_setup_mono(sc, x, y, wi, he,
1490 1.4.4.2 rpaulo ri->ri_devcmap[fg], ri->ri_devcmap[bg]);
1491 1.4.4.2 rpaulo for (i = 0; i < (wi * he) / 4; i++) {
1492 1.4.4.2 rpaulo MMIO_OUT32(VIA_MMIO_BLTBASE, *data);
1493 1.4.4.2 rpaulo data++;
1494 1.4.4.2 rpaulo }
1495 1.4.4.2 rpaulo }
1496 1.4.4.2 rpaulo }
1497 1.4.4.2 rpaulo
1498 1.4.4.2 rpaulo return;
1499 1.4.4.2 rpaulo }
1500