pxa2xx-ac97.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * linux/sound/pxa2xx-ac97.c -- AC97 support for the Intel PXA2xx chip.
  3. *
  4. * Author: Nicolas Pitre
  5. * Created: Dec 02, 2004
  6. * Copyright: MontaVista Software Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. #include <linux/platform_device.h>
  15. #include <sound/core.h>
  16. #include <sound/ac97_codec.h>
  17. #include <sound/soc.h>
  18. #include <sound/pxa2xx-lib.h>
  19. #include <mach/hardware.h>
  20. #include <mach/regs-ac97.h>
  21. #include <mach/dma.h>
  22. #include <mach/audio.h>
  23. #include "pxa2xx-pcm.h"
  24. #include "pxa2xx-ac97.h"
  25. static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
  26. {
  27. pxa2xx_ac97_try_warm_reset(ac97);
  28. pxa2xx_ac97_finish_reset(ac97);
  29. }
  30. static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
  31. {
  32. pxa2xx_ac97_try_cold_reset(ac97);
  33. pxa2xx_ac97_finish_reset(ac97);
  34. }
  35. struct snd_ac97_bus_ops soc_ac97_ops = {
  36. .read = pxa2xx_ac97_read,
  37. .write = pxa2xx_ac97_write,
  38. .warm_reset = pxa2xx_ac97_warm_reset,
  39. .reset = pxa2xx_ac97_cold_reset,
  40. };
  41. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_out = {
  42. .name = "AC97 PCM Stereo out",
  43. .dev_addr = __PREG(PCDR),
  44. .drcmr = &DRCMR(12),
  45. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  46. DCMD_BURST32 | DCMD_WIDTH4,
  47. };
  48. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_in = {
  49. .name = "AC97 PCM Stereo in",
  50. .dev_addr = __PREG(PCDR),
  51. .drcmr = &DRCMR(11),
  52. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  53. DCMD_BURST32 | DCMD_WIDTH4,
  54. };
  55. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_out = {
  56. .name = "AC97 Aux PCM (Slot 5) Mono out",
  57. .dev_addr = __PREG(MODR),
  58. .drcmr = &DRCMR(10),
  59. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  60. DCMD_BURST16 | DCMD_WIDTH2,
  61. };
  62. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_in = {
  63. .name = "AC97 Aux PCM (Slot 5) Mono in",
  64. .dev_addr = __PREG(MODR),
  65. .drcmr = &DRCMR(9),
  66. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  67. DCMD_BURST16 | DCMD_WIDTH2,
  68. };
  69. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_mic_mono_in = {
  70. .name = "AC97 Mic PCM (Slot 6) Mono in",
  71. .dev_addr = __PREG(MCDR),
  72. .drcmr = &DRCMR(8),
  73. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  74. DCMD_BURST16 | DCMD_WIDTH2,
  75. };
  76. #ifdef CONFIG_PM
  77. static int pxa2xx_ac97_suspend(struct snd_soc_dai *dai)
  78. {
  79. return pxa2xx_ac97_hw_suspend();
  80. }
  81. static int pxa2xx_ac97_resume(struct snd_soc_dai *dai)
  82. {
  83. return pxa2xx_ac97_hw_resume();
  84. }
  85. #else
  86. #define pxa2xx_ac97_suspend NULL
  87. #define pxa2xx_ac97_resume NULL
  88. #endif
  89. static int pxa2xx_ac97_probe(struct platform_device *pdev,
  90. struct snd_soc_dai *dai)
  91. {
  92. return pxa2xx_ac97_hw_probe(to_platform_device(dai->dev));
  93. }
  94. static void pxa2xx_ac97_remove(struct platform_device *pdev,
  95. struct snd_soc_dai *dai)
  96. {
  97. pxa2xx_ac97_hw_remove(to_platform_device(dai->dev));
  98. }
  99. static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
  100. struct snd_pcm_hw_params *params,
  101. struct snd_soc_dai *dai)
  102. {
  103. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  105. struct pxa2xx_pcm_dma_params *dma_data;
  106. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  107. dma_data = &pxa2xx_ac97_pcm_stereo_out;
  108. else
  109. dma_data = &pxa2xx_ac97_pcm_stereo_in;
  110. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  111. return 0;
  112. }
  113. static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream,
  114. struct snd_pcm_hw_params *params,
  115. struct snd_soc_dai *dai)
  116. {
  117. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  118. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  119. struct pxa2xx_pcm_dma_params *dma_data;
  120. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  121. dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
  122. else
  123. dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
  124. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  125. return 0;
  126. }
  127. static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
  128. struct snd_pcm_hw_params *params,
  129. struct snd_soc_dai *dai)
  130. {
  131. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  132. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  133. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  134. return -ENODEV;
  135. else
  136. snd_soc_dai_set_dma_data(cpu_dai, substream,
  137. &pxa2xx_ac97_pcm_mic_mono_in);
  138. return 0;
  139. }
  140. #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  141. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
  142. SNDRV_PCM_RATE_48000)
  143. static struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
  144. .hw_params = pxa2xx_ac97_hw_params,
  145. };
  146. static struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
  147. .hw_params = pxa2xx_ac97_hw_aux_params,
  148. };
  149. static struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
  150. .hw_params = pxa2xx_ac97_hw_mic_params,
  151. };
  152. /*
  153. * There is only 1 physical AC97 interface for pxa2xx, but it
  154. * has extra fifo's that can be used for aux DACs and ADCs.
  155. */
  156. struct snd_soc_dai pxa_ac97_dai[] = {
  157. {
  158. .name = "pxa2xx-ac97",
  159. .id = 0,
  160. .ac97_control = 1,
  161. .probe = pxa2xx_ac97_probe,
  162. .remove = pxa2xx_ac97_remove,
  163. .suspend = pxa2xx_ac97_suspend,
  164. .resume = pxa2xx_ac97_resume,
  165. .playback = {
  166. .stream_name = "AC97 Playback",
  167. .channels_min = 2,
  168. .channels_max = 2,
  169. .rates = PXA2XX_AC97_RATES,
  170. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  171. .capture = {
  172. .stream_name = "AC97 Capture",
  173. .channels_min = 2,
  174. .channels_max = 2,
  175. .rates = PXA2XX_AC97_RATES,
  176. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  177. .ops = &pxa_ac97_hifi_dai_ops,
  178. },
  179. {
  180. .name = "pxa2xx-ac97-aux",
  181. .id = 1,
  182. .ac97_control = 1,
  183. .playback = {
  184. .stream_name = "AC97 Aux Playback",
  185. .channels_min = 1,
  186. .channels_max = 1,
  187. .rates = PXA2XX_AC97_RATES,
  188. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  189. .capture = {
  190. .stream_name = "AC97 Aux Capture",
  191. .channels_min = 1,
  192. .channels_max = 1,
  193. .rates = PXA2XX_AC97_RATES,
  194. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  195. .ops = &pxa_ac97_aux_dai_ops,
  196. },
  197. {
  198. .name = "pxa2xx-ac97-mic",
  199. .id = 2,
  200. .ac97_control = 1,
  201. .capture = {
  202. .stream_name = "AC97 Mic Capture",
  203. .channels_min = 1,
  204. .channels_max = 1,
  205. .rates = PXA2XX_AC97_RATES,
  206. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  207. .ops = &pxa_ac97_mic_dai_ops,
  208. },
  209. };
  210. EXPORT_SYMBOL_GPL(pxa_ac97_dai);
  211. EXPORT_SYMBOL_GPL(soc_ac97_ops);
  212. static int __devinit pxa2xx_ac97_dev_probe(struct platform_device *pdev)
  213. {
  214. int i;
  215. pxa2xx_audio_ops_t *pdata = pdev->dev.platform_data;
  216. if (pdev->id >= 0) {
  217. dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
  218. return -ENXIO;
  219. }
  220. for (i = 0; i < ARRAY_SIZE(pxa_ac97_dai); i++) {
  221. pxa_ac97_dai[i].dev = &pdev->dev;
  222. if (pdata && pdata->codec_pdata[0])
  223. pxa_ac97_dai[i].ac97_pdata = pdata->codec_pdata[0];
  224. }
  225. /* Punt most of the init to the SoC probe; we may need the machine
  226. * driver to do interesting things with the clocking to get us up
  227. * and running.
  228. */
  229. return snd_soc_register_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai));
  230. }
  231. static int __devexit pxa2xx_ac97_dev_remove(struct platform_device *pdev)
  232. {
  233. snd_soc_unregister_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai));
  234. return 0;
  235. }
  236. static struct platform_driver pxa2xx_ac97_driver = {
  237. .probe = pxa2xx_ac97_dev_probe,
  238. .remove = __devexit_p(pxa2xx_ac97_dev_remove),
  239. .driver = {
  240. .name = "pxa2xx-ac97",
  241. .owner = THIS_MODULE,
  242. },
  243. };
  244. static int __init pxa_ac97_init(void)
  245. {
  246. return platform_driver_register(&pxa2xx_ac97_driver);
  247. }
  248. module_init(pxa_ac97_init);
  249. static void __exit pxa_ac97_exit(void)
  250. {
  251. platform_driver_unregister(&pxa2xx_ac97_driver);
  252. }
  253. module_exit(pxa_ac97_exit);
  254. MODULE_AUTHOR("Nicolas Pitre");
  255. MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  256. MODULE_LICENSE("GPL");