osk5912.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <mach/hardware.h>
  30. #include <linux/gpio.h>
  31. #include <linux/module.h>
  32. #include <plat/mcbsp.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. #include "../codecs/tlv320aic23.h"
  36. #define CODEC_CLOCK 12000000
  37. static struct clk *tlv320aic23_mclk;
  38. static int osk_startup(struct snd_pcm_substream *substream)
  39. {
  40. return clk_enable(tlv320aic23_mclk);
  41. }
  42. static void osk_shutdown(struct snd_pcm_substream *substream)
  43. {
  44. clk_disable(tlv320aic23_mclk);
  45. }
  46. static int osk_hw_params(struct snd_pcm_substream *substream,
  47. struct snd_pcm_hw_params *params)
  48. {
  49. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  50. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  51. int err;
  52. /* Set the codec system clock for DAC and ADC */
  53. err =
  54. snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN);
  55. if (err < 0) {
  56. printk(KERN_ERR "can't set codec system clock\n");
  57. return err;
  58. }
  59. return err;
  60. }
  61. static struct snd_soc_ops osk_ops = {
  62. .startup = osk_startup,
  63. .hw_params = osk_hw_params,
  64. .shutdown = osk_shutdown,
  65. };
  66. static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = {
  67. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  68. SND_SOC_DAPM_LINE("Line In", NULL),
  69. SND_SOC_DAPM_MIC("Mic Jack", NULL),
  70. };
  71. static const struct snd_soc_dapm_route audio_map[] = {
  72. {"Headphone Jack", NULL, "LHPOUT"},
  73. {"Headphone Jack", NULL, "RHPOUT"},
  74. {"LLINEIN", NULL, "Line In"},
  75. {"RLINEIN", NULL, "Line In"},
  76. {"MICIN", NULL, "Mic Jack"},
  77. };
  78. /* Digital audio interface glue - connects codec <--> CPU */
  79. static struct snd_soc_dai_link osk_dai = {
  80. .name = "TLV320AIC23",
  81. .stream_name = "AIC23",
  82. .cpu_dai_name = "omap-mcbsp.1",
  83. .codec_dai_name = "tlv320aic23-hifi",
  84. .platform_name = "omap-pcm-audio",
  85. .codec_name = "tlv320aic23-codec",
  86. .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
  87. SND_SOC_DAIFMT_CBM_CFM,
  88. .ops = &osk_ops,
  89. };
  90. /* Audio machine driver */
  91. static struct snd_soc_card snd_soc_card_osk = {
  92. .name = "OSK5912",
  93. .owner = THIS_MODULE,
  94. .dai_link = &osk_dai,
  95. .num_links = 1,
  96. .dapm_widgets = tlv320aic23_dapm_widgets,
  97. .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets),
  98. .dapm_routes = audio_map,
  99. .num_dapm_routes = ARRAY_SIZE(audio_map),
  100. };
  101. static struct platform_device *osk_snd_device;
  102. static int __init osk_soc_init(void)
  103. {
  104. int err;
  105. u32 curRate;
  106. struct device *dev;
  107. if (!(machine_is_omap_osk()))
  108. return -ENODEV;
  109. osk_snd_device = platform_device_alloc("soc-audio", -1);
  110. if (!osk_snd_device)
  111. return -ENOMEM;
  112. platform_set_drvdata(osk_snd_device, &snd_soc_card_osk);
  113. err = platform_device_add(osk_snd_device);
  114. if (err)
  115. goto err1;
  116. dev = &osk_snd_device->dev;
  117. tlv320aic23_mclk = clk_get(dev, "mclk");
  118. if (IS_ERR(tlv320aic23_mclk)) {
  119. printk(KERN_ERR "Could not get mclk clock\n");
  120. err = PTR_ERR(tlv320aic23_mclk);
  121. goto err2;
  122. }
  123. /*
  124. * Configure 12 MHz output on MCLK.
  125. */
  126. curRate = (uint) clk_get_rate(tlv320aic23_mclk);
  127. if (curRate != CODEC_CLOCK) {
  128. if (clk_set_rate(tlv320aic23_mclk, CODEC_CLOCK)) {
  129. printk(KERN_ERR "Cannot set MCLK for AIC23 CODEC\n");
  130. err = -ECANCELED;
  131. goto err3;
  132. }
  133. }
  134. printk(KERN_INFO "MCLK = %d [%d]\n",
  135. (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
  136. return 0;
  137. err3:
  138. clk_put(tlv320aic23_mclk);
  139. err2:
  140. platform_device_del(osk_snd_device);
  141. err1:
  142. platform_device_put(osk_snd_device);
  143. return err;
  144. }
  145. static void __exit osk_soc_exit(void)
  146. {
  147. clk_put(tlv320aic23_mclk);
  148. platform_device_unregister(osk_snd_device);
  149. }
  150. module_init(osk_soc_init);
  151. module_exit(osk_soc_exit);
  152. MODULE_AUTHOR("Arun KS <arunks@mistralsolutions.com>");
  153. MODULE_DESCRIPTION("ALSA SoC OSK 5912");
  154. MODULE_LICENSE("GPL");