pxa2xx-ac97.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/pxa-regs.h>
  21. #include "pxa2xx-pcm.h"
  22. #include "pxa2xx-ac97.h"
  23. static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
  24. {
  25. pxa2xx_ac97_try_warm_reset(ac97);
  26. pxa2xx_ac97_finish_reset(ac97);
  27. }
  28. static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
  29. {
  30. pxa2xx_ac97_try_cold_reset(ac97);
  31. pxa2xx_ac97_finish_reset(ac97);
  32. }
  33. struct snd_ac97_bus_ops soc_ac97_ops = {
  34. .read = pxa2xx_ac97_read,
  35. .write = pxa2xx_ac97_write,
  36. .warm_reset = pxa2xx_ac97_warm_reset,
  37. .reset = pxa2xx_ac97_cold_reset,
  38. };
  39. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_out = {
  40. .name = "AC97 PCM Stereo out",
  41. .dev_addr = __PREG(PCDR),
  42. .drcmr = &DRCMRTXPCDR,
  43. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  44. DCMD_BURST32 | DCMD_WIDTH4,
  45. };
  46. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_in = {
  47. .name = "AC97 PCM Stereo in",
  48. .dev_addr = __PREG(PCDR),
  49. .drcmr = &DRCMRRXPCDR,
  50. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  51. DCMD_BURST32 | DCMD_WIDTH4,
  52. };
  53. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_out = {
  54. .name = "AC97 Aux PCM (Slot 5) Mono out",
  55. .dev_addr = __PREG(MODR),
  56. .drcmr = &DRCMRTXMODR,
  57. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  58. DCMD_BURST16 | DCMD_WIDTH2,
  59. };
  60. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_in = {
  61. .name = "AC97 Aux PCM (Slot 5) Mono in",
  62. .dev_addr = __PREG(MODR),
  63. .drcmr = &DRCMRRXMODR,
  64. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  65. DCMD_BURST16 | DCMD_WIDTH2,
  66. };
  67. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_mic_mono_in = {
  68. .name = "AC97 Mic PCM (Slot 6) Mono in",
  69. .dev_addr = __PREG(MCDR),
  70. .drcmr = &DRCMRRXMCDR,
  71. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  72. DCMD_BURST16 | DCMD_WIDTH2,
  73. };
  74. #ifdef CONFIG_PM
  75. static int pxa2xx_ac97_suspend(struct platform_device *pdev,
  76. struct snd_soc_dai *dai)
  77. {
  78. return pxa2xx_ac97_hw_suspend();
  79. }
  80. static int pxa2xx_ac97_resume(struct platform_device *pdev,
  81. 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(pdev);
  93. }
  94. static void pxa2xx_ac97_remove(struct platform_device *pdev,
  95. struct snd_soc_dai *dai)
  96. {
  97. pxa2xx_ac97_hw_remove(pdev);
  98. }
  99. static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
  100. struct snd_pcm_hw_params *params)
  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. {
  113. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  114. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  115. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  116. cpu_dai->dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
  117. else
  118. cpu_dai->dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
  119. return 0;
  120. }
  121. static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
  122. struct snd_pcm_hw_params *params)
  123. {
  124. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  125. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  126. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  127. return -ENODEV;
  128. else
  129. cpu_dai->dma_data = &pxa2xx_ac97_pcm_mic_mono_in;
  130. return 0;
  131. }
  132. #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  133. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
  134. SNDRV_PCM_RATE_48000)
  135. /*
  136. * There is only 1 physical AC97 interface for pxa2xx, but it
  137. * has extra fifo's that can be used for aux DACs and ADCs.
  138. */
  139. struct snd_soc_dai pxa_ac97_dai[] = {
  140. {
  141. .name = "pxa2xx-ac97",
  142. .id = 0,
  143. .type = SND_SOC_DAI_AC97,
  144. .probe = pxa2xx_ac97_probe,
  145. .remove = pxa2xx_ac97_remove,
  146. .suspend = pxa2xx_ac97_suspend,
  147. .resume = pxa2xx_ac97_resume,
  148. .playback = {
  149. .stream_name = "AC97 Playback",
  150. .channels_min = 2,
  151. .channels_max = 2,
  152. .rates = PXA2XX_AC97_RATES,
  153. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  154. .capture = {
  155. .stream_name = "AC97 Capture",
  156. .channels_min = 2,
  157. .channels_max = 2,
  158. .rates = PXA2XX_AC97_RATES,
  159. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  160. .ops = {
  161. .hw_params = pxa2xx_ac97_hw_params,},
  162. },
  163. {
  164. .name = "pxa2xx-ac97-aux",
  165. .id = 1,
  166. .type = SND_SOC_DAI_AC97,
  167. .playback = {
  168. .stream_name = "AC97 Aux Playback",
  169. .channels_min = 1,
  170. .channels_max = 1,
  171. .rates = PXA2XX_AC97_RATES,
  172. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  173. .capture = {
  174. .stream_name = "AC97 Aux Capture",
  175. .channels_min = 1,
  176. .channels_max = 1,
  177. .rates = PXA2XX_AC97_RATES,
  178. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  179. .ops = {
  180. .hw_params = pxa2xx_ac97_hw_aux_params,},
  181. },
  182. {
  183. .name = "pxa2xx-ac97-mic",
  184. .id = 2,
  185. .type = SND_SOC_DAI_AC97,
  186. .capture = {
  187. .stream_name = "AC97 Mic Capture",
  188. .channels_min = 1,
  189. .channels_max = 1,
  190. .rates = PXA2XX_AC97_RATES,
  191. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  192. .ops = {
  193. .hw_params = pxa2xx_ac97_hw_mic_params,},
  194. },
  195. };
  196. EXPORT_SYMBOL_GPL(pxa_ac97_dai);
  197. EXPORT_SYMBOL_GPL(soc_ac97_ops);
  198. MODULE_AUTHOR("Nicolas Pitre");
  199. MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  200. MODULE_LICENSE("GPL");