zoom2.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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 <sound/core.h>
  24. #include <sound/pcm.h>
  25. #include <sound/soc.h>
  26. #include <asm/mach-types.h>
  27. #include <mach/hardware.h>
  28. #include <mach/gpio.h>
  29. #include <mach/board-zoom.h>
  30. #include <plat/mcbsp.h>
  31. /* Register descriptions for twl4030 codec part */
  32. #include <linux/mfd/twl4030-audio.h>
  33. #include "omap-mcbsp.h"
  34. #include "omap-pcm.h"
  35. #define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15)
  36. static int zoom2_hw_params(struct snd_pcm_substream *substream,
  37. struct snd_pcm_hw_params *params)
  38. {
  39. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  40. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  41. int ret;
  42. /* Set the codec system clock for DAC and ADC */
  43. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  44. SND_SOC_CLOCK_IN);
  45. if (ret < 0) {
  46. printk(KERN_ERR "can't set codec system clock\n");
  47. return ret;
  48. }
  49. return 0;
  50. }
  51. static struct snd_soc_ops zoom2_ops = {
  52. .hw_params = zoom2_hw_params,
  53. };
  54. /* Zoom2 machine DAPM */
  55. static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
  56. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  57. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  58. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  59. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  60. SND_SOC_DAPM_LINE("Aux In", NULL),
  61. };
  62. static const struct snd_soc_dapm_route audio_map[] = {
  63. /* External Mics: MAINMIC, SUBMIC with bias*/
  64. {"MAINMIC", NULL, "Mic Bias 1"},
  65. {"SUBMIC", NULL, "Mic Bias 2"},
  66. {"Mic Bias 1", NULL, "Ext Mic"},
  67. {"Mic Bias 2", NULL, "Ext Mic"},
  68. /* External Speakers: HFL, HFR */
  69. {"Ext Spk", NULL, "HFL"},
  70. {"Ext Spk", NULL, "HFR"},
  71. /* Headset Stereophone: HSOL, HSOR */
  72. {"Headset Stereophone", NULL, "HSOL"},
  73. {"Headset Stereophone", NULL, "HSOR"},
  74. /* Headset Mic: HSMIC with bias */
  75. {"HSMIC", NULL, "Headset Mic Bias"},
  76. {"Headset Mic Bias", NULL, "Headset Mic"},
  77. /* Aux In: AUXL, AUXR */
  78. {"Aux In", NULL, "AUXL"},
  79. {"Aux In", NULL, "AUXR"},
  80. };
  81. static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
  82. {
  83. struct snd_soc_codec *codec = rtd->codec;
  84. struct snd_soc_dapm_context *dapm = &codec->dapm;
  85. int ret;
  86. /* Add Zoom2 specific widgets */
  87. ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
  88. ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
  89. if (ret)
  90. return ret;
  91. /* Set up Zoom2 specific audio path audio_map */
  92. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  93. /* Zoom2 connected pins */
  94. snd_soc_dapm_enable_pin(dapm, "Ext Mic");
  95. snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  96. snd_soc_dapm_enable_pin(dapm, "Headset Mic");
  97. snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
  98. snd_soc_dapm_enable_pin(dapm, "Aux In");
  99. /* TWL4030 not connected pins */
  100. snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
  101. snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
  102. snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
  103. snd_soc_dapm_nc_pin(dapm, "EARPIECE");
  104. snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
  105. snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
  106. snd_soc_dapm_nc_pin(dapm, "CARKITL");
  107. snd_soc_dapm_nc_pin(dapm, "CARKITR");
  108. ret = snd_soc_dapm_sync(dapm);
  109. return ret;
  110. }
  111. static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
  112. {
  113. struct snd_soc_codec *codec = rtd->codec;
  114. unsigned short reg;
  115. /* Enable voice interface */
  116. reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
  117. reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
  118. codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
  119. return 0;
  120. }
  121. /* Digital audio interface glue - connects codec <--> CPU */
  122. static struct snd_soc_dai_link zoom2_dai[] = {
  123. {
  124. .name = "TWL4030 I2S",
  125. .stream_name = "TWL4030 Audio",
  126. .cpu_dai_name = "omap-mcbsp-dai.1",
  127. .codec_dai_name = "twl4030-hifi",
  128. .platform_name = "omap-pcm-audio",
  129. .codec_name = "twl4030-codec",
  130. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  131. SND_SOC_DAIFMT_CBM_CFM,
  132. .init = zoom2_twl4030_init,
  133. .ops = &zoom2_ops,
  134. },
  135. {
  136. .name = "TWL4030 PCM",
  137. .stream_name = "TWL4030 Voice",
  138. .cpu_dai_name = "omap-mcbsp-dai.2",
  139. .codec_dai_name = "twl4030-voice",
  140. .platform_name = "omap-pcm-audio",
  141. .codec_name = "twl4030-codec",
  142. .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF |
  143. SND_SOC_DAIFMT_CBM_CFM,
  144. .init = zoom2_twl4030_voice_init,
  145. .ops = &zoom2_ops,
  146. },
  147. };
  148. /* Audio machine driver */
  149. static struct snd_soc_card snd_soc_zoom2 = {
  150. .name = "Zoom2",
  151. .dai_link = zoom2_dai,
  152. .num_links = ARRAY_SIZE(zoom2_dai),
  153. };
  154. static struct platform_device *zoom2_snd_device;
  155. static int __init zoom2_soc_init(void)
  156. {
  157. int ret;
  158. if (!machine_is_omap_zoom2())
  159. return -ENODEV;
  160. printk(KERN_INFO "Zoom2 SoC init\n");
  161. zoom2_snd_device = platform_device_alloc("soc-audio", -1);
  162. if (!zoom2_snd_device) {
  163. printk(KERN_ERR "Platform device allocation failed\n");
  164. return -ENOMEM;
  165. }
  166. platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
  167. ret = platform_device_add(zoom2_snd_device);
  168. if (ret)
  169. goto err1;
  170. BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
  171. gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
  172. BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
  173. gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
  174. return 0;
  175. err1:
  176. printk(KERN_ERR "Unable to add platform device\n");
  177. platform_device_put(zoom2_snd_device);
  178. return ret;
  179. }
  180. module_init(zoom2_soc_init);
  181. static void __exit zoom2_soc_exit(void)
  182. {
  183. gpio_free(ZOOM2_HEADSET_MUX_GPIO);
  184. gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
  185. platform_device_unregister(zoom2_snd_device);
  186. }
  187. module_exit(zoom2_soc_exit);
  188. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  189. MODULE_DESCRIPTION("ALSA SoC Zoom2");
  190. MODULE_LICENSE("GPL");