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