summaryrefslogtreecommitdiff
path: root/sound/soc/msm/qdsp6v2/msm-dai-stub-v2.c
blob: 616a1b22b0c3445d9328316973c252097ae0039a (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
#include <linux/init.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/of_device.h>
#include <linux/platform_device.h>
#include <sound/core.h>
#include <sound/pcm.h>
#include <sound/soc.h>

enum {
	STUB_RX,
	STUB_TX,
	STUB_1_RX,
	STUB_1_TX,
	STUB_DTMF_TX,
	STUB_HOST_RX_CAPTURE_TX,
	STUB_HOST_RX_PLAYBACK_RX,
	STUB_HOST_TX_CAPTURE_TX,
	STUB_HOST_TX_PLAYBACK_RX,
};

static int msm_dai_stub_set_channel_map(struct snd_soc_dai *dai,
		unsigned int tx_num, unsigned int *tx_slot,
		unsigned int rx_num, unsigned int *rx_slot)
{
	pr_debug("%s:\n", __func__);

	return 0;
}

static struct snd_soc_dai_ops msm_dai_stub_ops = {
	.set_channel_map = msm_dai_stub_set_channel_map,
};

static int msm_dai_stub_add_route(struct snd_soc_dai *dai)
{
	struct snd_soc_dapm_route intercon;
	struct snd_soc_dapm_context *dapm;

	if (!dai || !dai->driver) {
		pr_err("%s Invalid params\n", __func__);
		return -EINVAL;
	}
	dapm = snd_soc_component_get_dapm(dai->component);
	memset(&intercon, 0 , sizeof(intercon));
	if (dai->driver->playback.stream_name &&
		dai->driver->playback.aif_name) {
		dev_dbg(dai->dev, "%s add route for widget %s",
			__func__, dai->driver->playback.stream_name);
		intercon.source = dai->driver->playback.aif_name;
		intercon.sink = dai->driver->playback.stream_name;
		dev_dbg(dai->dev, "%s src %s sink %s\n",
			__func__, intercon.source, intercon.sink);
		snd_soc_dapm_add_routes(dapm, &intercon, 1);
	}
	if (dai->driver->capture.stream_name &&
		dai->driver->capture.aif_name) {
		dev_dbg(dai->dev, "%s add route for widget %s",
			__func__, dai->driver->capture.stream_name);
		intercon.sink = dai->driver->capture.aif_name;
		intercon.source = dai->driver->capture.stream_name;
		dev_dbg(dai->dev, "%s src %s sink %s\n",
			__func__, intercon.source, intercon.sink);
		snd_soc_dapm_add_routes(dapm, &intercon, 1);
	}
	return 0;
}

static int msm_dai_stub_dai_probe(struct snd_soc_dai *dai)
{
	return msm_dai_stub_add_route(dai);
}

static int msm_dai_stub_dai_remove(struct snd_soc_dai *dai)
{
	pr_debug("%s:\n", __func__);
	return 0;
}

static struct snd_soc_dai_driver msm_dai_stub_dai_rx = {
	.playback = {
		.stream_name = "Stub Playback",
		.aif_name = "STUB_RX",
		.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
			SNDRV_PCM_RATE_16000,
		.formats = SNDRV_PCM_FMTBIT_S16_LE,
		.channels_min = 1,
		.channels_max = 2,
		.rate_min = 8000,
		.rate_max = 48000,
	},
	.ops = &msm_dai_stub_ops,
	.probe = &msm_dai_stub_dai_probe,
	.remove = &msm_dai_stub_dai_remove,
};

static struct snd_soc_dai_driver msm_dai_stub_dai_tx[] = {
	{
		.capture = {
			.stream_name = "Stub Capture",
			.aif_name = "STUB_TX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	},
	{
		.capture = {
			.stream_name = "Stub1 Capture",
			.aif_name = "STUB_1_TX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	}
};

static struct snd_soc_dai_driver msm_dai_stub_dtmf_tx_dai = {
	.capture = {
		.stream_name = "DTMF TX",
		.aif_name = "STUB_DTMF_TX",
		.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
			 SNDRV_PCM_RATE_16000,
		.formats = SNDRV_PCM_FMTBIT_S16_LE,
		.channels_min = 1,
		.channels_max = 2,
		.rate_min = 8000,
		.rate_max = 48000,
	},
	.ops = &msm_dai_stub_ops,
	.probe = &msm_dai_stub_dai_probe,
	.remove = &msm_dai_stub_dai_remove,
};

static struct snd_soc_dai_driver msm_dai_stub_host_capture_tx_dai[] = {
	{
		.capture = {
			.stream_name = "CS-VOICE HOST RX CAPTURE",
			.aif_name = "STUB_HOST_RX_CAPTURE_TX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	},
	{
		.capture = {
			.stream_name = "CS-VOICE HOST TX CAPTURE",
			.aif_name = "STUB_HOST_TX_CAPTURE_TX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	},
};

static struct snd_soc_dai_driver msm_dai_stub_host_playback_rx_dai[] = {
	{
		.playback = {
			.stream_name = "CS-VOICE HOST RX PLAYBACK",
			.aif_name = "STUB_HOST_RX_PLAYBACK_RX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				 SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	},
	{
		.playback = {
			.stream_name = "CS-VOICE HOST TX PLAYBACK",
			.aif_name = "STUB_HOST_TX_PLAYBACK_RX",
			.rates = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_8000 |
				 SNDRV_PCM_RATE_16000,
			.formats = SNDRV_PCM_FMTBIT_S16_LE,
			.channels_min = 1,
			.channels_max = 2,
			.rate_min = 8000,
			.rate_max = 48000,
		},
		.ops = &msm_dai_stub_ops,
		.probe = &msm_dai_stub_dai_probe,
		.remove = &msm_dai_stub_dai_remove,
	},
};

static const struct snd_soc_component_driver msm_dai_stub_component = {
	.name		= "msm-dai-stub-dev",
};

static int msm_dai_stub_dev_probe(struct platform_device *pdev)
{
	int rc, id = -1;
	const char *stub_dev_id = "qcom,msm-dai-stub-dev-id";

	rc = of_property_read_u32(pdev->dev.of_node, stub_dev_id, &id);
	if (rc) {
		dev_err(&pdev->dev,
			"%s: missing %s in dt node\n", __func__, stub_dev_id);
		return rc;
	}

	pdev->id = id;

	pr_debug("%s: dev name %s, id:%d\n", __func__,
		 dev_name(&pdev->dev), pdev->id);

	switch (id) {
	case STUB_RX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component, &msm_dai_stub_dai_rx, 1);
		break;
	case STUB_TX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component, &msm_dai_stub_dai_tx[0], 1);
		break;
	case STUB_1_TX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component, &msm_dai_stub_dai_tx[1], 1);
		break;
	case STUB_DTMF_TX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component,
			&msm_dai_stub_dtmf_tx_dai, 1);
		break;
	case STUB_HOST_RX_CAPTURE_TX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component,
			&msm_dai_stub_host_capture_tx_dai[0], 1);
		break;
	case STUB_HOST_TX_CAPTURE_TX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component,
			&msm_dai_stub_host_capture_tx_dai[1], 1);
		break;
	case STUB_HOST_RX_PLAYBACK_RX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component,
			&msm_dai_stub_host_playback_rx_dai[0], 1);
		break;
	case STUB_HOST_TX_PLAYBACK_RX:
		rc = snd_soc_register_component(&pdev->dev,
			&msm_dai_stub_component,
			&msm_dai_stub_host_playback_rx_dai[1], 1);
		break;
	}

	return rc;
}

static int msm_dai_stub_dev_remove(struct platform_device *pdev)
{
	snd_soc_unregister_component(&pdev->dev);
	return 0;
}

static const struct of_device_id msm_dai_stub_dev_dt_match[] = {
	{ .compatible = "qcom,msm-dai-stub-dev", },
	{ }
};
MODULE_DEVICE_TABLE(of, msm_dai_stub_dev_dt_match);

static struct platform_driver msm_dai_stub_dev = {
	.probe  = msm_dai_stub_dev_probe,
	.remove = msm_dai_stub_dev_remove,
	.driver = {
		.name = "msm-dai-stub-dev",
		.owner = THIS_MODULE,
		.of_match_table = msm_dai_stub_dev_dt_match,
	},
};

static int msm_dai_stub_probe(struct platform_device *pdev)
{
	int rc = 0;

	dev_dbg(&pdev->dev, "dev name %s\n", dev_name(&pdev->dev));

	rc = of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev);
	if (rc) {
		dev_err(&pdev->dev, "%s: failed to add child nodes, rc=%d\n",
			__func__, rc);
	} else
		dev_dbg(&pdev->dev, "%s: added child node\n", __func__);

	return rc;
}

static int msm_dai_stub_remove(struct platform_device *pdev)
{
	pr_debug("%s:\n", __func__);

	return 0;
}

static const struct of_device_id msm_dai_stub_dt_match[] = {
	{.compatible = "qcom,msm-dai-stub"},
	{}
};

MODULE_DEVICE_TABLE(of, msm_dai_stub_dt_match);


static struct platform_driver msm_dai_stub_driver = {
	.probe  = msm_dai_stub_probe,
	.remove = msm_dai_stub_remove,
	.driver = {
		.name = "msm-dai-stub",
		.owner = THIS_MODULE,
		.of_match_table = msm_dai_stub_dt_match,
	},
};

static int __init msm_dai_stub_init(void)
{
	int rc = 0;

	pr_debug("%s:\n", __func__);

	rc = platform_driver_register(&msm_dai_stub_driver);
	if (rc) {
		pr_err("%s: fail to register dai q6 driver", __func__);
		goto fail;
	}

	rc = platform_driver_register(&msm_dai_stub_dev);
	if (rc) {
		pr_err("%s: fail to register dai q6 dev driver", __func__);
		goto dai_stub_dev_fail;
	}
	return rc;

dai_stub_dev_fail:
	platform_driver_unregister(&msm_dai_stub_driver);
fail:
	return rc;
}
module_init(msm_dai_stub_init);

static void __exit msm_dai_stub_exit(void)
{
	pr_debug("%s:\n", __func__);

	platform_driver_unregister(&msm_dai_stub_dev);
	platform_driver_unregister(&msm_dai_stub_driver);
}
module_exit(msm_dai_stub_exit);

/* Module information */
MODULE_DESCRIPTION("MSM Stub DSP DAI driver");
MODULE_LICENSE("GPL v2");