Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Dooks <ben-alsa@fluff.org>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Ben Dooks <ben-alsa@fluff.org>, alsa-devel@alsa-project.org
Subject: Re: ASoC CODEC power management on reboot
Date: Tue, 23 Jun 2009 20:39:05 +0100	[thread overview]
Message-ID: <20090623193905.GA29142@trinity.fluff.org> (raw)
In-Reply-To: <20090622121823.GA4495@sirena.org.uk>

On Mon, Jun 22, 2009 at 01:18:26PM +0100, Mark Brown wrote:
> On Mon, Jun 22, 2009 at 12:32:50PM +0100, Mark Brown wrote:
> > On Mon, Jun 22, 2009 at 12:13:23PM +0100, Ben Dooks wrote:
> 
> > > Should the ASoC (possibly DAPM) layer sort out powering down the CODEC
> > > before reboot, or should it be down to the codec or the mapping driver
> > > to do this?
> 
> > Core.
> 
> Please try this (completely untested) patch:
> 
> >From 506921be0ce5b96c3761c771a9356f2c53bd6628 Mon Sep 17 00:00:00 2001
> From: Mark Brown <broonie@opensource.wolfsonmicro.com>
> Date: Mon, 22 Jun 2009 13:16:51 +0100
> Subject: [PATCH] ASoC: Add a shutdown callback
> 
> Ensure that the audio subsystem is powered down cleanly when the system
> shuts down by providing a shutdown operation. This ensures that all the
> components have been returned to an off state cleanly which should avoid
> audio issues from partially charged capacitors or noise on digital inputs
> if the system is restarted quickly.

Right, so far this seems to have worked.
 
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Tested-by: Ben Dooks <ben-linux@fluff.org>

> ---
>  include/sound/soc-dapm.h |    1 +
>  sound/soc/soc-core.c     |   16 ++++++++++++++++
>  sound/soc/soc-dapm.c     |   29 +++++++++++++++++++++++++++++
>  3 files changed, 46 insertions(+), 0 deletions(-)
> 
> diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
> index ec8a45f..35814ce 100644
> --- a/include/sound/soc-dapm.h
> +++ b/include/sound/soc-dapm.h
> @@ -279,6 +279,7 @@ int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
>  /* dapm events */
>  int snd_soc_dapm_stream_event(struct snd_soc_codec *codec, char *stream,
>  	int event);
> +void snd_soc_dapm_shutdown(struct snd_soc_device *socdev);
>  
>  /* dapm sys fs - used by the core */
>  int snd_soc_dapm_sys_add(struct device *dev);
> diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
> index 4414117..55d45c4 100644
> --- a/sound/soc/soc-core.c
> +++ b/sound/soc/soc-core.c
> @@ -1020,6 +1020,21 @@ static int soc_remove(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static void soc_shutdown(struct platform_device *pdev)
> +{
> +	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
> +	struct snd_soc_card *card = socdev->card;
> +
> +	if (!card->instantiated)
> +		return;
> +
> +	/* Flush out pmdown_time work - we actually do want to run it
> +	 * now, we're shutting down so no imminent restart. */
> +	run_delayed_work(&card->delayed_work);
> +
> +	snd_soc_dapm_shutdown(socdev);
> +}
> +
>  /* ASoC platform driver */
>  static struct platform_driver soc_driver = {
>  	.driver		= {
> @@ -1030,6 +1045,7 @@ static struct platform_driver soc_driver = {
>  	.remove		= soc_remove,
>  	.suspend	= soc_suspend,
>  	.resume		= soc_resume,
> +	.shutdown	= soc_shutdown,
>  };
>  
>  /* create a new pcm */
> diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
> index 6534359..b9129ef 100644
> --- a/sound/soc/soc-dapm.c
> +++ b/sound/soc/soc-dapm.c
> @@ -2032,6 +2032,35 @@ void snd_soc_dapm_free(struct snd_soc_device *socdev)
>  }
>  EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
>  
> +/*
> + * snd_soc_dapm_shutdown - callback for system shutdown
> + */
> +void snd_soc_dapm_shutdown(struct snd_soc_device *socdev)
> +{
> +	struct snd_soc_codec *codec = socdev->card->codec;
> +	struct snd_soc_dapm_widget *w;
> +	LIST_HEAD(down_list);
> +	int powerdown = 0;
> +
> +	list_for_each_entry(w, &codec->dapm_widgets, list) {
> +		if (w->power) {
> +			dapm_seq_insert(w, &down_list, dapm_down_seq);
> +			powerdown = 1;
> +		}
> +	}
> +
> +	/* If there were no widgets to power down we're already in
> +	 * standby.
> +	 */
> +	if (powerdown) {
> +		snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_PREPARE);
> +		dapm_seq_run(codec, &down_list, 0, dapm_down_seq);
> +		snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_STANDBY);
> +	}
> +
> +	snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF);
> +}
> +
>  /* Module information */
>  MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
>  MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");
> -- 
> 1.6.3.1
> 
> _______________________________________________
> Alsa-devel mailing list
> Alsa-devel@alsa-project.org
> http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

-- 
-- 
Ben

Q:      What's a light-year?
A:      One-third less calories than a regular year.

      reply	other threads:[~2009-06-23 19:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-22 11:13 ASoC CODEC power management on reboot Ben Dooks
2009-06-22 11:32 ` Mark Brown
2009-06-22 12:18   ` Mark Brown
2009-06-23 19:39     ` Ben Dooks [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090623193905.GA29142@trinity.fluff.org \
    --to=ben-alsa@fluff.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox