Module Name:    src
Committed By:   jmcneill
Date:           Fri May 11 23:05:41 UTC 2018

Modified Files:
        src/sys/arch/arm/sunxi: sun50i_a64_acodec.c sun8i_codec.c

Log Message:
Disable lineout by default. If HP is not plugged at boot, we get an
unplug event. However, no plug event when HP is plugged at boot.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/arm/sunxi/sun50i_a64_acodec.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/arm/sunxi/sun8i_codec.c

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/sunxi/sun50i_a64_acodec.c
diff -u src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.3 src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.4
--- src/sys/arch/arm/sunxi/sun50i_a64_acodec.c:1.3	Fri May 11 22:51:12 2018
+++ src/sys/arch/arm/sunxi/sun50i_a64_acodec.c	Fri May 11 23:05:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sun50i_a64_acodec.c,v 1.3 2018/05/11 22:51:12 jmcneill Exp $ */
+/* $NetBSD: sun50i_a64_acodec.c,v 1.4 2018/05/11 23:05:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_acodec.c,v 1.3 2018/05/11 22:51:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun50i_a64_acodec.c,v 1.4 2018/05/11 23:05:41 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -439,15 +439,21 @@ a64_acodec_dai_jack_detect(audio_dai_tag
 {
 	struct a64_acodec_softc * const sc = audio_dai_private(dai);
 	const uint32_t lineout_mask = A64_LINEOUT_LEFT_EN | A64_LINEOUT_RIGHT_EN;
+	const uint32_t hppa_mask = A64_HPPA_EN;
 
 	switch (jack) {
 	case AUDIO_DAI_JACK_HP:
-		if (present)
+		if (present) {
 			a64_acodec_pr_set_clear(sc, A64_LINEOUT_CTRL0,
 			    0, lineout_mask);
-		else
+			a64_acodec_pr_set_clear(sc, A64_HP_CTRL,
+			    hppa_mask, 0);
+		} else {
 			a64_acodec_pr_set_clear(sc, A64_LINEOUT_CTRL0,
 			    lineout_mask, 0);
+			a64_acodec_pr_set_clear(sc, A64_HP_CTRL,
+			    0, hppa_mask);
+		}
 		break;
 	case AUDIO_DAI_JACK_MIC:
 		/* XXX TODO */
@@ -495,12 +501,10 @@ a64_acodec_attach(device_t parent, devic
 	aprint_naive("\n");
 	aprint_normal(": A64 Audio Codec (analog part)\n");
 
-	/* Right & Left LINEOUT enable */
-	a64_acodec_pr_set_clear(sc, A64_LINEOUT_CTRL0,
-	    A64_LINEOUT_LEFT_EN | A64_LINEOUT_RIGHT_EN, 0);
 	/* Right & Left Headphone PA enable */
 	a64_acodec_pr_set_clear(sc, A64_HP_CTRL,
 	    A64_HPPA_EN, 0);
+
 	/* Jack detect enable */
 	a64_acodec_pr_set_clear(sc, A64_JACK_MIC_CTRL,
 	    A64_JACKDETEN | A64_INNERRESEN | A64_AUTOPLEN, 0);

Index: src/sys/arch/arm/sunxi/sun8i_codec.c
diff -u src/sys/arch/arm/sunxi/sun8i_codec.c:1.2 src/sys/arch/arm/sunxi/sun8i_codec.c:1.3
--- src/sys/arch/arm/sunxi/sun8i_codec.c:1.2	Fri May 11 22:51:12 2018
+++ src/sys/arch/arm/sunxi/sun8i_codec.c	Fri May 11 23:05:41 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sun8i_codec.c,v 1.2 2018/05/11 22:51:12 jmcneill Exp $ */
+/* $NetBSD: sun8i_codec.c,v 1.3 2018/05/11 23:05:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 Jared McNeill <jmcne...@invisible.ca>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sun8i_codec.c,v 1.2 2018/05/11 22:51:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sun8i_codec.c,v 1.3 2018/05/11 23:05:41 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -118,7 +118,6 @@ struct sun8i_codec_softc {
 
 	struct audio_dai_device	sc_dai;
 	audio_dai_tag_t		sc_codec_analog;
-	uint32_t		sc_jackdet;
 	int			sc_jackdet_pol;
 
 	struct fdtbus_gpio_pin	*sc_pin_pa;
@@ -260,15 +259,15 @@ sun8i_codec_set_jackdet(struct sun8i_cod
 static int
 sun8i_codec_intr(void *priv)
 {
-	struct sun8i_codec_softc * const sc = priv;
 	const uint32_t mask =
 	    HMIC_STS_JACK_DET_OIRQ |
 	    HMIC_STS_JACK_DET_IIRQ |
 	    HMIC_STS_MIC_DET_ST;
+	struct sun8i_codec_softc * const sc = priv;
+	uint32_t val;
 
-	sc->sc_jackdet = RD4(sc, HMIC_STS);
-
-	if (sc->sc_jackdet & mask) {
+	val = RD4(sc, HMIC_STS);
+	if (val & mask) {
 		/* Disable jack detect IRQ until work is complete */
 		sun8i_codec_set_jackdet(sc, false);
 
@@ -276,8 +275,6 @@ sun8i_codec_intr(void *priv)
 		workqueue_enqueue(sc->sc_workq, &sc->sc_work, NULL);
 	}
 
-	WR4(sc, HMIC_STS, sc->sc_jackdet);
-
 	return 1;
 }
 
@@ -286,17 +283,19 @@ static void
 sun8i_codec_thread(struct work *wk, void *priv)
 {
 	struct sun8i_codec_softc * const sc = priv;
-	const uint32_t sts = sc->sc_jackdet;
 	int hpdet = -1, micdet = -1;
+	uint32_t val;
+
+	val = RD4(sc, HMIC_STS);
 
 	if (sc->sc_codec_analog) {
-		if (sts & HMIC_STS_JACK_DET_OIRQ)
+		if (val & HMIC_STS_JACK_DET_OIRQ)
 			hpdet = 0 ^ sc->sc_jackdet_pol;
-		else if (sts & HMIC_STS_JACK_DET_IIRQ)
+		else if (val & HMIC_STS_JACK_DET_IIRQ)
 			hpdet = 1 ^ sc->sc_jackdet_pol;
 
-		if (sts & HMIC_STS_MIC_DET_ST)
-			micdet = !!(sts & HMIC_STS_MIC_PRESENT);
+		if (val & HMIC_STS_MIC_DET_ST)
+			micdet = !!(val & HMIC_STS_MIC_PRESENT);
 
 		if (hpdet != -1) {
 			audio_dai_jack_detect(sc->sc_codec_analog,
@@ -308,6 +307,8 @@ sun8i_codec_thread(struct work *wk, void
 		}
 	}
 
+	WR4(sc, HMIC_STS, val);
+
 	/* Re-enable jack detect IRQ */
 	sun8i_codec_set_jackdet(sc, true);
 }

Reply via email to