Skip to content

Commit

Permalink
ASoC: intel: sof_sdw: Only pass dai_link pointer around
Browse files Browse the repository at this point in the history
Rather than passing around a pointer to the dai_link array and an index
into this array, simply pass a pointer to the current dai_link.

Signed-off-by: Charles Keepax <[email protected]>
  • Loading branch information
charleskeepax committed Jun 20, 2023
1 parent 5d925d0 commit fd25bdf
Showing 1 changed file with 26 additions and 35 deletions.
61 changes: 26 additions & 35 deletions sound/soc/intel/boards/sof_sdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,8 +1374,8 @@ static void set_dailink_map(struct snd_soc_dai_link_codec_ch_map *sdw_codec_ch_m

static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"};

static int create_sdw_dailink(struct snd_soc_card *card, int *link_index,
struct snd_soc_dai_link *dai_links, int sdw_be_num,
static int create_sdw_dailink(struct snd_soc_card *card,
struct snd_soc_dai_link **dai_links,
const struct snd_soc_acpi_link_adr *adr_link,
struct snd_soc_codec_conf **codec_conf,
int *be_id,
Expand Down Expand Up @@ -1496,31 +1496,21 @@ static int create_sdw_dailink(struct snd_soc_card *card, int *link_index,
cpus[k].dai_name = cpu_name;
}

/*
* We create sdw dai links at first stage, so link index should
* not be larger than sdw_be_num
*/
if (*link_index >= sdw_be_num) {
dev_err(dev, "invalid dai link index %d", *link_index);
return -EINVAL;
}

playback = (stream == SNDRV_PCM_STREAM_PLAYBACK);
capture = (stream == SNDRV_PCM_STREAM_CAPTURE);

init_dai_link(dev, dai_links + *link_index, be_id, name,
playback, capture, cpus, cpu_dai_num, codecs, codec_num,
NULL, &sdw_ops);
init_dai_link(dev, *dai_links, be_id, name, playback, capture,
cpus, cpu_dai_num, codecs, codec_num, NULL, &sdw_ops);

/*
* SoundWire DAILINKs use 'stream' functions and Bank Switch operations
* based on wait_for_completion(), tag them as 'nonatomic'.
*/
dai_links[*link_index].nonatomic = true;
(*dai_links)->nonatomic = true;

set_dailink_map(sdw_codec_ch_maps, codec_num, cpu_dai_num);
dai_links[*link_index].codec_ch_maps = sdw_codec_ch_maps;
ret = set_codec_init_func(card, adr_link, dai_links + (*link_index)++,
(*dai_links)->codec_ch_maps = sdw_codec_ch_maps;
ret = set_codec_init_func(card, adr_link, (*dai_links)++,
playback, group_id, adr_index, dai_index);
if (ret < 0) {
dev_err(dev, "failed to init codec %d", codec_index);
Expand Down Expand Up @@ -1549,7 +1539,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
bool group_generated[SDW_MAX_GROUPS] = { };
int ssp_codec_index, ssp_mask;
struct snd_soc_dai_link *dai_links;
int num_links, link_index = 0;
int num_links;
char *name, *cpu_dai_name, *codec_name, *codec_dai_name;
int i, j, be_id = 0;
int codec_index;
Expand Down Expand Up @@ -1603,6 +1593,8 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
if (!codec_conf)
return -ENOMEM;

card->dai_link = dai_links;
card->num_links = num_links;
card->codec_conf = codec_conf;
card->num_configs = codec_conf_num;

Expand Down Expand Up @@ -1631,11 +1623,13 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
return codec_index;

for (j = 0; j < codec_info_list[codec_index].dai_num ; j++) {
ret = create_sdw_dailink(card, &link_index, dai_links, sdw_be_num,
adr_link, &codec_conf, &be_id,
&ignore_pch_dmic, append_dai_type, i, j);
ret = create_sdw_dailink(card, &dai_links, adr_link,
&codec_conf, &be_id,
&ignore_pch_dmic,
append_dai_type, i, j);
if (ret < 0) {
dev_err(dev, "failed to create dai link %d", link_index);
dev_err(dev, "failed to create dai link %ld",
dai_links - card->dai_link);
return ret;
}
}
Expand Down Expand Up @@ -1675,18 +1669,18 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
playback = info->dais[0].direction[SNDRV_PCM_STREAM_PLAYBACK];
capture = info->dais[0].direction[SNDRV_PCM_STREAM_CAPTURE];

ret = init_simple_dai_link(dev, dai_links + link_index, &be_id, name,
ret = init_simple_dai_link(dev, dai_links, &be_id, name,
playback, capture, cpu_dai_name,
codec_name, info->dais[0].dai_name,
NULL, info->ops);
if (ret)
return ret;

ret = info->dais[0].init(card, NULL, dai_links + link_index, info, 0);
ret = info->dais[0].init(card, NULL, dai_links, info, 0);
if (ret < 0)
return ret;

link_index++;
dai_links++;
}

DMIC:
Expand All @@ -1697,24 +1691,24 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
goto HDMI;
}

ret = init_simple_dai_link(dev, dai_links + link_index, &be_id, "dmic01",
ret = init_simple_dai_link(dev, dai_links, &be_id, "dmic01",
0, 1, // DMIC only supports capture
"DMIC01 Pin", "dmic-codec", "dmic-hifi",
sof_sdw_dmic_init, NULL);
if (ret)
return ret;

link_index++;
dai_links++;

ret = init_simple_dai_link(dev, dai_links + link_index, &be_id, "dmic16k",
ret = init_simple_dai_link(dev, dai_links, &be_id, "dmic16k",
0, 1, // DMIC only supports capture
"DMIC16k Pin", "dmic-codec", "dmic-hifi",
/* don't call sof_sdw_dmic_init() twice */
NULL, NULL);
if (ret)
return ret;

link_index++;
dai_links++;
}

HDMI:
Expand All @@ -1740,14 +1734,14 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
codec_dai_name = "snd-soc-dummy-dai";
}

ret = init_simple_dai_link(dev, dai_links + link_index, &be_id, name,
ret = init_simple_dai_link(dev, dai_links, &be_id, name,
1, 0, // HDMI only supports playback
cpu_dai_name, codec_name, codec_dai_name,
sof_sdw_hdmi_init, NULL);
if (ret)
return ret;

link_index++;
dai_links++;
}

if (sof_sdw_quirk & SOF_SSP_BT_OFFLOAD_PRESENT) {
Expand All @@ -1762,16 +1756,13 @@ static int sof_card_dai_links_create(struct snd_soc_card *card)
if (!cpu_dai_name)
return -ENOMEM;

ret = init_simple_dai_link(dev, dai_links + link_index, &be_id, name,
ret = init_simple_dai_link(dev, dai_links, &be_id, name,
1, 1, cpu_dai_name, "snd-soc-dummy",
"snd-soc-dummy-dai", NULL, NULL);
if (ret)
return ret;
}

card->dai_link = dai_links;
card->num_links = num_links;

return 0;
}

Expand Down

0 comments on commit fd25bdf

Please sign in to comment.