Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/amlogic Add Meson (FDT) framebuffer support.
details: https://anonhg.NetBSD.org/src/rev/0d0b2779ff42
branches: trunk
changeset: 447641:0d0b2779ff42
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sat Jan 19 21:43:43 2019 +0000
description:
Add Meson (FDT) framebuffer support.
diffstat:
sys/arch/arm/amlogic/files.meson | 6 +-
sys/arch/arm/amlogic/meson_canvasreg.h | 54 ++
sys/arch/arm/amlogic/meson_genfb.c | 728 +++++++++++++++++++++++++++++++++
sys/arch/arm/amlogic/meson_hdmireg.h | 38 +
sys/arch/arm/amlogic/meson_vpureg.h | 151 ++++++
5 files changed, 976 insertions(+), 1 deletions(-)
diffs (truncated from 1007 to 300 lines):
diff -r 3c5bdeb3a0f9 -r 0d0b2779ff42 sys/arch/arm/amlogic/files.meson
--- a/sys/arch/arm/amlogic/files.meson Sat Jan 19 21:43:07 2019 +0000
+++ b/sys/arch/arm/amlogic/files.meson Sat Jan 19 21:43:43 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.meson,v 1.1 2019/01/19 20:56:03 jmcneill Exp $
+# $NetBSD: files.meson,v 1.2 2019/01/19 21:43:43 jmcneill Exp $
#
# Configuration info for Amlogic Meson family SoCs
#
@@ -32,6 +32,10 @@
attach mesonuart at fdt with meson_uart
file arch/arm/amlogic/meson_uart.c meson_uart
+# Framebuffer console
+attach genfb at fdt with meson_genfb
+file arch/arm/amlogic/meson_genfb.c meson_genfb & soc_meson
+
# GPIO
device mesonpinctrl: gpiobus
attach mesonpinctrl at fdt with meson_pinctrl
diff -r 3c5bdeb3a0f9 -r 0d0b2779ff42 sys/arch/arm/amlogic/meson_canvasreg.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/meson_canvasreg.h Sat Jan 19 21:43:43 2019 +0000
@@ -0,0 +1,54 @@
+/* $NetBSD: meson_canvasreg.h,v 1.1 2019/01/19 21:43:43 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015 Jared 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 _MESON_CANVASREG_H
+#define _MESON_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 /* _MESON_CANVASREG_H */
diff -r 3c5bdeb3a0f9 -r 0d0b2779ff42 sys/arch/arm/amlogic/meson_genfb.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/amlogic/meson_genfb.c Sat Jan 19 21:43:43 2019 +0000
@@ -0,0 +1,728 @@
+/* $NetBSD: meson_genfb.c,v 1.1 2019/01/19 21:43:43 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2015-2019 Jared 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 "opt_wsdisplay_compat.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: meson_genfb.c,v 1.1 2019/01/19 21:43:43 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 <sys/sysctl.h>
+
+#include <dev/fdt/fdtvar.h>
+
+#include <arm/amlogic/meson_canvasreg.h>
+#include <arm/amlogic/meson_vpureg.h>
+#include <arm/amlogic/meson_hdmireg.h>
+
+#include <dev/wsfb/genfbvar.h>
+
+static const char * const compatible[] = {
+ "amlogic,meson8b-fb",
+ NULL
+};
+
+#define AMLOGIC_GENFB_DEFAULT_DEPTH 16
+
+/* Map CEA-861-D video code (VIC) to framebuffer dimensions */
+static const struct meson_genfb_vic2mode {
+ u_int vic;
+ u_int width;
+ u_int height;
+ u_int flags;
+#define INTERLACE __BIT(0)
+#define DBLSCAN __BIT(1)
+} meson_genfb_modes[] = {
+ { 1, 640, 480 },
+ { 2, 720, 480 },
+ { 3, 720, 480 },
+ { 4, 1280, 720 },
+ { 5, 1920, 1080, INTERLACE },
+ { 6, 720, 480, DBLSCAN | INTERLACE },
+ { 7, 720, 480, DBLSCAN | INTERLACE },
+ { 8, 720, 240, DBLSCAN },
+ { 9, 720, 240, DBLSCAN },
+ { 16, 1920, 1080 },
+ { 17, 720, 576 },
+ { 18, 720, 576 },
+ { 19, 1280, 720 },
+ { 20, 1920, 1080, INTERLACE },
+ { 31, 1920, 1080 },
+ { 32, 1920, 1080 },
+ { 33, 1920, 1080 },
+ { 34, 1920, 1080 },
+ { 39, 1920, 1080, INTERLACE },
+};
+
+struct meson_genfb_softc {
+ struct genfb_softc sc_gen;
+ bus_space_tag_t sc_bst;
+ bus_space_handle_t sc_cav_bsh;
+ bus_space_handle_t sc_hdmi_bsh;
+ bus_space_handle_t sc_vpu_bsh;
+ bus_dma_tag_t sc_dmat;
+
+ kmutex_t sc_lock;
+
+ u_int sc_scale;
+
+ bus_dma_segment_t sc_dmasegs[1];
+ bus_size_t sc_dmasize;
+ bus_dmamap_t sc_dmamap;
+ void *sc_dmap;
+
+ uint32_t sc_wstype;
+
+ struct sysctllog *sc_sysctllog;
+ int sc_node_scale;
+};
+
+static int meson_genfb_match(device_t, cfdata_t, void *);
+static void meson_genfb_attach(device_t, device_t, void *);
+
+static int meson_genfb_ioctl(void *, void *, u_long, void *, int, lwp_t *);
+static paddr_t meson_genfb_mmap(void *, void *, off_t, int);
+static bool meson_genfb_shutdown(device_t, int);
+
+static void meson_genfb_canvas_config(struct meson_genfb_softc *);
+static void meson_genfb_osd_config(struct meson_genfb_softc *);
+static void meson_genfb_scaler_config(struct meson_genfb_softc *);
+
+static void meson_genfb_init(struct meson_genfb_softc *);
+static int meson_genfb_alloc_videomem(struct meson_genfb_softc *);
+
+static int meson_genfb_scale_helper(SYSCTLFN_PROTO);
+
+void meson_genfb_set_console_dev(device_t);
+void meson_genfb_ddb_trap_callback(int);
+
+static int meson_genfb_console_phandle = -1;
+static device_t meson_genfb_console_dev = NULL;
+
+CFATTACH_DECL_NEW(meson_genfb, sizeof(struct meson_genfb_softc),
+ meson_genfb_match, meson_genfb_attach, NULL, NULL);
+
+static inline uint32_t
+meson_genfb_hdmi_read_4(struct meson_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 __unused inline void
+meson_genfb_hdmi_write_4(struct meson_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 meson_genfb_hdmi_read_4
+#define HDMI_WRITE meson_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))
+
+#define CAV_READ(sc, reg) \
+ bus_space_read_4((sc)->sc_bst, (sc)->sc_cav_bsh, (reg))
+#define CAV_WRITE(sc, reg, val) \
+ bus_space_write_4((sc)->sc_bst, (sc)->sc_cav_bsh, (reg), (val))
+
+static int
+meson_genfb_match(device_t parent, cfdata_t match, void *aux)
+{
+ struct fdt_attach_args * const faa = aux;
+
+ return of_match_compatible(faa->faa_phandle, compatible);
+}
+
+static void
+meson_genfb_attach(device_t parent, device_t self, void *aux)
+{
+ struct meson_genfb_softc *sc = device_private(self);
+ struct fdt_attach_args * const faa = aux;
+ const int phandle = faa->faa_phandle;
+ prop_dictionary_t dict = device_properties(self);
+ static const struct genfb_ops zero_ops;
+ struct genfb_ops ops = zero_ops;
+ bus_addr_t addr[3];
+ bus_size_t size[3];
+
+ for (int i = 0; i < 3; i++) {
+ if (fdtbus_get_reg(phandle, i, &addr[i], &size[i]) != 0) {
+ aprint_error(": couldn't get register #%d\n", i);
+ return;
+ }
+ }
+
+ sc->sc_gen.sc_dev = self;
+ sc->sc_bst = faa->faa_bst;
+ sc->sc_dmat = faa->faa_dmat;
+ if (bus_space_map(sc->sc_bst, addr[0], size[0], 0, &sc->sc_cav_bsh) != 0 ||
+ bus_space_map(sc->sc_bst, addr[1], size[1], 0, &sc->sc_hdmi_bsh) != 0 ||
+ bus_space_map(sc->sc_bst, addr[2], size[2], 0, &sc->sc_vpu_bsh) != 0) {
+ aprint_error(": couldn't map registers\n");
+ return;
+ }
+ mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
+
+ meson_genfb_init(sc);
+
+ sc->sc_wstype = WSDISPLAY_TYPE_MESON;
+
+ aprint_naive("\n");
+ aprint_normal("\n");
+
+ genfb_init(&sc->sc_gen);
+
+ if (sc->sc_gen.sc_width == 0 ||
+ sc->sc_gen.sc_fbsize == 0) {
Home |
Main Index |
Thread Index |
Old Index