brownstone.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * linux/sound/soc/pxa/brownstone.c
  3. *
  4. * Copyright (C) 2011 Marvell International Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. */
  12. #include <linux/module.h>
  13. #include <sound/core.h>
  14. #include <sound/pcm.h>
  15. #include <sound/soc.h>
  16. #include <sound/jack.h>
  17. #include "../codecs/wm8994.h"
  18. #include "mmp-sspa.h"
  19. static const struct snd_kcontrol_new brownstone_dapm_control[] = {
  20. SOC_DAPM_PIN_SWITCH("Ext Spk"),
  21. };
  22. static const struct snd_soc_dapm_widget brownstone_dapm_widgets[] = {
  23. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  24. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  25. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  26. SND_SOC_DAPM_MIC("Main Mic", NULL),
  27. };
  28. static const struct snd_soc_dapm_route brownstone_audio_map[] = {
  29. {"Ext Spk", NULL, "SPKOUTLP"},
  30. {"Ext Spk", NULL, "SPKOUTLN"},
  31. {"Ext Spk", NULL, "SPKOUTRP"},
  32. {"Ext Spk", NULL, "SPKOUTRN"},
  33. {"Headset Stereophone", NULL, "HPOUT1L"},
  34. {"Headset Stereophone", NULL, "HPOUT1R"},
  35. {"IN1RN", NULL, "Headset Mic"},
  36. {"DMIC1DAT", NULL, "MICBIAS1"},
  37. {"MICBIAS1", NULL, "Main Mic"},
  38. };
  39. static int brownstone_wm8994_hw_params(struct snd_pcm_substream *substream,
  40. struct snd_pcm_hw_params *params)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  43. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  44. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  45. int freq_out, sspa_mclk, sysclk;
  46. int sspa_div;
  47. if (params_rate(params) > 11025) {
  48. freq_out = params_rate(params) * 512;
  49. sysclk = params_rate(params) * 256;
  50. sspa_mclk = params_rate(params) * 64;
  51. } else {
  52. freq_out = params_rate(params) * 1024;
  53. sysclk = params_rate(params) * 512;
  54. sspa_mclk = params_rate(params) * 64;
  55. }
  56. sspa_div = freq_out;
  57. do_div(sspa_div, sspa_mclk);
  58. snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
  59. snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
  60. snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
  61. /* set wm8994 sysclk */
  62. snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
  63. return 0;
  64. }
  65. /* machine stream operations */
  66. static struct snd_soc_ops brownstone_ops = {
  67. .hw_params = brownstone_wm8994_hw_params,
  68. };
  69. static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
  70. {
  71. .name = "WM8994",
  72. .stream_name = "WM8994 HiFi",
  73. .cpu_dai_name = "mmp-sspa-dai.0",
  74. .codec_dai_name = "wm8994-aif1",
  75. .platform_name = "mmp-pcm-audio",
  76. .codec_name = "wm8994-codec",
  77. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  78. SND_SOC_DAIFMT_CBS_CFS,
  79. .ops = &brownstone_ops,
  80. },
  81. };
  82. /* audio machine driver */
  83. static struct snd_soc_card brownstone = {
  84. .name = "brownstone",
  85. .owner = THIS_MODULE,
  86. .dai_link = brownstone_wm8994_dai,
  87. .num_links = ARRAY_SIZE(brownstone_wm8994_dai),
  88. .controls = brownstone_dapm_control,
  89. .num_controls = ARRAY_SIZE(brownstone_dapm_control),
  90. .dapm_widgets = brownstone_dapm_widgets,
  91. .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
  92. .dapm_routes = brownstone_audio_map,
  93. .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
  94. .fully_routed = true,
  95. };
  96. static int brownstone_probe(struct platform_device *pdev)
  97. {
  98. int ret;
  99. brownstone.dev = &pdev->dev;
  100. ret = snd_soc_register_card(&brownstone);
  101. if (ret)
  102. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  103. ret);
  104. return ret;
  105. }
  106. static int brownstone_remove(struct platform_device *pdev)
  107. {
  108. snd_soc_unregister_card(&brownstone);
  109. return 0;
  110. }
  111. static struct platform_driver mmp_driver = {
  112. .driver = {
  113. .name = "brownstone-audio",
  114. .pm = &snd_soc_pm_ops,
  115. },
  116. .probe = brownstone_probe,
  117. .remove = brownstone_remove,
  118. };
  119. module_platform_driver(mmp_driver);
  120. MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
  121. MODULE_DESCRIPTION("ALSA SoC Brownstone");
  122. MODULE_LICENSE("GPL");