aboutsummaryrefslogtreecommitdiffstats
path: root/common/recipes-kernel/linux/linux-yocto-4.14.71/1110-ASoC-AMD-create-add-dummy-codec-and-machine-devices-.patch
blob: 6588432204eb33cf9994fc5a2eb8cdb36fc4a30b (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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
From 75e335dc0329493b561602eba43490ba1e5d9b56 Mon Sep 17 00:00:00 2001
From: Maruthi Srinivas Bayyavarapu <Maruthi.Bayyavarapu@amd.com>
Date: Thu, 30 Mar 2017 16:05:24 +0530
Subject: [PATCH 1110/4131] ASoC: AMD: create/add dummy codec and machine
 devices/drivers

Dummy codec and machine devices are created so that ASoC based
soundcard can be created. Respective drivers which bound to
these devices are added.

Signed-off-by: Maruthi Bayyavarapu <maruthi.bayyavarapu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
---
 sound/soc/amd/raven/Makefile          |   4 +
 sound/soc/amd/raven/acp3x-dummy5102.c | 136 ++++++++++++++++++++++++++++++++++
 sound/soc/amd/raven/dummy-w5102.c     | 102 +++++++++++++++++++++++++
 sound/soc/amd/raven/pci-acp3x.c       |  34 ++++++++-
 4 files changed, 272 insertions(+), 4 deletions(-)
 create mode 100644 sound/soc/amd/raven/acp3x-dummy5102.c
 create mode 100644 sound/soc/amd/raven/dummy-w5102.c

diff --git a/sound/soc/amd/raven/Makefile b/sound/soc/amd/raven/Makefile
index 8c03e6f..5db3afc 100644
--- a/sound/soc/amd/raven/Makefile
+++ b/sound/soc/amd/raven/Makefile
@@ -1,4 +1,8 @@
 snd-pci-acp3x-objs	:= pci-acp3x.o
 snd-acp3x-pcm-dma-objs	:= acp3x-pcm-dma.o
+snd-soc-dummy-w5102-objs := dummy-w5102.o
+snd-soc-acp3x-mach-objs := acp3x-dummy5102.o
 obj-$(CONFIG_SND_SOC_AMD_ACP3x)	 += snd-pci-acp3x.o
 obj-$(CONFIG_SND_SOC_AMD_ACP3x)	 += snd-acp3x-pcm-dma.o
+obj-$(CONFIG_SND_SOC_AMD_ACP3x)	+= snd-soc-dummy-w5102.o
+obj-$(CONFIG_SND_SOC_AMD_ACP3x)	+= snd-soc-acp3x-mach.o
diff --git a/sound/soc/amd/raven/acp3x-dummy5102.c b/sound/soc/amd/raven/acp3x-dummy5102.c
new file mode 100644
index 0000000..3b2f509
--- /dev/null
+++ b/sound/soc/amd/raven/acp3x-dummy5102.c
@@ -0,0 +1,136 @@
+/*
+ * Machine driver for AMD ACP Audio engine using dummy codec
+ *
+ * Copyright 2016 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ */
+
+#include <sound/soc.h>
+#include <sound/soc-dapm.h>
+#include <linux/module.h>
+
+static int acp3x_hw_params(struct snd_pcm_substream *substream,
+				struct snd_pcm_hw_params *params)
+
+{
+	return 0;
+}
+
+static struct snd_soc_ops acp3x_wm5102_ops = {
+	.hw_params = acp3x_hw_params,
+};
+
+static int acp3x_init(struct snd_soc_pcm_runtime *rtd)
+{
+	return 0;
+}
+
+static struct snd_soc_dai_link acp3x_dai_w5102[] = {
+	{
+		.name = "RV-W5102-PLAY",
+		.stream_name = "Playback",
+		.platform_name = "acp3x_rv_i2s.0",
+		.cpu_dai_name = "acp3x_rv_i2s.0",
+		.codec_dai_name = "dummy_w5102_dai",
+		.codec_name = "dummy_w5102.0",
+		.dai_fmt = SND_SOC_DAIFMT_DSP_A /*SND_SOC_DAIFMT_I2S*/ | SND_SOC_DAIFMT_NB_NF
+				| SND_SOC_DAIFMT_CBM_CFM,
+		.ops = &acp3x_wm5102_ops,
+		.init = acp3x_init,
+	},
+};
+
+static const struct snd_soc_dapm_widget acp3x_widgets[] = {
+	SND_SOC_DAPM_HP("Headphones", NULL),
+	SND_SOC_DAPM_MIC("Analog Mic", NULL),
+};
+
+static const struct snd_soc_dapm_route acp3x_audio_route[] = {
+	{"Headphones", NULL, "HPO L"},
+	{"Headphones", NULL, "HPO R"},
+	{"MIC1", NULL, "Analog Mic"},
+};
+
+static struct snd_soc_card acp3x_card = {
+	.name = "acp3x",
+	.owner = THIS_MODULE,
+	.dai_link = acp3x_dai_w5102,
+	.num_links = 1,
+};
+
+static int acp3x_probe(struct platform_device *pdev)
+{
+	int ret;
+	struct acp_wm5102 *machine = NULL;
+	struct snd_soc_card *card;
+
+	card = &acp3x_card;
+	acp3x_card.dev = &pdev->dev;
+
+	platform_set_drvdata(pdev, card);
+	snd_soc_card_set_drvdata(card, machine);
+
+	ret = snd_soc_register_card(card);
+	if (ret) {
+		dev_err(&pdev->dev,
+				"snd_soc_register_card(%s) failed: %d\n",
+				acp3x_card.name, ret);
+		return ret;
+	}
+	return 0;
+}
+
+static int acp3x_remove(struct platform_device *pdev)
+{
+	struct snd_soc_card *card;
+
+	card = platform_get_drvdata(pdev);
+	snd_soc_unregister_card(card);
+
+	return 0;
+}
+
+static struct platform_driver acp3x_mach_driver = {
+	.driver = {
+		.name = "acp3x_w5102_mach",
+		.pm = &snd_soc_pm_ops,
+	},
+	.probe = acp3x_probe,
+	.remove = acp3x_remove,
+};
+
+static int __init acp3x_audio_init(void)
+{
+	platform_driver_register(&acp3x_mach_driver);
+	return 0;
+}
+
+static void __exit acp3x_audio_exit(void)
+{
+	platform_driver_unregister(&acp3x_mach_driver);
+}
+
+module_init(acp3x_audio_init);
+module_exit(acp3x_audio_exit);
+
+MODULE_AUTHOR("Maruthi.Bayyavarapu@amd.com");
+MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/amd/raven/dummy-w5102.c b/sound/soc/amd/raven/dummy-w5102.c
new file mode 100644
index 0000000..3e09e32
--- /dev/null
+++ b/sound/soc/amd/raven/dummy-w5102.c
@@ -0,0 +1,102 @@
+/*
+ * dummy audio codec driver
+ *
+ * Copyright 2016 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ */
+
+#include <linux/module.h>
+#include <sound/soc.h>
+
+#define W5102_RATES	SNDRV_PCM_RATE_8000_96000
+#define W5102_FORMATS	(SNDRV_PCM_FMTBIT_S16_LE | \
+			SNDRV_PCM_FMTBIT_S32_LE | \
+			SNDRV_PCM_FMTBIT_S24_LE)
+
+static const struct snd_soc_dapm_widget w5102_widgets[] = {
+	SND_SOC_DAPM_OUTPUT("dummy-w5102-out"),
+	SND_SOC_DAPM_INPUT("dummy-w5102-in"),
+};
+
+static const struct snd_soc_dapm_route w5102_routes[] = {
+	{ "dummy-w5102-out", NULL, "Playback" },
+	{ "Capture", NULL, "dummy-w5102-in" },
+};
+
+static struct snd_soc_codec_driver soc_codec_w5102_dummy = {
+	.component_driver = {
+		.dapm_widgets = w5102_widgets,
+		.num_dapm_widgets = ARRAY_SIZE(w5102_widgets),
+		.dapm_routes = w5102_routes,
+		.num_dapm_routes = ARRAY_SIZE(w5102_routes),
+	},
+};
+
+static struct snd_soc_dai_driver w5102_stub_dai = {
+	.name		= "dummy_w5102_dai",
+	.playback	= {
+		.stream_name	= "Playback",
+		.channels_min	= 2,
+		.channels_max	= 2,
+		.rates		= W5102_RATES,
+		.formats	= W5102_FORMATS,
+	},
+	.capture	= {
+		.stream_name	= "Capture",
+		.channels_min	= 2,
+		.channels_max	= 2,
+		.rates		= W5102_RATES,
+		.formats	= W5102_FORMATS,
+	},
+
+};
+
+static int dummy_w5102_probe(struct platform_device *pdev)
+{
+	int ret;
+
+	ret = snd_soc_register_codec(&pdev->dev, &soc_codec_w5102_dummy,
+			&w5102_stub_dai, 1);
+	return ret;
+}
+
+static int dummy_w5102_remove(struct platform_device *pdev)
+{
+	snd_soc_unregister_codec(&pdev->dev);
+	return 0;
+}
+
+
+static struct platform_driver dummy_w5102_driver = {
+	.probe		= dummy_w5102_probe,
+	.remove		= dummy_w5102_remove,
+	.driver		= {
+		.name	= "dummy_w5102",
+		.owner	= THIS_MODULE,
+	},
+};
+
+module_platform_driver(dummy_w5102_driver);
+
+MODULE_DESCRIPTION("dummy-w5102 dummy codec driver");
+MODULE_LICENSE("GPL v2");
+MODULE_ALIAS("platform: dummy_w5102");
diff --git a/sound/soc/amd/raven/pci-acp3x.c b/sound/soc/amd/raven/pci-acp3x.c
index a182013..5891c5b 100644
--- a/sound/soc/amd/raven/pci-acp3x.c
+++ b/sound/soc/amd/raven/pci-acp3x.c
@@ -24,7 +24,7 @@ struct acp3x_dev_data {
 	void __iomem *acp3x_base;
 	bool acp3x_audio_mode;
 	struct resource *res;
-	struct platform_device *pdev;
+	struct platform_device *pdev[3];
 };
 
 static int snd_acp3x_probe(struct pci_dev *pci,
@@ -103,13 +103,30 @@ static int snd_acp3x_probe(struct pci_dev *pci,
 		pdevinfo.data = &irqflags;
 		pdevinfo.size_data = sizeof(irqflags);
 
-		adata->pdev = platform_device_register_full(&pdevinfo);
-		if (adata->pdev == NULL) {
+		adata->pdev[0] = platform_device_register_full(&pdevinfo);
+		if (adata->pdev[0] == NULL) {
 			dev_err(&pci->dev, "cannot register %s device\n",
 				pdevinfo.name);
 			ret = -ENODEV;
 			goto unmap_mmio;
 		}
+
+		/* create dummy codec device */
+		adata->pdev[1] = platform_device_register_simple("dummy_w5102",
+					0, NULL, 0);
+		if (IS_ERR(adata->pdev[1])) {
+			dev_err(&pci->dev, "Cannot register dummy_w5102\n");
+			ret = -ENODEV;
+			goto unregister_pdev0;
+		}
+		/* create dummy mach device */
+		adata->pdev[2] = platform_device_register_simple(
+					"acp3x_w5102_mach", 0, NULL, 0);
+		if (IS_ERR(adata->pdev[2])) {
+			dev_err(&pci->dev, "Cannot register acp3x_w5102_mach\n");
+			ret = -ENODEV;
+			goto unregister_pdev1;
+		}
 	} else {
 		dev_err(&pci->dev, "Inavlid ACP audio mode : %d\n", val);
 		ret = -ENODEV;
@@ -118,6 +135,10 @@ static int snd_acp3x_probe(struct pci_dev *pci,
 
 	return 0;
 
+unregister_pdev1:
+	platform_device_unregister(adata->pdev[1]);
+unregister_pdev0:
+	platform_device_unregister(adata->pdev[0]);
 unmap_mmio:
 	pci_disable_msi(pci);
 	iounmap(adata->acp3x_base);
@@ -131,9 +152,14 @@ static int snd_acp3x_probe(struct pci_dev *pci,
 
 static void snd_acp3x_remove(struct pci_dev *pci)
 {
+	int i;
 	struct acp3x_dev_data *adata = pci_get_drvdata(pci);
 
-	platform_device_unregister(adata->pdev);
+	if (adata->acp3x_audio_mode == ACP3x_I2S_MODE) {
+		for (i = 2; i >= 0; i--)
+			platform_device_unregister(adata->pdev[i]);
+	}
+
 	iounmap(adata->acp3x_base);
 
 	pci_disable_msi(pci);
-- 
2.7.4