s3c64xx-i2s.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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/module.h>
  15. #include <linux/clk.h>
  16. #include <linux/gpio.h>
  17. #include <linux/io.h>
  18. #include <linux/slab.h>
  19. #include <sound/soc.h>
  20. #include <plat/audio.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 clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
  40. {
  41. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
  42. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  43. if (iismod & S3C2412_IISMOD_IMS_SYSMUX)
  44. return i2s->iis_cclk;
  45. else
  46. return i2s->iis_pclk;
  47. }
  48. EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
  49. static int s3c64xx_i2s_probe(struct snd_soc_dai *dai)
  50. {
  51. struct s3c_i2sv2_info *i2s;
  52. int ret;
  53. if (dai->id >= MAX_I2SV3) {
  54. dev_err(dai->dev, "id %d out of range\n", dai->id);
  55. return -EINVAL;
  56. }
  57. i2s = &s3c64xx_i2s[dai->id];
  58. snd_soc_dai_set_drvdata(dai, i2s);
  59. i2s->iis_cclk = clk_get(dai->dev, "audio-bus");
  60. if (IS_ERR(i2s->iis_cclk)) {
  61. dev_err(dai->dev, "failed to get audio-bus\n");
  62. ret = PTR_ERR(i2s->iis_cclk);
  63. goto err;
  64. }
  65. clk_enable(i2s->iis_cclk);
  66. ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
  67. if (ret)
  68. goto err_clk;
  69. return 0;
  70. err_clk:
  71. clk_disable(i2s->iis_cclk);
  72. clk_put(i2s->iis_cclk);
  73. err:
  74. kfree(i2s);
  75. return ret;
  76. }
  77. static int s3c64xx_i2s_remove(struct snd_soc_dai *dai)
  78. {
  79. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(dai);
  80. clk_disable(i2s->iis_cclk);
  81. clk_put(i2s->iis_cclk);
  82. kfree(i2s);
  83. return 0;
  84. }
  85. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops;
  86. static struct snd_soc_dai_driver s3c64xx_i2s_dai[MAX_I2SV3] = {
  87. {
  88. .name = "s3c64xx-i2s-0",
  89. .probe = s3c64xx_i2s_probe,
  90. .remove = s3c64xx_i2s_remove,
  91. .playback = {
  92. .channels_min = 2,
  93. .channels_max = 2,
  94. .rates = S3C64XX_I2S_RATES,
  95. .formats = S3C64XX_I2S_FMTS,},
  96. .capture = {
  97. .channels_min = 2,
  98. .channels_max = 2,
  99. .rates = S3C64XX_I2S_RATES,
  100. .formats = S3C64XX_I2S_FMTS,},
  101. .ops = &s3c64xx_i2s_dai_ops,
  102. .symmetric_rates = 1,
  103. }, {
  104. .name = "s3c64xx-i2s-1",
  105. .probe = s3c64xx_i2s_probe,
  106. .remove = s3c64xx_i2s_remove,
  107. .playback = {
  108. .channels_min = 2,
  109. .channels_max = 2,
  110. .rates = S3C64XX_I2S_RATES,
  111. .formats = S3C64XX_I2S_FMTS,},
  112. .capture = {
  113. .channels_min = 2,
  114. .channels_max = 2,
  115. .rates = S3C64XX_I2S_RATES,
  116. .formats = S3C64XX_I2S_FMTS,},
  117. .ops = &s3c64xx_i2s_dai_ops,
  118. .symmetric_rates = 1,
  119. },};
  120. static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
  121. {
  122. struct s3c_audio_pdata *i2s_pdata;
  123. struct s3c_i2sv2_info *i2s;
  124. struct resource *res;
  125. int i, ret;
  126. if (pdev->id >= MAX_I2SV3) {
  127. dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
  128. return -EINVAL;
  129. }
  130. i2s = &s3c64xx_i2s[pdev->id];
  131. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  132. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  133. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  134. if (!res) {
  135. dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
  136. return -ENXIO;
  137. }
  138. i2s->dma_playback->channel = res->start;
  139. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  140. if (!res) {
  141. dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
  142. return -ENXIO;
  143. }
  144. i2s->dma_capture->channel = res->start;
  145. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  146. if (!res) {
  147. dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
  148. return -ENXIO;
  149. }
  150. if (!request_mem_region(res->start, resource_size(res),
  151. "s3c64xx-i2s")) {
  152. dev_err(&pdev->dev, "Unable to request SFR region\n");
  153. return -EBUSY;
  154. }
  155. i2s->base = res->start;
  156. i2s_pdata = pdev->dev.platform_data;
  157. if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
  158. dev_err(&pdev->dev, "Unable to configure gpio\n");
  159. return -EINVAL;
  160. }
  161. i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
  162. i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
  163. i2s->dma_capture->client = &s3c64xx_dma_client_in;
  164. i2s->dma_capture->dma_size = 4;
  165. i2s->dma_playback->client = &s3c64xx_dma_client_out;
  166. i2s->dma_playback->dma_size = 4;
  167. for (i = 0; i < ARRAY_SIZE(s3c64xx_i2s_dai); i++) {
  168. ret = s3c_i2sv2_register_dai(&pdev->dev, i,
  169. &s3c64xx_i2s_dai[i]);
  170. if (ret != 0)
  171. return ret;
  172. }
  173. return 0;
  174. }
  175. static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
  176. {
  177. snd_soc_unregister_dais(&pdev->dev, ARRAY_SIZE(s3c64xx_i2s_dai));
  178. return 0;
  179. }
  180. static struct platform_driver s3c64xx_iis_driver = {
  181. .probe = s3c64xx_iis_dev_probe,
  182. .remove = s3c64xx_iis_dev_remove,
  183. .driver = {
  184. .name = "s3c64xx-iis",
  185. .owner = THIS_MODULE,
  186. },
  187. };
  188. static int __init s3c64xx_i2s_init(void)
  189. {
  190. return platform_driver_register(&s3c64xx_iis_driver);
  191. }
  192. module_init(s3c64xx_i2s_init);
  193. static void __exit s3c64xx_i2s_exit(void)
  194. {
  195. platform_driver_unregister(&s3c64xx_iis_driver);
  196. }
  197. module_exit(s3c64xx_i2s_exit);
  198. /* Module information */
  199. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  200. MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
  201. MODULE_LICENSE("GPL");
  202. MODULE_ALIAS("platform:s3c64xx-iis");