s3c64xx-i2s.c 6.3 KB

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