zoom2.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * zoom2.c -- SoC audio for Zoom2
  3. *
  4. * Author: Misael Lopez Cruz <x0052729@ti.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  18. * 02110-1301 USA
  19. *
  20. */
  21. #include <linux/clk.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/gpio.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/soc.h>
  27. #include <asm/mach-types.h>
  28. #include <linux/platform_data/asoc-ti-mcbsp.h>
  29. #include <linux/platform_data/gpio-omap.h>
  30. /* Register descriptions for twl4030 codec part */
  31. #include <linux/mfd/twl4030-audio.h>
  32. #include <linux/module.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. static int zoom2_hw_params(struct snd_pcm_substream *substream,
  36. struct snd_pcm_hw_params *params)
  37. {
  38. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  39. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  40. int ret;
  41. /* Set the codec system clock for DAC and ADC */
  42. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  43. SND_SOC_CLOCK_IN);
  44. if (ret < 0) {
  45. printk(KERN_ERR "can't set codec system clock\n");
  46. return ret;
  47. }
  48. return 0;
  49. }
  50. static struct snd_soc_ops zoom2_ops = {
  51. .hw_params = zoom2_hw_params,
  52. };
  53. /* Zoom2 machine DAPM */
  54. static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
  55. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  56. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  57. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  58. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  59. SND_SOC_DAPM_LINE("Aux In", NULL),
  60. };
  61. static const struct snd_soc_dapm_route audio_map[] = {
  62. /* External Mics: MAINMIC, SUBMIC with bias*/
  63. {"MAINMIC", NULL, "Mic Bias 1"},
  64. {"SUBMIC", NULL, "Mic Bias 2"},
  65. {"Mic Bias 1", NULL, "Ext Mic"},
  66. {"Mic Bias 2", NULL, "Ext Mic"},
  67. /* External Speakers: HFL, HFR */
  68. {"Ext Spk", NULL, "HFL"},
  69. {"Ext Spk", NULL, "HFR"},
  70. /* Headset Stereophone: HSOL, HSOR */
  71. {"Headset Stereophone", NULL, "HSOL"},
  72. {"Headset Stereophone", NULL, "HSOR"},
  73. /* Headset Mic: HSMIC with bias */
  74. {"HSMIC", NULL, "Headset Mic Bias"},
  75. {"Headset Mic Bias", NULL, "Headset Mic"},
  76. /* Aux In: AUXL, AUXR */
  77. {"Aux In", NULL, "AUXL"},
  78. {"Aux In", NULL, "AUXR"},
  79. };
  80. static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
  81. {
  82. struct snd_soc_codec *codec = rtd->codec;
  83. struct snd_soc_dapm_context *dapm = &codec->dapm;
  84. /* TWL4030 not connected pins */
  85. snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
  86. snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
  87. snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
  88. snd_soc_dapm_nc_pin(dapm, "EARPIECE");
  89. snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
  90. snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
  91. snd_soc_dapm_nc_pin(dapm, "CARKITL");
  92. snd_soc_dapm_nc_pin(dapm, "CARKITR");
  93. return 0;
  94. }
  95. static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
  96. {
  97. struct snd_soc_codec *codec = rtd->codec;
  98. unsigned short reg;
  99. /* Enable voice interface */
  100. reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
  101. reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
  102. codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
  103. return 0;
  104. }
  105. /* Digital audio interface glue - connects codec <--> CPU */
  106. static struct snd_soc_dai_link zoom2_dai[] = {
  107. {
  108. .name = "TWL4030 I2S",
  109. .stream_name = "TWL4030 Audio",
  110. .cpu_dai_name = "omap-mcbsp.2",
  111. .codec_dai_name = "twl4030-hifi",
  112. .platform_name = "omap-pcm-audio",
  113. .codec_name = "twl4030-codec",
  114. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  115. SND_SOC_DAIFMT_CBM_CFM,
  116. .init = zoom2_twl4030_init,
  117. .ops = &zoom2_ops,
  118. },
  119. {
  120. .name = "TWL4030 PCM",
  121. .stream_name = "TWL4030 Voice",
  122. .cpu_dai_name = "omap-mcbsp.3",
  123. .codec_dai_name = "twl4030-voice",
  124. .platform_name = "omap-pcm-audio",
  125. .codec_name = "twl4030-codec",
  126. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
  127. SND_SOC_DAIFMT_CBM_CFM,
  128. .init = zoom2_twl4030_voice_init,
  129. .ops = &zoom2_ops,
  130. },
  131. };
  132. /* Audio machine driver */
  133. static struct snd_soc_card snd_soc_zoom2 = {
  134. .name = "Zoom2",
  135. .owner = THIS_MODULE,
  136. .dai_link = zoom2_dai,
  137. .num_links = ARRAY_SIZE(zoom2_dai),
  138. .dapm_widgets = zoom2_twl4030_dapm_widgets,
  139. .num_dapm_widgets = ARRAY_SIZE(zoom2_twl4030_dapm_widgets),
  140. .dapm_routes = audio_map,
  141. .num_dapm_routes = ARRAY_SIZE(audio_map),
  142. };
  143. static struct platform_device *zoom2_snd_device;
  144. static int __init zoom2_soc_init(void)
  145. {
  146. int ret;
  147. if (!machine_is_omap_zoom2())
  148. return -ENODEV;
  149. printk(KERN_INFO "Zoom2 SoC init\n");
  150. zoom2_snd_device = platform_device_alloc("soc-audio", -1);
  151. if (!zoom2_snd_device) {
  152. printk(KERN_ERR "Platform device allocation failed\n");
  153. return -ENOMEM;
  154. }
  155. platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
  156. ret = platform_device_add(zoom2_snd_device);
  157. if (ret)
  158. goto err1;
  159. return 0;
  160. err1:
  161. printk(KERN_ERR "Unable to add platform device\n");
  162. platform_device_put(zoom2_snd_device);
  163. return ret;
  164. }
  165. module_init(zoom2_soc_init);
  166. static void __exit zoom2_soc_exit(void)
  167. {
  168. platform_device_unregister(zoom2_snd_device);
  169. }
  170. module_exit(zoom2_soc_exit);
  171. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  172. MODULE_DESCRIPTION("ALSA SoC Zoom2");
  173. MODULE_LICENSE("GPL");