Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Basic framebuffer console support. Work in progress.



details:   https://anonhg.NetBSD.org/src/rev/0dc6263eeb57
branches:  trunk
changeset: 806951:0dc6263eeb57
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Mar 21 01:17:00 2015 +0000

description:
Basic framebuffer console support. Work in progress.

diffstat:

 sys/arch/arm/amlogic/amlogic_canvasreg.h  |   54 ++++
 sys/arch/arm/amlogic/amlogic_genfb.c      |  389 ++++++++++++++++++++++++++++++
 sys/arch/arm/amlogic/amlogic_hdmireg.h    |   38 ++
 sys/arch/arm/amlogic/amlogic_io.c         |    6 +-
 sys/arch/arm/amlogic/amlogic_reg.h        |    8 +-
 sys/arch/arm/amlogic/amlogic_var.h        |    5 +-
 sys/arch/arm/amlogic/amlogic_vpureg.h     |   73 +++++
 sys/arch/arm/amlogic/files.amlogic        |    6 +-
 sys/arch/evbarm/amlogic/amlogic_machdep.c |   31 +-
 sys/arch/evbarm/conf/ODROID-C1            |   30 +-
 10 files changed, 613 insertions(+), 27 deletions(-)

diffs (truncated from 771 to 300 lines):

diff -r 0a3f5e15d85e -r 0dc6263eeb57 sys/arch/arm/amlogic/amlogic_canvasreg.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_canvasreg.h  Sat Mar 21 01:17:00 2015 +0000
@@ -0,0 +1,54 @@
+/* $NetBSD: amlogic_canvasreg.h,v 1.1 2015/03/21 01:17:00 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * 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 _ARM_AMLOGIC_CANVASREG_H
+#define _ARM_AMLOGIC_CANVASREG_H
+
+#define CANVAS_REG(n)  ((n) << 2)
+
+#define DC_CAV_LUT_DATAL_REG   CANVAS_REG(0x12)
+#define DC_CAV_LUT_DATAH_REG   CANVAS_REG(0x13)
+#define DC_CAV_LUT_ADDR_REG    CANVAS_REG(0x14)
+
+#define DC_CAV_LUT_DATAL_FBADDR                __BITS(28,0)
+#define DC_CAV_LUT_DATAL_WIDTH_L       __BITS(31,29)
+
+#define DC_CAV_LUT_DATAH_BLKMODE       __BITS(25,24)
+#define DC_CAV_LUT_DATAH_BLKMODE_LINEAR        0
+#define DC_CAV_LUT_DATAH_BLKMODE_32X32 1
+#define DC_CAV_LUT_DATAH_BLKMODE_64X64 2
+#define DC_CAV_LUT_DATAH_YWRAP         __BIT(23)
+#define DC_CAV_LUT_DATAH_XWRAP         __BIT(22)
+#define DC_CAV_LUT_DATAH_HEIGHT                __BITS(21,9)
+#define DC_CAV_LUT_DATAH_WIDTH_H       __BITS(8,0)
+
+#define DC_CAV_LUT_ADDR_WR_EN          __BIT(9)
+#define DC_CAV_LUT_ADDR_RD_EN          __BIT(8)
+#define DC_CAV_LUT_ADDR_INDEX          __BITS(2,0)
+
+#endif /* _ARM_AMLOGIC_CANVASREG_H */
diff -r 0a3f5e15d85e -r 0dc6263eeb57 sys/arch/arm/amlogic/amlogic_genfb.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/amlogic_genfb.c      Sat Mar 21 01:17:00 2015 +0000
@@ -0,0 +1,389 @@
+/* $NetBSD: amlogic_genfb.c,v 1.1 2015/03/21 01:17:00 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+/*
+ * Generic framebuffer console driver
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: amlogic_genfb.c,v 1.1 2015/03/21 01:17:00 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/conf.h>
+#include <sys/bus.h>
+#include <sys/kmem.h>
+
+#include <arm/amlogic/amlogic_reg.h>
+#include <arm/amlogic/amlogic_var.h>
+#include <arm/amlogic/amlogic_canvasreg.h>
+#include <arm/amlogic/amlogic_vpureg.h>
+#include <arm/amlogic/amlogic_hdmireg.h>
+
+#include <dev/wsfb/genfbvar.h>
+
+/* Map CEA-861-D video code (VIC) to framebuffer dimensions */
+static const struct amlogic_genfb_vic2mode {
+       u_int vic;
+       u_int width;
+       u_int height;
+} amlogic_genfb_modes[] = {
+       { 1, 640, 480 },
+       { 2, 720, 480 },
+       { 3, 720, 480 },
+       { 4, 1280, 720 },
+       { 5, 1920, 1080 },
+       { 16, 1920, 1080 },
+       { 17, 720, 576 },
+       { 18, 720, 576 },
+       { 19, 1280, 720 },
+       { 20, 1920, 1080 },
+       { 31, 1920, 1080 },
+       { 32, 1920, 1080 },
+       { 33, 1920, 1080 },
+       { 34, 1920, 1080 },
+       { 39, 1920, 1080 },
+};
+
+struct amlogic_genfb_softc {
+       struct genfb_softc      sc_gen;
+       bus_space_tag_t         sc_bst;
+       bus_space_handle_t      sc_bsh;
+       bus_space_handle_t      sc_hdmi_bsh;
+       bus_space_handle_t      sc_vpu_bsh;
+       bus_dma_tag_t           sc_dmat;
+
+       bus_dma_segment_t       sc_dmasegs[1];
+       bus_size_t              sc_dmasize;
+       bus_dmamap_t            sc_dmamap;
+       void                    *sc_dmap;
+
+       uint32_t                sc_wstype;
+};
+
+static int     amlogic_genfb_match(device_t, cfdata_t, void *);
+static void    amlogic_genfb_attach(device_t, device_t, void *);
+
+static int     amlogic_genfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
+static paddr_t amlogic_genfb_mmap(void *, void *, off_t, int);
+static bool    amlogic_genfb_shutdown(device_t, int);
+
+static void    amlogic_genfb_probe(struct amlogic_genfb_softc *);
+static int     amlogic_genfb_alloc_videomem(struct amlogic_genfb_softc *);
+
+void           amlogic_genfb_set_console_dev(device_t);
+void           amlogic_genfb_ddb_trap_callback(int);
+
+static device_t amlogic_genfb_console_dev = NULL;
+
+CFATTACH_DECL_NEW(amlogic_genfb, sizeof(struct amlogic_genfb_softc),
+    amlogic_genfb_match, amlogic_genfb_attach, NULL, NULL);
+
+static inline uint32_t
+amlogic_genfb_hdmi_read_4(struct amlogic_genfb_softc *sc, uint32_t addr)
+{
+       bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
+       bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
+       return bus_space_read_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_DATA_REG);
+}
+
+static inline void
+amlogic_genfb_hdmi_write_4(struct amlogic_genfb_softc *sc, uint32_t addr,
+    uint32_t data)
+{
+       bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
+       bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_ADDR_REG, addr);
+       bus_space_write_4(sc->sc_bst, sc->sc_hdmi_bsh, HDMI_DATA_REG, data);
+}
+
+#define HDMI_READ      amlogic_genfb_hdmi_read_4
+#define HDMI_WRITE     amlogic_genfb_hdmi_write_4
+
+#define VPU_READ(sc, reg) \
+    bus_space_read_4((sc)->sc_bst, (sc)->sc_vpu_bsh, (reg))
+#define VPU_WRITE(sc, reg, val) \
+    bus_space_write_4((sc)->sc_bst, (sc)->sc_vpu_bsh, (reg), (val))
+
+static int
+amlogic_genfb_match(device_t parent, cfdata_t match, void *aux)
+{
+       return 1;
+}
+
+static void
+amlogic_genfb_attach(device_t parent, device_t self, void *aux)
+{
+       struct amlogic_genfb_softc *sc = device_private(self);
+       struct amlogicio_attach_args * const aio = aux;
+       const struct amlogic_locators * const loc = &aio->aio_loc;
+       prop_dictionary_t dict = device_properties(self);
+       static const struct genfb_ops zero_ops;
+       struct genfb_ops ops = zero_ops;
+       bool is_console = false;
+
+       sc->sc_gen.sc_dev = self;
+       sc->sc_bst = aio->aio_core_bst;
+       sc->sc_dmat = aio->aio_dmat;
+       bus_space_subregion(aio->aio_core_bst, aio->aio_bsh,
+           loc->loc_offset, loc->loc_size, &sc->sc_bsh);
+       bus_space_subregion(aio->aio_core_bst, aio->aio_bsh,
+           AMLOGIC_HDMI_OFFSET, AMLOGIC_HDMI_SIZE, &sc->sc_hdmi_bsh);
+       bus_space_subregion(aio->aio_core_bst, aio->aio_bsh,
+           AMLOGIC_VPU_OFFSET, AMLOGIC_VPU_SIZE, &sc->sc_vpu_bsh);
+
+       amlogic_genfb_probe(sc);
+
+       sc->sc_wstype = WSDISPLAY_TYPE_MESON;
+       prop_dictionary_get_bool(dict, "is_console", &is_console);
+
+       genfb_init(&sc->sc_gen);
+
+       if (sc->sc_gen.sc_width == 0 ||
+           sc->sc_gen.sc_fbsize == 0) {
+               aprint_normal(": disabled\n");
+               return;
+       }
+
+       pmf_device_register1(self, NULL, NULL, amlogic_genfb_shutdown);
+
+       memset(&ops, 0, sizeof(ops));
+       ops.genfb_ioctl = amlogic_genfb_ioctl;
+       ops.genfb_mmap = amlogic_genfb_mmap;
+
+       aprint_naive("\n");
+
+       if (is_console)
+               aprint_normal(": switching to framebuffer console\n");
+       else
+               aprint_normal("\n");
+
+       genfb_attach(&sc->sc_gen, &ops);
+}
+
+static int
+amlogic_genfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, lwp_t *l)
+{
+       struct amlogic_genfb_softc *sc = v;
+       struct wsdisplayio_bus_id *busid;
+
+       switch (cmd) {
+       case WSDISPLAYIO_GTYPE:
+               *(u_int *)data = sc->sc_wstype;
+               return 0;
+       case WSDISPLAYIO_GET_BUSID:
+               busid = data;
+               busid->bus_type = WSDISPLAYIO_BUS_SOC;
+               return 0;
+       case WSDISPLAYIO_GET_FBINFO:
+               {
+                       struct wsdisplayio_fbinfo *fbi = data;
+                       struct rasops_info *ri = &sc->sc_gen.vd.active->scr_ri;
+                       int ret;
+
+                       ret = wsdisplayio_get_fbinfo(ri, fbi);
+                       fbi->fbi_flags |= WSFB_VRAM_IS_RAM;
+                       return ret;
+               }
+       default:
+               return EPASSTHROUGH;
+       }
+}
+
+static paddr_t
+amlogic_genfb_mmap(void *v, void *vs, off_t offset, int prot)
+{
+       struct amlogic_genfb_softc *sc = v;
+
+       if (offset < 0 || offset >= sc->sc_dmasegs[0].ds_len)
+               return -1;
+
+       return bus_dmamem_mmap(sc->sc_dmat, sc->sc_dmasegs, 1,
+           offset, prot, BUS_DMA_PREFETCHABLE);
+}
+
+static bool
+amlogic_genfb_shutdown(device_t self, int flags)
+{
+       genfb_enable_polling(self);
+       return true;
+}
+
+static void



Home | Main Index | Thread Index | Old Index