sdp4430.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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 twl6040_power_mode;
  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. if (twl6040_power_mode) {
  43. clk_id = TWL6040_SYSCLK_SEL_HPPLL;
  44. freq = 38400000;
  45. } else {
  46. clk_id = TWL6040_SYSCLK_SEL_LPPLL;
  47. freq = 32768;
  48. }
  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. static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
  75. struct snd_ctl_elem_value *ucontrol)
  76. {
  77. ucontrol->value.integer.value[0] = twl6040_power_mode;
  78. return 0;
  79. }
  80. static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol,
  81. struct snd_ctl_elem_value *ucontrol)
  82. {
  83. if (twl6040_power_mode == ucontrol->value.integer.value[0])
  84. return 0;
  85. twl6040_power_mode = ucontrol->value.integer.value[0];
  86. return 1;
  87. }
  88. static const char *power_texts[] = {"Low-Power", "High-Performance"};
  89. static const struct soc_enum sdp4430_enum[] = {
  90. SOC_ENUM_SINGLE_EXT(2, power_texts),
  91. };
  92. static const struct snd_kcontrol_new sdp4430_controls[] = {
  93. SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0],
  94. sdp4430_get_power_mode, sdp4430_set_power_mode),
  95. };
  96. /* SDP4430 machine DAPM */
  97. static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
  98. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  99. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  100. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  101. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  102. SND_SOC_DAPM_SPK("Earphone Spk", NULL),
  103. SND_SOC_DAPM_INPUT("Aux/FM Stereo In"),
  104. };
  105. static const struct snd_soc_dapm_route audio_map[] = {
  106. /* External Mics: MAINMIC, SUBMIC with bias*/
  107. {"MAINMIC", NULL, "Main Mic Bias"},
  108. {"SUBMIC", NULL, "Main Mic Bias"},
  109. {"Main Mic Bias", NULL, "Ext Mic"},
  110. /* External Speakers: HFL, HFR */
  111. {"Ext Spk", NULL, "HFL"},
  112. {"Ext Spk", NULL, "HFR"},
  113. /* Headset Mic: HSMIC with bias */
  114. {"HSMIC", NULL, "Headset Mic Bias"},
  115. {"Headset Mic Bias", NULL, "Headset Mic"},
  116. /* Headset Stereophone (Headphone): HSOL, HSOR */
  117. {"Headset Stereophone", NULL, "HSOL"},
  118. {"Headset Stereophone", NULL, "HSOR"},
  119. /* Earphone speaker */
  120. {"Earphone Spk", NULL, "EP"},
  121. /* Aux/FM Stereo In: AFML, AFMR */
  122. {"AFML", NULL, "Aux/FM Stereo In"},
  123. {"AFMR", NULL, "Aux/FM Stereo In"},
  124. };
  125. static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
  126. {
  127. struct snd_soc_codec *codec = rtd->codec;
  128. struct snd_soc_dapm_context *dapm = &codec->dapm;
  129. int ret;
  130. /* Add SDP4430 specific controls */
  131. ret = snd_soc_add_controls(codec, sdp4430_controls,
  132. ARRAY_SIZE(sdp4430_controls));
  133. if (ret)
  134. return ret;
  135. /* Add SDP4430 specific widgets */
  136. ret = snd_soc_dapm_new_controls(dapm, sdp4430_twl6040_dapm_widgets,
  137. ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
  138. if (ret)
  139. return ret;
  140. /* Set up SDP4430 specific audio path audio_map */
  141. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  142. /* SDP4430 connected pins */
  143. snd_soc_dapm_enable_pin(dapm, "Ext Mic");
  144. snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  145. snd_soc_dapm_enable_pin(dapm, "AFML");
  146. snd_soc_dapm_enable_pin(dapm, "AFMR");
  147. snd_soc_dapm_enable_pin(dapm, "Headset Mic");
  148. snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
  149. ret = snd_soc_dapm_sync(dapm);
  150. if (ret)
  151. return ret;
  152. /* Headset jack detection */
  153. ret = snd_soc_jack_new(codec, "Headset Jack",
  154. SND_JACK_HEADSET, &hs_jack);
  155. if (ret)
  156. return ret;
  157. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  158. hs_jack_pins);
  159. if (machine_is_omap_4430sdp())
  160. twl6040_hs_jack_detect(codec, &hs_jack, SND_JACK_HEADSET);
  161. else
  162. snd_soc_jack_report(&hs_jack, SND_JACK_HEADSET, SND_JACK_HEADSET);
  163. return ret;
  164. }
  165. /* Digital audio interface glue - connects codec <--> CPU */
  166. static struct snd_soc_dai_link sdp4430_dai = {
  167. .name = "TWL6040",
  168. .stream_name = "TWL6040",
  169. .cpu_dai_name ="omap-mcpdm-dai",
  170. .codec_dai_name = "twl6040-hifi",
  171. .platform_name = "omap-pcm-audio",
  172. .codec_name = "twl6040-codec",
  173. .init = sdp4430_twl6040_init,
  174. .ops = &sdp4430_ops,
  175. };
  176. /* Audio machine driver */
  177. static struct snd_soc_card snd_soc_sdp4430 = {
  178. .name = "SDP4430",
  179. .dai_link = &sdp4430_dai,
  180. .num_links = 1,
  181. };
  182. static struct platform_device *sdp4430_snd_device;
  183. static int __init sdp4430_soc_init(void)
  184. {
  185. int ret;
  186. if (!machine_is_omap_4430sdp())
  187. return -ENODEV;
  188. printk(KERN_INFO "SDP4430 SoC init\n");
  189. sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
  190. if (!sdp4430_snd_device) {
  191. printk(KERN_ERR "Platform device allocation failed\n");
  192. return -ENOMEM;
  193. }
  194. platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
  195. ret = platform_device_add(sdp4430_snd_device);
  196. if (ret)
  197. goto err;
  198. /* Codec starts in HP mode */
  199. twl6040_power_mode = 1;
  200. return 0;
  201. err:
  202. printk(KERN_ERR "Unable to add platform device\n");
  203. platform_device_put(sdp4430_snd_device);
  204. return ret;
  205. }
  206. module_init(sdp4430_soc_init);
  207. static void __exit sdp4430_soc_exit(void)
  208. {
  209. platform_device_unregister(sdp4430_snd_device);
  210. }
  211. module_exit(sdp4430_soc_exit);
  212. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  213. MODULE_DESCRIPTION("ALSA SoC SDP4430");
  214. MODULE_LICENSE("GPL");