imote2.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /* set codec DAI configuration */
  28. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  29. | SND_SOC_DAIFMT_NB_NF
  30. | SND_SOC_DAIFMT_CBS_CFS);
  31. if (ret < 0)
  32. return ret;
  33. /* CPU should be clock master */
  34. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  35. | SND_SOC_DAIFMT_NB_NF
  36. | SND_SOC_DAIFMT_CBS_CFS);
  37. if (ret < 0)
  38. return ret;
  39. ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
  40. SND_SOC_CLOCK_IN);
  41. if (ret < 0)
  42. return ret;
  43. /* set the I2S system clock as input (unused) */
  44. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
  45. SND_SOC_CLOCK_OUT);
  46. return ret;
  47. }
  48. static struct snd_soc_ops imote2_asoc_ops = {
  49. .hw_params = imote2_asoc_hw_params,
  50. };
  51. static struct snd_soc_dai_link imote2_dai = {
  52. .name = "WM8940",
  53. .stream_name = "WM8940",
  54. .cpu_dai_name = "pxa2xx-i2s",
  55. .codec_dai_name = "wm8940-hifi",
  56. .platform_name = "pxa-pcm-audio",
  57. .codec_name = "wm8940-codec.0-0034",
  58. .ops = &imote2_asoc_ops,
  59. };
  60. static struct snd_soc_card snd_soc_imote2 = {
  61. .name = "Imote2",
  62. .dai_link = &imote2_dai,
  63. .num_links = 1,
  64. };
  65. static struct platform_device *imote2_snd_device;
  66. static int __init imote2_asoc_init(void)
  67. {
  68. int ret;
  69. if (!machine_is_intelmote2())
  70. return -ENODEV;
  71. imote2_snd_device = platform_device_alloc("soc-audio", -1);
  72. if (!imote2_snd_device)
  73. return -ENOMEM;
  74. platform_set_drvdata(imote2_snd_device, &snd_soc_imote2);
  75. ret = platform_device_add(imote2_snd_device);
  76. if (ret)
  77. platform_device_put(imote2_snd_device);
  78. return ret;
  79. }
  80. module_init(imote2_asoc_init);
  81. static void __exit imote2_asoc_exit(void)
  82. {
  83. platform_device_unregister(imote2_snd_device);
  84. }
  85. module_exit(imote2_asoc_exit);
  86. MODULE_AUTHOR("Jonathan Cameron");
  87. MODULE_DESCRIPTION("ALSA SoC Imote 2");
  88. MODULE_LICENSE("GPL");