b1e1e7bb988c3f743351a32dbe2267d84270ce8d
[openwrt/openwrt.git] / target / linux / brcm2708 / patches-3.14 / 0043-ASoC-wm8804-Implement-MCLK-configuration-options-add.patch
1 From 0b1d46fef20d096cc3991df89ec793a10df0eaf2 Mon Sep 17 00:00:00 2001
2 From: Daniel Matuschek <info@crazy-audio.com>
3 Date: Wed, 15 Jan 2014 21:41:23 +0100
4 Subject: [PATCH 43/54] ASoC: wm8804: Implement MCLK configuration options, add
5 32bit support WM8804 can run with PLL frequencies of 256xfs and 128xfs for
6 most sample rates. At 192kHz only 128xfs is supported. The existing driver
7 selects 128xfs automatically for some lower samples rates. By using an
8 additional mclk_div divider, it is now possible to control the behaviour.
9 This allows using 256xfs PLL frequency on all sample rates up to 96kHz. It
10 should allow lower jitter and better signal quality. The behavior has to be
11 controlled by the sound card driver, because some sample frequency share the
12 same setting. e.g. 192kHz and 96kHz use 24.576MHz master clock. The only
13 difference is the MCLK divider.
14
15 This also added support for 32bit data.
16
17 Signed-off-by: Daniel Matuschek <daniel@matuschek.net>
18 ---
19 sound/soc/codecs/wm8804.c | 19 +++++++++++++++----
20 sound/soc/codecs/wm8804.h | 4 ++++
21 2 files changed, 19 insertions(+), 4 deletions(-)
22
23 diff --git a/sound/soc/codecs/wm8804.c b/sound/soc/codecs/wm8804.c
24 index 9bc8206..c35b4f3 100644
25 --- a/sound/soc/codecs/wm8804.c
26 +++ b/sound/soc/codecs/wm8804.c
27 @@ -63,6 +63,7 @@ struct wm8804_priv {
28 struct regmap *regmap;
29 struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
30 struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
31 + int mclk_div;
32 };
33
34 static int txsrc_get(struct snd_kcontrol *kcontrol,
35 @@ -277,6 +278,7 @@ static int wm8804_hw_params(struct snd_pcm_substream *substream,
36 blen = 0x1;
37 break;
38 case SNDRV_PCM_FORMAT_S24_LE:
39 + case SNDRV_PCM_FORMAT_S32_LE:
40 blen = 0x2;
41 break;
42 default:
43 @@ -318,7 +320,7 @@ static struct {
44
45 #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
46 static int pll_factors(struct pll_div *pll_div, unsigned int target,
47 - unsigned int source)
48 + unsigned int source, unsigned int mclk_div)
49 {
50 u64 Kpart;
51 unsigned long int K, Ndiv, Nmod, tmp;
52 @@ -330,7 +332,8 @@ static int pll_factors(struct pll_div *pll_div, unsigned int target,
53 */
54 for (i = 0; i < ARRAY_SIZE(post_table); i++) {
55 tmp = target * post_table[i].div;
56 - if (tmp >= 90000000 && tmp <= 100000000) {
57 + if ((tmp >= 90000000 && tmp <= 100000000) &&
58 + (mclk_div == post_table[i].mclkdiv)) {
59 pll_div->freqmode = post_table[i].freqmode;
60 pll_div->mclkdiv = post_table[i].mclkdiv;
61 target *= post_table[i].div;
62 @@ -387,8 +390,11 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id,
63 } else {
64 int ret;
65 struct pll_div pll_div;
66 + struct wm8804_priv *wm8804;
67
68 - ret = pll_factors(&pll_div, freq_out, freq_in);
69 + wm8804 = snd_soc_codec_get_drvdata(codec);
70 +
71 + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
72 if (ret)
73 return ret;
74
75 @@ -452,6 +458,7 @@ static int wm8804_set_clkdiv(struct snd_soc_dai *dai,
76 int div_id, int div)
77 {
78 struct snd_soc_codec *codec;
79 + struct wm8804_priv *wm8804;
80
81 codec = dai->codec;
82 switch (div_id) {
83 @@ -459,6 +466,10 @@ static int wm8804_set_clkdiv(struct snd_soc_dai *dai,
84 snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
85 (div & 0x3) << 4);
86 break;
87 + case WM8804_MCLK_DIV:
88 + wm8804 = snd_soc_codec_get_drvdata(codec);
89 + wm8804->mclk_div = div;
90 + break;
91 default:
92 dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
93 return -EINVAL;
94 @@ -641,7 +652,7 @@ static const struct snd_soc_dai_ops wm8804_dai_ops = {
95 };
96
97 #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
98 - SNDRV_PCM_FMTBIT_S24_LE)
99 + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
100
101 #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
102 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
103 diff --git a/sound/soc/codecs/wm8804.h b/sound/soc/codecs/wm8804.h
104 index 8ec14f5..e72d4f4 100644
105 --- a/sound/soc/codecs/wm8804.h
106 +++ b/sound/soc/codecs/wm8804.h
107 @@ -57,5 +57,9 @@
108 #define WM8804_CLKOUT_SRC_OSCCLK 4
109
110 #define WM8804_CLKOUT_DIV 1
111 +#define WM8804_MCLK_DIV 2
112 +
113 +#define WM8804_MCLKDIV_256FS 0
114 +#define WM8804_MCLKDIV_128FS 1
115
116 #endif /* _WM8804_H */
117 --
118 1.9.1
119