osk5912.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * osk5912.c -- SoC audio for OSK 5912
  3. *
  4. * Copyright (C) 2008 Mistral Solutions
  5. *
  6. * Contact: Arun KS <arunks@mistralsolutions.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * version 2 as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. *
  22. */
  23. #include <linux/clk.h>
  24. #include <linux/platform_device.h>
  25. #include <sound/core.h>
  26. #include <sound/pcm.h>
  27. #include <sound/soc.h>
  28. #include <asm/mach-types.h>
  29. #include <linux/gpio.h>
  30. #include <linux/module.h>
  31. #include <linux/platform_data/asoc-ti-mcbsp.h>
  32. #include "omap-mcbsp.h"
  33. #include "../codecs/tlv320aic23.h"
  34. #define CODEC_CLOCK 12000000
  35. static struct clk *tlv320aic23_mclk;
  36. static int osk_startup(struct snd_pcm_substream *substream)
  37. {
  38. return clk_enable(tlv320aic23_mclk);
  39. }
  40. static void osk_shutdown(struct snd_pcm_substream *substream)
  41. {
  42. clk_disable(tlv320aic23_mclk);
  43. }
  44. static int osk_hw_params(struct snd_pcm_substream *substream,
  45. struct snd_pcm_hw_params *params)
  46. {
  47. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  48. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  49. int err;
  50. /* Set the codec system clock for DAC and ADC */
  51. err =
  52. snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
  53. if (err < 0) {
  54. printk(KERN_ERR "can't set codec system clock\n");
  55. return err;
  56. }
  57. return err;
  58. }
  59. static struct snd_soc_ops osk_ops = {
  60. .startup = osk_startup,
  61. .hw_params = osk_hw_params,
  62. .shutdown = osk_shutdown,
  63. };
  64. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  65. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  66. SND_SOC_DAPM_LINE("Line In", NULL),
  67. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  68. };
  69. static const struct snd_soc_dapm_route audio_map[] = {
  70. {"Headphone Jack", NULL, "LHPOUT"},
  71. {"Headphone Jack", NULL, "RHPOUT"},
  72. {"LLINEIN", NULL, "Line In"},
  73. {"RLINEIN", NULL, "Line In"},
  74. {"MICIN", NULL, "Mic Jack"},
  75. };
  76. /* Digital audio interface glue - connects codec <--> CPU */
  77. static struct snd_soc_dai_link osk_dai = {
  78. .name = "TLV320AIC23",
  79. .stream_name = "AIC23",
  80. .cpu_dai_name = "omap-mcbsp.1",
  81. .codec_dai_name = "tlv320aic23-hifi",
  82. .platform_name = "omap-mcbsp.1",
  83. .codec_name = "tlv320aic23-codec",
  84. .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
  85. SND_SOC_DAIFMT_CBM_CFM,
  86. .ops = &osk_ops,
  87. };
  88. /* Audio machine driver */
  89. static struct snd_soc_card snd_soc_card_osk = {
  90. .name = "OSK5912",
  91. .owner = THIS_MODULE,
  92. .dai_link = &osk_dai,
  93. .num_links = 1,
  94. .dapm_widgets = tlv320aic23_dapm_widgets,
  95. .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
  96. .dapm_routes = audio_map,
  97. .num_dapm_routes = ARRAY_SIZE(audio_map),
  98. };
  99. static struct platform_device *osk_snd_device;
  100. static int __init osk_soc_init(void)
  101. {
  102. int err;
  103. u32 curRate;
  104. struct device *dev;
  105. if (!(machine_is_omap_osk()))
  106. return -ENODEV;
  107. osk_snd_device = platform_device_alloc("soc-audio", -1);
  108. if (!osk_snd_device)
  109. return -ENOMEM;
  110. platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
  111. err = platform_device_add(osk_snd_device);
  112. if (err)
  113. goto err1;
  114. dev = &osk_snd_device->dev;
  115. tlv320aic23_mclk = clk_get(dev, "mclk");
  116. if (IS_ERR(tlv320aic23_mclk)) {
  117. printk(KERN_ERR "Could not get mclk clock\n");
  118. err = PTR_ERR(tlv320aic23_mclk);
  119. goto err2;
  120. }
  121. /*
  122. * Configure 12 MHz output on MCLK.
  123. */
  124. curRate = (uint) clk_get_rate(tlv320aic23_mclk);
  125. if (curRate != CODEC_CLOCK) {
  126. if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
  127. printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
  128. err = -ECANCELED;
  129. goto err3;
  130. }
  131. }
  132. printk(KERN_INFO "MCLK = %d [%d]\n",
  133. (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
  134. return 0;
  135. err3:
  136. clk_put(tlv320aic23_mclk);
  137. err2:
  138. platform_device_del(osk_snd_device);
  139. err1:
  140. platform_device_put(osk_snd_device);
  141. return err;
  142. }
  143. static void __exit osk_soc_exit(void)
  144. {
  145. clk_put(tlv320aic23_mclk);
  146. platform_device_unregister(osk_snd_device);
  147. }
  148. module_init(osk_soc_init);
  149. module_exit(osk_soc_exit);
  150. MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
  151. MODULE_DESCRIPTION("ALSA SoC OSK 5912");
  152. MODULE_LICENSE("GPL");