snd-soc-afeb9260.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  44. int err;
  45. /* Set codec DAI configuration */
  46. err = snd_soc_dai_set_fmt(codec_dai,
  47. SND_SOC_DAIFMT_I2S|
  48. SND_SOC_DAIFMT_NB_IF |
  49. SND_SOC_DAIFMT_CBM_CFM);
  50. if (err < 0) {
  51. printk(KERN_ERR "can't set codec DAI configuration\n");
  52. return err;
  53. }
  54. /* Set cpu DAI configuration */
  55. err = snd_soc_dai_set_fmt(cpu_dai,
  56. SND_SOC_DAIFMT_I2S |
  57. SND_SOC_DAIFMT_NB_IF |
  58. SND_SOC_DAIFMT_CBM_CFM);
  59. if (err < 0) {
  60. printk(KERN_ERR "can't set cpu DAI configuration\n");
  61. return err;
  62. }
  63. /* Set the codec system clock for DAC and ADC */
  64. err =
  65. snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
  66. if (err < 0) {
  67. printk(KERN_ERR "can't set codec system clock\n");
  68. return err;
  69. }
  70. return err;
  71. }
  72. static struct snd_soc_ops afeb9260_ops = {
  73. .hw_params = afeb9260_hw_params,
  74. };
  75. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  76. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  77. SND_SOC_DAPM_LINE("Line In", NULL),
  78. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  79. };
  80. static const struct snd_soc_dapm_route audio_map[] = {
  81. {"Headphone Jack", NULL, "LHPOUT"},
  82. {"Headphone Jack", NULL, "RHPOUT"},
  83. {"LLINEIN", NULL, "Line In"},
  84. {"RLINEIN", NULL, "Line In"},
  85. {"MICIN", NULL, "Mic Jack"},
  86. };
  87. static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  88. {
  89. struct snd_soc_codec *codec = rtd->codec;
  90. struct snd_soc_dapm_context *dapm = &codec->dapm;
  91. /* Add afeb9260 specific widgets */
  92. snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
  93. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  94. /* Set up afeb9260 specific audio path audio_map */
  95. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  96. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  97. snd_soc_dapm_enable_pin(dapm, "Line In");
  98. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  99. snd_soc_dapm_sync(dapm);
  100. return 0;
  101. }
  102. /* Digital audio interface glue - connects codec <--> CPU */
  103. static struct snd_soc_dai_link afeb9260_dai = {
  104. .name = "TLV320AIC23",
  105. .stream_name = "AIC23",
  106. .cpu_dai_name = "atmel-ssc-dai.0",
  107. .codec_dai_name = "tlv320aic23-hifi",
  108. .platform_name = "atmel_pcm-audio",
  109. .codec_name = "tlv320aic23-codec.0-001a",
  110. .init = afeb9260_tlv320aic23_init,
  111. .ops = &afeb9260_ops,
  112. };
  113. /* Audio machine driver */
  114. static struct snd_soc_card snd_soc_machine_afeb9260 = {
  115. .name = "AFEB9260",
  116. .dai_link = &afeb9260_dai,
  117. .num_links = 1,
  118. };
  119. static struct platform_device *afeb9260_snd_device;
  120. static int __init afeb9260_soc_init(void)
  121. {
  122. int err;
  123. struct device *dev;
  124. if (!(machine_is_afeb9260()))
  125. return -ENODEV;
  126. afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
  127. if (!afeb9260_snd_device) {
  128. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  129. return -ENOMEM;
  130. }
  131. platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
  132. err = platform_device_add(afeb9260_snd_device);
  133. if (err)
  134. goto err1;
  135. dev = &afeb9260_snd_device->dev;
  136. return 0;
  137. err1:
  138. platform_device_put(afeb9260_snd_device);
  139. return err;
  140. }
  141. static void __exit afeb9260_soc_exit(void)
  142. {
  143. platform_device_unregister(afeb9260_snd_device);
  144. }
  145. module_init(afeb9260_soc_init);
  146. module_exit(afeb9260_soc_exit);
  147. MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
  148. MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
  149. MODULE_LICENSE("GPL");