sdp3430.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 Jack",
  82. .mask = SND_JACK_HEADSET,
  83. },
  84. };
  85. /* Headset jack detection gpios */
  86. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  87. {
  88. .gpio = (OMAP_MAX_GPIO_LINES + 2),
  89. .name = "hsdet-gpio",
  90. .report = SND_JACK_HEADSET,
  91. .debounce_time = 200,
  92. },
  93. };
  94. /* SDP3430 machine DAPM */
  95. static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
  96. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  97. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  98. SND_SOC_DAPM_HP("Headset Jack", NULL),
  99. };
  100. static const struct snd_soc_dapm_route audio_map[] = {
  101. /* External Mics: MAINMIC, SUBMIC with bias*/
  102. {"MAINMIC", NULL, "Mic Bias 1"},
  103. {"SUBMIC", NULL, "Mic Bias 2"},
  104. {"Mic Bias 1", NULL, "Ext Mic"},
  105. {"Mic Bias 2", NULL, "Ext Mic"},
  106. /* External Speakers: HFL, HFR */
  107. {"Ext Spk", NULL, "HFL"},
  108. {"Ext Spk", NULL, "HFR"},
  109. /* Headset: HSMIC (with bias), HSOL, HSOR */
  110. {"Headset Jack", NULL, "HSOL"},
  111. {"Headset Jack", NULL, "HSOR"},
  112. {"HSMIC", NULL, "Headset Mic Bias"},
  113. {"Headset Mic Bias", NULL, "Headset Jack"},
  114. };
  115. static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
  116. {
  117. int ret;
  118. /* Add SDP3430 specific widgets */
  119. ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
  120. ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
  121. if (ret)
  122. return ret;
  123. /* Set up SDP3430 specific audio path audio_map */
  124. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  125. /* SDP3430 connected pins */
  126. snd_soc_dapm_enable_pin(codec, "Ext Mic");
  127. snd_soc_dapm_enable_pin(codec, "Ext Spk");
  128. snd_soc_dapm_disable_pin(codec, "Headset Jack");
  129. /* TWL4030 not connected pins */
  130. snd_soc_dapm_nc_pin(codec, "AUXL");
  131. snd_soc_dapm_nc_pin(codec, "AUXR");
  132. snd_soc_dapm_nc_pin(codec, "CARKITMIC");
  133. snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
  134. snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
  135. snd_soc_dapm_nc_pin(codec, "OUTL");
  136. snd_soc_dapm_nc_pin(codec, "OUTR");
  137. snd_soc_dapm_nc_pin(codec, "EARPIECE");
  138. snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
  139. snd_soc_dapm_nc_pin(codec, "PREDRIVER");
  140. snd_soc_dapm_nc_pin(codec, "CARKITL");
  141. snd_soc_dapm_nc_pin(codec, "CARKITR");
  142. ret = snd_soc_dapm_sync(codec);
  143. if (ret)
  144. return ret;
  145. /* Headset jack detection */
  146. ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack",
  147. SND_JACK_HEADSET, &hs_jack);
  148. if (ret)
  149. return ret;
  150. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  151. hs_jack_pins);
  152. if (ret)
  153. return ret;
  154. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  155. hs_jack_gpios);
  156. return ret;
  157. }
  158. /* Digital audio interface glue - connects codec <--> CPU */
  159. static struct snd_soc_dai_link sdp3430_dai = {
  160. .name = "TWL4030",
  161. .stream_name = "TWL4030",
  162. .cpu_dai = &omap_mcbsp_dai[0],
  163. .codec_dai = &twl4030_dai,
  164. .init = sdp3430_twl4030_init,
  165. .ops = &sdp3430_ops,
  166. };
  167. /* Audio machine driver */
  168. static struct snd_soc_card snd_soc_sdp3430 = {
  169. .name = "SDP3430",
  170. .platform = &omap_soc_platform,
  171. .dai_link = &sdp3430_dai,
  172. .num_links = 1,
  173. };
  174. /* Audio subsystem */
  175. static struct snd_soc_device sdp3430_snd_devdata = {
  176. .card = &snd_soc_sdp3430,
  177. .codec_dev = &soc_codec_dev_twl4030,
  178. };
  179. static struct platform_device *sdp3430_snd_device;
  180. static int __init sdp3430_soc_init(void)
  181. {
  182. int ret;
  183. if (!machine_is_omap_3430sdp()) {
  184. pr_debug("Not SDP3430!\n");
  185. return -ENODEV;
  186. }
  187. printk(KERN_INFO "SDP3430 SoC init\n");
  188. sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
  189. if (!sdp3430_snd_device) {
  190. printk(KERN_ERR "Platform device allocation failed\n");
  191. return -ENOMEM;
  192. }
  193. platform_set_drvdata(sdp3430_snd_device, &sdp3430_snd_devdata);
  194. sdp3430_snd_devdata.dev = &sdp3430_snd_device->dev;
  195. *(unsigned int *)sdp3430_dai.cpu_dai->private_data = 1; /* McBSP2 */
  196. ret = platform_device_add(sdp3430_snd_device);
  197. if (ret)
  198. goto err1;
  199. return 0;
  200. err1:
  201. printk(KERN_ERR "Unable to add platform device\n");
  202. platform_device_put(sdp3430_snd_device);
  203. return ret;
  204. }
  205. module_init(sdp3430_soc_init);
  206. static void __exit sdp3430_soc_exit(void)
  207. {
  208. snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  209. hs_jack_gpios);
  210. platform_device_unregister(sdp3430_snd_device);
  211. }
  212. module_exit(sdp3430_soc_exit);
  213. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  214. MODULE_DESCRIPTION("ALSA SoC SDP3430");
  215. MODULE_LICENSE("GPL");