Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/arm/ti Add support for AM335x display controller (L...
details: https://anonhg.NetBSD.org/src/rev/153c4989d348
branches: trunk
changeset: 460786:153c4989d348
user: jmcneill <jmcneill%NetBSD.org@localhost>
date: Sun Nov 03 22:59:06 2019 +0000
description:
Add support for AM335x display controller (LCDC).
diffstat:
sys/arch/arm/ti/am3_prcm.c | 59 +++-
sys/arch/arm/ti/files.ti | 11 +-
sys/arch/arm/ti/ti_fb.c | 161 ++++++++++
sys/arch/arm/ti/ti_lcdc.c | 656 +++++++++++++++++++++++++++++++++++++++++++
sys/arch/arm/ti/ti_lcdc.h | 110 +++++++
sys/arch/arm/ti/ti_lcdcreg.h | 136 ++++++++
6 files changed, 1130 insertions(+), 3 deletions(-)
diffs (truncated from 1207 to 300 lines):
diff -r d5fe53b25dd0 -r 153c4989d348 sys/arch/arm/ti/am3_prcm.c
--- a/sys/arch/arm/ti/am3_prcm.c Sun Nov 03 22:57:52 2019 +0000
+++ b/sys/arch/arm/ti/am3_prcm.c Sun Nov 03 22:59:06 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: am3_prcm.c,v 1.8 2019/10/30 21:40:04 jmcneill Exp $ */
+/* $NetBSD: am3_prcm.c,v 1.9 2019/11/03 22:59:06 jmcneill Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: am3_prcm.c,v 1.8 2019/10/30 21:40:04 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: am3_prcm.c,v 1.9 2019/11/03 22:59:06 jmcneill Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -52,6 +52,18 @@
#define AM3_PRCM_CLKCTRL_MODULEMODE __BITS(1,0)
#define AM3_PRCM_CLKCTRL_MODULEMODE_ENABLE 0x2
+/* WKUP */
+#define AM3_PRCM_CM_IDLEST_DPLL_DISP (AM3_PRCM_CM_WKUP + 0x48)
+#define AM3_PRCM_CM_IDLEST_DPLL_DISP_ST_MN_BYPASS __BIT(8)
+#define AM3_PRCM_CM_IDLEST_DPLL_DISP_ST_DPLL_CLK __BIT(0)
+#define AM3_PRCM_CM_CLKSEL_DPLL_DISP (AM3_PRCM_CM_WKUP + 0x54)
+#define AM3_PRCM_CM_CLKSEL_DPLL_DISP_DPLL_MULT __BITS(18,8)
+#define AM3_PRCM_CM_CLKSEL_DPLL_DISP_DPLL_DIV __BITS(6,0)
+#define AM3_PRCM_CM_CLKMODE_DPLL_DISP (AM3_PRCM_CM_WKUP + 0x98)
+#define AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN __BITS(2,0)
+#define AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN_MN_BYPASS 4
+#define AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN_LOCK 7
+
static int am3_prcm_match(device_t, cfdata_t, void *);
static void am3_prcm_attach(device_t, device_t, void *);
@@ -70,8 +82,48 @@
return 0;
}
+static int
+am3_prcm_hwmod_enable_display(struct ti_prcm_softc *sc, struct ti_prcm_clk *tc, int enable)
+{
+ uint32_t val;
+ int retry;
+
+ if (enable) {
+ /* Put the DPLL in MN bypass mode */
+ PRCM_WRITE(sc, AM3_PRCM_CM_CLKMODE_DPLL_DISP,
+ __SHIFTIN(AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN_MN_BYPASS,
+ AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN));
+ for (retry = 10000; retry > 0; retry--) {
+ val = PRCM_READ(sc, AM3_PRCM_CM_IDLEST_DPLL_DISP);
+ if ((val & AM3_PRCM_CM_IDLEST_DPLL_DISP_ST_MN_BYPASS) != 0)
+ break;
+ delay(10);
+ }
+
+ /* Set DPLL frequency to 270 MHz */
+ val = __SHIFTIN(270, AM3_PRCM_CM_CLKSEL_DPLL_DISP_DPLL_MULT);
+ val |= __SHIFTIN(24 - 1, AM3_PRCM_CM_CLKSEL_DPLL_DISP_DPLL_DIV);
+ PRCM_WRITE(sc, AM3_PRCM_CM_CLKSEL_DPLL_DISP, val);
+
+ /* Disable MN bypass mode */
+ PRCM_WRITE(sc, AM3_PRCM_CM_CLKMODE_DPLL_DISP,
+ __SHIFTIN(AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN_LOCK,
+ AM3_PRCM_CM_CLKMODE_DPLL_DISP_DPLL_EN));
+ for (retry = 10000; retry > 0; retry--) {
+ val = PRCM_READ(sc, AM3_PRCM_CM_IDLEST_DPLL_DISP);
+ if ((val & AM3_PRCM_CM_IDLEST_DPLL_DISP_ST_DPLL_CLK) != 0)
+ break;
+ delay(10);
+ }
+ }
+
+ return am3_prcm_hwmod_enable(sc, tc, enable);
+}
+
#define AM3_PRCM_HWMOD_PER(_name, _reg, _parent) \
TI_PRCM_HWMOD((_name), AM3_PRCM_CM_PER + (_reg), (_parent), am3_prcm_hwmod_enable)
+#define AM3_PRCM_HWMOD_PER_DISP(_name, _reg, _parent) \
+ TI_PRCM_HWMOD((_name), AM3_PRCM_CM_PER + (_reg), (_parent), am3_prcm_hwmod_enable_display)
#define AM3_PRCM_HWMOD_WKUP(_name, _reg, _parent) \
TI_PRCM_HWMOD((_name), AM3_PRCM_CM_WKUP + (_reg), (_parent), am3_prcm_hwmod_enable)
@@ -89,6 +141,7 @@
TI_PRCM_FIXED("FIXED_24MHZ", 24000000),
TI_PRCM_FIXED("FIXED_48MHZ", 48000000),
TI_PRCM_FIXED("FIXED_96MHZ", 96000000),
+ TI_PRCM_FIXED("DISPLAY_CLK", 270000000),
TI_PRCM_FIXED_FACTOR("PERIPH_CLK", 1, 1, "FIXED_48MHZ"),
TI_PRCM_FIXED_FACTOR("MMC_CLK", 1, 1, "FIXED_96MHZ"),
@@ -127,6 +180,8 @@
AM3_PRCM_HWMOD_PER("usb_otg_hs", 0x1c, "PERIPH_CLK"),
AM3_PRCM_HWMOD_PER("rng", 0x90, "PERIPH_CLK"),
+
+ AM3_PRCM_HWMOD_PER_DISP("lcdc", 0x18, "DISPLAY_CLK"),
};
static int
diff -r d5fe53b25dd0 -r 153c4989d348 sys/arch/arm/ti/files.ti
--- a/sys/arch/arm/ti/files.ti Sun Nov 03 22:57:52 2019 +0000
+++ b/sys/arch/arm/ti/files.ti Sun Nov 03 22:59:06 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.ti,v 1.19 2019/11/01 11:53:35 jmcneill Exp $
+# $NetBSD: files.ti,v 1.20 2019/11/03 22:59:06 jmcneill Exp $
#
file arch/arm/ti/ti_cpufreq.c soc_ti
@@ -112,6 +112,15 @@
attach omapfb at fdt with omap3_dss
file arch/arm/ti/omap3_dss.c omap3_dss
+define tilcdcfbbus { }
+device tilcdc: drmkms, tilcdcfbbus
+attach tilcdc at fdt with ti_lcdc
+file arch/arm/ti/ti_lcdc.c ti_lcdc
+
+device tifb: tilcdcfbbus, drmfb, wsemuldisplaydev
+attach tifb at tilcdcfbbus with ti_fb
+file arch/arm/ti/ti_fb.c ti_fb
+
# Memory controller
device tigpmc { } : fdt
attach tigpmc at fdt with ti_gpmc
diff -r d5fe53b25dd0 -r 153c4989d348 sys/arch/arm/ti/ti_fb.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/ti/ti_fb.c Sun Nov 03 22:59:06 2019 +0000
@@ -0,0 +1,161 @@
+/* $NetBSD: ti_fb.c,v 1.1 2019/11/03 22:59:06 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 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.
+ */
+
+#include "opt_wsdisplay_compat.h"
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: ti_fb.c,v 1.1 2019/11/03 22:59:06 jmcneill Exp $");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/device.h>
+
+#include <dev/fdt/fdtvar.h>
+#include <dev/fdt/fdt_port.h>
+
+#include <drm/drmP.h>
+#include <drm/drmfb.h>
+
+#include <arm/ti/ti_lcdc.h>
+
+static int ti_fb_match(device_t, cfdata_t, void *);
+static void ti_fb_attach(device_t, device_t, void *);
+
+static bool ti_fb_shutdown(device_t, int);
+
+struct ti_fb_softc {
+ struct drmfb_softc sc_drmfb;
+ device_t sc_dev;
+ struct tilcdc_framebuffer *sc_fb;
+ struct tilcdcfb_attach_args sc_tfa;
+};
+
+static paddr_t ti_fb_mmapfb(struct drmfb_softc *, off_t, int);
+static int ti_fb_ioctl(struct drmfb_softc *, u_long, void *, int,
+ lwp_t *);
+
+static const struct drmfb_params tifb_drmfb_params = {
+ .dp_mmapfb = ti_fb_mmapfb,
+ .dp_ioctl = ti_fb_ioctl,
+
+};
+
+CFATTACH_DECL_NEW(ti_fb, sizeof(struct ti_fb_softc),
+ ti_fb_match, ti_fb_attach, NULL, NULL);
+
+static int
+ti_fb_match(device_t parent, cfdata_t cf, void *aux)
+{
+ return 1;
+}
+
+static void
+ti_fb_attach(device_t parent, device_t self, void *aux)
+{
+ struct ti_fb_softc * const sc = device_private(self);
+ struct tilcdcfb_attach_args * const tfa = aux;
+ int error;
+
+ sc->sc_dev = self;
+ sc->sc_tfa = *tfa;
+ sc->sc_fb = to_tilcdc_framebuffer(tfa->tfa_fb_helper->fb);
+
+ aprint_naive("\n");
+ aprint_normal("\n");
+
+#ifdef WSDISPLAY_MULTICONS
+ prop_dictionary_t dict = device_properties(self);
+ const bool is_console = true;
+ prop_dictionary_set_bool(dict, "is_console", is_console);
+#endif
+
+ const struct drmfb_attach_args da = {
+ .da_dev = self,
+ .da_fb_helper = tfa->tfa_fb_helper,
+ .da_fb_sizes = &tfa->tfa_fb_sizes,
+ .da_fb_vaddr = sc->sc_fb->obj->vaddr,
+ .da_fb_linebytes = tfa->tfa_fb_linebytes,
+ .da_params = &tifb_drmfb_params,
+ };
+
+ error = drmfb_attach(&sc->sc_drmfb, &da);
+ if (error) {
+ aprint_error_dev(self, "failed to attach drmfb: %d\n", error);
+ return;
+ }
+
+ pmf_device_register1(self, NULL, NULL, ti_fb_shutdown);
+}
+
+static bool
+ti_fb_shutdown(device_t self, int flags)
+{
+ struct ti_fb_softc * const sc = device_private(self);
+
+ return drmfb_shutdown(&sc->sc_drmfb, flags);
+}
+
+static paddr_t
+ti_fb_mmapfb(struct drmfb_softc *sc, off_t off, int prot)
+{
+ struct ti_fb_softc * const tfb_sc = (struct ti_fb_softc *)sc;
+ struct drm_gem_cma_object *obj = tfb_sc->sc_fb->obj;
+
+ KASSERT(off >= 0);
+ KASSERT(off < obj->dmasize);
+
+ return bus_dmamem_mmap(obj->dmat, obj->dmasegs, 1, off, prot,
+ BUS_DMA_PREFETCHABLE);
+}
+
+static int
+ti_fb_ioctl(struct drmfb_softc *sc, u_long cmd, void *data, int flag,
+ lwp_t *l)
+{
+ struct wsdisplayio_bus_id *busid;
+ struct wsdisplayio_fbinfo *fbi;
+ struct rasops_info *ri = &sc->sc_genfb.vd.active->scr_ri;
+ int error;
+
+ switch (cmd) {
+ case WSDISPLAYIO_GET_BUSID:
+ busid = data;
+ busid->bus_type = WSDISPLAYIO_BUS_SOC;
+ return 0;
+ case WSDISPLAYIO_GTYPE:
+ *(u_int *)data = WSDISPLAY_TYPE_GENFB;
+ return 0;
+ case WSDISPLAYIO_GET_FBINFO:
+ fbi = data;
+ error = wsdisplayio_get_fbinfo(ri, fbi);
+ fbi->fbi_flags |= WSFB_VRAM_IS_RAM;
+ return error;
+ default:
+ return EPASSTHROUGH;
+ }
+}
diff -r d5fe53b25dd0 -r 153c4989d348 sys/arch/arm/ti/ti_lcdc.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/ti/ti_lcdc.c Sun Nov 03 22:59:06 2019 +0000
@@ -0,0 +1,656 @@
+/* $NetBSD: ti_lcdc.c,v 1.1 2019/11/03 22:59:06 jmcneill Exp $ */
+
+/*-
Home |
Main Index |
Thread Index |
Old Index