s3c64xx-i2s.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. case S3C64XX_CLKSRC_CDCLK:
  88. switch (dir) {
  89. case SND_SOC_CLOCK_IN:
  90. iismod |= S3C64XX_IISMOD_CDCLKCON;
  91. break;
  92. case SND_SOC_CLOCK_OUT:
  93. iismod &= ~S3C64XX_IISMOD_CDCLKCON;
  94. break;
  95. default:
  96. return -EINVAL;
  97. }
  98. break;
  99. default:
  100. return -EINVAL;
  101. }
  102. writel(iismod, i2s->regs + S3C2412_IISMOD);
  103. return 0;
  104. }
  105. struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
  106. {
  107. struct s3c_i2sv2_info *i2s = to_info(dai);
  108. return i2s->iis_cclk;
  109. }
  110. EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
  111. static int s3c64xx_i2s_probe(struct platform_device *pdev,
  112. struct snd_soc_dai *dai)
  113. {
  114. /* configure GPIO for i2s port */
  115. switch (dai->id) {
  116. case 0:
  117. s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
  118. s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
  119. s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
  120. s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
  121. s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
  122. break;
  123. case 1:
  124. s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
  125. s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
  126. s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
  127. s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
  128. s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
  129. }
  130. return 0;
  131. }
  132. #define S3C64XX_I2S_RATES \
  133. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  134. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  135. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  136. #define S3C64XX_I2S_FMTS \
  137. (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
  138. SNDRV_PCM_FMTBIT_S24_LE)
  139. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
  140. .set_sysclk = s3c64xx_i2s_set_sysclk,
  141. };
  142. struct snd_soc_dai s3c64xx_i2s_dai[] = {
  143. {
  144. .name = "s3c64xx-i2s",
  145. .id = 0,
  146. .probe = s3c64xx_i2s_probe,
  147. .playback = {
  148. .channels_min = 2,
  149. .channels_max = 2,
  150. .rates = S3C64XX_I2S_RATES,
  151. .formats = S3C64XX_I2S_FMTS,
  152. },
  153. .capture = {
  154. .channels_min = 2,
  155. .channels_max = 2,
  156. .rates = S3C64XX_I2S_RATES,
  157. .formats = S3C64XX_I2S_FMTS,
  158. },
  159. .ops = &s3c64xx_i2s_dai_ops,
  160. .symmetric_rates = 1,
  161. },
  162. {
  163. .name = "s3c64xx-i2s",
  164. .id = 1,
  165. .probe = s3c64xx_i2s_probe,
  166. .playback = {
  167. .channels_min = 2,
  168. .channels_max = 2,
  169. .rates = S3C64XX_I2S_RATES,
  170. .formats = S3C64XX_I2S_FMTS,
  171. },
  172. .capture = {
  173. .channels_min = 2,
  174. .channels_max = 2,
  175. .rates = S3C64XX_I2S_RATES,
  176. .formats = S3C64XX_I2S_FMTS,
  177. },
  178. .ops = &s3c64xx_i2s_dai_ops,
  179. .symmetric_rates = 1,
  180. },
  181. };
  182. EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
  183. static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
  184. {
  185. struct s3c_i2sv2_info *i2s;
  186. struct snd_soc_dai *dai;
  187. int ret;
  188. if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) {
  189. dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
  190. return -EINVAL;
  191. }
  192. i2s = &s3c64xx_i2s[pdev->id];
  193. dai = &s3c64xx_i2s_dai[pdev->id];
  194. dai->dev = &pdev->dev;
  195. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  196. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  197. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  198. if (IS_ERR(i2s->iis_cclk)) {
  199. dev_err(&pdev->dev, "failed to get audio-bus\n");
  200. ret = PTR_ERR(i2s->iis_cclk);
  201. goto err;
  202. }
  203. ret = s3c_i2sv2_probe(pdev, dai, i2s, 0);
  204. if (ret)
  205. goto err_clk;
  206. ret = s3c_i2sv2_register_dai(dai);
  207. if (ret != 0)
  208. goto err_i2sv2;
  209. return 0;
  210. err_i2sv2:
  211. /* Not implemented for I2Sv2 core yet */
  212. err_clk:
  213. clk_put(i2s->iis_cclk);
  214. err:
  215. return ret;
  216. }
  217. static __devexit int s3c64xx_iis_dev_remove(struct platform_device *pdev)
  218. {
  219. dev_err(&pdev->dev, "Device removal not yet supported\n");
  220. return 0;
  221. }
  222. static struct platform_driver s3c64xx_iis_driver = {
  223. .probe = s3c64xx_iis_dev_probe,
  224. .remove = s3c64xx_iis_dev_remove,
  225. .driver = {
  226. .name = "s3c64xx-iis",
  227. .owner = THIS_MODULE,
  228. },
  229. };
  230. static int __init s3c64xx_i2s_init(void)
  231. {
  232. return platform_driver_register(&s3c64xx_iis_driver);
  233. }
  234. module_init(s3c64xx_i2s_init);
  235. static void __exit s3c64xx_i2s_exit(void)
  236. {
  237. platform_driver_unregister(&s3c64xx_iis_driver);
  238. }
  239. module_exit(s3c64xx_i2s_exit);
  240. /* Module information */
  241. MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
  242. MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
  243. MODULE_LICENSE("GPL");