s3c64xx-i2s.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 <mach/map.h>
  32. #include <mach/dma.h>
  33. #include "s3c-dma.h"
  34. #include "s3c64xx-i2s.h"
  35. static struct s3c2410_dma_client s3c64xx_dma_client_out = {
  36. .name = "I2S PCM Stereo out"
  37. };
  38. static struct s3c2410_dma_client s3c64xx_dma_client_in = {
  39. .name = "I2S PCM Stereo in"
  40. };
  41. static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
  42. [0] = {
  43. .channel = DMACH_I2S0_OUT,
  44. .client = &s3c64xx_dma_client_out,
  45. .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
  46. .dma_size = 4,
  47. },
  48. [1] = {
  49. .channel = DMACH_I2S1_OUT,
  50. .client = &s3c64xx_dma_client_out,
  51. .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
  52. .dma_size = 4,
  53. },
  54. };
  55. static struct s3c_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
  56. [0] = {
  57. .channel = DMACH_I2S0_IN,
  58. .client = &s3c64xx_dma_client_in,
  59. .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
  60. .dma_size = 4,
  61. },
  62. [1] = {
  63. .channel = DMACH_I2S1_IN,
  64. .client = &s3c64xx_dma_client_in,
  65. .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
  66. .dma_size = 4,
  67. },
  68. };
  69. static struct s3c_i2sv2_info s3c64xx_i2s[2];
  70. static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
  71. {
  72. return cpu_dai->private_data;
  73. }
  74. static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
  75. int clk_id, unsigned int freq, int dir)
  76. {
  77. struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
  78. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  79. switch (clk_id) {
  80. case S3C64XX_CLKSRC_PCLK:
  81. iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
  82. break;
  83. case S3C64XX_CLKSRC_MUX:
  84. iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
  85. break;
  86. case S3C64XX_CLKSRC_CDCLK:
  87. switch (dir) {
  88. case SND_SOC_CLOCK_IN:
  89. iismod |= S3C64XX_IISMOD_CDCLKCON;
  90. break;
  91. case SND_SOC_CLOCK_OUT:
  92. iismod &= ~S3C64XX_IISMOD_CDCLKCON;
  93. break;
  94. default:
  95. return -EINVAL;
  96. }
  97. break;
  98. default:
  99. return -EINVAL;
  100. }
  101. writel(iismod, i2s->regs + S3C2412_IISMOD);
  102. return 0;
  103. }
  104. struct clk *s3c64xx_i2s_get_clock(struct snd_soc_dai *dai)
  105. {
  106. struct s3c_i2sv2_info *i2s = to_info(dai);
  107. u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
  108. if (iismod & S3C64XX_IISMOD_IMS_SYSMUX)
  109. return i2s->iis_cclk;
  110. else
  111. return i2s->iis_pclk;
  112. }
  113. EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clock);
  114. static int s3c64xx_i2s_probe(struct platform_device *pdev,
  115. struct snd_soc_dai *dai)
  116. {
  117. /* configure GPIO for i2s port */
  118. switch (dai->id) {
  119. case 0:
  120. s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
  121. s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
  122. s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
  123. s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
  124. s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
  125. break;
  126. case 1:
  127. s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
  128. s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
  129. s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
  130. s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
  131. s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
  132. }
  133. return 0;
  134. }
  135. #define S3C64XX_I2S_RATES \
  136. (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
  137. SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  138. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
  139. #define S3C64XX_I2S_FMTS \
  140. (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
  141. SNDRV_PCM_FMTBIT_S24_LE)
  142. static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
  143. .set_sysclk = s3c64xx_i2s_set_sysclk,
  144. };
  145. struct snd_soc_dai s3c64xx_i2s_dai[] = {
  146. {
  147. .name = "s3c64xx-i2s",
  148. .id = 0,
  149. .probe = s3c64xx_i2s_probe,
  150. .playback = {
  151. .channels_min = 2,
  152. .channels_max = 2,
  153. .rates = S3C64XX_I2S_RATES,
  154. .formats = S3C64XX_I2S_FMTS,
  155. },
  156. .capture = {
  157. .channels_min = 2,
  158. .channels_max = 2,
  159. .rates = S3C64XX_I2S_RATES,
  160. .formats = S3C64XX_I2S_FMTS,
  161. },
  162. .ops = &s3c64xx_i2s_dai_ops,
  163. .symmetric_rates = 1,
  164. },
  165. {
  166. .name = "s3c64xx-i2s",
  167. .id = 1,
  168. .probe = s3c64xx_i2s_probe,
  169. .playback = {
  170. .channels_min = 2,
  171. .channels_max = 2,
  172. .rates = S3C64XX_I2S_RATES,
  173. .formats = S3C64XX_I2S_FMTS,
  174. },
  175. .capture = {
  176. .channels_min = 2,
  177. .channels_max = 2,
  178. .rates = S3C64XX_I2S_RATES,
  179. .formats = S3C64XX_I2S_FMTS,
  180. },
  181. .ops = &s3c64xx_i2s_dai_ops,
  182. .symmetric_rates = 1,
  183. },
  184. };
  185. EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
  186. static __devinit int s3c64xx_iis_dev_probe(struct platform_device *pdev)
  187. {
  188. struct s3c_i2sv2_info *i2s;
  189. struct snd_soc_dai *dai;
  190. int ret;
  191. if (pdev->id >= ARRAY_SIZE(s3c64xx_i2s)) {
  192. dev_err(&pdev->dev, "id %d out of range\n", pdev->id);
  193. return -EINVAL;
  194. }
  195. i2s = &s3c64xx_i2s[pdev->id];
  196. dai = &s3c64xx_i2s_dai[pdev->id];
  197. dai->dev = &pdev->dev;
  198. i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
  199. i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
  200. i2s->iis_cclk = clk_get(&pdev->dev, "audio-bus");
  201. if (IS_ERR(i2s->iis_cclk)) {
  202. dev_err(&pdev->dev, "failed to get audio-bus\n");
  203. ret = PTR_ERR(i2s->iis_cclk);
  204. goto err;
  205. }
  206. clk_enable(i2s->iis_cclk);
  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");