pxa2xx-ac97.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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/io.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <sound/core.h>
  17. #include <sound/ac97_codec.h>
  18. #include <sound/soc.h>
  19. #include <sound/pxa2xx-lib.h>
  20. #include <mach/hardware.h>
  21. #include <mach/regs-ac97.h>
  22. #include <mach/dma.h>
  23. #include <mach/audio.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. EXPORT_SYMBOL_GPL(soc_ac97_ops);
  42. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_out = {
  43. .name = "AC97 PCM Stereo out",
  44. .dev_addr = __PREG(PCDR),
  45. .drcmr = &DRCMR(12),
  46. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  47. DCMD_BURST32 | DCMD_WIDTH4,
  48. };
  49. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_stereo_in = {
  50. .name = "AC97 PCM Stereo in",
  51. .dev_addr = __PREG(PCDR),
  52. .drcmr = &DRCMR(11),
  53. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  54. DCMD_BURST32 | DCMD_WIDTH4,
  55. };
  56. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_out = {
  57. .name = "AC97 Aux PCM (Slot 5) Mono out",
  58. .dev_addr = __PREG(MODR),
  59. .drcmr = &DRCMR(10),
  60. .dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG |
  61. DCMD_BURST16 | DCMD_WIDTH2,
  62. };
  63. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_aux_mono_in = {
  64. .name = "AC97 Aux PCM (Slot 5) Mono in",
  65. .dev_addr = __PREG(MODR),
  66. .drcmr = &DRCMR(9),
  67. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  68. DCMD_BURST16 | DCMD_WIDTH2,
  69. };
  70. static struct pxa2xx_pcm_dma_params pxa2xx_ac97_pcm_mic_mono_in = {
  71. .name = "AC97 Mic PCM (Slot 6) Mono in",
  72. .dev_addr = __PREG(MCDR),
  73. .drcmr = &DRCMR(8),
  74. .dcmd = DCMD_INCTRGADDR | DCMD_FLOWSRC |
  75. DCMD_BURST16 | DCMD_WIDTH2,
  76. };
  77. #ifdef CONFIG_PM
  78. static int pxa2xx_ac97_suspend(struct snd_soc_dai *dai)
  79. {
  80. return pxa2xx_ac97_hw_suspend();
  81. }
  82. static int pxa2xx_ac97_resume(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 snd_soc_dai *dai)
  91. {
  92. return pxa2xx_ac97_hw_probe(to_platform_device(dai->dev));
  93. }
  94. static int pxa2xx_ac97_remove(struct snd_soc_dai *dai)
  95. {
  96. pxa2xx_ac97_hw_remove(to_platform_device(dai->dev));
  97. return 0;
  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 *cpu_dai)
  102. {
  103. struct pxa2xx_pcm_dma_params *dma_data;
  104. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  105. dma_data = &pxa2xx_ac97_pcm_stereo_out;
  106. else
  107. dma_data = &pxa2xx_ac97_pcm_stereo_in;
  108. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  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. struct snd_soc_dai *cpu_dai)
  114. {
  115. struct pxa2xx_pcm_dma_params *dma_data;
  116. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  117. dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
  118. else
  119. dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
  120. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  121. return 0;
  122. }
  123. static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
  124. struct snd_pcm_hw_params *params,
  125. struct snd_soc_dai *cpu_dai)
  126. {
  127. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  128. return -ENODEV;
  129. else
  130. snd_soc_dai_set_dma_data(cpu_dai, substream,
  131. &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 const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
  138. .hw_params = pxa2xx_ac97_hw_params,
  139. };
  140. static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
  141. .hw_params = pxa2xx_ac97_hw_aux_params,
  142. };
  143. static const 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. static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
  151. {
  152. .name = "pxa2xx-ac97",
  153. .ac97_control = 1,
  154. .probe = pxa2xx_ac97_probe,
  155. .remove = pxa2xx_ac97_remove,
  156. .suspend = pxa2xx_ac97_suspend,
  157. .resume = pxa2xx_ac97_resume,
  158. .playback = {
  159. .stream_name = "AC97 Playback",
  160. .channels_min = 2,
  161. .channels_max = 2,
  162. .rates = PXA2XX_AC97_RATES,
  163. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  164. .capture = {
  165. .stream_name = "AC97 Capture",
  166. .channels_min = 2,
  167. .channels_max = 2,
  168. .rates = PXA2XX_AC97_RATES,
  169. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  170. .ops = &pxa_ac97_hifi_dai_ops,
  171. },
  172. {
  173. .name = "pxa2xx-ac97-aux",
  174. .ac97_control = 1,
  175. .playback = {
  176. .stream_name = "AC97 Aux Playback",
  177. .channels_min = 1,
  178. .channels_max = 1,
  179. .rates = PXA2XX_AC97_RATES,
  180. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  181. .capture = {
  182. .stream_name = "AC97 Aux Capture",
  183. .channels_min = 1,
  184. .channels_max = 1,
  185. .rates = PXA2XX_AC97_RATES,
  186. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  187. .ops = &pxa_ac97_aux_dai_ops,
  188. },
  189. {
  190. .name = "pxa2xx-ac97-mic",
  191. .ac97_control = 1,
  192. .capture = {
  193. .stream_name = "AC97 Mic Capture",
  194. .channels_min = 1,
  195. .channels_max = 1,
  196. .rates = PXA2XX_AC97_RATES,
  197. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  198. .ops = &pxa_ac97_mic_dai_ops,
  199. },
  200. };
  201. static const struct snd_soc_component_driver pxa_ac97_component = {
  202. .name = "pxa-ac97",
  203. };
  204. static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
  205. {
  206. if (pdev->id != -1) {
  207. dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
  208. return -ENXIO;
  209. }
  210. /* Punt most of the init to the SoC probe; we may need the machine
  211. * driver to do interesting things with the clocking to get us up
  212. * and running.
  213. */
  214. return snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
  215. pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
  216. }
  217. static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
  218. {
  219. snd_soc_unregister_component(&pdev->dev);
  220. return 0;
  221. }
  222. static struct platform_driver pxa2xx_ac97_driver = {
  223. .probe = pxa2xx_ac97_dev_probe,
  224. .remove = pxa2xx_ac97_dev_remove,
  225. .driver = {
  226. .name = "pxa2xx-ac97",
  227. .owner = THIS_MODULE,
  228. },
  229. };
  230. module_platform_driver(pxa2xx_ac97_driver);
  231. MODULE_AUTHOR("Nicolas Pitre");
  232. MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  233. MODULE_LICENSE("GPL");