snd-soc-afeb9260.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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->dai->codec_dai;
  44. struct snd_soc_dai *cpu_dai = rtd->dai->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_codec *codec)
  89. {
  90. /* Add afeb9260 specific widgets */
  91. snd_soc_dapm_new_controls(codec, tlv320aic23_dapm_widgets,
  92. ARRAY_SIZE(tlv320aic23_dapm_widgets));
  93. /* Set up afeb9260 specific audio path audio_map */
  94. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  95. snd_soc_dapm_enable_pin(codec, "Headphone Jack");
  96. snd_soc_dapm_enable_pin(codec, "Line In");
  97. snd_soc_dapm_enable_pin(codec, "Mic Jack");
  98. snd_soc_dapm_sync(codec);
  99. return 0;
  100. }
  101. /* Digital audio interface glue - connects codec <--> CPU */
  102. static struct snd_soc_dai_link afeb9260_dai = {
  103. .name = "TLV320AIC23",
  104. .stream_name = "AIC23",
  105. .cpu_dai = &atmel_ssc_dai[0],
  106. .codec_dai = &tlv320aic23_dai,
  107. .init = afeb9260_tlv320aic23_init,
  108. .ops = &afeb9260_ops,
  109. };
  110. /* Audio machine driver */
  111. static struct snd_soc_card snd_soc_machine_afeb9260 = {
  112. .name = "AFEB9260",
  113. .platform = &atmel_soc_platform,
  114. .dai_link = &afeb9260_dai,
  115. .num_links = 1,
  116. };
  117. /* Audio subsystem */
  118. static struct snd_soc_device afeb9260_snd_devdata = {
  119. .card = &snd_soc_machine_afeb9260,
  120. .codec_dev = &soc_codec_dev_tlv320aic23,
  121. };
  122. static struct platform_device *afeb9260_snd_device;
  123. static int __init afeb9260_soc_init(void)
  124. {
  125. int err;
  126. struct device *dev;
  127. struct atmel_ssc_info *ssc_p = afeb9260_dai.cpu_dai->private_data;
  128. struct ssc_device *ssc = NULL;
  129. if (!(machine_is_afeb9260()))
  130. return -ENODEV;
  131. ssc = ssc_request(0);
  132. if (IS_ERR(ssc)) {
  133. printk(KERN_ERR "ASoC: Failed to request SSC 0\n");
  134. err = PTR_ERR(ssc);
  135. ssc = NULL;
  136. goto err_ssc;
  137. }
  138. ssc_p->ssc = ssc;
  139. afeb9260_snd_device = platform_device_alloc("soc-audio", -1);
  140. if (!afeb9260_snd_device) {
  141. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  142. return -ENOMEM;
  143. }
  144. platform_set_drvdata(afeb9260_snd_device, &afeb9260_snd_devdata);
  145. afeb9260_snd_devdata.dev = &afeb9260_snd_device->dev;
  146. err = platform_device_add(afeb9260_snd_device);
  147. if (err)
  148. goto err1;
  149. dev = &afeb9260_snd_device->dev;
  150. return 0;
  151. err1:
  152. platform_device_del(afeb9260_snd_device);
  153. platform_device_put(afeb9260_snd_device);
  154. err_ssc:
  155. return err;
  156. }
  157. static void __exit afeb9260_soc_exit(void)
  158. {
  159. platform_device_unregister(afeb9260_snd_device);
  160. }
  161. module_init(afeb9260_soc_init);
  162. module_exit(afeb9260_soc_exit);
  163. MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>");
  164. MODULE_DESCRIPTION("ALSA SoC for AFEB9260");
  165. MODULE_LICENSE("GPL");