sdp3430.c 9.1 KB

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