pxa2xx-ac97.c 7.1 KB

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