snappercl15.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
  4. *
  5. * Copyright (C) 2008 Bluewater Systems Ltd
  6. * Author: Ryan Mallon
  7. */
  8. #include <linux/platform_device.h>
  9. #include <linux/module.h>
  10. #include <linux/soc/cirrus/ep93xx.h>
  11. #include <sound/core.h>
  12. #include <sound/pcm.h>
  13. #include <sound/soc.h>
  14. #include <asm/mach-types.h>
  15. #include "../codecs/tlv320aic23.h"
  16. #define CODEC_CLOCK 5644800
  17. static int snappercl15_hw_params(struct snd_pcm_substream *substream,
  18. struct snd_pcm_hw_params *params)
  19. {
  20. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  21. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  22. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  23. int err;
  24. err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
  25. SND_SOC_CLOCK_IN);
  26. if (err)
  27. return err;
  28. err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
  29. SND_SOC_CLOCK_OUT);
  30. if (err)
  31. return err;
  32. return 0;
  33. }
  34. static const struct snd_soc_ops snappercl15_ops = {
  35. .hw_params = snappercl15_hw_params,
  36. };
  37. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  38. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  39. SND_SOC_DAPM_LINE("Line In", NULL),
  40. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  41. };
  42. static const struct snd_soc_dapm_route audio_map[] = {
  43. {"Headphone Jack", NULL, "LHPOUT"},
  44. {"Headphone Jack", NULL, "RHPOUT"},
  45. {"LLINEIN", NULL, "Line In"},
  46. {"RLINEIN", NULL, "Line In"},
  47. {"MICIN", NULL, "Mic Jack"},
  48. };
  49. SND_SOC_DAILINK_DEFS(aic23,
  50. DAILINK_COMP_ARRAY(COMP_CPU("ep93xx-i2s")),
  51. DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic23-codec.0-001a",
  52. "tlv320aic23-hifi")),
  53. DAILINK_COMP_ARRAY(COMP_PLATFORM("ep93xx-i2s")));
  54. static struct snd_soc_dai_link snappercl15_dai = {
  55. .name = "tlv320aic23",
  56. .stream_name = "AIC23",
  57. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  58. SND_SOC_DAIFMT_CBC_CFC,
  59. .ops = &snappercl15_ops,
  60. SND_SOC_DAILINK_REG(aic23),
  61. };
  62. static struct snd_soc_card snd_soc_snappercl15 = {
  63. .name = "Snapper CL15",
  64. .owner = THIS_MODULE,
  65. .dai_link = &snappercl15_dai,
  66. .num_links = 1,
  67. .dapm_widgets = tlv320aic23_dapm_widgets,
  68. .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
  69. .dapm_routes = audio_map,
  70. .num_dapm_routes = ARRAY_SIZE(audio_map),
  71. };
  72. static int snappercl15_probe(struct platform_device *pdev)
  73. {
  74. struct snd_soc_card *card = &snd_soc_snappercl15;
  75. int ret;
  76. ret = ep93xx_i2s_acquire();
  77. if (ret)
  78. return ret;
  79. card->dev = &pdev->dev;
  80. ret = snd_soc_register_card(card);
  81. if (ret) {
  82. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  83. ret);
  84. ep93xx_i2s_release();
  85. }
  86. return ret;
  87. }
  88. static int snappercl15_remove(struct platform_device *pdev)
  89. {
  90. struct snd_soc_card *card = platform_get_drvdata(pdev);
  91. snd_soc_unregister_card(card);
  92. ep93xx_i2s_release();
  93. return 0;
  94. }
  95. static struct platform_driver snappercl15_driver = {
  96. .driver = {
  97. .name = "snappercl15-audio",
  98. },
  99. .probe = snappercl15_probe,
  100. .remove = snappercl15_remove,
  101. };
  102. module_platform_driver(snappercl15_driver);
  103. MODULE_AUTHOR("Ryan Mallon");
  104. MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
  105. MODULE_LICENSE("GPL");
  106. MODULE_ALIAS("platform:snappercl15-audio");