brownstone.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. if (params_rate(params) > 11025) {
  47. freq_out = params_rate(params) * 512;
  48. sysclk = params_rate(params) * 256;
  49. sspa_mclk = params_rate(params) * 64;
  50. } else {
  51. freq_out = params_rate(params) * 1024;
  52. sysclk = params_rate(params) * 512;
  53. sspa_mclk = params_rate(params) * 64;
  54. }
  55. snd_soc_dai_set_sysclk(cpu_dai, MMP_SSPA_CLK_AUDIO, freq_out, 0);
  56. snd_soc_dai_set_pll(cpu_dai, MMP_SYSCLK, 0, freq_out, sysclk);
  57. snd_soc_dai_set_pll(cpu_dai, MMP_SSPA_CLK, 0, freq_out, sspa_mclk);
  58. /* set wm8994 sysclk */
  59. snd_soc_dai_set_sysclk(codec_dai, WM8994_SYSCLK_MCLK1, sysclk, 0);
  60. return 0;
  61. }
  62. /* machine stream operations */
  63. static struct snd_soc_ops brownstone_ops = {
  64. .hw_params = brownstone_wm8994_hw_params,
  65. };
  66. static struct snd_soc_dai_link brownstone_wm8994_dai[] = {
  67. {
  68. .name = "WM8994",
  69. .stream_name = "WM8994 HiFi",
  70. .cpu_dai_name = "mmp-sspa-dai.0",
  71. .codec_dai_name = "wm8994-aif1",
  72. .platform_name = "mmp-pcm-audio",
  73. .codec_name = "wm8994-codec",
  74. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  75. SND_SOC_DAIFMT_CBS_CFS,
  76. .ops = &brownstone_ops,
  77. },
  78. };
  79. /* audio machine driver */
  80. static struct snd_soc_card brownstone = {
  81. .name = "brownstone",
  82. .owner = THIS_MODULE,
  83. .dai_link = brownstone_wm8994_dai,
  84. .num_links = ARRAY_SIZE(brownstone_wm8994_dai),
  85. .controls = brownstone_dapm_control,
  86. .num_controls = ARRAY_SIZE(brownstone_dapm_control),
  87. .dapm_widgets = brownstone_dapm_widgets,
  88. .num_dapm_widgets = ARRAY_SIZE(brownstone_dapm_widgets),
  89. .dapm_routes = brownstone_audio_map,
  90. .num_dapm_routes = ARRAY_SIZE(brownstone_audio_map),
  91. .fully_routed = true,
  92. };
  93. static int brownstone_probe(struct platform_device *pdev)
  94. {
  95. int ret;
  96. brownstone.dev = &pdev->dev;
  97. ret = devm_snd_soc_register_card(&pdev->dev, &brownstone);
  98. if (ret)
  99. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  100. ret);
  101. return ret;
  102. }
  103. static struct platform_driver mmp_driver = {
  104. .driver = {
  105. .name = "brownstone-audio",
  106. .pm = &snd_soc_pm_ops,
  107. },
  108. .probe = brownstone_probe,
  109. };
  110. module_platform_driver(mmp_driver);
  111. MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
  112. MODULE_DESCRIPTION("ALSA SoC Brownstone");
  113. MODULE_LICENSE("GPL");
  114. MODULE_ALIAS("platform:brownstone-audio");