snd-soc-afeb9260.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * afeb9260.c -- SoC audio for AFEB9260
  3. *
  4. * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org>
  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
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/module.h>
  22. #include <linux/moduleparam.h>
  23. #include <linux/kernel.h>
  24. #include <linux/clk.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/atmel-ssc.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/soc.h>
  31. #include <asm/mach-types.h>
  32. #include <mach/hardware.h>
  33. #include <linux/gpio.h>
  34. #include "../codecs/tlv320aic23.h"
  35. #include "atmel-pcm.h"
  36. #include "atmel_ssc_dai.h"
  37. #define CODEC_CLOCK 12000000
  38. static int afeb9260_hw_params(struct snd_pcm_substream *substream,
  39. struct snd_pcm_hw_params *params)
  40. {
  41. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  42. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  43. int err;
  44. /* Set the codec system clock for DAC and ADC */
  45. err =
  46. snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
  47. if (err < 0) {
  48. printk(KERN_ERR "can't set codec system clock\n");
  49. return err;
  50. }
  51. return err;
  52. }
  53. static struct snd_soc_ops afeb9260_ops = {
  54. .hw_params = afeb9260_hw_params,
  55. };
  56. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  57. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  58. SND_SOC_DAPM_LINE("Line In", NULL),
  59. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  60. };
  61. static const struct snd_soc_dapm_route afeb9260_audio_map[] = {
  62. {"Headphone Jack", NULL, "LHPOUT"},
  63. {"Headphone Jack", NULL, "RHPOUT"},
  64. {"LLINEIN", NULL, "Line In"},
  65. {"RLINEIN", NULL, "Line In"},
  66. {"MICIN", NULL, "Mic Jack"},
  67. };
  68. static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  69. {
  70. struct snd_soc_codec *codec = rtd->codec;
  71. struct snd_soc_dapm_context *dapm = &codec->dapm;
  72. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  73. snd_soc_dapm_enable_pin(dapm, "Line In");
  74. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  75. return 0;
  76. }
  77. /* Digital audio interface glue - connects codec <--> CPU */
  78. static struct snd_soc_dai_link afeb9260_dai = {
  79. .name = "TLV320AIC23",
  80. .stream_name = "AIC23",
  81. .cpu_dai_name = "atmel-ssc-dai.0",
  82. .codec_dai_name = "tlv320aic23-hifi",
  83. .platform_name = "atmel_pcm-audio",
  84. .codec_name = "tlv320aic23-codec.0-001a",
  85. .init = afeb9260_tlv320aic23_init,
  86. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
  87. SND_SOC_DAIFMT_CBM_CFM,
  88. .ops = &afeb9260_ops,
  89. };
  90. /* Audio machine driver */
  91. static struct snd_soc_card snd_soc_machine_afeb9260 = {
  92. .name = "AFEB9260",
  93. .owner = THIS_MODULE,
  94. .dai_link = &afeb9260_dai,
  95. .num_links = 1,
  96. .dapm_widgets = tlv320aic23_dapm_widgets,
  97. .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
  98. .dapm_routes = afeb9260_audio_map,
  99. .num_dapm_routes = ARRAY_SIZE(afeb9260_audio_map),
  100. };
  101. static struct platform_device *afeb9260_snd_device;
  102. static int __init afeb9260_soc_init(void)
  103. {
  104. int err;
  105. struct device *dev;
  106. if (!(machine_is_afeb9260()))
  107. return -ENODEV;
  108. afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
  109. if (!afeb9260_snd_device) {
  110. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  111. return -ENOMEM;
  112. }
  113. platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
  114. err = platform_device_add(afeb9260_snd_device);
  115. if (err)
  116. goto err1;
  117. dev = &afeb9260_snd_device->dev;
  118. return 0;
  119. err1:
  120. platform_device_put(afeb9260_snd_device);
  121. return err;
  122. }
  123. static void __exit afeb9260_soc_exit(void)
  124. {
  125. platform_device_unregister(afeb9260_snd_device);
  126. }
  127. module_init(afeb9260_soc_init);
  128. module_exit(afeb9260_soc_exit);
  129. MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
  130. MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
  131. MODULE_LICENSE("GPL");