From: richard.genoud@gmail.com (Richard Genoud)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v6 1/8] ASoC: wm8731: add rates constraints
Date: Tue, 30 Jul 2013 12:32:02 +0200 [thread overview]
Message-ID: <1375180329-4860-2-git-send-email-richard.genoud@gmail.com> (raw)
In-Reply-To: <1375180329-4860-1-git-send-email-richard.genoud@gmail.com>
Depending on the mclk (or crystal) selected, the wm8731 codec have some
constraints on its data sampling rates:
e.g. with a 12.288MHz or 18.432MHz crystal, the authorized rates are
8KHz, 32KHz, 48KHz and 96KHz.
Signed-off-by: Richard Genoud <richard.genoud@gmail.com>
---
sound/soc/codecs/wm8731.c | 60 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 57 insertions(+), 3 deletions(-)
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 5276062..456bb8c 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -45,6 +45,7 @@ static const char *wm8731_supply_names[WM8731_NUM_SUPPLIES] = {
struct wm8731_priv {
struct regmap *regmap;
struct regulator_bulk_data supplies[WM8731_NUM_SUPPLIES];
+ const struct snd_pcm_hw_constraint_list *constraints;
unsigned int sysclk;
int sysclk_type;
int playback_fs;
@@ -290,6 +291,36 @@ static const struct _coeff_div coeff_div[] = {
{12000000, 88200, 136, 0xf, 0x1, 0x1},
};
+/* rates constraints */
+static const unsigned int wm8731_rates_12000000[] = {
+ 8000, 32000, 44100, 48000, 96000, 88200,
+};
+
+static const unsigned int wm8731_rates_12288000_18432000[] = {
+ 8000, 32000, 48000, 96000,
+};
+
+static const unsigned int wm8731_rates_11289600_16934400[] = {
+ 8000, 44100, 88200,
+};
+
+static const struct snd_pcm_hw_constraint_list wm8731_constraints_12000000 = {
+ .list = wm8731_rates_12000000,
+ .count = ARRAY_SIZE(wm8731_rates_12000000),
+};
+
+static const
+struct snd_pcm_hw_constraint_list wm8731_constraints_12288000_18432000 = {
+ .list = wm8731_rates_12288000_18432000,
+ .count = ARRAY_SIZE(wm8731_rates_12288000_18432000),
+};
+
+static const
+struct snd_pcm_hw_constraint_list wm8731_constraints_11289600_16934400 = {
+ .list = wm8731_rates_11289600_16934400,
+ .count = ARRAY_SIZE(wm8731_rates_11289600_16934400),
+};
+
static inline int get_coeff(int mclk, int rate)
{
int i;
@@ -362,17 +393,26 @@ static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
}
switch (freq) {
- case 11289600:
+ case 0:
+ wm8731->constraints = NULL;
+ break;
case 12000000:
+ wm8731->constraints = &wm8731_constraints_12000000;
+ break;
case 12288000:
- case 16934400:
case 18432000:
- wm8731->sysclk = freq;
+ wm8731->constraints = &wm8731_constraints_12288000_18432000;
+ break;
+ case 16934400:
+ case 11289600:
+ wm8731->constraints = &wm8731_constraints_11289600_16934400;
break;
default:
return -EINVAL;
}
+ wm8731->sysclk = freq;
+
snd_soc_dapm_sync(&codec->dapm);
return 0;
@@ -475,12 +515,26 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
return 0;
}
+static int wm8731_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct wm8731_priv *wm8731 = snd_soc_codec_get_drvdata(dai->codec);
+
+ if (wm8731->constraints)
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ wm8731->constraints);
+
+ return 0;
+}
+
#define WM8731_RATES SNDRV_PCM_RATE_8000_96000
#define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
SNDRV_PCM_FMTBIT_S24_LE)
static const struct snd_soc_dai_ops wm8731_dai_ops = {
+ .startup = wm8731_startup,
.hw_params = wm8731_hw_params,
.digital_mute = wm8731_mute,
.set_sysclk = wm8731_set_dai_sysclk,
--
1.7.10.4
next prev parent reply other threads:[~2013-07-30 10:32 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-30 10:32 [PATCH v6 0/8] Sound support for at91sam9x5-wm8731 based boards Richard Genoud
2013-07-30 10:32 ` Richard Genoud [this message]
2013-07-30 11:29 ` [PATCH v6 1/8] ASoC: wm8731: add rates constraints Mark Brown
2013-07-30 10:32 ` [PATCH v6 2/8] ASoC: atmel: machine driver for at91sam9x5-wm8731 boards Richard Genoud
2013-07-30 17:45 ` Stephen Warren
2013-07-30 20:45 ` Mark Brown
2013-07-30 21:29 ` Stephen Warren
2013-07-30 22:58 ` Mark Brown
2013-07-31 22:16 ` Stephen Warren
2013-08-01 9:53 ` Mark Brown
2013-08-06 17:11 ` Mark Brown
2013-08-07 8:20 ` Richard Genoud
2013-07-30 10:32 ` [PATCH v6 3/8] Documentation: DT: update atmel SSC with DMA binding Richard Genoud
2013-08-06 17:12 ` Mark Brown
2013-07-30 10:32 ` [PATCH v6 4/8] ARM: AT91: DTS: sam9x5: add SSC DMA parameters Richard Genoud
2013-07-30 10:32 ` [PATCH v6 5/8] ARM: AT91: DTS: sam9x5ek: add WM8731 codec Richard Genoud
2013-07-30 10:32 ` [PATCH v6 6/8] ARM: AT91: DTS: sam9x5ek: enable SSC Richard Genoud
2013-07-30 10:32 ` [PATCH v6 7/8] ARM: AT91: DTS: sam9x5ek: add sound configuration Richard Genoud
2013-07-30 10:32 ` [PATCH v6 8/8] ASoC: sam9x5: get codec MCLK via device tree Richard Genoud
2013-07-30 12:03 ` Mark Brown
2013-07-30 12:15 ` Richard Genoud
-- strict thread matches above, loose matches on Subject: below --
2013-07-30 9:59 [PATCH v6 0/8] Sound support for at91sam9x5-wm8731 based boards Richard Genoud
2013-07-30 9:59 ` [PATCH v6 1/8] ASoC: wm8731: add rates constraints Richard Genoud
2013-07-30 11:28 ` Mark Brown
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=1375180329-4860-2-git-send-email-richard.genoud@gmail.com \
--to=richard.genoud@gmail.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).