pxa2xx-ac97.c 7.6 KB

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