Module Name:    src
Committed By:   bouyer
Date:           Thu Nov 19 18:48:22 UTC 2015

Modified Files:
        src/sys/arch/arm/allwinner: awin_debe.c awin_hdmi.c awin_hdmiaudio.c
            awin_tcon.c awin_var.h

Log Message:
Turn off video output on WSDISPLAYIO_SVIDEO.
For LCD/LVDS, just stop the tcon0.
For HDMI, turn off tcon and hdmi (so that the monitor goes to sleeo)
if the audio output is inactive.
For this, add a lock-protected refcount in awin_hdmi, incremented when
audio and/or video is active.
Tested with an audio-enabled HDMI display.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/arm/allwinner/awin_debe.c \
    src/sys/arch/arm/allwinner/awin_hdmi.c
cvs rdiff -u -r1.5 -r1.6 src/sys/arch/arm/allwinner/awin_hdmiaudio.c
cvs rdiff -u -r1.9 -r1.10 src/sys/arch/arm/allwinner/awin_tcon.c
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/arm/allwinner/awin_var.h

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/arm/allwinner/awin_debe.c
diff -u src/sys/arch/arm/allwinner/awin_debe.c:1.18 src/sys/arch/arm/allwinner/awin_debe.c:1.19
--- src/sys/arch/arm/allwinner/awin_debe.c:1.18	Tue Nov  3 18:38:03 2015
+++ src/sys/arch/arm/allwinner/awin_debe.c	Thu Nov 19 18:48:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_debe.c,v 1.18 2015/11/03 18:38:03 bouyer Exp $ */
+/* $NetBSD: awin_debe.c,v 1.19 2015/11/19 18:48:22 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <[email protected]>
@@ -37,7 +37,7 @@
 #define AWIN_DEBE_CURMAX	64
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_debe.c,v 1.18 2015/11/03 18:38:03 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_debe.c,v 1.19 2015/11/19 18:48:22 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -583,6 +583,10 @@ awin_debe_ioctl(device_t self, u_long cm
 		enable = *(int *)data;
 		val = DEBE_READ(sc, AWIN_DEBE_MODCTL_REG);
 		if (enable) {
+			if (val & AWIN_DEBE_MODCTL_LAY0_EN) {
+				/* already enabled */
+				return 0;
+			}
 			val |= AWIN_DEBE_MODCTL_LAY0_EN;
 			if (sc->sc_cursor_enable) {
 				val |= AWIN_DEBE_MODCTL_HWC_EN;
@@ -590,10 +594,16 @@ awin_debe_ioctl(device_t self, u_long cm
 				val &= ~AWIN_DEBE_MODCTL_HWC_EN;
 			}
 		} else {
+			if ((val & AWIN_DEBE_MODCTL_LAY0_EN) == 0) {
+				/* already disabled */
+				return 0;
+			}
 			val &= ~AWIN_DEBE_MODCTL_LAY0_EN;
 			val &= ~AWIN_DEBE_MODCTL_HWC_EN;
 		}
 		DEBE_WRITE(sc, AWIN_DEBE_MODCTL_REG, val);
+		/* debe0 always connected to tcon0, debe1 to tcon1*/
+		awin_tcon_setvideo(device_unit(sc->sc_dev), enable);
 		return 0;
 	case WSDISPLAYIO_GVIDEO:
 		val = DEBE_READ(sc, AWIN_DEBE_MODCTL_REG);
Index: src/sys/arch/arm/allwinner/awin_hdmi.c
diff -u src/sys/arch/arm/allwinner/awin_hdmi.c:1.18 src/sys/arch/arm/allwinner/awin_hdmi.c:1.19
--- src/sys/arch/arm/allwinner/awin_hdmi.c:1.18	Sun Nov 15 21:28:54 2015
+++ src/sys/arch/arm/allwinner/awin_hdmi.c	Thu Nov 19 18:48:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_hdmi.c,v 1.18 2015/11/15 21:28:54 bouyer Exp $ */
+/* $NetBSD: awin_hdmi.c,v 1.19 2015/11/19 18:48:22 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <[email protected]>
@@ -30,7 +30,7 @@
 #include "opt_ddb.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_hdmi.c,v 1.18 2015/11/15 21:28:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_hdmi.c,v 1.19 2015/11/19 18:48:22 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -74,6 +74,9 @@ struct awin_hdmi_softc {
 	int   sc_tcon_unit;
 	unsigned int sc_tcon_pll;
 
+	kmutex_t sc_pwr_lock;
+	int	sc_pwr_refcount; /* reference who needs HDMI */
+
 	uint32_t sc_ver;
 	unsigned int sc_i2c_blklen;
 };
