linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: broonie@opensource.wolfsonmicro.com (Mark Brown)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/4] ASoC: cx20442: add bias control over a platform provided regulator
Date: Mon, 26 Dec 2011 11:02:01 +0000	[thread overview]
Message-ID: <20111226110201.GA8722@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1324681944-19067-3-git-send-email-jkrzyszt@tis.icnet.pl>

On Sat, Dec 24, 2011 at 12:12:22AM +0100, Janusz Krzysztofik wrote:

> +	case SND_SOC_BIAS_ON:
> +	case SND_SOC_BIAS_PREPARE:
> +		if (IS_ERR(cx20442->por.regulator)) {
> +			err = PTR_ERR(cx20442->por.regulator);
> +		} else if (!cx20442->por.enabled) {
> +			err = regulator_enable(cx20442->por.regulator);
> +			if (!err)
> +				cx20442->por.enabled = true;
> +		}
> +		break;
> +	case SND_SOC_BIAS_STANDBY:
> +	case SND_SOC_BIAS_OFF:
> +		if (IS_ERR(cx20442->por.regulator)) {
> +			err = PTR_ERR(cx20442->por.regulator);
> +		} else if (cx20442->por.enabled) {
> +			err = regulator_disable(cx20442->por.regulator);
> +			if (!err)
> +				cx20442->por.enabled = false;
> +		}
> +	}
> +	mutex_unlock(&cx20442->por.lock);

You can avoid the mutex and simplify the code by relying on the fact
that the only possible transitions are:

   OFF <-> STANDBY <-> PREPARE <-> ON

which would look a lot more natural - you shouldn't need to remember if
the regulator is enabled, you should just turn it on in the STANDBY to
PREPARE transition and turn it off in the ON to PREPARE or PREPARE to
STANDBY transitions.

  reply	other threads:[~2011-12-26 11:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-23 23:12 [PATCH 0/4] Amstrad Delta: access MODEM_RESET GPIO pin over a regulator Janusz Krzysztofik
2011-12-23 23:12 ` [PATCH 1/4] ARM: OMAP1: ams-delta: set up regulator over modem reset GPIO pin Janusz Krzysztofik
2011-12-23 23:12 ` [PATCH 2/4] ASoC: cx20442: add bias control over a platform provided regulator Janusz Krzysztofik
2011-12-26 11:02   ` Mark Brown [this message]
2011-12-26 12:18     ` [alsa-devel] " Janusz Krzysztofik
2011-12-27 14:16     ` Janusz Krzysztofik
2011-12-27 17:26       ` Mark Brown
2011-12-23 23:12 ` [PATCH 3/4] ARM: OMAP1: ams-delta: update the modem to use regulator API Janusz Krzysztofik
2011-12-23 23:12 ` [PATCH 4/4] ASoC: OMAP: ams-delta: drop .set_bias_level callback Janusz Krzysztofik
2011-12-26 11:03   ` Mark Brown
2011-12-26 12:30     ` Janusz Krzysztofik
2011-12-26 17:23       ` Mark Brown
2011-12-26 20:43         ` Janusz Krzysztofik

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=20111226110201.GA8722@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).