Commit | Line | Data |
---|---|---|
8380222e SH |
1 | /* |
2 | * imx-pcm-dma-mx2.c -- ALSA Soc Audio Layer | |
3 | * | |
4 | * Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de> | |
5 | * | |
6 | * This code is based on code copyrighted by Freescale, | |
7 | * Liam Girdwood, Javier Martin and probably others. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify it | |
10 | * under the terms of the GNU General Public License as published by the | |
11 | * Free Software Foundation; either version 2 of the License, or (at your | |
12 | * option) any later version. | |
13 | */ | |
14 | #include <linux/clk.h> | |
15 | #include <linux/delay.h> | |
16 | #include <linux/device.h> | |
17 | #include <linux/dma-mapping.h> | |
18 | #include <linux/init.h> | |
19 | #include <linux/interrupt.h> | |
20 | #include <linux/module.h> | |
21 | #include <linux/platform_device.h> | |
5a0e3ad6 | 22 | #include <linux/slab.h> |
bf974a0d | 23 | #include <linux/dmaengine.h> |
258aea76 | 24 | #include <linux/types.h> |
8380222e SH |
25 | |
26 | #include <sound/core.h> | |
27 | #include <sound/initval.h> | |
28 | #include <sound/pcm.h> | |
29 | #include <sound/pcm_params.h> | |
30 | #include <sound/soc.h> | |
c307e8e3 | 31 | #include <sound/dmaengine_pcm.h> |
8380222e | 32 | |
4762fbab | 33 | #include "imx-pcm.h" |
8380222e | 34 | |
bf974a0d | 35 | static bool filter(struct dma_chan *chan, void *param) |
8380222e | 36 | { |
a8909c9b LPC |
37 | struct snd_dmaengine_dai_dma_data *dma_data = param; |
38 | ||
bf974a0d SH |
39 | if (!imx_dma_is_general_purpose(chan)) |
40 | return false; | |
8380222e | 41 | |
a8909c9b | 42 | chan->private = dma_data->filter_data; |
671999cb | 43 | |
c307e8e3 | 44 | return true; |
4564d10f LPC |
45 | } |
46 | ||
47 | static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream, | |
48 | struct snd_pcm_hw_params *params) | |
49 | { | |
50 | struct snd_soc_pcm_runtime *rtd = substream->private_data; | |
c307e8e3 | 51 | struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream); |
4564d10f | 52 | struct dma_slave_config slave_config; |
4564d10f LPC |
53 | int ret; |
54 | ||
c307e8e3 LPC |
55 | ret = snd_hwparams_to_dma_slave_config(substream, params, &slave_config); |
56 | if (ret) | |
57 | return ret; | |
8380222e | 58 | |
a8909c9b LPC |
59 | snd_dmaengine_pcm_set_config_from_dai_data(substream, |
60 | snd_soc_dai_get_dma_data(rtd->cpu_dai, substream), | |
61 | &slave_config); | |
8380222e | 62 | |
4564d10f | 63 | ret = dmaengine_slave_config(chan, &slave_config); |
bf974a0d SH |
64 | if (ret) |
65 | return ret; | |
8380222e | 66 | |
8380222e SH |
67 | snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); |
68 | ||
8380222e SH |
69 | return 0; |
70 | } | |
71 | ||
8380222e SH |
72 | static struct snd_pcm_hardware snd_imx_hardware = { |
73 | .info = SNDRV_PCM_INFO_INTERLEAVED | | |
74 | SNDRV_PCM_INFO_BLOCK_TRANSFER | | |
75 | SNDRV_PCM_INFO_MMAP | | |
76 | SNDRV_PCM_INFO_MMAP_VALID | | |
77 | SNDRV_PCM_INFO_PAUSE | | |
78 | SNDRV_PCM_INFO_RESUME, | |
79 | .formats = SNDRV_PCM_FMTBIT_S16_LE, | |
80 | .rate_min = 8000, | |
81 | .channels_min = 2, | |
82 | .channels_max = 2, | |
83 | .buffer_bytes_max = IMX_SSI_DMABUF_SIZE, | |
84 | .period_bytes_min = 128, | |
bf974a0d | 85 | .period_bytes_max = 65535, /* Limited by SDMA engine */ |
8380222e SH |
86 | .periods_min = 2, |
87 | .periods_max = 255, | |
88 | .fifo_size = 0, | |
89 | }; | |
90 | ||
91 | static int snd_imx_open(struct snd_pcm_substream *substream) | |
92 | { | |
c307e8e3 | 93 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
8380222e | 94 | |
c307e8e3 | 95 | snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware); |
8380222e | 96 | |
a8909c9b LPC |
97 | return snd_dmaengine_pcm_open(substream, filter, |
98 | snd_soc_dai_get_dma_data(rtd->cpu_dai, substream)); | |
8380222e SH |
99 | } |
100 | ||
101 | static struct snd_pcm_ops imx_pcm_ops = { | |
102 | .open = snd_imx_open, | |
7c1c1d4a | 103 | .close = snd_dmaengine_pcm_close_release_chan, |
8380222e SH |
104 | .ioctl = snd_pcm_lib_ioctl, |
105 | .hw_params = snd_imx_pcm_hw_params, | |
c307e8e3 | 106 | .trigger = snd_dmaengine_pcm_trigger, |
9883ab22 | 107 | .pointer = snd_dmaengine_pcm_pointer_no_residue, |
8380222e SH |
108 | .mmap = snd_imx_pcm_mmap, |
109 | }; | |
110 | ||
f0fba2ad LG |
111 | static struct snd_soc_platform_driver imx_soc_platform_mx2 = { |
112 | .ops = &imx_pcm_ops, | |
8380222e SH |
113 | .pcm_new = imx_pcm_new, |
114 | .pcm_free = imx_pcm_free, | |
115 | }; | |
116 | ||
1927661b | 117 | int imx_pcm_dma_init(struct platform_device *pdev) |
8380222e | 118 | { |
f0fba2ad LG |
119 | return snd_soc_register_platform(&pdev->dev, &imx_soc_platform_mx2); |
120 | } |