sdp4430.c 5.4 KB

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