Advertisement
Guest User

Untitled

a guest
Mar 15th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.05 KB | None | 0 0
  1. From a58ff934aa92585cbd1516b02ecf728a1804f6f9 Mon Sep 17 00:00:00 2001
  2. From: Daniel Baluta <daniel.baluta@nxp.com>
  3. Date: Mon, 13 Mar 2017 19:49:01 +0200
  4. Subject: [PATCH 2/2] MLK-14277: ASoC: codec: wm8960: Relax bit clock
  5.  computation
  6.  
  7. WM8960 derives bit clock from sysclock using BCLKDIV[3:0] of R8
  8. clocking register (See WM8960 datasheet, page 71).
  9.  
  10. There are use cases, like this:
  11. aplay -Dhw:0,0 -r 48000 -c 1 -f S20_3LE -t raw audio48k20b_3LE1c.pcm
  12.  
  13. where no BCLKDIV applied to sysclock can give us the exact requested
  14. bitclk, so driver fails to configure clocking and aplay fails to run.
  15.  
  16. Fix this by relaxing bitclk computation, so that when no exact value
  17. can be derived from sysclk pick the closest value greater than
  18. expected bitclk.
  19.  
  20. Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
  21. ---
  22.  sound/soc/codecs/wm8960.c | 39 +++++++++++++++++++++++++++++++++------
  23.  1 file changed, 33 insertions(+), 6 deletions(-)
  24.  
  25. diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c
  26. index c01f3de..fa88935 100644
  27. --- a/sound/soc/codecs/wm8960.c
  28. +++ b/sound/soc/codecs/wm8960.c
  29. @@ -611,6 +611,10 @@ static const int bclk_divs[] = {
  30.   *     - lrclk      = sysclk / dac_divs
  31.   *     - 10 * bclk  = sysclk / bclk_divs
  32.   *
  33. + * If we cannot find an exact match for (sysclk, lrclk, bclk)
  34. + * triplet, we relax the bclk such that bclk is chosen as the
  35. + * closest available frequency greater than expected bclk.
  36. + *
  37.   * @wm8960_priv: wm8960 codec private data
  38.   * @mclk: MCLK used to derive sysclk
  39.   * @_i: sysclk_divs index for found sysclk
  40. @@ -620,14 +624,14 @@ static const int bclk_divs[] = {
  41.   * Returns:
  42.   * -1, in case no sysclk frequency available found
  43.   *  0, in case an exact match is found. See @_i, @_j, @_k
  44. - *
  45. + * >0, in case a relaxed match is found. See @_i, @_j, @_k
  46.   */
  47.  int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
  48.               int *_i, int *_j, int *_k)
  49.  {
  50.     int sysclk, bclk, lrclk;
  51.     int i, j, k;
  52. -   int diff;
  53. +   int diff, closest = mclk;
  54.  
  55.     bclk = wm8960->bclk;
  56.     lrclk = wm8960->lrclk;
  57. @@ -648,6 +652,12 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
  58.                     *_k = k;
  59.                     break;
  60.                 }
  61. +               if (diff > 0 && closest > diff) {
  62. +                   *_i = i;
  63. +                   *_j = j;
  64. +                   *_k = k;
  65. +                   closest = diff;
  66. +               }
  67.             }
  68.             if (k != ARRAY_SIZE(bclk_divs))
  69.                 break;
  70. @@ -656,10 +666,16 @@ int wm8960_configure_sysclk(struct wm8960_priv *wm8960, int mclk,
  71.             break;
  72.     }
  73.  
  74. +   /* exact match */
  75.     if (i != ARRAY_SIZE(sysclk_divs))
  76.         return 0;
  77.  
  78. -   return -1;
  79. +   /* no match */
  80. +   if (closest == mclk)
  81. +       return -1;
  82. +
  83. +   /* relaxed match */
  84. +   return 1;
  85.  }
  86.  
  87.  static int wm8960_configure_clocking(struct snd_soc_codec *codec)
  88. @@ -668,6 +684,7 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
  89.     int sysclk, bclk, lrclk, freq_out, freq_in;
  90.     u16 iface1 = snd_soc_read(codec, WM8960_IFACE1);
  91.     int i, j, k;
  92. +   int best_sysclk_div, best_dac_div, best_bclk_div = -1;
  93.     int ret;
  94.  
  95.     if (!(iface1 & (1<<6))) {
  96. @@ -705,10 +722,14 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
  97.         ret = wm8960_configure_sysclk(wm8960, freq_out, &i, &j, &k);
  98.         if (ret == 0)
  99.             goto configure_clock;
  100. -       else if (wm8960->clk_id != WM8960_SYSCLK_AUTO) {
  101. +       else if (ret < 0 && wm8960->clk_id != WM8960_SYSCLK_AUTO) {
  102.             dev_err(codec->dev, "failed to configure clock\n");
  103.             return -EINVAL;
  104.         }
  105. +       /* there is still hope, keep this if no PLL out available */
  106. +       best_sysclk_div = i;
  107. +       best_dac_div    = j;
  108. +       best_bclk_div   = k;
  109.     }
  110.     /* get a available pll out frequency and set pll */
  111.     for (i = 0; i < ARRAY_SIZE(sysclk_divs); ++i) {
  112. @@ -736,8 +757,14 @@ static int wm8960_configure_clocking(struct snd_soc_codec *codec)
  113.     }
  114.  
  115.     if (i == ARRAY_SIZE(sysclk_divs)) {
  116. -       dev_err(codec->dev, "failed to configure clock\n");
  117. -       return -EINVAL;
  118. +       if (best_bclk_div != -1) {
  119. +           i = best_sysclk_div;
  120. +           j = best_dac_div;
  121. +           k = best_bclk_div;
  122. +       } else {
  123. +           dev_err(codec->dev, "failed to configure clock\n");
  124. +           return -EINVAL;
  125. +       }
  126.     }
  127.  
  128.  configure_clock:
  129. --
  130. 2.7.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement