Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/macppc drivers to support the onboard video circuit...



details:   https://anonhg.NetBSD.org/src/rev/adbaffd41af2
branches:  trunk
changeset: 773000:adbaffd41af2
user:      macallan <macallan%NetBSD.org@localhost>
date:      Tue Jan 24 04:33:11 2012 +0000

description:
drivers to support the onboard video circuitry found in for example the
Performa 6360

diffstat:

 sys/arch/macppc/conf/files.macppc   |   10 +-
 sys/arch/macppc/dev/valkyriefb.c    |  439 ++++++++++++++++++++++++++++++++++++
 sys/arch/macppc/dev/valkyriefbreg.h |   52 ++++
 sys/arch/macppc/dev/videopll.c      |  157 ++++++++++++
 sys/arch/macppc/dev/videopllvar.h   |   35 ++
 5 files changed, 692 insertions(+), 1 deletions(-)

diffs (truncated from 721 to 300 lines):

diff -r 25d8fa048995 -r adbaffd41af2 sys/arch/macppc/conf/files.macppc
--- a/sys/arch/macppc/conf/files.macppc Tue Jan 24 01:58:40 2012 +0000
+++ b/sys/arch/macppc/conf/files.macppc Tue Jan 24 04:33:11 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.macppc,v 1.98 2011/07/13 22:54:33 macallan Exp $
+#      $NetBSD: files.macppc,v 1.99 2012/01/24 04:33:11 macallan Exp $
 #
 # macppc-specific configuration info
 
@@ -295,4 +295,12 @@
 attach deq at ki2c
 file arch/macppc/dev/deq.c                             deq
 
+device videopll
+attach videopll at iic
+file arch/macppc/dev/videopll.c                                videopll needs-flag
+defflag opt_videopll.h VIDEOPLL_DEBUG
 
