tegra_pcm.c (9a64e8e0ace51b309fdcff4b4754b3649250382a) tegra_pcm.c (df79f55df3992fdd5dd206de6aa9af6a8ec1f86f)
1/*
2 * tegra_pcm.c - Tegra PCM driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *

--- 22 unchanged lines hidden (view full) ---

31
32#include <linux/dma-mapping.h>
33#include <linux/module.h>
34#include <linux/slab.h>
35#include <sound/core.h>
36#include <sound/pcm.h>
37#include <sound/pcm_params.h>
38#include <sound/soc.h>
1/*
2 * tegra_pcm.c - Tegra PCM driver
3 *
4 * Author: Stephen Warren <swarren@nvidia.com>
5 * Copyright (C) 2010,2012 - NVIDIA, Inc.
6 *
7 * Based on code copyright/by:
8 *

--- 22 unchanged lines hidden (view full) ---

31
32#include <linux/dma-mapping.h>
33#include <linux/module.h>
34#include <linux/slab.h>
35#include <sound/core.h>
36#include <sound/pcm.h>
37#include <sound/pcm_params.h>
38#include <sound/soc.h>
39#include <sound/dmaengine_pcm.h>
39
40#include "tegra_pcm.h"
41
42static const struct snd_pcm_hardware tegra_pcm_hardware = {
43 .info = SNDRV_PCM_INFO_MMAP |
44 SNDRV_PCM_INFO_MMAP_VALID |
45 SNDRV_PCM_INFO_PAUSE |
46 SNDRV_PCM_INFO_RESUME |

--- 4 unchanged lines hidden (view full) ---

51 .period_bytes_min = 1024,
52 .period_bytes_max = PAGE_SIZE,
53 .periods_min = 2,
54 .periods_max = 8,
55 .buffer_bytes_max = PAGE_SIZE * 8,
56 .fifo_size = 4,
57};
58
40
41#include "tegra_pcm.h"
42
43static const struct snd_pcm_hardware tegra_pcm_hardware = {
44 .info = SNDRV_PCM_INFO_MMAP |
45 SNDRV_PCM_INFO_MMAP_VALID |
46 SNDRV_PCM_INFO_PAUSE |
47 SNDRV_PCM_INFO_RESUME |

--- 4 unchanged lines hidden (view full) ---

52 .period_bytes_min = 1024,
53 .period_bytes_max = PAGE_SIZE,
54 .periods_min = 2,
55 .periods_max = 8,
56 .buffer_bytes_max = PAGE_SIZE * 8,
57 .fifo_size = 4,
58};
59
60#if defined(CONFIG_TEGRA_SYSTEM_DMA)
59static void tegra_pcm_queue_dma(struct tegra_runtime_data *prtd)
60{
61 struct snd_pcm_substream *substream = prtd->substream;
62 struct snd_dma_buffer *buf = &substream->dma_buffer;
63 struct tegra_dma_req *dma_req;
64 unsigned long addr;
65
66 dma_req = &prtd->dma_req[prtd->dma_req_idx];

--- 213 unchanged lines hidden (view full) ---

280 .close = tegra_pcm_close,
281 .ioctl = snd_pcm_lib_ioctl,
282 .hw_params = tegra_pcm_hw_params,
283 .hw_free = tegra_pcm_hw_free,
284 .trigger = tegra_pcm_trigger,
285 .pointer = tegra_pcm_pointer,
286 .mmap = tegra_pcm_mmap,
287};
61static void tegra_pcm_queue_dma(struct tegra_runtime_data *prtd)
62{
63 struct snd_pcm_substream *substream = prtd->substream;
64 struct snd_dma_buffer *buf = &substream->dma_buffer;
65 struct tegra_dma_req *dma_req;
66 unsigned long addr;
67
68 dma_req = &prtd->dma_req[prtd->dma_req_idx];

--- 213 unchanged lines hidden (view full) ---

282 .close = tegra_pcm_close,
283 .ioctl = snd_pcm_lib_ioctl,
284 .hw_params = tegra_pcm_hw_params,
285 .hw_free = tegra_pcm_hw_free,
286 .trigger = tegra_pcm_trigger,
287 .pointer = tegra_pcm_pointer,
288 .mmap = tegra_pcm_mmap,
289};
290#else
291static int tegra_pcm_open(struct snd_pcm_substream *substream)
292{
293 struct snd_soc_pcm_runtime *rtd = substream->private_data;
294 struct device *dev = rtd->platform->dev;
295 int ret;
288
296
297 /* Set HW params now that initialization is complete */
298 snd_soc_set_runtime_hwparams(substream, &tegra_pcm_hardware);
299
300 ret = snd_dmaengine_pcm_open(substream, NULL, NULL);
301 if (ret) {
302 dev_err(dev, "dmaengine pcm open failed with err %d\n", ret);
303 return ret;
304 }
305
306 return 0;
307}
308
309static int tegra_pcm_close(struct snd_pcm_substream *substream)
310{
311 snd_dmaengine_pcm_close(substream);
312 return 0;
313}
314
315static int tegra_pcm_hw_params(struct snd_pcm_substream *substream,
316 struct snd_pcm_hw_params *params)
317{
318 struct snd_soc_pcm_runtime *rtd = substream->private_data;
319 struct device *dev = rtd->platform->dev;
320 struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
321 struct tegra_pcm_dma_params *dmap;
322 struct dma_slave_config slave_config;
323 int ret;
324
325 dmap = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
326
327 ret = snd_hwparams_to_dma_slave_config(substream, params,
328 &slave_config);
329 if (ret) {
330 dev_err(dev, "hw params config failed with err %d\n", ret);
331 return ret;
332 }
333
334 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
335 slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
336 slave_config.dst_addr = dmap->addr;
337 slave_config.src_maxburst = 0;
338 } else {
339 slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
340 slave_config.src_addr = dmap->addr;
341 slave_config.dst_maxburst = 0;
342 }
343 slave_config.slave_id = dmap->req_sel;
344
345 ret = dmaengine_slave_config(chan, &slave_config);
346 if (ret < 0) {
347 dev_err(dev, "dma slave config failed with err %d\n", ret);
348 return ret;
349 }
350
351 snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
352 return 0;
353}
354
355static int tegra_pcm_hw_free(struct snd_pcm_substream *substream)
356{
357 snd_pcm_set_runtime_buffer(substream, NULL);
358 return 0;
359}
360
361static int tegra_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
362{
363 switch (cmd) {
364 case SNDRV_PCM_TRIGGER_START:
365 case SNDRV_PCM_TRIGGER_RESUME:
366 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
367 return snd_dmaengine_pcm_trigger(substream,
368 SNDRV_PCM_TRIGGER_START);
369
370 case SNDRV_PCM_TRIGGER_STOP:
371 case SNDRV_PCM_TRIGGER_SUSPEND:
372 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
373 return snd_dmaengine_pcm_trigger(substream,
374 SNDRV_PCM_TRIGGER_STOP);
375 default:
376 return -EINVAL;
377 }
378 return 0;
379}
380
381static int tegra_pcm_mmap(struct snd_pcm_substream *substream,
382 struct vm_area_struct *vma)
383{
384 struct snd_pcm_runtime *runtime = substream->runtime;
385
386 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
387 runtime->dma_area,
388 runtime->dma_addr,
389 runtime->dma_bytes);
390}
391
392static struct snd_pcm_ops tegra_pcm_ops = {
393 .open = tegra_pcm_open,
394 .close = tegra_pcm_close,
395 .ioctl = snd_pcm_lib_ioctl,
396 .hw_params = tegra_pcm_hw_params,
397 .hw_free = tegra_pcm_hw_free,
398 .trigger = tegra_pcm_trigger,
399 .pointer = snd_dmaengine_pcm_pointer,
400 .mmap = tegra_pcm_mmap,
401};
402#endif
403
289static int tegra_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
290{
291 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
292 struct snd_dma_buffer *buf = &substream->dma_buffer;
293 size_t size = tegra_pcm_hardware.buffer_bytes_max;
294
295 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
296 &buf->addr, GFP_KERNEL);

--- 91 unchanged lines hidden ---
404static int tegra_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
405{
406 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
407 struct snd_dma_buffer *buf = &substream->dma_buffer;
408 size_t size = tegra_pcm_hardware.buffer_bytes_max;
409
410 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
411 &buf->addr, GFP_KERNEL);

--- 91 unchanged lines hidden ---