s3c2412-i2s.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* sound/soc/samsung/s3c2412-i2s.c
  2. *
  3. * ALSA Soc Audio Layer - S3C2412 I2S driver
  4. *
  5. * Copyright (c) 2006 Wolfson Microelectronics PLC.
  6. * Graeme Gregory graeme.gregory@wolfsonmicro.com
  7. * linux@wolfsonmicro.com
  8. *
  9. * Copyright (c) 2007, 2004-2005 Simtec Electronics
  10. * http://armlinux.simtec.co.uk/
  11. * Ben Dooks <ben@simtec.co.uk>
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/delay.h>
  19. #include <linux/gpio.h>
  20. #include <linux/clk.h>
  21. #include <linux/io.h>
  22. #include <linux/module.h>
  23. #include <sound/soc.h>
  24. #include <sound/pcm_params.h>
  25. #include <mach/gpio-samsung.h>
  26. #include <plat/gpio-cfg.h>
  27. #include "dma.h"
  28. #include "regs-i2s-v2.h"
  29. #include "s3c2412-i2s.h"
  30. #include <linux/platform_data/asoc-s3c.h>
  31. static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_out = {
  32. .addr_width = 4,
  33. };
  34. static struct snd_dmaengine_dai_dma_data s3c2412_i2s_pcm_stereo_in = {
  35. .addr_width = 4,
  36. };
  37. static struct s3c_i2sv2_info s3c2412_i2s;
  38. static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
  39. {
  40. int ret;
  41. pr_debug("Entered %s\n", __func__);
  42. snd_soc_dai_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
  43. &s3c2412_i2s_pcm_stereo_in);
  44. ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
  45. if (ret)
  46. return ret;
  47. s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
  48. s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
  49. s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
  50. if (IS_ERR(s3c2412_i2s.iis_cclk)) {
  51. pr_err("failed to get i2sclk clock\n");
  52. return PTR_ERR(s3c2412_i2s.iis_cclk);
  53. }
  54. /* Set MPLL as the source for IIS CLK */
  55. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  56. clk_prepare_enable(s3c2412_i2s.iis_cclk);
  57. s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
  58. /* Configure the I2S pins (GPE0...GPE4) in correct mode */
  59. s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
  60. S3C_GPIO_PULL_NONE);
  61. return 0;
  62. }
  63. static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
  64. {
  65. clk_disable_unprepare(s3c2412_i2s.iis_cclk);
  66. return 0;
  67. }
  68. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  69. struct snd_pcm_hw_params *params,
  70. struct snd_soc_dai *cpu_dai)
  71. {
  72. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
  73. u32 iismod;
  74. pr_debug("Entered %s\n", __func__);
  75. iismod = readl(i2s->regs + S3C2412_IISMOD);
  76. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  77. switch (params_width(params)) {
  78. case 8:
  79. iismod |= S3C2412_IISMOD_8BIT;
  80. break;
  81. case 16:
  82. iismod &= ~S3C2412_IISMOD_8BIT;
  83. break;
  84. }
  85. writel(iismod, i2s->regs + S3C2412_IISMOD);
  86. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  87. return 0;
  88. }
  89. #define S3C2412_I2S_RATES \
  90. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  91. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  92. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  93. static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
  94. .hw_params = s3c2412_i2s_hw_params,
  95. };
  96. static struct snd_soc_dai_driver s3c2412_i2s_dai = {
  97. .probe = s3c2412_i2s_probe,
  98. .remove = s3c2412_i2s_remove,
  99. .playback = {
  100. .channels_min = 2,
  101. .channels_max = 2,
  102. .rates = S3C2412_I2S_RATES,
  103. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  104. },
  105. .capture = {
  106. .channels_min = 2,
  107. .channels_max = 2,
  108. .rates = S3C2412_I2S_RATES,
  109. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  110. },
  111. .ops = &s3c2412_i2s_dai_ops,
  112. };
  113. static const struct snd_soc_component_driver s3c2412_i2s_component = {
  114. .name = "s3c2412-i2s",
  115. };
  116. static int s3c2412_iis_dev_probe(struct platform_device *pdev)
  117. {
  118. int ret = 0;
  119. struct resource *res;
  120. struct s3c_audio_pdata *pdata = dev_get_platdata(&pdev->dev);
  121. if (!pdata) {
  122. dev_err(&pdev->dev, "missing platform data");
  123. return -ENXIO;
  124. }
  125. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  126. s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
  127. if (IS_ERR(s3c2412_i2s.regs))
  128. return PTR_ERR(s3c2412_i2s.regs);
  129. s3c2412_i2s_pcm_stereo_out.addr = res->start + S3C2412_IISTXD;
  130. s3c2412_i2s_pcm_stereo_out.filter_data = pdata->dma_playback;
  131. s3c2412_i2s_pcm_stereo_in.addr = res->start + S3C2412_IISRXD;
  132. s3c2412_i2s_pcm_stereo_in.filter_data = pdata->dma_capture;
  133. ret = samsung_asoc_dma_platform_register(&pdev->dev,
  134. pdata->dma_filter,
  135. NULL, NULL);
  136. if (ret) {
  137. pr_err("failed to register the DMA: %d\n", ret);
  138. return ret;
  139. }
  140. ret = s3c_i2sv2_register_component(&pdev->dev, -1,
  141. &s3c2412_i2s_component,
  142. &s3c2412_i2s_dai);
  143. if (ret)
  144. pr_err("failed to register the dai\n");
  145. return ret;
  146. }
  147. static struct platform_driver s3c2412_iis_driver = {
  148. .probe = s3c2412_iis_dev_probe,
  149. .driver = {
  150. .name = "s3c2412-iis",
  151. },
  152. };
  153. module_platform_driver(s3c2412_iis_driver);
  154. /* Module information */
  155. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  156. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  157. MODULE_LICENSE("GPL");
  158. MODULE_ALIAS("platform:s3c2412-iis");