sdp4430.c 6.6 KB

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