@@ -219,6 +222,9 @@ awin_hdmi_attach(device_t parent, device
 	aprint_normal_dev(self, "interrupting on irq %d\n", loc->loc_intr);
 #endif
 
+	mutex_init(&sc->sc_pwr_lock, MUTEX_DEFAULT, IPL_NONE);
+	sc->sc_pwr_refcount = 1; /* we start with video powered on */
+
 	awin_hdmi_i2c_init(sc);
 
 	awin_hdmi_enable(sc);
@@ -990,6 +996,36 @@ awin_hdmi_get_info(struct awin_hdmi_info
 	}
 }
 
+void
+awin_hdmi_poweron(bool enable)
+{
+	struct awin_hdmi_softc *sc;
+	device_t dev;
+
+	dev = device_find_by_driver_unit("awinhdmi", 0);
+	if (dev == NULL) {
+		return;
+	}
+	sc = device_private(dev);
+	mutex_enter(&sc->sc_pwr_lock);
+	if (enable) {
+		KASSERT(sc->sc_pwr_refcount >= 0);
+		if (sc->sc_pwr_refcount == 0) {
+			awin_tcon1_enable(sc->sc_tcon_unit, true);
+			awin_hdmi_video_enable(sc, true);
+		}
+		sc->sc_pwr_refcount++;
+	} else {
+		sc->sc_pwr_refcount--;
+		KASSERT(sc->sc_pwr_refcount >= 0);
+		if (sc->sc_pwr_refcount == 0) {
+			awin_hdmi_video_enable(sc, false);
+			awin_tcon1_enable(sc->sc_tcon_unit, false);
+		}
+	}
+	mutex_exit(&sc->sc_pwr_lock);
+}
+
 #if defined(DDB)
 void
 awin_hdmi_dump_regs(void)

