pxa2xx-ac97.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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 <linux/dmaengine.h>
  17. #include <sound/core.h>
  18. #include <sound/ac97_codec.h>
  19. #include <sound/soc.h>
  20. #include <sound/pxa2xx-lib.h>
  21. #include <sound/dmaengine_pcm.h>
  22. #include <mach/hardware.h>
  23. #include <mach/regs-ac97.h>
  24. #include <mach/audio.h>
  25. #include "pxa2xx-ac97.h"
  26. static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
  27. {
  28. pxa2xx_ac97_try_warm_reset(ac97);
  29. pxa2xx_ac97_finish_reset(ac97);
  30. }
  31. static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
  32. {
  33. pxa2xx_ac97_try_cold_reset(ac97);
  34. pxa2xx_ac97_finish_reset(ac97);
  35. }
  36. static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
  37. .read = pxa2xx_ac97_read,
  38. .write = pxa2xx_ac97_write,
  39. .warm_reset = pxa2xx_ac97_warm_reset,
  40. .reset = pxa2xx_ac97_cold_reset,
  41. };
  42. static unsigned long pxa2xx_ac97_pcm_stereo_in_req = 12;
  43. static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_in = {
  44. .addr = __PREG(PCDR),
  45. .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  46. .maxburst = 32,
  47. .filter_data = &pxa2xx_ac97_pcm_stereo_in_req,
  48. };
  49. static unsigned long pxa2xx_ac97_pcm_stereo_out_req = 11;
  50. static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_stereo_out = {
  51. .addr = __PREG(PCDR),
  52. .addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
  53. .maxburst = 32,
  54. .filter_data = &pxa2xx_ac97_pcm_stereo_out_req,
  55. };
  56. static unsigned long pxa2xx_ac97_pcm_aux_mono_out_req = 10;
  57. static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_out = {
  58. .addr = __PREG(MODR),
  59. .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
  60. .maxburst = 16,
  61. .filter_data = &pxa2xx_ac97_pcm_aux_mono_out_req,
  62. };
  63. static unsigned long pxa2xx_ac97_pcm_aux_mono_in_req = 9;
  64. static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_aux_mono_in = {
  65. .addr = __PREG(MODR),
  66. .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
  67. .maxburst = 16,
  68. .filter_data = &pxa2xx_ac97_pcm_aux_mono_in_req,
  69. };
  70. static unsigned long pxa2xx_ac97_pcm_aux_mic_mono_req = 8;
  71. static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_mic_mono_in = {
  72. .addr = __PREG(MCDR),
  73. .addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES,
  74. .maxburst = 16,
  75. .filter_data = &pxa2xx_ac97_pcm_aux_mic_mono_req,
  76. };
  77. static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
  78. struct snd_pcm_hw_params *params,
  79. struct snd_soc_dai *cpu_dai)
  80. {
  81. struct snd_dmaengine_dai_dma_data *dma_data;
  82. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  83. dma_data = &pxa2xx_ac97_pcm_stereo_out;
  84. else
  85. dma_data = &pxa2xx_ac97_pcm_stereo_in;
  86. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  87. return 0;
  88. }
  89. static int pxa2xx_ac97_hw_aux_params(struct snd_pcm_substream *substream,
  90. struct snd_pcm_hw_params *params,
  91. struct snd_soc_dai *cpu_dai)
  92. {
  93. struct snd_dmaengine_dai_dma_data *dma_data;
  94. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  95. dma_data = &pxa2xx_ac97_pcm_aux_mono_out;
  96. else
  97. dma_data = &pxa2xx_ac97_pcm_aux_mono_in;
  98. snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
  99. return 0;
  100. }
  101. static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
  102. struct snd_pcm_hw_params *params,
  103. struct snd_soc_dai *cpu_dai)
  104. {
  105. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  106. return -ENODEV;
  107. else
  108. snd_soc_dai_set_dma_data(cpu_dai, substream,
  109. &pxa2xx_ac97_pcm_mic_mono_in);
  110. return 0;
  111. }
  112. #define PXA2XX_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
  113. SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
  114. SNDRV_PCM_RATE_48000)
  115. static const struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
  116. .hw_params = pxa2xx_ac97_hw_params,
  117. };
  118. static const struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
  119. .hw_params = pxa2xx_ac97_hw_aux_params,
  120. };
  121. static const struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
  122. .hw_params = pxa2xx_ac97_hw_mic_params,
  123. };
  124. /*
  125. * There is only 1 physical AC97 interface for pxa2xx, but it
  126. * has extra fifo's that can be used for aux DACs and ADCs.
  127. */
  128. static struct snd_soc_dai_driver pxa_ac97_dai_driver[] = {
  129. {
  130. .name = "pxa2xx-ac97",
  131. .bus_control = true,
  132. .playback = {
  133. .stream_name = "AC97 Playback",
  134. .channels_min = 2,
  135. .channels_max = 2,
  136. .rates = PXA2XX_AC97_RATES,
  137. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  138. .capture = {
  139. .stream_name = "AC97 Capture",
  140. .channels_min = 2,
  141. .channels_max = 2,
  142. .rates = PXA2XX_AC97_RATES,
  143. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  144. .ops = &pxa_ac97_hifi_dai_ops,
  145. },
  146. {
  147. .name = "pxa2xx-ac97-aux",
  148. .bus_control = true,
  149. .playback = {
  150. .stream_name = "AC97 Aux Playback",
  151. .channels_min = 1,
  152. .channels_max = 1,
  153. .rates = PXA2XX_AC97_RATES,
  154. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  155. .capture = {
  156. .stream_name = "AC97 Aux Capture",
  157. .channels_min = 1,
  158. .channels_max = 1,
  159. .rates = PXA2XX_AC97_RATES,
  160. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  161. .ops = &pxa_ac97_aux_dai_ops,
  162. },
  163. {
  164. .name = "pxa2xx-ac97-mic",
  165. .bus_control = true,
  166. .capture = {
  167. .stream_name = "AC97 Mic Capture",
  168. .channels_min = 1,
  169. .channels_max = 1,
  170. .rates = PXA2XX_AC97_RATES,
  171. .formats = SNDRV_PCM_FMTBIT_S16_LE,},
  172. .ops = &pxa_ac97_mic_dai_ops,
  173. },
  174. };
  175. static const struct snd_soc_component_driver pxa_ac97_component = {
  176. .name = "pxa-ac97",
  177. };
  178. static int pxa2xx_ac97_dev_probe(struct platform_device *pdev)
  179. {
  180. int ret;
  181. if (pdev->id != -1) {
  182. dev_err(&pdev->dev, "PXA2xx has only one AC97 port.\n");
  183. return -ENXIO;
  184. }
  185. ret = pxa2xx_ac97_hw_probe(pdev);
  186. if (ret) {
  187. dev_err(&pdev->dev, "PXA2xx AC97 hw probe error (%d)\n", ret);
  188. return ret;
  189. }
  190. ret = snd_soc_set_ac97_ops(&pxa2xx_ac97_ops);
  191. if (ret != 0)
  192. return ret;
  193. /* Punt most of the init to the SoC probe; we may need the machine
  194. * driver to do interesting things with the clocking to get us up
  195. * and running.
  196. */
  197. return snd_soc_register_component(&pdev->dev, &pxa_ac97_component,
  198. pxa_ac97_dai_driver, ARRAY_SIZE(pxa_ac97_dai_driver));
  199. }
  200. static int pxa2xx_ac97_dev_remove(struct platform_device *pdev)
  201. {
  202. snd_soc_unregister_component(&pdev->dev);
  203. snd_soc_set_ac97_ops(NULL);
  204. pxa2xx_ac97_hw_remove(pdev);
  205. return 0;
  206. }
  207. #ifdef CONFIG_PM_SLEEP
  208. static int pxa2xx_ac97_dev_suspend(struct device *dev)
  209. {
  210. return pxa2xx_ac97_hw_suspend();
  211. }
  212. static int pxa2xx_ac97_dev_resume(struct device *dev)
  213. {
  214. return pxa2xx_ac97_hw_resume();
  215. }
  216. static SIMPLE_DEV_PM_OPS(pxa2xx_ac97_pm_ops,
  217. pxa2xx_ac97_dev_suspend, pxa2xx_ac97_dev_resume);
  218. #endif
  219. static struct platform_driver pxa2xx_ac97_driver = {
  220. .probe = pxa2xx_ac97_dev_probe,
  221. .remove = pxa2xx_ac97_dev_remove,
  222. .driver = {
  223. .name = "pxa2xx-ac97",
  224. #ifdef CONFIG_PM_SLEEP
  225. .pm = &pxa2xx_ac97_pm_ops,
  226. #endif
  227. },
  228. };
  229. module_platform_driver(pxa2xx_ac97_driver);
  230. MODULE_AUTHOR("Nicolas Pitre");
  231. MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
  232. MODULE_LICENSE("GPL");