~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/soc/pxa/mmp-pcm.c

Version: ~ [ linux-5.9.1 ] ~ [ linux-5.8.16 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.72 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.152 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.202 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.240 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.240 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * linux/sound/soc/pxa/mmp-pcm.c
  3  *
  4  * Copyright (C) 2011 Marvell International Ltd.
  5  *
  6  * This program is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as published by
  8  * the Free Software Foundation; either version 2 of the License, or
  9  * (at your option) any later version.
 10  *
 11  */
 12 #include <linux/module.h>
 13 #include <linux/init.h>
 14 #include <linux/platform_device.h>
 15 #include <linux/slab.h>
 16 #include <linux/dma-mapping.h>
 17 #include <linux/dmaengine.h>
 18 #include <linux/platform_data/dma-mmp_tdma.h>
 19 #include <linux/platform_data/mmp_audio.h>
 20 
 21 #include <sound/pxa2xx-lib.h>
 22 #include <sound/core.h>
 23 #include <sound/pcm.h>
 24 #include <sound/pcm_params.h>
 25 #include <sound/soc.h>
 26 #include <sound/dmaengine_pcm.h>
 27 
 28 #define DRV_NAME "mmp-pcm"
 29 
 30 struct mmp_dma_data {
 31         int ssp_id;
 32         struct resource *dma_res;
 33 };
 34 
 35 #define MMP_PCM_INFO (SNDRV_PCM_INFO_MMAP |     \
 36                 SNDRV_PCM_INFO_MMAP_VALID |     \
 37                 SNDRV_PCM_INFO_INTERLEAVED |    \
 38                 SNDRV_PCM_INFO_PAUSE |          \
 39                 SNDRV_PCM_INFO_RESUME |         \
 40                 SNDRV_PCM_INFO_NO_PERIOD_WAKEUP)
 41 
 42 static struct snd_pcm_hardware mmp_pcm_hardware[] = {
 43         {
 44                 .info                   = MMP_PCM_INFO,
 45                 .period_bytes_min       = 1024,
 46                 .period_bytes_max       = 2048,
 47                 .periods_min            = 2,
 48                 .periods_max            = 32,
 49                 .buffer_bytes_max       = 4096,
 50                 .fifo_size              = 32,
 51         },
 52         {
 53                 .info                   = MMP_PCM_INFO,
 54                 .period_bytes_min       = 1024,
 55                 .period_bytes_max       = 2048,
 56                 .periods_min            = 2,
 57                 .periods_max            = 32,
 58                 .buffer_bytes_max       = 4096,
 59                 .fifo_size              = 32,
 60         },
 61 };
 62 
 63 static int mmp_pcm_hw_params(struct snd_pcm_substream *substream,
 64                               struct snd_pcm_hw_params *params)
 65 {
 66         struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
 67         struct dma_slave_config slave_config;
 68         int ret;
 69 
 70         ret =
 71             snd_dmaengine_pcm_prepare_slave_config(substream, params,
 72                                                    &slave_config);
 73         if (ret)
 74                 return ret;
 75 
 76         ret = dmaengine_slave_config(chan, &slave_config);
 77         if (ret)
 78                 return ret;
 79 
 80         snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
 81 
 82         return 0;
 83 }
 84 
 85 static bool filter(struct dma_chan *chan, void *param)
 86 {
 87         struct mmp_dma_data *dma_data = param;
 88         bool found = false;
 89         char *devname;
 90 
 91         devname = kasprintf(GFP_KERNEL, "%s.%d", dma_data->dma_res->name,
 92                 dma_data->ssp_id);
 93         if ((strcmp(dev_name(chan->device->dev), devname) == 0) &&
 94                 (chan->chan_id == dma_data->dma_res->start)) {
 95                 found = true;
 96         }
 97 
 98         kfree(devname);
 99         return found;
100 }
101 
102 static int mmp_pcm_open(struct snd_pcm_substream *substream)
103 {
104         struct snd_soc_pcm_runtime *rtd = substream->private_data;
105         struct snd_soc_component *component = snd_soc_rtdcom_lookup(rtd, DRV_NAME);
106         struct platform_device *pdev = to_platform_device(component->dev);
107         struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
108         struct mmp_dma_data dma_data;
109         struct resource *r;
110 
111         r = platform_get_resource(pdev, IORESOURCE_DMA, substream->stream);
112         if (!r)
113                 return -EBUSY;
114 
115         snd_soc_set_runtime_hwparams(substream,
116                                 &mmp_pcm_hardware[substream->stream]);
117 
118         dma_data.dma_res = r;
119         dma_data.ssp_id = cpu_dai->id;
120 
121         return snd_dmaengine_pcm_open_request_chan(substream, filter,
122                     &dma_data);
123 }
124 
125 static int mmp_pcm_mmap(struct snd_pcm_substream *substream,
126                          struct vm_area_struct *vma)
127 {
128         struct snd_pcm_runtime *runtime = substream->runtime;
129         unsigned long off = vma->vm_pgoff;
130 
131         vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
132         return remap_pfn_range(vma, vma->vm_start,
133                 __phys_to_pfn(runtime->dma_addr) + off,
134                 vma->vm_end - vma->vm_start, vma->vm_page_prot);
135 }
136 
137 static const struct snd_pcm_ops mmp_pcm_ops = {
138         .open           = mmp_pcm_open,
139         .close          = snd_dmaengine_pcm_close_release_chan,
140         .ioctl          = snd_pcm_lib_ioctl,
141         .hw_params      = mmp_pcm_hw_params,
142         .trigger        = snd_dmaengine_pcm_trigger,
143         .pointer        = snd_dmaengine_pcm_pointer,
144         .mmap           = mmp_pcm_mmap,
145 };
146 
147 static void mmp_pcm_free_dma_buffers(struct snd_pcm *pcm)
148 {
149         struct snd_pcm_substream *substream;
150         struct snd_dma_buffer *buf;
151         int stream;
152         struct gen_pool *gpool;
153 
154         gpool = sram_get_gpool("asram");
155         if (!gpool)
156                 return;
157 
158         for (stream = 0; stream < 2; stream++) {
159                 size_t size = mmp_pcm_hardware[stream].buffer_bytes_max;
160 
161                 substream = pcm->streams[stream].substream;
162                 if (!substream)
163                         continue;
164 
165                 buf = &substream->dma_buffer;
166                 if (!buf->area)
167                         continue;
168                 gen_pool_free(gpool, (unsigned long)buf->area, size);
169                 buf->area = NULL;
170         }
171 
172 }
173 
174 static int mmp_pcm_preallocate_dma_buffer(struct snd_pcm_substream *substream,
175                                                                 int stream)
176 {
177         struct snd_dma_buffer *buf = &substream->dma_buffer;
178         size_t size = mmp_pcm_hardware[stream].buffer_bytes_max;
179         struct gen_pool *gpool;
180 
181         buf->dev.type = SNDRV_DMA_TYPE_DEV;
182         buf->dev.dev = substream->pcm->card->dev;
183         buf->private_data = NULL;
184 
185         gpool = sram_get_gpool("asram");
186         if (!gpool)
187                 return -ENOMEM;
188 
189         buf->area = gen_pool_dma_alloc(gpool, size, &buf->addr);
190         if (!buf->area)
191                 return -ENOMEM;
192         buf->bytes = size;
193         return 0;
194 }
195 
196 static int mmp_pcm_new(struct snd_soc_pcm_runtime *rtd)
197 {
198         struct snd_pcm_substream *substream;
199         struct snd_pcm *pcm = rtd->pcm;
200         int ret = 0, stream;
201 
202         for (stream = 0; stream < 2; stream++) {
203                 substream = pcm->streams[stream].substream;
204 
205                 ret = mmp_pcm_preallocate_dma_buffer(substream, stream);
206                 if (ret)
207                         goto err;
208         }
209 
210         return 0;
211 
212 err:
213         mmp_pcm_free_dma_buffers(pcm);
214         return ret;
215 }
216 
217 static const struct snd_soc_component_driver mmp_soc_component = {
218         .name           = DRV_NAME,
219         .ops            = &mmp_pcm_ops,
220         .pcm_new        = mmp_pcm_new,
221         .pcm_free       = mmp_pcm_free_dma_buffers,
222 };
223 
224 static int mmp_pcm_probe(struct platform_device *pdev)
225 {
226         struct mmp_audio_platdata *pdata = pdev->dev.platform_data;
227 
228         if (pdata) {
229                 mmp_pcm_hardware[SNDRV_PCM_STREAM_PLAYBACK].buffer_bytes_max =
230                                                 pdata->buffer_max_playback;
231                 mmp_pcm_hardware[SNDRV_PCM_STREAM_PLAYBACK].period_bytes_max =
232                                                 pdata->period_max_playback;
233                 mmp_pcm_hardware[SNDRV_PCM_STREAM_CAPTURE].buffer_bytes_max =
234                                                 pdata->buffer_max_capture;
235                 mmp_pcm_hardware[SNDRV_PCM_STREAM_CAPTURE].period_bytes_max =
236                                                 pdata->period_max_capture;
237         }
238         return devm_snd_soc_register_component(&pdev->dev, &mmp_soc_component,
239                                                NULL, 0);
240 }
241 
242 static struct platform_driver mmp_pcm_driver = {
243         .driver = {
244                 .name = "mmp-pcm-audio",
245         },
246 
247         .probe = mmp_pcm_probe,
248 };
249 
250 module_platform_driver(mmp_pcm_driver);
251 
252 MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
253 MODULE_DESCRIPTION("MMP Soc Audio DMA module");
254 MODULE_LICENSE("GPL");
255 MODULE_ALIAS("platform:mmp-pcm-audio");
256 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp