sdp3430.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * sdp3430.c -- SoC audio for TI OMAP3430 SDP
  3. *
  4. * Author: Misael Lopez Cruz <x0052729@ti.com>
  5. *
  6. * Based on:
  7. * Author: Steve Sakoman <steve@sakoman.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  21. * 02110-1301 USA
  22. *
  23. */
  24. #include <linux/clk.h>
  25. #include <linux/platform_device.h>
  26. #include <sound/core.h>
  27. #include <sound/pcm.h>
  28. #include <sound/soc.h>
  29. #include <sound/soc-dapm.h>
  30. #include <sound/jack.h>
  31. #include <asm/mach-types.h>
  32. #include <mach/hardware.h>
  33. #include <mach/gpio.h>
  34. #include <mach/mcbsp.h>
  35. #include "omap-mcbsp.h"
  36. #include "omap-pcm.h"
  37. #include "../codecs/twl4030.h"
  38. static struct snd_soc_card snd_soc_sdp3430;
  39. static int sdp3430_hw_params(struct snd_pcm_substream *substream,
  40. struct snd_pcm_hw_params *params)
  41. {
  42. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  43. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  44. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  45. int ret;
  46. /* Set codec DAI configuration */
  47. ret = snd_soc_dai_set_fmt(codec_dai,
  48. SND_SOC_DAIFMT_I2S |
  49. SND_SOC_DAIFMT_NB_NF |
  50. SND_SOC_DAIFMT_CBM_CFM);
  51. if (ret < 0) {
  52. printk(KERN_ERR "can't set codec DAI configuration\n");
  53. return ret;
  54. }
  55. /* Set cpu DAI configuration */
  56. ret = snd_soc_dai_set_fmt(cpu_dai,
  57. SND_SOC_DAIFMT_I2S |
  58. SND_SOC_DAIFMT_NB_NF |
  59. SND_SOC_DAIFMT_CBM_CFM);
  60. if (ret < 0) {
  61. printk(KERN_ERR "can't set cpu DAI configuration\n");
  62. return ret;
  63. }
  64. /* Set the codec system clock for DAC and ADC */
  65. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  66. SND_SOC_CLOCK_IN);
  67. if (ret < 0) {
  68. printk(KERN_ERR "can't set codec system clock\n");
  69. return ret;
  70. }
  71. return 0;
  72. }
  73. static struct snd_soc_ops sdp3430_ops = {
  74. .hw_params = sdp3430_hw_params,
  75. };
  76. /* Headset jack */
  77. static struct snd_soc_jack hs_jack;
  78. /* Headset jack detection DAPM pins */
  79. static struct snd_soc_jack_pin hs_jack_pins[] = {
  80. {
  81. .pin = "Headset Mic",
  82. .mask = SND_JACK_MICROPHONE,
  83. },
  84. {
  85. .pin = "Headset Stereophone",
  86. .mask = SND_JACK_HEADPHONE,
  87. },
  88. };
  89. /* Headset jack detection gpios */
  90. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  91. {
  92. .gpio = (OMAP_MAX_GPIO_LINES + 2),
  93. .name = "hsdet-gpio",
  94. .report = SND_JACK_HEADSET,
  95. .debounce_time = 200,
  96. },
  97. };
  98. /* SDP3430 machine DAPM */
  99. static const struct snd_soc_dapm_widget sdp3430_twl4030_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. };
  105. static const struct snd_soc_dapm_route audio_map[] = {
  106. /* External Mics: MAINMIC, SUBMIC with bias*/
  107. {"MAINMIC", NULL, "Mic Bias 1"},
  108. {"SUBMIC", NULL, "Mic Bias 2"},
  109. {"Mic Bias 1", NULL, "Ext Mic"},
  110. {"Mic Bias 2", NULL, "Ext Mic"},
  111. /* External Speakers: HFL, HFR */
  112. {"Ext Spk", NULL, "HFL"},
  113. {"Ext Spk", NULL, "HFR"},
  114. /* Headset Mic: HSMIC with bias */
  115. {"HSMIC", NULL, "Headset Mic Bias"},
  116. {"Headset Mic Bias", NULL, "Headset Mic"},
  117. /* Headset Stereophone (Headphone): HSOL, HSOR */
  118. {"Headset Stereophone", NULL, "HSOL"},
  119. {"Headset Stereophone", NULL, "HSOR"},
  120. };
  121. static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
  122. {
  123. int ret;
  124. /* Add SDP3430 specific widgets */
  125. ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
  126. ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
  127. if (ret)
  128. return ret;
  129. /* Set up SDP3430 specific audio path audio_map */
  130. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  131. /* SDP3430 connected pins */
  132. snd_soc_dapm_enable_pin(codec, "Ext Mic");
  133. snd_soc_dapm_enable_pin(codec, "Ext Spk");
  134. snd_soc_dapm_disable_pin(codec, "Headset Mic");
  135. snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
  136. /* TWL4030 not connected pins */
  137. snd_soc_dapm_nc_pin(codec, "AUXL");
  138. snd_soc_dapm_nc_pin(codec, "AUXR");
  139. snd_soc_dapm_nc_pin(codec, "CARKITMIC");
  140. snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
  141. snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
  142. snd_soc_dapm_nc_pin(codec, "OUTL");
  143. snd_soc_dapm_nc_pin(codec, "OUTR");
  144. snd_soc_dapm_nc_pin(codec, "EARPIECE");
  145. snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
  146. snd_soc_dapm_nc_pin(codec, "PREDRIVER");
  147. snd_soc_dapm_nc_pin(codec, "CARKITL");
  148. snd_soc_dapm_nc_pin(codec, "CARKITR");
  149. ret = snd_soc_dapm_sync(codec);
  150. if (ret)
  151. return ret;
  152. /* Headset jack detection */
  153. ret = snd_soc_jack_new(&snd_soc_sdp3430, "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 (ret)
  160. return ret;
  161. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  162. hs_jack_gpios);
  163. return ret;
  164. }
  165. /* Digital audio interface glue - connects codec <--> CPU */
  166. static struct snd_soc_dai_link sdp3430_dai = {
  167. .name = "TWL4030",
  168. .stream_name = "TWL4030",
  169. .cpu_dai = &omap_mcbsp_dai[0],
  170. .codec_dai = &twl4030_dai,
  171. .init = sdp3430_twl4030_init,
  172. .ops = &sdp3430_ops,
  173. };
  174. /* Audio machine driver */
  175. static struct snd_soc_card snd_soc_sdp3430 = {
  176. .name = "SDP3430",
  177. .platform = &omap_soc_platform,
  178. .dai_link = &sdp3430_dai,
  179. .num_links = 1,
  180. };
  181. /* Audio subsystem */
  182. static struct snd_soc_device sdp3430_snd_devdata = {
  183. .card = &snd_soc_sdp3430,
  184. .codec_dev = &soc_codec_dev_twl4030,
  185. };
  186. static struct platform_device *sdp3430_snd_device;
  187. static int __init sdp3430_soc_init(void)
  188. {
  189. int ret;
  190. if (!machine_is_omap_3430sdp()) {
  191. pr_debug("Not SDP3430!\n");
  192. return -ENODEV;
  193. }
  194. printk(KERN_INFO "SDP3430 SoC init\n");
  195. sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
  196. if (!sdp3430_snd_device) {
  197. printk(KERN_ERR "Platform device allocation failed\n");
  198. return -ENOMEM;
  199. }
  200. platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata);
  201. sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev;
  202. *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */
  203. ret = platform_device_add(sdp3430_snd_device);
  204. if (ret)
  205. goto err1;
  206. return 0;
  207. err1:
  208. printk(KERN_ERR "Unable to add platform device\n");
  209. platform_device_put(sdp3430_snd_device);
  210. return ret;
  211. }
  212. module_init(sdp3430_soc_init);
  213. static void __exit sdp3430_soc_exit(void)
  214. {
  215. snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  216. hs_jack_gpios);
  217. platform_device_unregister(sdp3430_snd_device);
  218. }
  219. module_exit(sdp3430_soc_exit);
  220. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  221. MODULE_DESCRIPTION("ALSA SoC SDP3430");
  222. MODULE_LICENSE("GPL");