950-0064-ASoC-pcm512x-implement-set_tdm_slot-interface.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From 5fd7bb26ef791a7da1c0573b980ab4fe6b9c2641 Mon Sep 17 00:00:00 2001
  2. From: Matthias Reichl <[email protected]>
  3. Date: Thu, 22 Feb 2018 11:55:06 +0100
  4. Subject: [PATCH] ASoC: pcm512x: implement set_tdm_slot interface
  5. PCM512x can accept data padded with additional BCLK cycles
  6. but the driver currently lacks an interface to configure this.
  7. This leads to the problem that S24_LE format in master mode
  8. can result in non-integer clock divisors and pcm512x running
  9. at a rather off rate.
  10. For example 48kHz with 48fs BCLK and SCLK at 24.576MHz uses
  11. a divisor of 10 (rounded down from 10.6666) and results in a
  12. 51.2kHz LRCLK. With 64fs BCLK a divisor of 8 is used and
  13. LRCLK runs at exactly 48kHz.
  14. Fix this by providing a minimal set_tdm_slot implementation
  15. so machine drivers can optionally configure custom BCLK ratios.
  16. Signed-off-by: Matthias Reichl <[email protected]>
  17. ---
  18. sound/soc/codecs/pcm512x.c | 28 +++++++++++++++++++++++++++-
  19. 1 file changed, 27 insertions(+), 1 deletion(-)
  20. --- a/sound/soc/codecs/pcm512x.c
  21. +++ b/sound/soc/codecs/pcm512x.c
  22. @@ -53,6 +53,7 @@ struct pcm512x_priv {
  23. unsigned long overclock_pll;
  24. unsigned long overclock_dac;
  25. unsigned long overclock_dsp;
  26. + int lrclk_div;
  27. };
  28. /*
  29. @@ -851,7 +852,10 @@ static int pcm512x_set_dividers(struct s
  30. int fssp;
  31. int gpio;
  32. - lrclk_div = snd_soc_params_to_frame_size(params);
  33. + if (pcm512x->lrclk_div)
  34. + lrclk_div = pcm512x->lrclk_div;
  35. + else
  36. + lrclk_div = snd_soc_params_to_frame_size(params);
  37. if (lrclk_div == 0) {
  38. dev_err(dev, "No LRCLK?\n");
  39. return -EINVAL;
  40. @@ -1319,10 +1323,32 @@ static int pcm512x_set_fmt(struct snd_so
  41. return 0;
  42. }
  43. +static int pcm512x_set_tdm_slot(struct snd_soc_dai *dai,
  44. + unsigned int tx_mask, unsigned int rx_mask,
  45. + int slots, int width)
  46. +{
  47. + struct snd_soc_component *component = dai->component;
  48. + struct pcm512x_priv *pcm512x = snd_soc_component_get_drvdata(component);
  49. +
  50. + switch (slots) {
  51. + case 0:
  52. + pcm512x->lrclk_div = 0;
  53. + return 0;
  54. + case 2:
  55. + if (tx_mask != 0x03 || rx_mask != 0x03)
  56. + return -EINVAL;
  57. + pcm512x->lrclk_div = slots * width;
  58. + return 0;
  59. + default:
  60. + return -EINVAL;
  61. + }
  62. +}
  63. +
  64. static const struct snd_soc_dai_ops pcm512x_dai_ops = {
  65. .startup = pcm512x_dai_startup,
  66. .hw_params = pcm512x_hw_params,
  67. .set_fmt = pcm512x_set_fmt,
  68. + .set_tdm_slot = pcm512x_set_tdm_slot,
  69. };
  70. static struct snd_soc_dai_driver pcm512x_dai = {