armada-370-db.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Copyright (C) 2014 Marvell
  3. *
  4. * Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of the
  9. * License, or (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/slab.h>
  16. #include <sound/soc.h>
  17. #include <linux/of.h>
  18. #include <linux/platform_data/asoc-kirkwood.h>
  19. #include "../codecs/cs42l51.h"
  20. static int a370db_hw_params(struct snd_pcm_substream *substream,
  21. struct snd_pcm_hw_params *params)
  22. {
  23. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  24. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  25. unsigned int freq;
  26. switch (params_rate(params)) {
  27. default:
  28. case 44100:
  29. freq = 11289600;
  30. break;
  31. case 48000:
  32. freq = 12288000;
  33. break;
  34. case 96000:
  35. freq = 24576000;
  36. break;
  37. }
  38. return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
  39. }
  40. static struct snd_soc_ops a370db_ops = {
  41. .hw_params = a370db_hw_params,
  42. };
  43. static const struct snd_soc_dapm_widget a370db_dapm_widgets[] = {
  44. SND_SOC_DAPM_HP("Out Jack", NULL),
  45. SND_SOC_DAPM_LINE("In Jack", NULL),
  46. };
  47. static const struct snd_soc_dapm_route a370db_route[] = {
  48. { "Out Jack", NULL, "HPL" },
  49. { "Out Jack", NULL, "HPR" },
  50. { "AIN1L", NULL, "In Jack" },
  51. { "AIN1L", NULL, "In Jack" },
  52. };
  53. static struct snd_soc_dai_link a370db_dai[] = {
  54. {
  55. .name = "CS42L51",
  56. .stream_name = "analog",
  57. .cpu_dai_name = "i2s",
  58. .codec_dai_name = "cs42l51-hifi",
  59. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
  60. .ops = &a370db_ops,
  61. },
  62. {
  63. .name = "S/PDIF out",
  64. .stream_name = "spdif-out",
  65. .cpu_dai_name = "spdif",
  66. .codec_dai_name = "dit-hifi",
  67. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
  68. },
  69. {
  70. .name = "S/PDIF in",
  71. .stream_name = "spdif-in",
  72. .cpu_dai_name = "spdif",
  73. .codec_dai_name = "dir-hifi",
  74. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS,
  75. },
  76. };
  77. static struct snd_soc_card a370db = {
  78. .name = "a370db",
  79. .owner = THIS_MODULE,
  80. .dai_link = a370db_dai,
  81. .num_links = ARRAY_SIZE(a370db_dai),
  82. .dapm_widgets = a370db_dapm_widgets,
  83. .num_dapm_widgets = ARRAY_SIZE(a370db_dapm_widgets),
  84. .dapm_routes = a370db_route,
  85. .num_dapm_routes = ARRAY_SIZE(a370db_route),
  86. };
  87. static int a370db_probe(struct platform_device *pdev)
  88. {
  89. struct snd_soc_card *card = &a370db;
  90. card->dev = &pdev->dev;
  91. a370db_dai[0].cpu_of_node =
  92. of_parse_phandle(pdev->dev.of_node,
  93. "marvell,audio-controller", 0);
  94. a370db_dai[0].platform_of_node = a370db_dai[0].cpu_of_node;
  95. a370db_dai[0].codec_of_node =
  96. of_parse_phandle(pdev->dev.of_node,
  97. "marvell,audio-codec", 0);
  98. a370db_dai[1].cpu_of_node = a370db_dai[0].cpu_of_node;
  99. a370db_dai[1].platform_of_node = a370db_dai[0].cpu_of_node;
  100. a370db_dai[1].codec_of_node =
  101. of_parse_phandle(pdev->dev.of_node,
  102. "marvell,audio-codec", 1);
  103. a370db_dai[2].cpu_of_node = a370db_dai[0].cpu_of_node;
  104. a370db_dai[2].platform_of_node = a370db_dai[0].cpu_of_node;
  105. a370db_dai[2].codec_of_node =
  106. of_parse_phandle(pdev->dev.of_node,
  107. "marvell,audio-codec", 2);
  108. return devm_snd_soc_register_card(card->dev, card);
  109. }
  110. static const struct of_device_id a370db_dt_ids[] = {
  111. { .compatible = "marvell,a370db-audio" },
  112. { },
  113. };
  114. MODULE_DEVICE_TABLE(of, a370db_dt_ids);
  115. static struct platform_driver a370db_driver = {
  116. .driver = {
  117. .name = "a370db-audio",
  118. .of_match_table = of_match_ptr(a370db_dt_ids),
  119. },
  120. .probe = a370db_probe,
  121. };
  122. module_platform_driver(a370db_driver);
  123. MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
  124. MODULE_DESCRIPTION("ALSA SoC a370db audio client");
  125. MODULE_LICENSE("GPL");
  126. MODULE_ALIAS("platform:a370db-audio");