diff mbox

[PATCHv6,3/9] ASOC: wm8971: modify the control of deemphasis

Message ID 1417416721-17271-3-git-send-email-xavier.hsu@linaro.org
State New
Headers show

Commit Message

Xavier Hsu Dec. 1, 2014, 6:51 a.m. UTC
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 |   75 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 72 insertions(+), 3 deletions(-)
 mode change 100644 => 100755 sound/soc/codecs/wm8971.c

Comments

Xavier Hsu Dec. 2, 2014, 7:54 a.m. UTC | #1
Hi Richard and Charles :
Thanks for your feedback.
Sorry for waste your time to help us for checking our patches because I
make a mistake.
We have a platform that contain wm8973 audio codec.
I need to apply all patches and then I can test our patches.
After testing our patches, I go back to PATCHv6 3/9 and modify our program.
But I forgot to modify some code......
(static const char const *wm8971_deemp[] = {"None", "32kHz", "44.1kHz",
"48kHz"};
=> static const int wm8971_deemp[] = {0, 32000, 44100, 48000};)

I am very sorry....
Please forgive my carelessness...

We will check all our patches and then release them.
If you have any other suggestions, please let me know, thanks.
Sorry again.

BR,
Xavier

2014-12-01 18:04 GMT+08:00 Richard Fitzgerald <
rf@opensource.wolfsonmicro.com>:

> On Mon, Dec 01, 2014 at 02:51:55PM +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 |   75
> +++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 72 insertions(+), 3 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 60c90c6..b5cb636
> > --- a/sound/soc/codecs/wm8971.c
> > +++ b/sound/soc/codecs/wm8971.c
> > @@ -40,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;
> >  };
> >
> >  /*
> > @@ -104,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"};
> > @@ -118,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"};
>
> This is the same as the original version of the array that you've deleted.
> I'm guess from the code below that you intended to change this to an
> array of integers, messed up, and didn't bother to test that your patch
> compiled before posting it up here.
>
> > +
> > +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))
>
> wm8971_deemp[i] is a string and then you try to subtract a value from it.
> I wouldn't expect that to even compile (at least not without warnings), and
> if it does compile I can't imagine what the result would be and I doubt it
> is what you wanted.
> I'm not even sure what you were trying to do here.
>
> > +                             best = i;
> > +             }
> > +             val = best << 1;
> > +     }
> > +
> > +     dev_dbg(codec->dev, "Set deemphasis %d (%dHz)\n",
> > +             best, wm8971_deemp[best]);
> > +
>
> wm_8971_deemp[best] is a string
>
>
>
diff mbox

Patch

diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
old mode 100644
new mode 100755
index 60c90c6..b5cb636
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -40,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;
 };
 
 /*
@@ -104,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"};
@@ -118,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))
+				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 SOC_ENUM_SINGLE_DECL(bass_boost, WM8971_BASS, 7, wm8971_bass);
 static const SOC_ENUM_SINGLE_DECL(bass_filter, WM8971_BASS,
@@ -142,7 +206,6 @@  static const SOC_ENUM_SINGLE_DECL(right_pga, WM8971_RADCIN,
 static const SOC_ENUM_SINGLE_DECL(capture_polarity, WM8971_ADCDAC,
 				  5, wm8971_adcpol);
 static const SOC_ENUM_SINGLE_DECL(monomux, WM8971_ADCIN, 6, wm8971_mono_mux);
-static const SOC_ENUM_SINGLE_DECL(deemp, WM8971_ADCDAC, 1, wm8971_deemp);
 
 static const struct snd_kcontrol_new wm8971_snd_controls[] = {
 	SOC_DOUBLE_R("Capture Volume", WM8971_LINVOL, WM8971_RINVOL, 0, 63, 0),
@@ -196,7 +259,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", deemp),
+	SOC_SINGLE_BOOL_EXT("Playback De-emphasis Switch", 0,
+			    wm8971_get_deemph, wm8971_put_deemph),
 	SOC_ENUM("Playback Function", dac_mono_mix),
 	SOC_ENUM("Playback Phase", dac_phase_inv),
 
@@ -546,6 +610,9 @@  static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
 		break;
 	}
 
+	wm8971->playback_fs = params_rate(params);
+	wm8971_set_deemph(codec);
+
 	/* set iface & srate */
 	snd_soc_write(codec, WM8971_IFACE, iface);
 	if (coeff >= 0)
@@ -739,6 +806,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);