[U-Boot] [PATCH 22/33] sandbox: sound: Silence sound for testing
Bin Meng
bmeng.cn at gmail.com
Wed Feb 13 09:39:09 UTC 2019
Hi Simon,
On Tue, Jan 22, 2019 at 9:14 AM Simon Glass <sjg at chromium.org> wrote:
>
> When testing the sound system we don't need the hear the beeps. The
> testing works by checking the data that would be emitted. Add a
> device-tree property to silence the sound, and enable it for testing.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> arch/sandbox/dts/test.dts | 1 +
> drivers/sound/sandbox.c | 23 +++++++++++++++++++++--
> 2 files changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
> index 9144430cc0..5748cd60b1 100644
> --- a/arch/sandbox/dts/test.dts
> +++ b/arch/sandbox/dts/test.dts
> @@ -389,6 +389,7 @@
> i2s: i2s {
> compatible = "sandbox,i2s";
> #sound-dai-cells = <1>;
> + sandbox,silent; /* Don't emit sounds while testing */
> };
>
> misc-test {
> diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c
> index 600523160f..4b57ef6759 100644
> --- a/drivers/sound/sandbox.c
> +++ b/drivers/sound/sandbox.c
> @@ -3,6 +3,8 @@
> * Copyright (c) 2013 Google, Inc
> */
>
> +#define LOG_CATEGORY UCLASS_SOUND
> +
> #include <common.h>
> #include <audio_codec.h>
> #include <dm.h>
> @@ -20,6 +22,7 @@ struct sandbox_codec_priv {
>
> struct sandbox_i2s_priv {
> int sum; /* Use to sum the provided audio data */
> + bool silent; /* Sound is silent, don't use SDL */
> };
>
> struct sandbox_sound_priv {
> @@ -101,12 +104,21 @@ static int sandbox_i2s_tx_data(struct udevice *dev, void *data,
> for (i = 0; i < data_size; i++)
> priv->sum += ((uint8_t *)data)[i];
>
> - return sandbox_sdl_sound_play(data, data_size);
> + if (!priv->silent) {
> + int ret;
> +
> + ret = sandbox_sdl_sound_play(data, data_size);
> + if (ret)
> + return ret;
> + }
> +
> + return 0;
> }
>
> static int sandbox_i2s_probe(struct udevice *dev)
> {
> struct i2s_uc_priv *uc_priv = dev_get_uclass_priv(dev);
> + struct sandbox_i2s_priv *priv = dev_get_priv(dev);
>
> /* Use hard-coded values here */
> uc_priv->rfs = 256;
> @@ -117,8 +129,15 @@ static int sandbox_i2s_probe(struct udevice *dev)
> uc_priv->channels = 2;
> uc_priv->id = 1;
>
> + priv->silent = dev_read_bool(dev, "sandbox,silent");
> +
> /* Ignore any error here - we'll just have no sound */
> - sandbox_sdl_sound_init(uc_priv->samplingrate, uc_priv->channels);
> + if (priv->silent) {
> + log_warning("Sound is silenced\n");
> + } else if (sandbox_sdl_sound_init(uc_priv->samplingrate,
> + uc_priv->channels)) {
> + priv->silent = true;
should be false?
> + }
>
> return 0;
> }
Regards,
Bin
More information about the U-Boot
mailing list