brcm2708: update against latest rpi-3.10.y branch
[openwrt/svn-archive/archive.git] / target / linux / brcm2708 / patches-3.10 / 0156-ASoC-wm8804-Implement-MCLK-configuration-options-add.patch
1 From 01aa1e11984ac4cd798308cd7a40c92fc4be214e 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 156/174] ASoC: wm8804: Implement MCLK configuration options,
5 add 32bit support WM8804 can run with PLL frequencies of 256xfs and 128xfs
6 for most sample rates. At 192kHz only 128xfs is supported. The existing
7 driver 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 --- a/sound/soc/codecs/wm8804.c
24 +++ b/sound/soc/codecs/wm8804.c
25 @@ -63,6 +63,7 @@ struct wm8804_priv {
26 struct regmap *regmap;
27 struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
28 struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
29 + int mclk_div;
30 };
31
32 static int txsrc_get(struct snd_kcontrol *kcontrol,
33 @@ -277,6 +278,7 @@ static int wm8804_hw_params(struct snd_p
34 blen = 0x1;
35 break;
36 case SNDRV_PCM_FORMAT_S24_LE:
37 + case SNDRV_PCM_FORMAT_S32_LE:
38 blen = 0x2;
39 break;
40 default:
41 @@ -318,7 +320,7 @@ static struct {
42
43 #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
44 static int pll_factors(struct pll_div *pll_div, unsigned int target,
45 - unsigned int source)
46 + unsigned int source, unsigned int mclk_div)
47 {
48 u64 Kpart;
49 unsigned long int K, Ndiv, Nmod, tmp;
50 @@ -330,7 +332,8 @@ static int pll_factors(struct pll_div *p
51 */
52 for (i = 0; i < ARRAY_SIZE(post_table); i++) {
53 tmp = target * post_table[i].div;
54 - if (tmp >= 90000000 && tmp <= 100000000) {
55 + if ((tmp >= 90000000 && tmp <= 100000000) &&
56 + (mclk_div == post_table[i].mclkdiv)) {
57 pll_div->freqmode = post_table[i].freqmode;
58 pll_div->mclkdiv = post_table[i].mclkdiv;
59 target *= post_table[i].div;
60 @@ -387,8 +390,11 @@ static int wm8804_set_pll(struct snd_soc
61 } else {
62 int ret;
63 struct pll_div pll_div;
64 + struct wm8804_priv *wm8804;
65
66 - ret = pll_factors(&pll_div, freq_out, freq_in);
67 + wm8804 = snd_soc_codec_get_drvdata(codec);
68 +
69 + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
70 if (ret)
71 return ret;
72
73 @@ -452,6 +458,7 @@ static int wm8804_set_clkdiv(struct snd_
74 int div_id, int div)
75 {
76 struct snd_soc_codec *codec;
77 + struct wm8804_priv *wm8804;
78
79 codec = dai->codec;
80 switch (div_id) {
81 @@ -459,6 +466,10 @@ static int wm8804_set_clkdiv(struct snd_
82 snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
83 (div & 0x3) << 4);
84 break;
85 + case WM8804_MCLK_DIV:
86 + wm8804 = snd_soc_codec_get_drvdata(codec);
87 + wm8804->mclk_div = div;
88 + break;
89 default:
90 dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
91 return -EINVAL;
92 @@ -641,7 +652,7 @@ static const struct snd_soc_dai_ops wm88
93 };
94
95 #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
96 - SNDRV_PCM_FMTBIT_S24_LE)
97 + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
98
99 #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
100 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
101 --- a/sound/soc/codecs/wm8804.h
102 +++ b/sound/soc/codecs/wm8804.h
103 @@ -57,5 +57,9 @@
104 #define WM8804_CLKOUT_SRC_OSCCLK 4
105
106 #define WM8804_CLKOUT_DIV 1
107 +#define WM8804_MCLK_DIV 2
108 +
109 +#define WM8804_MCLKDIV_256FS 0
110 +#define WM8804_MCLKDIV_128FS 1
111
112 #endif /* _WM8804_H */