aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/samsung/dma-wrapper.c
blob: 77b23e40f27326858ca629dac3bb82f61d7a16eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*
 *  dma-wrapper.c  --  I2S DMA Platform Wrapper Driver
 *
 *  * Copyright (c) 2010 Samsung Electronics Co. Ltd
 *
 *    This program is free software; you can redistribute  it and/or modify it
 *    under  the terms of  the GNU General  Public License as published by the
 *    Free Software Foundation;  either version 2 of the  License, or (at your
 *    option) any later version.
 */

#include <sound/soc.h>
#include "dma.h"
#include "idma.h"

#ifdef CONFIG_SND_SOC_SAMSUNG_USE_DMA_WRAPPER
static struct snd_soc_platform_driver *asoc_get_platform(struct snd_pcm *pcm)
{
	struct snd_soc_pcm_runtime *rtd = pcm->private_data;
	const char *cpu_dai_name = rtd->cpu_dai->name;

	if (!strcmp(cpu_dai_name, "samsung-i2s.4"))
		return &samsung_asoc_idma_platform;
	else
		return &samsung_asoc_platform;
}

static int asoc_platform_hw_params(struct snd_pcm_substream *substream,
				struct snd_pcm_hw_params *params)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->hw_params)
		return platform->ops->hw_params(substream, params);
	else
		return 0;
}

static int asoc_platform_hw_free(struct snd_pcm_substream *substream)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->hw_free)
		return platform->ops->hw_free(substream);
	else
		return 0;
}

static int asoc_platform_prepare(struct snd_pcm_substream *substream)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->prepare)
		return platform->ops->prepare(substream);
	else
		return 0;
}

static int asoc_platform_trigger(struct snd_pcm_substream *substream, int cmd)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->trigger)
		return platform->ops->trigger(substream, cmd);
	else
		return 0;
}

static snd_pcm_uframes_t
asoc_platform_pointer(struct snd_pcm_substream *substream)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->pointer)
		return platform->ops->pointer(substream);
	else
		return 0;
}

static int asoc_platform_open(struct snd_pcm_substream *substream)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->open)
		return platform->ops->open(substream);
	else
		return 0;
}

static int asoc_platform_close(struct snd_pcm_substream *substream)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->close)
		return platform->ops->close(substream);
	else
		return 0;
}

static int asoc_platform_ioctl(struct snd_pcm_substream *substream,
				unsigned int cmd, void *arg)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->ioctl)
		return platform->ops->ioctl(substream, cmd, arg);
	else
		return 0;
}

static int asoc_platform_mmap(struct snd_pcm_substream *substream,
				struct vm_area_struct *vma)
{
	struct snd_soc_platform_driver *platform =
					asoc_get_platform(substream->pcm);

	if (platform->ops->mmap)
		return platform->ops->mmap(substream, vma);
	else
		return 0;
}

static struct snd_pcm_ops asoc_platform_ops = {
	.open		= asoc_platform_open,
	.close		= asoc_platform_close,
	.ioctl		= asoc_platform_ioctl,
	.hw_params	= asoc_platform_hw_params,
	.hw_free	= asoc_platform_hw_free,
	.prepare	= asoc_platform_prepare,
	.trigger	= asoc_platform_trigger,
	.pointer	= asoc_platform_pointer,
	.mmap		= asoc_platform_mmap,
};

static void asoc_platform_free_dma_buffers(struct snd_pcm *pcm)
{
	struct snd_soc_platform_driver *platform = asoc_get_platform(pcm);

	if (platform->pcm_free)
		platform->pcm_free(pcm);
}

static int asoc_platform_new(struct snd_card *card,
				struct snd_soc_dai *dai, struct snd_pcm *pcm)
{
	struct snd_soc_platform_driver *platform = asoc_get_platform(pcm);

	if (platform->pcm_new)
		platform->pcm_new(card, dai, pcm);

	return 0;
}

static struct snd_soc_platform_driver asoc_dma_platform = {
	.ops		= &asoc_platform_ops,
	.pcm_new	= asoc_platform_new,
	.pcm_free	= asoc_platform_free_dma_buffers,
};

static int __devinit samsung_asoc_platform_probe(struct platform_device *pdev)
{
	return snd_soc_register_platform(&pdev->dev, &asoc_dma_platform);
}

static int __devexit samsung_asoc_platform_remove(struct platform_device *pdev)
{
	snd_soc_unregister_platform(&pdev->dev);
	return 0;
}

static struct platform_driver asoc_platform_driver = {
	.driver = {
		.name = "samsung-audio",
		.owner = THIS_MODULE,
	},

	.probe = samsung_asoc_platform_probe,
	.remove = __devexit_p(samsung_asoc_platform_remove),
};

static int __init samsung_asoc_init(void)
{
	return platform_driver_register(&asoc_platform_driver);
}
module_init(samsung_asoc_init);

static void __exit samsung_asoc_exit(void)
{
	platform_driver_unregister(&asoc_platform_driver);
}
module_exit(samsung_asoc_exit);
#endif

MODULE_DESCRIPTION("Samsung ASoC DMA wrapper");
MODULE_LICENSE("GPL");