Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions sound/soc/intel/boards/sof_sdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,27 +409,23 @@ static int create_codec_dai_name(struct device *dev,
return 0;
}

static int set_codec_init_func(const struct snd_soc_acpi_link_adr *link,
static int set_dailink_init_func(const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links,
bool playback)
{
int i;

for (i = 0; i < link->num_adr; i++) {
unsigned int part_id;
int codec_index;
unsigned int part_id;
int codec_index;

ghost Mar 30, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I don't think this change is correct.
We don't want to make the assumption that if there are more than one devices on the link then they are all RT1308. That's not good, it means we cannot support hybrid configurations.


part_id = SDW_PART_ID(link->adr_d[i].adr);
codec_index = find_codec_info_part(part_id);
part_id = SDW_PART_ID(link->adr_d[0].adr);
codec_index = find_codec_info_part(part_id);

if (codec_index < 0)
return codec_index;
if (codec_index < 0)
return codec_index;

if (codec_info_list[codec_index].init)
codec_info_list[codec_index].init(link, dai_links,

ghost Mar 30, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the process well enough, but this raises an alarm for me. Are we really sure that it's always enough to just call .init() once for the first codec iinfo? That we'll never have mixed codecs or a codec, that needs certain initialisation performed for each instance? Individual codec .init() implementations might need to check whether an instance has already initialised on this card, but can we really skip this completely globally?

ghost Mar 30, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao I guess this is ok as this init() is specific to the sof-sdw driver and you only do dailink specific actions, but it's worth a check still. I.e. is this future proof to not all init for all codecs on the dailink?

ghost Mar 30, 2020

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand the process well enough, but this raises an alarm for me. Are we really sure that it's always enough to just call .init() once for the first codec iinfo? That we'll never have mixed codecs or a codec, that needs certain initialisation performed for each instance? Individual codec .init() implementations might need to check whether an instance has already initialised on this card, but can we really skip this completely globally?

@lyakh If we look at the "codec init" functions, we can see that they are used to set dailink init function. So it is fine to called them once per dailink. We don't support mixed codecs in a dailink for now. If we want to do that, we will do more modification than this PR. Current code doesn't allow us to have different init function for the same codec either. So, I think the PR is safe for current code.

@bardliao I guess this is ok as this init() is specific to the sof-sdw driver and you only do dailink specific actions, but it's worth a check still. I.e. is this future proof to not all init for all codecs on the dailink?

@kv2019i Yes, I checked all the init functions for supported codecs. None of them need to be called more than once per dailink. In fact, sof_sdw_rt1308_init() was the only one which will be called more than one time per dailink before this change.

&codec_info_list[codec_index],
playback);
}
if (codec_info_list[codec_index].init)
codec_info_list[codec_index].init(link, dai_links,
&codec_info_list[codec_index],
playback);

return 0;
}
Expand Down Expand Up @@ -622,8 +618,8 @@ static int create_sdw_dailink(struct device *dev, int *be_index,
codecs, codec_num,
NULL, &sdw_ops);

ret = set_codec_init_func(link, dai_links + (*be_index)++,
playback);
ret = set_dailink_init_func(link, dai_links + (*be_index)++,
playback);
if (ret < 0) {
dev_err(dev, "failed to init codec %d", codec_index);
return ret;
Expand Down
11 changes: 5 additions & 6 deletions sound/soc/intel/boards/sof_sdw_rt1308.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,17 @@ int sof_sdw_rt1308_init(const struct snd_soc_acpi_link_adr *link,
struct sof_sdw_codec_info *info,
bool playback)
{
info->amp_num++;
info->amp_num += dai_links->num_codecs;
if (info->amp_num == 1)
dai_links->init = first_spk_init;

ghost Mar 30, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao How about the logic below checking "info->amp_num == 1". Is this still valid in case amp_num is incremented possibly by many amps in one call?

ghost Mar 30, 2020

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @kv2019i . This code assumes amp_num ==1 or ==2, I don't understand this at all. Also num_codecs can include other devices, not just the amps, so the logic is not future proof?


if (info->amp_num == 2) {
/*
* if two 1308s are in one dai link, the init function
* in this dai link will be first set for the first speaker,
* and it should be reset to initialize all speakers when
* the second speaker is found.
* if dai_links->num_codecs = 2, it implies that 2 rt1308s
* are in the same dai link. Otherwise they will be in 2
* dai links.
*/
if (dai_links->init)
if (dai_links->num_codecs == 2)

ghost Mar 30, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bardliao I think the check would be a lot more intuitive if you say if (dai_lisnk->num_codecs == info->amp_num)

ghost Mar 30, 2020 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but that's a wrong assumption! We should NOT assume num_codecs == num_amps.

ghost Mar 31, 2020

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm yes you are right @plbossart . It makes sense only if there is only one set of amps.

dai_links->init = all_spk_init;
else
dai_links->init = second_spk_init;
Expand Down