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

@ -1413,9 +1413,6 @@ static int uart_stm32_init(const struct device *dev)
#if defined(CONFIG_UART_INTERRUPT_DRIVEN) || defined(CONFIG_UART_ASYNC_API)
config->uconf.irq_config_func(dev);
#endif
#ifdef CONFIG_PM_DEVICE
data->pm_state = PM_DEVICE_STATE_ACTIVE;
#endif /* CONFIG_PM_DEVICE */
#ifdef CONFIG_UART_ASYNC_API
return uart_stm32_async_init(dev);
@ -1429,7 +1426,6 @@ static int uart_stm32_set_power_state(const struct device *dev,
enum pm_device_state new_state)
{
USART_TypeDef *UartInstance = UART_STRUCT(dev);
struct uart_stm32_data *data = DEV_DATA(dev);
/* setting a low power mode */
if (new_state != PM_DEVICE_STATE_ACTIVE) {
@ -1449,7 +1445,7 @@ static int uart_stm32_set_power_state(const struct device *dev,
LL_USART_ClearFlag_ORE(UartInstance);
/* Leave UartInstance unchanged */
}
data->pm_state = new_state;
/* UartInstance returning to active mode has nothing special to do */
return 0;
}
@ -1467,17 +1463,13 @@ static int uart_stm32_pm_control(const struct device *dev,
uint32_t ctrl_command,
enum pm_device_state *state)
{
struct uart_stm32_data *data = DEV_DATA(dev);
if (ctrl_command == PM_DEVICE_STATE_SET) {
enum pm_device_state new_state = *state;
enum pm_device_state curr_state;
if (new_state != data->pm_state) {
uart_stm32_set_power_state(dev, new_state);
(void)pm_device_state_get(dev, &curr_state);
if (*state != curr_state) {
uart_stm32_set_power_state(dev, *state);
}
} else {
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
*state = data->pm_state;
}
return 0;