pm: device: remove usage of local states

The device PM subsystem already holds the device state, so there is no
need to keep duplicates inside the device. The pm_device_state_get has
been refactored to just return the device state. Note that this is still
not safe, but the same applied to the previous implementation. This
problem will be addressed later.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2021-06-04 17:41:39 +02:00 committed by Anas Nashif
commit c2cf1ad203
48 changed files with 198 additions and 715 deletions

View file

@ -22,9 +22,6 @@ struct i2c_nrfx_twim_data {
uint32_t dev_config;
uint16_t concat_buf_size;
uint8_t *concat_buf;
#ifdef CONFIG_PM_DEVICE
enum pm_device_state pm_state;
#endif
};
struct i2c_nrfx_twim_config {
@ -253,10 +250,6 @@ static int init_twim(const struct device *dev)
return -EBUSY;
}
#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif
return 0;
}
@ -266,13 +259,13 @@ static int twim_nrfx_pm_control(const struct device *dev,
enum pm_device_state *state)
{
int ret = 0;
enum pm_device_state pm_current_state = get_dev_data(dev)->pm_state;
if (ctrl_command == PM_DEVICE_STATE_SET) {
enum pm_device_state new_state = *state;
enum pm_device_state curr_state;
if (new_state != pm_current_state) {
switch (new_state) {
(void)pm_device_state_get(dev, &curr_state);
if (*state != curr_state) {
switch (*state) {
case PM_DEVICE_STATE_ACTIVE:
init_twim(dev);
if (get_dev_data(dev)->dev_config) {
@ -285,7 +278,7 @@ static int twim_nrfx_pm_control(const struct device *dev,
case PM_DEVICE_STATE_LOW_POWER:
case PM_DEVICE_STATE_SUSPEND:
case PM_DEVICE_STATE_OFF:
if (pm_current_state != PM_DEVICE_STATE_ACTIVE) {
if (curr_state != PM_DEVICE_STATE_ACTIVE) {
break;
}
nrfx_twim_uninit(&get_dev_config(dev)->twim);
@ -294,13 +287,7 @@ static int twim_nrfx_pm_control(const struct device *dev,
default:
ret = -ENOTSUP;
}
if (!ret) {
get_dev_data(dev)->pm_state = new_state;
}
}
} else {
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
*state = get_dev_data(dev)->pm_state;
}
return ret;