summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--firmware/drivers/audio/erosqlinux_codec.c15
-rw-r--r--firmware/drivers/audio/fiiolinux_codec.c25
-rw-r--r--firmware/drivers/audio/rocker_codec.c9
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c15
4 files changed, 40 insertions, 24 deletions
diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c
index c8a104efd6..268da54280 100644
--- a/firmware/drivers/audio/erosqlinux_codec.c
+++ b/firmware/drivers/audio/erosqlinux_codec.c
@@ -37,8 +37,7 @@
#include "logf.h"
-static int fd_hw;
-static int inited = 0;
+static int fd_hw = -1;
static long int vol_l_hw = 255;
static long int vol_r_hw = 255;
@@ -54,6 +53,7 @@ static void hw_open(void)
static void hw_close(void)
{
close(fd_hw);
+ fd_hw = -1;
}
static int muted = -1;
@@ -62,7 +62,7 @@ void audiohw_mute(int mute)
{
logf("mute %d", mute);
- if (muted == mute)
+ if (fd_hw < 0 || muted == mute)
return;
muted = mute;
@@ -84,7 +84,7 @@ int erosq_get_outputs(void) {
int status = 0;
- if (!inited) return ps;
+ if (fd_hw < 0) return ps;
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
@@ -102,7 +102,7 @@ int erosq_get_outputs(void) {
void erosq_set_output(int ps)
{
- if (!inited || muted) return;
+ if (fd_hw < 0 || muted) return;
if (last_ps != ps)
{
@@ -119,9 +119,7 @@ void audiohw_preinit(void)
logf("hw preinit");
alsa_controls_init();
hw_open();
-// audiohw_mute(true); /* Start muted to avoid the POP */
- audiohw_mute(false);
- inited = 1;
+ audiohw_mute(false); /* No need to stay muted */
}
void audiohw_postinit(void)
@@ -132,7 +130,6 @@ void audiohw_postinit(void)
void audiohw_close(void)
{
logf("hw close");
- inited = 0;
hw_close();
alsa_controls_close();
}
diff --git a/firmware/drivers/audio/fiiolinux_codec.c b/firmware/drivers/audio/fiiolinux_codec.c
index 44ebdd092c..d23e023564 100644
--- a/firmware/drivers/audio/fiiolinux_codec.c
+++ b/firmware/drivers/audio/fiiolinux_codec.c
@@ -32,8 +32,8 @@
#include "pcm-alsa.h"
#include <sys/ioctl.h>
-static int fd_hw;
-static int ak_hw;
+static int fd_hw = -1;
+static int ak_hw = -1;
static int vol_sw[2] = {0};
static long int vol_hw[2] = {0};
@@ -61,8 +61,8 @@ static void hw_close(void)
panicf("Call cmd AK4376_POWER_OFF fail");
}
close(ak_hw);
-
close(fd_hw);
+ ak_hw = fd_hw = -1;
}
void audiohw_preinit(void)
@@ -91,10 +91,15 @@ void audiohw_set_frequency(int fsel)
(void)fsel;
}
+static int muted = -1;
+
void audiohw_set_volume(int vol_l, int vol_r)
{
int vol[2];
+ if (fd_hw < 0)
+ return;
+
vol[0] = vol_l / 20;
vol[1] = vol_r / 20;
@@ -121,15 +126,20 @@ void audiohw_set_volume(int vol_l, int vol_r)
}
}
- alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]);
- alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]);
- pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]);
+ if (!muted) {
+ alsa_controls_set_ints("DACL Playback Volume", 1, &vol_hw[0]);
+ alsa_controls_set_ints("DACR Playback Volume", 1, &vol_hw[1]);
+ pcm_alsa_set_digital_volume(vol_sw[0], vol_sw[1]);
+ }
}
void audiohw_mute(int mute)
{
long int vol0 = 0;
+ if (fd_hw < 0 || muted == mute)
+ return;
+
if(mute)
{
alsa_controls_set_ints("DACL Playback Volume", 1, &vol0);
@@ -146,6 +156,9 @@ void audiohw_mute(int mute)
void audiohw_set_filter_roll_off(int value)
{
+ if (fd_hw < 0)
+ return;
+
/* 0 = Sharp;
1 = Slow;
2 = Short Sharp
diff --git a/firmware/drivers/audio/rocker_codec.c b/firmware/drivers/audio/rocker_codec.c
index f4135fdaa5..abe13be285 100644
--- a/firmware/drivers/audio/rocker_codec.c
+++ b/firmware/drivers/audio/rocker_codec.c
@@ -27,7 +27,7 @@
#include "panic.h"
#include "alsa-controls.h"
-static int fd_hw;
+static int fd_hw = -1;
static long int vol_l_hw = 255;
static long int vol_r_hw = 255;
@@ -44,11 +44,13 @@ static void hw_open(void)
static void hw_close(void)
{
close(fd_hw);
+ fd_hw = -1;
+ muted = -1;
}
void audiohw_mute(int mute)
{
- if (muted == mute)
+ if (fd_hw < 0 || muted == mute)
return;
muted = mute;
@@ -92,6 +94,9 @@ 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)
+ return;
+
alsa_controls_set_ints("Left Playback Volume", 1, &vol_l_hw);
alsa_controls_set_ints("Right Playback Volume", 1, &vol_r_hw);
}
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c
index 0425989dc5..31224abd96 100644
--- a/firmware/drivers/audio/xduoolinux_codec.c
+++ b/firmware/drivers/audio/xduoolinux_codec.c
@@ -36,8 +36,7 @@
#include "logf.h"
-static int fd_hw;
-static int inited = 0;
+static int fd_hw = -1;
static long int vol_l_hw = 255;
static long int vol_r_hw = 255;
@@ -53,6 +52,7 @@ static void hw_open(void)
static void hw_close(void)
{
close(fd_hw);
+ fd_hw = -1;
}
static int muted = -1;
@@ -61,7 +61,7 @@ void audiohw_mute(int mute)
{
logf("mute %d", mute);
- if (muted == mute)
+ if (fd_hw < 0 || muted == mute)
return;
muted = mute;
@@ -83,7 +83,7 @@ int xduoo_get_outputs(void){
int status = 0;
- if (!inited) return ps;
+ if (fd_hw < 0) return ps;
const char * const sysfs_lo_switch = "/sys/class/switch/lineout/state";
const char * const sysfs_hs_switch = "/sys/class/switch/headset/state";
@@ -109,7 +109,7 @@ int xduoo_get_outputs(void){
void xduoo_set_output(int ps)
{
- if (!inited || muted) return;
+ if (fd_hw < 0 || muted) return;
if (last_ps != ps)
{
@@ -127,7 +127,6 @@ void audiohw_preinit(void)
alsa_controls_init();
hw_open();
audiohw_mute(true); /* Start muted to avoid the POP */
- inited = 1;
// const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000
}
@@ -139,7 +138,6 @@ void audiohw_postinit(void)
void audiohw_close(void)
{
logf("hw close");
- inited = 0;
hw_close();
alsa_controls_close();
}
@@ -166,6 +164,9 @@ void audiohw_set_volume(int vol_l, int vol_r)
r = -vol_r/5;
}
+ if (fd_hw < 0)
+ return;
+
alsa_controls_set_ints("Left Playback Volume", 1, &l);
alsa_controls_set_ints("Right Playback Volume", 1, &r);
}