s3c2412-i2s.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* sound/soc/s3c24xx/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/init.h>
  19. #include <linux/module.h>
  20. #include <linux/device.h>
  21. #include <linux/delay.h>
  22. #include <linux/gpio.h>
  23. #include <linux/clk.h>
  24. #include <linux/kernel.h>
  25. #include <linux/io.h>
  26. #include <sound/core.h>
  27. #include <sound/pcm.h>
  28. #include <sound/pcm_params.h>
  29. #include <sound/initval.h>
  30. #include <sound/soc.h>
  31. #include <mach/hardware.h>
  32. #include <mach/regs-gpio.h>
  33. #include <mach/dma.h>
  34. #include "s3c-dma.h"
  35. #include "regs-i2s-v2.h"
  36. #include "s3c2412-i2s.h"
  37. #define S3C2412_I2S_DEBUG 0
  38. static struct s3c2410_dma_client s3c2412_dma_client_out = {
  39. .name = "I2S PCM Stereo out"
  40. };
  41. static struct s3c2410_dma_client s3c2412_dma_client_in = {
  42. .name = "I2S PCM Stereo in"
  43. };
  44. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_out = {
  45. .client = &s3c2412_dma_client_out,
  46. .channel = DMACH_I2S_OUT,
  47. .dma_addr = S3C2410_PA_IIS + S3C2412_IISTXD,
  48. .dma_size = 4,
  49. };
  50. static struct s3c_dma_params s3c2412_i2s_pcm_stereo_in = {
  51. .client = &s3c2412_dma_client_in,
  52. .channel = DMACH_I2S_IN,
  53. .dma_addr = S3C2410_PA_IIS + S3C2412_IISRXD,
  54. .dma_size = 4,
  55. };
  56. static struct s3c_i2sv2_info s3c2412_i2s;
  57. /*
  58. * Set S3C2412 Clock source
  59. */
  60. static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
  61. int clk_id, unsigned int freq, int dir)
  62. {
  63. u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
  64. pr_debug("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id,
  65. freq, dir);
  66. switch (clk_id) {
  67. case S3C2412_CLKSRC_PCLK:
  68. iismod &= ~S3C2412_IISMOD_IMS_SYSMUX;
  69. break;
  70. case S3C2412_CLKSRC_I2SCLK:
  71. iismod |= S3C2412_IISMOD_IMS_SYSMUX;
  72. break;
  73. default:
  74. return -EINVAL;
  75. }
  76. writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
  77. return 0;
  78. }
  79. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  80. {
  81. return cpu_dai->private_data;
  82. }
  83. static int s3c2412_i2s_probe(struct platform_device *pdev,
  84. struct snd_soc_dai *dai)
  85. {
  86. int ret;
  87. pr_debug("Entered %s\n", __func__);
  88. ret = s3c_i2sv2_probe(pdev, dai, &s3c2412_i2s, S3C2410_PA_IIS);
  89. if (ret)
  90. return ret;
  91. s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
  92. s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
  93. s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk");
  94. if (s3c2412_i2s.iis_cclk == NULL) {
  95. pr_err("failed to get i2sclk clock\n");
  96. iounmap(s3c2412_i2s.regs);
  97. return -ENODEV;
  98. }
  99. /* Set MPLL as the source for IIS CLK */
  100. clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
  101. clk_enable(s3c2412_i2s.iis_cclk);
  102. s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
  103. /* Configure the I2S pins in correct mode */
  104. s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
  105. s3c2410_gpio_cfgpin(S3C2410_GPE1, S3C2410_GPE1_I2SSCLK);
  106. s3c2410_gpio_cfgpin(S3C2410_GPE2, S3C2410_GPE2_CDCLK);
  107. s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI);
  108. s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
  109. return 0;
  110. }
  111. static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
  112. struct snd_pcm_hw_params *params,
  113. struct snd_soc_dai *cpu_dai)
  114. {
  115. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  116. struct s3c_dma_params *dma_data;
  117. u32 iismod;
  118. pr_debug("Entered %s\n", __func__);
  119. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  120. dma_data = i2s->dma_playback;
  121. else
  122. dma_data = i2s->dma_capture;
  123. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  124. iismod = readl(i2s->regs + S3C2412_IISMOD);
  125. pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
  126. switch (params_format(params)) {
  127. case SNDRV_PCM_FORMAT_S8:
  128. iismod |= S3C2412_IISMOD_8BIT;
  129. break;
  130. case SNDRV_PCM_FORMAT_S16_LE:
  131. iismod &= ~S3C2412_IISMOD_8BIT;
  132. break;
  133. }
  134. writel(iismod, i2s->regs + S3C2412_IISMOD);
  135. pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
  136. return 0;
  137. }
  138. #define S3C2412_I2S_RATES \
  139. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  140. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  141. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  142. static struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
  143. .set_sysclk = s3c2412_i2s_set_sysclk,
  144. .hw_params = s3c2412_i2s_hw_params,
  145. };
  146. struct snd_soc_dai s3c2412_i2s_dai = {
  147. .name = "s3c2412-i2s",
  148. .id = 0,
  149. .probe = s3c2412_i2s_probe,
  150. .playback = {
  151. .channels_min = 2,
  152. .channels_max = 2,
  153. .rates = S3C2412_I2S_RATES,
  154. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  155. },
  156. .capture = {
  157. .channels_min = 2,
  158. .channels_max = 2,
  159. .rates = S3C2412_I2S_RATES,
  160. .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
  161. },
  162. .ops = &s3c2412_i2s_dai_ops,
  163. };
  164. EXPORT_SYMBOL_GPL(s3c2412_i2s_dai);
  165. static int __init s3c2412_i2s_init(void)
  166. {
  167. return s3c_i2sv2_register_dai(&s3c2412_i2s_dai);
  168. }
  169. module_init(s3c2412_i2s_init);
  170. static void __exit s3c2412_i2s_exit(void)
  171. {
  172. snd_soc_unregister_dai(&s3c2412_i2s_dai);
  173. }
  174. module_exit(s3c2412_i2s_exit);
  175. /* Module information */
  176. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  177. MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
  178. MODULE_LICENSE("GPL");