Index: src/sys/arch/arm/allwinner/awin_hdmiaudio.c
diff -u src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.5 src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.6
--- src/sys/arch/arm/allwinner/awin_hdmiaudio.c:1.5	Tue Nov 18 01:53:53 2014
+++ src/sys/arch/arm/allwinner/awin_hdmiaudio.c	Thu Nov 19 18:48:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_hdmiaudio.c,v 1.5 2014/11/18 01:53:53 jmcneill Exp $ */
+/* $NetBSD: awin_hdmiaudio.c,v 1.6 2015/11/19 18:48:22 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_hdmiaudio.c,v 1.5 2014/11/18 01:53:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_hdmiaudio.c,v 1.6 2015/11/19 18:48:22 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -410,6 +410,7 @@ awin_hdmiaudio_halt_output(void *priv)
 
 	sc->sc_pint = NULL;
 	sc->sc_pintarg = NULL;
+	awin_hdmi_poweron(false);
 
 	return 0;
 }
@@ -638,6 +639,7 @@ awin_hdmiaudio_trigger_output(void *priv
 	sc->sc_pstart = sc->sc_pcur = pstart;
 	sc->sc_pend = sc->sc_pstart + psize;
 	sc->sc_pblksize = blksize;
+	awin_hdmi_poweron(true);
 
 	dmacfg = 0;
 	dmacfg |= __SHIFTIN(AWIN_DMA_CTL_DATA_WIDTH_32,

Index: src/sys/arch/arm/allwinner/awin_tcon.c
diff -u src/sys/arch/arm/allwinner/awin_tcon.c:1.9 src/sys/arch/arm/allwinner/awin_tcon.c:1.10
--- src/sys/arch/arm/allwinner/awin_tcon.c:1.9	Sun Nov 15 21:28:54 2015
+++ src/sys/arch/arm/allwinner/awin_tcon.c	Thu Nov 19 18:48:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_tcon.c,v 1.9 2015/11/15 21:28:54 bouyer Exp $ */
+/* $NetBSD: awin_tcon.c,v 1.10 2015/11/19 18:48:22 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill <[email protected]>
@@ -29,7 +29,7 @@
 #include "opt_allwinner.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: awin_tcon.c,v 1.9 2015/11/15 21:28:54 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: awin_tcon.c,v 1.10 2015/11/19 18:48:22 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -91,6 +91,7 @@ static void	awin_tcon_attach(device_t, d
 
 static void	awin_tcon_set_pll(struct awin_tcon_softc *, int, int);
 static void	awin_tcon0_set_video(struct awin_tcon_softc *);
+static void 	awin_tcon0_enable(struct awin_tcon_softc *, bool);
 
 static void
 awin_tcon_clear_reset(struct awinio_attach_args * const aio, int unit)
@@ -537,6 +538,32 @@ awin_tcon0_set_video(struct awin_tcon_so
 	}
 }
 
+static void 
+awin_tcon0_enable(struct awin_tcon_softc *sc, bool enable) {
+	uint32_t val;
+
+	/* turn on/off backlight */
+	if (sc->sc_lcdblk_pin_name != NULL) {
+		awin_gpio_pindata_write(&sc->sc_lcdblk_pin, enable ? 1 : 0);
+	}
+	/* turn on/off LCD */
+	if (sc->sc_lcdpwr_pin_name != NULL) {
+		awin_gpio_pindata_write(&sc->sc_lcdpwr_pin, enable ? 1 : 0);
+	}
+	/* and finally disable of enable the tcon */
+	KASSERT(sc->sc_output_type != OUTPUT_HDMI);
+
+	awin_debe_enable(device_unit(sc->sc_dev), enable);
+	delay(20000);
+	val = TCON_READ(sc, AWIN_TCON_GCTL_REG);
+	if (enable) {
+		val |= AWIN_TCON_GCTL_EN;
+	} else {
+		val &= ~AWIN_TCON_GCTL_EN;
+	}
+	TCON_WRITE(sc, AWIN_TCON_GCTL_REG, val);
+}
+
 void
 awin_tcon1_enable(int unit, bool enable)
 {
@@ -736,3 +763,23 @@ awin_tcon_get_clk_dbl(int unit)
 
 	return sc->sc_clk_dbl;
 }
+
+void
+awin_tcon_setvideo(int unit, bool enable)
+{
+	struct awin_tcon_softc *sc;
+	device_t dev;
+
+	dev = device_find_by_driver_unit("awintcon", unit);
+	if (dev == NULL) {
+		printf("TCON%d: no driver found\n", unit);
+		return;
+	}
+	sc = device_private(dev);
+
+	if (sc->sc_output_type == OUTPUT_HDMI)  {
+		awin_hdmi_poweron(enable);
+	} else {
+		awin_tcon0_enable(sc, enable);
+	}
+}

Index: src/sys/arch/arm/allwinner/awin_var.h
diff -u src/sys/arch/arm/allwinner/awin_var.h:1.38 src/sys/arch/arm/allwinner/awin_var.h:1.39
--- src/sys/arch/arm/allwinner/awin_var.h:1.38	Sun Nov 15 21:28:54 2015
+++ src/sys/arch/arm/allwinner/awin_var.h	Thu Nov 19 18:48:22 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: awin_var.h,v 1.38 2015/11/15 21:28:54 bouyer Exp $ */
+/* $NetBSD: awin_var.h,v 1.39 2015/11/19 18:48:22 bouyer Exp $ */
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -142,6 +142,7 @@ unsigned int awin_tcon_get_clk_div(int);
 bool	awin_tcon_get_clk_dbl(int);
 void	awin_tcon1_set_videomode(int, const struct videomode *);
 void	awin_tcon1_enable(int, bool);
+void	awin_tcon_setvideo(int, bool);
 void	awin_debe_set_videomode(int, const struct videomode *);
 void	awin_debe_enable(int, bool);
 int	awin_debe_ioctl(device_t, u_long, void *);
@@ -155,6 +156,7 @@ struct awin_hdmi_info {
 	bool	display_hdmimode;
 };
 void	awin_hdmi_get_info(struct awin_hdmi_info *);
+void	awin_hdmi_poweron(bool);
 
 void	awin_fb_set_videomode(device_t, u_int, u_int);
 void	awin_fb_ddb_trap_callback(int);

Reply via email to