bf5xx-ad1836.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. * File: sound/soc/blackfin/bf5xx-ad1836.c
  3. * Author: Barry Song <Barry.Song@analog.com>
  4. *
  5. * Created: Aug 4 2009
  6. * Description: Board driver for ad1836 sound chip
  7. *
  8. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. */
  16. #include <linux/module.h>
  17. #include <linux/moduleparam.h>
  18. #include <linux/device.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/soc.h>
  22. #include <sound/soc-dapm.h>
  23. #include <sound/pcm_params.h>
  24. #include <asm/blackfin.h>
  25. #include <asm/cacheflush.h>
  26. #include <asm/irq.h>
  27. #include <asm/dma.h>
  28. #include <asm/portmux.h>
  29. #include "../codecs/ad1836.h"
  30. #include "bf5xx-sport.h"
  31. #include "bf5xx-tdm-pcm.h"
  32. #include "bf5xx-tdm.h"
  33. static struct snd_soc_card bf5xx_ad1836;
  34. static int bf5xx_ad1836_startup(struct snd_pcm_substream *substream)
  35. {
  36. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  37. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  38. cpu_dai->private_data = sport_handle;
  39. return 0;
  40. }
  41. static int bf5xx_ad1836_hw_params(struct snd_pcm_substream *substream,
  42. struct snd_pcm_hw_params *params)
  43. {
  44. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  45. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  46. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  47. unsigned int channel_map[] = {0, 4, 1, 5, 2, 6, 3, 7};
  48. int ret = 0;
  49. /* set cpu DAI configuration */
  50. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_DSP_A |
  51. SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
  52. if (ret < 0)
  53. return ret;
  54. /* set codec DAI configuration */
  55. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A |
  56. SND_SOC_DAIFMT_IB_IF | SND_SOC_DAIFMT_CBM_CFM);
  57. if (ret < 0)
  58. return ret;
  59. /* set cpu DAI channel mapping */
  60. ret = snd_soc_dai_set_channel_map(cpu_dai, ARRAY_SIZE(channel_map),
  61. channel_map, ARRAY_SIZE(channel_map), channel_map);
  62. if (ret < 0)
  63. return ret;
  64. return 0;
  65. }
  66. static struct snd_soc_ops bf5xx_ad1836_ops = {
  67. .startup = bf5xx_ad1836_startup,
  68. .hw_params = bf5xx_ad1836_hw_params,
  69. };
  70. static struct snd_soc_dai_link bf5xx_ad1836_dai = {
  71. .name = "ad1836",
  72. .stream_name = "AD1836",
  73. .cpu_dai = &bf5xx_tdm_dai,
  74. .codec_dai = &ad1836_dai,
  75. .ops = &bf5xx_ad1836_ops,
  76. };
  77. static struct snd_soc_card bf5xx_ad1836 = {
  78. .name = "bf5xx_ad1836",
  79. .platform = &bf5xx_tdm_soc_platform,
  80. .dai_link = &bf5xx_ad1836_dai,
  81. .num_links = 1,
  82. };
  83. static struct snd_soc_device bf5xx_ad1836_snd_devdata = {
  84. .card = &bf5xx_ad1836,
  85. .codec_dev = &soc_codec_dev_ad1836,
  86. };
  87. static struct platform_device *bfxx_ad1836_snd_device;
  88. static int __init bf5xx_ad1836_init(void)
  89. {
  90. int ret;
  91. bfxx_ad1836_snd_device = platform_device_alloc("soc-audio", -1);
  92. if (!bfxx_ad1836_snd_device)
  93. return -ENOMEM;
  94. platform_set_drvdata(bfxx_ad1836_snd_device, &bf5xx_ad1836_snd_devdata);
  95. bf5xx_ad1836_snd_devdata.dev = &bfxx_ad1836_snd_device->dev;
  96. ret = platform_device_add(bfxx_ad1836_snd_device);
  97. if (ret)
  98. platform_device_put(bfxx_ad1836_snd_device);
  99. return ret;
  100. }
  101. static void __exit bf5xx_ad1836_exit(void)
  102. {
  103. platform_device_unregister(bfxx_ad1836_snd_device);
  104. }
  105. module_init(bf5xx_ad1836_init);
  106. module_exit(bf5xx_ad1836_exit);
  107. /* Module information */
  108. MODULE_AUTHOR("Barry Song");
  109. MODULE_DESCRIPTION("ALSA SoC AD1836 board driver");
  110. MODULE_LICENSE("GPL");