s3c64xx-i2s.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* sound/soc/s3c24xx/s3c64xx-i2s.c
  2. *
  3. * ALSA SoC Audio Layer - S3C64XX I2S driver
  4. *
  5. * Copyright 2008 Openmoko, Inc.
  6. * Copyright 2008 Simtec Electronics
  7. * Ben Dooks <ben@simtec.co.uk>
  8. * http://armlinux.simtec.co.uk/
  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 version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/device.h>
  17. #include <linux/delay.h>
  18. #include <linux/clk.h>
  19. #include <linux/kernel.h>
  20. #include <linux/gpio.h>
  21. #include <linux/io.h>
  22. #include <sound/core.h>
  23. #include <sound/pcm.h>
  24. #include <sound/pcm_params.h>
  25. #include <sound/initval.h>
  26. #include <sound/soc.h>
  27. #include <plat/regs-s3c2412-iis.h>
  28. #include <plat/gpio-bank-d.h>
  29. #include <plat/gpio-bank-e.h>
  30. #include <plat/gpio-cfg.h>
  31. #include <plat/audio.h>
  32. #include <mach/map.h>
  33. #include <mach/dma.h>
  34. #include "s3c24xx-pcm.h"
  35. #include "s3c64xx-i2s.h"
  36. static struct s3c2410_dma_client s3c64xx_dma_client_out = {
  37. .name = "I2S PCM Stereo out"
  38. };
  39. static struct s3c2410_dma_client s3c64xx_dma_client_in = {
  40. .name = "I2S PCM Stereo in"
  41. };
  42. static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
  43. [0] = {
  44. .channel = DMACH_I2S0_OUT,
  45. .client = &s3c64xx_dma_client_out,
  46. .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
  47. .dma_size = 4,
  48. },
  49. [1] = {
  50. .channel = DMACH_I2S1_OUT,
  51. .client = &s3c64xx_dma_client_out,
  52. .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
  53. .dma_size = 4,
  54. },
  55. };
  56. static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
  57. [0] = {
  58. .channel = DMACH_I2S0_IN,
  59. .client = &s3c64xx_dma_client_in,
  60. .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
  61. .dma_size = 4,
  62. },
  63. [1] = {
  64. .channel = DMACH_I2S1_IN,
  65. .client = &s3c64xx_dma_client_in,
  66. .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
  67. .dma_size = 4,
  68. },
  69. };
  70. static struct s3c_i2sv2_info s3c64xx_i2s[2];
  71. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  72. {
  73. return cpu_dai->private_data;
  74. }
  75. static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
  76. int clk_id, unsigned int freq, int dir)
  77. {
  78. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  79. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  80. switch (clk_id) {
  81. case S3C64XX_CLKSRC_PCLK:
  82. iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
  83. break;
  84. case S3C64XX_CLKSRC_MUX:
  85. iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
  86. break;
  87. default:
  88. return -EINVAL;
  89. }
  90. writel(iismod, i2s->regs + S3C2412_IISMOD);
  91. return 0;
  92. }
  93. unsigned long s3c64xx_i2s_get_clockrate(struct snd_soc_dai *dai)
  94. {
  95. struct s3c_i2sv2_info *i2s = to_info(dai);
  96. return clk_get_rate(i2s->iis_cclk);
  97. }
  98. EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clockrate);
  99. static int s3c64xx_i2s_probe(struct platform_device *pdev,
  100. struct snd_soc_dai *dai)
  101. {
  102. struct device *dev = &pdev->dev;
  103. struct s3c_i2sv2_info *i2s;
  104. int ret;
  105. dev_dbg(dev, "%s: probing dai %d\n", __func__, pdev->id);
  106. if (pdev->id < 0 || pdev->id > ARRAY_SIZE(s3c64xx_i2s)) {
  107. dev_err(dev, "id %d out of range\n", pdev->id);
  108. return -EINVAL;
  109. }
  110. i2s = &s3c64xx_i2s[pdev->id];
  111. ret = s3c_i2sv2_probe(pdev, dai, i2s,
  112. pdev->id ? S3C64XX_PA_IIS1 : S3C64XX_PA_IIS0);
  113. if (ret)
  114. return ret;
  115. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  116. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  117. i2s->iis_cclk = clk_get(dev, "audio-bus");
  118. if (IS_ERR(i2s->iis_cclk)) {
  119. dev_err(dev, "failed to get audio-bus");
  120. iounmap(i2s->regs);
  121. return -ENODEV;
  122. }
  123. /* configure GPIO for i2s port */
  124. switch (pdev->id) {
  125. case 0:
  126. s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
  127. s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
  128. s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
  129. s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
  130. s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
  131. break;
  132. case 1:
  133. s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
  134. s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
  135. s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
  136. s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
  137. s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
  138. }
  139. return 0;
  140. }
  141. #define S3C64XX_I2S_RATES \
  142. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  143. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  144. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  145. #define S3C64XX_I2S_FMTS \
  146. (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE)
  147. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
  148. .set_sysclk = s3c64xx_i2s_set_sysclk,
  149. };
  150. struct snd_soc_dai s3c64xx_i2s_dai = {
  151. .name = "s3c64xx-i2s",
  152. .id = 0,
  153. .probe = s3c64xx_i2s_probe,
  154. .playback = {
  155. .channels_min = 2,
  156. .channels_max = 2,
  157. .rates = S3C64XX_I2S_RATES,
  158. .formats = S3C64XX_I2S_FMTS,
  159. },
  160. .capture = {
  161. .channels_min = 2,
  162. .channels_max = 2,
  163. .rates = S3C64XX_I2S_RATES,
  164. .formats = S3C64XX_I2S_FMTS,
  165. },
  166. .ops = &s3c64xx_i2s_dai_ops,
  167. };
  168. EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
  169. static int __init s3c64xx_i2s_init(void)
  170. {
  171. return s3c_i2sv2_register_dai(&s3c64xx_i2s_dai);
  172. }
  173. module_init(s3c64xx_i2s_init);
  174. static void __exit s3c64xx_i2s_exit(void)
  175. {
  176. snd_soc_unregister_dai(&s3c64xx_i2s_dai);
  177. }
  178. module_exit(s3c64xx_i2s_exit);
  179. /* Module information */
  180. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  181. MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
  182. MODULE_LICENSE("GPL");