summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Werner <jwerner@chromium.org>2016-11-01 01:07:35 (GMT)
committerchrome-bot <chrome-bot@chromium.org>2016-11-02 02:18:10 (GMT)
commitdfffe58ca6242fcdb4c5020235ab7f221772ecd5 (patch)
tree98073068929c434399cf0c2dc5386a4c2f5a662c /src
parentc8b674e7e1d49bda9717d7dec1fb26b81bdcd47b (diff)
downloaddepthcharge-dfffe58ca6242fcdb4c5020235ab7f221772ecd5.tar.gz
depthcharge-dfffe58ca6242fcdb4c5020235ab7f221772ecd5.tar.xz
sound: Add optional disable callback to SoundRouteComponent
Depthcharge likes to always just turn things on and forget about them, including the sound route components. This is usually fine, but occasionally we might have components that really need to be disabled again after we're done playing audio to ensure the thermal integrity of our speakers. This patch adds an optional callback that can be used for that purpose. BRANCH=gru BUG=chrome-os-partner:59038 TEST=Booted Kevin, listened to dev mode beep. Change-Id: I7fbeadd6a1ef660edc9f5223e8e223b4416ea41c Signed-off-by: Julius Werner <jwerner@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/405869 Tested-by: Xing Zheng <zhengxing@rock-chips.com> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src')
-rw-r--r--src/drivers/sound/route.c64
-rw-r--r--src/drivers/sound/route.h2
2 files changed, 48 insertions, 18 deletions
diff --git a/src/drivers/sound/route.c b/src/drivers/sound/route.c
index af018d3..7acc4b6 100644
--- a/src/drivers/sound/route.c
+++ b/src/drivers/sound/route.c
@@ -14,17 +14,26 @@
#include "base/list.h"
#include "drivers/sound/route.h"
-static int route_enable_components(SoundRoute *route)
+static int route_enable_components(SoundRoute *route, int enable)
{
int res = 0;
SoundRouteComponent *component;
list_for_each(component, route->components, list_node) {
- if (!component->enabled) {
- if (component->ops.enable(&component->ops))
- res = -1;
- else
- component->enabled = 1;
+ if (component->enabled != enable) {
+ if (enable) {
+ if (component->ops.enable(&component->ops))
+ res = -1;
+ else
+ component->enabled = 1;
+ } else {
+ if (!component->ops.disable)
+ continue;
+ if (component->ops.disable(&component->ops))
+ res = -1;
+ else
+ component->enabled = 0;
+ }
}
}
@@ -34,42 +43,61 @@ static int route_enable_components(SoundRoute *route)
static int route_start(SoundOps *me, uint32_t frequency)
{
SoundRoute *route = container_of(me, SoundRoute, ops);
-
- if (route_enable_components(route))
- return 1;
+ int res;
if (!route->source->start)
return -1;
- return route->source->start(route->source, frequency);
+
+ res = route_enable_components(route, 1);
+ if (res)
+ goto err;
+
+ res = route->source->start(route->source, frequency);
+ if (res)
+ goto err;
+
+ return 0;
+
+err:
+ route_enable_components(route, 0);
+ return res;
}
static int route_stop(SoundOps *me)
{
SoundRoute *route = container_of(me, SoundRoute, ops);
+ int res;
+
if (!route->source->stop)
return -1;
- return route->source->stop(route->source);
+ res = route->source->stop(route->source);
+ res |= route_enable_components(route, 0);
+ return res;
}
static int route_play(SoundOps *me, uint32_t msec, uint32_t frequency)
{
SoundRoute *route = container_of(me, SoundRoute, ops);
-
- if (route_enable_components(route))
- return 1;
+ int res;
if (!route->source->play)
return -1;
- return route->source->play(route->source, msec, frequency);
+
+ res = route_enable_components(route, 1);
+ if (res)
+ goto out;
+
+ res = route->source->play(route->source, msec, frequency);
+
+out:
+ res |= route_enable_components(route, 0);
+ return res;
}
static int route_set_volume(SoundOps *me, uint32_t volume)
{
SoundRoute *route = container_of(me, SoundRoute, ops);
- if (route_enable_components(route))
- return 1;
-
if (!route->source->set_volume)
return -1;
return route->source->set_volume(route->source, volume);
diff --git a/src/drivers/sound/route.h b/src/drivers/sound/route.h
index 7df7b14..a1f3f43 100644
--- a/src/drivers/sound/route.h
+++ b/src/drivers/sound/route.h
@@ -17,6 +17,8 @@
typedef struct SoundRouteComponentOps
{
int (*enable)(struct SoundRouteComponentOps *me);
+ // The disable() callback is optional. Only use when necessary!
+ int (*disable)(struct SoundRouteComponentOps *me);
} SoundRouteComponentOps;
typedef struct