PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/recipes/linux/linux-omap3-psp/omap3evm/2.1.2.9/0412-ASoC-Provide-core-support-for-symmetric-sample-rate.patch

https://bitbucket.org/flozzone/my-arago-da830
Patch | 118 lines | 108 code | 10 blank | 0 comment | 0 complexity | 18c1bacd4b91a3be43837c6620c4b94a MD5 | raw file
  1. From 1218a7108d6d6aa729dc60d9539d42d710ccbd59 Mon Sep 17 00:00:00 2001
  2. From: Mark Brown <broonie@opensource.wolfsonmicro.com>
  3. Date: Tue, 7 Apr 2009 18:10:13 +0100
  4. Subject: [PATCH 412/426] ASoC: Provide core support for symmetric sample rates
  5. Many devices require symmetric configurations of capture and playback
  6. data formats, often due to shared clocking but sometimes also due to
  7. other shared playback and record configuration in the device. Start
  8. providing core support for this by allowing the DAIs or the machine
  9. to specify that the sample rates used should be kept symmetric.
  10. A flag symmetric_rates is provided in the snd_soc_dai and
  11. snd_soc_dai_link structures. If this is set in either of the DAIs or in
  12. the machine then a constraint will be applied when a stream is already
  13. open preventing any changes in sample rate.
  14. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  15. ---
  16. include/sound/soc-dai.h | 1 +
  17. include/sound/soc.h | 6 ++++++
  18. sound/soc/soc-core.c | 38 ++++++++++++++++++++++++++++++++++++++
  19. 3 files changed, 45 insertions(+), 0 deletions(-)
  20. diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
  21. index 1367647..22b729f 100644
  22. --- a/include/sound/soc-dai.h
  23. +++ b/include/sound/soc-dai.h
  24. @@ -208,6 +208,7 @@ struct snd_soc_dai {
  25. /* DAI capabilities */
  26. struct snd_soc_pcm_stream capture;
  27. struct snd_soc_pcm_stream playback;
  28. + unsigned int symmetric_rates:1;
  29. /* DAI runtime info */
  30. struct snd_pcm_runtime *runtime;
  31. diff --git a/include/sound/soc.h b/include/sound/soc.h
  32. index 4b41df6..6e27c0a 100644
  33. --- a/include/sound/soc.h
  34. +++ b/include/sound/soc.h
  35. @@ -420,6 +420,12 @@ struct snd_soc_dai_link {
  36. /* codec/machine specific init - e.g. add machine controls */
  37. int (*init)(struct snd_soc_codec *codec);
  38. + /* Symmetry requirements */
  39. + unsigned int symmetric_rates:1;
  40. +
  41. + /* Symmetry data - only valid if symmetry is being enforced */
  42. + unsigned int rate;
  43. +
  44. /* DAI pcm */
  45. struct snd_pcm *pcm;
  46. };
  47. diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
  48. index 28a06f5..2a3adaf 100644
  49. --- a/sound/soc/soc-core.c
  50. +++ b/sound/soc/soc-core.c
  51. @@ -113,6 +113,35 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
  52. }
  53. #endif
  54. +static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
  55. +{
  56. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  57. + struct snd_soc_device *socdev = rtd->socdev;
  58. + struct snd_soc_card *card = socdev->card;
  59. + struct snd_soc_dai_link *machine = rtd->dai;
  60. + struct snd_soc_dai *cpu_dai = machine->cpu_dai;
  61. + struct snd_soc_dai *codec_dai = machine->codec_dai;
  62. + int ret;
  63. +
  64. + if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
  65. + machine->symmetric_rates) {
  66. + dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
  67. + machine->rate);
  68. +
  69. + ret = snd_pcm_hw_constraint_minmax(substream->runtime,
  70. + SNDRV_PCM_HW_PARAM_RATE,
  71. + machine->rate,
  72. + machine->rate);
  73. + if (ret < 0) {
  74. + dev_err(card->dev,
  75. + "Unable to apply rate symmetry constraint: %d\n", ret);
  76. + return ret;
  77. + }
  78. + }
  79. +
  80. + return 0;
  81. +}
  82. +
  83. /*
  84. * Called by ALSA when a PCM substream is opened, the runtime->hw record is
  85. * then initialized and any private data can be allocated. This also calls
  86. @@ -221,6 +250,13 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
  87. goto machine_err;
  88. }
  89. + /* Symmetry only applies if we've already got an active stream. */
  90. + if (cpu_dai->active || codec_dai->active) {
  91. + ret = soc_pcm_apply_symmetry(substream);
  92. + if (ret != 0)
  93. + goto machine_err;
  94. + }
  95. +
  96. pr_debug("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
  97. pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
  98. pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
  99. @@ -479,6 +515,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
  100. }
  101. }
  102. + machine->rate = params_rate(params);
  103. +
  104. out:
  105. mutex_unlock(&pcm_mutex);
  106. return ret;
  107. --
  108. 1.6.2.4