pxa2xx-ac97.c 7.9 KB

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