s3c64xx-i2s.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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/clk.h>
  15. #include <linux/gpio.h>
  16. #include <linux/io.h>
  17. #include <sound/soc.h>
  18. #include <mach/gpio-bank-d.h>
  19. #include <mach/gpio-bank-e.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <mach/map.h>
  22. #include <mach/dma.h>
  23. #include "s3c-dma.h"
  24. #include "regs-i2s-v2.h"
  25. #include "s3c64xx-i2s.h"
  26. /* The value should be set to maximum of the total number
  27. * of I2Sv3 controllers that any supported SoC has.
  28. */
  29. #define MAX_I2SV3 2
  30. static struct s3c2410_dma_client s3c64xx_dma_client_out = {
  31. .name = "I2S PCM Stereo out"
  32. };
  33. static struct s3c2410_dma_client s3c64xx_dma_client_in = {
  34. .name = "I2S PCM Stereo in"
  35. };
  36. static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[MAX_I2SV3];
  37. static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[MAX_I2SV3];
  38. static struct s3c_i2sv2_info s3c64xx_i2s[MAX_I2SV3];
  39. struct snd_soc_dai s3c64xx_i2s_dai[MAX_I2SV3];
  40. EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
  41. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  42. {
  43. return cpu_dai->private_data;
  44. }
  45. static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
  46. int clk_id, unsigned int freq, int dir)
  47. {
  48. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  49. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  50. switch (clk_id) {
  51. case S3C64XX_CLKSRC_PCLK:
  52. iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
  53. break;
  54. case S3C64XX_CLKSRC_MUX:
  55. iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
  56. break;
  57. case S3C64XX_CLKSRC_CDCLK:
  58. switch (dir) {
  59. case SND_SOC_CLOCK_IN:
  60. iismod |= S3C64XX_IISMOD_CDCLKCON;
  61. break;
  62. case SND_SOC_CLOCK_OUT:
  63. iismod &= ~S3C64XX_IISMOD_CDCLKCON;
  64. break;
  65. default:
  66. return -EINVAL;
  67. }
  68. break;
  69. default:
  70. return -EINVAL;
  71. }
  72. writel(iismod, i2s->regs + S3C2412_IISMOD);
  73. return 0;
  74. }
  75. static int s3c64xx_i2s_probe(struct platform_device *pdev,
  76. struct snd_soc_dai *dai)
  77. {
  78. /* configure GPIO for i2s port */
  79. switch (dai->id) {
  80. case 0:
  81. s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
  82. s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
  83. s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
  84. s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
  85. s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
  86. break;
  87. case 1:
  88. s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
  89. s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
  90. s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
  91. s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
  92. s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
  93. }
  94. return 0;
  95. }
  96. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
  97. .set_sysclk = s3c64xx_i2s_set_sysclk,
  98. };
  99. static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
  100. {
  101. struct s3c_i2sv2_info *i2s;
  102. struct snd_soc_dai *dai;
  103. int ret;
  104. if (pdev->id >= MAX_I2SV3) {
  105. dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
  106. return -EINVAL;
  107. }
  108. i2s = &s3c64xx_i2s[pdev->id];
  109. dai = &s3c64xx_i2s_dai[pdev->id];
  110. dai->dev = &pdev->dev;
  111. dai->name = "s3c64xx-i2s";
  112. dai->id = pdev->id;
  113. dai->symmetric_rates = 1;
  114. dai->playback.channels_min = 2;
  115. dai->playback.channels_max = 2;
  116. dai->playback.rates = S3C64XX_I2S_RATES;
  117. dai->playback.formats = S3C64XX_I2S_FMTS;
  118. dai->capture.channels_min = 2;
  119. dai->capture.channels_max = 2;
  120. dai->capture.rates = S3C64XX_I2S_RATES;
  121. dai->capture.formats = S3C64XX_I2S_FMTS;
  122. dai->probe = s3c64xx_i2s_probe;
  123. dai->ops = &s3c64xx_i2s_dai_ops;
  124. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  125. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  126. if (pdev->id == 0) {
  127. i2s->dma_capture->channel = DMACH_I2S0_IN;
  128. i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD;
  129. i2s->dma_playback->channel = DMACH_I2S0_OUT;
  130. i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD;
  131. } else {
  132. i2s->dma_capture->channel = DMACH_I2S1_IN;
  133. i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD;
  134. i2s->dma_playback->channel = DMACH_I2S1_OUT;
  135. i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD;
  136. }
  137. i2s->dma_capture->client = &s3c64xx_dma_client_in;
  138. i2s->dma_capture->dma_size = 4;
  139. i2s->dma_playback->client = &s3c64xx_dma_client_out;
  140. i2s->dma_playback->dma_size = 4;
  141. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  142. if (IS_ERR(i2s->iis_cclk)) {
  143. dev_err(&pdev->dev, "failed to get audio-bus\n");
  144. ret = PTR_ERR(i2s->iis_cclk);
  145. goto err;
  146. }
  147. clk_enable(i2s->iis_cclk);
  148. ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
  149. if (ret)
  150. goto err_clk;
  151. ret = s3c_i2sv2_register_dai(dai);
  152. if (ret != 0)
  153. goto err_i2sv2;
  154. return 0;
  155. err_i2sv2:
  156. /* Not implemented for I2Sv2 core yet */
  157. err_clk:
  158. clk_put(i2s->iis_cclk);
  159. err:
  160. return ret;
  161. }
  162. static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
  163. {
  164. dev_err(&pdev->dev, "Device removal not yet supported\n");
  165. return 0;
  166. }
  167. static struct platform_driver s3c64xx_iis_driver = {
  168. .probe = s3c64xx_iis_dev_probe,
  169. .remove = s3c64xx_iis_dev_remove,
  170. .driver = {
  171. .name = "s3c64xx-iis",
  172. .owner = THIS_MODULE,
  173. },
  174. };
  175. static int __init s3c64xx_i2s_init(void)
  176. {
  177. return platform_driver_register(&s3c64xx_iis_driver);
  178. }
  179. module_init(s3c64xx_i2s_init);
  180. static void __exit s3c64xx_i2s_exit(void)
  181. {
  182. platform_driver_unregister(&s3c64xx_iis_driver);
  183. }
  184. module_exit(s3c64xx_i2s_exit);
  185. /* Module information */
  186. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  187. MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
  188. MODULE_LICENSE("GPL");