Module Name:    src
Committed By:   jmcneill
Date:           Sat Feb  8 00:14:06 UTC 2020

Modified Files:
        src/sys/dev/hdaudio: hdaudio.c

Log Message:
Read GCAP and version regs after taking the controller out of reset. Fixes
stream counts on my Radeon HD 7850.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/hdaudio/hdaudio.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/dev/hdaudio/hdaudio.c
diff -u src/sys/dev/hdaudio/hdaudio.c:1.9 src/sys/dev/hdaudio/hdaudio.c:1.10
--- src/sys/dev/hdaudio/hdaudio.c:1.9	Fri Jul 26 11:13:46 2019
+++ src/sys/dev/hdaudio/hdaudio.c	Sat Feb  8 00:14:06 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: hdaudio.c,v 1.9 2019/07/26 11:13:46 jmcneill Exp $ */
+/* $NetBSD: hdaudio.c,v 1.10 2020/02/08 00:14:06 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2009 Precedence Technologies Ltd <supp...@precedence.co.uk>
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.9 2019/07/26 11:13:46 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hdaudio.c,v 1.10 2020/02/08 00:14:06 jmcneill Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -121,36 +121,21 @@ hdaudio_codec_init(struct hdaudio_softc 
 static void
 hdaudio_init(struct hdaudio_softc *sc)
 {
-	uint16_t gcap;
-	int nos, nis, nbidir;
-#if defined(HDAUDIO_DEBUG)
-	uint8_t vmin, vmaj;
-	int nsdo, addr64;
-#endif
-
-#if defined(HDAUDIO_DEBUG)
-	vmaj = hda_read1(sc, HDAUDIO_MMIO_VMAJ);
-	vmin = hda_read1(sc, HDAUDIO_MMIO_VMIN);
-
-	hda_print(sc, "High Definition Audio version %d.%d\n", vmaj, vmin);
-#endif
+	const uint8_t vmaj = hda_read1(sc, HDAUDIO_MMIO_VMAJ);
+	const uint8_t vmin = hda_read1(sc, HDAUDIO_MMIO_VMIN);
+	const uint16_t gcap = hda_read2(sc, HDAUDIO_MMIO_GCAP);
+	const int nis = HDAUDIO_GCAP_ISS(gcap);
+	const int nos = HDAUDIO_GCAP_OSS(gcap);
+	const int nbidir = HDAUDIO_GCAP_BSS(gcap);
+	const int nsdo = HDAUDIO_GCAP_NSDO(gcap);
+	const int addr64 = HDAUDIO_GCAP_64OK(gcap);
 
-	gcap = hda_read2(sc, HDAUDIO_MMIO_GCAP);
-	nis = HDAUDIO_GCAP_ISS(gcap);
-	nos = HDAUDIO_GCAP_OSS(gcap);
-	nbidir = HDAUDIO_GCAP_BSS(gcap);
+	hda_print(sc, "HDA ver. %d.%d, OSS %d, ISS %d, BSS %d, SDO %d%s\n",
+	    vmaj, vmin, nos, nis, nbidir, nsdo, addr64 ? ", 64-bit" : "");
 
 	/* Initialize codecs and streams */
 	hdaudio_codec_init(sc);
 	hdaudio_stream_init(sc, nis, nos, nbidir);
-
-#if defined(HDAUDIO_DEBUG)
-	nsdo = HDAUDIO_GCAP_NSDO(gcap);
-	addr64 = HDAUDIO_GCAP_64OK(gcap);
-
-	hda_print(sc, "OSS %d ISS %d BSS %d SDO %d%s\n",
-	    nos, nis, nbidir, nsdo, addr64 ? " 64-bit" : "");
-#endif
 }
 
 static int
@@ -795,8 +780,6 @@ hdaudio_attach(device_t dev, struct hdau
 	mutex_init(&sc->sc_corb_mtx, MUTEX_DEFAULT, IPL_AUDIO);
 	mutex_init(&sc->sc_stream_mtx, MUTEX_DEFAULT, IPL_AUDIO);
 
-	hdaudio_init(sc);
-
 	/*
 	 * Put the controller into a known state by entering and leaving
 	 * CRST as necessary.
@@ -814,6 +797,15 @@ hdaudio_attach(device_t dev, struct hdau
 	 * In reality, we need to wait longer than this.
 	 */
 	hda_delay(HDAUDIO_CODEC_DELAY);
+
+	/*
+	 * Read device capabilities
+	 */
+	hdaudio_init(sc);
+
+	/*
+	 * Detect codecs
+	 */
 	if (hdaudio_codec_probe(sc) == 0) {
 		hda_error(sc, "no codecs found\n");
 		err = ENODEV;

Reply via email to