1f19493a3SShawn Guo /* 2f19493a3SShawn Guo * imx-pcm-dma-mx2.c -- ALSA Soc Audio Layer 3f19493a3SShawn Guo * 4f19493a3SShawn Guo * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de> 5f19493a3SShawn Guo * 6f19493a3SShawn Guo * This code is based on code copyrighted by Freescale, 7f19493a3SShawn Guo * Liam Girdwood, Javier Martin and probably others. 8f19493a3SShawn Guo * 9f19493a3SShawn Guo * This program is free software; you can redistribute it and/or modify it 10f19493a3SShawn Guo * under the terms of the GNU General Public License as published by the 11f19493a3SShawn Guo * Free Software Foundation; either version 2 of the License, or (at your 12f19493a3SShawn Guo * option) any later version. 13f19493a3SShawn Guo */ 14f19493a3SShawn Guo #include <linux/platform_device.h> 15f19493a3SShawn Guo #include <linux/dmaengine.h> 16f19493a3SShawn Guo #include <linux/types.h> 17f19493a3SShawn Guo 18f19493a3SShawn Guo #include <sound/core.h> 19f19493a3SShawn Guo #include <sound/pcm.h> 20f19493a3SShawn Guo #include <sound/soc.h> 21f19493a3SShawn Guo #include <sound/dmaengine_pcm.h> 22f19493a3SShawn Guo 23f19493a3SShawn Guo #include "imx-pcm.h" 24f19493a3SShawn Guo 25f19493a3SShawn Guo static bool filter(struct dma_chan *chan, void *param) 26f19493a3SShawn Guo { 27a8909c9bSLars-Peter Clausen struct snd_dmaengine_dai_dma_data *dma_data = param; 28a8909c9bSLars-Peter Clausen 29f19493a3SShawn Guo if (!imx_dma_is_general_purpose(chan)) 30f19493a3SShawn Guo return false; 31f19493a3SShawn Guo 32a8909c9bSLars-Peter Clausen chan->private = dma_data->filter_data; 33f19493a3SShawn Guo 34f19493a3SShawn Guo return true; 35f19493a3SShawn Guo } 36f19493a3SShawn Guo 37*adaa3229SLars-Peter Clausen static const struct snd_pcm_hardware imx_pcm_hardware = { 38f19493a3SShawn Guo .info = SNDRV_PCM_INFO_INTERLEAVED | 39f19493a3SShawn Guo SNDRV_PCM_INFO_BLOCK_TRANSFER | 40f19493a3SShawn Guo SNDRV_PCM_INFO_MMAP | 41f19493a3SShawn Guo SNDRV_PCM_INFO_MMAP_VALID | 42f19493a3SShawn Guo SNDRV_PCM_INFO_PAUSE | 43f19493a3SShawn Guo SNDRV_PCM_INFO_RESUME, 44f19493a3SShawn Guo .formats = SNDRV_PCM_FMTBIT_S16_LE, 45f19493a3SShawn Guo .rate_min = 8000, 46f19493a3SShawn Guo .channels_min = 2, 47f19493a3SShawn Guo .channels_max = 2, 48f19493a3SShawn Guo .buffer_bytes_max = IMX_SSI_DMABUF_SIZE, 49f19493a3SShawn Guo .period_bytes_min = 128, 50f19493a3SShawn Guo .period_bytes_max = 65535, /* Limited by SDMA engine */ 51f19493a3SShawn Guo .periods_min = 2, 52f19493a3SShawn Guo .periods_max = 255, 53f19493a3SShawn Guo .fifo_size = 0, 54f19493a3SShawn Guo }; 55f19493a3SShawn Guo 56*adaa3229SLars-Peter Clausen static const struct snd_dmaengine_pcm_config imx_dmaengine_pcm_config = { 57*adaa3229SLars-Peter Clausen .pcm_hardware = &imx_pcm_hardware, 58*adaa3229SLars-Peter Clausen .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config, 59*adaa3229SLars-Peter Clausen .compat_filter_fn = filter, 60*adaa3229SLars-Peter Clausen .prealloc_buffer_size = IMX_SSI_DMABUF_SIZE, 61f19493a3SShawn Guo }; 62f19493a3SShawn Guo 631927661bSShawn Guo int imx_pcm_dma_init(struct platform_device *pdev) 64f19493a3SShawn Guo { 65*adaa3229SLars-Peter Clausen return snd_dmaengine_pcm_register(&pdev->dev, &imx_dmaengine_pcm_config, 66*adaa3229SLars-Peter Clausen SND_DMAENGINE_PCM_FLAG_NO_RESIDUE | 67*adaa3229SLars-Peter Clausen SND_DMAENGINE_PCM_FLAG_NO_DT | 68*adaa3229SLars-Peter Clausen SND_DMAENGINE_PCM_FLAG_COMPAT); 69*adaa3229SLars-Peter Clausen } 70*adaa3229SLars-Peter Clausen 71*adaa3229SLars-Peter Clausen void imx_pcm_dma_exit(struct platform_device *pdev) 72*adaa3229SLars-Peter Clausen { 73*adaa3229SLars-Peter Clausen snd_dmaengine_pcm_unregister(&pdev->dev); 74f19493a3SShawn Guo } 75