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
10 changes: 10 additions & 0 deletions include/sound/sof.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ struct snd_sof_pdata {
/* parent device */
struct device *dev;

/*
* notification callback used if the hardware initialization
* can take time or is handled in a workqueue. This callback
* can be used by the parent device to e.g. enable runtime_pm
* or limit functionality until all low-level inits are
* complete. The device argument refers to the parent, not the
* "sof-audio" device.
*/
void (*sof_probe_complete)(struct device *dev);

/* descriptor */
const struct sof_dev_desc *desc;

Expand Down
9 changes: 8 additions & 1 deletion sound/soc/sof/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ static int sof_probe(struct platform_device *pdev)
INIT_LIST_HEAD(&sdev->widget_list);
INIT_LIST_HEAD(&sdev->dai_list);
INIT_LIST_HEAD(&sdev->route_list);
dev_set_drvdata(&pdev->dev, sdev);
spin_lock_init(&sdev->ipc_lock);
spin_lock_init(&sdev->hw_lock);

Expand Down Expand Up @@ -388,6 +387,14 @@ static int sof_probe(struct platform_device *pdev)
dev_dbg(sdev->dev, "created machine %s\n",
dev_name(&plat_data->pdev_mach->dev));

/*
* so far so good, set the drvdata which can be used to test probe
* success. Also let the parent device know the probe completed
*/
dev_set_drvdata(&pdev->dev, sdev);
if (plat_data->sof_probe_complete)
plat_data->sof_probe_complete(sdev->parent);

return 0;

comp_err:
Expand Down
8 changes: 8 additions & 0 deletions sound/soc/sof/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,10 @@ static int sof_resume(struct device *dev, bool runtime_resume)
struct snd_sof_dev *sdev = dev_get_drvdata(&priv->pdev_pcm->dev);
int ret = 0;

/* do nothing if the probe failed somehow */
if (!sdev)
return 0;

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.

@plbossart Thanks, yes this covers all our discussions on this topic but I have a question here. If sdev is in fact NULL, should we return 0 or an error? 0 indicates that suspend/resume was successful. But what we're doing here is avoiding a suspend/resume in this case.


/* do nothing if dsp resume callbacks are not set */
if (!sof_ops(sdev)->resume || !sof_ops(sdev)->runtime_resume)
return 0;
Expand Down Expand Up @@ -304,6 +308,10 @@ static int sof_suspend(struct device *dev, bool runtime_suspend)
struct snd_sof_dev *sdev = dev_get_drvdata(&priv->pdev_pcm->dev);
int ret = 0;

/* do nothing if the probe failed somehow */
if (!sdev)
return 0;

/* do nothing if dsp suspend callback is not set */
if (!sof_ops(sdev)->suspend)
return 0;
Expand Down
34 changes: 21 additions & 13 deletions sound/soc/sof/sof-pci-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ static const struct dev_pm_ops sof_pci_pm = {
NULL)
};

static void sof_pci_probe_complete(struct device *dev)
{
dev_dbg(dev, "Completing SOF PCI probe");

/* allow runtime_pm */
pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(dev);

/*
* runtime pm for pci device is "forbidden" by default.
* so call pm_runtime_allow() to enable it.
*/
pm_runtime_allow(dev);

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.

@plbossart I am wondering what would happen if the dsp probe failed in sof_probe() failed and we never enabled PM?
What would be the impact of calling pm_runtime_get_noresume() in sof_pci_remove()?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@ranj063 you tell me :-)
I tested this without any firmware files, and didn't see any impact. I could add/remove modules, fail the probe and loop forever.


/* follow recommendation in pci-driver.c to decrement usage counter */
pm_runtime_put_noidle(dev);
}

static int sof_pci_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
Expand Down Expand Up @@ -217,26 +235,16 @@ static int sof_pci_probe(struct pci_dev *pci,
sof_pdata->dev = &pci->dev;
sof_pdata->platform = "sof-audio";

/* set callback to enable runtime_pm */
sof_pdata->sof_probe_complete = sof_pci_probe_complete;

/* register sof-audio platform driver */
ret = sof_create_platform_device(priv);
if (ret) {
dev_err(dev, "error: failed to create platform device!\n");
goto release_regions;
}

/* allow runtime_pm */
pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
pm_runtime_use_autosuspend(dev);

/*
* runtime pm for pci device is "forbidden" by default.
* so call pm_runtime_allow() to enable it.
*/
pm_runtime_allow(dev);

/* follow recommendation in pci-driver.c to decrement usage counter */
pm_runtime_put_noidle(dev);

return ret;

release_regions:
Expand Down