edb93xx.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. static int edb93xx_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->codec_dai;
  34. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  35. int err;
  36. unsigned int mclk_rate;
  37. unsigned int rate = params_rate(params);
  38. /*
  39. * According to CS4271 datasheet we use MCLK/LRCK=256 for
  40. * rates below 50kHz and 128 for higher sample rates
  41. */
  42. if (rate < 50000)
  43. mclk_rate = rate * 64 * 4;
  44. else
  45. mclk_rate = rate * 64 * 2;
  46. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
  47. SND_SOC_CLOCK_IN);
  48. if (err)
  49. return err;
  50. return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
  51. SND_SOC_CLOCK_OUT);
  52. }
  53. static struct snd_soc_ops edb93xx_ops = {
  54. .hw_params = edb93xx_hw_params,
  55. };
  56. static struct snd_soc_dai_link edb93xx_dai = {
  57. .name = "CS4271",
  58. .stream_name = "CS4271 HiFi",
  59. .platform_name = "ep93xx-i2s",
  60. .cpu_dai_name = "ep93xx-i2s",
  61. .codec_name = "spi0.0",
  62. .codec_dai_name = "cs4271-hifi",
  63. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  64. SND_SOC_DAIFMT_CBS_CFS,
  65. .ops = &edb93xx_ops,
  66. };
  67. static struct snd_soc_card snd_soc_edb93xx = {
  68. .name = "EDB93XX",
  69. .owner = THIS_MODULE,
  70. .dai_link = &edb93xx_dai,
  71. .num_links = 1,
  72. };
  73. static int edb93xx_probe(struct platform_device *pdev)
  74. {
  75. struct snd_soc_card *card = &snd_soc_edb93xx;
  76. int ret;
  77. ret = ep93xx_i2s_acquire();
  78. if (ret)
  79. return ret;
  80. card->dev = &pdev->dev;
  81. ret = snd_soc_register_card(card);
  82. if (ret) {
  83. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  84. ret);
  85. ep93xx_i2s_release();
  86. }
  87. return ret;
  88. }
  89. static int edb93xx_remove(struct platform_device *pdev)
  90. {
  91. struct snd_soc_card *card = platform_get_drvdata(pdev);
  92. snd_soc_unregister_card(card);
  93. ep93xx_i2s_release();
  94. return 0;
  95. }
  96. static struct platform_driver edb93xx_driver = {
  97. .driver = {
  98. .name = "edb93xx-audio",
  99. },
  100. .probe = edb93xx_probe,
  101. .remove = edb93xx_remove,
  102. };
  103. module_platform_driver(edb93xx_driver);
  104. MODULE_AUTHOR("Alexander Sverdlin <subaparts@yandex.ru>");
  105. MODULE_DESCRIPTION("ALSA SoC EDB93xx");
  106. MODULE_LICENSE("GPL");
  107. MODULE_ALIAS("platform:edb93xx-audio");