From patchwork Sun Jan 12 19:06:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1221852 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Ru20t4Fz; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47wmWq4T9xz9s4Y for ; Mon, 13 Jan 2020 06:10:31 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 64AE181815; Sun, 12 Jan 2020 20:07:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Ru20t4Fz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F236E817E5; Sun, 12 Jan 2020 20:07:29 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-io1-xd42.google.com (mail-io1-xd42.google.com [IPv6:2607:f8b0:4864:20::d42]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 97F23817ED for ; Sun, 12 Jan 2020 20:07:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd42.google.com with SMTP id b10so7246917iof.11 for ; Sun, 12 Jan 2020 11:07:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=aDJzVmW53obFzAXK1A0QSc4hPcx9+Zm0/8Gxan06CFc=; b=Ru20t4Fzb+kH2L+wvdDcViII0RFXDgso6GR6o5C2kx+uFdTZymq7JME5nVBO+uWMA7 d2G+jiVj14cb4I6YMJIyyFSXevw6cmMy5eI556LdWDFEQUalFUlJI1+e9vQ/TvLnTxRD BiCHY/rCfsLwo/Wgk6kLHGhtyO1Y9F4O5avLk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aDJzVmW53obFzAXK1A0QSc4hPcx9+Zm0/8Gxan06CFc=; b=PVdJiMyrpDoGiYS0t2zV+ipfYT8jahE2BoQ/gPXHBcj5g1GYKT28I0scc9kY/4YsQn XLA2vciSsTihUS84ig43Vp+qA/VsYm3AyF+buyZceYDJwEvYpUVLrN6jQu5uHHrcu3Gx FYg65mj1/V7wZ5LfIUYrrkT7mXpes/dapDGPXlCCNxeyEV5zIvZjgqGrFE4CT/A+KOR4 kFA28Mk+wyIQ3DncAQPHkKEjr9NmgtsHz2GEkrp2Qs47u9ZsUOA8zyWHMbRsOu7F0pA4 recQNPEukE00Vpb763FUTX5e87KyeWL9Q7Tm+HqR8049gQEb07vk97rNwxoN4FAPg0r7 PuTg== X-Gm-Message-State: APjAAAUN8MVrFmcCFa6DWBdX4KGdlK5HLzaMP6Psf8z97Zsvu9iTRNgv YqBx1SKS55Rm3tcU6CuB4SupJDrNOB0= X-Google-Smtp-Source: APXvYqyCsyUVxVr0apcVft0MbiVt7DcruheHwCwc+K6gtzb5g3uBsGhnuHratjZnRPEGcio01MAvUg== X-Received: by 2002:a05:6638:2b7:: with SMTP id d23mr11172879jaq.108.1578856045348; Sun, 12 Jan 2020 11:07:25 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id r22sm3039219ilb.25.2020.01.12.11.07.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Jan 2020 11:07:25 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 20/33] sound: Add a new stop_play() method Date: Sun, 12 Jan 2020 12:06:11 -0700 Message-Id: <20200112120216.20.Idee00db432aa6168b0a13fa31b073708ace5ae29@changeid> X-Mailer: git-send-email 2.25.0.rc1.283.g88dfdc4193-goog In-Reply-To: <20200112190624.79077-1-sjg@chromium.org> References: <20200112190624.79077-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ramon Fried Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean At present there is no positive indication that U-Boot has finished sending sound data. This means that it is not possible to power down an audio codec, for example. Add a new method that is called once all sound data has been sent. Add a new method for this, called when the sound_play() call is done. Signed-off-by: Simon Glass --- arch/sandbox/include/asm/test.h | 7 +++++++ drivers/sound/sandbox.c | 21 ++++++++++++++++++++- drivers/sound/sound-uclass.c | 11 +++++++++++ include/sound.h | 12 ++++++++++++ test/dm/sound.c | 1 + 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 2421922c9e..92ff494453 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -165,6 +165,13 @@ int sandbox_get_i2s_sum(struct udevice *dev); */ int sandbox_get_setup_called(struct udevice *dev); +/** + * sandbox_get_sound_active() - Returns whether sound play is in progress + * + * @return true if active, false if not + */ +int sandbox_get_sound_active(struct udevice *dev); + /** * sandbox_get_sound_sum() - Read back the sum of the sound data so far * diff --git a/drivers/sound/sandbox.c b/drivers/sound/sandbox.c index 363c687baf..9034a8385a 100644 --- a/drivers/sound/sandbox.c +++ b/drivers/sound/sandbox.c @@ -26,7 +26,8 @@ struct sandbox_i2s_priv { }; struct sandbox_sound_priv { - int setup_called; + int setup_called; /* Incremented when setup() method is called */ + bool active; /* TX data is being sent */ int sum; /* Use to sum the provided audio data */ bool allow_beep; /* true to allow the start_beep() interface */ int frequency_hz; /* Beep frequency if active, else 0 */ @@ -59,6 +60,13 @@ int sandbox_get_setup_called(struct udevice *dev) return priv->setup_called; } +int sandbox_get_sound_active(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + return priv->active; +} + int sandbox_get_sound_sum(struct udevice *dev) { struct sandbox_sound_priv *priv = dev_get_priv(dev); @@ -163,6 +171,16 @@ static int sandbox_sound_play(struct udevice *dev, void *data, uint data_size) return i2s_tx_data(uc_priv->i2s, data, data_size); } +static int sandbox_sound_stop_play(struct udevice *dev) +{ + struct sandbox_sound_priv *priv = dev_get_priv(dev); + + sandbox_sdl_sound_stop(); + priv->active = false; + + return 0; +} + int sandbox_sound_start_beep(struct udevice *dev, int frequency_hz) { struct sandbox_sound_priv *priv = dev_get_priv(dev); @@ -228,6 +246,7 @@ U_BOOT_DRIVER(sandbox_i2s) = { static const struct sound_ops sandbox_sound_ops = { .setup = sandbox_sound_setup, .play = sandbox_sound_play, + .stop_play = sandbox_sound_stop_play, .start_beep = sandbox_sound_start_beep, .stop_beep = sandbox_sound_stop_beep, }; diff --git a/drivers/sound/sound-uclass.c b/drivers/sound/sound-uclass.c index d49f29bcd5..c213472d60 100644 --- a/drivers/sound/sound-uclass.c +++ b/drivers/sound/sound-uclass.c @@ -31,6 +31,16 @@ int sound_play(struct udevice *dev, void *data, uint data_size) return ops->play(dev, data, data_size); } +int sound_stop_play(struct udevice *dev) +{ + struct sound_ops *ops = sound_get_ops(dev); + + if (!ops->play) + return -ENOSYS; + + return ops->stop_play(dev); +} + int sound_start_beep(struct udevice *dev, int frequency_hz) { struct sound_ops *ops = sound_get_ops(dev); @@ -97,6 +107,7 @@ int sound_beep(struct udevice *dev, int msecs, int frequency_hz) ret = sound_play(dev, data, size); } + sound_stop_play(dev); free(data); diff --git a/include/sound.h b/include/sound.h index 47de9fa3ed..71bd850652 100644 --- a/include/sound.h +++ b/include/sound.h @@ -68,6 +68,18 @@ struct sound_ops { */ int (*play)(struct udevice *dev, void *data, uint data_size); + /** + * stop_play() - Indicate that there is no more data coming + * + * This is called once play() has finished sending all the data to the + * output device. This may be used to tell the hardware to turn off the + * codec, for example. + * + * @dev: Sound device + * @return 0 if OK, -ve on error + */ + int (*stop_play)(struct udevice *dev); + /** * start_beep() - Start beeping (optional) * diff --git a/test/dm/sound.c b/test/dm/sound.c index 3767abbd1c..aa5368f05b 100644 --- a/test/dm/sound.c +++ b/test/dm/sound.c @@ -28,6 +28,7 @@ static int dm_test_sound(struct unit_test_state *uts) ut_asserteq(4560, sandbox_get_sound_sum(dev)); ut_assertok(sound_beep(dev, 1, 100)); ut_asserteq(9120, sandbox_get_sound_sum(dev)); + ut_asserteq(false, sandbox_get_sound_active(dev)); return 0; }