pxa2xx-ac97.c 7.3 KB

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