snappercl15.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * snappercl15.c -- SoC audio for Bluewater Systems Snapper CL15 module
  3. *
  4. * Copyright (C) 2008 Bluewater Systems Ltd
  5. * Author: Ryan Mallon
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. *
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/module.h>
  15. #include <sound/core.h>
  16. #include <sound/pcm.h>
  17. #include <sound/soc.h>
  18. #include <asm/mach-types.h>
  19. #include <mach/hardware.h>
  20. #include "../codecs/tlv320aic23.h"
  21. #include "ep93xx-pcm.h"
  22. #define CODEC_CLOCK 5644800
  23. static int snappercl15_hw_params(struct snd_pcm_substream *substream,
  24. struct snd_pcm_hw_params *params)
  25. {
  26. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  27. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  28. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  29. int err;
  30. err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
  31. SND_SOC_CLOCK_IN);
  32. if (err)
  33. return err;
  34. err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
  35. SND_SOC_CLOCK_OUT);
  36. if (err)
  37. return err;
  38. return 0;
  39. }
  40. static struct snd_soc_ops snappercl15_ops = {
  41. .hw_params = snappercl15_hw_params,
  42. };
  43. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  44. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  45. SND_SOC_DAPM_LINE("Line In", NULL),
  46. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  47. };
  48. static const struct snd_soc_dapm_route audio_map[] = {
  49. {"Headphone Jack", NULL, "LHPOUT"},
  50. {"Headphone Jack", NULL, "RHPOUT"},
  51. {"LLINEIN", NULL, "Line In"},
  52. {"RLINEIN", NULL, "Line In"},
  53. {"MICIN", NULL, "Mic Jack"},
  54. };
  55. static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  56. {
  57. struct snd_soc_codec *codec = rtd->codec;
  58. struct snd_soc_dapm_context *dapm = &codec->dapm;
  59. snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
  60. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  61. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  62. return 0;
  63. }
  64. static struct snd_soc_dai_link snappercl15_dai = {
  65. .name = "tlv320aic23",
  66. .stream_name = "AIC23",
  67. .cpu_dai_name = "ep93xx-i2s",
  68. .codec_dai_name = "tlv320aic23-hifi",
  69. .codec_name = "tlv320aic23-codec.0-001a",
  70. .platform_name = "ep93xx-pcm-audio",
  71. .init = snappercl15_tlv320aic23_init,
  72. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
  73. SND_SOC_DAIFMT_CBS_CFS,
  74. .ops = &snappercl15_ops,
  75. };
  76. static struct snd_soc_card snd_soc_snappercl15 = {
  77. .name = "Snapper CL15",
  78. .owner = THIS_MODULE,
  79. .dai_link = &snappercl15_dai,
  80. .num_links = 1,
  81. };
  82. static int __devinit snappercl15_probe(struct platform_device *pdev)
  83. {
  84. struct snd_soc_card *card = &snd_soc_snappercl15;
  85. int ret;
  86. ret = ep93xx_i2s_acquire();
  87. if (ret)
  88. return ret;
  89. card->dev = &pdev->dev;
  90. ret = snd_soc_register_card(card);
  91. if (ret) {
  92. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  93. ret);
  94. ep93xx_i2s_release();
  95. }
  96. return ret;
  97. }
  98. static int __devexit snappercl15_remove(struct platform_device *pdev)
  99. {
  100. struct snd_soc_card *card = platform_get_drvdata(pdev);
  101. snd_soc_unregister_card(card);
  102. ep93xx_i2s_release();
  103. return 0;
  104. }
  105. static struct platform_driver snappercl15_driver = {
  106. .driver = {
  107. .name = "snappercl15-audio",
  108. .owner = THIS_MODULE,
  109. },
  110. .probe = snappercl15_probe,
  111. .remove = __devexit_p(snappercl15_remove),
  112. };
  113. module_platform_driver(snappercl15_driver);
  114. MODULE_AUTHOR("Ryan Mallon");
  115. MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
  116. MODULE_LICENSE("GPL");
  117. MODULE_ALIAS("platform:snappercl15-audio");