sdp4430.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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/soc-dapm.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. static int sdp4430_get_power_mode(struct snd_kcontrol *kcontrol,
  61. struct snd_ctl_elem_value *ucontrol)
  62. {
  63. ucontrol->value.integer.value[0] = twl6040_power_mode;
  64. return 0;
  65. }
  66. static int sdp4430_set_power_mode(struct snd_kcontrol *kcontrol,
  67. struct snd_ctl_elem_value *ucontrol)
  68. {
  69. if (twl6040_power_mode == ucontrol->value.integer.value[0])
  70. return 0;
  71. twl6040_power_mode = ucontrol->value.integer.value[0];
  72. return 1;
  73. }
  74. static const char *power_texts[] = {"Low-Power", "High-Performance"};
  75. static const struct soc_enum sdp4430_enum[] = {
  76. SOC_ENUM_SINGLE_EXT(2, power_texts),
  77. };
  78. static const struct snd_kcontrol_new sdp4430_controls[] = {
  79. SOC_ENUM_EXT("TWL6040 Power Mode", sdp4430_enum[0],
  80. sdp4430_get_power_mode, sdp4430_set_power_mode),
  81. };
  82. /* SDP4430 machine DAPM */
  83. static const struct snd_soc_dapm_widget sdp4430_twl6040_dapm_widgets[] = {
  84. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  85. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  86. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  87. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  88. SND_SOC_DAPM_SPK("Earphone Spk", NULL),
  89. };
  90. static const struct snd_soc_dapm_route audio_map[] = {
  91. /* External Mics: MAINMIC, SUBMIC with bias*/
  92. {"MAINMIC", NULL, "Main Mic Bias"},
  93. {"SUBMIC", NULL, "Main Mic Bias"},
  94. {"Main Mic Bias", NULL, "Ext Mic"},
  95. /* External Speakers: HFL, HFR */
  96. {"Ext Spk", NULL, "HFL"},
  97. {"Ext Spk", NULL, "HFR"},
  98. /* Headset Mic: HSMIC with bias */
  99. {"HSMIC", NULL, "Headset Mic Bias"},
  100. {"Headset Mic Bias", NULL, "Headset Mic"},
  101. /* Headset Stereophone (Headphone): HSOL, HSOR */
  102. {"Headset Stereophone", NULL, "HSOL"},
  103. {"Headset Stereophone", NULL, "HSOR"},
  104. /* Earphone speaker */
  105. {"Earphone Spk", NULL, "EP"},
  106. };
  107. static int sdp4430_twl6040_init(struct snd_soc_pcm_runtime *rtd)
  108. {
  109. struct snd_soc_codec *codec = rtd->codec;
  110. int ret;
  111. /* Add SDP4430 specific controls */
  112. ret = snd_soc_add_controls(codec, sdp4430_controls,
  113. ARRAY_SIZE(sdp4430_controls));
  114. if (ret)
  115. return ret;
  116. /* Add SDP4430 specific widgets */
  117. ret = snd_soc_dapm_new_controls(codec, sdp4430_twl6040_dapm_widgets,
  118. ARRAY_SIZE(sdp4430_twl6040_dapm_widgets));
  119. if (ret)
  120. return ret;
  121. /* Set up SDP4430 specific audio path audio_map */
  122. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  123. /* SDP4430 connected pins */
  124. snd_soc_dapm_enable_pin(codec, "Ext Mic");
  125. snd_soc_dapm_enable_pin(codec, "Ext Spk");
  126. snd_soc_dapm_enable_pin(codec, "Headset Mic");
  127. snd_soc_dapm_enable_pin(codec, "Headset Stereophone");
  128. /* TWL6040 not connected pins */
  129. snd_soc_dapm_nc_pin(codec, "AFML");
  130. snd_soc_dapm_nc_pin(codec, "AFMR");
  131. ret = snd_soc_dapm_sync(codec);
  132. return ret;
  133. }
  134. /* Digital audio interface glue - connects codec <--> CPU */
  135. static struct snd_soc_dai_link sdp4430_dai = {
  136. .name = "TWL6040",
  137. .stream_name = "TWL6040",
  138. .cpu_dai_name ="omap-mcpdm-dai",
  139. .codec_dai_name = "twl6040-hifi",
  140. .platform_name = "omap-pcm-audio",
  141. .codec_name = "twl6040-codec",
  142. .init = sdp4430_twl6040_init,
  143. .ops = &sdp4430_ops,
  144. };
  145. /* Audio machine driver */
  146. static struct snd_soc_card snd_soc_sdp4430 = {
  147. .name = "SDP4430",
  148. .dai_link = &sdp4430_dai,
  149. .num_links = 1,
  150. };
  151. static struct platform_device *sdp4430_snd_device;
  152. static int __init sdp4430_soc_init(void)
  153. {
  154. int ret;
  155. if (!machine_is_omap_4430sdp())
  156. return -ENODEV;
  157. printk(KERN_INFO "SDP4430 SoC init\n");
  158. sdp4430_snd_device = platform_device_alloc("soc-audio", -1);
  159. if (!sdp4430_snd_device) {
  160. printk(KERN_ERR "Platform device allocation failed\n");
  161. return -ENOMEM;
  162. }
  163. platform_set_drvdata(sdp4430_snd_device, &snd_soc_sdp4430);
  164. ret = platform_device_add(sdp4430_snd_device);
  165. if (ret)
  166. goto err;
  167. /* Codec starts in HP mode */
  168. twl6040_power_mode = 1;
  169. return 0;
  170. err:
  171. printk(KERN_ERR "Unable to add platform device\n");
  172. platform_device_put(sdp4430_snd_device);
  173. return ret;
  174. }
  175. module_init(sdp4430_soc_init);
  176. static void __exit sdp4430_soc_exit(void)
  177. {
  178. platform_device_unregister(sdp4430_snd_device);
  179. }
  180. module_exit(sdp4430_soc_exit);
  181. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  182. MODULE_DESCRIPTION("ALSA SoC SDP4430");
  183. MODULE_LICENSE("GPL");