mx27vis-aic32x4.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // mx27vis-aic32x4.c
  4. //
  5. // Copyright 2011 Vista Silicon S.L.
  6. //
  7. // Author: Javier Martin <javier.martin@vista-silicon.com>
  8. #include <linux/module.h>
  9. #include <linux/moduleparam.h>
  10. #include <linux/device.h>
  11. #include <linux/i2c.h>
  12. #include <linux/gpio.h>
  13. #include <linux/platform_data/asoc-mx27vis.h>
  14. #include <sound/core.h>
  15. #include <sound/pcm.h>
  16. #include <sound/soc.h>
  17. #include <sound/soc-dapm.h>
  18. #include <sound/tlv.h>
  19. #include <asm/mach-types.h>
  20. #include "../codecs/tlv320aic32x4.h"
  21. #include "imx-ssi.h"
  22. #include "imx-audmux.h"
  23. #define MX27VIS_AMP_GAIN 0
  24. #define MX27VIS_AMP_MUTE 1
  25. static int mx27vis_amp_gain;
  26. static int mx27vis_amp_mute;
  27. static int mx27vis_amp_gain0_gpio;
  28. static int mx27vis_amp_gain1_gpio;
  29. static int mx27vis_amp_mutel_gpio;
  30. static int mx27vis_amp_muter_gpio;
  31. static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream *substream,
  32. struct snd_pcm_hw_params *params)
  33. {
  34. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  35. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  36. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  37. int ret;
  38. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  39. 25000000, SND_SOC_CLOCK_OUT);
  40. if (ret) {
  41. pr_err("%s: failed setting codec sysclk\n", __func__);
  42. return ret;
  43. }
  44. ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
  45. SND_SOC_CLOCK_IN);
  46. if (ret) {
  47. pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
  48. return ret;
  49. }
  50. return 0;
  51. }
  52. static const struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
  53. .hw_params = mx27vis_aic32x4_hw_params,
  54. };
  55. static int mx27vis_amp_set(struct snd_kcontrol *kcontrol,
  56. struct snd_ctl_elem_value *ucontrol)
  57. {
  58. struct soc_mixer_control *mc =
  59. (struct soc_mixer_control *)kcontrol->private_value;
  60. int value = ucontrol->value.integer.value[0];
  61. unsigned int reg = mc->reg;
  62. int max = mc->max;
  63. if (value > max)
  64. return -EINVAL;
  65. switch (reg) {
  66. case MX27VIS_AMP_GAIN:
  67. gpio_set_value(mx27vis_amp_gain0_gpio, value & 1);
  68. gpio_set_value(mx27vis_amp_gain1_gpio, value >> 1);
  69. mx27vis_amp_gain = value;
  70. break;
  71. case MX27VIS_AMP_MUTE:
  72. gpio_set_value(mx27vis_amp_mutel_gpio, value & 1);
  73. gpio_set_value(mx27vis_amp_muter_gpio, value >> 1);
  74. mx27vis_amp_mute = value;
  75. break;
  76. }
  77. return 0;
  78. }
  79. static int mx27vis_amp_get(struct snd_kcontrol *kcontrol,
  80. struct snd_ctl_elem_value *ucontrol)
  81. {
  82. struct soc_mixer_control *mc =
  83. (struct soc_mixer_control *)kcontrol->private_value;
  84. unsigned int reg = mc->reg;
  85. switch (reg) {
  86. case MX27VIS_AMP_GAIN:
  87. ucontrol->value.integer.value[0] = mx27vis_amp_gain;
  88. break;
  89. case MX27VIS_AMP_MUTE:
  90. ucontrol->value.integer.value[0] = mx27vis_amp_mute;
  91. break;
  92. }
  93. return 0;
  94. }
  95. /* From 6dB to 24dB in steps of 6dB */
  96. static const DECLARE_TLV_DB_SCALE(mx27vis_amp_tlv, 600, 600, 0);
  97. static const struct snd_kcontrol_new mx27vis_aic32x4_controls[] = {
  98. SOC_DAPM_PIN_SWITCH("External Mic"),
  99. SOC_SINGLE_EXT_TLV("LO Ext Boost", MX27VIS_AMP_GAIN, 0, 3, 0,
  100. mx27vis_amp_get, mx27vis_amp_set, mx27vis_amp_tlv),
  101. SOC_DOUBLE_EXT("LO Ext Mute Switch", MX27VIS_AMP_MUTE, 0, 1, 1, 0,
  102. mx27vis_amp_get, mx27vis_amp_set),
  103. };
  104. static const struct snd_soc_dapm_widget aic32x4_dapm_widgets[] = {
  105. SND_SOC_DAPM_MIC("External Mic", NULL),
  106. };
  107. static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
  108. {"Mic Bias", NULL, "External Mic"},
  109. {"IN1_R", NULL, "Mic Bias"},
  110. {"IN2_R", NULL, "Mic Bias"},
  111. {"IN3_R", NULL, "Mic Bias"},
  112. {"IN1_L", NULL, "Mic Bias"},
  113. {"IN2_L", NULL, "Mic Bias"},
  114. {"IN3_L", NULL, "Mic Bias"},
  115. };
  116. SND_SOC_DAILINK_DEFS(hifi,
  117. DAILINK_COMP_ARRAY(COMP_CPU("imx-ssi.0")),
  118. DAILINK_COMP_ARRAY(COMP_CODEC("tlv320aic32x4.0-0018",
  119. "tlv320aic32x4-hifi")),
  120. DAILINK_COMP_ARRAY(COMP_PLATFORM("imx-ssi.0")));
  121. static struct snd_soc_dai_link mx27vis_aic32x4_dai = {
  122. .name = "tlv320aic32x4",
  123. .stream_name = "TLV320AIC32X4",
  124. .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
  125. SND_SOC_DAIFMT_CBM_CFM,
  126. .ops = &mx27vis_aic32x4_snd_ops,
  127. SND_SOC_DAILINK_REG(hifi),
  128. };
  129. static struct snd_soc_card mx27vis_aic32x4 = {
  130. .name = "visstrim_m10-audio",
  131. .owner = THIS_MODULE,
  132. .dai_link = &mx27vis_aic32x4_dai,
  133. .num_links = 1,
  134. .controls = mx27vis_aic32x4_controls,
  135. .num_controls = ARRAY_SIZE(mx27vis_aic32x4_controls),
  136. .dapm_widgets = aic32x4_dapm_widgets,
  137. .num_dapm_widgets = ARRAY_SIZE(aic32x4_dapm_widgets),
  138. .dapm_routes = aic32x4_dapm_routes,
  139. .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
  140. };
  141. static int mx27vis_aic32x4_probe(struct platform_device *pdev)
  142. {
  143. struct snd_mx27vis_platform_data *pdata = pdev->dev.platform_data;
  144. int ret;
  145. if (!pdata) {
  146. dev_err(&pdev->dev, "No platform data supplied\n");
  147. return -EINVAL;
  148. }
  149. mx27vis_amp_gain0_gpio = pdata->amp_gain0_gpio;
  150. mx27vis_amp_gain1_gpio = pdata->amp_gain1_gpio;
  151. mx27vis_amp_mutel_gpio = pdata->amp_mutel_gpio;
  152. mx27vis_amp_muter_gpio = pdata->amp_muter_gpio;
  153. mx27vis_aic32x4.dev = &pdev->dev;
  154. ret = devm_snd_soc_register_card(&pdev->dev, &mx27vis_aic32x4);
  155. if (ret) {
  156. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  157. ret);
  158. return ret;
  159. }
  160. /* Connect SSI0 as clock slave to SSI1 external pins */
  161. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  162. IMX_AUDMUX_V1_PCR_SYN |
  163. IMX_AUDMUX_V1_PCR_TFSDIR |
  164. IMX_AUDMUX_V1_PCR_TCLKDIR |
  165. IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1) |
  166. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1)
  167. );
  168. imx_audmux_v1_configure_port(MX27_AUDMUX_PPCR1_SSI_PINS_1,
  169. IMX_AUDMUX_V1_PCR_SYN |
  170. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
  171. );
  172. return ret;
  173. }
  174. static struct platform_driver mx27vis_aic32x4_audio_driver = {
  175. .driver = {
  176. .name = "mx27vis",
  177. },
  178. .probe = mx27vis_aic32x4_probe,
  179. };
  180. module_platform_driver(mx27vis_aic32x4_audio_driver);
  181. MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
  182. MODULE_DESCRIPTION("ALSA SoC AIC32X4 mx27 visstrim");
  183. MODULE_LICENSE("GPL");
  184. MODULE_ALIAS("platform:mx27vis");