imote2.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <linux/module.h>
  2. #include <sound/soc.h>
  3. #include <asm/mach-types.h>
  4. #include "../codecs/wm8940.h"
  5. #include "pxa2xx-i2s.h"
  6. static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
  7. struct snd_pcm_hw_params *params)
  8. {
  9. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  10. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  11. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  12. unsigned int clk = 0;
  13. int ret;
  14. switch (params_rate(params)) {
  15. case 8000:
  16. case 16000:
  17. case 48000:
  18. case 96000:
  19. clk = 12288000;
  20. break;
  21. case 11025:
  22. case 22050:
  23. case 44100:
  24. clk = 11289600;
  25. break;
  26. }
  27. ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
  28. SND_SOC_CLOCK_IN);
  29. if (ret < 0)
  30. return ret;
  31. /* set the I2S system clock as input (unused) */
  32. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
  33. SND_SOC_CLOCK_OUT);
  34. return ret;
  35. }
  36. static struct snd_soc_ops imote2_asoc_ops = {
  37. .hw_params = imote2_asoc_hw_params,
  38. };
  39. static struct snd_soc_dai_link imote2_dai = {
  40. .name = "WM8940",
  41. .stream_name = "WM8940",
  42. .cpu_dai_name = "pxa2xx-i2s",
  43. .codec_dai_name = "wm8940-hifi",
  44. .platform_name = "pxa-pcm-audio",
  45. .codec_name = "wm8940-codec.0-0034",
  46. .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  47. SND_SOC_DAIFMT_CBS_CFS,
  48. .ops = &imote2_asoc_ops,
  49. };
  50. static struct snd_soc_card imote2 = {
  51. .name = "Imote2",
  52. .owner = THIS_MODULE,
  53. .dai_link = &imote2_dai,
  54. .num_links = 1,
  55. };
  56. static int imote2_probe(struct platform_device *pdev)
  57. {
  58. struct snd_soc_card *card = &imote2;
  59. int ret;
  60. card->dev = &pdev->dev;
  61. ret = devm_snd_soc_register_card(&pdev->dev, card);
  62. if (ret)
  63. dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n",
  64. ret);
  65. return ret;
  66. }
  67. static struct platform_driver imote2_driver = {
  68. .driver = {
  69. .name = "imote2-audio",
  70. .pm = &snd_soc_pm_ops,
  71. },
  72. .probe = imote2_probe,
  73. };
  74. module_platform_driver(imote2_driver);
  75. MODULE_AUTHOR("Jonathan Cameron");
  76. MODULE_DESCRIPTION("ALSA SoC Imote 2");
  77. MODULE_LICENSE("GPL");
  78. MODULE_ALIAS("platform:imote2-audio");