Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
To: Xavier Hsu <xavier.hsu@linaro.org>
Cc: Andy Green <andy.green@linaro.org>,
	alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	lars@metafoo.de, patches@linaro.org
Subject: Re: [PATCHv5 2/9] ASOC: wm8971: modify the control of deemphasis
Date: Wed, 29 Oct 2014 09:46:39 +0000	[thread overview]
Message-ID: <20141029094638.GH23178@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1414130435-14183-2-git-send-email-xavier.hsu@linaro.org>

On Fri, Oct 24, 2014 at 02:00:28PM +0800, Xavier Hsu wrote:
> We add a switch for automatic updating
> the frequency of wm8971.
> 
> Signed-off-by: Xavier Hsu <xavier.hsu@linaro.org>
> Signed-off-by: Andy Green <andy.green@linaro.org>
> ---
>  sound/soc/codecs/wm8971.c |   77 +++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 75 insertions(+), 2 deletions(-)
>  mode change 100644 => 100755 sound/soc/codecs/wm8971.c
> 
> diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
> old mode 100644
> new mode 100755
> index 01c76a4..6df0a3b
> --- a/sound/soc/codecs/wm8971.c
> +++ b/sound/soc/codecs/wm8971.c
> @@ -7,6 +7,10 @@
>   *
>   * Based on wm8753.c by Liam Girdwood
>   *
> + * WM8971 Improve Copyright (C) 2014 Linaro, Ltd
> + * Author: Xavier Hsu <xavier.hsu@linaro.org>
> + *         Andy Green <andy.green@linaro.org>
> + *
>   *  This program is free software; you can redistribute  it and/or modify it
>   *  under  the terms of  the GNU General  Public License as published by the
>   *  Free Software Foundation;  either version 2 of the  License, or (at your
> @@ -36,6 +40,11 @@ static struct workqueue_struct *wm8971_workq;
>  /* codec private data */
>  struct wm8971_priv {
>  	unsigned int sysclk;
> +
> +	/* De-emphasis */
> +	struct mutex deemph_mutex;
> +	int playback_fs;
> +	bool deemph;
>  };
>  
>  /*
> @@ -100,7 +109,6 @@ static const char const *wm8971_alc_func[] = {"Off", "Right",
>  					      "Left", "Stereo"};
>  static const char const *wm8971_ng_type[] = {"Constant PGA Gain",
>  					     "Mute ADC Output"};
> -static const char const *wm8971_deemp[] = {"None", "32kHz", "44.1kHz", "48kHz"};
>  static const char const *wm8971_mono_mux[] = {"Stereo", "Mono (Left)",
>  					      "Mono (Right)", "Digital Mono"};
>  static const char const *wm8971_dac_phase[] = {"Non Inverted", "Inverted"};
> @@ -114,6 +122,66 @@ static const char const *wm8971_rpga_sel[] = {"Line", "Mic", "NC",
>  					      "Differential"};
>  static const char const *wm8971_adcpol[] = {"Normal", "L Invert",
>  					    "R Invert", "L + R Invert"};
> +static const char const *wm8971_deemp[] = {"None", "32kHz",
> +					   "44.1kHz", "48kHz"};
> +
> +static int wm8971_set_deemph(struct snd_soc_codec *codec)
> +{
> +	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
> +	int val = 0, i, best = 0;
> +
> +	/* If we're using deemphasis select the nearest available sample
> +	 * rate.
> +	*/
> +	if (wm8971->deemph) {
> +		best = 1;
> +		for (i = 2; i < ARRAY_SIZE(wm8971_deemp); i++) {
> +			if (abs(wm8971_deemp[i] - wm8971->playback_fs) <
> +			    abs(wm8971_deemp[best] - wm8971->playback_fs))

I am not quite clear on how this is working, we seem to be
subtracting an int (playback_fs) from a char * (wm8971_deemp[i])?
Also playback_fs is never set anywhere in the driver so will
always be zero? Has this patch been tested?

> +				best = i;
> +		}
> +		val = best << 1;
> +	}
> +
> +	dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
> +		best, wm8971_deemp[best]);
> +
> +	return snd_soc_update_bits(codec, WM8971_ADCDAC, 0x6, val);
> +}
> +
> +static int wm8971_get_deemph(struct snd_kcontrol *kcontrol,
> +			     struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
> +	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
> +
> +	ucontrol->value.enumerated.item[0] = wm8971->deemph;
> +
> +	return 0;
> +}
> +
> +static int wm8971_put_deemph(struct snd_kcontrol *kcontrol,
> +			     struct snd_ctl_elem_value *ucontrol)
> +{
> +	struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol);
> +	struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
> +	int deemph = ucontrol->value.enumerated.item[0];
> +	int ret = 0;
> +
> +	if (deemph > 1)
> +		return -EINVAL;
> +
> +	mutex_lock(&wm8971->deemph_mutex);
> +	if (wm8971->deemph != deemph) {
> +		wm8971->deemph = deemph;
> +		wm8971_set_deemph(codec);
> +
> +		ret = 1;
> +	}
> +	mutex_unlock(&wm8971->deemph_mutex);
> +
> +	return ret;
> +}
>  
>  static const struct soc_enum wm8971_enum[] = {
>  	SOC_ENUM_SINGLE(WM8971_BASS, 7, 2, wm8971_bass),	/* 0 */
> @@ -184,7 +252,8 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = {
>  	SOC_SINGLE("Capture 6dB Attenuate", WM8971_ADCDAC, 8, 1, 0),
>  	SOC_SINGLE("Playback 6dB Attenuate", WM8971_ADCDAC, 7, 1, 0),
>  
> -	SOC_ENUM("Playback De-emphasis", wm8971_enum[5]),

You are removing the only user of wm8971_enum[5], probably should
remove that entry in the array as well. Ah I see you then remove
it in patch 2 perhaps reorder those two patches and explicitly
remove it in this patch, would be more clear.

> +	SOC_SINGLE_BOOL_EXT("Playback De-emphasis Switch", 0,
> +			    wm8971_get_deemph, wm8971_put_deemph),
>  	SOC_ENUM("Playback Function", wm8971_enum[6]),
>  	SOC_ENUM("Playback Phase", wm8971_enum[7]),
>  
> @@ -534,6 +603,8 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
>  		break;
>  	}
>  
> +	wm8971_set_deemph(codec);
> +
>  	/* set iface & srate */
>  	snd_soc_write(codec, WM8971_IFACE, iface);
>  	if (coeff >= 0)
> @@ -727,6 +798,8 @@ static int wm8971_i2c_probe(struct i2c_client *i2c,
>  	if (wm8971 == NULL)
>  		return -ENOMEM;
>  
> +	mutex_init(&wm8971->deemph_mutex);
> +
>  	regmap = devm_regmap_init_i2c(i2c, &wm8971_regmap);
>  	if (IS_ERR(regmap))
>  		return PTR_ERR(regmap);
> -- 
> 1.7.9.5
> 

Also I tried to apply this against the current ASoC for next and
it fails to apply. Is this generated against the right tree?

Thanks,
Charles

  reply	other threads:[~2014-10-29  9:46 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-24  6:00 [PATCHv5 1/9] ASOC: wm8971: clean for checkpatch --strict Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 2/9] ASOC: wm8971: modify the control of deemphasis Xavier Hsu
2014-10-29  9:46   ` Charles Keepax [this message]
2014-10-30  3:02     ` Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 3/9] ASOC: wm8971: use SOC_ENUM_SINGLE_DECL to replace SOC_ENUM_SINGLE Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 4/9] ASOC: wm8971: add TLV information Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 5/9] ASOC: wm8971: improve the function of wm8971_set_dai_fmt() Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 6/9] ASOC: wm8971: add constraint for setting set_sysclk() Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 7/9] ASOC: wm8971: use msleep to replace work queue Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 8/9] ASOC: wm8971: use regcache_sync to replace snd_soc_cache_sync Xavier Hsu
2014-10-24  6:00 ` [PATCHv5 9/9] ASOC: wm8971: add WM8973 support to WM8971 Xavier Hsu

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=20141029094638.GH23178@opensource.wolfsonmicro.com \
    --to=ckeepax@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andy.green@linaro.org \
    --cc=lars@metafoo.de \
    --cc=patches@linaro.org \
    --cc=patches@opensource.wolfsonmicro.com \
    --cc=xavier.hsu@linaro.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