snd-soc-afeb9260.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 <sound/soc-dapm.h>
  32. #include <asm/mach-types.h>
  33. #include <mach/hardware.h>
  34. #include <linux/gpio.h>
  35. #include "../codecs/tlv320aic23.h"
  36. #include "atmel-pcm.h"
  37. #include "atmel_ssc_dai.h"
  38. #define CODEC_CLOCK 12000000
  39. static int afeb9260_hw_params(struct snd_pcm_substream *substream,
  40. struct snd_pcm_hw_params *params)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  43. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  44. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  45. int err;
  46. /* Set codec DAI configuration */
  47. err = snd_soc_dai_set_fmt(codec_dai,
  48. SND_SOC_DAIFMT_I2S|
  49. SND_SOC_DAIFMT_NB_IF |
  50. SND_SOC_DAIFMT_CBM_CFM);
  51. if (err < 0) {
  52. printk(KERN_ERR "can't set codec DAI configuration\n");
  53. return err;
  54. }
  55. /* Set cpu DAI configuration */
  56. err = snd_soc_dai_set_fmt(cpu_dai,
  57. SND_SOC_DAIFMT_I2S |
  58. SND_SOC_DAIFMT_NB_IF |
  59. SND_SOC_DAIFMT_CBM_CFM);
  60. if (err < 0) {
  61. printk(KERN_ERR "can't set cpu DAI configuration\n");
  62. return err;
  63. }
  64. /* Set the codec system clock for DAC and ADC */
  65. err =
  66. snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
  67. if (err < 0) {
  68. printk(KERN_ERR "can't set codec system clock\n");
  69. return err;
  70. }
  71. return err;
  72. }
  73. static struct snd_soc_ops afeb9260_ops = {
  74. .hw_params = afeb9260_hw_params,
  75. };
  76. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  77. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  78. SND_SOC_DAPM_LINE("Line In", NULL),
  79. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  80. };
  81. static const struct snd_soc_dapm_route audio_map[] = {
  82. {"Headphone Jack", NULL, "LHPOUT"},
  83. {"Headphone Jack", NULL, "RHPOUT"},
  84. {"LLINEIN", NULL, "Line In"},
  85. {"RLINEIN", NULL, "Line In"},
  86. {"MICIN", NULL, "Mic Jack"},
  87. };
  88. static int afeb9260_tlv320aic23_init(struct snd_soc_pcm_runtime *rtd)
  89. {
  90. struct snd_soc_codec *codec = rtd->codec;
  91. /* Add afeb9260 specific widgets */
  92. snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
  93. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  94. /* Set up afeb9260 specific audio path audio_map */
  95. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  96. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  97. snd_soc_dapm_enable_pin(codec, "Line In");
  98. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  99. snd_soc_dapm_sync(codec);
  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-0x1a",
  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");