s3c64xx-i2s.c 6.5 KB

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