s3c64xx-i2s.c 6.7 KB

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