Module Name: src
Committed By: jmcneill
Date: Sun Jan 21 13:05:29 UTC 2024
Modified Files:
src/sys/arch/evbppc/wii/dev: vireg.h wiifb.c
Added Files:
src/sys/arch/evbppc/wii/dev: viio.h
Log Message:
wii: Add NTSC 480p support.
In addition to this, add VIIO_{GET,SET}REGS ioctl support to allow for
poking at video interface registers from userland. This is helpful for
debugging display issues.
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/evbppc/wii/dev/viio.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/evbppc/wii/dev/vireg.h \
src/sys/arch/evbppc/wii/dev/wiifb.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/evbppc/wii/dev/vireg.h
diff -u src/sys/arch/evbppc/wii/dev/vireg.h:1.1 src/sys/arch/evbppc/wii/dev/vireg.h:1.2
--- src/sys/arch/evbppc/wii/dev/vireg.h:1.1 Sat Jan 20 21:36:00 2024
+++ src/sys/arch/evbppc/wii/dev/vireg.h Sun Jan 21 13:05:29 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: vireg.h,v 1.1 2024/01/20 21:36:00 jmcneill Exp $ */
+/* $NetBSD: vireg.h,v 1.2 2024/01/21 13:05:29 jmcneill Exp $ */
/*-
* Copyright (c) 2024 Jared McNeill <[email protected]>
@@ -163,7 +163,8 @@
/* [2B] VISEL - VI DTV Status Register */
#define VI_VISEL 0x6e
-#define VI_VISEL_SEL __BIT(2)
+#define VI_VISEL_SEL __BIT(2)
+#define VI_VISEL_COMPONENT_CABLE __BIT(0)
/* [2B] VI_HSCALINGW - Horizontal Scaling Width */
#define VI_HSCALINGW 0x70
Index: src/sys/arch/evbppc/wii/dev/wiifb.c
diff -u src/sys/arch/evbppc/wii/dev/wiifb.c:1.1 src/sys/arch/evbppc/wii/dev/wiifb.c:1.2
--- src/sys/arch/evbppc/wii/dev/wiifb.c:1.1 Sat Jan 20 21:36:00 2024
+++ src/sys/arch/evbppc/wii/dev/wiifb.c Sun Jan 21 13:05:29 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: wiifb.c,v 1.1 2024/01/20 21:36:00 jmcneill Exp $ */
+/* $NetBSD: wiifb.c,v 1.2 2024/01/21 13:05:29 jmcneill Exp $ */
/*-
* Copyright (c) 2024 Jared McNeill <[email protected]>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wiifb.c,v 1.1 2024/01/20 21:36:00 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wiifb.c,v 1.2 2024/01/21 13:05:29 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: wiifb.c,v 1.
#include "mainbus.h"
#include "vireg.h"
+#include "viio.h"
#define WIIFB_ERROR_BLINK_INTERVAL 1000000
@@ -179,30 +180,22 @@ static void
wiifb_init(struct wiifb_softc *sc)
{
uint16_t dcr;
+ uint16_t visel;
-#if notyet
/* Read current display format and interlaced settings. */
dcr = RD2(sc, VI_DCR);
- sc->sc_format = __SHIFTOUT(dcr, VI_DCR_FMT);
- sc->sc_interlaced = (dcr & VI_DCR_NIN) == 0;
+ if ((dcr & VI_DCR_ENB) != 0) {
+ sc->sc_format = __SHIFTOUT(dcr, VI_DCR_FMT);
+ sc->sc_interlaced = (dcr & VI_DCR_NIN) == 0;
+ } else {
+ visel = RD2(sc, VI_VISEL);
+ sc->sc_format = VI_DCR_FMT_NTSC;
+ sc->sc_interlaced = (visel & VI_VISEL_COMPONENT_CABLE) == 0;
+ }
/* Reset video interface. */
WR2(sc, VI_DCR, dcr | VI_DCR_RST);
WR2(sc, VI_DCR, dcr & ~VI_DCR_RST);
-#else
- /* Force NTSC 480i and reset video interface. */
- dcr = RD2(sc, VI_DCR);
- dcr |= VI_DCR_RST;
- WR2(sc, VI_DCR, dcr);
- dcr &= ~VI_DCR_RST;
- dcr &= ~VI_DCR_FMT;
- dcr |= __SHIFTIN(VI_DCR_FMT_NTSC, VI_DCR_FMT);
- dcr &= ~VI_DCR_NIN;
- WR2(sc, VI_DCR, dcr);
-
- sc->sc_format = VI_DCR_FMT_NTSC;
- sc->sc_interlaced = 1;
-#endif
}
static void
@@ -219,7 +212,7 @@ wiifb_set_mode(struct wiifb_softc *sc, u
sc->sc_curmode = &wiifb_modes[modeidx];
if (modeidx == WIIFB_MODE_INDEX(VI_DCR_FMT_NTSC, 1)) {
- /* Magic numbers from YAGCD. */
+ /* NTSC 480i Magic numbers from YAGCD. */
WR2(sc, VI_VTR, 0x0f06);
WR4(sc, VI_HTR0, 0x476901AD);
WR4(sc, VI_HTR1, 0x02EA5140);
@@ -227,6 +220,15 @@ wiifb_set_mode(struct wiifb_softc *sc, u
WR4(sc, VI_VTE, 0x00020019);
WR4(sc, VI_BBOI, 0x410C410C);
WR4(sc, VI_BBEI, 0x40ED40ED);
+ } else if (modeidx == WIIFB_MODE_INDEX(VI_DCR_FMT_NTSC, 0)) {
+ /* NTSC 480p */
+ WR2(sc, VI_VTR, 0x1e0c);
+ WR4(sc, VI_HTR0, 0x476901ad);
+ WR4(sc, VI_HTR1, 0x030a4940);
+ WR4(sc, VI_VTO, 0x00060030);
+ WR4(sc, VI_VTE, 0x00060030);
+ WR4(sc, VI_BBOI, 0x81d881d8);
+ WR4(sc, VI_BBEI, 0x81d881d8);
} else {
/*
* Display mode is not supported. Blink the slot LED to
@@ -242,7 +244,12 @@ wiifb_set_mode(struct wiifb_softc *sc, u
__SHIFTIN(strides, VI_PICCONF_STRIDES) |
__SHIFTIN(reads, VI_PICCONF_READS));
- WR2(sc, VI_HSR, __SHIFTIN(256, VI_HSR_STP));
+ /* Horizontal scaler configuration */
+ if (interlaced) {
+ WR2(sc, VI_HSR, __SHIFTIN(256, VI_HSR_STP));
+ } else {
+ WR2(sc, VI_HSR, __SHIFTIN(244, VI_HSR_STP) | VI_HSR_HS_EN);
+ }
/* Video clock configuration */
WR2(sc, VI_VICLK,
@@ -281,6 +288,7 @@ wiifb_ioctl(void *v, void *vs, u_long cm
struct wiifb_softc *sc = v;
struct wsdisplayio_bus_id *busid;
struct wsdisplayio_fbinfo *fbi;
+ struct vi_regs *vr;
switch (cmd) {
case WSDISPLAYIO_GTYPE:
@@ -306,6 +314,35 @@ wiifb_ioctl(void *v, void *vs, u_long cm
fbi->fbi_pixeltype = WSFB_YUY2;
fbi->fbi_flags = WSFB_VRAM_IS_RAM;
return 0;
+
+ case VIIO_GETREGS:
+ case VIIO_SETREGS:
+ vr = data;
+ switch (vr->bits) {
+ case 16:
+ if ((vr->reg & 1) != 0) {
+ return EINVAL;
+ }
+ if (cmd == VIIO_GETREGS) {
+ vr->val16 = RD2(sc, vr->reg);
+ } else {
+ WR2(sc, vr->reg, vr->val16);
+ }
+ return 0;
+ case 32:
+ if ((vr->reg & 3) != 0) {
+ return EINVAL;
+ }
+ if (cmd == VIIO_GETREGS) {
+ vr->val32 = RD4(sc, vr->reg);
+ } else {
+ WR4(sc, vr->reg, vr->val32);
+ }
+ return 0;
+ default:
+ return EINVAL;
+ }
+ return 0;
}
return EPASSTHROUGH;
Added files:
Index: src/sys/arch/evbppc/wii/dev/viio.h
diff -u /dev/null src/sys/arch/evbppc/wii/dev/viio.h:1.1
--- /dev/null Sun Jan 21 13:05:29 2024
+++ src/sys/arch/evbppc/wii/dev/viio.h Sun Jan 21 13:05:29 2024
@@ -0,0 +1,47 @@
+/* $NetBSD: viio.h,v 1.1 2024/01/21 13:05:29 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2024 Jared McNeill <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _WII_DEV_VIIO_H
+#define _WII_DEV_VIIO_H
+
+#include <sys/types.h>
+#include <sys/ioccom.h>
+
+struct vi_regs {
+ uint8_t reg;
+ uint8_t bits;
+ union {
+ uint16_t val16;
+ uint32_t val32;
+ };
+};
+
+#define VIIO_GETREGS _IOWR('w', 1, struct vi_regs)
+#define VIIO_SETREGS _IOWR('w', 2, struct vi_regs)
+
+#endif /* !_WII_DEV_VIIO_H */