s3c64xx-i2s.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_probe(struct platform_device *pdev,
  46. struct snd_soc_dai *dai)
  47. {
  48. /* configure GPIO for i2s port */
  49. switch (dai->id) {
  50. case 0:
  51. s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
  52. s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
  53. s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
  54. s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
  55. s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
  56. break;
  57. case 1:
  58. s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
  59. s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
  60. s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
  61. s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
  62. s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
  63. }
  64. return 0;
  65. }
  66. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
  67. static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
  68. {
  69. struct s3c_i2sv2_info *i2s;
  70. struct snd_soc_dai *dai;
  71. int ret;
  72. if (pdev->id >= MAX_I2SV3) {
  73. dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
  74. return -EINVAL;
  75. }
  76. i2s = &s3c64xx_i2s[pdev->id];
  77. dai = &s3c64xx_i2s_dai[pdev->id];
  78. dai->dev = &pdev->dev;
  79. dai->name = "s3c64xx-i2s";
  80. dai->id = pdev->id;
  81. dai->symmetric_rates = 1;
  82. dai->playback.channels_min = 2;
  83. dai->playback.channels_max = 2;
  84. dai->playback.rates = S3C64XX_I2S_RATES;
  85. dai->playback.formats = S3C64XX_I2S_FMTS;
  86. dai->capture.channels_min = 2;
  87. dai->capture.channels_max = 2;
  88. dai->capture.rates = S3C64XX_I2S_RATES;
  89. dai->capture.formats = S3C64XX_I2S_FMTS;
  90. dai->probe = s3c64xx_i2s_probe;
  91. dai->ops = &s3c64xx_i2s_dai_ops;
  92. i2s->feature |= S3C_FEATURE_CDCLKCON;
  93. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  94. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  95. if (pdev->id == 0) {
  96. i2s->dma_capture->channel = DMACH_I2S0_IN;
  97. i2s->dma_capture->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD;
  98. i2s->dma_playback->channel = DMACH_I2S0_OUT;
  99. i2s->dma_playback->dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD;
  100. } else {
  101. i2s->dma_capture->channel = DMACH_I2S1_IN;
  102. i2s->dma_capture->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD;
  103. i2s->dma_playback->channel = DMACH_I2S1_OUT;
  104. i2s->dma_playback->dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD;
  105. }
  106. i2s->dma_capture->client = &s3c64xx_dma_client_in;
  107. i2s->dma_capture->dma_size = 4;
  108. i2s->dma_playback->client = &s3c64xx_dma_client_out;
  109. i2s->dma_playback->dma_size = 4;
  110. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  111. if (IS_ERR(i2s->iis_cclk)) {
  112. dev_err(&pdev->dev, "failed to get audio-bus\n");
  113. ret = PTR_ERR(i2s->iis_cclk);
  114. goto err;
  115. }
  116. clk_enable(i2s->iis_cclk);
  117. ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
  118. if (ret)
  119. goto err_clk;
  120. ret = s3c_i2sv2_register_dai(dai);
  121. if (ret != 0)
  122. goto err_i2sv2;
  123. return 0;
  124. err_i2sv2:
  125. /* Not implemented for I2Sv2 core yet */
  126. err_clk:
  127. clk_put(i2s->iis_cclk);
  128. err:
  129. return ret;
  130. }
  131. static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
  132. {
  133. dev_err(&pdev->dev, "Device removal not yet supported\n");
  134. return 0;
  135. }
  136. static struct platform_driver s3c64xx_iis_driver = {
  137. .probe = s3c64xx_iis_dev_probe,
  138. .remove = s3c64xx_iis_dev_remove,
  139. .driver = {
  140. .name = "s3c64xx-iis",
  141. .owner = THIS_MODULE,
  142. },
  143. };
  144. static int __init s3c64xx_i2s_init(void)
  145. {
  146. return platform_driver_register(&s3c64xx_iis_driver);
  147. }
  148. module_init(s3c64xx_i2s_init);
  149. static void __exit s3c64xx_i2s_exit(void)
  150. {
  151. platform_driver_unregister(&s3c64xx_iis_driver);
  152. }
  153. module_exit(s3c64xx_i2s_exit);
  154. /* Module information */
  155. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  156. MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
  157. MODULE_LICENSE("GPL");