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
|
@ -265,43 +265,25 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
||||||
int ret = 0;
|
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
|
|
||||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
|
||||||
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
|
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
|
||||||
start_trng(data);
|
start_trng(data);
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
stop_trng(data);
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
|
||||||
|
|
||||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
stop_trng(data);
|
|
||||||
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
|
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
return entropy_cc13xx_cc26xx_set_power_state(dev, state);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
ret = entropy_cc13xx_cc26xx_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -628,36 +628,29 @@ static int spi_flash_at45_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
|
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
|
||||||
int err = 0;
|
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
switch (state) {
|
acquire(dev);
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
power_down_op(dev, CMD_EXIT_DPD, dev_config->t_exit_dpd);
|
||||||
acquire(dev);
|
release(dev);
|
||||||
power_down_op(dev, CMD_EXIT_DPD,
|
break;
|
||||||
dev_config->t_exit_dpd);
|
|
||||||
release(dev);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_OFF:
|
case PM_DEVICE_STATE_OFF:
|
||||||
acquire(dev);
|
acquire(dev);
|
||||||
power_down_op(dev,
|
power_down_op(dev,
|
||||||
dev_config->use_udpd ? CMD_ENTER_UDPD
|
dev_config->use_udpd ? CMD_ENTER_UDPD : CMD_ENTER_DPD,
|
||||||
: CMD_ENTER_DPD,
|
dev_config->t_enter_dpd);
|
||||||
dev_config->t_enter_dpd);
|
release(dev);
|
||||||
release(dev);
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /* IS_ENABLED(CONFIG_PM_DEVICE) */
|
#endif /* IS_ENABLED(CONFIG_PM_DEVICE) */
|
||||||
|
|
||||||
|
|
|
@ -575,15 +575,15 @@ static const struct gpio_driver_api gpio_stm32_driver = {
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int gpio_stm32_set_power_state(const struct device *dev,
|
static int gpio_stm32_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
ret = gpio_stm32_clock_request(dev, true);
|
ret = gpio_stm32_clock_request(dev, true);
|
||||||
} else if (new_state == PM_DEVICE_STATE_SUSPEND) {
|
} else if (state == PM_DEVICE_STATE_SUSPEND) {
|
||||||
ret = gpio_stm32_clock_request(dev, false);
|
ret = gpio_stm32_clock_request(dev, false);
|
||||||
} else if (new_state == PM_DEVICE_STATE_LOW_POWER) {
|
} else if (state == PM_DEVICE_STATE_LOW_POWER) {
|
||||||
ret = gpio_stm32_clock_request(dev, false);
|
ret = gpio_stm32_clock_request(dev, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -597,15 +597,7 @@ static int gpio_stm32_set_power_state(const struct device *dev,
|
||||||
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
return gpio_stm32_set_power_state(dev, state);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
ret = gpio_stm32_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -327,14 +327,11 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
|
|
||||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state) {
|
|
||||||
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
|
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
|
||||||
IOCPinTypeI2c(get_dev_config(dev)->base,
|
IOCPinTypeI2c(get_dev_config(dev)->base,
|
||||||
get_dev_config(dev)->sda_pin,
|
get_dev_config(dev)->sda_pin,
|
||||||
|
@ -345,20 +342,14 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
I2CMasterIntEnable(get_dev_config(dev)->base);
|
I2CMasterIntEnable(get_dev_config(dev)->base);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
I2CMasterIntDisable(get_dev_config(dev)->base);
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
I2CMasterDisable(get_dev_config(dev)->base);
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
/* Reset pin type to default GPIO configuration */
|
||||||
|
IOCPortConfigureSet(get_dev_config(dev)->scl_pin,
|
||||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||||
I2CMasterIntDisable(get_dev_config(dev)->base);
|
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
|
||||||
I2CMasterDisable(get_dev_config(dev)->base);
|
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
||||||
/* Reset pin type to default GPIO configuration */
|
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
|
||||||
IOCPortConfigureSet(get_dev_config(dev)->scl_pin,
|
|
||||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
|
||||||
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
|
|
||||||
IOC_PORT_GPIO, IOC_STD_OUTPUT);
|
|
||||||
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -367,16 +358,7 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
|
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
return i2c_cc13xx_cc26xx_set_power_state(dev, state);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
ret = i2c_cc13xx_cc26xx_set_power_state(dev,
|
|
||||||
new_state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -220,31 +220,24 @@ static int twi_nrfx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
switch (state) {
|
init_twi(dev);
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
if (get_dev_data(dev)->dev_config) {
|
||||||
init_twi(dev);
|
i2c_nrfx_twi_configure(dev,
|
||||||
if (get_dev_data(dev)->dev_config) {
|
get_dev_data(dev)->dev_config);
|
||||||
i2c_nrfx_twi_configure(
|
|
||||||
dev,
|
|
||||||
get_dev_data(dev)->dev_config);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
|
||||||
case PM_DEVICE_STATE_OFF:
|
|
||||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
nrfx_twi_uninit(&get_dev_config(dev)->twi);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = -ENOTSUP;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
|
case PM_DEVICE_STATE_OFF:
|
||||||
|
nrfx_twi_uninit(&get_dev_config(dev)->twi);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ret = -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -258,32 +258,24 @@ static int twim_nrfx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
switch (state) {
|
init_twim(dev);
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
if (get_dev_data(dev)->dev_config) {
|
||||||
init_twim(dev);
|
i2c_nrfx_twim_configure(dev,
|
||||||
if (get_dev_data(dev)->dev_config) {
|
get_dev_data(dev)->dev_config);
|
||||||
i2c_nrfx_twim_configure(
|
|
||||||
dev,
|
|
||||||
get_dev_data(dev)->dev_config);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
|
||||||
case PM_DEVICE_STATE_OFF:
|
|
||||||
if (curr_state != PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
nrfx_twim_uninit(&get_dev_config(dev)->twim);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = -ENOTSUP;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
|
case PM_DEVICE_STATE_OFF:
|
||||||
|
nrfx_twim_uninit(&get_dev_config(dev)->twim);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ret = -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -313,16 +313,12 @@ static int ioapic_device_ctrl(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
break;
|
break;
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
if (curr_state != PM_DEVICE_STATE_LOW_POWER) {
|
ret = ioapic_resume_from_suspend(dev);
|
||||||
ret = ioapic_resume_from_suspend(dev);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
||||||
|
|
|
@ -119,13 +119,6 @@ static int led_pwm_pm_set_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state new_state)
|
||||||
{
|
{
|
||||||
const struct led_pwm_config *config = DEV_CFG(dev);
|
const struct led_pwm_config *config = DEV_CFG(dev);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
|
|
||||||
if (curr_state == new_state) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* switch all underlying PWM devices to the new state */
|
/* switch all underlying PWM devices to the new state */
|
||||||
for (size_t i = 0; i < config->num_leds; i++) {
|
for (size_t i = 0; i < config->num_leds; i++) {
|
||||||
|
|
|
@ -292,13 +292,12 @@ static void pwm_nrfx_uninit(const struct device *dev)
|
||||||
memset(dev->data, 0, sizeof(struct pwm_nrfx_data));
|
memset(dev->data, 0, sizeof(struct pwm_nrfx_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
static int pwm_nrfx_set_power_state(enum pm_device_state state,
|
||||||
enum pm_device_state current_state,
|
|
||||||
const struct device *dev)
|
const struct device *dev)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
switch (new_state) {
|
switch (state) {
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
err = pwm_nrfx_init(dev);
|
err = pwm_nrfx_init(dev);
|
||||||
break;
|
break;
|
||||||
|
@ -306,9 +305,7 @@ static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
case PM_DEVICE_STATE_FORCE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_OFF:
|
case PM_DEVICE_STATE_OFF:
|
||||||
if (current_state == PM_DEVICE_STATE_ACTIVE) {
|
pwm_nrfx_uninit(dev);
|
||||||
pwm_nrfx_uninit(dev);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
__ASSERT_NO_MSG(false);
|
__ASSERT_NO_MSG(false);
|
||||||
|
@ -320,15 +317,7 @@ static int pwm_nrfx_set_power_state(enum pm_device_state new_state,
|
||||||
static int pwm_nrfx_pm_control(const struct device *dev,
|
static int pwm_nrfx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int err = 0;
|
return pwm_nrfx_set_power_state(state, dev);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != current_state) {
|
|
||||||
err = pwm_nrfx_set_power_state(state, current_state, dev);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PWM_NRFX_PM_CONTROL(idx) \
|
#define PWM_NRFX_PM_CONTROL(idx) \
|
||||||
|
|
|
@ -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 bme280_pm_ctrl(const struct device *dev, enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
pm_device_state_get(dev, &curr_state);
|
/* Switching from OFF to any */
|
||||||
if (state != curr_state) {
|
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 */
|
/* Put the chip into sleep mode */
|
||||||
if (curr_state == PM_DEVICE_STATE_OFF) {
|
ret = bme280_reg_write(dev,
|
||||||
|
BME280_REG_CTRL_MEAS,
|
||||||
|
BME280_CTRL_MEAS_OFF_VAL);
|
||||||
|
|
||||||
/* Re-initialize the chip */
|
if (ret < 0)
|
||||||
ret = bme280_chip_init(dev);
|
LOG_DBG("CTRL_MEAS write failed: %d", ret);
|
||||||
}
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -550,21 +550,14 @@ static int bmp388_get_calibration_data(const struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int bmp388_set_power_state(const struct device *dev,
|
static int bmp388_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state power_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
uint8_t reg_val;
|
uint8_t reg_val;
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
if (state == power_state) {
|
|
||||||
/* We are already in the desired state. */
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (power_state == PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
reg_val = BMP388_PWR_CTRL_MODE_NORMAL;
|
reg_val = BMP388_PWR_CTRL_MODE_NORMAL;
|
||||||
} else if ((power_state == PM_DEVICE_STATE_SUSPEND) ||
|
} else if ((state == PM_DEVICE_STATE_SUSPEND) ||
|
||||||
(power_state == PM_DEVICE_STATE_OFF)) {
|
(state == PM_DEVICE_STATE_OFF)) {
|
||||||
reg_val = BMP388_PWR_CTRL_MODE_SLEEP;
|
reg_val = BMP388_PWR_CTRL_MODE_SLEEP;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -539,21 +539,16 @@ static int fdc2x1x_device_pm_ctrl(const struct device *dev,
|
||||||
{
|
{
|
||||||
struct fdc2x1x_data *data = dev->data;
|
struct fdc2x1x_data *data = dev->data;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
switch (state) {
|
case PM_DEVICE_STATE_OFF:
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
ret = fdc2x1x_set_pm_state(dev, state);
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
break;
|
||||||
case PM_DEVICE_STATE_OFF:
|
default:
|
||||||
ret = fdc2x1x_set_pm_state(dev, state);
|
LOG_ERR("PM state not supported");
|
||||||
break;
|
ret = -EINVAL;
|
||||||
default:
|
|
||||||
LOG_ERR("PM state not supported");
|
|
||||||
ret = -EINVAL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -444,12 +444,12 @@ static int lis2mdl_init(const struct device *dev)
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
||||||
const struct lis2mdl_config *const config,
|
const struct lis2mdl_config *const config,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx;
|
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&config->ctx;
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
if (config->single_mode) {
|
if (config->single_mode) {
|
||||||
status = lis2mdl_operating_mode_set(ctx,
|
status = lis2mdl_operating_mode_set(ctx,
|
||||||
LIS2MDL_SINGLE_TRIGGER);
|
LIS2MDL_SINGLE_TRIGGER);
|
||||||
|
@ -462,9 +462,6 @@ static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
||||||
}
|
}
|
||||||
LOG_DBG("State changed to active");
|
LOG_DBG("State changed to active");
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
|
||||||
status = lis2mdl_operating_mode_set(ctx, LIS2MDL_POWER_DOWN);
|
status = lis2mdl_operating_mode_set(ctx, LIS2MDL_POWER_DOWN);
|
||||||
if (status) {
|
if (status) {
|
||||||
LOG_ERR("Power down failed");
|
LOG_ERR("Power down failed");
|
||||||
|
@ -480,15 +477,8 @@ static int lis2mdl_pm_control(const struct device *dev,
|
||||||
{
|
{
|
||||||
struct lis2mdl_data *lis2mdl = dev->data;
|
struct lis2mdl_data *lis2mdl = dev->data;
|
||||||
const struct lis2mdl_config *const config = dev->config;
|
const struct lis2mdl_config *const config = dev->config;
|
||||||
int status = 0;
|
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
return lis2mdl_set_power_state(lis2mdl, config, state);
|
||||||
if (state != curr_state) {
|
|
||||||
status = lis2mdl_set_power_state(lis2mdl, config, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return status;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -209,33 +209,20 @@ static int qdec_nrfx_init(const struct device *dev)
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
|
|
||||||
static int qdec_nrfx_pm_set_state(struct qdec_nrfx_data *data,
|
static int qdec_nrfx_pm_set_state(struct qdec_nrfx_data *data,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
enum pm_device_state curr_state;
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
|
qdec_nrfx_gpio_ctrl(true);
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
nrfx_qdec_enable();
|
||||||
|
} else if (state == PM_DEVICE_STATE_OFF) {
|
||||||
if (curr_state == new_state) {
|
/* device must be uninitialized */
|
||||||
/* leave unchanged */
|
nrfx_qdec_uninit();
|
||||||
return 0;
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
/* device must be suspended */
|
/* device must be suspended */
|
||||||
nrfx_qdec_disable();
|
nrfx_qdec_disable();
|
||||||
qdec_nrfx_gpio_ctrl(false);
|
qdec_nrfx_gpio_ctrl(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_state == PM_DEVICE_STATE_OFF) {
|
|
||||||
/* device must be uninitialized */
|
|
||||||
nrfx_qdec_uninit();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
qdec_nrfx_gpio_ctrl(true);
|
|
||||||
nrfx_qdec_enable();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,13 +191,6 @@ static int sgp40_set_power_state(const struct device *dev,
|
||||||
{
|
{
|
||||||
uint16_t cmd;
|
uint16_t cmd;
|
||||||
int rc;
|
int rc;
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
|
||||||
if (state == power_state) {
|
|
||||||
LOG_DBG("Device already in requested PM_STATE.");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (power_state == PM_DEVICE_STATE_ACTIVE) {
|
if (power_state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
/* activate the hotplate by sending a measure command */
|
/* activate the hotplate by sending a measure command */
|
||||||
|
|
|
@ -398,16 +398,12 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
|
if (get_dev_conf(dev)->regs == DT_INST_REG_ADDR(0)) {
|
||||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
|
||||||
if (get_dev_conf(dev)->regs ==
|
|
||||||
DT_INST_REG_ADDR(0)) {
|
|
||||||
Power_setDependency(PowerCC26XX_PERIPH_UART0);
|
Power_setDependency(PowerCC26XX_PERIPH_UART0);
|
||||||
} else {
|
} else {
|
||||||
Power_setDependency(PowerCC26X2_PERIPH_UART1);
|
Power_setDependency(PowerCC26X2_PERIPH_UART1);
|
||||||
|
@ -416,24 +412,16 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
ret = uart_cc13xx_cc26xx_configure(dev,
|
ret = uart_cc13xx_cc26xx_configure(dev,
|
||||||
&get_dev_data(dev)->uart_config);
|
&get_dev_data(dev)->uart_config);
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
UARTDisable(get_dev_conf(dev)->regs);
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
/*
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
* Release power dependency - i.e. potentially power
|
||||||
|
* down serial domain.
|
||||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
*/
|
||||||
UARTDisable(get_dev_conf(dev)->regs);
|
if (get_dev_conf(dev)->regs ==
|
||||||
/*
|
DT_INST_REG_ADDR(0)) {
|
||||||
* Release power dependency - i.e. potentially power
|
Power_releaseDependency(PowerCC26XX_PERIPH_UART0);
|
||||||
* down serial domain.
|
} else {
|
||||||
*/
|
Power_releaseDependency(PowerCC26X2_PERIPH_UART1);
|
||||||
if (get_dev_conf(dev)->regs ==
|
|
||||||
DT_INST_REG_ADDR(0)) {
|
|
||||||
Power_releaseDependency(
|
|
||||||
PowerCC26XX_PERIPH_UART0);
|
|
||||||
} else {
|
|
||||||
Power_releaseDependency(
|
|
||||||
PowerCC26X2_PERIPH_UART1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,15 +431,7 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
|
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
return uart_cc13xx_cc26xx_set_power_state(dev, state);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
ret = uart_cc13xx_cc26xx_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -1140,9 +1140,9 @@ static void uart_nrfx_pins_enable(const struct device *dev, bool enable)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void uart_nrfx_set_power_state(const struct device *dev,
|
static void uart_nrfx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
uart_nrfx_pins_enable(dev, true);
|
uart_nrfx_pins_enable(dev, true);
|
||||||
nrf_uart_enable(uart0_addr);
|
nrf_uart_enable(uart0_addr);
|
||||||
if (RX_PIN_USED) {
|
if (RX_PIN_USED) {
|
||||||
|
@ -1150,9 +1150,6 @@ static void uart_nrfx_set_power_state(const struct device *dev,
|
||||||
NRF_UART_TASK_STARTRX);
|
NRF_UART_TASK_STARTRX);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
|
||||||
nrf_uart_disable(uart0_addr);
|
nrf_uart_disable(uart0_addr);
|
||||||
uart_nrfx_pins_enable(dev, false);
|
uart_nrfx_pins_enable(dev, false);
|
||||||
}
|
}
|
||||||
|
@ -1161,12 +1158,7 @@ static void uart_nrfx_set_power_state(const struct device *dev,
|
||||||
static int uart_nrfx_pm_control(const struct device *dev,
|
static int uart_nrfx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
enum pm_device_state current_state;
|
uart_nrfx_set_power_state(dev, state);
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, ¤t_state);
|
|
||||||
if (state != current_state) {
|
|
||||||
uart_nrfx_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1832,14 +1832,14 @@ static void wait_for_tx_stopped(const struct device *dev)
|
||||||
|
|
||||||
|
|
||||||
static void uarte_nrfx_set_power_state(const struct device *dev,
|
static void uarte_nrfx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
NRF_UARTE_Type *uarte = get_uarte_instance(dev);
|
||||||
#if defined(CONFIG_UART_ASYNC_API) || defined(UARTE_INTERRUPT_DRIVEN)
|
#if defined(CONFIG_UART_ASYNC_API) || defined(UARTE_INTERRUPT_DRIVEN)
|
||||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (new_state == PM_DEVICE_STATE_ACTIVE) {
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
uarte_nrfx_pins_enable(dev, true);
|
uarte_nrfx_pins_enable(dev, true);
|
||||||
nrf_uarte_enable(uarte);
|
nrf_uarte_enable(uarte);
|
||||||
|
|
||||||
|
@ -1864,20 +1864,6 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enum pm_device_state state;
|
|
||||||
|
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
|
||||||
|
|
||||||
/* if pm is already not active, driver will stay indefinitely
|
|
||||||
* in while loop waiting for event NRF_UARTE_EVENT_RXTO
|
|
||||||
*/
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
|
||||||
if (state != PM_DEVICE_STATE_ACTIVE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disabling UART requires stopping RX, but stop RX event is
|
/* Disabling UART requires stopping RX, but stop RX event is
|
||||||
* only sent after each RX if async UART API is used.
|
* only sent after each RX if async UART API is used.
|
||||||
*/
|
*/
|
||||||
|
@ -1924,12 +1910,7 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
|
||||||
static int uarte_nrfx_pm_control(const struct device *dev,
|
static int uarte_nrfx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
enum pm_device_state curr_state;
|
uarte_nrfx_set_power_state(dev, state);
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
uarte_nrfx_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1423,12 +1423,12 @@ static int uart_stm32_init(const struct device *dev)
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int uart_stm32_set_power_state(const struct device *dev,
|
static int uart_stm32_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
USART_TypeDef *UartInstance = UART_STRUCT(dev);
|
||||||
|
|
||||||
/* setting a low power mode */
|
/* setting a low power mode */
|
||||||
if (new_state != PM_DEVICE_STATE_ACTIVE) {
|
if (state != PM_DEVICE_STATE_ACTIVE) {
|
||||||
#ifdef USART_ISR_BUSY
|
#ifdef USART_ISR_BUSY
|
||||||
/* Make sure that no USART transfer is on-going */
|
/* Make sure that no USART transfer is on-going */
|
||||||
while (LL_USART_IsActiveFlag_BUSY(UartInstance) == 1) {
|
while (LL_USART_IsActiveFlag_BUSY(UartInstance) == 1) {
|
||||||
|
@ -1462,12 +1462,7 @@ static int uart_stm32_set_power_state(const struct device *dev,
|
||||||
static int uart_stm32_pm_control(const struct device *dev,
|
static int uart_stm32_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
enum pm_device_state curr_state;
|
uart_stm32_set_power_state(dev, state);
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
uart_stm32_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -209,56 +209,33 @@ static int spi_cc13xx_cc26xx_release(const struct device *dev,
|
||||||
|
|
||||||
#ifdef CONFIG_PM_DEVICE
|
#ifdef CONFIG_PM_DEVICE
|
||||||
static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
||||||
enum pm_device_state new_state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
if (state == PM_DEVICE_STATE_ACTIVE) {
|
||||||
enum pm_device_state state;
|
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) {
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &state);
|
|
||||||
|
|
||||||
if ((new_state == PM_DEVICE_STATE_ACTIVE) && (new_state != state)) {
|
|
||||||
if (get_dev_config(dev)->base ==
|
|
||||||
DT_INST_REG_ADDR(0)) {
|
|
||||||
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
|
Power_setDependency(PowerCC26XX_PERIPH_SSI0);
|
||||||
} else {
|
} else {
|
||||||
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
|
Power_setDependency(PowerCC26XX_PERIPH_SSI1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
__ASSERT_NO_MSG(new_state == PM_DEVICE_STATE_LOW_POWER ||
|
SSIDisable(get_dev_config(dev)->base);
|
||||||
new_state == PM_DEVICE_STATE_SUSPEND ||
|
/*
|
||||||
new_state == PM_DEVICE_STATE_OFF);
|
* Release power dependency
|
||||||
|
*/
|
||||||
if (state == PM_DEVICE_STATE_ACTIVE) {
|
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) {
|
||||||
SSIDisable(get_dev_config(dev)->base);
|
Power_releaseDependency(PowerCC26XX_PERIPH_SSI0);
|
||||||
/*
|
} else {
|
||||||
* Release power dependency
|
Power_releaseDependency(PowerCC26XX_PERIPH_SSI1);
|
||||||
*/
|
|
||||||
if (get_dev_config(dev)->base ==
|
|
||||||
DT_INST_REG_ADDR(0)) {
|
|
||||||
Power_releaseDependency(
|
|
||||||
PowerCC26XX_PERIPH_SSI0);
|
|
||||||
} else {
|
|
||||||
Power_releaseDependency(
|
|
||||||
PowerCC26XX_PERIPH_SSI1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||||
enum pm_device_state state)
|
enum pm_device_state state)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
return spi_cc13xx_cc26xx_set_power_state(dev, state);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
|
||||||
if (state != curr_state) {
|
|
||||||
ret = spi_cc13xx_cc26xx_set_power_state(dev, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_PM_DEVICE */
|
#endif /* CONFIG_PM_DEVICE */
|
||||||
|
|
||||||
|
|
|
@ -283,28 +283,22 @@ static int spi_nrfx_pm_control(const struct device *dev,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
switch (state) {
|
ret = init_spi(dev);
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
/* Force reconfiguration before next transfer */
|
||||||
ret = init_spi(dev);
|
data->ctx.config = NULL;
|
||||||
/* Force reconfiguration before next transfer */
|
break;
|
||||||
data->ctx.config = NULL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_OFF:
|
case PM_DEVICE_STATE_OFF:
|
||||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
nrfx_spi_uninit(&config->spi);
|
||||||
nrfx_spi_uninit(&config->spi);
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -330,28 +330,22 @@ static int spim_nrfx_pm_control(const struct device *dev,
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||||
enum pm_device_state curr_state;
|
|
||||||
|
|
||||||
(void)pm_device_state_get(dev, &curr_state);
|
switch (state) {
|
||||||
if (state != curr_state) {
|
case PM_DEVICE_STATE_ACTIVE:
|
||||||
switch (state) {
|
ret = init_spim(dev);
|
||||||
case PM_DEVICE_STATE_ACTIVE:
|
/* Force reconfiguration before next transfer */
|
||||||
ret = init_spim(dev);
|
data->ctx.config = NULL;
|
||||||
/* Force reconfiguration before next transfer */
|
break;
|
||||||
data->ctx.config = NULL;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PM_DEVICE_STATE_LOW_POWER:
|
case PM_DEVICE_STATE_LOW_POWER:
|
||||||
case PM_DEVICE_STATE_SUSPEND:
|
case PM_DEVICE_STATE_SUSPEND:
|
||||||
case PM_DEVICE_STATE_OFF:
|
case PM_DEVICE_STATE_OFF:
|
||||||
if (curr_state == PM_DEVICE_STATE_ACTIVE) {
|
nrfx_spim_uninit(&config->spim);
|
||||||
nrfx_spim_uninit(&config->spim);
|
break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ret = -ENOTSUP;
|
ret = -ENOTSUP;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue