sdp4430.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * sdp4430.c -- SoC audio for TI OMAP4430 SDP
  3. *
  4. * Author: Misael Lopez Cruz <x0052729@ti.com>
  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/clk.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/mfd/twl6040.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/soc.h>
  27. #include <sound/jack.h>
  28. #include <asm/mach-types.h>
  29. #include <plat/hardware.h>
  30. #include <plat/mux.h>
  31. #include "mcpdm.h"
  32. #include "omap-pcm.h"
  33. #include "../codecs/twl6040.h"
  34. static int sdp4430_hw_params(struct snd_pcm_substream *substream,
  35. struct snd_pcm_hw_params *params)
  36. {
  37. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  38. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  39. int clk_id, freq;
  40. int ret;
  41. clk_id = twl6040_get_clk_id(rtd->codec);
  42. if (clk_id == TWL6040_SYSCLK_SEL_HPPLL)
  43. freq = 38400000;
  44. else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL)
  45. freq = 32768;
  46. else
  47. return -EINVAL;
  48. /* set the codec mclk */
  49. ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
  50. SND_SOC_CLOCK_IN);
  51. if (ret) {
  52. printk(KERN_ERR "can't set codec system clock\n");
  53. return ret;
  54. }
  55. return ret;
  56. }
  57. static struct snd_soc_ops sdp4430_ops = {
  58. .hw_params = sdp4430_hw_params,
  59. };
  60. /* Headset jack */
  61. static struct snd_soc_jack hs_jack;
  62. /*Headset jack detection DAPM pins */
  63. static struct snd_soc_jack_pin hs_jack_pins[] = {
  64. {
  65. .pin = "Headset Mic",
  66. .mask = SND_JACK_MICROPHONE,
  67. },
  68. {
  69. .pin = "Headset Stereophone",
  70. .mask = SND_JACK_HEADPHONE,
  71. },
  72. };
  73. /* SDP4430 machine DAPM */
  74. static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
  75. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  76. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  77. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  78. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  79. SND_SOC_DAPM_SPK("Earphone Spk", NULL),
  80. SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
  81. };
  82. static const struct snd_soc_dapm_route audio_map[] = {
  83. /* External Mics: MAINMIC, SUBMIC with bias*/
  84. {"MAINMIC", NULL, "Main Mic Bias"},
  85. {"SUBMIC", NULL, "Main Mic Bias"},
  86. {"Main Mic Bias", NULL, "Ext Mic"},
  87. /* External Speakers: HFL, HFR */
  88. {"Ext Spk", NULL, "HFL"},
  89. {"Ext Spk", NULL, "HFR"},
  90. /* Headset Mic: HSMIC with bias */
  91. {"HSMIC", NULL, "Headset Mic Bias"},
  92. {"Headset Mic Bias", NULL, "Headset Mic"},
  93. /* Headset Stereophone (Headphone): HSOL, HSOR */
  94. {"Headset Stereophone", NULL, "HSOL"},
  95. {"Headset Stereophone", NULL, "HSOR"},
  96. /* Earphone speaker */
  97. {"Earphone Spk", NULL, "EP"},
  98. /* Aux/FM Stereo In: AFML, AFMR */
  99. {"AFML", NULL, "Aux/FM Stereo In"},
  100. {"AFMR", NULL, "Aux/FM Stereo In"},
  101. };
  102. static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
  103. {
  104. struct snd_soc_codec *codec = rtd->codec;
  105. struct snd_soc_dapm_context *dapm = &codec->dapm;
  106. int ret;
  107. /* Add SDP4430 specific widgets */
  108. ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
  109. ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
  110. if (ret)
  111. return ret;
  112. /* Set up SDP4430 specific audio path audio_map */
  113. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  114. /* SDP4430 connected pins */
  115. snd_soc_dapm_enable_pin(dapm, "Ext Mic");
  116. snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  117. snd_soc_dapm_enable_pin(dapm, "AFML");
  118. snd_soc_dapm_enable_pin(dapm, "AFMR");
  119. snd_soc_dapm_enable_pin(dapm, "Headset Mic");
  120. snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
  121. ret = snd_soc_dapm_sync(dapm);
  122. if (ret)
  123. return ret;
  124. /* Headset jack detection */
  125. ret = snd_soc_jack_new(codec, "Headset Jack",
  126. SND_JACK_HEADSET, &hs_jack);
  127. if (ret)
  128. return ret;
  129. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  130. hs_jack_pins);
  131. if (machine_is_omap_4430sdp())
  132. twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
  133. else
  134. snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
  135. return ret;
  136. }
  137. /* Digital audio interface glue - connects codec <--> CPU */
  138. static struct snd_soc_dai_link sdp4430_dai = {
  139. .name = "TWL6040",
  140. .stream_name = "TWL6040",
  141. .cpu_dai_name ="omap-mcpdm-dai",
  142. .codec_dai_name = "twl6040-hifi",
  143. .platform_name = "omap-pcm-audio",
  144. .codec_name = "twl6040-codec",
  145. .init = sdp4430_twl6040_init,
  146. .ops = &sdp4430_ops,
  147. };
  148. /* Audio machine driver */
  149. static struct snd_soc_card snd_soc_sdp4430 = {
  150. .name = "SDP4430",
  151. .dai_link = &sdp4430_dai,
  152. .num_links = 1,
  153. };
  154. static struct platform_device *sdp4430_snd_device;
  155. static int __init sdp4430_soc_init(void)
  156. {
  157. int ret;
  158. if (!machine_is_omap_4430sdp())
  159. return -ENODEV;
  160. printk(KERN_INFO "SDP4430 SoC init\n");
  161. sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
  162. if (!sdp4430_snd_device) {
  163. printk(KERN_ERR "Platform device allocation failed\n");
  164. return -ENOMEM;
  165. }
  166. platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
  167. ret = platform_device_add(sdp4430_snd_device);
  168. if (ret)
  169. goto err;
  170. return 0;
  171. err:
  172. printk(KERN_ERR "Unable to add platform device\n");
  173. platform_device_put(sdp4430_snd_device);
  174. return ret;
  175. }
  176. module_init(sdp4430_soc_init);
  177. static void __exit sdp4430_soc_exit(void)
  178. {
  179. platform_device_unregister(sdp4430_snd_device);
  180. }
  181. module_exit(sdp4430_soc_exit);
  182. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  183. MODULE_DESCRIPTION("ALSA SoC SDP4430");
  184. MODULE_LICENSE("GPL");