snd-soc-afeb9260.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 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. /* Add afeb9260 specific widgets */
  73. snd_soc_dapm_new_controls(dapm, tlv320aic23_dapm_widgets,
  74. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  75. /* Set up afeb9260 specific audio path audio_map */
  76. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  77. snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
  78. snd_soc_dapm_enable_pin(dapm, "Line In");
  79. snd_soc_dapm_enable_pin(dapm, "Mic Jack");
  80. return 0;
  81. }
  82. /* Digital audio interface glue - connects codec <--> CPU */
  83. static struct snd_soc_dai_link afeb9260_dai = {
  84. .name = "TLV320AIC23",
  85. .stream_name = "AIC23",
  86. .cpu_dai_name = "atmel-ssc-dai.0",
  87. .codec_dai_name = "tlv320aic23-hifi",
  88. .platform_name = "atmel_pcm-audio",
  89. .codec_name = "tlv320aic23-codec.0-001a",
  90. .init = afeb9260_tlv320aic23_init,
  91. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
  92. SND_SOC_DAIFMT_CBM_CFM,
  93. .ops = &afeb9260_ops,
  94. };
  95. /* Audio machine driver */
  96. static struct snd_soc_card snd_soc_machine_afeb9260 = {
  97. .name = "AFEB9260",
  98. .owner = THIS_MODULE,
  99. .dai_link = &afeb9260_dai,
  100. .num_links = 1,
  101. };
  102. static struct platform_device *afeb9260_snd_device;
  103. static int __init afeb9260_soc_init(void)
  104. {
  105. int err;
  106. struct device *dev;
  107. if (!(machine_is_afeb9260()))
  108. return -ENODEV;
  109. afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
  110. if (!afeb9260_snd_device) {
  111. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  112. return -ENOMEM;
  113. }
  114. platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260);
  115. err = platform_device_add(afeb9260_snd_device);
  116. if (err)
  117. goto err1;
  118. dev = &afeb9260_snd_device->dev;
  119. return 0;
  120. err1:
  121. platform_device_put(afeb9260_snd_device);
  122. return err;
  123. }
  124. static void __exit afeb9260_soc_exit(void)
  125. {
  126. platform_device_unregister(afeb9260_snd_device);
  127. }
  128. module_init(afeb9260_soc_init);
  129. module_exit(afeb9260_soc_exit);
  130. MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
  131. MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
  132. MODULE_LICENSE("GPL");