s3c64xx-i2s.c 6.4 KB

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