Re: Remove audio(9) speaker_ctl(), let open() handle speakers where needed

2022-11-02 Thread Alexandre Ratchov
On Sun, Oct 30, 2022 at 11:02:39AM +, Klemens Nanni wrote:
> Only five legacy half-duplex hardware drivers require this function to
> change between playing and recording:
>   i386: ess(4), gus(4), pas(4), sb(4)
>   luna88k: nec86(4)
> 
> If defined, it is always called early in audio_open(), so just move the
> call from audio(4) to each hardware driver's open() handler.
> 
> SPKR_ON/OFF remain defined to leave driver-specific code unchanged.
> 
> Further cleanup (unchecked speaker_ctl() return values,
> FWRITE -> AUMODE_PLAY -> SPKR_ON dances, etc.) can happen later.
> 
> i386/GENERIC.MP builds fine.
> Feedback? Objection? OK?

ok ratchov



Remove audio(9) speaker_ctl(), let open() handle speakers where needed

2022-10-30 Thread Klemens Nanni
Only five legacy half-duplex hardware drivers require this function to
change between playing and recording:
i386: ess(4), gus(4), pas(4), sb(4)
luna88k: nec86(4)

If defined, it is always called early in audio_open(), so just move the
call from audio(4) to each hardware driver's open() handler.

SPKR_ON/OFF remain defined to leave driver-specific code unchanged.

Further cleanup (unchecked speaker_ctl() return values,
FWRITE -> AUMODE_PLAY -> SPKR_ON dances, etc.) can happen later.

i386/GENERIC.MP builds fine.
Feedback? Objection? OK?
---
 share/man/man9/audio.9  | 10 --
 sys/arch/luna88k/cbus/nec86.c   |  1 -
 sys/arch/luna88k/cbus/nec86hw.c |  2 ++
 sys/dev/audio.c |  8 
 sys/dev/audio_if.h  |  1 -
 sys/dev/isa/ess.c   |  4 ++--
 sys/dev/isa/gus.c   | 13 +++--
 sys/dev/isa/gusvar.h|  1 -
 sys/dev/isa/pas.c   |  1 -
 sys/dev/isa/sb.c|  1 -
 sys/dev/isa/sbdsp.c |  2 ++
 11 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/share/man/man9/audio.9 b/share/man/man9/audio.9
index f03bd74c8b8..50cf1197fa9 100644
--- a/share/man/man9/audio.9
+++ b/share/man/man9/audio.9
@@ -60,10 +60,6 @@ struct audio_hw_if {
int (*halt_output)(void *);
int (*halt_input)(void *);
 
-   int (*speaker_ctl)(void *, int);
-#define SPKR_ON  1
-#define SPKR_OFF 0
-
int (*set_port)(void *, struct mixer_ctrl *);
int (*get_port)(void *, struct mixer_ctrl *);
 
@@ -275,12 +271,6 @@ This function is called to abort the input transfer 
(started by
 .Fn start_input )
 in progress.
 This function returns 0 on success, otherwise an error code.
-.It Ft int Fn (*speaker_ctl) "void *hdl" "int on"
-This function is optional.
-If supplied, it is called when a half duplex device changes between
-playing and recording.
-It can, e.g., be used to turn the speaker on and off.
-This function returns 0 on success, otherwise an error code.
 .It Ft int Fn (*set_port) "void *hdl" "struct mixer_ctrl *mc"
 This function is called when the
 .Dv AUDIO_MIXER_WRITE
diff --git a/sys/arch/luna88k/cbus/nec86.c b/sys/arch/luna88k/cbus/nec86.c
index 49e31c52d46..36d34fa50bf 100644
--- a/sys/arch/luna88k/cbus/nec86.c
+++ b/sys/arch/luna88k/cbus/nec86.c
@@ -79,7 +79,6 @@ const struct audio_hw_if nec86_hw_if = {
.start_input= nec86hw_pdma_input,
.halt_output= nec86hw_halt_pdma,
.halt_input = nec86hw_halt_pdma,
-   .speaker_ctl= nec86hw_speaker_ctl,
.set_port   = nec86hw_mixer_set_port,
.get_port   = nec86hw_mixer_get_port,
.query_devinfo  = nec86hw_mixer_query_devinfo,
diff --git a/sys/arch/luna88k/cbus/nec86hw.c b/sys/arch/luna88k/cbus/nec86hw.c
index 070c7f57344..7a4740f781c 100644
--- a/sys/arch/luna88k/cbus/nec86hw.c
+++ b/sys/arch/luna88k/cbus/nec86hw.c
@@ -176,6 +176,8 @@ nec86hw_open(void *arg, int flags)
if (sc->sc_open != 0 || nec86hw_reset(sc) != 0)
return ENXIO;
 
+   nec86hw_speaker_ctl(sc, (flags & FWRITE) ? SPKR_ON : SPKR_OFF);
+
sc->sc_open = 1;
sc->sc_intr = NULL;
sc->sc_arg = NULL;
diff --git a/sys/dev/audio.c b/sys/dev/audio.c
index d57a743460a..06ddb17de32 100644
--- a/sys/dev/audio.c
+++ b/sys/dev/audio.c
@@ -1492,14 +1492,6 @@ audio_open(struct audio_softc *sc, int flags)
if (flags & FREAD)
sc->mode |= AUMODE_RECORD;
 
-   if (sc->ops->speaker_ctl) {
-   /*
-* XXX: what is this used for?
-*/
-   sc->ops->speaker_ctl(sc->arg,
-   (sc->mode & AUMODE_PLAY) ? SPKR_ON : SPKR_OFF);
-   }
-
error = audio_setpar(sc);
if (error)
goto bad;
diff --git a/sys/dev/audio_if.h b/sys/dev/audio_if.h
index 564139271bb..a3c1e6f307b 100644
--- a/sys/dev/audio_if.h
+++ b/sys/dev/audio_if.h
@@ -99,7 +99,6 @@ struct audio_hw_if {
int (*halt_output)(void *);
int (*halt_input)(void *);
 
-   int (*speaker_ctl)(void *, int);
 #define SPKR_ON1
 #define SPKR_OFF   0
 
diff --git a/sys/dev/isa/ess.c b/sys/dev/isa/ess.c
index c195a1749d3..90c48be7d6a 100644
--- a/sys/dev/isa/ess.c
+++ b/sys/dev/isa/ess.c
@@ -204,7 +204,6 @@ const struct audio_hw_if ess_1788_hw_if = {
.round_blocksize = ess_round_blocksize,
.halt_output = ess_audio1_halt,
.halt_input = ess_audio1_halt,
-   .speaker_ctl = ess_speaker_ctl,
.set_port = ess_set_port,
.get_port = ess_get_port,
.query_devinfo = ess_query_devinfo,
@@ -222,7 +221,6 @@ const struct audio_hw_if ess_1888_hw_if = {
.round_blocksize = ess_round_blocksize,
.halt_output = ess_audio2_halt,
.halt_input = ess_audio1_halt,
-   .speaker_ctl = ess_speaker_ctl,
.set_port = ess_set_port,
.get_port = ess_get_port,