Skip to content

Commit d7508af

Browse files
Daniel Matuschekpopcornmix
authored andcommitted
ASoC: wm8804: Implement MCLK configuration options, add 32bit support WM8804 can run with PLL frequencies of 256xfs and 128xfs for most sample rates. At 192kHz only 128xfs is supported. The existing driver selects 128xfs automatically for some lower samples rates. By using an additional mclk_div divider, it is now possible to control the behaviour. This allows using 256xfs PLL frequency on all sample rates up to 96kHz. It should allow lower jitter and better signal quality. The behavior has to be controlled by the sound card driver, because some sample frequency share the same setting. e.g. 192kHz and 96kHz use 24.576MHz master clock. The only difference is the MCLK divider.
This also added support for 32bit data. Signed-off-by: Daniel Matuschek <daniel@matuschek.net>
1 parent be0d12e commit d7508af

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

‎sound/soc/codecs/wm8804.c‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct wm8804_priv {
6363
struct regmap *regmap;
6464
struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
6565
struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
66+
int mclk_div;
6667
};
6768

6869
static int txsrc_get(struct snd_kcontrol *kcontrol,
@@ -277,6 +278,7 @@ static int wm8804_hw_params(struct snd_pcm_substream *substream,
277278
blen = 0x1;
278279
break;
279280
case SNDRV_PCM_FORMAT_S24_LE:
281+
case SNDRV_PCM_FORMAT_S32_LE:
280282
blen = 0x2;
281283
break;
282284
default:
@@ -318,7 +320,7 @@ static struct {
318320

319321
#define FIXED_PLL_SIZE ((1ULL << 22) * 10)
320322
static int pll_factors(struct pll_div *pll_div, unsigned int target,
321-
unsigned int source)
323+
unsigned int source, unsigned int mclk_div)
322324
{
323325
u64 Kpart;
324326
unsigned long int K, Ndiv, Nmod, tmp;
@@ -330,7 +332,8 @@ static int pll_factors(struct pll_div *pll_div, unsigned int target,
330332
*/
331333
for (i = 0; i < ARRAY_SIZE(post_table); i++) {
332334
tmp = target * post_table[i].div;
333-
if (tmp >= 90000000 && tmp <= 100000000) {
335+
if ((tmp >= 90000000 && tmp <= 100000000) &&
336+
(mclk_div == post_table[i].mclkdiv)) {
334337
pll_div->freqmode = post_table[i].freqmode;
335338
pll_div->mclkdiv = post_table[i].mclkdiv;
336339
target *= post_table[i].div;
@@ -387,8 +390,11 @@ static int wm8804_set_pll(struct snd_soc_dai *dai, int pll_id,
387390
} else {
388391
int ret;
389392
struct pll_div pll_div;
393+
struct wm8804_priv *wm8804;
390394

391-
ret = pll_factors(&pll_div, freq_out, freq_in);
395+
wm8804 = snd_soc_codec_get_drvdata(codec);
396+
397+
ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
392398
if (ret)
393399
return ret;
394400

@@ -452,13 +458,18 @@ static int wm8804_set_clkdiv(struct snd_soc_dai *dai,
452458
int div_id, int div)
453459
{
454460
struct snd_soc_codec *codec;
461+
struct wm8804_priv *wm8804;
455462

456463
codec = dai->codec;
457464
switch (div_id) {
458465
case WM8804_CLKOUT_DIV:
459466
snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
460467
(div & 0x3) << 4);
461468
break;
469+
case WM8804_MCLK_DIV:
470+
wm8804 = snd_soc_codec_get_drvdata(codec);
471+
wm8804->mclk_div = div;
472+
break;
462473
default:
463474
dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
464475
return -EINVAL;
@@ -641,7 +652,7 @@ static const struct snd_soc_dai_ops wm8804_dai_ops = {
641652
};
642653

643654
#define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
644-
SNDRV_PCM_FMTBIT_S24_LE)
655+
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
645656

646657
#define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
647658
SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \

‎sound/soc/codecs/wm8804.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,9 @@
5757
#define WM8804_CLKOUT_SRC_OSCCLK 4
5858

5959
#define WM8804_CLKOUT_DIV 1
60+
#define WM8804_MCLK_DIV 2
61+
62+
#define WM8804_MCLKDIV_256FS 0
63+
#define WM8804_MCLKDIV_128FS 1
6064

6165
#endif /* _WM8804_H */

0 commit comments

Comments
 (0)