sdp3430.c 7.3 KB

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