s3c64xx-i2s-v4.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /* sound/soc/s3c24xx/s3c64xx-i2s-v4.c
  2. *
  3. * ALSA SoC Audio Layer - S3C64XX I2Sv4 driver
  4. * Copyright (c) 2010 Samsung Electronics Co. Ltd
  5. * Author: Jaswinder Singh <jassi.brar@samsung.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/gpio.h>
  13. #include <linux/io.h>
  14. #include <sound/soc.h>
  15. #include <sound/pcm_params.h>
  16. #include <plat/audio.h>
  17. #include <mach/map.h>
  18. #include <mach/dma.h>
  19. #include "s3c-dma.h"
  20. #include "regs-i2s-v2.h"
  21. #include "s3c64xx-i2s.h"
  22. static struct s3c2410_dma_client s3c64xx_dma_client_out = {
  23. .name = "I2Sv4 PCM Stereo out"
  24. };
  25. static struct s3c2410_dma_client s3c64xx_dma_client_in = {
  26. .name = "I2Sv4 PCM Stereo in"
  27. };
  28. static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
  29. static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
  30. static struct s3c_i2sv2_info s3c64xx_i2sv4;
  31. static int s3c64xx_i2sv4_probe(struct snd_soc_dai *dai)
  32. {
  33. struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
  34. int ret = 0;
  35. snd_soc_dai_set_drvdata(dai, i2s);
  36. ret = s3c_i2sv2_probe(dai, i2s, i2s->base);
  37. return ret;
  38. }
  39. static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
  40. struct snd_pcm_hw_params *params,
  41. struct snd_soc_dai *cpu_dai)
  42. {
  43. struct s3c_i2sv2_info *i2s = snd_soc_dai_get_drvdata(cpu_dai);
  44. struct s3c_dma_params *dma_data;
  45. u32 iismod;
  46. dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
  47. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  48. dma_data = i2s->dma_playback;
  49. else
  50. dma_data = i2s->dma_capture;
  51. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  52. iismod = readl(i2s->regs + S3C2412_IISMOD);
  53. dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
  54. iismod &= ~S3C64XX_IISMOD_BLC_MASK;
  55. switch (params_format(params)) {
  56. case SNDRV_PCM_FORMAT_S8:
  57. iismod |= S3C64XX_IISMOD_BLC_8BIT;
  58. break;
  59. case SNDRV_PCM_FORMAT_S16_LE:
  60. break;
  61. case SNDRV_PCM_FORMAT_S24_LE:
  62. iismod |= S3C64XX_IISMOD_BLC_24BIT;
  63. break;
  64. }
  65. writel(iismod, i2s->regs + S3C2412_IISMOD);
  66. dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
  67. return 0;
  68. }
  69. static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
  70. .hw_params = s3c_i2sv4_hw_params,
  71. };
  72. static struct snd_soc_dai_driver s3c64xx_i2s_v4_dai = {
  73. .symmetric_rates = 1,
  74. .playback = {
  75. .channels_min = 2,
  76. .channels_max = 2,
  77. .rates = S3C64XX_I2S_RATES,
  78. .formats = S3C64XX_I2S_FMTS,
  79. },
  80. .capture = {
  81. .channels_min = 2,
  82. .channels_max = 2,
  83. .rates = S3C64XX_I2S_RATES,
  84. .formats = S3C64XX_I2S_FMTS,
  85. },
  86. .probe = s3c64xx_i2sv4_probe,
  87. .ops = &s3c64xx_i2sv4_dai_ops,
  88. };
  89. static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
  90. {
  91. struct s3c_audio_pdata *i2s_pdata;
  92. struct s3c_i2sv2_info *i2s;
  93. struct resource *res;
  94. int ret;
  95. i2s = &s3c64xx_i2sv4;
  96. i2s->feature |= S3C_FEATURE_CDCLKCON;
  97. i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
  98. i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
  99. res = platform_get_resource(pdev, IORESOURCE_DMA, 0);
  100. if (!res) {
  101. dev_err(&pdev->dev, "Unable to get I2S-TX dma resource\n");
  102. return -ENXIO;
  103. }
  104. i2s->dma_playback->channel = res->start;
  105. res = platform_get_resource(pdev, IORESOURCE_DMA, 1);
  106. if (!res) {
  107. dev_err(&pdev->dev, "Unable to get I2S-RX dma resource\n");
  108. return -ENXIO;
  109. }
  110. i2s->dma_capture->channel = res->start;
  111. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  112. if (!res) {
  113. dev_err(&pdev->dev, "Unable to get I2S SFR address\n");
  114. return -ENXIO;
  115. }
  116. if (!request_mem_region(res->start, resource_size(res),
  117. "s3c64xx-i2s-v4")) {
  118. dev_err(&pdev->dev, "Unable to request SFR region\n");
  119. return -EBUSY;
  120. }
  121. i2s->dma_capture->dma_addr = res->start + S3C2412_IISRXD;
  122. i2s->dma_playback->dma_addr = res->start + S3C2412_IISTXD;
  123. i2s->dma_capture->client = &s3c64xx_dma_client_in;
  124. i2s->dma_capture->dma_size = 4;
  125. i2s->dma_playback->client = &s3c64xx_dma_client_out;
  126. i2s->dma_playback->dma_size = 4;
  127. i2s->base = res->start;
  128. i2s_pdata = pdev->dev.platform_data;
  129. if (i2s_pdata && i2s_pdata->cfg_gpio && i2s_pdata->cfg_gpio(pdev)) {
  130. dev_err(&pdev->dev, "Unable to configure gpio\n");
  131. return -EINVAL;
  132. }
  133. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  134. if (IS_ERR(i2s->iis_cclk)) {
  135. dev_err(&pdev->dev, "failed to get audio-bus\n");
  136. ret = PTR_ERR(i2s->iis_cclk);
  137. goto err;
  138. }
  139. clk_enable(i2s->iis_cclk);
  140. ret = s3c_i2sv2_register_dai(&pdev->dev, pdev->id, &s3c64xx_i2s_v4_dai);
  141. if (ret != 0)
  142. goto err_i2sv2;
  143. return 0;
  144. err_i2sv2:
  145. clk_put(i2s->iis_cclk);
  146. err:
  147. return ret;
  148. }
  149. static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
  150. {
  151. struct s3c_i2sv2_info *i2s = &s3c64xx_i2sv4;
  152. struct resource *res;
  153. snd_soc_unregister_dai(&pdev->dev);
  154. clk_put(i2s->iis_cclk);
  155. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  156. if (res)
  157. release_mem_region(res->start, resource_size(res));
  158. else
  159. dev_warn(&pdev->dev, "Unable to get I2S SFR address\n");
  160. return 0;
  161. }
  162. static struct platform_driver s3c64xx_i2sv4_driver = {
  163. .probe = s3c64xx_i2sv4_dev_probe,
  164. .remove = s3c64xx_i2sv4_dev_remove,
  165. .driver = {
  166. .name = "s3c64xx-iis-v4",
  167. .owner = THIS_MODULE,
  168. },
  169. };
  170. static int __init s3c64xx_i2sv4_init(void)
  171. {
  172. return platform_driver_register(&s3c64xx_i2sv4_driver);
  173. }
  174. module_init(s3c64xx_i2sv4_init);
  175. static void __exit s3c64xx_i2sv4_exit(void)
  176. {
  177. platform_driver_unregister(&s3c64xx_i2sv4_driver);
  178. }
  179. module_exit(s3c64xx_i2sv4_exit);
  180. /* Module information */
  181. MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
  182. MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
  183. MODULE_LICENSE("GPL");
  184. MODULE_ALIAS("platform:s3c64xx-iis-v4");