From: Xavier Hsu <xavier.hsu@linaro.org>
To: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
patches@linaro.org
Cc: Xavier Hsu <xavier.hsu@linaro.org>,
ckeepax@opensource.wolfsonmicro.com, lars@metafoo.de,
Andy Green <andy.green@linaro.org>
Subject: [PATCHv4 6/9] Using the constraint based on wm8971_set_dai_sysclk
Date: Wed, 17 Sep 2014 16:41:12 +0800 [thread overview]
Message-ID: <1410943275-4160-6-git-send-email-xavier.hsu@linaro.org> (raw)
In-Reply-To: <1410943275-4160-1-git-send-email-xavier.hsu@linaro.org>
This patch improves WM8971.
We use the constraint based on the function of
wm8971_set_dai_sysclk().
Signed-off-by: Xavier Hsu <xavier.hsu@linaro.org>
Signed-off-by: Andy Green <andy.green@linaro.org>
---
Any comments about improving the patch are welcome.
Thanks.
sound/soc/codecs/wm8971.c | 80 +++++++++++++++++++++++++++++++++++++++++----
1 file changed, 74 insertions(+), 6 deletions(-)
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index 7021f77..5b38c7a 100755
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -40,7 +40,9 @@ static struct workqueue_struct *wm8971_workq;
/* codec private data */
struct wm8971_priv {
+ /* MCLK */
unsigned int sysclk;
+ struct snd_pcm_hw_constraint_list *sysclk_constraints;
/* De-emphasis */
struct mutex deemph_mutex;
@@ -530,6 +532,35 @@ static int get_coeff(int mclk, int rate)
return -EINVAL;
}
+/* The set of rates we can generate from the above for each SYSCLK */
+static const unsigned int rates_48000[] = {
+ 8000, 12000, 16000, 24000, 32000, 48000, 96000
+};
+
+static struct snd_pcm_hw_constraint_list constraints_48000 = {
+ .count = ARRAY_SIZE(rates_48000),
+ .list = rates_48000,
+};
+
+static const unsigned int rates_44100[] = {
+ 8000, 11025, 22050, 44100, 88200
+};
+
+static struct snd_pcm_hw_constraint_list constraints_44100 = {
+ .count = ARRAY_SIZE(rates_44100),
+ .list = rates_44100,
+};
+
+static const unsigned int rates_12[] = {
+ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 41100, 48000,
+ 88235, 96000,
+};
+
+static struct snd_pcm_hw_constraint_list constraints_12 = {
+ .count = ARRAY_SIZE(rates_12),
+ .list = rates_12,
+};
+
static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai,
int clk_id, unsigned int freq, int dir)
{
@@ -537,15 +568,29 @@ static int wm8971_set_dai_sysclk(struct snd_soc_dai *codec_dai,
struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
switch (freq) {
- case 11289600:
- case 12000000:
case 12288000:
- case 16934400:
+ case 24576000:
case 18432000:
- wm8971->sysclk = freq;
- return 0;
+ case 36864000:
+ wm8971->sysclk_constraints = &constraints_48000;
+ break;
+ case 11289600:
+ case 22579200:
+ case 16934400:
+ case 33868800:
+ wm8971->sysclk_constraints = &constraints_44100;
+ break;
+ case 12000000:
+ case 24000000:
+ wm8971->sysclk_constraints = &constraints_12;
+ break;
+ default:
+ return -EINVAL;
}
- return -EINVAL;
+
+ wm8971->sysclk = freq;
+
+ return 0;
}
static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai,
@@ -604,6 +649,28 @@ static int wm8971_set_dai_fmt(struct snd_soc_dai *codec_dai,
return 0;
}
+static int wm8971_pcm_startup(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *dai)
+{
+ struct snd_soc_codec *codec = dai->codec;
+ struct wm8971_priv *wm8971 = snd_soc_codec_get_drvdata(codec);
+
+ /* The set of sample rates that can be supported depends on the
+ * MCLK supplied to the CODEC - enforce this.
+ */
+ if (!wm8971->sysclk) {
+ dev_err(codec->dev,
+ "No MCLK configured, call set_sysclk() on init\n");
+ return -EINVAL;
+ }
+
+ snd_pcm_hw_constraint_list(substream->runtime, 0,
+ SNDRV_PCM_HW_PARAM_RATE,
+ wm8971->sysclk_constraints);
+
+ return 0;
+}
+
static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
@@ -688,6 +755,7 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
SNDRV_PCM_FMTBIT_S24_LE)
static const struct snd_soc_dai_ops wm8971_dai_ops = {
+ .startup = wm8971_pcm_startup,
.hw_params = wm8971_pcm_hw_params,
.digital_mute = wm8971_mute,
.set_fmt = wm8971_set_dai_fmt,
--
1.7.9.5
next prev parent reply other threads:[~2014-09-17 8:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-17 8:41 [PATCHv4 1/9] Clean WM8971 through checkpatch Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 2/9] WM8971 modifies the control of deemphasis Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 3/9] WM8971 uses SOC_ENUM_SINGLE_DECL to replace SOC_ENUM_SINGLE Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 4/9] WM8971 uses TLV information Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 5/9] Improve wm8971_set_dai_fmt Xavier Hsu
2014-09-17 8:41 ` Xavier Hsu [this message]
2014-09-17 8:41 ` [PATCHv4 7/9] WM8971 uses msleep to replace work queue Xavier Hsu
2014-09-22 12:16 ` Charles Keepax
2014-09-24 7:37 ` Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 8/9] WM8971 uses regcache_sync to replace snd_soc_cache_sync Xavier Hsu
2014-09-17 8:41 ` [PATCHv4 9/9] ASOC add WM8973 support to WM8971 Xavier Hsu
2014-09-22 12:34 ` Charles Keepax
2014-09-22 12:35 ` [PATCHv4 1/9] Clean WM8971 through checkpatch Charles Keepax
2014-09-23 6:54 ` 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=1410943275-4160-6-git-send-email-xavier.hsu@linaro.org \
--to=xavier.hsu@linaro.org \
--cc=alsa-devel@alsa-project.org \
--cc=andy.green@linaro.org \
--cc=ckeepax@opensource.wolfsonmicro.com \
--cc=lars@metafoo.de \
--cc=patches@linaro.org \
--cc=patches@opensource.wolfsonmicro.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;
as well as URLs for NNTP newsgroup(s).