sdp3430.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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 <linux/i2c/twl.h>
  27. #include <sound/core.h>
  28. #include <sound/pcm.h>
  29. #include <sound/soc.h>
  30. #include <sound/jack.h>
  31. #include <asm/mach-types.h>
  32. #include <mach/hardware.h>
  33. #include <mach/gpio.h>
  34. #include <plat/mcbsp.h>
  35. /* Register descriptions for twl4030 codec part */
  36. #include <linux/mfd/twl4030-audio.h>
  37. #include "omap-mcbsp.h"
  38. #include "omap-pcm.h"
  39. /* TWL4030 PMBR1 Register */
  40. #define TWL4030_INTBR_PMBR1 0x0D
  41. /* TWL4030 PMBR1 Register GPIO6 mux bit */
  42. #define TWL4030_GPIO6_PWM0_MUTE(value) (value << 2)
  43. static struct snd_soc_card snd_soc_sdp3430;
  44. static int sdp3430_hw_params(struct snd_pcm_substream *substream,
  45. struct snd_pcm_hw_params *params)
  46. {
  47. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  48. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  49. int ret;
  50. /* Set the codec system clock for DAC and ADC */
  51. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  52. SND_SOC_CLOCK_IN);
  53. if (ret < 0) {
  54. printk(KERN_ERR "can't set codec system clock\n");
  55. return ret;
  56. }
  57. return 0;
  58. }
  59. static struct snd_soc_ops sdp3430_ops = {
  60. .hw_params = sdp3430_hw_params,
  61. };
  62. static int sdp3430_hw_voice_params(struct snd_pcm_substream *substream,
  63. struct snd_pcm_hw_params *params)
  64. {
  65. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  66. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  67. int ret;
  68. /* Set the codec system clock for DAC and ADC */
  69. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  70. SND_SOC_CLOCK_IN);
  71. if (ret < 0) {
  72. printk(KERN_ERR "can't set codec system clock\n");
  73. return ret;
  74. }
  75. return 0;
  76. }
  77. static struct snd_soc_ops sdp3430_voice_ops = {
  78. .hw_params = sdp3430_hw_voice_params,
  79. };
  80. /* Headset jack */
  81. static struct snd_soc_jack hs_jack;
  82. /* Headset jack detection DAPM pins */
  83. static struct snd_soc_jack_pin hs_jack_pins[] = {
  84. {
  85. .pin = "Headset Mic",
  86. .mask = SND_JACK_MICROPHONE,
  87. },
  88. {
  89. .pin = "Headset Stereophone",
  90. .mask = SND_JACK_HEADPHONE,
  91. },
  92. };
  93. /* Headset jack detection gpios */
  94. static struct snd_soc_jack_gpio hs_jack_gpios[] = {
  95. {
  96. .gpio = (OMAP_MAX_GPIO_LINES + 2),
  97. .name = "hsdet-gpio",
  98. .report = SND_JACK_HEADSET,
  99. .debounce_time = 200,
  100. },
  101. };
  102. /* SDP3430 machine DAPM */
  103. static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
  104. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  105. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  106. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  107. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  108. };
  109. static const struct snd_soc_dapm_route audio_map[] = {
  110. /* External Mics: MAINMIC, SUBMIC with bias*/
  111. {"MAINMIC", NULL, "Mic Bias 1"},
  112. {"SUBMIC", NULL, "Mic Bias 2"},
  113. {"Mic Bias 1", NULL, "Ext Mic"},
  114. {"Mic Bias 2", NULL, "Ext Mic"},
  115. /* External Speakers: HFL, HFR */
  116. {"Ext Spk", NULL, "HFL"},
  117. {"Ext Spk", NULL, "HFR"},
  118. /* Headset Mic: HSMIC with bias */
  119. {"HSMIC", NULL, "Headset Mic Bias"},
  120. {"Headset Mic Bias", NULL, "Headset Mic"},
  121. /* Headset Stereophone (Headphone): HSOL, HSOR */
  122. {"Headset Stereophone", NULL, "HSOL"},
  123. {"Headset Stereophone", NULL, "HSOR"},
  124. };
  125. static int sdp3430_twl4030_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 SDP3430 specific widgets */
  131. ret = snd_soc_dapm_new_controls(dapm, sdp3430_twl4030_dapm_widgets,
  132. ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
  133. if (ret)
  134. return ret;
  135. /* Set up SDP3430 specific audio path audio_map */
  136. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  137. /* SDP3430 connected pins */
  138. snd_soc_dapm_enable_pin(dapm, "Ext Mic");
  139. snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  140. snd_soc_dapm_disable_pin(dapm, "Headset Mic");
  141. snd_soc_dapm_disable_pin(dapm, "Headset Stereophone");
  142. /* TWL4030 not connected pins */
  143. snd_soc_dapm_nc_pin(dapm, "AUXL");
  144. snd_soc_dapm_nc_pin(dapm, "AUXR");
  145. snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
  146. snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
  147. snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
  148. snd_soc_dapm_nc_pin(dapm, "OUTL");
  149. snd_soc_dapm_nc_pin(dapm, "OUTR");
  150. snd_soc_dapm_nc_pin(dapm, "EARPIECE");
  151. snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
  152. snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
  153. snd_soc_dapm_nc_pin(dapm, "CARKITL");
  154. snd_soc_dapm_nc_pin(dapm, "CARKITR");
  155. ret = snd_soc_dapm_sync(dapm);
  156. if (ret)
  157. return ret;
  158. /* Headset jack detection */
  159. ret = snd_soc_jack_new(codec, "Headset Jack",
  160. SND_JACK_HEADSET, &hs_jack);
  161. if (ret)
  162. return ret;
  163. ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
  164. hs_jack_pins);
  165. if (ret)
  166. return ret;
  167. ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  168. hs_jack_gpios);
  169. return ret;
  170. }
  171. static int sdp3430_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
  172. {
  173. struct snd_soc_codec *codec = rtd->codec;
  174. unsigned short reg;
  175. /* Enable voice interface */
  176. reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
  177. reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
  178. codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
  179. return 0;
  180. }
  181. /* Digital audio interface glue - connects codec <--> CPU */
  182. static struct snd_soc_dai_link sdp3430_dai[] = {
  183. {
  184. .name = "TWL4030 I2S",
  185. .stream_name = "TWL4030 Audio",
  186. .cpu_dai_name = "omap-mcbsp-dai.1",
  187. .codec_dai_name = "twl4030-hifi",
  188. .platform_name = "omap-pcm-audio",
  189. .codec_name = "twl4030-codec",
  190. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  191. SND_SOC_DAIFMT_CBM_CFM,
  192. .init = sdp3430_twl4030_init,
  193. .ops = &sdp3430_ops,
  194. },
  195. {
  196. .name = "TWL4030 PCM",
  197. .stream_name = "TWL4030 Voice",
  198. .cpu_dai_name = "omap-mcbsp-dai.2",
  199. .codec_dai_name = "twl4030-voice",
  200. .platform_name = "omap-pcm-audio",
  201. .codec_name = "twl4030-codec",
  202. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
  203. SND_SOC_DAIFMT_CBM_CFM,
  204. .init = sdp3430_twl4030_voice_init,
  205. .ops = &sdp3430_voice_ops,
  206. },
  207. };
  208. /* Audio machine driver */
  209. static struct snd_soc_card snd_soc_sdp3430 = {
  210. .name = "SDP3430",
  211. .dai_link = sdp3430_dai,
  212. .num_links = ARRAY_SIZE(sdp3430_dai),
  213. };
  214. static struct platform_device *sdp3430_snd_device;
  215. static int __init sdp3430_soc_init(void)
  216. {
  217. int ret;
  218. u8 pin_mux;
  219. if (!machine_is_omap_3430sdp())
  220. return -ENODEV;
  221. printk(KERN_INFO "SDP3430 SoC init\n");
  222. sdp3430_snd_device = platform_device_alloc("soc-audio", -1);
  223. if (!sdp3430_snd_device) {
  224. printk(KERN_ERR "Platform device allocation failed\n");
  225. return -ENOMEM;
  226. }
  227. platform_set_drvdata(sdp3430_snd_device, &snd_soc_sdp3430);
  228. /* Set TWL4030 GPIO6 as EXTMUTE signal */
  229. twl_i2c_read_u8(TWL4030_MODULE_INTBR, &pin_mux,
  230. TWL4030_INTBR_PMBR1);
  231. pin_mux &= ~TWL4030_GPIO6_PWM0_MUTE(0x03);
  232. pin_mux |= TWL4030_GPIO6_PWM0_MUTE(0x02);
  233. twl_i2c_write_u8(TWL4030_MODULE_INTBR, pin_mux,
  234. TWL4030_INTBR_PMBR1);
  235. ret = platform_device_add(sdp3430_snd_device);
  236. if (ret)
  237. goto err1;
  238. return 0;
  239. err1:
  240. printk(KERN_ERR "Unable to add platform device\n");
  241. platform_device_put(sdp3430_snd_device);
  242. return ret;
  243. }
  244. module_init(sdp3430_soc_init);
  245. static void __exit sdp3430_soc_exit(void)
  246. {
  247. snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
  248. hs_jack_gpios);
  249. platform_device_unregister(sdp3430_snd_device);
  250. }
  251. module_exit(sdp3430_soc_exit);
  252. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  253. MODULE_DESCRIPTION("ALSA SoC SDP3430");
  254. MODULE_LICENSE("GPL");