sdp3430.c 8.8 KB

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