kirkwood-openrd.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "kirkwood-i2s.h"
  21. #include "kirkwood-dma.h"
  22. #include "../codecs/cs42l51.h"
  23. static int openrd_client_hw_params(struct snd_pcm_substream *substream,
  24. struct snd_pcm_hw_params *params)
  25. {
  26. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  27. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  28. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  29. int ret;
  30. unsigned int freq, fmt;
  31. fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBS_CFS;
  32. ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
  33. if (ret < 0)
  34. return ret;
  35. ret = snd_soc_dai_set_fmt(codec_dai, fmt);
  36. if (ret < 0)
  37. return ret;
  38. switch (params_rate(params)) {
  39. default:
  40. case 44100:
  41. freq = 11289600;
  42. break;
  43. case 48000:
  44. freq = 12288000;
  45. break;
  46. case 96000:
  47. freq = 24576000;
  48. break;
  49. }
  50. return snd_soc_dai_set_sysclk(codec_dai, 0, freq, SND_SOC_CLOCK_IN);
  51. }
  52. static struct snd_soc_ops openrd_client_ops = {
  53. .hw_params = openrd_client_hw_params,
  54. };
  55. static struct snd_soc_dai_link openrd_client_dai[] = {
  56. {
  57. .name = "CS42L51",
  58. .stream_name = "CS42L51 HiFi",
  59. .cpu_dai = &kirkwood_i2s_dai,
  60. .codec_dai = &cs42l51_dai,
  61. .ops = &openrd_client_ops,
  62. },
  63. };
  64. static struct snd_soc_card openrd_client = {
  65. .name = "OpenRD Client",
  66. .platform = &kirkwood_soc_platform,
  67. .dai_link = openrd_client_dai,
  68. .num_links = ARRAY_SIZE(openrd_client_dai),
  69. };
  70. static struct snd_soc_device openrd_client_snd_devdata = {
  71. .card = &openrd_client,
  72. .codec_dev = &soc_codec_device_cs42l51,
  73. };
  74. static struct platform_device *openrd_client_snd_device;
  75. static int __init openrd_client_init(void)
  76. {
  77. int ret;
  78. if (!machine_is_openrd_client())
  79. return 0;
  80. openrd_client_snd_device = platform_device_alloc("soc-audio", -1);
  81. if (!openrd_client_snd_device)
  82. return -ENOMEM;
  83. platform_set_drvdata(openrd_client_snd_device,
  84. &openrd_client_snd_devdata);
  85. openrd_client_snd_devdata.dev = &openrd_client_snd_device->dev;
  86. ret = platform_device_add(openrd_client_snd_device);
  87. if (ret) {
  88. printk(KERN_ERR "%s: platform_device_add failed\n", __func__);
  89. platform_device_put(openrd_client_snd_device);
  90. }
  91. return ret;
  92. }
  93. static void __exit openrd_client_exit(void)
  94. {
  95. platform_device_unregister(openrd_client_snd_device);
  96. }
  97. module_init(openrd_client_init);
  98. module_exit(openrd_client_exit);
  99. /* Module information */
  100. MODULE_AUTHOR("Arnaud Patard <apatard@mandriva.com>");
  101. MODULE_DESCRIPTION("ALSA SoC OpenRD Client");
  102. MODULE_LICENSE("GPL");
  103. MODULE_ALIAS("platform:soc-audio");