pm: simplify state change check logic

The device PM control function will only be called if the requested
state is different from the current one. A significant amount of drivers
were checking for state changes, now unnecessary. This patch removes all
this redundant logic.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-07-02 13:01:05 +02:00 committed by Anas Nashif
commit 920f30cc0e
22 changed files with 176 additions and 400 deletions

View file

@ -413,29 +413,22 @@ static int bme280_chip_init(const struct device *dev)
int bme280_pm_ctrl(const struct device *dev, enum pm_device_state state)
{
int ret = 0;
enum pm_device_state curr_state;
pm_device_state_get(dev, &curr_state);
if (state != curr_state) {
/* Switching from OFF to any */
if (state != PM_DEVICE_STATE_OFF) {
/* Re-initialize the chip */
ret = bme280_chip_init(dev);
}
/* Switching to OFF from any */
else if (state == PM_DEVICE_STATE_OFF) {
/* Switching from OFF to any */
if (curr_state == PM_DEVICE_STATE_OFF) {
/* Put the chip into sleep mode */
ret = bme280_reg_write(dev,
BME280_REG_CTRL_MEAS,
BME280_CTRL_MEAS_OFF_VAL);
/* Re-initialize the chip */
ret = bme280_chip_init(dev);
}
/* Switching to OFF from any */
else if (state == PM_DEVICE_STATE_OFF) {
/* Put the chip into sleep mode */
ret = bme280_reg_write(dev,
BME280_REG_CTRL_MEAS,
BME280_CTRL_MEAS_OFF_VAL);
if (ret < 0)
LOG_DBG("CTRL_MEAS write failed: %d",
ret);
}
if (ret < 0)
LOG_DBG("CTRL_MEAS write failed: %d", ret);
}
return ret;