Module Name:    src
Committed By:   isaki
Date:           Sat Jun  8 08:20:11 UTC 2019

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

Log Message:
Improve checking and displaying property.
- Full/half duplex and independentness are valid only on bidirectional
  device.
- MMAP is no longer hardware driver's property.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/audio/audio.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/audio/audio.c
diff -u src/sys/dev/audio/audio.c:1.12 src/sys/dev/audio/audio.c:1.13
--- src/sys/dev/audio/audio.c:1.12	Sat Jun  8 08:02:37 2019
+++ src/sys/dev/audio/audio.c	Sat Jun  8 08:20:10 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: audio.c,v 1.12 2019/06/08 08:02:37 isaki Exp $	*/
+/*	$NetBSD: audio.c,v 1.13 2019/06/08 08:20:10 isaki Exp $	*/
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -142,7 +142,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.12 2019/06/08 08:02:37 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.13 2019/06/08 08:20:10 isaki Exp $");
 
 #ifdef _KERNEL_OPT
 #include "audio.h"
@@ -838,7 +838,10 @@ audioattach(device_t parent, device_t se
 	audio_filter_reg_t rfil;
 	const struct sysctlnode *node;
 	void *hdlp;
-	bool is_indep;
+	bool has_playback;
+	bool has_capture;
+	bool has_indep;
+	bool has_fulldup;
 	int mode;
 	int props;
 	int error;
@@ -884,38 +887,47 @@ audioattach(device_t parent, device_t se
 	props = audio_get_props(sc);
 	mutex_exit(sc->sc_lock);
 
-	if ((props & AUDIO_PROP_FULLDUPLEX))
-		aprint_normal(": full duplex");
-	else
-		aprint_normal(": half duplex");
+	has_playback = (props & AUDIO_PROP_PLAYBACK);
+	has_capture  = (props & AUDIO_PROP_CAPTURE);
+	has_indep    = (props & AUDIO_PROP_INDEPENDENT);
+	has_fulldup  = (props & AUDIO_PROP_FULLDUPLEX);
+
+	KASSERT(has_playback || has_capture);
+	/* Unidirectional device must have neither FULLDUP nor INDEPENDENT. */
+	if (!has_playback || !has_capture) {
+		KASSERT(!has_indep);
+		KASSERT(!has_fulldup);
+	}
 
-	is_indep = (props & AUDIO_PROP_INDEPENDENT);
 	mode = 0;
-	if ((props & AUDIO_PROP_PLAYBACK)) {
+	if (has_playback) {
+		aprint_normal(": playback");
 		mode |= AUMODE_PLAY;
-		aprint_normal(", playback");
 	}
-	if ((props & AUDIO_PROP_CAPTURE)) {
+	if (has_capture) {
+		aprint_normal("%c capture", has_playback ? ',' : ':');
 		mode |= AUMODE_RECORD;
-		aprint_normal(", capture");
 	}
-	if ((props & AUDIO_PROP_MMAP) != 0)
-		aprint_normal(", mmap");
-	if (is_indep)
-		aprint_normal(", independent");
+	if (has_playback && has_capture) {
+		if (has_fulldup)
+			aprint_normal(", full duplex");
+		else
+			aprint_normal(", half duplex");
+
+		if (has_indep)
+			aprint_normal(", independent");
+	}
 
 	aprint_naive("\n");
 	aprint_normal("\n");
 
-	KASSERT((mode & (AUMODE_PLAY | AUMODE_RECORD)) != 0);
-
 	/* probe hw params */
 	memset(&phwfmt, 0, sizeof(phwfmt));
 	memset(&rhwfmt, 0, sizeof(rhwfmt));
 	memset(&pfil, 0, sizeof(pfil));
 	memset(&rfil, 0, sizeof(rfil));
 	mutex_enter(sc->sc_lock);
-	error = audio_hw_probe(sc, is_indep, &mode, &phwfmt, &rhwfmt);
+	error = audio_hw_probe(sc, has_indep, &mode, &phwfmt, &rhwfmt);
 	if (error) {
 		mutex_exit(sc->sc_lock);
 		aprint_error_dev(self, "audio_hw_probe failed, "

Reply via email to