Repository navigation
SoundWire: fix pm_runtime on host and codec sides - #4345
Conversation
|
SOFCI TEST |
1 similar comment
|
SOFCI TEST |
|
@bardliao @RanderWang @ranj063 @ujfalusi can you take a look. |
|
@plbossart IMHO, the main issue is that the codec is not attached in startup. The runtime_pm of master devices are already enabled by sdw_master_device_add which will be called in probe. |
We don't control when the startup() happens @bardliao. While I agree with you that in the nominal case the sdw-master-N device is likely active in the probe, the parent isn't, and when we enable pm_runtime in the parent we should make sure the sdw-master remains active. It's not going to solve everything but it's a first step to make sure the states are consistent.
that's a different problem IMHO. The card should not be used until all codecs are attached, I agree with that, but I don't have a solution. we would need to add a deferred probe or something. |
|
@bardliao @shumingfan can you take a look at the last patches? I think my interpretation of pm_runtime is mostly correct but the codecs complain with things I don't understand Never mind, I forgot to restore the cache status in io_init(). Too much multitasking, works for me now. |
3d4d390 to
19a7c73
Compare
As far as I know, the only device model that ever met the issue is ADLP_RVP_SDW_IPC4ZPH. I didn't reproduce the issue with this PR so far. But I met |
Thanks for testing @bardliao. I don't think this can be qualified as success if we get this 'IO error'. I am not sure what happens here, I really don't understand how the jack is handled. @shumingfan can you help with guidance/comments on what could cause this error? BTW the pm-runtime errors are reported by an end-users on a Dell SDCA device, see issue #4353 |
05840dc
|
@bardliao the error -16 means -EBUSY, I suspect this happens while we try to read from a cache-only regmap, but I can't figure out how this can happen. I added a bunch of traces, can you retry? |
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>
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>
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>
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>
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>
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>
…nded' 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>
32dc825 to
741e069
Compare
|
@charleskeepax @rfvirgil FYI, not sure if this applies you cs42l42 and other codec drivers you are working on. |
| return ret; | ||
|
|
||
| /* set autosuspend parameters */ | ||
| pm_runtime_set_autosuspend_delay(dev, 3000); |
There was a problem hiding this comment.
in SOF driver we set it to SND_SOF_SUSPEND_DELAY_MS = 2000. I don't know why it is 3000 ? And 3000 is used for all sdw codec can we use a macro definition to replace it ?
|
This is what we were talking about a few weeks ago on the sync call. The cs42l43 driver does not call snd_soc_register_component until after the device has enumerated, although that is hard to achieve unless you are an MFD driver. The cs35l56 driver is waiting in component_probe for the device to enumerate, effectively blocking card registration until the device has enumerated. cs42l42 does probably still have the problem, as we haven't got around to fixing that one yet. I can't say I totally follow all the pm_runtime gymnastics you guys are doing to work around the issues, but it would probably be a lot simpler and less prone to introducing new issues to simply delay registration of the card as we are doing. In general having a situation where user-space can talk to hardware that might not be available yet is just going to be a bottomless hole of issues. |
|
I am not sure how your solution works @charleskeepax The card will be as a result of the SOF driver creating a platform device. If the required components are not present, the deferred probe mechanism will kick in. But the catch is that the probe will be retried only when other devices are registered (or drivers probed?). Registering an ASoC component later does not guarantee that the probe would be triggered. That's a generic problem with deferred probes, it does not work in case of async registration of resources...What we would need is to register this component but explicitly force the deferred probe queue to be re-evaluated. Unfortunately GregKH didn't want my one-line solution in https://lore.kernel.org/alsa-devel/20210817190057.255264-1-pierre-louis.bossart@linux.intel.com/ |
I am assuming here you refer to the cs42l43 solution not the cs35l56, please correct me if that is wrong. Although I think the cs35l56 solution would probably work better for you guys since you really need an MFD for the cs42l43 solution, since you really need 2 struct devices.
Sort of, probing of the ASoC components is a kinda weird 2 stage affair in its own right, the struct device for the card is a result of the platform device yes, but the sound card itself is created separately by ASoC. So the CODEC driver not being present will not actually cause the machine driver to probe defer. That ASoC level stuff just runs on each new component registration (snd_soc_register_component/card) and when all the bits of the card are ready it creates it, so the driver model is irrelevant there. At least I thought that was how it worked got me doubting myself now.... no ok that is non-sense, apologies there. The machine driver does probe defer, that is why you need the MFD for this solution to work. The deferred probes retrigger whenever a new driver binds, in the case of cs42l43 it is an MFD and we dont register the CODEC driver until the device has enumerated (mfd_add_devices) so when that driver is added that is what causes the probe defer list to be revisited. |
Right, but the probe defer list is only revisited when a new driver becoming attached, and not on the ASoC component being registered. We are in agreement, your solution does not work for 'generic' codecs which don't register a new device :-) |
|
Yeah agreed there for the cs42l43 solution, but the cs35l56 solution of waiting for the enumeration in component_probe should work for non-MFD devices. |
I don't know what you are referring to for cs35l56, I don't see the component_probe being used. +static int cs35l56_sdw_probe(struct sdw_slave *peripheral, const struct sdw_device_id *id)
+{
+ struct device *dev = &peripheral->dev;
+ struct cs35l56_private *cs35l56;
+ int ret;
+
+ cs35l56 = devm_kzalloc(dev, sizeof(*cs35l56), GFP_KERNEL);
+ if (!cs35l56)
+ return -ENOMEM;
+
+ cs35l56->dev = dev;
+ cs35l56->sdw_peripheral = peripheral;
+ INIT_WORK(&cs35l56->sdw_irq_work, cs35l56_sdw_irq_work);
+
+ dev_set_drvdata(dev, cs35l56);
+
+ cs35l56->regmap = devm_regmap_init(dev, &cs35l56_regmap_bus_sdw,
+ peripheral, &cs35l56_regmap_sdw);
+ if (IS_ERR(cs35l56->regmap)) {
+ ret = PTR_ERR(cs35l56->regmap);
+ return dev_err_probe(dev, ret, "Failed to allocate register map\n");
+ }
+
+ /* Start in cache-only until device is enumerated */
+ regcache_cache_only(cs35l56->regmap, true);
+
+ ret = cs35l56_common_probe(cs35l56);
+ if (ret != 0)
+ return ret;
+
+ return 0;
+} |
|
On 06/06/2023 16:14, Pierre-Louis Bossart wrote:
Yeah agreed there for the cs42l43 solution, but the cs35l56 solution
of waiting for the enumeration in component_probe should work for
non-MFD devices.
I don't know what you are referring to for cs35l56, I don't see the
component_probe being used.
In cs35l56 we used your suggestion to solve the problem by waiting in
component_probe() for initialization to complete.
Except that instead of waiting on the SoundWire initialization_complete
as you suggested, we wait on our internal completion that tells us we
have also done all our hardware init.
|
|
Right, but this PR only tries to solve the problem of when to enable pm_runtime. That's different to the issue of waiting for the device to be initialized. If pm_runtime is enabled when the hardware is attached, we do see error cases, and there is also the issue of the -EACCESS failing silently. What this PR does is keep the device in 'suspended' mode until it's attached/initialized, and if you try to use the device before its initialized, the resume will wait for the attachment/initialization. |
|
Certainly yes you don't want to have cases where you have the device fully probed and the pm_runtime is not yet enabled. You would probably need to move the pm_runtime_enable either way, I haven't looked at the drivers in question in detail to be sure though. You could treat this as solving the pm_runtime issue and consider waiting for the device to initialise separately. |
bardliao
left a comment
There was a problem hiding this comment.
Thanks @plbossart It looks good to me.
|
alright, time to merge this PR. That will give us 2-3 weeks of actual testing before it's send upstream. |
No description provided.