s3c64xx-i2s-v4.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 <mach/gpio-bank-c.h>
  17. #include <mach/gpio-bank-h.h>
  18. #include <plat/gpio-cfg.h>
  19. #include <mach/map.h>
  20. #include <mach/dma.h>
  21. #include "s3c-dma.h"
  22. #include "regs-i2s-v2.h"
  23. #include "s3c64xx-i2s.h"
  24. static struct s3c2410_dma_client s3c64xx_dma_client_out = {
  25. .name = "I2Sv4 PCM Stereo out"
  26. };
  27. static struct s3c2410_dma_client s3c64xx_dma_client_in = {
  28. .name = "I2Sv4 PCM Stereo in"
  29. };
  30. static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_out;
  31. static struct s3c_dma_params s3c64xx_i2sv4_pcm_stereo_in;
  32. static struct s3c_i2sv2_info s3c64xx_i2sv4;
  33. struct snd_soc_dai s3c64xx_i2s_v4_dai;
  34. EXPORT_SYMBOL_GPL(s3c64xx_i2s_v4_dai);
  35. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  36. {
  37. return cpu_dai->private_data;
  38. }
  39. static int s3c64xx_i2sv4_probe(struct platform_device *pdev,
  40. struct snd_soc_dai *dai)
  41. {
  42. /* configure GPIO for i2s port */
  43. s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C64XX_GPC4_I2S_V40_DO0);
  44. s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C64XX_GPC5_I2S_V40_DO1);
  45. s3c_gpio_cfgpin(S3C64XX_GPC(7), S3C64XX_GPC7_I2S_V40_DO2);
  46. s3c_gpio_cfgpin(S3C64XX_GPH(6), S3C64XX_GPH6_I2S_V40_BCLK);
  47. s3c_gpio_cfgpin(S3C64XX_GPH(7), S3C64XX_GPH7_I2S_V40_CDCLK);
  48. s3c_gpio_cfgpin(S3C64XX_GPH(8), S3C64XX_GPH8_I2S_V40_LRCLK);
  49. s3c_gpio_cfgpin(S3C64XX_GPH(9), S3C64XX_GPH9_I2S_V40_DI);
  50. return 0;
  51. }
  52. static int s3c_i2sv4_hw_params(struct snd_pcm_substream *substream,
  53. struct snd_pcm_hw_params *params,
  54. struct snd_soc_dai *cpu_dai)
  55. {
  56. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  57. struct s3c_dma_params *dma_data;
  58. u32 iismod;
  59. dev_dbg(cpu_dai->dev, "Entered %s\n", __func__);
  60. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  61. dma_data = i2s->dma_playback;
  62. else
  63. dma_data = i2s->dma_capture;
  64. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  65. iismod = readl(i2s->regs + S3C2412_IISMOD);
  66. dev_dbg(cpu_dai->dev, "%s: r: IISMOD: %x\n", __func__, iismod);
  67. iismod &= ~S3C64XX_IISMOD_BLC_MASK;
  68. switch (params_format(params)) {
  69. case SNDRV_PCM_FORMAT_S8:
  70. iismod |= S3C64XX_IISMOD_BLC_8BIT;
  71. break;
  72. case SNDRV_PCM_FORMAT_S16_LE:
  73. break;
  74. case SNDRV_PCM_FORMAT_S24_LE:
  75. iismod |= S3C64XX_IISMOD_BLC_24BIT;
  76. break;
  77. }
  78. writel(iismod, i2s->regs + S3C2412_IISMOD);
  79. dev_dbg(cpu_dai->dev, "%s: w: IISMOD: %x\n", __func__, iismod);
  80. return 0;
  81. }
  82. static struct snd_soc_dai_ops s3c64xx_i2sv4_dai_ops = {
  83. .hw_params = s3c_i2sv4_hw_params,
  84. };
  85. static __devinit int s3c64xx_i2sv4_dev_probe(struct platform_device *pdev)
  86. {
  87. struct s3c_i2sv2_info *i2s;
  88. struct snd_soc_dai *dai;
  89. int ret;
  90. i2s = &s3c64xx_i2sv4;
  91. dai = &s3c64xx_i2s_v4_dai;
  92. if (dai->dev) {
  93. dev_dbg(dai->dev, "%s: \
  94. I2Sv4 instance already registered!\n", __func__);
  95. return -EBUSY;
  96. }
  97. dai->dev = &pdev->dev;
  98. dai->name = "s3c64xx-i2s-v4";
  99. dai->id = 0;
  100. dai->symmetric_rates = 1;
  101. dai->playback.channels_min = 2;
  102. dai->playback.channels_max = 2;
  103. dai->playback.rates = S3C64XX_I2S_RATES;
  104. dai->playback.formats = S3C64XX_I2S_FMTS;
  105. dai->capture.channels_min = 2;
  106. dai->capture.channels_max = 2;
  107. dai->capture.rates = S3C64XX_I2S_RATES;
  108. dai->capture.formats = S3C64XX_I2S_FMTS;
  109. dai->probe = s3c64xx_i2sv4_probe;
  110. dai->ops = &s3c64xx_i2sv4_dai_ops;
  111. i2s->feature |= S3C_FEATURE_CDCLKCON;
  112. i2s->dma_capture = &s3c64xx_i2sv4_pcm_stereo_in;
  113. i2s->dma_playback = &s3c64xx_i2sv4_pcm_stereo_out;
  114. i2s->dma_capture->channel = DMACH_HSI_I2SV40_RX;
  115. i2s->dma_capture->dma_addr = S3C64XX_PA_IISV4 + S3C2412_IISRXD;
  116. i2s->dma_playback->channel = DMACH_HSI_I2SV40_TX;
  117. i2s->dma_playback->dma_addr = S3C64XX_PA_IISV4 + S3C2412_IISTXD;
  118. i2s->dma_capture->client = &s3c64xx_dma_client_in;
  119. i2s->dma_capture->dma_size = 4;
  120. i2s->dma_playback->client = &s3c64xx_dma_client_out;
  121. i2s->dma_playback->dma_size = 4;
  122. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  123. if (IS_ERR(i2s->iis_cclk)) {
  124. dev_err(&pdev->dev, "failed to get audio-bus\n");
  125. ret = PTR_ERR(i2s->iis_cclk);
  126. goto err;
  127. }
  128. clk_enable(i2s->iis_cclk);
  129. ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
  130. if (ret)
  131. goto err_clk;
  132. ret = s3c_i2sv2_register_dai(dai);
  133. if (ret != 0)
  134. goto err_i2sv2;
  135. return 0;
  136. err_i2sv2:
  137. /* Not implemented for I2Sv2 core yet */
  138. err_clk:
  139. clk_put(i2s->iis_cclk);
  140. err:
  141. return ret;
  142. }
  143. static __devexit int s3c64xx_i2sv4_dev_remove(struct platform_device *pdev)
  144. {
  145. dev_err(&pdev->dev, "Device removal not yet supported\n");
  146. return 0;
  147. }
  148. static struct platform_driver s3c64xx_i2sv4_driver = {
  149. .probe = s3c64xx_i2sv4_dev_probe,
  150. .remove = s3c64xx_i2sv4_dev_remove,
  151. .driver = {
  152. .name = "s3c64xx-iis-v4",
  153. .owner = THIS_MODULE,
  154. },
  155. };
  156. static int __init s3c64xx_i2sv4_init(void)
  157. {
  158. return platform_driver_register(&s3c64xx_i2sv4_driver);
  159. }
  160. module_init(s3c64xx_i2sv4_init);
  161. static void __exit s3c64xx_i2sv4_exit(void)
  162. {
  163. platform_driver_unregister(&s3c64xx_i2sv4_driver);
  164. }
  165. module_exit(s3c64xx_i2sv4_exit);
  166. /* Module information */
  167. MODULE_AUTHOR("Jaswinder Singh, <jassi.brar@samsung.com>");
  168. MODULE_DESCRIPTION("S3C64XX I2Sv4 SoC Interface");
  169. MODULE_LICENSE("GPL");