power: device: void *context -> uint32_t *state
The context parameter used across device power management is actually the power state. Just use it and avoid a lot of unnecessary casts. Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
9ac646f277
commit
7eba310220
30 changed files with 111 additions and 109 deletions
|
@ -409,14 +409,14 @@ static void st7789v_enter_sleep(struct st7789v_data *data)
|
|||
}
|
||||
|
||||
static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct st7789v_data *data = (struct st7789v_data *)dev->data;
|
||||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
case DEVICE_PM_SET_POWER_STATE:
|
||||
if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
st7789v_exit_sleep(data);
|
||||
data->pm_state = PM_DEVICE_ACTIVE_STATE;
|
||||
ret = 0;
|
||||
|
@ -427,14 +427,14 @@ static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,
|
|||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
if (cb != NULL) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -293,14 +293,14 @@ static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
|
||||
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb,
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
|
||||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != data->pm_state) {
|
||||
ret = entropy_cc13xx_cc26xx_set_power_state(dev,
|
||||
|
@ -308,11 +308,11 @@ static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -186,7 +186,8 @@ void eth_mcux_phy_stop(struct eth_context *context);
|
|||
|
||||
static int eth_mcux_device_pm_control(const struct device *dev,
|
||||
uint32_t command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
struct eth_context *eth_ctx = (struct eth_context *)dev->data;
|
||||
int ret = 0;
|
||||
|
@ -199,7 +200,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
|
|||
}
|
||||
|
||||
if (command == PM_DEVICE_STATE_SET) {
|
||||
if (*(uint32_t *)context == PM_DEVICE_SUSPEND_STATE) {
|
||||
if (*state == PM_DEVICE_SUSPEND_STATE) {
|
||||
LOG_DBG("Suspending");
|
||||
|
||||
ret = net_if_suspend(eth_ctx->iface);
|
||||
|
@ -214,7 +215,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
|
|||
ENET_Deinit(eth_ctx->base);
|
||||
clock_control_off(eth_ctx->clock_dev,
|
||||
(clock_control_subsys_t)eth_ctx->clock);
|
||||
} else if (*(uint32_t *)context == PM_DEVICE_ACTIVE_STATE) {
|
||||
} else if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
LOG_DBG("Resuming");
|
||||
|
||||
clock_control_on(eth_ctx->clock_dev,
|
||||
|
@ -228,7 +229,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
|
|||
|
||||
out:
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -629,14 +629,15 @@ static int spi_flash_at45_init(const struct device *dev)
|
|||
#if IS_ENABLED(CONFIG_PM_DEVICE)
|
||||
static int spi_flash_at45_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
struct spi_flash_at45_data *dev_data = get_dev_data(dev);
|
||||
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
|
||||
int err = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != dev_data->pm_state) {
|
||||
switch (new_state) {
|
||||
|
@ -666,11 +667,11 @@ static int spi_flash_at45_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = dev_data->pm_state;
|
||||
*state = dev_data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, err, context, arg);
|
||||
cb(dev, err, state, arg);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -605,7 +605,7 @@ static int gpio_stm32_set_power_state(const struct device *dev,
|
|||
|
||||
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
struct gpio_stm32_data *data = dev->data;
|
||||
uint32_t new_state;
|
||||
|
@ -613,13 +613,13 @@ static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
|||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
new_state = *((const uint32_t *)context);
|
||||
new_state = *state;
|
||||
if (new_state != data->power_state) {
|
||||
ret = gpio_stm32_set_power_state(dev, new_state);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = gpio_stm32_get_power_state(dev);
|
||||
*state = gpio_stm32_get_power_state(dev);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
|
@ -627,7 +627,7 @@ static int gpio_stm32_pm_device_ctrl(const struct device *dev,
|
|||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -368,13 +368,13 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
|
||||
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb,
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != get_dev_data(dev)->pm_state) {
|
||||
ret = i2c_cc13xx_cc26xx_set_power_state(dev,
|
||||
|
@ -382,11 +382,11 @@ static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -224,13 +224,13 @@ static int init_twi(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
static int twi_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != pm_current_state) {
|
||||
switch (new_state) {
|
||||
|
@ -260,11 +260,11 @@ static int twi_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -263,13 +263,13 @@ static int init_twim(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
static int twim_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != pm_current_state) {
|
||||
switch (new_state) {
|
||||
|
@ -300,11 +300,11 @@ static int twim_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -192,7 +192,7 @@ static int arc_v2_irq_unit_get_state(const struct device *dev)
|
|||
* @return operation result
|
||||
*/
|
||||
static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command, void *context,
|
||||
uint32_t ctrl_command, uint32_t *context,
|
||||
pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
|
|
@ -303,7 +303,7 @@ int ioapic_resume_from_suspend(const struct device *port)
|
|||
*/
|
||||
static int ioapic_device_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *context, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
|
|
|
@ -404,18 +404,18 @@ int loapic_resume(const struct device *port)
|
|||
*/
|
||||
static int loapic_device_ctrl(const struct device *port,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *context, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
if (*((uint32_t *)context) == PM_DEVICE_SUSPEND_STATE) {
|
||||
if (*context == PM_DEVICE_SUSPEND_STATE) {
|
||||
ret = loapic_suspend(port);
|
||||
} else if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
} else if (*context == PM_DEVICE_ACTIVE_STATE) {
|
||||
ret = loapic_resume(port);
|
||||
}
|
||||
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
|
||||
*((uint32_t *)context) = loapic_device_power_state;
|
||||
*context = loapic_device_power_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
|
|
|
@ -317,25 +317,25 @@ static int pwm_nrfx_set_power_state(uint32_t new_state,
|
|||
|
||||
static int pwm_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context,
|
||||
uint32_t *state,
|
||||
uint32_t *current_state)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *((const uint32_t *)state);
|
||||
|
||||
if (new_state != (*current_state)) {
|
||||
err = pwm_nrfx_set_power_state(new_state,
|
||||
*current_state,
|
||||
dev);
|
||||
if (!err) {
|
||||
(*current_state) = new_state;
|
||||
*current_state = new_state;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = (*current_state);
|
||||
*state = *current_state;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -344,16 +344,16 @@ static int pwm_nrfx_pm_control(const struct device *dev,
|
|||
#define PWM_NRFX_PM_CONTROL(idx) \
|
||||
static int pwm_##idx##_nrfx_pm_control(const struct device *dev, \
|
||||
uint32_t ctrl_command, \
|
||||
void *context, \
|
||||
uint32_t *state, \
|
||||
pm_device_cb cb, \
|
||||
void *arg) \
|
||||
{ \
|
||||
static uint32_t current_state = PM_DEVICE_ACTIVE_STATE; \
|
||||
int ret = 0; \
|
||||
ret = pwm_nrfx_pm_control(dev, ctrl_command, context, \
|
||||
ret = pwm_nrfx_pm_control(dev, ctrl_command, state, \
|
||||
¤t_state); \
|
||||
if (cb) { \
|
||||
cb(dev, ret, context, arg); \
|
||||
cb(dev, ret, state, arg); \
|
||||
} \
|
||||
return ret; \
|
||||
}
|
||||
|
|
|
@ -520,7 +520,7 @@ static int lis2mdl_set_power_state(struct lis2mdl_data *lis2mdl,
|
|||
}
|
||||
|
||||
static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
struct lis2mdl_data *lis2mdl = dev->data;
|
||||
const struct lis2mdl_config *const config = dev->config;
|
||||
|
@ -530,14 +530,14 @@ static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command,
|
|||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
new_state = *((const uint32_t *)context);
|
||||
new_state = *state;
|
||||
if (new_state != current_state) {
|
||||
status = lis2mdl_set_power_state(lis2mdl, config,
|
||||
new_state);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = current_state;
|
||||
*state = current_state;
|
||||
break;
|
||||
default:
|
||||
LOG_ERR("Got unknown power management control command");
|
||||
|
@ -545,7 +545,7 @@ static int lis2mdl_pm_control(const struct device *dev, uint32_t ctrl_command,
|
|||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, status, context, arg);
|
||||
cb(dev, status, state, arg);
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
@ -268,7 +268,7 @@ static int qdec_nrfx_pm_set_state(struct qdec_nrfx_data *data,
|
|||
|
||||
static int qdec_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
struct qdec_nrfx_data *data = &qdec_nrfx_data;
|
||||
int err;
|
||||
|
@ -277,11 +277,11 @@ static int qdec_nrfx_pm_control(const struct device *dev,
|
|||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_GET:
|
||||
err = qdec_nrfx_pm_get_state(data, context);
|
||||
err = qdec_nrfx_pm_get_state(data, state);
|
||||
break;
|
||||
|
||||
case PM_DEVICE_STATE_SET:
|
||||
err = qdec_nrfx_pm_set_state(data, *((uint32_t *)context));
|
||||
err = qdec_nrfx_pm_set_state(data, *state);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -290,7 +290,7 @@ static int qdec_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, err, context, arg);
|
||||
cb(dev, err, state, arg);
|
||||
}
|
||||
|
||||
return err;
|
||||
|
|
|
@ -444,13 +444,13 @@ static int uart_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
|
||||
static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb,
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != get_dev_data(dev)->pm_state) {
|
||||
ret = uart_cc13xx_cc26xx_set_power_state(dev,
|
||||
|
@ -458,11 +458,11 @@ static int uart_cc13xx_cc26xx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -470,23 +470,23 @@ static inline int uart_npcx_set_power_state(const struct device *dev,
|
|||
|
||||
/* Implements the device power management control functionality */
|
||||
static int uart_npcx_pm_control(const struct device *dev, uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
ret = uart_npcx_set_power_state(dev, *((uint32_t *)context));
|
||||
ret = uart_npcx_set_power_state(dev, *state);
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
ret = uart_npcx_get_power_state(dev, (uint32_t *)context);
|
||||
ret = uart_npcx_get_power_state(dev, state);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
if (cb != NULL) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -1158,12 +1158,12 @@ static void uart_nrfx_set_power_state(const struct device *dev,
|
|||
|
||||
static int uart_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
static uint32_t current_state = PM_DEVICE_ACTIVE_STATE;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != current_state) {
|
||||
uart_nrfx_set_power_state(dev, new_state);
|
||||
|
@ -1171,11 +1171,11 @@ static int uart_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = current_state;
|
||||
*state = current_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, 0, context, arg);
|
||||
cb(dev, 0, state, arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1865,23 +1865,23 @@ static void uarte_nrfx_set_power_state(const struct device *dev,
|
|||
|
||||
static int uarte_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
struct uarte_nrfx_data *data = get_dev_data(dev);
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != data->pm_state) {
|
||||
uarte_nrfx_set_power_state(dev, new_state);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, 0, context, arg);
|
||||
cb(dev, 0, state, arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1461,24 +1461,24 @@ static int uart_stm32_set_power_state(const struct device *dev,
|
|||
*/
|
||||
static int uart_stm32_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb,
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
struct uart_stm32_data *data = DEV_DATA(dev);
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != data->pm_state) {
|
||||
uart_stm32_set_power_state(dev, new_state);
|
||||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, 0, context, arg);
|
||||
cb(dev, 0, state, arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -251,13 +251,13 @@ static int spi_cc13xx_cc26xx_set_power_state(const struct device *dev,
|
|||
|
||||
static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb,
|
||||
uint32_t *state, pm_device_cb cb,
|
||||
void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != get_dev_data(dev)->pm_state) {
|
||||
ret = spi_cc13xx_cc26xx_set_power_state(dev,
|
||||
|
@ -265,11 +265,11 @@ static int spi_cc13xx_cc26xx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = get_dev_data(dev)->pm_state;
|
||||
*state = get_dev_data(dev)->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -286,14 +286,14 @@ static int init_spi(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
static int spi_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != data->pm_state) {
|
||||
switch (new_state) {
|
||||
|
@ -320,11 +320,11 @@ static int spi_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -334,14 +334,14 @@ static int init_spim(const struct device *dev)
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
static int spim_nrfx_pm_control(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
struct spi_nrfx_data *data = get_dev_data(dev);
|
||||
const struct spi_nrfx_config *config = get_dev_config(dev);
|
||||
|
||||
if (ctrl_command == PM_DEVICE_STATE_SET) {
|
||||
uint32_t new_state = *((const uint32_t *)context);
|
||||
uint32_t new_state = *state;
|
||||
|
||||
if (new_state != data->pm_state) {
|
||||
switch (new_state) {
|
||||
|
@ -368,11 +368,11 @@ static int spim_nrfx_pm_control(const struct device *dev,
|
|||
}
|
||||
} else {
|
||||
__ASSERT_NO_MSG(ctrl_command == PM_DEVICE_STATE_GET);
|
||||
*((uint32_t *)context) = data->pm_state;
|
||||
*state = data->pm_state;
|
||||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -32,7 +32,7 @@ int __weak sys_clock_driver_init(const struct device *dev)
|
|||
|
||||
int __weak sys_clock_device_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *context, pm_device_cb cb, void *arg)
|
||||
{
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
|
|
@ -387,7 +387,7 @@ struct device {
|
|||
#ifdef CONFIG_PM_DEVICE
|
||||
/** Power Management function */
|
||||
int (*pm_control)(const struct device *dev, uint32_t command,
|
||||
void *context, pm_device_cb cb, void *arg);
|
||||
uint32_t *state, pm_device_cb cb, void *arg);
|
||||
/** Pointer to device instance power management data */
|
||||
struct pm_device * const pm;
|
||||
#endif
|
||||
|
|
|
@ -78,7 +78,7 @@ struct device;
|
|||
#define PM_DEVICE_STATE_GET 2
|
||||
|
||||
typedef void (*pm_device_cb)(const struct device *dev,
|
||||
int status, void *context, void *arg);
|
||||
int status, uint32_t *state, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Device PM info
|
||||
|
|
|
@ -117,27 +117,27 @@ static int dummy_resume_from_suspend(const struct device *dev)
|
|||
|
||||
static int dummy_device_pm_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
ret = dummy_resume_from_suspend(dev);
|
||||
} else {
|
||||
ret = dummy_suspend(dev);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = dummy_get_power_state(dev);
|
||||
*state = dummy_get_power_state(dev);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
|
||||
}
|
||||
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -48,27 +48,27 @@ static int dummy_resume_from_suspend(const struct device *dev)
|
|||
|
||||
static int dummy_parent_pm_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
ret = dummy_resume_from_suspend(dev);
|
||||
} else {
|
||||
ret = dummy_suspend(dev);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = dummy_get_power_state(dev);
|
||||
*state = dummy_get_power_state(dev);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
|
||||
}
|
||||
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,12 +27,12 @@ enum device_pm_state {
|
|||
#define PM_DEVICE_ASYNC (1 << 0)
|
||||
|
||||
static void device_pm_callback(const struct device *dev,
|
||||
int retval, void *context, void *arg)
|
||||
int retval, uint32_t *state, void *arg)
|
||||
{
|
||||
__ASSERT(retval == 0, "Device set power state failed");
|
||||
|
||||
/* Set the fsm_state */
|
||||
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
atomic_set(&dev->pm->fsm_state,
|
||||
PM_DEVICE_STATE_ACTIVE);
|
||||
} else {
|
||||
|
|
|
@ -22,18 +22,18 @@ struct fake_dev_context {
|
|||
};
|
||||
|
||||
static int fake_dev_pm_control(const struct device *dev, uint32_t command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
struct fake_dev_context *ctx = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
if (command == PM_DEVICE_STATE_SET) {
|
||||
if (*(uint32_t *)context == PM_DEVICE_SUSPEND_STATE) {
|
||||
if (*state == PM_DEVICE_SUSPEND_STATE) {
|
||||
ret = net_if_suspend(ctx->iface);
|
||||
if (ret == -EBUSY) {
|
||||
goto out;
|
||||
}
|
||||
} else if (*(uint32_t *)context == PM_DEVICE_ACTIVE_STATE) {
|
||||
} else if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
ret = net_if_resume(ctx->iface);
|
||||
}
|
||||
} else {
|
||||
|
@ -42,7 +42,7 @@ static int fake_dev_pm_control(const struct device *dev, uint32_t command,
|
|||
|
||||
out:
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -40,20 +40,20 @@ static int dummy_resume_from_suspend(const struct device *dev)
|
|||
|
||||
static int dummy_device_pm_ctrl(const struct device *dev,
|
||||
uint32_t ctrl_command,
|
||||
void *context, pm_device_cb cb, void *arg)
|
||||
uint32_t *state, pm_device_cb cb, void *arg)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
switch (ctrl_command) {
|
||||
case PM_DEVICE_STATE_SET:
|
||||
if (*((uint32_t *)context) == PM_DEVICE_ACTIVE_STATE) {
|
||||
if (*state == PM_DEVICE_ACTIVE_STATE) {
|
||||
ret = dummy_resume_from_suspend(dev);
|
||||
} else {
|
||||
ret = dummy_suspend(dev);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_STATE_GET:
|
||||
*((uint32_t *)context) = dummy_get_power_state(dev);
|
||||
*state = dummy_get_power_state(dev);
|
||||
break;
|
||||
default:
|
||||
ret = -EINVAL;
|
||||
|
@ -61,7 +61,7 @@ static int dummy_device_pm_ctrl(const struct device *dev,
|
|||
}
|
||||
|
||||
if (cb) {
|
||||
cb(dev, ret, context, arg);
|
||||
cb(dev, ret, state, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue