mx27vis-aic32x4.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 <sound/core.h>
  29. #include <sound/pcm.h>
  30. #include <sound/soc.h>
  31. #include <sound/soc-dapm.h>
  32. #include <sound/tlv.h>
  33. #include <asm/mach-types.h>
  34. #include <mach/iomux-mx27.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. #define MX27VIS_PIN_G0 (GPIO_PORTF + 9)
  41. #define MX27VIS_PIN_G1 (GPIO_PORTF + 8)
  42. #define MX27VIS_PIN_SDL (GPIO_PORTE + 5)
  43. #define MX27VIS_PIN_SDR (GPIO_PORTF + 7)
  44. static int mx27vis_amp_gain;
  45. static int mx27vis_amp_mute;
  46. static const int mx27vis_amp_pins[] = {
  47. MX27VIS_PIN_G0 | GPIO_GPIO | GPIO_OUT,
  48. MX27VIS_PIN_G1 | GPIO_GPIO | GPIO_OUT,
  49. MX27VIS_PIN_SDL | GPIO_GPIO | GPIO_OUT,
  50. MX27VIS_PIN_SDR | GPIO_GPIO | GPIO_OUT,
  51. };
  52. static int mx27vis_aic32x4_hw_params(struct snd_pcm_substream *substream,
  53. struct snd_pcm_hw_params *params)
  54. {
  55. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  56. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  57. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  58. int ret;
  59. u32 dai_format;
  60. dai_format = SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_NB_NF |
  61. SND_SOC_DAIFMT_CBM_CFM;
  62. /* set codec DAI configuration */
  63. snd_soc_dai_set_fmt(codec_dai, dai_format);
  64. /* set cpu DAI configuration */
  65. snd_soc_dai_set_fmt(cpu_dai, dai_format);
  66. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  67. 25000000, SND_SOC_CLOCK_OUT);
  68. if (ret) {
  69. pr_err("%s: failed setting codec sysclk\n", __func__);
  70. return ret;
  71. }
  72. ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
  73. SND_SOC_CLOCK_IN);
  74. if (ret) {
  75. pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
  76. return ret;
  77. }
  78. return 0;
  79. }
  80. static struct snd_soc_ops mx27vis_aic32x4_snd_ops = {
  81. .hw_params = mx27vis_aic32x4_hw_params,
  82. };
  83. static int mx27vis_amp_set(struct snd_kcontrol *kcontrol,
  84. struct snd_ctl_elem_value *ucontrol)
  85. {
  86. struct soc_mixer_control *mc =
  87. (struct soc_mixer_control *)kcontrol->private_value;
  88. int value = ucontrol->value.integer.value[0];
  89. unsigned int reg = mc->reg;
  90. int max = mc->max;
  91. if (value > max)
  92. return -EINVAL;
  93. switch (reg) {
  94. case MX27VIS_AMP_GAIN:
  95. gpio_set_value(MX27VIS_PIN_G0, value & 1);
  96. gpio_set_value(MX27VIS_PIN_G1, value >> 1);
  97. mx27vis_amp_gain = value;
  98. break;
  99. case MX27VIS_AMP_MUTE:
  100. gpio_set_value(MX27VIS_PIN_SDL, value & 1);
  101. gpio_set_value(MX27VIS_PIN_SDR, value >> 1);
  102. mx27vis_amp_mute = value;
  103. break;
  104. }
  105. return 0;
  106. }
  107. static int mx27vis_amp_get(struct snd_kcontrol *kcontrol,
  108. struct snd_ctl_elem_value *ucontrol)
  109. {
  110. struct soc_mixer_control *mc =
  111. (struct soc_mixer_control *)kcontrol->private_value;
  112. unsigned int reg = mc->reg;
  113. switch (reg) {
  114. case MX27VIS_AMP_GAIN:
  115. ucontrol->value.integer.value[0] = mx27vis_amp_gain;
  116. break;
  117. case MX27VIS_AMP_MUTE:
  118. ucontrol->value.integer.value[0] = mx27vis_amp_mute;
  119. break;
  120. }
  121. return 0;
  122. }
  123. /* From 6dB to 24dB in steps of 6dB */
  124. static const DECLARE_TLV_DB_SCALE(mx27vis_amp_tlv, 600, 600, 0);
  125. static const struct snd_kcontrol_new mx27vis_aic32x4_controls[] = {
  126. SOC_DAPM_PIN_SWITCH("External Mic"),
  127. SOC_SINGLE_EXT_TLV("LO Ext Boost", MX27VIS_AMP_GAIN, 0, 3, 0,
  128. mx27vis_amp_get, mx27vis_amp_set, mx27vis_amp_tlv),
  129. SOC_DOUBLE_EXT("LO Ext Mute Switch", MX27VIS_AMP_MUTE, 0, 1, 1, 0,
  130. mx27vis_amp_get, mx27vis_amp_set),
  131. };
  132. static const struct snd_soc_dapm_widget aic32x4_dapm_widgets[] = {
  133. SND_SOC_DAPM_MIC("External Mic", NULL),
  134. };
  135. static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
  136. {"Mic Bias", NULL, "External Mic"},
  137. {"IN1_R", NULL, "Mic Bias"},
  138. {"IN2_R", NULL, "Mic Bias"},
  139. {"IN3_R", NULL, "Mic Bias"},
  140. {"IN1_L", NULL, "Mic Bias"},
  141. {"IN2_L", NULL, "Mic Bias"},
  142. {"IN3_L", NULL, "Mic Bias"},
  143. };
  144. static struct snd_soc_dai_link mx27vis_aic32x4_dai = {
  145. .name = "tlv320aic32x4",
  146. .stream_name = "TLV320AIC32X4",
  147. .codec_dai_name = "tlv320aic32x4-hifi",
  148. .platform_name = "imx-pcm-audio.0",
  149. .codec_name = "tlv320aic32x4.0-0018",
  150. .cpu_dai_name = "imx-ssi.0",
  151. .ops = &mx27vis_aic32x4_snd_ops,
  152. };
  153. static struct snd_soc_card mx27vis_aic32x4 = {
  154. .name = "visstrim_m10-audio",
  155. .owner = THIS_MODULE,
  156. .dai_link = &mx27vis_aic32x4_dai,
  157. .num_links = 1,
  158. .controls = mx27vis_aic32x4_controls,
  159. .num_controls = ARRAY_SIZE(mx27vis_aic32x4_controls),
  160. .dapm_widgets = aic32x4_dapm_widgets,
  161. .num_dapm_widgets = ARRAY_SIZE(aic32x4_dapm_widgets),
  162. .dapm_routes = aic32x4_dapm_routes,
  163. .num_dapm_routes = ARRAY_SIZE(aic32x4_dapm_routes),
  164. };
  165. static int __devinit mx27vis_aic32x4_probe(struct platform_device *pdev)
  166. {
  167. int ret;
  168. mx27vis_aic32x4.dev = &pdev->dev;
  169. ret = snd_soc_register_card(&mx27vis_aic32x4);
  170. if (ret) {
  171. dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n",
  172. ret);
  173. return ret;
  174. }
  175. /* Connect SSI0 as clock slave to SSI1 external pins */
  176. imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
  177. IMX_AUDMUX_V1_PCR_SYN |
  178. IMX_AUDMUX_V1_PCR_TFSDIR |
  179. IMX_AUDMUX_V1_PCR_TCLKDIR |
  180. IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1) |
  181. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_PPCR1_SSI_PINS_1)
  182. );
  183. imx_audmux_v1_configure_port(MX27_AUDMUX_PPCR1_SSI_PINS_1,
  184. IMX_AUDMUX_V1_PCR_SYN |
  185. IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
  186. );
  187. ret = mxc_gpio_setup_multiple_pins(mx27vis_amp_pins,
  188. ARRAY_SIZE(mx27vis_amp_pins), "MX27VIS_AMP");
  189. if (ret)
  190. printk(KERN_ERR "ASoC: unable to setup gpios\n");
  191. return ret;
  192. }
  193. static int __devexit mx27vis_aic32x4_remove(struct platform_device *pdev)
  194. {
  195. snd_soc_unregister_card(&mx27vis_aic32x4);
  196. return 0;
  197. }
  198. static struct platform_driver mx27vis_aic32x4_audio_driver = {
  199. .driver = {
  200. .name = "mx27vis",
  201. .owner = THIS_MODULE,
  202. },
  203. .probe = mx27vis_aic32x4_probe,
  204. .remove = __devexit_p(mx27vis_aic32x4_remove),
  205. };
  206. module_platform_driver(mx27vis_aic32x4_audio_driver);
  207. MODULE_AUTHOR("Javier Martin <javier.martin@vista-silicon.com>");
  208. MODULE_DESCRIPTION("ALSA SoC AIC32X4 mx27 visstrim");
  209. MODULE_LICENSE("GPL");
  210. MODULE_ALIAS("platform:mx27vis");