Skip to content

Commit 34b7f81

Browse files
committed
ASoC: max98373-sdw: enable pm_runtime in probe, keep status as 'suspended'
This patch suggests enabling pm_runtime during the probe, but marking the device as 'active' only after it is enumerated. That will force a dependency between the card and the codec, pm_runtime_get_sync() will have to wait for the codec device to resume and hence implicitly wait for the enumeration/initialization to be completed. In the nominal case where the codec device is already active the get_sync() would only perform a ref-count increase. The changes are directly inspired by RT711 and RT711-sdca changes. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
1 parent 696a709 commit 34b7f81

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

‎sound/soc/codecs/max98373-sdw.c‎

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -366,22 +366,12 @@ static int max98373_io_init(struct sdw_slave *slave)
366366
regcache_cache_bypass(max98373->regmap, true);
367367

368368
/*
369-
* PM runtime is only enabled when a Slave reports as Attached
369+
* PM runtime status is marked as 'active' only when a Slave reports as Attached
370370
*/
371-
if (!max98373->first_hw_init) {
372-
/* set autosuspend parameters */
373-
pm_runtime_set_autosuspend_delay(dev, 3000);
374-
pm_runtime_use_autosuspend(dev);
375-
371+
if (!max98373->first_hw_init)
376372
/* update count of parent 'active' children */
377373
pm_runtime_set_active(dev);
378374

379-
/* make sure the device does not suspend immediately */
380-
pm_runtime_mark_last_busy(dev);
381-
382-
pm_runtime_enable(dev);
383-
}
384-
385375
pm_runtime_get_noresume(dev);
386376

387377
/* Software Reset */
@@ -774,10 +764,27 @@ static int max98373_init(struct sdw_slave *slave, struct regmap *regmap)
774764
ret = devm_snd_soc_register_component(dev, &soc_codec_dev_max98373_sdw,
775765
max98373_sdw_dai,
776766
ARRAY_SIZE(max98373_sdw_dai));
777-
if (ret < 0)
767+
if (ret < 0) {
778768
dev_err(dev, "Failed to register codec: %d\n", ret);
769+
return ret;
770+
}
779771

780-
return ret;
772+
/* set autosuspend parameters */
773+
pm_runtime_set_autosuspend_delay(dev, 3000);
774+
pm_runtime_use_autosuspend(dev);
775+
776+
/* make sure the device does not suspend immediately */
777+
pm_runtime_mark_last_busy(dev);
778+
779+
pm_runtime_enable(dev);
780+
781+
/* important note: the device is NOT tagged as 'active' and will remain
782+
* 'suspended' until the hardware is enumerated/initialized. This is required
783+
* to make sure the ASoC framework use of pm_runtime_get_sync() does not silently
784+
* fail with -EACCESS because of race conditions between card creation and enumeration
785+
*/
786+
787+
return 0;
781788
}
782789

783790
static int max98373_update_status(struct sdw_slave *slave,
@@ -835,10 +842,7 @@ static int max98373_sdw_probe(struct sdw_slave *slave,
835842

836843
static int max98373_sdw_remove(struct sdw_slave *slave)
837844
{
838-
struct max98373_priv *max98373 = dev_get_drvdata(&slave->dev);
839-
840-
if (max98373->first_hw_init)
841-
pm_runtime_disable(&slave->dev);
845+
pm_runtime_disable(&slave->dev);
842846

843847
return 0;
844848
}

0 commit comments

Comments
 (0)