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:
parent
bc2990f82d
commit
920f30cc0e
22 changed files with 176 additions and 400 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue