sdp4430.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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-dmic.h"
  33. #include "omap-mcpdm.h"
  34. #include "omap-pcm.h"
  35. #include "../codecs/twl6040.h"
  36. static int sdp4430_hw_params(struct snd_pcm_substream *substream,
  37. struct snd_pcm_hw_params *params)
  38. {
  39. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  40. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  41. int clk_id, freq;
  42. int ret;
  43. clk_id = twl6040_get_clk_id(rtd->codec);
  44. if (clk_id == TWL6040_SYSCLK_SEL_HPPLL)
  45. freq = 38400000;
  46. else if (clk_id == TWL6040_SYSCLK_SEL_LPPLL)
  47. freq = 32768;
  48. else
  49. return -EINVAL;
  50. /* set the codec mclk */
  51. ret = snd_soc_dai_set_sysclk(codec_dai, clk_id, freq,
  52. SND_SOC_CLOCK_IN);
  53. if (ret) {
  54. printk(KERN_ERR "can't set codec system clock\n");
  55. return ret;
  56. }
  57. return ret;
  58. }
  59. static struct snd_soc_ops sdp4430_ops = {
  60. .hw_params = sdp4430_hw_params,
  61. };
  62. static int sdp4430_dmic_hw_params(struct snd_pcm_substream *substream,
  63. struct snd_pcm_hw_params *params)
  64. {
  65. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  66. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  67. int ret = 0;
  68. ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_SYSCLK_PAD_CLKS,
  69. 19200000, SND_SOC_CLOCK_IN);
  70. if (ret < 0) {
  71. printk(KERN_ERR "can't set DMIC cpu system clock\n");
  72. return ret;
  73. }
  74. ret = snd_soc_dai_set_sysclk(cpu_dai, OMAP_DMIC_ABE_DMIC_CLK, 2400000,
  75. SND_SOC_CLOCK_OUT);
  76. if (ret < 0) {
  77. printk(KERN_ERR "can't set DMIC output clock\n");
  78. return ret;
  79. }
  80. return 0;
  81. }
  82. static struct snd_soc_ops sdp4430_dmic_ops = {
  83. .hw_params = sdp4430_dmic_hw_params,
  84. };
  85. /* Headset jack */
  86. static struct snd_soc_jack hs_jack;
  87. /*Headset jack detection DAPM pins */
  88. static struct snd_soc_jack_pin hs_jack_pins[] = {
  89. {
  90. .pin = "Headset Mic",
  91. .mask = SND_JACK_MICROPHONE,
  92. },
  93. {
  94. .pin = "Headset Stereophone",
  95. .mask = SND_JACK_HEADPHONE,
  96. },
  97. };
  98. /* SDP4430 machine DAPM */
  99. static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
  100. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  101. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  102. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  103. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  104. SND_SOC_DAPM_SPK("Earphone Spk", NULL),
  105. SND_SOC_DAPM_INPUT("FM Stereo In"),
  106. };
  107. static const struct snd_soc_dapm_route audio_map[] = {
  108. /* External Mics: MAINMIC, SUBMIC with bias*/
  109. {"MAINMIC", NULL, "Main Mic Bias"},
  110. {"SUBMIC", NULL, "Main Mic Bias"},
  111. {"Main Mic Bias", NULL, "Ext Mic"},
  112. /* External Speakers: HFL, HFR */
  113. {"Ext Spk", NULL, "HFL"},
  114. {"Ext Spk", NULL, "HFR"},
  115. /* Headset Mic: HSMIC with bias */
  116. {"HSMIC", NULL, "Headset Mic Bias"},
  117. {"Headset Mic Bias", NULL, "Headset Mic"},
  118. /* Headset Stereophone (Headphone): HSOL, HSOR */
  119. {"Headset Stereophone", NULL, "HSOL"},
  120. {"Headset Stereophone", NULL, "HSOR"},
  121. /* Earphone speaker */
  122. {"Earphone Spk", NULL, "EP"},
  123. /* Aux/FM Stereo In: AFML, AFMR */
  124. {"AFML", NULL, "FM Stereo In"},
  125. {"AFMR", NULL, "FM Stereo In"},
  126. };
  127. static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
  128. {
  129. struct snd_soc_codec *codec = rtd->codec;
  130. int ret, hs_trim;
  131. /*
  132. * Configure McPDM offset cancellation based on the HSOTRIM value from
  133. * twl6040.
  134. */
  135. hs_trim = twl6040_get_trim_value(codec, TWL6040_TRIM_HSOTRIM);
  136. omap_mcpdm_configure_dn_offsets(rtd, TWL6040_HSF_TRIM_LEFT(hs_trim),
  137. TWL6040_HSF_TRIM_RIGHT(hs_trim));
  138. /* Headset jack detection */
  139. ret = snd_soc_jack_new(codec, "Headset Jack",
  140. SND_JACK_HEADSET, &hs_jack);
  141. if (ret)
  142. return ret;
  143. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  144. hs_jack_pins);
  145. if (machine_is_omap_4430sdp())
  146. twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
  147. else
  148. snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
  149. return ret;
  150. }
  151. static const struct snd_soc_dapm_widget sdp4430_dmic_dapm_widgets[] = {
  152. SND_SOC_DAPM_MIC("Digital Mic", NULL),
  153. };
  154. static const struct snd_soc_dapm_route dmic_audio_map[] = {
  155. {"DMic", NULL, "Digital Mic1 Bias"},
  156. {"Digital Mic1 Bias", NULL, "Digital Mic"},
  157. };
  158. static int sdp4430_dmic_init(struct snd_soc_pcm_runtime *rtd)
  159. {
  160. struct snd_soc_codec *codec = rtd->codec;
  161. struct snd_soc_dapm_context *dapm = &codec->dapm;
  162. int ret;
  163. ret = snd_soc_dapm_new_controls(dapm, sdp4430_dmic_dapm_widgets,
  164. ARRAY_SIZE(sdp4430_dmic_dapm_widgets));
  165. if (ret)
  166. return ret;
  167. return snd_soc_dapm_add_routes(dapm, dmic_audio_map,
  168. ARRAY_SIZE(dmic_audio_map));
  169. }
  170. /* Digital audio interface glue - connects codec <--> CPU */
  171. static struct snd_soc_dai_link sdp4430_dai[] = {
  172. {
  173. .name = "TWL6040",
  174. .stream_name = "TWL6040",
  175. .cpu_dai_name = "omap-mcpdm",
  176. .codec_dai_name = "twl6040-legacy",
  177. .platform_name = "omap-pcm-audio",
  178. .codec_name = "twl6040-codec",
  179. .init = sdp4430_twl6040_init,
  180. .ops = &sdp4430_ops,
  181. },
  182. {
  183. .name = "DMIC",
  184. .stream_name = "DMIC Capture",
  185. .cpu_dai_name = "omap-dmic",
  186. .codec_dai_name = "dmic-hifi",
  187. .platform_name = "omap-pcm-audio",
  188. .codec_name = "dmic-codec",
  189. .init = sdp4430_dmic_init,
  190. .ops = &sdp4430_dmic_ops,
  191. },
  192. };
  193. /* Audio machine driver */
  194. static struct snd_soc_card snd_soc_sdp4430 = {
  195. .name = "SDP4430",
  196. .owner = THIS_MODULE,
  197. .dai_link = sdp4430_dai,
  198. .num_links = ARRAY_SIZE(sdp4430_dai),
  199. .dapm_widgets = sdp4430_twl6040_dapm_widgets,
  200. .num_dapm_widgets = ARRAY_SIZE(sdp4430_twl6040_dapm_widgets),
  201. .dapm_routes = audio_map,
  202. .num_dapm_routes = ARRAY_SIZE(audio_map),
  203. };
  204. static struct platform_device *sdp4430_snd_device;
  205. static int __init sdp4430_soc_init(void)
  206. {
  207. int ret;
  208. if (!machine_is_omap_4430sdp())
  209. return -ENODEV;
  210. printk(KERN_INFO "SDP4430 SoC init\n");
  211. sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
  212. if (!sdp4430_snd_device) {
  213. printk(KERN_ERR "Platform device allocation failed\n");
  214. return -ENOMEM;
  215. }
  216. platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
  217. ret = platform_device_add(sdp4430_snd_device);
  218. if (ret)
  219. goto err;
  220. return 0;
  221. err:
  222. printk(KERN_ERR "Unable to add platform device\n");
  223. platform_device_put(sdp4430_snd_device);
  224. return ret;
  225. }
  226. module_init(sdp4430_soc_init);
  227. static void __exit sdp4430_soc_exit(void)
  228. {
  229. platform_device_unregister(sdp4430_snd_device);
  230. }
  231. module_exit(sdp4430_soc_exit);
  232. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  233. MODULE_DESCRIPTION("ALSA SoC SDP4430");
  234. MODULE_LICENSE("GPL");