mx27vis-aic32x4.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * mx27vis-aic32x4.c
  3. *
  4. * Copyright 2011 Vista Silicon S.L.
  5. *
  6. * Author: Javier Martin <javier.martin@vista-silicon.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU 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 Street, Fifth Floor, Boston,
  21. * MA 02110-1301, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/device.h>
  26. #include <linux/i2c.h>
  27. #include <linux/gpio.h>
  28. #include <linux/platform_data/asoc-mx27vis.h>
  29. #include <sound/core.h>
  30. #include <sound/pcm.h>
  31. #include <sound/soc.h>
  32. #include <sound/soc-dapm.h>
  33. #include <sound/tlv.h>
  34. #include <asm/mach-types.h>
  35. #include "../codecs/tlv320aic32x4.h"
  36. #include "imx-ssi.h"
  37. #include "imx-audmux.h"
  38. #define MX27VIS_AMP_GAIN 0
  39. #define MX27VIS_AMP_MUTE 1
  40. static int mx27vis_amp_gain;
  41. static int mx27vis_amp_mute;
  42. static int mx27vis_amp_gain0_gpio;
  43. static int mx27vis_amp_gain1_gpio;
  44. static int mx27vis_amp_mutel_gpio;
  45. static int mx27vis_amp_muter_gpio;
  46. static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream *substream,
  47. struct snd_pcm_hw_params *params)
  48. {
  49. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  50. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  51. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  52. int ret;
  53. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  54. 25000000, SND_SOC_CLOCK_OUT);
  55. if (ret) {
  56. pr_err("%s: failed setting codec sysclk\n", __func__);
  57. return ret;
  58. }
  59. ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
  60. SND_SOC_CLOCK_IN);
  61. if (ret) {
  62. pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
  63. return ret;
  64. }
  65. return 0;
  66. }
  67. static struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
  68. .hw_params = mx27vis_aic32x4_hw_params,
  69. };
  70. static int mx27vis_amp_set(struct snd_kcontrol *kcontrol,
  71. struct snd_ctl_elem_value *ucontrol)
  72. {
  73. struct soc_mixer_control *mc =
  74. (struct soc_mixer_control *)kcontrol->private_value;
  75. int value = ucontrol->value.integer.value[0];
  76. unsigned int reg = mc->reg;
  77. int max = mc->max;
  78. if (value > max)
  79. return -EINVAL;
  80. switch (reg) {
  81. case MX27VIS_AMP_GAIN:
  82. gpio_set_value(mx27vis_amp_gain0_gpio, value & 1);
  83. gpio_set_value(mx27vis_amp_gain1_gpio, value >> 1);
  84. mx27vis_amp_gain = value;
  85. break;
  86. case MX27VIS_AMP_MUTE:
  87. gpio_set_value(mx27vis_amp_mutel_gpio, value & 1);
  88. gpio_set_value(mx27vis_amp_muter_gpio, value >> 1);
  89. mx27vis_amp_mute = value;
  90. break;
  91. }
  92. return 0;
  93. }
  94. static int mx27vis_amp_get(struct snd_kcontrol *kcontrol,
  95. struct snd_ctl_elem_value *ucontrol)
  96. {
  97. struct soc_mixer_control *mc =
  98. (struct soc_mixer_control *)kcontrol->private_value;
  99. unsigned int reg = mc->reg;
  100. switch (reg) {
  101. case MX27VIS_AMP_GAIN:
  102. ucontrol->value.integer.value[0] = mx27vis_amp_gain;
  103. break;
  104. case MX27VIS_AMP_MUTE:
  105. ucontrol->value.integer.value[0] = mx27vis_amp_mute;
  106. break;
  107. }
  108. return 0;
  109. }
  110. /* From 6dB to 24dB in steps of 6dB */
  111. static const DECLARE_TLV_DB_SCALE(mx27vis_amp_tlv, 600, 600, 0);
  112. static const struct snd_kcontrol_new mx27vis_aic32x4_controls[] = {
  113. SOC_DAPM_PIN_SWITCH("External Mic"),
  114. SOC_SINGLE_EXT_TLV("LO Ext Boost", MX27VIS_AMP_GAIN, 0, 3, 0,
  115. mx27vis_amp_get, mx27vis_amp_set, mx27vis_amp_tlv),
  116. SOC_DOUBLE_EXT("LO Ext Mute Switch", MX27VIS_AMP_MUTE, 0, 1, 1, 0,
  117. mx27vis_amp_get, mx27vis_amp_set),
  118. };
  119. static const struct snd_soc_dapm_widget aic32x4_dapm_widgets[] = {
  120. SND_SOC_DAPM_MIC("External Mic", NULL),
  121. };
  122. static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
  123. {"Mic Bias", NULL, "External Mic"},
  124. {"IN1_R", NULL, "Mic Bias"},
  125. {"IN2_R", NULL, "Mic Bias"},
  126. {"IN3_R", NULL, "Mic Bias"},
  127. {"IN1_L", NULL, "Mic Bias"},
  128. {"IN2_L", NULL, "Mic Bias"},
  129. {"IN3_L", NULL, "Mic Bias"},
  130. };
  131. static struct snd_soc_dai_link mx27vis_aic32x4_dai = {
  132. .name = "tlv320aic32x4",
  133. .stream_name = "TLV320AIC32X4",
  134. .codec_dai_name = "tlv320aic32x4-hifi",
  135. .platform_name = "imx-ssi.0",
  136. .codec_name = "tlv320aic32x4.0-0018",
  137. .cpu_dai_name = "imx-ssi.0",
  138. .dai_fmt = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
  139. SND_SOC_DAIFMT_CBM_CFM,
  140. .ops = &mx27vis_aic32x4_snd_ops,
  141. };
  142. static struct snd_soc_card mx27vis_aic32x4 = {
  143. .name = "visstrim_m10-audio",
  144. .owner = THIS_MODULE,
  145. .dai_link = &mx27vis_aic32x4_dai,
  146. .num_links = 1,
  147. .controls = mx27vis_aic32x4_controls,
  148. .num_controls = ARRAY_SIZE(mx27vis_aic32x4_controls),
  149. .dapm_widgets = aic32x4_dapm_widgets,
  150. .num_dapm_widgets = ARRAY_SIZE(aic32x4_dapm_widgets),
  151. .dapm_routes = aic32x4_dapm_routes,
  152. .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
  153. };
  154. static int mx27vis_aic32x4_probe(struct platform_device *pdev)
  155. {
  156. struct snd_mx27vis_platform_data *pdata = pdev->dev.platform_data;
  157. int ret;
  158. if (!pdata) {
  159. dev_err(&pdev->dev, "No platform data supplied\n");
  160. return -EINVAL;
  161. }
  162. mx27vis_amp_gain0_gpio = pdata->amp_gain0_gpio;
  163. mx27vis_amp_gain1_gpio = pdata->amp_gain1_gpio;
  164. mx27vis_amp_mutel_gpio = pdata->amp_mutel_gpio;
  165. mx27vis_amp_muter_gpio = pdata->amp_muter_gpio;
  166. mx27vis_aic32x4.dev = &pdev->dev;
  167. ret = snd_soc_register_card(&mx27vis_aic32x4);
  168. if (ret) {
  169. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  170. ret);
  171. return ret;
  172. }
  173. /* Connect SSI0 as clock slave to SSI1 external pins */
  174. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  175. IMX_AUDMUX_V1_PCR_SYN |
  176. IMX_AUDMUX_V1_PCR_TFSDIR |
  177. IMX_AUDMUX_V1_PCR_TCLKDIR |
  178. IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1) |
  179. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1)
  180. );
  181. imx_audmux_v1_configure_port(MX27_AUDMUX_PPCR1_SSI_PINS_1,
  182. IMX_AUDMUX_V1_PCR_SYN |
  183. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
  184. );
  185. return ret;
  186. }
  187. static int mx27vis_aic32x4_remove(struct platform_device *pdev)
  188. {
  189. snd_soc_unregister_card(&mx27vis_aic32x4);
  190. return 0;
  191. }
  192. static struct platform_driver mx27vis_aic32x4_audio_driver = {
  193. .driver = {
  194. .name = "mx27vis",
  195. },
  196. .probe = mx27vis_aic32x4_probe,
  197. .remove = mx27vis_aic32x4_remove,
  198. };
  199. module_platform_driver(mx27vis_aic32x4_audio_driver);
  200. MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
  201. MODULE_DESCRIPTION("ALSA SoC AIC32X4 mx27 visstrim");
  202. MODULE_LICENSE("GPL");
  203. MODULE_ALIAS("platform:mx27vis");