From 42dba708e3bcd2fa448f9d2865157b910a62a11a Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Tue, 13 Apr 2021 21:38:14 -0400 Subject: hosted: Don't open alsa control device directly It was just being used as a proxy "yeah, we called hw_init()" so just use a flag for that directly. affects rocker, erosq, xduoo x3ii/x20, and fiiom3klinux Change-Id: I14bd9f8d91f1d6cc8de0982a7426e2a103c6bfce --- firmware/drivers/audio/erosqlinux_codec.c | 30 +++++++----------------------- firmware/drivers/audio/fiiolinux_codec.c | 16 +++++----------- firmware/drivers/audio/rocker_codec.c | 25 ++++++------------------- firmware/drivers/audio/xduoolinux_codec.c | 27 +++++++-------------------- 4 files changed, 25 insertions(+), 73 deletions(-) diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c index abb4fea01f..2b7d819e82 100644 --- a/firmware/drivers/audio/erosqlinux_codec.c +++ b/firmware/drivers/audio/erosqlinux_codec.c @@ -25,15 +25,11 @@ #include "config.h" #include "audio.h" #include "audiohw.h" -#include "button.h" #include "system.h" -#include "kernel.h" #include "panic.h" #include "sysfs.h" #include "alsa-controls.h" #include "pcm-alsa.h" -#include "pcm_sw_volume.h" - #include "settings.h" #include "logf.h" @@ -64,32 +60,19 @@ : values=4 */ -static int fd_hw = -1; +static int hw_init = 0; static long int vol_l_hw = 255; static long int vol_r_hw = 255; static long int last_ps = -1; -static void hw_open(void) -{ - fd_hw = open("/dev/snd/controlC0", O_RDWR); - if(fd_hw < 0) - panicf("Cannot open '/dev/snd/controlC0'"); -} - -static void hw_close(void) -{ - close(fd_hw); - fd_hw = -1; -} - static int muted = -1; void audiohw_mute(int mute) { logf("mute %d", mute); - if (fd_hw < 0 || muted == mute) + if (hw_init < 0 || muted == mute) return; muted = mute; @@ -111,7 +94,7 @@ int erosq_get_outputs(void) { int status = 0; - if (fd_hw < 0) return ps; + if (!hw_init) return ps; const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; @@ -129,7 +112,7 @@ int erosq_get_outputs(void) { void erosq_set_output(int ps) { - if (fd_hw < 0 || muted) return; + if (!hw_init || muted) return; if (last_ps != ps) { @@ -145,7 +128,7 @@ void audiohw_preinit(void) { logf("hw preinit"); alsa_controls_init("default"); - hw_open(); + hw_init = 1; audiohw_mute(false); /* No need to stay muted */ } @@ -157,7 +140,8 @@ void audiohw_postinit(void) void audiohw_close(void) { logf("hw close"); - hw_close(); + hw_init = 0; + muted = -1; alsa_controls_close(); } diff --git a/firmware/drivers/audio/fiiolinux_codec.c b/firmware/drivers/audio/fiiolinux_codec.c index 31731fd6ed..99cff3f5e4 100644 --- a/firmware/drivers/audio/fiiolinux_codec.c +++ b/firmware/drivers/audio/fiiolinux_codec.c @@ -32,7 +32,6 @@ #include "pcm-alsa.h" #include -static int fd_hw = -1; static int ak_hw = -1; static int vol_sw[2] = {0}; @@ -40,10 +39,6 @@ static long int vol_hw[2] = {0}; static void hw_open(void) { - fd_hw = open("/dev/snd/controlC0", O_RDWR); - if(fd_hw < 0) - panicf("Cannot open '/dev/snd/controlC0'"); - ak_hw = open("/dev/ak4376", O_RDWR); if(ak_hw < 0) panicf("Cannot open '/dev/ak4376'"); @@ -61,8 +56,7 @@ static void hw_close(void) panicf("Call cmd AK4376_POWER_OFF fail"); } close(ak_hw); - close(fd_hw); - ak_hw = fd_hw = -1; + ak_hw = -1; } void audiohw_preinit(void) @@ -98,7 +92,7 @@ void audiohw_set_volume(int vol_l, int vol_r) { int vol[2]; - if (fd_hw < 0) + if (ak_hw < 0) return; vol[0] = vol_l / 20; @@ -138,7 +132,7 @@ void audiohw_mute(int mute) { long int vol0 = 0; - if (fd_hw < 0 || muted == mute) + if (ak_hw < 0 || muted == mute) return; muted = mute; @@ -159,14 +153,14 @@ void audiohw_mute(int mute) void audiohw_set_filter_roll_off(int value) { - if (fd_hw < 0) +#if 0 // defined(FIIO_M3K_LINUX) + if (ak_hw < 0) return; /* 0 = Sharp; 1 = Slow; 2 = Short Sharp 3 = Short Slow */ -#if 0 // defined(FIIO_M3K_LINUX) // AK4376 supports this but the control isn't wired into ALSA! long int value_hw = value; alsa_controls_set_ints("AK4376 Digital Filter", 1, &value_hw); diff --git a/firmware/drivers/audio/rocker_codec.c b/firmware/drivers/audio/rocker_codec.c index 87257c92a4..20e45d5afb 100644 --- a/firmware/drivers/audio/rocker_codec.c +++ b/firmware/drivers/audio/rocker_codec.c @@ -27,30 +27,16 @@ #include "panic.h" #include "alsa-controls.h" -static int fd_hw = -1; +static int hw_init = 0; static long int vol_l_hw = 255; static long int vol_r_hw = 255; static int muted = -1; -static void hw_open(void) -{ - fd_hw = open("/dev/snd/controlC0", O_RDWR); - if(fd_hw < 0) - panicf("Cannot open '/dev/snd/controlC0'"); -} - -static void hw_close(void) -{ - close(fd_hw); - fd_hw = -1; - muted = -1; -} - void audiohw_mute(int mute) { - if (fd_hw < 0 || muted == mute) + if (!hw_init || muted == mute) return; muted = mute; @@ -70,7 +56,7 @@ void audiohw_mute(int mute) void audiohw_preinit(void) { alsa_controls_init("default"); - hw_open(); + hw_init = 1; #if defined(AUDIOHW_MUTE_ON_STOP) || defined(AUDIOHW_NEEDS_INITIAL_UNMUTE) audiohw_mute(true); /* Start muted to avoid the POP */ #else @@ -84,7 +70,8 @@ void audiohw_postinit(void) void audiohw_close(void) { - hw_close(); + hw_init = 0; + muted = -1; alsa_controls_close(); } @@ -98,7 +85,7 @@ void audiohw_set_volume(int vol_l, int vol_r) vol_l_hw = -vol_l/5; vol_r_hw = -vol_r/5; - if (fd_hw < 0) + if (!hw_init) return; alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw); diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c index c78864db2c..749d551739 100644 --- a/firmware/drivers/audio/xduoolinux_codec.c +++ b/firmware/drivers/audio/xduoolinux_codec.c @@ -78,32 +78,19 @@ X3ii: */ -static int fd_hw = -1; +static int hw_init = 0; static long int vol_l_hw = 255; static long int vol_r_hw = 255; static long int last_ps = -1; -static void hw_open(void) -{ - fd_hw = open("/dev/snd/controlC0", O_RDWR); - if(fd_hw < 0) - panicf("Cannot open '/dev/snd/controlC0'"); -} - -static void hw_close(void) -{ - close(fd_hw); - fd_hw = -1; -} - static int muted = -1; void audiohw_mute(int mute) { logf("mute %d", mute); - if (fd_hw < 0 || muted == mute) + if (!hw_init || muted == mute) return; muted = mute; @@ -125,7 +112,7 @@ int xduoo_get_outputs(void){ int status = 0; - if (fd_hw < 0) return ps; + if (!hw_init) return ps; const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state"; const char * const sysfs_hs_switch = "/sys/class/switch/headset/state"; @@ -151,7 +138,7 @@ int xduoo_get_outputs(void){ void xduoo_set_output(int ps) { - if (fd_hw < 0 || muted) return; + if (!hw_init || muted) return; if (last_ps != ps) { @@ -172,7 +159,7 @@ void audiohw_preinit(void) { logf("hw preinit"); alsa_controls_init("default"); - hw_open(); + hw_init = 1; #if defined(XDUOO_X3II) audiohw_mute(true); /* Start muted to avoid the POP */ @@ -191,7 +178,7 @@ void audiohw_postinit(void) void audiohw_close(void) { logf("hw close"); - hw_close(); + hw_init = 0; alsa_controls_close(); } @@ -217,7 +204,7 @@ void audiohw_set_volume(int vol_l, int vol_r) r = -vol_r/5; } - if (fd_hw < 0) + if (!hw_init) return; alsa_controls_set_ints("Left Playback Volume", 1, &l); -- cgit v1.2.3