edb93xx.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * SoC audio for EDB93xx
  3. *
  4. * Copyright (c) 2010 Alexander Sverdlin <subaparts@yandex.ru>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * This driver support CS4271 codec being master or slave, working
  17. * in control port mode, connected either via SPI or I2C.
  18. * The data format accepted is I2S or left-justified.
  19. * DAPM support not implemented.
  20. */
  21. #include <linux/platform_device.h>
  22. #include <linux/gpio.h>
  23. #include <linux/module.h>
  24. #include <sound/core.h>
  25. #include <sound/pcm.h>
  26. #include <sound/soc.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/hardware.h>
  29. #include "ep93xx-pcm.h"
  30. static int edb93xx_hw_params(struct snd_pcm_substream *substream,
  31. struct snd_pcm_hw_params *params)
  32. {
  33. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  34. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  35. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  36. int err;
  37. unsigned int mclk_rate;
  38. unsigned int rate = params_rate(params);
  39. /*
  40. * According to CS4271 datasheet we use MCLK/LRCK=256 for
  41. * rates below 50kHz and 128 for higher sample rates
  42. */
  43. if (rate < 50000)
  44. mclk_rate = rate * 64 * 4;
  45. else
  46. mclk_rate = rate * 64 * 2;
  47. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
  48. SND_SOC_CLOCK_IN);
  49. if (err)
  50. return err;
  51. return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
  52. SND_SOC_CLOCK_OUT);
  53. }
  54. static struct snd_soc_ops edb93xx_ops = {
  55. .hw_params = edb93xx_hw_params,
  56. };
  57. static struct snd_soc_dai_link edb93xx_dai = {
  58. .name = "CS4271",
  59. .stream_name = "CS4271 HiFi",
  60. .platform_name = "ep93xx-pcm-audio",
  61. .cpu_dai_name = "ep93xx-i2s",
  62. .codec_name = "spi0.0",
  63. .codec_dai_name = "cs4271-hifi",
  64. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF |
  65. SND_SOC_DAIFMT_CBS_CFS,
  66. .ops = &edb93xx_ops,
  67. };
  68. static struct snd_soc_card snd_soc_edb93xx = {
  69. .name = "EDB93XX",
  70. .owner = THIS_MODULE,
  71. .dai_link = &edb93xx_dai,
  72. .num_links = 1,
  73. };
  74. static int __devinit edb93xx_probe(struct platform_device *pdev)
  75. {
  76. struct snd_soc_card *card = &snd_soc_edb93xx;
  77. int ret;
  78. ret = ep93xx_i2s_acquire();
  79. if (ret)
  80. return ret;
  81. card->dev = &pdev->dev;
  82. ret = snd_soc_register_card(card);
  83. if (ret) {
  84. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  85. ret);
  86. ep93xx_i2s_release();
  87. }
  88. return ret;
  89. }
  90. static int __devexit edb93xx_remove(struct platform_device *pdev)
  91. {
  92. struct snd_soc_card *card = platform_get_drvdata(pdev);
  93. snd_soc_unregister_card(card);
  94. ep93xx_i2s_release();
  95. return 0;
  96. }
  97. static struct platform_driver edb93xx_driver = {
  98. .driver = {
  99. .name = "edb93xx-audio",
  100. .owner = THIS_MODULE,
  101. },
  102. .probe = edb93xx_probe,
  103. .remove = __devexit_p(edb93xx_remove),
  104. };
  105. module_platform_driver(edb93xx_driver);
  106. MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
  107. MODULE_DESCRIPTION("ALSA SoC EDB93xx");
  108. MODULE_LICENSE("GPL");
  109. MODULE_ALIAS("platform:edb93xx-audio");