s3c2412-i2s.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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/dma.h>
  26. #include <mach/gpio-samsung.h>
  27. #include <plat/gpio-cfg.h>
  28. #include "dma.h"
  29. #include "regs-i2s-v2.h"
  30. #include "s3c2412-i2s.h"
  31. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_out = {
  32. .channel = DMACH_I2S_OUT,
  33. .ch_name = "tx",
  34. .dma_size = 4,
  35. };
  36. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
  37. .channel = DMACH_I2S_IN,
  38. .ch_name = "rx",
  39. .dma_size = 4,
  40. };
  41. static struct s3c_i2sv2_info s3c2412_i2s;
  42. static int s3c2412_i2s_probe(struct snd_soc_dai *dai)
  43. {
  44. int ret;
  45. pr_debug("Entered %s\n", __func__);
  46. samsung_asoc_init_dma_data(dai, &s3c2412_i2s_pcm_stereo_out,
  47. &s3c2412_i2s_pcm_stereo_in);
  48. ret = s3c_i2sv2_probe(dai, &s3c2412_i2s, S3C2410_PA_IIS);
  49. if (ret)
  50. return ret;
  51. s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
  52. s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
  53. s3c2412_i2s.iis_cclk = devm_clk_get(dai->dev, "i2sclk");
  54. if (IS_ERR(s3c2412_i2s.iis_cclk)) {
  55. pr_err("failed to get i2sclk clock\n");
  56. return PTR_ERR(s3c2412_i2s.iis_cclk);
  57. }
  58. /* Set MPLL as the source for IIS CLK */
  59. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  60. clk_prepare_enable(s3c2412_i2s.iis_cclk);
  61. s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
  62. /* Configure the I2S pins (GPE0...GPE4) in correct mode */
  63. s3c_gpio_cfgall_range(S3C2410_GPE(0), 5, S3C_GPIO_SFN(2),
  64. S3C_GPIO_PULL_NONE);
  65. return 0;
  66. }
  67. static int s3c2412_i2s_remove(struct snd_soc_dai *dai)
  68. {
  69. clk_disable_unprepare(s3c2412_i2s.iis_cclk);
  70. return 0;
  71. }
  72. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  73. struct snd_pcm_hw_params *params,
  74. struct snd_soc_dai *cpu_dai)
  75. {
  76. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
  77. u32 iismod;
  78. pr_debug("Entered %s\n", __func__);
  79. iismod = readl(i2s->regs + S3C2412_IISMOD);
  80. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  81. switch (params_width(params)) {
  82. case 8:
  83. iismod |= S3C2412_IISMOD_8BIT;
  84. break;
  85. case 16:
  86. iismod &= ~S3C2412_IISMOD_8BIT;
  87. break;
  88. }
  89. writel(iismod, i2s->regs + S3C2412_IISMOD);
  90. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  91. return 0;
  92. }
  93. #define S3C2412_I2S_RATES \
  94. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  95. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  96. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  97. static const struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
  98. .hw_params = s3c2412_i2s_hw_params,
  99. };
  100. static struct snd_soc_dai_driver s3c2412_i2s_dai = {
  101. .probe = s3c2412_i2s_probe,
  102. .remove = s3c2412_i2s_remove,
  103. .playback = {
  104. .channels_min = 2,
  105. .channels_max = 2,
  106. .rates = S3C2412_I2S_RATES,
  107. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  108. },
  109. .capture = {
  110. .channels_min = 2,
  111. .channels_max = 2,
  112. .rates = S3C2412_I2S_RATES,
  113. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  114. },
  115. .ops = &s3c2412_i2s_dai_ops,
  116. };
  117. static const struct snd_soc_component_driver s3c2412_i2s_component = {
  118. .name = "s3c2412-i2s",
  119. };
  120. static int s3c2412_iis_dev_probe(struct platform_device *pdev)
  121. {
  122. int ret = 0;
  123. struct resource *res;
  124. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  125. s3c2412_i2s.regs = devm_ioremap_resource(&pdev->dev, res);
  126. if (IS_ERR(s3c2412_i2s.regs))
  127. return PTR_ERR(s3c2412_i2s.regs);
  128. s3c2412_i2s_pcm_stereo_out.dma_addr = res->start + S3C2412_IISTXD;
  129. s3c2412_i2s_pcm_stereo_in.dma_addr = res->start + S3C2412_IISRXD;
  130. ret = s3c_i2sv2_register_component(&pdev->dev, -1,
  131. &s3c2412_i2s_component,
  132. &s3c2412_i2s_dai);
  133. if (ret) {
  134. pr_err("failed to register the dai\n");
  135. return ret;
  136. }
  137. ret = samsung_asoc_dma_platform_register(&pdev->dev);
  138. if (ret)
  139. pr_err("failed to register the DMA: %d\n", ret);
  140. return ret;
  141. }
  142. static struct platform_driver s3c2412_iis_driver = {
  143. .probe = s3c2412_iis_dev_probe,
  144. .driver = {
  145. .name = "s3c2412-iis",
  146. .owner = THIS_MODULE,
  147. },
  148. };
  149. module_platform_driver(s3c2412_iis_driver);
  150. /* Module information */
  151. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  152. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  153. MODULE_LICENSE("GPL");
  154. MODULE_ALIAS("platform:s3c2412-iis");