imote2.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #include "pxa2xx-pcm.h"
  7. static int imote2_asoc_hw_params(struct snd_pcm_substream *substream,
  8. struct snd_pcm_hw_params *params)
  9. {
  10. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  11. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  12. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  13. unsigned int clk = 0;
  14. int ret;
  15. switch (params_rate(params)) {
  16. case 8000:
  17. case 16000:
  18. case 48000:
  19. case 96000:
  20. clk = 12288000;
  21. break;
  22. case 11025:
  23. case 22050:
  24. case 44100:
  25. clk = 11289600;
  26. break;
  27. }
  28. /* set codec DAI configuration */
  29. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S
  30. | SND_SOC_DAIFMT_NB_NF
  31. | SND_SOC_DAIFMT_CBS_CFS);
  32. if (ret < 0)
  33. return ret;
  34. /* CPU should be clock master */
  35. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S
  36. | SND_SOC_DAIFMT_NB_NF
  37. | SND_SOC_DAIFMT_CBS_CFS);
  38. if (ret < 0)
  39. return ret;
  40. ret = snd_soc_dai_set_sysclk(codec_dai, 0, clk,
  41. SND_SOC_CLOCK_IN);
  42. if (ret < 0)
  43. return ret;
  44. /* set the I2S system clock as input (unused) */
  45. ret = snd_soc_dai_set_sysclk(cpu_dai, PXA2XX_I2S_SYSCLK, clk,
  46. SND_SOC_CLOCK_OUT);
  47. return ret;
  48. }
  49. static struct snd_soc_ops imote2_asoc_ops = {
  50. .hw_params = imote2_asoc_hw_params,
  51. };
  52. static struct snd_soc_dai_link imote2_dai = {
  53. .name = "WM8940",
  54. .stream_name = "WM8940",
  55. .cpu_dai = &pxa_i2s_dai,
  56. .codec_dai = &wm8940_dai,
  57. .ops = &imote2_asoc_ops,
  58. };
  59. static struct snd_soc_card snd_soc_imote2 = {
  60. .name = "Imote2",
  61. .platform = &pxa2xx_soc_platform,
  62. .dai_link = &imote2_dai,
  63. .num_links = 1,
  64. };
  65. static struct snd_soc_device imote2_snd_devdata = {
  66. .card = &snd_soc_imote2,
  67. .codec_dev = &soc_codec_dev_wm8940,
  68. };
  69. static struct platform_device *imote2_snd_device;
  70. static int __init imote2_asoc_init(void)
  71. {
  72. int ret;
  73. if (!machine_is_intelmote2())
  74. return -ENODEV;
  75. imote2_snd_device = platform_device_alloc("soc-audio", -1);
  76. if (!imote2_snd_device)
  77. return -ENOMEM;
  78. platform_set_drvdata(imote2_snd_device, &imote2_snd_devdata);
  79. imote2_snd_devdata.dev = &imote2_snd_device->dev;
  80. ret = platform_device_add(imote2_snd_device);
  81. if (ret)
  82. platform_device_put(imote2_snd_device);
  83. return ret;
  84. }
  85. module_init(imote2_asoc_init);
  86. static void __exit imote2_asoc_exit(void)
  87. {
  88. platform_device_unregister(imote2_snd_device);
  89. }
  90. module_exit(imote2_asoc_exit);
  91. MODULE_AUTHOR("Jonathan Cameron");
  92. MODULE_DESCRIPTION("ALSA SoC Imote 2");
  93. MODULE_LICENSE("GPL");