pxa2xx-ac97.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 <mach/regs-ac97.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 platform_device *pdev,
  77. struct snd_soc_dai *dai)
  78. {
  79. return pxa2xx_ac97_hw_suspend();
  80. }
  81. static int pxa2xx_ac97_resume(struct platform_device *pdev,
  82. struct snd_soc_dai *dai)
  83. {
  84. return pxa2xx_ac97_hw_resume();
  85. }
  86. #else
  87. #define pxa2xx_ac97_suspend NULL
  88. #define pxa2xx_ac97_resume NULL
  89. #endif
  90. static int pxa2xx_ac97_probe(struct platform_device *pdev,
  91. struct snd_soc_dai *dai)
  92. {
  93. return pxa2xx_ac97_hw_probe(pdev);
  94. }
  95. static void pxa2xx_ac97_remove(struct platform_device *pdev,
  96. struct snd_soc_dai *dai)
  97. {
  98. pxa2xx_ac97_hw_remove(pdev);
  99. }
  100. static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
  101. struct snd_pcm_hw_params *params)
  102. {
  103. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  104. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  105. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  106. cpu_dai->dma_data = &pxa2xx_ac97_pcm_stereo_out;
  107. else
  108. cpu_dai->dma_data = &pxa2xx_ac97_pcm_stereo_in;
  109. return 0;
  110. }
  111. static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream,
  112. struct snd_pcm_hw_params *params)
  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. {
  125. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  126. struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  127. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  128. return -ENODEV;
  129. else
  130. cpu_dai->dma_data = &pxa2xx_ac97_pcm_mic_mono_in;
  131. return 0;
  132. }
  133. #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  134. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
  135. SNDRV_PCM_RATE_48000)
  136. /*
  137. * There is only 1 physical AC97 interface for pxa2xx, but it
  138. * has extra fifo's that can be used for aux DACs and ADCs.
  139. */
  140. struct snd_soc_dai pxa_ac97_dai[] = {
  141. {
  142. .name = "pxa2xx-ac97",
  143. .id = 0,
  144. .type = SND_SOC_DAI_AC97,
  145. .probe = pxa2xx_ac97_probe,
  146. .remove = pxa2xx_ac97_remove,
  147. .suspend = pxa2xx_ac97_suspend,
  148. .resume = pxa2xx_ac97_resume,
  149. .playback = {
  150. .stream_name = "AC97 Playback",
  151. .channels_min = 2,
  152. .channels_max = 2,
  153. .rates = PXA2XX_AC97_RATES,
  154. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  155. .capture = {
  156. .stream_name = "AC97 Capture",
  157. .channels_min = 2,
  158. .channels_max = 2,
  159. .rates = PXA2XX_AC97_RATES,
  160. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  161. .ops = {
  162. .hw_params = pxa2xx_ac97_hw_params,},
  163. },
  164. {
  165. .name = "pxa2xx-ac97-aux",
  166. .id = 1,
  167. .type = SND_SOC_DAI_AC97,
  168. .playback = {
  169. .stream_name = "AC97 Aux Playback",
  170. .channels_min = 1,
  171. .channels_max = 1,
  172. .rates = PXA2XX_AC97_RATES,
  173. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  174. .capture = {
  175. .stream_name = "AC97 Aux Capture",
  176. .channels_min = 1,
  177. .channels_max = 1,
  178. .rates = PXA2XX_AC97_RATES,
  179. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  180. .ops = {
  181. .hw_params = pxa2xx_ac97_hw_aux_params,},
  182. },
  183. {
  184. .name = "pxa2xx-ac97-mic",
  185. .id = 2,
  186. .type = SND_SOC_DAI_AC97,
  187. .capture = {
  188. .stream_name = "AC97 Mic Capture",
  189. .channels_min = 1,
  190. .channels_max = 1,
  191. .rates = PXA2XX_AC97_RATES,
  192. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  193. .ops = {
  194. .hw_params = pxa2xx_ac97_hw_mic_params,},
  195. },
  196. };
  197. EXPORT_SYMBOL_GPL(pxa_ac97_dai);
  198. EXPORT_SYMBOL_GPL(soc_ac97_ops);
  199. MODULE_AUTHOR("Nicolas Pitre");
  200. MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  201. MODULE_LICENSE("GPL");