1 /* $NetBSD: unichromefb.c,v 1.15 2009/05/06 09:25:17 cegger Exp $ */
4 * Copyright (c) 2006, 2008 Jared D. McNeill <jmcneill@invisible.ca>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
30 * Copyright 1998-2006 VIA Technologies, Inc. All Rights Reserved.
31 * Copyright 2001-2006 S3 Graphics, Inc. All Rights Reserved.
33 * Permission is hereby granted, free of charge, to any person obtaining a
34 * copy of this software and associated documentation files (the "Software"),
35 * to deal in the Software without restriction, including without limitation
36 * the rights to use, copy, modify, merge, publish, distribute, sub license,
37 * and/or sell copies of the Software, and to permit persons to whom the
38 * Software is furnished to do so, subject to the following conditions:
40 * The above copyright notice and this permission notice (including the
41 * next paragraph) shall be included in all copies or substantial portions
44 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
47 * THE AUTHOR(S) OR COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
48 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
49 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
50 * DEALINGS IN THE SOFTWARE.
53 #include <sys/cdefs.h>
54 __KERNEL_RCSID(0, "$NetBSD: unichromefb.c,v 1.15 2009/05/06 09:25:17 cegger Exp $");
56 #include <sys/param.h>
57 #include <sys/systm.h>
58 #include <sys/device.h>
59 #include <sys/malloc.h>
63 #include <dev/pci/pcivar.h>
64 #include <dev/pci/pcireg.h>
65 #include <dev/pci/pcidevs.h>
66 #include <dev/pci/pciio.h>
68 #include <dev/wscons/wsdisplayvar.h>
69 #include <dev/wscons/wsconsio.h>
70 #include <dev/wsfont/wsfont.h>
71 #include <dev/rasops/rasops.h>
72 #include <dev/wscons/wsdisplay_vconsvar.h>
74 #include <dev/pci/unichromereg.h>
75 #include <dev/pci/unichromemode.h>
76 #include <dev/pci/unichromehw.h>
77 #include <dev/pci/unichromeconfig.h>
78 #include <dev/pci/unichromeaccel.h>
83 #include <dev/ic/mc6845reg.h>
84 #include <dev/ic/pcdisplayvar.h>
85 #include <dev/ic/vgareg.h>
86 #include <dev/ic/vgavar.h>
90 #define UNICHROMEFB_DEPTH 16
91 #define UNICHROMEFB_MODE VIA_RES_1280X1024
92 #define UNICHROMEFB_WIDTH 1280
93 #define UNICHROMEFB_HEIGHT 1024
95 struct unichromefb_softc
{
97 struct vcons_data sc_vd
;
99 unsigned int sc_fbaddr
;
100 unsigned int sc_fbsize
;
101 bus_addr_t sc_mmiobase
;
102 bus_size_t sc_mmiosize
;
104 bus_space_tag_t sc_iot
;
105 bus_space_handle_t sc_ioh
;
107 bus_space_tag_t sc_memt
;
108 bus_space_handle_t sc_memh
;
109 bus_space_tag_t sc_apmemt
;
110 bus_space_handle_t sc_apmemh
;
112 struct pci_attach_args sc_pa
;
124 static int unichromefb_match(device_t
, cfdata_t
, void *);
125 static void unichromefb_attach(device_t
, device_t
, void *);
127 static int unichromefb_drm_print(void *, const char *);
128 static int unichromefb_drm_unmap(struct unichromefb_softc
*);
129 static int unichromefb_drm_map(struct unichromefb_softc
*);
131 struct wsscreen_descr unichromefb_stdscreen
= {
136 WSSCREEN_WSCOLORS
, NULL
,
139 static int unichromefb_ioctl(void *, void *, u_long
, void *, int,
141 static paddr_t
unichromefb_mmap(void *, void *, off_t
, int);
143 static void unichromefb_init_screen(void *, struct vcons_screen
*,
146 /* hardware access */
147 static uint8_t uni_rd(struct unichromefb_softc
*, int, uint8_t);
148 static void uni_wr(struct unichromefb_softc
*, int, uint8_t, uint8_t);
149 static void uni_wr_mask(struct unichromefb_softc
*, int, uint8_t,
151 static void uni_wr_x(struct unichromefb_softc
*, struct io_reg
*, int);
152 static void uni_wr_dac(struct unichromefb_softc
*, uint8_t, uint8_t,
156 static struct VideoModeTable
* uni_getmode(int);
157 static void uni_setmode(struct unichromefb_softc
*, int, int);
158 static void uni_crt_lock(struct unichromefb_softc
*);
159 static void uni_crt_unlock(struct unichromefb_softc
*);
160 static void uni_crt_enable(struct unichromefb_softc
*);
161 static void uni_crt_disable(struct unichromefb_softc
*);
162 static void uni_screen_enable(struct unichromefb_softc
*);
163 static void uni_screen_disable(struct unichromefb_softc
*);
164 static void uni_set_start(struct unichromefb_softc
*);
165 static void uni_set_crtc(struct unichromefb_softc
*,
166 struct crt_mode_table
*, int, int, int);
167 static void uni_load_crtc(struct unichromefb_softc
*, struct display_timing
,
169 static void uni_load_reg(struct unichromefb_softc
*, int, int,
170 struct io_register
*, int);
171 static void uni_fix_crtc(struct unichromefb_softc
*);
172 static void uni_load_offset(struct unichromefb_softc
*, int, int, int);
173 static void uni_load_fetchcnt(struct unichromefb_softc
*, int, int, int);
174 static void uni_load_fifo(struct unichromefb_softc
*, int, int, int);
175 static void uni_set_depth(struct unichromefb_softc
*, int, int);
176 static uint32_t uni_get_clkval(struct unichromefb_softc
*, int);
177 static void uni_set_vclk(struct unichromefb_softc
*, uint32_t, int);
178 static void uni_init_dac(struct unichromefb_softc
*, int);
179 static void uni_init_accel(struct unichromefb_softc
*);
180 static void uni_set_accel_depth(struct unichromefb_softc
*);
183 static void uni_wait_idle(struct unichromefb_softc
*);
184 static void uni_fillrect(struct unichromefb_softc
*,
185 int, int, int, int, int);
186 static void uni_rectinvert(struct unichromefb_softc
*,
188 static void uni_bitblit(struct unichromefb_softc
*, int, int, int, int,
190 static void uni_setup_mono(struct unichromefb_softc
*, int, int, int,
191 int, uint32_t, uint32_t);
193 static void uni_cursor_show(struct unichromefb_softc
*);
194 static void uni_cursor_hide(struct unichromefb_softc
*);
198 static void uni_copycols(void *, int, int, int, int);
199 static void uni_copyrows(void *, int, int, int);
200 static void uni_erasecols(void *, int, int, int, long);
201 static void uni_eraserows(void *, int, int, long);
202 static void uni_cursor(void *, int, int, int);
203 static void uni_putchar(void *, int, int, u_int
, long);
205 struct wsdisplay_accessops unichromefb_accessops
= {
216 static struct vcons_screen unichromefb_console_screen
;
218 const struct wsscreen_descr
*_unichromefb_scrlist
[] = {
219 &unichromefb_stdscreen
,
222 struct wsscreen_list unichromefb_screenlist
= {
223 sizeof(_unichromefb_scrlist
) / sizeof(struct wsscreen_descr
*),
227 CFATTACH_DECL_NEW(unichromefb
, sizeof(struct unichromefb_softc
),
228 unichromefb_match
, unichromefb_attach
, NULL
, NULL
);
231 unichromefb_match(device_t parent
, cfdata_t match
, void *opaque
)
233 struct pci_attach_args
*pa
;
235 pa
= (struct pci_attach_args
*)opaque
;
237 if (PCI_CLASS(pa
->pa_class
) != PCI_CLASS_DISPLAY
||
238 PCI_SUBCLASS(pa
->pa_class
) != PCI_SUBCLASS_DISPLAY_VGA
)
241 if (PCI_VENDOR(pa
->pa_id
) != PCI_VENDOR_VIATECH
)
244 switch (PCI_PRODUCT(pa
->pa_id
)) {
245 case PCI_PRODUCT_VIATECH_VT3314_IG
:
246 return 10; /* beat vga(4) */
253 unichromefb_attach(device_t parent
, device_t self
, void *opaque
)
255 struct unichromefb_softc
*sc
= device_private(self
);
256 struct pci_attach_args
*pa
;
257 struct rasops_info
*ri
;
258 struct wsemuldisplaydev_attach_args aa
;
262 pa
= (struct pci_attach_args
*)opaque
;
265 sc
->sc_width
= UNICHROMEFB_WIDTH
;
266 sc
->sc_height
= UNICHROMEFB_HEIGHT
;
267 sc
->sc_depth
= UNICHROMEFB_DEPTH
;
268 sc
->sc_stride
= sc
->sc_width
* (sc
->sc_depth
/ 8);
270 sc
->sc_wsmode
= WSDISPLAYIO_MODE_EMUL
;
272 sc
->sc_iot
= pa
->pa_iot
;
276 /* XXX vga_cnattach claims the I/O registers that we need;
277 * we need to nuke it here so we can take over.
282 if (bus_space_map(sc
->sc_iot
, VIA_REGBASE
, 0x20, 0, &sc
->sc_ioh
)) {
283 aprint_error(": failed to map I/O registers\n");
287 sc
->sc_apmemt
= pa
->pa_memt
;
288 val
= uni_rd(sc
, VIASR
, SR30
);
289 sc
->sc_fbaddr
= val
<< 24;
290 val
= uni_rd(sc
, VIASR
, SR39
);
291 sc
->sc_fbsize
= val
* (4*1024*1024);
292 if (sc
->sc_fbsize
< 16*1024*1024 || sc
->sc_fbsize
> 64*1024*1024)
293 sc
->sc_fbsize
= 16*1024*1024;
294 if (bus_space_map(sc
->sc_apmemt
, sc
->sc_fbaddr
, sc
->sc_fbsize
,
295 BUS_SPACE_MAP_LINEAR
, &sc
->sc_apmemh
)) {
296 aprint_error(": failed to map aperture at 0x%08x/0x%x\n",
297 sc
->sc_fbaddr
, sc
->sc_fbsize
);
300 sc
->sc_fbbase
= (void *)bus_space_vaddr(sc
->sc_apmemt
, sc
->sc_apmemh
);
302 if (pci_mapreg_map(pa
, 0x14, PCI_MAPREG_TYPE_MEM
, 0,
303 &sc
->sc_memt
, &sc
->sc_memh
, &sc
->sc_mmiobase
,
306 aprint_error(": failed to map MMIO registers\n");
312 aprint_normal(": VIA UniChrome frame buffer\n");
315 aprint_normal_dev(self
, "MMIO @0x%08x/0x%x\n",
316 (uint32_t)sc
->sc_mmiobase
,
317 (uint32_t)sc
->sc_mmiosize
);
319 ri
= &unichromefb_console_screen
.scr_ri
;
320 memset(ri
, 0, sizeof(struct rasops_info
));
322 vcons_init(&sc
->sc_vd
, sc
, &unichromefb_stdscreen
,
323 &unichromefb_accessops
);
324 sc
->sc_vd
.init_screen
= unichromefb_init_screen
;
326 uni_setmode(sc
, UNICHROMEFB_MODE
, sc
->sc_depth
);
328 uni_init_dac(sc
, IGA1
);
331 uni_fillrect(sc
, 0, 0, sc
->sc_width
, sc
->sc_height
, 0);
334 aprint_normal_dev(self
, "FB @0x%08x (%dx%dx%d)\n",
335 sc
->sc_fbaddr
, sc
->sc_width
, sc
->sc_height
, sc
->sc_depth
);
337 unichromefb_console_screen
.scr_flags
|= VCONS_SCREEN_IS_STATIC
;
338 vcons_init_screen(&sc
->sc_vd
, &unichromefb_console_screen
, 1, &defattr
);
340 unichromefb_stdscreen
.ncols
= ri
->ri_cols
;
341 unichromefb_stdscreen
.nrows
= ri
->ri_rows
;
342 unichromefb_stdscreen
.textops
= &ri
->ri_ops
;
343 unichromefb_stdscreen
.capabilities
= ri
->ri_caps
;
344 unichromefb_stdscreen
.modecookie
= NULL
;
346 wsdisplay_cnattach(&unichromefb_stdscreen
, ri
, 0, 0, defattr
);
348 aa
.console
= 1; /* XXX */
349 aa
.scrdata
= &unichromefb_screenlist
;
350 aa
.accessops
= &unichromefb_accessops
;
351 aa
.accesscookie
= &sc
->sc_vd
;
353 config_found(self
, &aa
, wsemuldisplaydevprint
);
355 config_found_ia(self
, "drm", opaque
, unichromefb_drm_print
);
361 unichromefb_drm_print(void *opaque
, const char *pnp
)
364 aprint_normal("drm at %s", pnp
);
370 unichromefb_drm_unmap(struct unichromefb_softc
*sc
)
372 aprint_debug_dev(sc
->sc_dev
, "releasing bus resources\n");
374 bus_space_unmap(sc
->sc_apmemt
, sc
->sc_apmemh
, sc
->sc_fbsize
);
375 bus_space_unmap(sc
->sc_memt
, sc
->sc_memh
, sc
->sc_mmiosize
);
376 bus_space_unmap(sc
->sc_iot
, sc
->sc_ioh
, 0x20);
382 unichromefb_drm_map(struct unichromefb_softc
*sc
)
386 rv
= bus_space_map(sc
->sc_iot
, VIA_REGBASE
, 0x20, 0,
389 aprint_error_dev(sc
->sc_dev
, "failed to map I/O registers\n");
392 rv
= bus_space_map(sc
->sc_apmemt
, sc
->sc_fbaddr
, sc
->sc_fbsize
,
393 BUS_SPACE_MAP_LINEAR
, &sc
->sc_apmemh
);
395 aprint_error_dev(sc
->sc_dev
,
396 "failed to map aperture at 0x%08x/0x%x\n",
397 sc
->sc_fbaddr
, sc
->sc_fbsize
);
400 sc
->sc_fbbase
= (void *)bus_space_vaddr(sc
->sc_apmemt
, sc
->sc_apmemh
);
401 rv
= pci_mapreg_map(&sc
->sc_pa
, 0x14, PCI_MAPREG_TYPE_MEM
, 0,
402 &sc
->sc_memt
, &sc
->sc_memh
, &sc
->sc_mmiobase
,
405 aprint_error_dev(sc
->sc_dev
, "failed to map MMIO registers\n");
409 uni_setmode(sc
, UNICHROMEFB_MODE
, sc
->sc_depth
);
410 uni_init_dac(sc
, IGA1
);
414 aprint_debug_dev(sc
->sc_dev
, "re-acquired bus resources\n");
420 unichromefb_ioctl(void *v
, void *vs
, u_long cmd
, void *data
, int flag
,
423 struct vcons_data
*vd
;
424 struct unichromefb_softc
*sc
;
425 struct wsdisplay_fbinfo
*fb
;
427 vd
= (struct vcons_data
*)v
;
428 sc
= (struct unichromefb_softc
*)vd
->cookie
;
431 case WSDISPLAYIO_GTYPE
:
432 *(u_int
*)data
= WSDISPLAY_TYPE_PCIMISC
;
434 case WSDISPLAYIO_GINFO
:
435 if (vd
->active
!= NULL
) {
436 fb
= (struct wsdisplay_fbinfo
*)data
;
437 fb
->width
= sc
->sc_width
;
438 fb
->height
= sc
->sc_height
;
439 fb
->depth
= sc
->sc_depth
;
444 case WSDISPLAYIO_GVIDEO
:
446 case WSDISPLAYIO_SVIDEO
:
448 case WSDISPLAYIO_GETCMAP
:
450 case WSDISPLAYIO_PUTCMAP
:
452 case WSDISPLAYIO_LINEBYTES
:
453 *(u_int
*)data
= sc
->sc_stride
;
455 case WSDISPLAYIO_SMODE
:
457 int new_mode
= *(int *)data
;
458 if (new_mode
!= sc
->sc_wsmode
) {
459 sc
->sc_wsmode
= new_mode
;
461 case WSDISPLAYIO_MODE_EMUL
:
462 unichromefb_drm_map(sc
);
463 vcons_redraw_screen(vd
->active
);
466 unichromefb_drm_unmap(sc
);
472 case WSDISPLAYIO_SSPLASH
:
474 case WSDISPLAYIO_SPROGRESS
:
477 /* PCI config read/write passthrough. */
478 case PCI_IOC_CFGREAD
:
479 case PCI_IOC_CFGWRITE
:
480 return (pci_devioctl(sc
->sc_pa
.pa_pc
, sc
->sc_pa
.pa_tag
,
481 cmd
, data
, flag
, l
));
488 unichromefb_mmap(void *v
, void *vs
, off_t offset
, int prot
)
494 unichromefb_init_screen(void *c
, struct vcons_screen
*scr
, int existing
,
497 struct unichromefb_softc
*sc
;
498 struct rasops_info
*ri
;
500 sc
= (struct unichromefb_softc
*)c
;
502 ri
->ri_flg
= RI_CENTER
;
503 ri
->ri_depth
= sc
->sc_depth
;
504 ri
->ri_width
= sc
->sc_width
;
505 ri
->ri_height
= sc
->sc_height
;
506 ri
->ri_stride
= sc
->sc_stride
;
507 ri
->ri_bits
= sc
->sc_fbbase
;
509 ri
->ri_flg
|= RI_CLEAR
;
511 switch (ri
->ri_depth
) {
513 ri
->ri_rnum
= ri
->ri_gnum
= ri
->ri_bnum
= 8;
528 rasops_init(ri
, sc
->sc_height
/ 16, sc
->sc_width
/ 8);
529 ri
->ri_caps
= WSSCREEN_WSCOLORS
;
530 rasops_reconfig(ri
, sc
->sc_height
/ ri
->ri_font
->fontheight
,
531 sc
->sc_width
/ ri
->ri_font
->fontwidth
);
535 ri
->ri_ops
.copyrows
= uni_copyrows
;
536 ri
->ri_ops
.copycols
= uni_copycols
;
537 ri
->ri_ops
.eraserows
= uni_eraserows
;
538 ri
->ri_ops
.erasecols
= uni_erasecols
;
539 ri
->ri_ops
.cursor
= uni_cursor
;
540 ri
->ri_ops
.putchar
= uni_putchar
;
550 uni_rd(struct unichromefb_softc
*sc
, int off
, uint8_t idx
)
552 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, off
, idx
);
553 return bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, off
+ 1);
557 uni_wr(struct unichromefb_softc
*sc
, int off
, uint8_t idx
, uint8_t val
)
559 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, off
, idx
);
560 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, off
+ 1, val
);
564 uni_wr_mask(struct unichromefb_softc
*sc
, int off
, uint8_t idx
,
565 uint8_t val
, uint8_t mask
)
569 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, off
, idx
);
570 tmp
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, off
+ 1);
571 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, off
+ 1,
572 ((val
& mask
) | (tmp
& ~mask
)));
576 uni_wr_dac(struct unichromefb_softc
*sc
, uint8_t idx
,
577 uint8_t r
, uint8_t g
, uint8_t b
)
579 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, LUT_INDEX_WRITE
, idx
);
580 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, LUT_DATA
, r
);
581 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, LUT_DATA
, g
);
582 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, LUT_DATA
, b
);
586 uni_wr_x(struct unichromefb_softc
*sc
, struct io_reg
*tbl
, int num
)
591 for (i
= 0; i
< num
; i
++) {
592 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, tbl
[i
].port
,
594 tmp
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
,
596 tmp
= (tmp
& (~tbl
[i
].mask
)) | tbl
[i
].value
;
597 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, tbl
[i
].index
+ 1,
605 static struct VideoModeTable
*
606 uni_getmode(int mode
)
610 for (i
= 0; i
< NUM_TOTAL_MODETABLE
; i
++)
611 if (CLE266Modes
[i
].ModeIndex
== mode
)
612 return &CLE266Modes
[i
];
618 uni_setmode(struct unichromefb_softc
*sc
, int idx
, int bpp
)
620 struct VideoModeTable
*vtbl
;
621 struct crt_mode_table
*crt
;
625 vtbl
= uni_getmode(idx
);
627 panic("%s: unsupported mode: %d\n",
628 device_xname(sc
->sc_dev
), idx
);
632 uni_screen_disable(sc
);
634 (void)bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, VIAStatus
);
635 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAAR
, 0);
637 /* XXX assume CN900 for now */
638 uni_wr_x(sc
, CN900_ModeXregs
, NUM_TOTAL_CN900_ModeXregs
);
642 /* Fill VPIT params */
643 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
, VPIT
.Misc
);
645 /* Write sequencer */
646 for (i
= 1; i
<= StdSR
; i
++) {
647 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIASR
, i
);
648 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIASR
+ 1,
654 uni_set_crtc(sc
, crt
, idx
, bpp
/ 8, IGA1
);
656 for (i
= 0; i
< StdGR
; i
++) {
657 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAGR
, i
);
658 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAGR
+ 1,
662 for (i
= 0; i
< StdAR
; i
++) {
663 (void)bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, VIAStatus
);
664 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAAR
, i
);
665 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAAR
,
669 (void)bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, VIAStatus
);
670 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAAR
, 0x20);
672 uni_set_crtc(sc
, crt
, idx
, bpp
/ 8, IGA1
);
673 /* set crt output path */
674 uni_wr_mask(sc
, VIASR
, SR16
, 0x00, BIT6
);
677 uni_screen_enable(sc
);
683 uni_crt_lock(struct unichromefb_softc
*sc
)
685 uni_wr_mask(sc
, VIACR
, CR11
, BIT7
, BIT7
);
689 uni_crt_unlock(struct unichromefb_softc
*sc
)
691 uni_wr_mask(sc
, VIACR
, CR11
, 0, BIT7
);
692 uni_wr_mask(sc
, VIACR
, CR47
, 0, BIT0
);
696 uni_crt_enable(struct unichromefb_softc
*sc
)
698 uni_wr_mask(sc
, VIACR
, CR36
, 0, BIT5
+BIT4
);
702 uni_crt_disable(struct unichromefb_softc
*sc
)
704 uni_wr_mask(sc
, VIACR
, CR36
, BIT5
+BIT4
, BIT5
+BIT4
);
708 uni_screen_enable(struct unichromefb_softc
*sc
)
710 uni_wr_mask(sc
, VIASR
, SR01
, 0, BIT5
);
714 uni_screen_disable(struct unichromefb_softc
*sc
)
716 uni_wr_mask(sc
, VIASR
, SR01
, 0x20, BIT5
);
720 uni_set_start(struct unichromefb_softc
*sc
)
724 uni_wr(sc
, VIACR
, CR0C
, 0x00);
725 uni_wr(sc
, VIACR
, CR0D
, 0x00);
726 uni_wr(sc
, VIACR
, CR34
, 0x00);
727 uni_wr_mask(sc
, VIACR
, CR48
, 0x00, BIT0
+ BIT1
);
729 uni_wr(sc
, VIACR
, CR62
, 0x00);
730 uni_wr(sc
, VIACR
, CR63
, 0x00);
731 uni_wr(sc
, VIACR
, CR64
, 0x00);
732 uni_wr(sc
, VIACR
, CRA3
, 0x00);
738 uni_set_crtc(struct unichromefb_softc
*sc
, struct crt_mode_table
*ctbl
,
739 int mode
, int bpp_byte
, int iga
)
741 struct VideoModeTable
*vtbl
;
742 struct display_timing crtreg
;
751 vtbl
= uni_getmode(mode
);
752 for (i
= 0; i
< vtbl
->mode_array
; i
++) {
754 if (ctbl
[i
].refresh_rate
== 60)
758 crtreg
= ctbl
[index
].crtc
;
760 haddr
= crtreg
.hor_addr
;
761 vaddr
= crtreg
.ver_addr
;
763 val
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, VIARMisc
);
764 if (ctbl
[index
].h_sync_polarity
== NEGATIVE
) {
765 if (ctbl
[index
].v_sync_polarity
== NEGATIVE
)
766 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
,
767 (val
& (~(BIT6
+BIT7
))) | (BIT6
+BIT7
));
769 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
,
770 (val
& (~(BIT6
+BIT7
))) | (BIT6
));
772 if (ctbl
[index
].v_sync_polarity
== NEGATIVE
)
773 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
,
774 (val
& (~(BIT6
+BIT7
))) | (BIT7
));
776 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
,
777 (val
& (~(BIT6
+BIT7
))));
782 uni_wr(sc
, VIACR
, CR09
, 0x00);
783 uni_wr_mask(sc
, VIACR
, CR11
, 0x00, BIT4
+BIT5
+BIT6
);
784 uni_wr_mask(sc
, VIACR
, CR17
, 0x00, BIT7
);
787 uni_load_crtc(sc
, crtreg
, iga
);
790 uni_wr_mask(sc
, VIACR
, CR17
, 0x80, BIT7
);
792 uni_load_offset(sc
, haddr
, bpp_byte
, iga
);
793 uni_load_fetchcnt(sc
, haddr
, bpp_byte
, iga
);
794 uni_load_fifo(sc
, iga
, haddr
, vaddr
);
796 uni_set_depth(sc
, bpp_byte
, iga
);
797 pll_d_n
= uni_get_clkval(sc
, ctbl
[index
].clk
);
798 uni_set_vclk(sc
, pll_d_n
, iga
);
802 uni_load_crtc(struct unichromefb_softc
*sc
,
803 struct display_timing device_timing
, int iga
)
806 struct io_register
*reg
;
814 for (i
= 0; i
< 12; i
++) {
819 val
= IGA1_HOR_TOTAL_FORMULA(
820 device_timing
.hor_total
);
821 regnum
= iga1_crtc_reg
.hor_total
.reg_num
;
822 reg
= iga1_crtc_reg
.hor_total
.reg
;
825 val
= IGA1_HOR_ADDR_FORMULA(
826 device_timing
.hor_addr
);
827 regnum
= iga1_crtc_reg
.hor_addr
.reg_num
;
828 reg
= iga1_crtc_reg
.hor_addr
.reg
;
830 case H_BLANK_START_INDEX
:
831 val
= IGA1_HOR_BLANK_START_FORMULA(
832 device_timing
.hor_blank_start
);
833 regnum
= iga1_crtc_reg
.hor_blank_start
.reg_num
;
834 reg
= iga1_crtc_reg
.hor_blank_start
.reg
;
836 case H_BLANK_END_INDEX
:
837 val
= IGA1_HOR_BLANK_END_FORMULA(
838 device_timing
.hor_blank_start
,
839 device_timing
.hor_blank_end
);
840 regnum
= iga1_crtc_reg
.hor_blank_end
.reg_num
;
841 reg
= iga1_crtc_reg
.hor_blank_end
.reg
;
843 case H_SYNC_START_INDEX
:
844 val
= IGA1_HOR_SYNC_START_FORMULA(
845 device_timing
.hor_sync_start
);
846 regnum
= iga1_crtc_reg
.hor_sync_start
.reg_num
;
847 reg
= iga1_crtc_reg
.hor_sync_start
.reg
;
849 case H_SYNC_END_INDEX
:
850 val
= IGA1_HOR_SYNC_END_FORMULA(
851 device_timing
.hor_sync_start
,
852 device_timing
.hor_sync_end
);
853 regnum
= iga1_crtc_reg
.hor_sync_end
.reg_num
;
854 reg
= iga1_crtc_reg
.hor_sync_end
.reg
;
857 val
= IGA1_VER_TOTAL_FORMULA(
858 device_timing
.ver_total
);
859 regnum
= iga1_crtc_reg
.ver_total
.reg_num
;
860 reg
= iga1_crtc_reg
.ver_total
.reg
;
863 val
= IGA1_VER_ADDR_FORMULA(
864 device_timing
.ver_addr
);
865 regnum
= iga1_crtc_reg
.ver_addr
.reg_num
;
866 reg
= iga1_crtc_reg
.ver_addr
.reg
;
868 case V_BLANK_START_INDEX
:
869 val
= IGA1_VER_BLANK_START_FORMULA(
870 device_timing
.ver_blank_start
);
871 regnum
= iga1_crtc_reg
.ver_blank_start
.reg_num
;
872 reg
= iga1_crtc_reg
.ver_blank_start
.reg
;
874 case V_BLANK_END_INDEX
:
875 val
= IGA1_VER_BLANK_END_FORMULA(
876 device_timing
.ver_blank_start
,
877 device_timing
.ver_blank_end
);
878 regnum
= iga1_crtc_reg
.ver_blank_end
.reg_num
;
879 reg
= iga1_crtc_reg
.ver_blank_end
.reg
;
881 case V_SYNC_START_INDEX
:
882 val
= IGA1_VER_SYNC_START_FORMULA(
883 device_timing
.ver_sync_start
);
884 regnum
= iga1_crtc_reg
.ver_sync_start
.reg_num
;
885 reg
= iga1_crtc_reg
.ver_sync_start
.reg
;
887 case V_SYNC_END_INDEX
:
888 val
= IGA1_VER_SYNC_END_FORMULA(
889 device_timing
.ver_sync_start
,
890 device_timing
.ver_sync_end
);
891 regnum
= iga1_crtc_reg
.ver_sync_end
.reg_num
;
892 reg
= iga1_crtc_reg
.ver_sync_end
.reg
;
895 aprint_error_dev(sc
->sc_dev
,
896 "unknown index %d while setting up CRTC\n",
902 aprint_error_dev(sc
->sc_dev
, "%s: IGA2 not supported\n",
907 uni_load_reg(sc
, val
, regnum
, reg
, VIACR
);
914 uni_load_reg(struct unichromefb_softc
*sc
, int timing
, int regnum
,
915 struct io_register
*reg
, int type
)
917 int regmask
, bitnum
, data
;
920 int startidx
, endidx
, cridx
;
925 for (i
= 0; i
< regnum
; i
++) {
927 startidx
= reg
[i
].start_bit
;
928 endidx
= reg
[i
].end_bit
;
929 cridx
= reg
[i
].io_addr
;
931 shift_next_reg
= bitnum
;
933 for (j
= startidx
; j
<= endidx
; j
++) {
934 regmask
= regmask
| (BIT0
<< j
);
935 getbit
= (timing
& (BIT0
<< bitnum
));
936 data
= data
| ((getbit
>> shift_next_reg
) << startidx
);
941 uni_wr_mask(sc
, VIACR
, cridx
, data
, regmask
);
943 uni_wr_mask(sc
, VIASR
, cridx
, data
, regmask
);
950 uni_fix_crtc(struct unichromefb_softc
*sc
)
952 uni_wr_mask(sc
, VIACR
, CR03
, 0x80, BIT7
);
953 uni_wr(sc
, VIACR
, CR18
, 0xff);
954 uni_wr_mask(sc
, VIACR
, CR07
, 0x10, BIT4
);
955 uni_wr_mask(sc
, VIACR
, CR09
, 0x40, BIT6
);
956 uni_wr_mask(sc
, VIACR
, CR35
, 0x10, BIT4
);
957 uni_wr_mask(sc
, VIACR
, CR33
, 0x06, BIT0
+BIT1
+BIT2
);
958 uni_wr(sc
, VIACR
, CR17
, 0xe3);
959 uni_wr(sc
, VIACR
, CR08
, 0x00);
960 uni_wr(sc
, VIACR
, CR14
, 0x00);
966 uni_load_offset(struct unichromefb_softc
*sc
, int haddr
, int bpp
, int iga
)
972 IGA1_OFFSET_FORMULA(haddr
, bpp
),
973 offset_reg
.iga1_offset_reg
.reg_num
,
974 offset_reg
.iga1_offset_reg
.reg
,
978 aprint_error_dev(sc
->sc_dev
, "%s: only IGA1 is supported\n",
987 uni_load_fetchcnt(struct unichromefb_softc
*sc
, int haddr
, int bpp
, int iga
)
993 IGA1_FETCH_COUNT_FORMULA(haddr
, bpp
),
994 fetch_count_reg
.iga1_fetch_count_reg
.reg_num
,
995 fetch_count_reg
.iga1_fetch_count_reg
.reg
,
999 aprint_error_dev(sc
->sc_dev
, "%s: only IGA1 is supported\n",
1008 uni_load_fifo(struct unichromefb_softc
*sc
, int iga
, int horact
, int veract
)
1011 struct io_register
*reg
;
1012 int iga1_fifo_max_depth
, iga1_fifo_threshold
;
1013 int iga1_fifo_high_threshold
, iga1_display_queue_expire_num
;
1016 iga1_fifo_max_depth
= iga1_fifo_threshold
= 0;
1017 iga1_fifo_high_threshold
= iga1_display_queue_expire_num
= 0;
1021 /* XXX if (type == CN900) { */
1022 iga1_fifo_max_depth
= CN900_IGA1_FIFO_MAX_DEPTH
;
1023 iga1_fifo_threshold
= CN900_IGA1_FIFO_THRESHOLD
;
1024 iga1_fifo_high_threshold
= CN900_IGA1_FIFO_HIGH_THRESHOLD
;
1025 if (horact
> 1280 && veract
> 1024)
1026 iga1_display_queue_expire_num
= 16;
1028 iga1_display_queue_expire_num
=
1029 CN900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM
;
1032 /* set display FIFO depth select */
1033 val
= IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth
);
1035 display_fifo_depth_reg
.iga1_fifo_depth_select_reg
.reg_num
;
1036 reg
= display_fifo_depth_reg
.iga1_fifo_depth_select_reg
.reg
;
1037 uni_load_reg(sc
, val
, regnum
, reg
, VIASR
);
1039 /* set display FIFO threshold select */
1040 val
= IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold
);
1041 regnum
= fifo_threshold_select_reg
.iga1_fifo_threshold_select_reg
.reg_num
;
1042 reg
= fifo_threshold_select_reg
.iga1_fifo_threshold_select_reg
.reg
;
1043 uni_load_reg(sc
, val
, regnum
, reg
, VIASR
);
1045 /* set display FIFO high threshold select */
1046 val
= IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold
);
1047 regnum
= fifo_high_threshold_select_reg
.iga1_fifo_high_threshold_select_reg
.reg_num
;
1048 reg
= fifo_high_threshold_select_reg
.iga1_fifo_high_threshold_select_reg
.reg
;
1049 uni_load_reg(sc
, val
, regnum
, reg
, VIASR
);
1051 /* set display queue expire num */
1052 val
= IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA(iga1_display_queue_expire_num
);
1053 regnum
= display_queue_expire_num_reg
.iga1_display_queue_expire_num_reg
.reg_num
;
1054 reg
= display_queue_expire_num_reg
.iga1_display_queue_expire_num_reg
.reg
;
1055 uni_load_reg(sc
, val
, regnum
, reg
, VIASR
);
1059 aprint_error_dev(sc
->sc_dev
, "%s: only IGA1 is supported\n",
1068 uni_set_depth(struct unichromefb_softc
*sc
, int bpp
, int iga
)
1074 uni_wr_mask(sc
, VIASR
, SR15
, 0xae, 0xfe);
1077 uni_wr_mask(sc
, VIASR
, SR15
, 0xb6, 0xfe);
1080 uni_wr_mask(sc
, VIASR
, SR15
, 0x22, 0xfe);
1083 aprint_error_dev(sc
->sc_dev
,
1084 "%s: mode (%d) unsupported\n", __func__
, bpp
);
1088 aprint_error_dev(sc
->sc_dev
, "%s: only IGA1 is supported\n",
1095 uni_get_clkval(struct unichromefb_softc
*sc
, int clk
)
1099 for (i
= 0; i
< NUM_TOTAL_PLL_TABLE
; i
++) {
1100 if (clk
== pll_value
[i
].clk
) {
1101 /* XXX only CN900 supported for now */
1102 return pll_value
[i
].k800_pll
;
1106 aprint_error_dev(sc
->sc_dev
, "can't find matching PLL value\n");
1112 uni_set_vclk(struct unichromefb_softc
*sc
, uint32_t clk
, int iga
)
1116 /* hardware reset on */
1117 uni_wr_mask(sc
, VIACR
, CR17
, 0x00, BIT7
);
1121 /* XXX only CN900 is supported */
1122 uni_wr(sc
, VIASR
, SR44
, clk
/ 0x10000);
1123 uni_wr(sc
, VIASR
, SR45
, (clk
& 0xffff) / 0x100);
1124 uni_wr(sc
, VIASR
, SR46
, clk
% 0x100);
1127 aprint_error_dev(sc
->sc_dev
, "%s: only IGA1 is supported\n",
1132 /* hardware reset off */
1133 uni_wr_mask(sc
, VIACR
, CR17
, 0x80, BIT7
);
1138 uni_wr_mask(sc
, VIASR
, SR40
, 0x02, BIT1
);
1139 uni_wr_mask(sc
, VIASR
, SR40
, 0x00, BIT1
);
1144 val
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, VIARMisc
);
1146 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, VIAWMisc
, val
);
1152 uni_init_dac(struct unichromefb_softc
*sc
, int iga
)
1156 /* XXX only IGA1 for now */
1157 uni_wr_mask(sc
, VIASR
, SR1A
, 0x00, BIT0
);
1158 uni_wr_mask(sc
, VIASR
, SR18
, 0x00, BIT7
+BIT6
);
1159 for (i
= 0; i
< 256; i
++)
1161 palLUT_table
[i
].red
, palLUT_table
[i
].green
, palLUT_table
[i
].blue
);
1163 uni_wr_mask(sc
, VIASR
, SR18
, 0xc0, BIT7
+BIT6
);
1169 uni_init_accel(struct unichromefb_softc
*sc
)
1172 /* init 2D engine regs to reset 2D engine */
1173 MMIO_OUT32(VIA_REG_GEMODE
, 0);
1174 MMIO_OUT32(VIA_REG_SRCPOS
, 0);
1175 MMIO_OUT32(VIA_REG_DSTPOS
, 0);
1176 MMIO_OUT32(VIA_REG_DIMENSION
, 0);
1177 MMIO_OUT32(VIA_REG_PATADDR
, 0);
1178 MMIO_OUT32(VIA_REG_FGCOLOR
, 0);
1179 MMIO_OUT32(VIA_REG_BGCOLOR
, 0);
1180 MMIO_OUT32(VIA_REG_CLIPTL
, 0);
1181 MMIO_OUT32(VIA_REG_CLIPBR
, 0);
1182 MMIO_OUT32(VIA_REG_OFFSET
, 0);
1183 MMIO_OUT32(VIA_REG_KEYCONTROL
, 0);
1184 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1185 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1186 MMIO_OUT32(VIA_REG_PITCH
, 0);
1187 MMIO_OUT32(VIA_REG_MONOPAT1
, 0);
1189 /* init AGP and VQ registers */
1190 MMIO_OUT32(VIA_REG_TRANSET
, 0x00100000);
1191 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x00000000);
1192 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x00333004);
1193 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x60000000);
1194 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x61000000);
1195 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x62000000);
1196 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x63000000);
1197 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x64000000);
1198 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x7d000000);
1200 MMIO_OUT32(VIA_REG_TRANSET
, 0xfe020000);
1201 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x00000000);
1204 MMIO_OUT32(VIA_REG_TRANSET
, 0x00fe0000);
1205 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x00000004);
1206 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x40008c0f);
1207 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x44000000);
1208 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x45080c04);
1209 MMIO_OUT32(VIA_REG_TRANSPACE
, 0x46800408);
1211 uni_set_accel_depth(sc
);
1213 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1214 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1216 MMIO_OUT32(VIA_REG_PITCH
, VIA_PITCH_ENABLE
|
1217 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) |
1218 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) << 16)));
1224 uni_set_accel_depth(struct unichromefb_softc
*sc
)
1228 gemode
= MMIO_IN32(0x04) & 0xfffffcff;
1230 switch (sc
->sc_depth
) {
1232 gemode
|= VIA_GEM_32bpp
;
1235 gemode
|= VIA_GEM_16bpp
;
1238 gemode
|= VIA_GEM_8bpp
;
1242 /* set colour depth and pitch */
1243 MMIO_OUT32(VIA_REG_GEMODE
, gemode
);
1249 uni_wait_idle(struct unichromefb_softc
*sc
)
1253 while (!(MMIO_IN32(VIA_REG_STATUS
) & VIA_VR_QUEUE_BUSY
) &&
1257 while ((MMIO_IN32(VIA_REG_STATUS
) &
1258 (VIA_CMD_RGTR_BUSY
| VIA_2D_ENG_BUSY
| VIA_3D_ENG_BUSY
)) &&
1262 if (loop
>= MAXLOOP
)
1263 aprint_error_dev(sc
->sc_dev
, "engine stall\n");
1269 uni_fillrect(struct unichromefb_softc
*sc
, int x
, int y
, int width
,
1270 int height
, int colour
)
1275 MMIO_OUT32(VIA_REG_SRCPOS
, 0);
1276 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1277 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1278 MMIO_OUT32(VIA_REG_PITCH
, VIA_PITCH_ENABLE
|
1279 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) |
1280 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) << 16)));
1281 MMIO_OUT32(VIA_REG_DSTPOS
, ((y
<< 16) | x
));
1282 MMIO_OUT32(VIA_REG_DIMENSION
,
1283 (((height
- 1) << 16) | (width
- 1)));
1284 MMIO_OUT32(VIA_REG_FGCOLOR
, colour
);
1285 MMIO_OUT32(VIA_REG_GECMD
, (0x01 | 0x2000 | 0xf0 << 24));
1291 uni_rectinvert(struct unichromefb_softc
*sc
, int x
, int y
, int width
,
1297 MMIO_OUT32(VIA_REG_SRCPOS
, 0);
1298 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1299 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1300 MMIO_OUT32(VIA_REG_PITCH
, VIA_PITCH_ENABLE
|
1301 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) |
1302 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) << 16)));
1303 MMIO_OUT32(VIA_REG_DSTPOS
, ((y
<< 16) | x
));
1304 MMIO_OUT32(VIA_REG_DIMENSION
,
1305 (((height
- 1) << 16) | (width
- 1)));
1306 MMIO_OUT32(VIA_REG_GECMD
, (0x01 | 0x2000 | 0x55 << 24));
1312 uni_bitblit(struct unichromefb_softc
*sc
, int xs
, int ys
, int xd
, int yd
, int width
, int height
)
1332 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1333 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1334 MMIO_OUT32(VIA_REG_PITCH
, VIA_PITCH_ENABLE
|
1335 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) |
1336 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) << 16)));
1337 MMIO_OUT32(VIA_REG_SRCPOS
, ys
<< 16 | xs
);
1338 MMIO_OUT32(VIA_REG_DSTPOS
, yd
<< 16 | xd
);
1339 MMIO_OUT32(VIA_REG_DIMENSION
, ((height
- 1) << 16) | (width
- 1));
1340 MMIO_OUT32(VIA_REG_GECMD
, (0x01 | dir
| (0xcc << 24)));
1346 uni_setup_mono(struct unichromefb_softc
*sc
, int xd
, int yd
, int width
, int height
,
1347 uint32_t fg
, uint32_t bg
)
1352 MMIO_OUT32(VIA_REG_SRCBASE
, 0);
1353 MMIO_OUT32(VIA_REG_DSTBASE
, 0);
1354 MMIO_OUT32(VIA_REG_PITCH
, VIA_PITCH_ENABLE
|
1355 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) |
1356 (((sc
->sc_width
* sc
->sc_depth
>> 3) >> 3) << 16)));
1357 MMIO_OUT32(VIA_REG_SRCPOS
, 0);
1358 MMIO_OUT32(VIA_REG_DSTPOS
, (yd
<< 16) | xd
);
1359 MMIO_OUT32(VIA_REG_DIMENSION
, ((height
- 1) << 16) | (width
- 1));
1360 MMIO_OUT32(VIA_REG_FGCOLOR
, fg
);
1361 MMIO_OUT32(VIA_REG_BGCOLOR
, bg
);
1362 MMIO_OUT32(VIA_REG_GECMD
, 0xcc020142);
1369 uni_cursor_show(struct unichromefb_softc
*sc
)
1373 val
= MMIO_IN32(VIA_REG_CURSOR_MODE
);
1375 MMIO_OUT32(VIA_REG_CURSOR_MODE
, val
);
1381 uni_cursor_hide(struct unichromefb_softc
*sc
)
1385 val
= MMIO_IN32(VIA_REG_CURSOR_MODE
);
1387 MMIO_OUT32(VIA_REG_CURSOR_MODE
, val
);
1397 uni_copycols(void *opaque
, int row
, int srccol
, int dstcol
, int ncols
)
1399 struct rasops_info
*ri
;
1400 struct vcons_screen
*scr
;
1401 struct unichromefb_softc
*sc
;
1402 int xs
, xd
, y
, width
, height
;
1404 ri
= (struct rasops_info
*)opaque
;
1405 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1406 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1408 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1409 xs
= ri
->ri_xorigin
+ ri
->ri_font
->fontwidth
* srccol
;
1410 xd
= ri
->ri_xorigin
+ ri
->ri_font
->fontwidth
* dstcol
;
1411 y
= ri
->ri_yorigin
+ ri
->ri_font
->fontheight
* row
;
1412 width
= ri
->ri_font
->fontwidth
* ncols
;
1413 height
= ri
->ri_font
->fontheight
;
1414 uni_bitblit(sc
, xs
, y
, xd
, y
, width
, height
);
1421 uni_copyrows(void *opaque
, int srcrow
, int dstrow
, int nrows
)
1423 struct rasops_info
*ri
;
1424 struct vcons_screen
*scr
;
1425 struct unichromefb_softc
*sc
;
1426 int x
, ys
, yd
, width
, height
;
1428 ri
= (struct rasops_info
*)opaque
;
1429 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1430 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1432 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1434 ys
= ri
->ri_yorigin
+ ri
->ri_font
->fontheight
* srcrow
;
1435 yd
= ri
->ri_yorigin
+ ri
->ri_font
->fontheight
* dstrow
;
1436 width
= ri
->ri_emuwidth
;
1437 height
= ri
->ri_font
->fontheight
* nrows
;
1438 uni_bitblit(sc
, x
, ys
, x
, yd
, width
, height
);
1445 uni_erasecols(void *opaque
, int row
, int startcol
, int ncols
, long fillattr
)
1447 struct rasops_info
*ri
;
1448 struct vcons_screen
*scr
;
1449 struct unichromefb_softc
*sc
;
1450 int x
, y
, width
, height
, fg
, bg
, ul
;
1452 ri
= (struct rasops_info
*)opaque
;
1453 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1454 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1456 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1457 x
= ri
->ri_xorigin
+ ri
->ri_font
->fontwidth
* startcol
;
1458 y
= ri
->ri_yorigin
+ ri
->ri_font
->fontheight
* row
;
1459 width
= ri
->ri_font
->fontwidth
* ncols
;
1460 height
= ri
->ri_font
->fontheight
;
1461 rasops_unpack_attr(fillattr
, &fg
, &bg
, &ul
);
1462 uni_fillrect(sc
, x
, y
, width
, height
, ri
->ri_devcmap
[bg
]);
1469 uni_eraserows(void *opaque
, int row
, int nrows
, long fillattr
)
1471 struct rasops_info
*ri
;
1472 struct vcons_screen
*scr
;
1473 struct unichromefb_softc
*sc
;
1474 int x
, y
, width
, height
, fg
, bg
, ul
;
1476 ri
= (struct rasops_info
*)opaque
;
1477 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1478 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1480 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1481 rasops_unpack_attr(fillattr
, &fg
, &bg
, &ul
);
1482 if ((row
== 0) && (nrows
== ri
->ri_rows
)) {
1483 /* clear the whole screen */
1484 uni_fillrect(sc
, 0, 0, ri
->ri_width
,
1485 ri
->ri_height
, ri
->ri_devcmap
[bg
]);
1488 y
= ri
->ri_yorigin
+ ri
->ri_font
->fontheight
* row
;
1489 width
= ri
->ri_emuwidth
;
1490 height
= ri
->ri_font
->fontheight
* nrows
;
1491 uni_fillrect(sc
, x
, y
, width
, height
,
1492 ri
->ri_devcmap
[bg
]);
1500 uni_cursor(void *opaque
, int on
, int row
, int col
)
1502 struct rasops_info
*ri
;
1503 struct vcons_screen
*scr
;
1504 struct unichromefb_softc
*sc
;
1507 ri
= (struct rasops_info
*)opaque
;
1508 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1509 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1513 wi
= ri
->ri_font
->fontwidth
;
1514 he
= ri
->ri_font
->fontheight
;
1516 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1517 x
= ri
->ri_ccol
* wi
+ ri
->ri_xorigin
;
1518 y
= ri
->ri_crow
* he
+ ri
->ri_yorigin
;
1519 if (ri
->ri_flg
& RI_CURSOR
) {
1520 uni_rectinvert(sc
, x
, y
, wi
, he
);
1521 ri
->ri_flg
&= ~RI_CURSOR
;
1526 x
= ri
->ri_ccol
* wi
+ ri
->ri_xorigin
;
1527 y
= ri
->ri_crow
* he
+ ri
->ri_yorigin
;
1528 uni_rectinvert(sc
, x
, y
, wi
, he
);
1529 ri
->ri_flg
|= RI_CURSOR
;
1532 ri
->ri_flg
&= ~RI_CURSOR
;
1541 uni_putchar(void *opaque
, int row
, int col
, u_int c
, long attr
)
1543 struct rasops_info
*ri
;
1544 struct vcons_screen
*scr
;
1545 struct unichromefb_softc
*sc
;
1547 ri
= (struct rasops_info
*)opaque
;
1548 scr
= (struct vcons_screen
*)ri
->ri_hw
;
1549 sc
= (struct unichromefb_softc
*)scr
->scr_cookie
;
1551 if (sc
->sc_wsmode
== WSDISPLAYIO_MODE_EMUL
) {
1553 int fg
, bg
, ul
, uc
, i
;
1556 wi
= ri
->ri_font
->fontwidth
;
1557 he
= ri
->ri_font
->fontheight
;
1559 if (!CHAR_IN_FONT(c
, ri
->ri_font
))
1562 rasops_unpack_attr(attr
, &fg
, &bg
, &ul
);
1563 x
= ri
->ri_xorigin
+ col
* wi
;
1564 y
= ri
->ri_yorigin
+ row
* he
;
1566 uni_fillrect(sc
, x
, y
, wi
, he
, ri
->ri_devcmap
[bg
]);
1568 uc
= c
- ri
->ri_font
->firstchar
;
1569 data
= (uint32_t *)((uint8_t *)ri
->ri_font
->data
+
1570 uc
* ri
->ri_fontscale
);
1571 uni_setup_mono(sc
, x
, y
, wi
, he
,
1572 ri
->ri_devcmap
[fg
], ri
->ri_devcmap
[bg
]);
1573 for (i
= 0; i
< (wi
* he
) / 4; i
++) {
1574 MMIO_OUT32(VIA_MMIO_BLTBASE
, *data
);