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

@ -32,9 +32,6 @@ struct i2c_cc13xx_cc26xx_data {
Power_NotifyObj postNotify;
uint32_t dev_config;
#endif
#ifdef CONFIG_PM_DEVICE
enum pm_device_state pm_state;
#endif
};
struct i2c_cc13xx_cc26xx_config {
@ -333,9 +330,11 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
enum pm_device_state new_state)
{
int ret = 0;
enum pm_device_state state;
if ((new_state == PM_DEVICE_STATE_ACTIVE) &&
(new_state != get_dev_data(dev)->pm_state)) {
(void)pm_device_state_get(dev, &state);
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state) {
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
IOCPinTypeI2c(get_dev_config(dev)->base,
get_dev_config(dev)->sda_pin,
@ -344,14 +343,13 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
get_dev_data(dev)->dev_config);
if (ret == 0) {
I2CMasterIntEnable(get_dev_config(dev)->base);
get_dev_data(dev)->pm_state = new_state;
}
} else {
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
new_state == PM_DEVICE_STATE_SUSPEND ||
new_state == PM_DEVICE_STATE_OFF);
if (get_dev_data(dev)->pm_state == PM_DEVICE_STATE_ACTIVE) {
if (state == PM_DEVICE_STATE_ACTIVE) {
I2CMasterIntDisable(get_dev_config(dev)->base);
I2CMasterDisable(get_dev_config(dev)->base);
/* Reset pin type to default GPIO configuration */
@ -360,7 +358,6 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
IOC_PORT_GPIO, IOC_STD_OUTPUT);
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
get_dev_data(dev)->pm_state = new_state;
}
}
@ -374,15 +371,13 @@ static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
int ret = 0;
if (ctrl_command == PM_DEVICE_STATE_SET) {
enum pm_device_state new_state = *state;
enum pm_device_state curr_state;
if (new_state != get_dev_data(dev)->pm_state) {
(void)pm_device_state_get(dev, &curr_state);
if (*state != curr_state) {
ret = i2c_cc13xx_cc26xx_set_power_state(dev,
new_state);
}
} else {
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
*state = get_dev_data(dev)->pm_state;
}
return ret;
@ -394,10 +389,6 @@ static int i2c_cc13xx_cc26xx_init(const struct device *dev)
uint32_t cfg;
int err;
#ifdef CONFIG_PM_DEVICE
get_dev_data(dev)->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif
#ifdef CONFIG_PM
/* Set Power dependencies & constraints */
Power_setDependency(PowerCC26XX_PERIPH_I2C0);