sdp3430.c 8.6 KB

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