zoom2.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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 <sound/soc-dapm.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/hardware.h>
  29. #include <mach/gpio.h>
  30. #include <mach/mcbsp.h>
  31. #include "omap-mcbsp.h"
  32. #include "omap-pcm.h"
  33. #include "../codecs/twl4030.h"
  34. #define ZOOM2_HEADSET_MUX_GPIO (OMAP_MAX_GPIO_LINES + 15)
  35. #define ZOOM2_HEADSET_EXTMUTE_GPIO 153
  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->dai->codec_dai;
  41. struct snd_soc_dai *cpu_dai = rtd->dai->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->dai->codec_dai;
  78. struct snd_soc_dai *cpu_dai = rtd->dai->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_codec *codec)
  138. {
  139. int ret;
  140. /* Add Zoom2 specific widgets */
  141. ret = snd_soc_dapm_new_controls(codec, zoom2_twl4030_dapm_widgets,
  142. ARRAY_SIZE(zoom2_twl4030_dapm_widgets));
  143. if (ret)
  144. return ret;
  145. /* Set up Zoom2 specific audio path audio_map */
  146. snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
  147. /* Zoom2 connected pins */
  148. snd_soc_dapm_enable_pin(codec, "Ext Mic");
  149. snd_soc_dapm_enable_pin(codec, "Ext Spk");
  150. snd_soc_dapm_enable_pin(codec, "Headset Mic");
  151. snd_soc_dapm_enable_pin(codec, "Headset Stereophone");
  152. snd_soc_dapm_enable_pin(codec, "Aux In");
  153. /* TWL4030 not connected pins */
  154. snd_soc_dapm_nc_pin(codec, "CARKITMIC");
  155. snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
  156. snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
  157. snd_soc_dapm_nc_pin(codec, "OUTL");
  158. snd_soc_dapm_nc_pin(codec, "OUTR");
  159. snd_soc_dapm_nc_pin(codec, "EARPIECE");
  160. snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
  161. snd_soc_dapm_nc_pin(codec, "PREDRIVER");
  162. snd_soc_dapm_nc_pin(codec, "CARKITL");
  163. snd_soc_dapm_nc_pin(codec, "CARKITR");
  164. ret = snd_soc_dapm_sync(codec);
  165. return ret;
  166. }
  167. static int zoom2_twl4030_voice_init(struct snd_soc_codec *codec)
  168. {
  169. unsigned short reg;
  170. /* Enable voice interface */
  171. reg = codec->read(codec, TWL4030_REG_VOICE_IF);
  172. reg |= TWL4030_VIF_DIN_EN | TWL4030_VIF_DOUT_EN | TWL4030_VIF_EN;
  173. codec->write(codec, TWL4030_REG_VOICE_IF, reg);
  174. return 0;
  175. }
  176. /* Digital audio interface glue - connects codec <--> CPU */
  177. static struct snd_soc_dai_link zoom2_dai[] = {
  178. {
  179. .name = "TWL4030 I2S",
  180. .stream_name = "TWL4030 Audio",
  181. .cpu_dai = &omap_mcbsp_dai[0],
  182. .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
  183. .init = zoom2_twl4030_init,
  184. .ops = &zoom2_ops,
  185. },
  186. {
  187. .name = "TWL4030 PCM",
  188. .stream_name = "TWL4030 Voice",
  189. .cpu_dai = &omap_mcbsp_dai[1],
  190. .codec_dai = &twl4030_dai[TWL4030_DAI_VOICE],
  191. .init = zoom2_twl4030_voice_init,
  192. .ops = &zoom2_voice_ops,
  193. },
  194. };
  195. /* Audio machine driver */
  196. static struct snd_soc_card snd_soc_zoom2 = {
  197. .name = "Zoom2",
  198. .platform = &omap_soc_platform,
  199. .dai_link = zoom2_dai,
  200. .num_links = ARRAY_SIZE(zoom2_dai),
  201. };
  202. /* EXTMUTE callback function */
  203. void zoom2_set_hs_extmute(int mute)
  204. {
  205. gpio_set_value(ZOOM2_HEADSET_EXTMUTE_GPIO, mute);
  206. }
  207. /* twl4030 setup */
  208. static struct twl4030_setup_data twl4030_setup = {
  209. .ramp_delay_value = 3, /* 161 ms */
  210. .sysclk = 26000,
  211. .hs_extmute = 1,
  212. .set_hs_extmute = zoom2_set_hs_extmute,
  213. };
  214. /* Audio subsystem */
  215. static struct snd_soc_device zoom2_snd_devdata = {
  216. .card = &snd_soc_zoom2,
  217. .codec_dev = &soc_codec_dev_twl4030,
  218. .codec_data = &twl4030_setup,
  219. };
  220. static struct platform_device *zoom2_snd_device;
  221. static int __init zoom2_soc_init(void)
  222. {
  223. int ret;
  224. if (!machine_is_omap_zoom2()) {
  225. pr_debug("Not Zoom2!\n");
  226. return -ENODEV;
  227. }
  228. printk(KERN_INFO "Zoom2 SoC init\n");
  229. zoom2_snd_device = platform_device_alloc("soc-audio", -1);
  230. if (!zoom2_snd_device) {
  231. printk(KERN_ERR "Platform device allocation failed\n");
  232. return -ENOMEM;
  233. }
  234. platform_set_drvdata(zoom2_snd_device, &zoom2_snd_devdata);
  235. zoom2_snd_devdata.dev = &zoom2_snd_device->dev;
  236. *(unsigned int *)zoom2_dai[0].cpu_dai->private_data = 1; /* McBSP2 */
  237. *(unsigned int *)zoom2_dai[1].cpu_dai->private_data = 2; /* McBSP3 */
  238. ret = platform_device_add(zoom2_snd_device);
  239. if (ret)
  240. goto err1;
  241. BUG_ON(gpio_request(ZOOM2_HEADSET_MUX_GPIO, "hs_mux") < 0);
  242. gpio_direction_output(ZOOM2_HEADSET_MUX_GPIO, 0);
  243. BUG_ON(gpio_request(ZOOM2_HEADSET_EXTMUTE_GPIO, "ext_mute") < 0);
  244. gpio_direction_output(ZOOM2_HEADSET_EXTMUTE_GPIO, 0);
  245. return 0;
  246. err1:
  247. printk(KERN_ERR "Unable to add platform device\n");
  248. platform_device_put(zoom2_snd_device);
  249. return ret;
  250. }
  251. module_init(zoom2_soc_init);
  252. static void __exit zoom2_soc_exit(void)
  253. {
  254. gpio_free(ZOOM2_HEADSET_MUX_GPIO);
  255. gpio_free(ZOOM2_HEADSET_EXTMUTE_GPIO);
  256. platform_device_unregister(zoom2_snd_device);
  257. }
  258. module_exit(zoom2_soc_exit);
  259. MODULE_AUTHOR("Misael Lopez Cruz <x0052729@ti.com>");
  260. MODULE_DESCRIPTION("ALSA SoC Zoom2");
  261. MODULE_LICENSE("GPL");