edb93xx.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * SoC audio for EDB93xx
  4. *
  5. * Copyright (c) 2010 Alexander Sverdlin <[email protected]>
  6. *
  7. * This driver support CS4271 codec being master or slave, working
  8. * in control port mode, connected either via SPI or I2C.
  9. * The data format accepted is I2S or left-justified.
  10. * DAPM support not implemented.
  11. */
  12. #include <linux/platform_device.h>
  13. #include <linux/gpio.h>
  14. #include <linux/module.h>
  15. #include <linux/soc/cirrus/ep93xx.h>
  16. #include <sound/core.h>
  17. #include <sound/pcm.h>
  18. #include <sound/soc.h>
  19. #include <asm/mach-types.h>
  20. static int edb93xx_hw_params(struct snd_pcm_substream *substream,
  21. struct snd_pcm_hw_params *params)
  22. {
  23. struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
  24. struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
  25. struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
  26. int err;
  27. unsigned int mclk_rate;
  28. unsigned int rate = params_rate(params);
  29. /*
  30. * According to CS4271 datasheet we use MCLK/LRCK=256 for
  31. * rates below 50kHz and 128 for higher sample rates
  32. */
  33. if (rate < 50000)
  34. mclk_rate = rate * 64 * 4;
  35. else
  36. mclk_rate = rate * 64 * 2;
  37. err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk_rate,
  38. SND_SOC_CLOCK_IN);
  39. if (err)
  40. return err;
  41. return snd_soc_dai_set_sysclk(cpu_dai, 0, mclk_rate,
  42. SND_SOC_CLOCK_OUT);
  43. }
  44. static const struct snd_soc_ops edb93xx_ops = {
  45. .hw_params = edb93xx_hw_params,
  46. };
  47. SND_SOC_DAILINK_DEFS(hifi,
  48. DAILINK_COMP_ARRAY(COMP_CPU("ep93xx-i2s")),
  49. DAILINK_COMP_ARRAY(COMP_CODEC("spi0.0", "cs4271-hifi")),
  50. DAILINK_COMP_ARRAY(COMP_PLATFORM("ep93xx-i2s")));
  51. static struct snd_soc_dai_link edb93xx_dai = {
  52. .name = "CS4271",
  53. .stream_name = "CS4271 HiFi",
  54. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  55. SND_SOC_DAIFMT_CBC_CFC,
  56. .ops = &edb93xx_ops,
  57. SND_SOC_DAILINK_REG(hifi),
  58. };
  59. static struct snd_soc_card snd_soc_edb93xx = {
  60. .name = "EDB93XX",
  61. .owner = THIS_MODULE,
  62. .dai_link = &edb93xx_dai,
  63. .num_links = 1,
  64. };
  65. static int edb93xx_probe(struct platform_device *pdev)
  66. {
  67. struct snd_soc_card *card = &snd_soc_edb93xx;
  68. int ret;
  69. ret = ep93xx_i2s_acquire();
  70. if (ret)
  71. return ret;
  72. card->dev = &pdev->dev;
  73. ret = snd_soc_register_card(card);
  74. if (ret) {
  75. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  76. ret);
  77. ep93xx_i2s_release();
  78. }
  79. return ret;
  80. }
  81. static int edb93xx_remove(struct platform_device *pdev)
  82. {
  83. struct snd_soc_card *card = platform_get_drvdata(pdev);
  84. snd_soc_unregister_card(card);
  85. ep93xx_i2s_release();
  86. return 0;
  87. }
  88. static struct platform_driver edb93xx_driver = {
  89. .driver = {
  90. .name = "edb93xx-audio",
  91. },
  92. .probe = edb93xx_probe,
  93. .remove = edb93xx_remove,
  94. };
  95. module_platform_driver(edb93xx_driver);
  96. MODULE_AUTHOR("Alexander Sverdlin <[email protected]>");
  97. MODULE_DESCRIPTION("ALSA SoC EDB93xx");
  98. MODULE_LICENSE("GPL");
  99. MODULE_ALIAS("platform:edb93xx-audio");