Skip to content

Commit 474336c

Browse files
committed
ASoC: sdw_utils: add rt1320 and rt1321 dmic dai in codec_info_list
Add 'rt1320-aif2' dai infos for rt1320 and rt1321 dmic function. Signed-off-by: Derek Fang <derek.fang@realtek.com>
1 parent ab2c7da commit 474336c

2 files changed

Lines changed: 66 additions & 5 deletions

File tree

sound/soc/sdw_utils/soc_sdw_rt_dmic.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,19 @@
99

1010
#include <linux/device.h>
1111
#include <linux/errno.h>
12+
#include <linux/soundwire/sdw_type.h>
1213
#include <sound/soc.h>
1314
#include <sound/soc-acpi.h>
1415
#include <sound/soc_sdw_utils.h>
16+
#include <sound/sdca_function.h>
1517

1618
int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
1719
{
1820
struct snd_soc_card *card = rtd->card;
1921
struct snd_soc_component *component;
22+
struct sdw_slave *sdw_peripheral = NULL;
2023
char *mic_name;
24+
int rt1320_dmic_num = 0, part_id, i;
2125

2226
component = dai->component;
2327

@@ -32,9 +36,44 @@ int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_da
3236
if (!mic_name)
3337
return -ENOMEM;
3438

35-
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
36-
"%s mic:%s", card->components,
37-
mic_name);
39+
/*
40+
* If there is any rt1320/rt1321 DMIC belonging to this card, try to count the `cfg-mics`
41+
* to be used in card->components.
42+
* Note: The rt1320 drivers register the peripheral dev to component->dev, so get the
43+
* sdw_peripheral from component->dev.
44+
*/
45+
if (is_sdw_slave(component->dev))
46+
sdw_peripheral = dev_to_sdw_dev(component->dev);
47+
if (sdw_peripheral &&
48+
(sdw_peripheral->id.part_id == 0x1320 || sdw_peripheral->id.part_id == 0x1321)) {
49+
part_id = sdw_peripheral->id.part_id;
50+
/*
51+
* This rtd init callback is called once, so count the rt1320/rt1321 with SDCA
52+
* function SmartMic type in this card.
53+
*/
54+
for_each_card_components(card, component) {
55+
if (!is_sdw_slave(component->dev))
56+
continue;
57+
sdw_peripheral = dev_to_sdw_dev(component->dev);
58+
if (sdw_peripheral->id.part_id != part_id)
59+
continue;
60+
for (i = 0; i < sdw_peripheral->sdca_data.num_functions; i++) {
61+
if (sdw_peripheral->sdca_data.function[i].type ==
62+
SDCA_FUNCTION_TYPE_SMART_MIC) {
63+
rt1320_dmic_num++;
64+
break;
65+
}
66+
}
67+
}
68+
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
69+
"%s mic:%s cfg-mics:%d", card->components,
70+
mic_name, rt1320_dmic_num);
71+
} else {
72+
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
73+
"%s mic:%s", card->components,
74+
mic_name);
75+
}
76+
3877
if (!card->components)
3978
return -ENOMEM;
4079

sound/soc/sdw_utils/soc_sdw_utils.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ struct asoc_sdw_codec_info codec_info_list[] = {
319319
{
320320
.part_id = 0x1320,
321321
.name_prefix = "rt1320",
322+
.is_amp = true,
322323
.dais = {
323324
{
324325
.direction = {true, false},
@@ -334,12 +335,23 @@ struct asoc_sdw_codec_info codec_info_list[] = {
334335
.widgets = generic_spk_widgets,
335336
.num_widgets = ARRAY_SIZE(generic_spk_widgets),
336337
},
338+
{
339+
.direction = {false, true},
340+
.dai_name = "rt1320-aif2",
341+
.component_name = "rt1320",
342+
.dai_type = SOC_SDW_DAI_TYPE_MIC,
343+
.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
344+
.rtd_init = asoc_sdw_rt_dmic_rtd_init,
345+
.widgets = generic_dmic_widgets,
346+
.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
347+
},
337348
},
338-
.dai_num = 1,
349+
.dai_num = 2,
339350
},
340351
{
341352
.part_id = 0x1321,
342353
.name_prefix = "rt1320",
354+
.is_amp = true,
343355
.dais = {
344356
{
345357
.direction = {true, false},
@@ -355,8 +367,18 @@ struct asoc_sdw_codec_info codec_info_list[] = {
355367
.widgets = generic_spk_widgets,
356368
.num_widgets = ARRAY_SIZE(generic_spk_widgets),
357369
},
370+
{
371+
.direction = {false, true},
372+
.dai_name = "rt1320-aif2",
373+
.component_name = "rt1320",
374+
.dai_type = SOC_SDW_DAI_TYPE_MIC,
375+
.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
376+
.rtd_init = asoc_sdw_rt_dmic_rtd_init,
377+
.widgets = generic_dmic_widgets,
378+
.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
379+
},
358380
},
359-
.dai_num = 1,
381+
.dai_num = 2,
360382
},
361383
{
362384
.part_id = 0x714,

0 commit comments

Comments
 (0)