Skip to content

Commit ba2ebd5

Browse files
claudiubeznearafaeljw
authored andcommitted
driver core: platform: Drop dev_pm_domain_detach() call
On the Renesas RZ/G3S (and other Renesas SoCs, e.g., RZ/G2{L, LC, UL}), clocks are managed through PM domains. These PM domains, registered on behalf of the clock controller driver, are configured with GENPD_FLAG_PM_CLK. In most of the Renesas drivers used by RZ SoCs, the clocks are enabled/disabled using runtime PM APIs. The power domains may also have power_on/power_off support implemented. After the device PM domain is powered off any CPU accesses to these domains leads to system aborts. During probe, devices are attached to the PM domain controlling their clocks and power. Similarly, during removal, devices are detached from the PM domain. The detachment call stack is as follows: device_driver_detach() -> device_release_driver_internal() -> __device_release_driver() -> device_remove() -> platform_remove() -> dev_pm_domain_detach() During driver unbind, after the device is detached from its PM domain, the device_unbind_cleanup() function is called, which subsequently invokes devres_release_all(). This function handles devres resource cleanup. If runtime PM is enabled in driver probe via devm_pm_runtime_enable(), the cleanup process triggers the action or reset function for disabling runtime PM. This function is pm_runtime_disable_action(), which leads to the following call stack of interest when called: pm_runtime_disable_action() -> pm_runtime_dont_use_autosuspend() -> __pm_runtime_use_autosuspend() -> update_autosuspend() -> rpm_idle() The rpm_idle() function attempts to resume the device at runtime. However, at the point it is called, the device is no longer part of a PM domain (which manages clocks and power states). If the driver implements its own runtime PM APIs for specific functionalities - such as the rzg2l_adc driver - while also relying on the power domain subsystem for power management, rpm_idle() will invoke the driver's runtime PM API. However, since the device is no longer part of a PM domain at this point, the PM domain's runtime PM APIs will not be called. This leads to system aborts on Renesas SoCs. Another identified case is when a subsystem performs various cleanups using device_unbind_cleanup(), calling driver-specific APIs in the process. A known example is the thermal subsystem, which may call driver- specific APIs to disable the thermal device. The relevant call stack in this case is: device_driver_detach() -> device_release_driver_internal() -> device_unbind_cleanup() -> devres_release_all() -> devm_thermal_of_zone_release() -> thermal_zone_device_disable() -> thermal_zone_device_set_mode() -> struct thermal_zone_device_ops::change_mode() At the moment the driver-specific change_mode() API is called, the device is no longer part of its PM domain. Accessing its registers without proper power management leads to system aborts. Drop the call to dev_pm_domain_detach() from the platform bus remove function and rely on the newly introduced call in device_unbind_cleanup(). This ensures the same effect, but the call now occurs after all driver-specific devres resources have been freed. Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org> Link: https://patch.msgid.link/20250703112708.1621607-4-claudiu.beznea.uj@bp.renesas.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent f995080 commit ba2ebd5

1 file changed

Lines changed: 3 additions & 6 deletions

File tree

drivers/base/platform.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,15 +1396,13 @@ static int platform_probe(struct device *_dev)
13961396
if (ret < 0)
13971397
return ret;
13981398

1399-
ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON);
1399+
ret = dev_pm_domain_attach(_dev, PD_FLAG_ATTACH_POWER_ON |
1400+
PD_FLAG_DETACH_POWER_OFF);
14001401
if (ret)
14011402
goto out;
14021403

1403-
if (drv->probe) {
1404+
if (drv->probe)
14041405
ret = drv->probe(dev);
1405-
if (ret)
1406-
dev_pm_domain_detach(_dev, true);
1407-
}
14081406

14091407
out:
14101408
if (drv->prevent_deferred_probe && ret == -EPROBE_DEFER) {
@@ -1422,7 +1420,6 @@ static void platform_remove(struct device *_dev)
14221420

14231421
if (drv->remove)
14241422
drv->remove(dev);
1425-
dev_pm_domain_detach(_dev, true);
14261423
}
14271424

14281425
static void platform_shutdown(struct device *_dev)

0 commit comments

Comments
 (0)