imx-mc13783.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * imx-mc13783.c -- SoC audio for imx based boards with mc13783 codec
  3. *
  4. * Copyright 2012 Philippe Retornaz, <philippe.retornaz@epfl.ch>
  5. *
  6. * Heavly based on phycore-mc13783:
  7. * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. */
  15. #include <linux/module.h>
  16. #include <linux/moduleparam.h>
  17. #include <linux/device.h>
  18. #include <sound/core.h>
  19. #include <sound/pcm.h>
  20. #include <sound/soc.h>
  21. #include <sound/soc-dapm.h>
  22. #include <asm/mach-types.h>
  23. #include "../codecs/mc13783.h"
  24. #include "imx-ssi.h"
  25. #include "imx-audmux.h"
  26. #define FMT_SSI (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | \
  27. SND_SOC_DAIFMT_CBM_CFM)
  28. static int imx_mc13783_hifi_hw_params(struct snd_pcm_substream *substream,
  29. struct snd_pcm_hw_params *params)
  30. {
  31. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  32. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  33. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  34. int ret;
  35. ret = snd_soc_dai_set_tdm_slot(codec_dai, 0xfffffffc, 0xfffffffc,
  36. 4, 16);
  37. if (ret)
  38. return ret;
  39. ret = snd_soc_dai_set_sysclk(codec_dai, MC13783_CLK_CLIA, 26000000, 0);
  40. if (ret)
  41. return ret;
  42. ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x0, 0xfffffffc, 2, 16);
  43. if (ret)
  44. return ret;
  45. return 0;
  46. }
  47. static struct snd_soc_ops imx_mc13783_hifi_ops = {
  48. .hw_params = imx_mc13783_hifi_hw_params,
  49. };
  50. static struct snd_soc_dai_link imx_mc13783_dai_mc13783[] = {
  51. {
  52. .name = "MC13783",
  53. .stream_name = "Sound",
  54. .codec_dai_name = "mc13783-hifi",
  55. .codec_name = "mc13783-codec",
  56. .cpu_dai_name = "imx-ssi.0",
  57. .platform_name = "imx-pcm-audio.0",
  58. .ops = &imx_mc13783_hifi_ops,
  59. .symmetric_rates = 1,
  60. .dai_fmt = FMT_SSI,
  61. },
  62. };
  63. static const struct snd_soc_dapm_widget imx_mc13783_widget[] = {
  64. SND_SOC_DAPM_MIC("Mic", NULL),
  65. SND_SOC_DAPM_HP("Headphone", NULL),
  66. SND_SOC_DAPM_SPK("Speaker", NULL),
  67. };
  68. static const struct snd_soc_dapm_route imx_mc13783_routes[] = {
  69. {"Speaker", NULL, "LSP"},
  70. {"Headphone", NULL, "HSL"},
  71. {"Headphone", NULL, "HSR"},
  72. {"MC1LIN", NULL, "MC1 Bias"},
  73. {"MC2IN", NULL, "MC2 Bias"},
  74. {"MC1 Bias", NULL, "Mic"},
  75. {"MC2 Bias", NULL, "Mic"},
  76. };
  77. static struct snd_soc_card imx_mc13783 = {
  78. .name = "imx_mc13783",
  79. .dai_link = imx_mc13783_dai_mc13783,
  80. .num_links = ARRAY_SIZE(imx_mc13783_dai_mc13783),
  81. .dapm_widgets = imx_mc13783_widget,
  82. .num_dapm_widgets = ARRAY_SIZE(imx_mc13783_widget),
  83. .dapm_routes = imx_mc13783_routes,
  84. .num_dapm_routes = ARRAY_SIZE(imx_mc13783_routes),
  85. };
  86. static int imx_mc13783_probe(struct platform_device *pdev)
  87. {
  88. int ret;
  89. imx_mc13783.dev = &pdev->dev;
  90. ret = snd_soc_register_card(&imx_mc13783);
  91. if (ret) {
  92. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  93. ret);
  94. return ret;
  95. }
  96. if (machine_is_mx31_3ds()) {
  97. imx_audmux_v2_configure_port(MX31_AUDMUX_PORT4_SSI_PINS_4,
  98. IMX_AUDMUX_V2_PTCR_SYN,
  99. IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT1_SSI0) |
  100. IMX_AUDMUX_V2_PDCR_MODE(1) |
  101. IMX_AUDMUX_V2_PDCR_INMMASK(0xfc));
  102. imx_audmux_v2_configure_port(MX31_AUDMUX_PORT1_SSI0,
  103. IMX_AUDMUX_V2_PTCR_SYN |
  104. IMX_AUDMUX_V2_PTCR_TFSDIR |
  105. IMX_AUDMUX_V2_PTCR_TFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
  106. IMX_AUDMUX_V2_PTCR_TCLKDIR |
  107. IMX_AUDMUX_V2_PTCR_TCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
  108. IMX_AUDMUX_V2_PTCR_RFSDIR |
  109. IMX_AUDMUX_V2_PTCR_RFSEL(MX31_AUDMUX_PORT4_SSI_PINS_4) |
  110. IMX_AUDMUX_V2_PTCR_RCLKDIR |
  111. IMX_AUDMUX_V2_PTCR_RCSEL(MX31_AUDMUX_PORT4_SSI_PINS_4),
  112. IMX_AUDMUX_V2_PDCR_RXDSEL(MX31_AUDMUX_PORT4_SSI_PINS_4));
  113. } else if (machine_is_mx27_3ds()) {
  114. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  115. IMX_AUDMUX_V1_PCR_SYN |
  116. IMX_AUDMUX_V1_PCR_TFSDIR |
  117. IMX_AUDMUX_V1_PCR_TCLKDIR |
  118. IMX_AUDMUX_V1_PCR_RFSDIR |
  119. IMX_AUDMUX_V1_PCR_RCLKDIR |
  120. IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
  121. IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
  122. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
  123. );
  124. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
  125. IMX_AUDMUX_V1_PCR_SYN |
  126. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
  127. );
  128. }
  129. return ret;
  130. }
  131. static int imx_mc13783_remove(struct platform_device *pdev)
  132. {
  133. snd_soc_unregister_card(&imx_mc13783);
  134. return 0;
  135. }
  136. static struct platform_driver imx_mc13783_audio_driver = {
  137. .driver = {
  138. .name = "imx_mc13783",
  139. .owner = THIS_MODULE,
  140. },
  141. .probe = imx_mc13783_probe,
  142. .remove = imx_mc13783_remove
  143. };
  144. module_platform_driver(imx_mc13783_audio_driver);
  145. MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
  146. MODULE_AUTHOR("Philippe Retornaz <philippe.retornaz@epfl.ch");
  147. MODULE_DESCRIPTION("imx with mc13783 codec ALSA SoC driver");
  148. MODULE_LICENSE("GPL");
  149. MODULE_ALIAS("platform:imx_mc13783");