Skip to content

Commit 1bd65de

Browse files
Sugar Zhangrkhuangtao
authored andcommitted
ASoC: rockchip: multi_dais: fixup channel min/max
This patch limit the channel min/max according channel mapping. Change-Id: Ia66c276e41d1c6b6f8c78c1c8db3c9087b8c9ca8 Signed-off-by: Sugar Zhang <sugar.zhang@rock-chips.com>
1 parent eac8245 commit 1bd65de

1 file changed

Lines changed: 66 additions & 28 deletions

File tree

sound/soc/rockchip/rockchip_multi_dais.c

Lines changed: 66 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -163,33 +163,6 @@ static const struct snd_soc_dai_ops rockchip_mdais_dai_ops = {
163163
.trigger = rockchip_mdais_trigger,
164164
};
165165

166-
static struct snd_soc_dai_driver rockchip_mdais_dai = {
167-
.probe = rockchip_mdais_dai_probe,
168-
.playback = {
169-
.stream_name = "Playback",
170-
.channels_min = 2,
171-
.channels_max = 32,
172-
.rates = SNDRV_PCM_RATE_8000_192000,
173-
.formats = (SNDRV_PCM_FMTBIT_S8 |
174-
SNDRV_PCM_FMTBIT_S16_LE |
175-
SNDRV_PCM_FMTBIT_S20_3LE |
176-
SNDRV_PCM_FMTBIT_S24_LE |
177-
SNDRV_PCM_FMTBIT_S32_LE),
178-
},
179-
.capture = {
180-
.stream_name = "Capture",
181-
.channels_min = 2,
182-
.channels_max = 32,
183-
.rates = SNDRV_PCM_RATE_8000_192000,
184-
.formats = (SNDRV_PCM_FMTBIT_S8 |
185-
SNDRV_PCM_FMTBIT_S16_LE |
186-
SNDRV_PCM_FMTBIT_S20_3LE |
187-
SNDRV_PCM_FMTBIT_S24_LE |
188-
SNDRV_PCM_FMTBIT_S32_LE),
189-
},
190-
.ops = &rockchip_mdais_dai_ops,
191-
};
192-
193166
static const struct snd_soc_component_driver rockchip_mdais_component = {
194167
.name = DAIS_DRV_NAME,
195168
};
@@ -313,17 +286,81 @@ static void mdais_parse_daifmt(struct device_node *node, struct rk_dai *dais,
313286
}
314287
}
315288

289+
static int rockchip_mdais_dai_prepare(struct platform_device *pdev,
290+
struct snd_soc_dai_driver **soc_dai)
291+
{
292+
struct snd_soc_dai_driver rockchip_mdais_dai = {
293+
.probe = rockchip_mdais_dai_probe,
294+
.playback = {
295+
.stream_name = "Playback",
296+
.channels_min = 2,
297+
.channels_max = 32,
298+
.rates = SNDRV_PCM_RATE_8000_192000,
299+
.formats = (SNDRV_PCM_FMTBIT_S8 |
300+
SNDRV_PCM_FMTBIT_S16_LE |
301+
SNDRV_PCM_FMTBIT_S20_3LE |
302+
SNDRV_PCM_FMTBIT_S24_LE |
303+
SNDRV_PCM_FMTBIT_S32_LE),
304+
},
305+
.capture = {
306+
.stream_name = "Capture",
307+
.channels_min = 2,
308+
.channels_max = 32,
309+
.rates = SNDRV_PCM_RATE_8000_192000,
310+
.formats = (SNDRV_PCM_FMTBIT_S8 |
311+
SNDRV_PCM_FMTBIT_S16_LE |
312+
SNDRV_PCM_FMTBIT_S20_3LE |
313+
SNDRV_PCM_FMTBIT_S24_LE |
314+
SNDRV_PCM_FMTBIT_S32_LE),
315+
},
316+
.ops = &rockchip_mdais_dai_ops,
317+
};
318+
319+
*soc_dai = devm_kmemdup(&pdev->dev, &rockchip_mdais_dai,
320+
sizeof(rockchip_mdais_dai), GFP_KERNEL);
321+
if (!(*soc_dai))
322+
return -ENOMEM;
323+
324+
return 0;
325+
}
326+
327+
static void mdais_fixup_dai(struct snd_soc_dai_driver *soc_dai,
328+
struct rk_mdais_dev *mdais)
329+
{
330+
int i, tch, rch;
331+
unsigned int *tx_maps, *rx_maps;
332+
333+
tch = 0;
334+
rch = 0;
335+
tx_maps = mdais->playback_channel_maps;
336+
rx_maps = mdais->capture_channel_maps;
337+
for (i = 0; i < mdais->num_dais; i++) {
338+
tch += tx_maps[i];
339+
rch += rx_maps[i];
340+
}
341+
342+
soc_dai->playback.channels_min = tch;
343+
soc_dai->playback.channels_max = tch;
344+
soc_dai->capture.channels_min = rch;
345+
soc_dai->capture.channels_max = rch;
346+
}
347+
316348
static int rockchip_mdais_probe(struct platform_device *pdev)
317349
{
318350
struct device_node *np = pdev->dev.of_node;
319351
struct platform_device *sub_pdev;
320352
struct rk_mdais_dev *mdais;
321353
struct device_node *node;
354+
struct snd_soc_dai_driver *soc_dai;
322355
struct rk_dai *dais;
323356
unsigned int *map;
324357
int count, mp_count;
325358
int ret = 0, i = 0;
326359

360+
ret = rockchip_mdais_dai_prepare(pdev, &soc_dai);
361+
if (ret < 0)
362+
return ret;
363+
327364
mdais = devm_kzalloc(&pdev->dev, sizeof(*mdais), GFP_KERNEL);
328365
if (!mdais)
329366
return -ENOMEM;
@@ -379,6 +416,7 @@ static int rockchip_mdais_probe(struct platform_device *pdev)
379416
}
380417

381418
mdais_parse_daifmt(np, dais, count);
419+
mdais_fixup_dai(soc_dai, mdais);
382420

383421
mdais->dais = dais;
384422
mdais->dev = &pdev->dev;
@@ -393,7 +431,7 @@ static int rockchip_mdais_probe(struct platform_device *pdev)
393431

394432
ret = devm_snd_soc_register_component(&pdev->dev,
395433
&rockchip_mdais_component,
396-
&rockchip_mdais_dai, 1);
434+
soc_dai, 1);
397435

398436
if (ret) {
399437
dev_err(&pdev->dev, "could not register dai: %d\n", ret);

0 commit comments

Comments
 (0)