Support for runtime power management in External Flash Manager

We developed a Matter product that uses external flash memory both for firmware updates as for storing application specific data. In the ncs-2.8.0 sdk release the flash is put into sleep mode when it is not used anymore. However this is done using  pm_device_action_run that doesn't take into account that other parts of the application maybe still need access to the external flash. Therefore we propose to use pm_device_runtime_get and pm_device_runtime_put if CONFIG_PM_DEVICE_RUNTIME is enabled:

    void DoAction(Action aAction)
    {
#if defined(CONFIG_PM_DEVICE) && defined(CONFIG_NORDIC_QSPI_NOR)
        // utilize the QSPI driver sleep power mode
        const auto * qspi_dev = DEVICE_DT_GET(DT_INST(0, nordic_qspi_nor));
        if (device_is_ready(qspi_dev))
        {
#if defined(CONFIG_PM_DEVICE_RUNTIME)
            if(Action::WAKE_UP == aAction) {
                pm_device_runtime_get(qspi_dev);
            }
            else {
                pm_device_runtime_put(qspi_dev);
            }
#elif
            const auto requestedAction = Action::WAKE_UP == aAction ? PM_DEVICE_ACTION_RESUME : PM_DEVICE_ACTION_SUSPEND;
            (void) pm_device_action_run(qspi_dev, requestedAction); // not much can be done in case of a failure
#endif
        }
#endif
    }

This makes sure that the flash is only put into deep power mode when it is not used anywhere anymore.

Any feedback? Could this change be added to a next sdk release?

Related