+device valkyriefb: wsemuldisplaydev, rasops8, vcons, videomode
+attach valkyriefb at mainbus
+file arch/macppc/dev/valkyriefb.c                      valkyriefb
+defflag opt_valkyriefb.h VALKYRIEFB_DEBUG
diff -r 25d8fa048995 -r adbaffd41af2 sys/arch/macppc/dev/valkyriefb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/dev/valkyriefb.c  Tue Jan 24 04:33:11 2012 +0000
@@ -0,0 +1,439 @@
+/*     $NetBSD: valkyriefb.c,v 1.1 2012/01/24 04:33:11 macallan Exp $  */
+
+/*
+ * Copyright (c) 2012 Michael Lorenz
+ * 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.
+ */
+
+/* 
+ * A console driver for Apple's Valkyrie onboard video controller, found in
+ * for example the Performa 6360
+ * This should be easy enough to adapt to mac68k but I don't have the hardware
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: valkyriefb.c,v 1.1 2012/01/24 04:33:11 macallan Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+
+#include <dev/ofw/openfirm.h>
+
+#include <machine/autoconf.h>
+
+#include <dev/wscons/wsdisplayvar.h>
+#include <dev/wscons/wsconsio.h>
+#include <dev/wsfont/wsfont.h>
+#include <dev/rasops/rasops.h>
+#include <dev/wscons/wsdisplay_vconsvar.h>
+
+#include <dev/videomode/videomode.h>
+
+#include <arch/macppc/dev/valkyriefbreg.h>
+#include <arch/macppc/dev/videopllvar.h>
+
+#include "opt_wsemul.h"
+#include "opt_valkyriefb.h"
+
+#include "videopll.h"
+#if NVIDEOPLL < 1
+#error "valkyriefb requires videopll at iic"
+#endif
+
+struct valkyriefb_softc {
+       device_t sc_dev;
+       int sc_node;
+       uint8_t *sc_base;
+
+       int sc_depth;
+       int sc_width, sc_height, sc_linebytes;
+       const struct videomode *sc_videomode;
+       uint8_t sc_modereg;
+
+       int sc_mode;
+       uint32_t sc_bg;
+               
+       u_char sc_cmap_red[256];
+       u_char sc_cmap_green[256];
+       u_char sc_cmap_blue[256];       
+
+       struct vcons_data vd;
+};
+
+struct valkyriefb_mode {
+       int width;
+       int height;
+       uint8_t mode;
+};
+
+/*
+ * Translate screen resolutions to values for Valkyrie's mode register.
+ * These numbers seem to roughly correspond to MacOS video mode numbers
+ * there are many numbers that result in the same resolution which in MacOS
+ * only differ by the display refresh rate, which isn't set by Valkyrie at
+ * all, instead there's a PLL chip hooked to cuda's i2c bus. It doesn't seem
+ * to matter which number we use as long as the resolution is right and we
+ * program the PLL for the right pixel clock
+ */
+static struct valkyriefb_mode modetab[] = {
+       {  640, 480, 6 },
+       {  800, 600, 12 },
+       {  832, 624, 9 },
+       { 1024, 768, 14},
+};
+       
+static struct vcons_screen valkyriefb_console_screen;
+
+static int     valkyriefb_match(device_t, cfdata_t, void *);
+static void    valkyriefb_attach(device_t, device_t, void *);
+static int     valkyriefb_init(device_t);
+static int     valkyriefb_set_mode(struct valkyriefb_softc *,
+                   const struct videomode *, int);
+
+CFATTACH_DECL_NEW(valkyriefb, sizeof(struct valkyriefb_softc),
+    valkyriefb_match, valkyriefb_attach, NULL, NULL);
+
+struct wsscreen_descr valkyriefb_defaultscreen = {
+       "default",
+       0, 0,
+       NULL,
+       8, 16,
+       WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
+       NULL,
+};
+
+const struct wsscreen_descr *_valkyriefb_scrlist[] = {
+       &valkyriefb_defaultscreen,
+       /* XXX other formats, graphics screen? */
+};
+
+struct wsscreen_list valkyriefb_screenlist = {
+       sizeof(_valkyriefb_scrlist) / sizeof(struct wsscreen_descr *), _valkyriefb_scrlist
+};
+
+static int     valkyriefb_ioctl(void *, void *, u_long, void *, int,
+                   struct lwp *);
+static paddr_t valkyriefb_mmap(void *, void *, off_t, int);
+
+static void    valkyriefb_init_screen(void *, struct vcons_screen *, int,
+                           long *);
+
+
+struct wsdisplay_accessops valkyriefb_accessops = {
+       valkyriefb_ioctl,
+       valkyriefb_mmap,
+       NULL,
+       NULL,
+       NULL,
+       NULL,   /* load_font */
+       NULL,   /* polls */
+       NULL,   /* scroll */
+};
+
+static inline void
+valkyriefb_write_reg(struct valkyriefb_softc *sc, int reg, uint8_t val)
+{
+       *(sc->sc_base + VAL_REGS_OFFSET + reg) = val;
+       __asm("eieio; sync;");
+}
+
+static inline uint8_t
+valkyriefb_read_reg(struct valkyriefb_softc *sc, int reg)
+{
+       return *(sc->sc_base + VAL_REGS_OFFSET + reg);
+}
+
+static void
+valkyriefb_write_cmap(struct valkyriefb_softc *sc,
+    int reg, uint8_t r, uint8_t g, uint8_t b)
+{
+       *(sc->sc_base + VAL_CMAP_OFFSET + VAL_CMAP_ADDR) = reg;
+       __asm("eieio; sync;");
+       *(sc->sc_base + VAL_CMAP_OFFSET + VAL_CMAP_LUT) = r;
+       __asm("eieio; sync;");
+       *(sc->sc_base + VAL_CMAP_OFFSET + VAL_CMAP_LUT) = g;
+       __asm("eieio; sync;");
+       *(sc->sc_base + VAL_CMAP_OFFSET + VAL_CMAP_LUT) = b;
+       __asm("eieio; sync;");
+}
+
+static int
+valkyriefb_match(device_t parent, cfdata_t cf, void *aux)
+{
+       struct confargs *ca = aux;
+
+       if (strcmp(ca->ca_name, "valkyrie") != 0)
+               return 0;
+       return 1;
+}
+
+static void
+valkyriefb_attach(device_t parent, device_t self, void *aux)
+{
+       struct valkyriefb_softc *sc = device_private(self);
+       struct confargs *ca = aux;
+       int i;
+       volatile uint32_t *fb;
+
+       sc->sc_dev = self;
+       sc->sc_node = ca->ca_node;
+
+       aprint_normal(" address 0x%08x\n", ca->ca_reg[0]);
+       aprint_verbose_dev(sc->sc_dev, "waiting for videopll...\n");
+       sc->sc_base = (uint8_t *)ca->ca_reg[0];
+#ifdef VALKYRIEFB_DEBUG
+       for (i = 0; i < 0x40; i += 8) {
+               aprint_error_dev(sc->sc_dev, "%02x: %02x\n", i, valkyriefb_read_reg(sc, i));
+       }
+#endif
+       config_finalize_register(sc->sc_dev, valkyriefb_init);
+       fb = (volatile uint32_t *)(sc->sc_base + 0x1000);
+       for (i = 0; i < 256; i++)
+               fb[i] = 0xffffffff;
+       for (i = 256; i < 0x10000; i++)
+               fb[i] = 0x80808080;
+}
+
+static int
+valkyriefb_init(device_t self)
+{
+       struct valkyriefb_softc *sc = device_private(self);
+       const struct videomode *mode;
+       struct rasops_info *ri;
+       prop_dictionary_t dict;
+       struct wsemuldisplaydev_attach_args aa;
+       bool console = FALSE;
+       long defattr;
+
+       mode = pick_mode_by_ref(800, 600, 60);
+       if (mode == NULL)
+               return 0;
+
+       valkyriefb_set_mode(sc, mode, 8);
+
+       vcons_init(&sc->vd, sc, &valkyriefb_defaultscreen, &valkyriefb_accessops);
+       sc->vd.init_screen = valkyriefb_init_screen;
+
+       dict = device_properties(sc->sc_dev);
+       prop_dictionary_get_bool(dict, "is_console", &console);
+
+       ri = &valkyriefb_console_screen.scr_ri;
+       vcons_init_screen(&sc->vd, &valkyriefb_console_screen, 1, &defattr);
+       valkyriefb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
+
+       valkyriefb_defaultscreen.textops = &ri->ri_ops;
+       valkyriefb_defaultscreen.capabilities = ri->ri_caps;
+       valkyriefb_defaultscreen.nrows = ri->ri_rows;
+       valkyriefb_defaultscreen.ncols = ri->ri_cols;
+       if (console) {
+               wsdisplay_cnattach(&valkyriefb_defaultscreen, ri, 0, 0, defattr);
+       }
+
+       memset(sc->sc_base + 0x1000, ri->ri_devcmap[(defattr >> 16) & 0xf],
+           sc->sc_width * sc->sc_linebytes);
+
+       if (console)
+               vcons_replay_msgbuf(&valkyriefb_console_screen);
+
+       aa.console = console;
+       aa.scrdata = &valkyriefb_screenlist;
+       aa.accessops = &valkyriefb_accessops;
+       aa.accesscookie = &sc->vd;
+
+       config_found(self, &aa, wsemuldisplaydevprint);
+
+       return 0;
+}
+
+static int
+valkyriefb_set_mode(struct valkyriefb_softc *sc,
+    const struct videomode *mode, int depth)
+{
+       int i;



Home | Main Index | Thread Index | Old Index