Repository navigation
ASoC:SOF:pm fix DAI config during resume #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2161,6 +2161,12 @@ static int sof_link_hda_process(struct snd_sof_dev *sdev, | |
|
|
||
| config->hda.link_dma_ch = slot; | ||
|
|
||
| /* Set the DAI config here since both DAI name and direction must | ||
| * be matched, this is important for playback and capture with the | ||
| * same DAI name. | ||
| */ | ||
| dai->dai_config = kmemdup(config, size, GFP_KERNEL); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, could you add a comment for it ? I know you don't call sof_set_dai_config, but you need to add the comment "set config for the DAI with name and direction matched". Or you could add other comments to emphasize the job of sof_set_dai_config is done at here
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always check for memory alloc issues!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no memory leak here now, previous may cause memory leak. The problem is like:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I talked about memory alloc and sorry mate but this can fail. you need to test all memory allocation. No discussion allowed on this topic. Also I am not clear about your change. We have 2 routines which do something similar: static int sof_link_hda_process(struct snd_sof_dev *sdev,
struct snd_soc_dai_link *link,
struct sof_ipc_dai_config *config,
int slot,
int direction)
{
struct sof_ipc_reply reply;
u32 size = sizeof(*config);
struct snd_sof_dai *dai;
int found = 0;
int ret;
/* for hda link, playback and capture are supported by different
* dai in FW. Here get the dai_index of each dai and send config
* to FW. In FW, each dai sets config by dai_index
*/
list_for_each_entry(dai, &sdev->dai_list, list) {
if (!dai->name)
continue;
if (strcmp(link->name, dai->name) == 0 &&
dai->comp_dai.direction == direction) {
config->dai_index = dai->comp_dai.dai_index;
found = 1;
break;
}
}and /* set config for all DAI's with name matching the link name */
static int sof_set_dai_config(struct snd_sof_dev *sdev, u32 size,
struct snd_soc_dai_link *link,
struct sof_ipc_dai_config *config)
{
struct snd_sof_dai *dai;
list_for_each_entry(dai, &sdev->dai_list, list) {
if (!dai->name)
continue;
if (strcmp(link->name, dai->name) == 0) {
dai->dai_config = kmemdup(config, size, GFP_KERNEL);
if (!dai->dai_config)
return -ENOMEM;
}
}
return 0;
}It seems to me we have two routines doing the same thing and that if the direction needs to be used it could be factored in with a boolean flag. I don't like copy/paste code with differences, it's a sure way to write spaghetti code.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, got it. will add check if alloc fails. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @plbossart I discussed with @ranj063, one issue in our restore process is: each dai link is restored by each dai component, but there are two dai components(playback and capture) in one dai link. This makes one dai_link is restored two times not one for I2S. I will refine this algorithm. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but for HDA, this algorithm is correct
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now only dai link with type SSP and DMIC call sof_set_dai_config and use dai name to find the dai. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, playback/capture in SSP have the same dai name |
||
|
|
||
| /* send message to DSP */ | ||
| ret = sof_ipc_tx_message(sdev->ipc, | ||
| config->hdr.cmd, config, size, &reply, | ||
|
|
@@ -2250,18 +2256,6 @@ static int sof_link_hda_load(struct snd_soc_component *scomp, int index, | |
| } | ||
| } | ||
|
|
||
| /* set config for all DAI's with name matching the link name */ | ||
| ret = sof_set_dai_config(sdev, size, link, config); | ||
| if (ret < 0) { | ||
| if (link->dpcm_playback) | ||
| dev_err(sdev->dev, "error: failed to save DAI config for playback HDA%d\n", | ||
| config->dai_index); | ||
|
|
||
| if (link->dpcm_capture) | ||
| dev_err(sdev->dev, "error: failed to save DAI config for capture HDA%d\n", | ||
| config->dai_index); | ||
| } | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am lost as to why this is removed? doesn't that function do precisely what you wanted in the first place?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As state before, the HDA dai need match both name and direction, sof_set_dai_config is a common API which only check the name. So the dai config setting part is move into the sof_link_hda_process, where the name and direction both checked.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please look into extending it to cover direction then. No need for duplication of code.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, it is OK to add direction check in sof_set_dai_config, and it will also effect sof_link_ssp_load and sof_link_dmic_load.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zhuyingjiang you could do some other checks in the function to check the type as well....if type is hda, check name and direction, else just name is enough. make sense?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang what is your opinion? since you write the sof_set_dai_config, how to refine this is the better way? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sof_set_dai_config is implemented by Ranjiani. I have discussed with Ranjiani, we need to refine pipeline restore. Now dai link is restored by dai component. This is wrong because there maybe two dai components, playback and capture, or one (playback or capture) in one dai link, and dai link would be restored two times for I2S. I plan to discard all the sof_set_dai_configs and restoring code in pm, and make clear of dai components and dai links. dai links should be recorded and restored by dai_link_list, not by dai components @zhuyingjiang do you want to do it? Or just close this PR and I will fix it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @RanderWang OK, please go ahead refine your code, please also consider the two dai_index Pierre mentioned. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, I will consider my plan again. I don't want to make a aggressive change without great improvement |
||
| return ret; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out what the comment means. You cannot match the DAI direction for playback and capture, the two parts of the sentence are logically opposite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean if the playback and capture have the same DAI name, we need both check the name and the direction to find the right dai we need, and thus set the dai config.