kirkwood-openrd.c 2.8 KB

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