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:
parent
1c0ed94601
commit
c2cf1ad203
48 changed files with 198 additions and 715 deletions
|
@ -19,9 +19,6 @@ struct i2c_nrfx_twi_data {
|
|||
struct k_sem completion_sync;
|
||||
volatile nrfx_err_t res;
|
||||
uint32_t dev_config;
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
enum pm_device_state pm_state;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct i2c_nrfx_twi_config {
|
||||
|
@ -214,9 +211,6 @@ static int init_twi(const struct device *dev)
|
|||
dev->name);
|
||||
return -EBUSY;
|
||||
}
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -227,13 +221,13 @@ static int twi_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_twi(dev);
|
||||
if (get_dev_data(dev)->dev_config) {
|
||||
|
@ -246,7 +240,7 @@ static int twi_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) {
|
||||
nrfx_twi_uninit(&get_dev_config(dev)->twi);
|
||||
}
|
||||
break;
|
||||
|
@ -254,13 +248,7 @@ static int twi_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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue