bf5xx-ssm2602.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * File: sound/soc/blackfin/bf5xx-ssm2602.c
  3. * Author: Cliff Cai <Cliff.Cai@analog.com>
  4. *
  5. * Created: Tue June 06 2008
  6. * Description: board driver for SSM2602 sound chip
  7. *
  8. * Modified:
  9. * Copyright 2008 Analog Devices Inc.
  10. *
  11. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, see the file COPYING, or write
  25. * to the Free Software Foundation, Inc.,
  26. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/device.h>
  31. #include <sound/core.h>
  32. #include <sound/pcm.h>
  33. #include <sound/soc.h>
  34. #include <sound/soc-dapm.h>
  35. #include <sound/pcm_params.h>
  36. #include <asm/dma.h>
  37. #include <asm/portmux.h>
  38. #include <linux/gpio.h>
  39. #include "../codecs/ssm2602.h"
  40. #include "bf5xx-sport.h"
  41. #include "bf5xx-i2s-pcm.h"
  42. #include "bf5xx-i2s.h"
  43. static struct snd_soc_card bf5xx_ssm2602;
  44. static int bf5xx_ssm2602_startup(struct snd_pcm_substream *substream)
  45. {
  46. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  47. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  48. pr_debug("%s enter\n", __func__);
  49. cpu_dai->private_data = sport_handle;
  50. return 0;
  51. }
  52. static int bf5xx_ssm2602_hw_params(struct snd_pcm_substream *substream,
  53. struct snd_pcm_hw_params *params)
  54. {
  55. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  56. struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  57. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  58. unsigned int clk = 0;
  59. int ret = 0;
  60. pr_debug("%s rate %d format %x\n", __func__, params_rate(params),
  61. params_format(params));
  62. /*
  63. * If you are using a crystal source which frequency is not 12MHz
  64. * then modify the below case statement with frequency of the crystal.
  65. *
  66. * If you are using the SPORT to generate clocking then this is
  67. * where to do it.
  68. */
  69. switch (params_rate(params)) {
  70. case 8000:
  71. case 16000:
  72. case 48000:
  73. case 96000:
  74. case 11025:
  75. case 22050:
  76. case 44100:
  77. clk = 12000000;
  78. break;
  79. }
  80. /*
  81. * CODEC is master for BCLK and LRC in this configuration.
  82. */
  83. /* set codec DAI configuration */
  84. ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
  85. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  86. if (ret < 0)
  87. return ret;
  88. /* set cpu DAI configuration */
  89. ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
  90. SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBM_CFM);
  91. if (ret < 0)
  92. return ret;
  93. ret = snd_soc_dai_set_sysclk(codec_dai, SSM2602_SYSCLK, clk,
  94. SND_SOC_CLOCK_IN);
  95. if (ret < 0)
  96. return ret;
  97. return 0;
  98. }
  99. static struct snd_soc_ops bf5xx_ssm2602_ops = {
  100. .startup = bf5xx_ssm2602_startup,
  101. .hw_params = bf5xx_ssm2602_hw_params,
  102. };
  103. static struct snd_soc_dai_link bf5xx_ssm2602_dai = {
  104. .name = "ssm2602",
  105. .stream_name = "SSM2602",
  106. .cpu_dai = &bf5xx_i2s_dai,
  107. .codec_dai = &ssm2602_dai,
  108. .ops = &bf5xx_ssm2602_ops,
  109. };
  110. /*
  111. * SSM2602 2 wire address is determined by CSB
  112. * state during powerup.
  113. * low = 0x1a
  114. * high = 0x1b
  115. */
  116. static struct ssm2602_setup_data bf5xx_ssm2602_setup = {
  117. .i2c_bus = 0,
  118. .i2c_address = 0x1b,
  119. };
  120. static struct snd_soc_card bf5xx_ssm2602 = {
  121. .name = "bf5xx_ssm2602",
  122. .platform = &bf5xx_i2s_soc_platform,
  123. .dai_link = &bf5xx_ssm2602_dai,
  124. .num_links = 1,
  125. };
  126. static struct snd_soc_device bf5xx_ssm2602_snd_devdata = {
  127. .card = &bf5xx_ssm2602,
  128. .codec_dev = &soc_codec_dev_ssm2602,
  129. .codec_data = &bf5xx_ssm2602_setup,
  130. };
  131. static struct platform_device *bf5xx_ssm2602_snd_device;
  132. static int __init bf5xx_ssm2602_init(void)
  133. {
  134. int ret;
  135. pr_debug("%s enter\n", __func__);
  136. bf5xx_ssm2602_snd_device = platform_device_alloc("soc-audio", -1);
  137. if (!bf5xx_ssm2602_snd_device)
  138. return -ENOMEM;
  139. platform_set_drvdata(bf5xx_ssm2602_snd_device,
  140. &bf5xx_ssm2602_snd_devdata);
  141. bf5xx_ssm2602_snd_devdata.dev = &bf5xx_ssm2602_snd_device->dev;
  142. ret = platform_device_add(bf5xx_ssm2602_snd_device);
  143. if (ret)
  144. platform_device_put(bf5xx_ssm2602_snd_device);
  145. return ret;
  146. }
  147. static void __exit bf5xx_ssm2602_exit(void)
  148. {
  149. pr_debug("%s enter\n", __func__);
  150. platform_device_unregister(bf5xx_ssm2602_snd_device);
  151. }
  152. module_init(bf5xx_ssm2602_init);
  153. module_exit(bf5xx_ssm2602_exit);
  154. /* Module information */
  155. MODULE_AUTHOR("Cliff Cai");
  156. MODULE_DESCRIPTION("ALSA SoC SSM2602 BF527-EZKIT");
  157. MODULE_LICENSE("GPL");