mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Cezary Rojewski <cezary.rojewski@intel.com>
To: Oleksandr Suvorov <oleksandr.suvorov@toradex.com>
Cc: Fabio Estevam <festevam@gmail.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	Marcel Ziswiler <marcel.ziswiler@toradex.com>,
	Igor Opaniuk <igor.opaniuk@toradex.com>,
	Jaroslav Kysela <perex@perex.cz>, Mark Brown <broonie@kernel.org>,
	Takashi Iwai <tiwai@suse.com>,
	Liam Girdwood <lgirdwood@gmail.com>
Subject: Re: [PATCH v3 6/6] ASoC: sgtl5000: Improve VAG power and mute control
Date: Sun, 14 Jul 2019 19:17:43 +0200	[thread overview]
Message-ID: <e9f0f7c7-4c11-36ad-679c-503f6160b83f@intel.com> (raw)
In-Reply-To: <20190712145550.27500-7-oleksandr.suvorov@toradex.com>

On 2019-07-12 16:56, Oleksandr Suvorov wrote:
>   
> +enum {
> +	HP_POWER_EVENT,
> +	DAC_POWER_EVENT,
> +	ADC_POWER_EVENT
> +};
> +
> +struct sgtl5000_mute_state {
> +	u16 hp_event;
> +	u16 dac_event;
> +	u16 adc_event;
> +};
> +
>   /* sgtl5000 private structure in codec */
>   struct sgtl5000_priv {
>   	int sysclk;	/* sysclk rate */
> @@ -137,8 +156,109 @@ struct sgtl5000_priv {
>   	u8 micbias_voltage;
>   	u8 lrclk_strength;
>   	u8 sclk_strength;
> +	struct sgtl5000_mute_state mute_state;

Why not array instead?
u16 mute_state[ADC_POWER_EVENT+1];
-or-
u16 mute_state[LAST_POWER_EVENT+1]; (if you choose to add explicit LAST 
enum constant).

Enables simplification, see below.

> @@ -170,40 +290,79 @@ static int mic_bias_event(struct snd_soc_dapm_widget *w,
>   	return 0;
>   }
>   
> -/*
> - * As manual described, ADC/DAC only works when VAG powerup,
> - * So enabled VAG before ADC/DAC up.
> - * In power down case, we need wait 400ms when vag fully ramped down.
> - */
> -static int power_vag_event(struct snd_soc_dapm_widget *w,
> -	struct snd_kcontrol *kcontrol, int event)
> +static void vag_and_mute_control(struct snd_soc_component *component,
> +				 int event, int event_source,
> +				 u16 mute_mask, u16 *mute_reg)
>   {
> -	struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
> -	const u32 mask = SGTL5000_DAC_POWERUP | SGTL5000_ADC_POWERUP;
> -
>   	switch (event) {
> -	case SND_SOC_DAPM_POST_PMU:
> -		snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
> -			SGTL5000_VAG_POWERUP, SGTL5000_VAG_POWERUP);
> -		msleep(400);
> +	case SND_SOC_DAPM_PRE_PMU:
> +		*mute_reg = mute_output(component, mute_mask);
> +		break;
> +	case SND_SOC_DAPM_POST_PMU:
> +		vag_power_on(component, event_source);
> +		restore_output(component, mute_mask, *mute_reg);
>   		break;
> -
>   	case SND_SOC_DAPM_PRE_PMD:
> -		/*
> -		 * Don't clear VAG_POWERUP, when both DAC and ADC are
> -		 * operational to prevent inadvertently starving the
> -		 * other one of them.
> -		 */
> -		if ((snd_soc_component_read32(component, SGTL5000_CHIP_ANA_POWER) &
> -				mask) != mask) {
> -			snd_soc_component_update_bits(component, SGTL5000_CHIP_ANA_POWER,
> -				SGTL5000_VAG_POWERUP, 0);
> -			msleep(400);
> -		}
> +		*mute_reg = mute_output(component, mute_mask);
> +		vag_power_off(component, event_source);
> +		break;
> +	case SND_SOC_DAPM_POST_PMD:
> +		restore_output(component, mute_mask, *mute_reg);
>   		break;
>   	default:
>   		break;
>   	}
> +}
> +
> +/*
> + * Mute Headphone when power it up/down.
> + * Control VAG power on HP power path.
> + */
> +static int headphone_pga_event(struct snd_soc_dapm_widget *w,
> +	struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_dapm_to_component(w->dapm);
> +	struct sgtl5000_priv *sgtl5000 =
> +		snd_soc_component_get_drvdata(component);
> +
> +	vag_and_mute_control(component, event, HP_POWER_EVENT,
> +			     SGTL5000_HP_MUTE,
> +			     &sgtl5000->mute_state.hp_event);
> +
> +	return 0;
> +}
> +
> +/* As manual describes, ADC/DAC powering up/down requires
> + * to mute outputs to avoid pops.
> + * Control VAG power on ADC/DAC power path.
> + */
> +static int adc_updown_depop(struct snd_soc_dapm_widget *w,
> +	struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_dapm_to_component(w->dapm);
> +	struct sgtl5000_priv *sgtl5000 =
> +		snd_soc_component_get_drvdata(component);
> +
> +	vag_and_mute_control(component, event, ADC_POWER_EVENT,
> +			     SGTL5000_OUTPUTS_MUTE,
> +			     &sgtl5000->mute_state.adc_event);
> +
> +	return 0;
> +}
> +
> +static int dac_updown_depop(struct snd_soc_dapm_widget *w,
> +	struct snd_kcontrol *kcontrol, int event)
> +{
> +	struct snd_soc_component *component =
> +		snd_soc_dapm_to_component(w->dapm);
> +	struct sgtl5000_priv *sgtl5000 =
> +		snd_soc_component_get_drvdata(component);
> +
> +	vag_and_mute_control(component, event, DAC_POWER_EVENT,
> +			     SGTL5000_OUTPUTS_MUTE,
> +			     &sgtl5000->mute_state.dac_event);
>   
>   	return 0;
>   }

With array approach you can simplify these 3 callbacks:
- remove local declaration of sgtl5000
- remove the need for "u16 *mute_reg" param for vag_and_mute_control
(you always provide the xxx_event field of mute_state corresponding to 
given XXX_POWER_EVENT anyway)

The sgtl5000 local ptr would be declared within common handler, which 
vag_and_mute_control clearly is. Said handler declaration could be 
updated to again require widget rather than component.

Cherry on top: relocation of "return 0;" directly to 
vag_and_mute_control. Leaving it void (as it is), however, might also be 
appropriate (explicit).

Czarek

  reply	other threads:[~2019-07-14 17:17 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-12 14:55 [PATCH v3 0/6] VAG power control improvement for sgtl5000 codec Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 1/6] ASoC: sgtl5000: Fix definition of VAG Ramp Control Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 2/6] ASoC: sgtl5000: add ADC mute control Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 3/6] ASoC: sgtl5000: Fix of unmute outputs on probe Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 4/6] ASoC: sgtl5000: Fix charge pump source assignment Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 5/6] ASoC: Define a set of DAPM pre/post-up events Oleksandr Suvorov
2019-07-12 14:56 ` [PATCH v3 6/6] ASoC: sgtl5000: Improve VAG power and mute control Oleksandr Suvorov
2019-07-14 17:17   ` Cezary Rojewski [this message]
2019-07-17 14:24     ` Oleksandr Suvorov
2019-07-15 19:06 ` [PATCH v3 0/6] VAG power control improvement for sgtl5000 codec Fabio Estevam
2019-07-17 16:34   ` Oleksandr Suvorov

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=e9f0f7c7-4c11-36ad-679c-503f6160b83f@intel.com \
    --to=cezary.rojewski@intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=festevam@gmail.com \
    --cc=igor.opaniuk@toradex.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel.ziswiler@toradex.com \
    --cc=oleksandr.suvorov@toradex.com \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.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

all inboxes | Powered by JetHome®