bfin-eval-adav80x.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * Machine driver for EVAL-ADAV801 and EVAL-ADAV803 on Analog Devices bfin
  3. * evaluation boards.
  4. *
  5. * Copyright 2011 Analog Devices Inc.
  6. * Author: Lars-Peter Clausen <lars@metafoo.de>
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/module.h>
  13. #include <sound/core.h>
  14. #include <sound/pcm.h>
  15. #include <sound/soc.h>
  16. #include "../codecs/adav80x.h"
  17. static const struct snd_soc_dapm_widget bfin_eval_adav80x_dapm_widgets[] = {
  18. SND_SOC_DAPM_LINE("Line Out", NULL),
  19. SND_SOC_DAPM_LINE("Line In", NULL),
  20. };
  21. static const struct snd_soc_dapm_route bfin_eval_adav80x_dapm_routes[] = {
  22. { "Line Out", NULL, "VOUTL" },
  23. { "Line Out", NULL, "VOUTR" },
  24. { "VINL", NULL, "Line In" },
  25. { "VINR", NULL, "Line In" },
  26. };
  27. static int bfin_eval_adav80x_hw_params(struct snd_pcm_substream *substream,
  28. struct snd_pcm_hw_params *params)
  29. {
  30. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  31. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  32. int ret;
  33. ret = snd_soc_dai_set_pll(codec_dai, ADAV80X_PLL1, ADAV80X_PLL_SRC_XTAL,
  34. 27000000, params_rate(params) * 256);
  35. if (ret)
  36. return ret;
  37. ret = snd_soc_dai_set_sysclk(codec_dai, ADAV80X_CLK_PLL1,
  38. params_rate(params) * 256, SND_SOC_CLOCK_IN);
  39. return ret;
  40. }
  41. static int bfin_eval_adav80x_codec_init(struct snd_soc_pcm_runtime *rtd)
  42. {
  43. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  44. snd_soc_dai_set_sysclk(codec_dai, ADAV80X_CLK_SYSCLK1, 0,
  45. SND_SOC_CLOCK_OUT);
  46. snd_soc_dai_set_sysclk(codec_dai, ADAV80X_CLK_SYSCLK2, 0,
  47. SND_SOC_CLOCK_OUT);
  48. snd_soc_dai_set_sysclk(codec_dai, ADAV80X_CLK_SYSCLK3, 0,
  49. SND_SOC_CLOCK_OUT);
  50. snd_soc_dai_set_sysclk(codec_dai, ADAV80X_CLK_XTAL, 2700000, 0);
  51. return 0;
  52. }
  53. static struct snd_soc_ops bfin_eval_adav80x_ops = {
  54. .hw_params = bfin_eval_adav80x_hw_params,
  55. };
  56. static struct snd_soc_dai_link bfin_eval_adav80x_dais[] = {
  57. {
  58. .name = "adav80x",
  59. .stream_name = "ADAV80x HiFi",
  60. .cpu_dai_name = "bfin-i2s.0",
  61. .codec_dai_name = "adav80x-hifi",
  62. .platform_name = "bfin-i2s-pcm-audio",
  63. .init = bfin_eval_adav80x_codec_init,
  64. .ops = &bfin_eval_adav80x_ops,
  65. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  66. SND_SOC_DAIFMT_CBM_CFM,
  67. },
  68. };
  69. static struct snd_soc_card bfin_eval_adav80x = {
  70. .name = "bfin-eval-adav80x",
  71. .owner = THIS_MODULE,
  72. .dai_link = bfin_eval_adav80x_dais,
  73. .num_links = ARRAY_SIZE(bfin_eval_adav80x_dais),
  74. .dapm_widgets = bfin_eval_adav80x_dapm_widgets,
  75. .num_dapm_widgets = ARRAY_SIZE(bfin_eval_adav80x_dapm_widgets),
  76. .dapm_routes = bfin_eval_adav80x_dapm_routes,
  77. .num_dapm_routes = ARRAY_SIZE(bfin_eval_adav80x_dapm_routes),
  78. };
  79. enum bfin_eval_adav80x_type {
  80. BFIN_EVAL_ADAV801,
  81. BFIN_EVAL_ADAV803,
  82. };
  83. static int bfin_eval_adav80x_probe(struct platform_device *pdev)
  84. {
  85. struct snd_soc_card *card = &bfin_eval_adav80x;
  86. const char *codec_name;
  87. switch (platform_get_device_id(pdev)->driver_data) {
  88. case BFIN_EVAL_ADAV801:
  89. codec_name = "spi0.1";
  90. break;
  91. case BFIN_EVAL_ADAV803:
  92. codec_name = "adav803.0-0034";
  93. break;
  94. default:
  95. return -EINVAL;
  96. }
  97. bfin_eval_adav80x_dais[0].codec_name = codec_name;
  98. card->dev = &pdev->dev;
  99. return devm_snd_soc_register_card(&pdev->dev, &bfin_eval_adav80x);
  100. }
  101. static const struct platform_device_id bfin_eval_adav80x_ids[] = {
  102. { "bfin-eval-adav801", BFIN_EVAL_ADAV801 },
  103. { "bfin-eval-adav803", BFIN_EVAL_ADAV803 },
  104. { },
  105. };
  106. MODULE_DEVICE_TABLE(platform, bfin_eval_adav80x_ids);
  107. static struct platform_driver bfin_eval_adav80x_driver = {
  108. .driver = {
  109. .name = "bfin-eval-adav80x",
  110. .pm = &snd_soc_pm_ops,
  111. },
  112. .probe = bfin_eval_adav80x_probe,
  113. .id_table = bfin_eval_adav80x_ids,
  114. };
  115. module_platform_driver(bfin_eval_adav80x_driver);
  116. MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
  117. MODULE_DESCRIPTION("ALSA SoC bfin adav80x driver");
  118. MODULE_LICENSE("GPL");