eukrea-tlv320.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode
  3. *
  4. * Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com>
  5. *
  6. * based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c
  7. * which is Copyright 2009 Simtec Electronics
  8. * and on sound/soc/imx/phycore-ac97.c which is
  9. * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify it
  12. * under the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the License, or (at your
  14. * option) any later version.
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/device.h>
  20. #include <linux/i2c.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <asm/mach-types.h>
  26. #include "../codecs/tlv320aic23.h"
  27. #include "imx-ssi.h"
  28. #define CODEC_CLOCK 12000000
  29. static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream,
  30. struct snd_pcm_hw_params *params)
  31. {
  32. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  33. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  34. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  35. int ret;
  36. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  37. SND_SOC_DAIFMT_NB_NF |
  38. SND_SOC_DAIFMT_CBM_CFM);
  39. if (ret) {
  40. pr_err("%s: failed set cpu dai format\n", __func__);
  41. return ret;
  42. }
  43. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  44. SND_SOC_DAIFMT_NB_NF |
  45. SND_SOC_DAIFMT_CBM_CFM);
  46. if (ret) {
  47. pr_err("%s: failed set codec dai format\n", __func__);
  48. return ret;
  49. }
  50. ret = snd_soc_dai_set_sysclk(codec_dai, 0,
  51. CODEC_CLOCK, SND_SOC_CLOCK_OUT);
  52. if (ret) {
  53. pr_err("%s: failed setting codec sysclk\n", __func__);
  54. return ret;
  55. }
  56. snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0);
  57. ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0,
  58. SND_SOC_CLOCK_IN);
  59. if (ret) {
  60. pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n");
  61. return ret;
  62. }
  63. return 0;
  64. }
  65. static struct snd_soc_ops eukrea_tlv320_snd_ops = {
  66. .hw_params = eukrea_tlv320_hw_params,
  67. };
  68. static struct snd_soc_dai_link eukrea_tlv320_dai = {
  69. .name = "tlv320aic23",
  70. .stream_name = "TLV320AIC23",
  71. .codec_dai = &tlv320aic23_dai,
  72. .ops = &eukrea_tlv320_snd_ops,
  73. };
  74. static struct snd_soc_card eukrea_tlv320 = {
  75. .name = "cpuimx-audio",
  76. .platform = &imx_soc_platform,
  77. .dai_link = &eukrea_tlv320_dai,
  78. .num_links = 1,
  79. };
  80. static struct snd_soc_device eukrea_tlv320_snd_devdata = {
  81. .card = &eukrea_tlv320,
  82. .codec_dev = &soc_codec_dev_tlv320aic23,
  83. };
  84. static struct platform_device *eukrea_tlv320_snd_device;
  85. static int __init eukrea_tlv320_init(void)
  86. {
  87. int ret;
  88. if (!machine_is_eukrea_cpuimx27() && !machine_is_eukrea_cpuimx25sd()
  89. && !machine_is_eukrea_cpuimx35sd())
  90. /* return happy. We might run on a totally different machine */
  91. return 0;
  92. eukrea_tlv320_snd_device = platform_device_alloc("soc-audio", -1);
  93. if (!eukrea_tlv320_snd_device)
  94. return -ENOMEM;
  95. eukrea_tlv320_dai.cpu_dai = &imx_ssi_pcm_dai[0];
  96. platform_set_drvdata(eukrea_tlv320_snd_device, &eukrea_tlv320_snd_devdata);
  97. eukrea_tlv320_snd_devdata.dev = &eukrea_tlv320_snd_device->dev;
  98. ret = platform_device_add(eukrea_tlv320_snd_device);
  99. if (ret) {
  100. printk(KERN_ERR "ASoC: Platform device allocation failed\n");
  101. platform_device_put(eukrea_tlv320_snd_device);
  102. }
  103. return ret;
  104. }
  105. static void __exit eukrea_tlv320_exit(void)
  106. {
  107. platform_device_unregister(eukrea_tlv320_snd_device);
  108. }
  109. module_init(eukrea_tlv320_init);
  110. module_exit(eukrea_tlv320_exit);
  111. MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>");
  112. MODULE_DESCRIPTION("CPUIMX ALSA SoC driver");
  113. MODULE_LICENSE("GPL");