snappercl15.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #define CODEC_CLOCK 5644800
  22. static int snappercl15_hw_params(struct snd_pcm_substream *substream,
  23. struct snd_pcm_hw_params *params)
  24. {
  25. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  26. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  27. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  28. int err;
  29. err = snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK,
  30. SND_SOC_CLOCK_IN);
  31. if (err)
  32. return err;
  33. err = snd_soc_dai_set_sysclk(cpu_dai, 0, CODEC_CLOCK,
  34. SND_SOC_CLOCK_OUT);
  35. if (err)
  36. return err;
  37. return 0;
  38. }
  39. static struct snd_soc_ops snappercl15_ops = {
  40. .hw_params = snappercl15_hw_params,
  41. };
  42. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  43. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  44. SND_SOC_DAPM_LINE("Line In", NULL),
  45. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  46. };
  47. static const struct snd_soc_dapm_route audio_map[] = {
  48. {"Headphone Jack", NULL, "LHPOUT"},
  49. {"Headphone Jack", NULL, "RHPOUT"},
  50. {"LLINEIN", NULL, "Line In"},
  51. {"RLINEIN", NULL, "Line In"},
  52. {"MICIN", NULL, "Mic Jack"},
  53. };
  54. static int snappercl15_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  55. {
  56. struct snd_soc_codec *codec = rtd->codec;
  57. struct snd_soc_dapm_context *dapm = &codec->dapm;
  58. snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
  59. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  60. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  61. return 0;
  62. }
  63. static struct snd_soc_dai_link snappercl15_dai = {
  64. .name = "tlv320aic23",
  65. .stream_name = "AIC23",
  66. .cpu_dai_name = "ep93xx-i2s",
  67. .codec_dai_name = "tlv320aic23-hifi",
  68. .codec_name = "tlv320aic23-codec.0-001a",
  69. .platform_name = "ep93xx-pcm-audio",
  70. .init = snappercl15_tlv320aic23_init,
  71. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
  72. SND_SOC_DAIFMT_CBS_CFS,
  73. .ops = &snappercl15_ops,
  74. };
  75. static struct snd_soc_card snd_soc_snappercl15 = {
  76. .name = "Snapper CL15",
  77. .owner = THIS_MODULE,
  78. .dai_link = &snappercl15_dai,
  79. .num_links = 1,
  80. };
  81. static int snappercl15_probe(struct platform_device *pdev)
  82. {
  83. struct snd_soc_card *card = &snd_soc_snappercl15;
  84. int ret;
  85. ret = ep93xx_i2s_acquire();
  86. if (ret)
  87. return ret;
  88. card->dev = &pdev->dev;
  89. ret = snd_soc_register_card(card);
  90. if (ret) {
  91. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  92. ret);
  93. ep93xx_i2s_release();
  94. }
  95. return ret;
  96. }
  97. static int snappercl15_remove(struct platform_device *pdev)
  98. {
  99. struct snd_soc_card *card = platform_get_drvdata(pdev);
  100. snd_soc_unregister_card(card);
  101. ep93xx_i2s_release();
  102. return 0;
  103. }
  104. static struct platform_driver snappercl15_driver = {
  105. .driver = {
  106. .name = "snappercl15-audio",
  107. .owner = THIS_MODULE,
  108. },
  109. .probe = snappercl15_probe,
  110. .remove = snappercl15_remove,
  111. };
  112. module_platform_driver(snappercl15_driver);
  113. MODULE_AUTHOR("Ryan Mallon");
  114. MODULE_DESCRIPTION("ALSA SoC Snapper CL15");
  115. MODULE_LICENSE("GPL");
  116. MODULE_ALIAS("platform:snappercl15-audio");