osk5912.c 5.3 KB

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