zoom2.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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-codec.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. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  42. int ret;
  43. /* Set codec DAI configuration */
  44. ret = snd_soc_dai_set_fmt(codec_dai,
  45. SND_SOC_DAIFMT_I2S |
  46. SND_SOC_DAIFMT_NB_NF |
  47. SND_SOC_DAIFMT_CBM_CFM);
  48. if (ret < 0) {
  49. printk(KERN_ERR "can't set codec DAI configuration\n");
  50. return ret;
  51. }
  52. /* Set cpu DAI configuration */
  53. ret = snd_soc_dai_set_fmt(cpu_dai,
  54. SND_SOC_DAIFMT_I2S |
  55. SND_SOC_DAIFMT_NB_NF |
  56. SND_SOC_DAIFMT_CBM_CFM);
  57. if (ret < 0) {
  58. printk(KERN_ERR "can't set cpu DAI configuration\n");
  59. return ret;
  60. }
  61. /* Set the codec system clock for DAC and ADC */
  62. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  63. SND_SOC_CLOCK_IN);
  64. if (ret < 0) {
  65. printk(KERN_ERR "can't set codec system clock\n");
  66. return ret;
  67. }
  68. return 0;
  69. }
  70. static struct snd_soc_ops zoom2_ops = {
  71. .hw_params = zoom2_hw_params,
  72. };
  73. static int zoom2_hw_voice_params(struct snd_pcm_substream *substream,
  74. struct snd_pcm_hw_params *params)
  75. {
  76. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  77. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  78. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  79. int ret;
  80. /* Set codec DAI configuration */
  81. ret = snd_soc_dai_set_fmt(codec_dai,
  82. SND_SOC_DAIFMT_DSP_A |
  83. SND_SOC_DAIFMT_IB_NF |
  84. SND_SOC_DAIFMT_CBM_CFM);
  85. if (ret) {
  86. printk(KERN_ERR "can't set codec DAI configuration\n");
  87. return ret;
  88. }
  89. /* Set cpu DAI configuration */
  90. ret = snd_soc_dai_set_fmt(cpu_dai,
  91. SND_SOC_DAIFMT_DSP_A |
  92. SND_SOC_DAIFMT_IB_NF |
  93. SND_SOC_DAIFMT_CBM_CFM);
  94. if (ret < 0) {
  95. printk(KERN_ERR "can't set cpu DAI configuration\n");
  96. return ret;
  97. }
  98. /* Set the codec system clock for DAC and ADC */
  99. ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
  100. SND_SOC_CLOCK_IN);
  101. if (ret < 0) {
  102. printk(KERN_ERR "can't set codec system clock\n");
  103. return ret;
  104. }
  105. return 0;
  106. }
  107. static struct snd_soc_ops zoom2_voice_ops = {
  108. .hw_params = zoom2_hw_voice_params,
  109. };
  110. /* Zoom2 machine DAPM */
  111. static const struct snd_soc_dapm_widget zoom2_twl4030_dapm_widgets[] = {
  112. SND_SOC_DAPM_MIC("Ext Mic", NULL),
  113. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  114. SND_SOC_DAPM_MIC("Headset Mic", NULL),
  115. SND_SOC_DAPM_HP("Headset Stereophone", NULL),
  116. SND_SOC_DAPM_LINE("Aux In", NULL),
  117. };
  118. static const struct snd_soc_dapm_route audio_map[] = {
  119. /* External Mics: MAINMIC, SUBMIC with bias*/
  120. {"MAINMIC", NULL, "Mic Bias 1"},
  121. {"SUBMIC", NULL, "Mic Bias 2"},
  122. {"Mic Bias 1", NULL, "Ext Mic"},
  123. {"Mic Bias 2", NULL, "Ext Mic"},
  124. /* External Speakers: HFL, HFR */
  125. {"Ext Spk", NULL, "HFL"},
  126. {"Ext Spk", NULL, "HFR"},
  127. /* Headset Stereophone: HSOL, HSOR */
  128. {"Headset Stereophone", NULL, "HSOL"},
  129. {"Headset Stereophone", NULL, "HSOR"},
  130. /* Headset Mic: HSMIC with bias */
  131. {"HSMIC", NULL, "Headset Mic Bias"},
  132. {"Headset Mic Bias", NULL, "Headset Mic"},
  133. /* Aux In: AUXL, AUXR */
  134. {"Aux In", NULL, "AUXL"},
  135. {"Aux In", NULL, "AUXR"},
  136. };
  137. static int zoom2_twl4030_init(struct snd_soc_pcm_runtime *rtd)
  138. {
  139. struct snd_soc_codec *codec = rtd->codec;
  140. struct snd_soc_dapm_context *dapm = &codec->dapm;
  141. int ret;
  142. /* Add Zoom2 specific widgets */
  143. ret = snd_soc_dapm_new_controls(dapm, zoom2_twl4030_dapm_widgets,
  144. ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
  145. if (ret)
  146. return ret;
  147. /* Set up Zoom2 specific audio path audio_map */
  148. snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
  149. /* Zoom2 connected pins */
  150. snd_soc_dapm_enable_pin(dapm, "Ext Mic");
  151. snd_soc_dapm_enable_pin(dapm, "Ext Spk");
  152. snd_soc_dapm_enable_pin(dapm, "Headset Mic");
  153. snd_soc_dapm_enable_pin(dapm, "Headset Stereophone");
  154. snd_soc_dapm_enable_pin(dapm, "Aux In");
  155. /* TWL4030 not connected pins */
  156. snd_soc_dapm_nc_pin(dapm, "CARKITMIC");
  157. snd_soc_dapm_nc_pin(dapm, "DIGIMIC0");
  158. snd_soc_dapm_nc_pin(dapm, "DIGIMIC1");
  159. snd_soc_dapm_nc_pin(dapm, "EARPIECE");
  160. snd_soc_dapm_nc_pin(dapm, "PREDRIVEL");
  161. snd_soc_dapm_nc_pin(dapm, "PREDRIVER");
  162. snd_soc_dapm_nc_pin(dapm, "CARKITL");
  163. snd_soc_dapm_nc_pin(dapm, "CARKITR");
  164. ret = snd_soc_dapm_sync(dapm);
  165. return ret;
  166. }
  167. static int zoom2_twl4030_voice_init(struct snd_soc_pcm_runtime *rtd)
  168. {
  169. struct snd_soc_codec *codec = rtd->codec;
  170. unsigned short reg;
  171. /* Enable voice interface */
  172. reg = codec->driver->read(codec, TWL4030_REG_VOICE_IF);
  173. reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
  174. codec->driver->write(codec, TWL4030_REG_VOICE_IF, reg);
  175. return 0;
  176. }
  177. /* Digital audio interface glue - connects codec <--> CPU */
  178. static struct snd_soc_dai_link zoom2_dai[] = {
  179. {
  180. .name = "TWL4030 I2S",
  181. .stream_name = "TWL4030 Audio",
  182. .cpu_dai_name = "omap-mcbsp-dai.1",
  183. .codec_dai_name = "twl4030-hifi",
  184. .platform_name = "omap-pcm-audio",
  185. .codec_name = "twl4030-codec",
  186. .init = zoom2_twl4030_init,
  187. .ops = &zoom2_ops,
  188. },
  189. {
  190. .name = "TWL4030 PCM",
  191. .stream_name = "TWL4030 Voice",
  192. .cpu_dai_name = "omap-mcbsp-dai.2",
  193. .codec_dai_name = "twl4030-voice",
  194. .platform_name = "omap-pcm-audio",
  195. .codec_name = "twl4030-codec",
  196. .init = zoom2_twl4030_voice_init,
  197. .ops = &zoom2_voice_ops,
  198. },
  199. };
  200. /* Audio machine driver */
  201. static struct snd_soc_card snd_soc_zoom2 = {
  202. .name = "Zoom2",
  203. .dai_link = zoom2_dai,
  204. .num_links = ARRAY_SIZE(zoom2_dai),
  205. };
  206. static struct platform_device *zoom2_snd_device;
  207. static int __init zoom2_soc_init(void)
  208. {
  209. int ret;
  210. if (!machine_is_omap_zoom2())
  211. return -ENODEV;
  212. printk(KERN_INFO "Zoom2 SoC init\n");
  213. zoom2_snd_device = platform_device_alloc("soc-audio", -1);
  214. if (!zoom2_snd_device) {
  215. printk(KERN_ERR "Platform device allocation failed\n");
  216. return -ENOMEM;
  217. }
  218. platform_set_drvdata(zoom2_snd_device, &snd_soc_zoom2);
  219. ret = platform_device_add(zoom2_snd_device);
  220. if (ret)
  221. goto err1;
  222. BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
  223. gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
  224. BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
  225. gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
  226. return 0;
  227. err1:
  228. printk(KERN_ERR "Unable to add platform device\n");
  229. platform_device_put(zoom2_snd_device);
  230. return ret;
  231. }
  232. module_init(zoom2_soc_init);
  233. static void __exit zoom2_soc_exit(void)
  234. {
  235. gpio_free(ZOOM2_HEADSET_MUX_GPIO);
  236. gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
  237. platform_device_unregister(zoom2_snd_device);
  238. }
  239. module_exit(zoom2_soc_exit);
  240. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  241. MODULE_DESCRIPTION("ALSA SoC Zoom2");
  242. MODULE_LICENSE("GPL");