pxa2xx-ac97.c 7.1 KB

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