kirkwood-openrd.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * kirkwood-openrd.c
  3. *
  4. * (c) 2010 Arnaud Patard <apatard@mandriva.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/platform_device.h>
  15. #include <linux/slab.h>
  16. #include <sound/soc.h>
  17. #include <mach/kirkwood.h>
  18. #include <plat/audio.h>
  19. #include <asm/mach-types.h>
  20. #include "../codecs/cs42l51.h"
  21. static int openrd_client_hw_params(struct snd_pcm_substream *substream,
  22. struct snd_pcm_hw_params *params)
  23. {
  24. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  25. struct snd_soc_dai *codec_dai = rtd->codec_dai;
  26. struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  27. int ret;
  28. unsigned int freq, fmt;
  29. fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
  30. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  31. if (ret < 0)
  32. return ret;
  33. ret = snd_soc_dai_set_fmt(codec_dai, fmt);
  34. if (ret < 0)
  35. return ret;
  36. switch (params_rate(params)) {
  37. default:
  38. case 44100:
  39. freq = 11289600;
  40. break;
  41. case 48000:
  42. freq = 12288000;
  43. break;
  44. case 96000:
  45. freq = 24576000;
  46. break;
  47. }
  48. return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
  49. }
  50. static struct snd_soc_ops openrd_client_ops = {
  51. .hw_params = openrd_client_hw_params,
  52. };
  53. static struct snd_soc_dai_link openrd_client_dai[] = {
  54. {
  55. .name = "CS42L51",
  56. .stream_name = "CS42L51 HiFi",
  57. .cpu_dai_name = "kirkwood-i2s",
  58. .platform_name = "kirkwood-pcm-audio",
  59. .codec_dai_name = "cs42l51-hifi",
  60. .codec_name = "cs42l51-codec.0-004a",
  61. .ops = &openrd_client_ops,
  62. },
  63. };
  64. static struct snd_soc_card openrd_client = {
  65. .name = "OpenRD Client",
  66. .dai_link = openrd_client_dai,
  67. .num_links = ARRAY_SIZE(openrd_client_dai),
  68. };
  69. static struct platform_device *openrd_client_snd_device;
  70. static int __init openrd_client_init(void)
  71. {
  72. int ret;
  73. if (!machine_is_openrd_client())
  74. return 0;
  75. openrd_client_snd_device = platform_device_alloc("soc-audio", -1);
  76. if (!openrd_client_snd_device)
  77. return -ENOMEM;
  78. platform_set_drvdata(openrd_client_snd_device,
  79. &openrd_client);
  80. ret = platform_device_add(openrd_client_snd_device);
  81. if (ret) {
  82. printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
  83. platform_device_put(openrd_client_snd_device);
  84. }
  85. return ret;
  86. }
  87. static void __exit openrd_client_exit(void)
  88. {
  89. platform_device_unregister(openrd_client_snd_device);
  90. }
  91. module_init(openrd_client_init);
  92. module_exit(openrd_client_exit);
  93. /* Module information */
  94. MODULE_AUTHOR("Arnaud Patard <apatard@mandriva.com>");
  95. MODULE_DESCRIPTION("ALSA SoC OpenRD Client");
  96. MODULE_LICENSE("GPL");
  97. MODULE_ALIAS("platform:soc-audio");