Skip to content

Commit 7ccc1a4

Browse files
gmarullnashif
authored andcommitted
pm: use actions for device PM control
Instead of passing target states, use actions for device PM control. Actions represent better the meaning of the callback argument. Furthermore, they are more future proof as they can be suitable for other PM actions that have no direct mapping to a state. If we compare with Linux, we could have a multi-stage suspend/resume. Such scenario would not have a good mapping when using target states. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 8be0472 commit 7ccc1a4

40 files changed

+176
-145
lines changed

drivers/display/display_st7735r.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,16 @@ static int st7735r_init(const struct device *dev)
495495

496496
#ifdef CONFIG_PM_DEVICE
497497
static int st7735r_pm_control(const struct device *dev,
498-
enum pm_device_state state)
498+
enum pm_device_action action)
499499
{
500500
int ret = 0;
501501
struct st7735r_data *data = (struct st7735r_data *)dev->data;
502502

503-
switch (state) {
504-
case PM_DEVICE_STATE_ACTIVE:
503+
switch (action) {
504+
case PM_DEVICE_ACTION_RESUME:
505505
ret = st7735r_exit_sleep(data);
506506
break;
507-
case PM_DEVICE_STATE_SUSPENDED:
507+
case PM_DEVICE_ACTION_SUSPEND:
508508
ret = st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0);
509509
break;
510510
default:

drivers/display/display_st7789v.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,16 @@ static int st7789v_init(const struct device *dev)
397397

398398
#ifdef CONFIG_PM_DEVICE
399399
static int st7789v_pm_control(const struct device *dev,
400-
enum pm_device_state state)
400+
enum pm_device_action action)
401401
{
402402
struct st7789v_data *data = (struct st7789v_data *)dev->data;
403403
int ret = 0;
404404

405-
switch (state) {
406-
case PM_DEVICE_STATE_ACTIVE:
405+
switch (action) {
406+
case PM_DEVICE_ACTION_RESUME:
407407
st7789v_exit_sleep(data);
408408
break;
409-
case PM_DEVICE_STATE_SUSPENDED:
409+
case PM_DEVICE_ACTION_SUSPEND:
410410
ret = st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0);
411411
break;
412412
default:

drivers/entropy/entropy_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,16 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
265265

266266
#ifdef CONFIG_PM_DEVICE
267267
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
268-
enum pm_device_state state)
268+
enum pm_device_action action)
269269
{
270270
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
271271

272-
switch (state) {
273-
case PM_DEVICE_STATE_ACTIVE:
272+
switch (action) {
273+
case PM_DEVICE_ACTION_RESUME:
274274
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
275275
start_trng(data);
276276
break;
277-
case PM_DEVICE_STATE_SUSPENDED:
277+
case PM_DEVICE_ACTION_SUSPEND:
278278
stop_trng(data);
279279
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
280280
break;

drivers/ethernet/eth_mcux.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ static void eth_mcux_phy_enter_reset(struct eth_context *context);
185185
void eth_mcux_phy_stop(struct eth_context *context);
186186

187187
static int eth_mcux_device_pm_control(const struct device *dev,
188-
enum pm_device_state state)
188+
enum pm_device_action action)
189189
{
190190
struct eth_context *eth_ctx = (struct eth_context *)dev->data;
191191
int ret = 0;
@@ -197,8 +197,8 @@ static int eth_mcux_device_pm_control(const struct device *dev,
197197
goto out;
198198
}
199199

200-
switch (state) {
201-
case PM_DEVICE_STATE_SUSPENDED:
200+
switch (action) {
201+
case PM_DEVICE_ACTION_SUSPEND:
202202
LOG_DBG("Suspending");
203203

204204
ret = net_if_suspend(eth_ctx->iface);
@@ -214,7 +214,7 @@ static int eth_mcux_device_pm_control(const struct device *dev,
214214
clock_control_off(eth_ctx->clock_dev,
215215
(clock_control_subsys_t)eth_ctx->clock);
216216
break;
217-
case PM_DEVICE_STATE_ACTIVE:
217+
case PM_DEVICE_ACTION_RESUME:
218218
LOG_DBG("Resuming");
219219

220220
clock_control_on(eth_ctx->clock_dev,

drivers/flash/spi_flash_at45.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -625,18 +625,18 @@ static int spi_flash_at45_init(const struct device *dev)
625625

626626
#if IS_ENABLED(CONFIG_PM_DEVICE)
627627
static int spi_flash_at45_pm_control(const struct device *dev,
628-
enum pm_device_state state)
628+
enum pm_device_action action)
629629
{
630630
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
631631

632-
switch (state) {
633-
case PM_DEVICE_STATE_ACTIVE:
632+
switch (action) {
633+
case PM_DEVICE_ACTION_RESUME:
634634
acquire(dev);
635635
power_down_op(dev, CMD_EXIT_DPD, dev_config->t_exit_dpd);
636636
release(dev);
637637
break;
638638

639-
case PM_DEVICE_STATE_SUSPENDED:
639+
case PM_DEVICE_ACTION_SUSPEND:
640640
acquire(dev);
641641
power_down_op(dev,
642642
dev_config->use_udpd ? CMD_ENTER_UDPD : CMD_ENTER_DPD,

drivers/gpio/gpio_dw.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ static inline int gpio_dw_manage_callback(const struct device *port,
430430
* the *context may include IN data or/and OUT data
431431
*/
432432
static int gpio_dw_device_ctrl(const struct device *dev,
433-
enum pm_device_state state)
433+
enum pm_device_action action)
434434
{
435-
switch (state) {
436-
case PM_DEVICE_STATE_SUSPENDED:
435+
switch (action) {
436+
case PM_DEVICE_ACTION_SUSPEND:
437437
gpio_dw_clock_off(dev);
438438
break;
439-
case PM_DEVICE_STATE_ACTIVE:
439+
case PM_DEVICE_ACTION_RESUME:
440440
gpio_dw_clock_on(dev);
441441
break;
442442
default:

drivers/gpio/gpio_stm32.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -575,12 +575,12 @@ static const struct gpio_driver_api gpio_stm32_driver = {
575575

576576
#ifdef CONFIG_PM_DEVICE
577577
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
578-
enum pm_device_state state)
578+
enum pm_device_action action)
579579
{
580-
switch (state) {
581-
case PM_DEVICE_STATE_ACTIVE:
580+
switch (action) {
581+
case PM_DEVICE_ACTION_RESUME:
582582
return gpio_stm32_clock_request(dev, true);
583-
case PM_DEVICE_STATE_SUSPENDED:
583+
case PM_DEVICE_ACTION_SUSPEND:
584584
return gpio_stm32_clock_request(dev, false);
585585
default:
586586
return -ENOTSUP;

drivers/i2c/i2c_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -327,12 +327,12 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
327327

328328
#ifdef CONFIG_PM_DEVICE
329329
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
330-
enum pm_device_state state)
330+
enum pm_device_action action)
331331
{
332332
int ret = 0;
333333

334-
switch (state) {
335-
case PM_DEVICE_STATE_ACTIVE:
334+
switch (action) {
335+
case PM_DEVICE_ACTION_RESUME:
336336
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
337337
IOCPinTypeI2c(get_dev_config(dev)->base,
338338
get_dev_config(dev)->sda_pin,
@@ -343,7 +343,7 @@ static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
343343
I2CMasterIntEnable(get_dev_config(dev)->base);
344344
}
345345
break;
346-
case PM_DEVICE_STATE_SUSPENDED:
346+
case PM_DEVICE_ACTION_SUSPEND:
347347
I2CMasterIntDisable(get_dev_config(dev)->base);
348348
I2CMasterDisable(get_dev_config(dev)->base);
349349
/* Reset pin type to default GPIO configuration */

drivers/i2c/i2c_nrfx_twi.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,20 @@ static int init_twi(const struct device *dev)
217217

218218
#ifdef CONFIG_PM_DEVICE
219219
static int twi_nrfx_pm_control(const struct device *dev,
220-
enum pm_device_state state)
220+
enum pm_device_action action)
221221
{
222222
int ret = 0;
223223

224-
switch (state) {
225-
case PM_DEVICE_STATE_ACTIVE:
224+
switch (action) {
225+
case PM_DEVICE_ACTION_RESUME:
226226
init_twi(dev);
227227
if (get_dev_data(dev)->dev_config) {
228228
i2c_nrfx_twi_configure(dev,
229229
get_dev_data(dev)->dev_config);
230230
}
231231
break;
232232

233-
case PM_DEVICE_STATE_SUSPENDED:
233+
case PM_DEVICE_ACTION_SUSPEND:
234234
nrfx_twi_uninit(&get_dev_config(dev)->twi);
235235
break;
236236

drivers/i2c/i2c_nrfx_twim.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -255,20 +255,20 @@ static int init_twim(const struct device *dev)
255255

256256
#ifdef CONFIG_PM_DEVICE
257257
static int twim_nrfx_pm_control(const struct device *dev,
258-
enum pm_device_state state)
258+
enum pm_device_action action)
259259
{
260260
int ret = 0;
261261

262-
switch (state) {
263-
case PM_DEVICE_STATE_ACTIVE:
262+
switch (action) {
263+
case PM_DEVICE_ACTION_RESUME:
264264
init_twim(dev);
265265
if (get_dev_data(dev)->dev_config) {
266266
i2c_nrfx_twim_configure(dev,
267267
get_dev_data(dev)->dev_config);
268268
}
269269
break;
270270

271-
case PM_DEVICE_STATE_SUSPENDED:
271+
case PM_DEVICE_ACTION_SUSPEND:
272272
nrfx_twim_uninit(&get_dev_config(dev)->twim);
273273
break;
274274

drivers/interrupt_controller/intc_arcv2_irq_unit.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,16 @@ static int arc_v2_irq_unit_resume(const struct device *dev)
175175
* @return operation result
176176
*/
177177
static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
178-
enum pm_device_state state)
178+
enum pm_device_action action)
179179
{
180180
int ret = 0;
181181
unsigned int key = arch_irq_lock();
182182

183-
switch (state) {
184-
case PM_DEVICE_STATE_SUSPENDED:
183+
switch (action) {
184+
case PM_DEVICE_ACTION_SUSPEND:
185185
ret = arc_v2_irq_unit_suspend(dev);
186186
break;
187-
case PM_DEVICE_STATE_ACTIVE:
187+
case PM_DEVICE_ACTION_RESUME:
188188
ret = arc_v2_irq_unit_resume(dev);
189189
break;
190190
default:

drivers/interrupt_controller/intc_ioapic.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ int ioapic_resume_from_suspend(const struct device *port)
310310
*/
311311
__pinned_func
312312
static int ioapic_device_ctrl(const struct device *dev,
313-
enum pm_device_state state)
313+
enum pm_device_action action)
314314
{
315315
int ret = 0;
316316

317-
switch (state) {
318-
case PM_DEVICE_STATE_ACTIVE:
317+
switch (action) {
318+
case PM_DEVICE_ACTION_RESUME:
319319
ret = ioapic_resume_from_suspend(dev);
320320
break;
321-
case PM_DEVICE_STATE_SUSPENDED:
321+
case PM_DEVICE_ACTION_SUSPEND:
322322
ret = ioapic_suspend(dev);
323323
break;
324324
default:

drivers/interrupt_controller/intc_loapic.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,15 +409,15 @@ int loapic_resume(const struct device *port)
409409
*/
410410
__pinned_func
411411
static int loapic_device_ctrl(const struct device *dev,
412-
enum pm_device_state state)
412+
enum pm_device_action action)
413413
{
414414
int ret = 0;
415415

416-
switch (state) {
417-
case PM_DEVICE_STATE_SUSPENDED:
416+
switch (action) {
417+
case PM_DEVICE_ACTION_SUSPEND:
418418
ret = loapic_suspend(dev);
419419
break;
420-
case PM_DEVICE_STATE_ACTIVE:
420+
case PM_DEVICE_ACTION_RESUME:
421421
ret = loapic_resume(dev);
422422
break;
423423
default:

drivers/led/led_pwm.c

+16-2
Original file line numberDiff line numberDiff line change
@@ -115,17 +115,31 @@ static int led_pwm_init(const struct device *dev)
115115

116116
#ifdef CONFIG_PM_DEVICE
117117
static int led_pwm_pm_control(const struct device *dev,
118-
enum pm_device_state state)
118+
enum pm_device_action action)
119119
{
120120
const struct led_pwm_config *config = DEV_CFG(dev);
121121

122122
/* switch all underlying PWM devices to the new state */
123123
for (size_t i = 0; i < config->num_leds; i++) {
124+
int err;
125+
enum pm_device_state state;
124126
const struct led_pwm *led_pwm = &config->led[i];
125127

126128
LOG_DBG("Switching PWM %p to state %" PRIu32, led_pwm->dev, state);
127-
int err = pm_device_state_set(led_pwm->dev, state);
128129

130+
/* NOTE: temporary solution, deserves proper fix */
131+
switch (action) {
132+
case PM_DEVICE_ACTION_RESUME:
133+
state = PM_DEVICE_STATE_ACTIVE;
134+
break;
135+
case PM_DEVICE_ACTION_SUSPEND:
136+
state = PM_DEVICE_STATE_SUSPENDED;
137+
break;
138+
default:
139+
return -ENOTSUP;
140+
}
141+
142+
err = pm_device_state_set(led_pwm->dev, state);
129143
if (err) {
130144
LOG_ERR("Cannot switch PWM %p power state", led_pwm->dev);
131145
}

drivers/pwm/pwm_nrfx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -292,15 +292,15 @@ static void pwm_nrfx_uninit(const struct device *dev)
292292
}
293293

294294
static int pwm_nrfx_pm_control(const struct device *dev,
295-
enum pm_device_state state)
295+
enum pm_device_action action)
296296
{
297297
int err = 0;
298298

299-
switch (state) {
300-
case PM_DEVICE_STATE_ACTIVE:
299+
switch (action) {
300+
case PM_DEVICE_ACTION_RESUME:
301301
err = pwm_nrfx_init(dev);
302302
break;
303-
case PM_DEVICE_STATE_SUSPENDED:
303+
case PM_DEVICE_ACTION_SUSPEND:
304304
pwm_nrfx_uninit(dev);
305305
break;
306306
default:

drivers/sensor/apds9960/apds9960.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -409,22 +409,22 @@ static int apds9960_init_interrupt(const struct device *dev)
409409

410410
#ifdef CONFIG_PM_DEVICE
411411
static int apds9960_device_ctrl(const struct device *dev,
412-
enum pm_device_state state)
412+
enum pm_device_action action)
413413
{
414414
const struct apds9960_config *config = dev->config;
415415
struct apds9960_data *data = dev->data;
416416
int ret = 0;
417417

418-
switch (state) {
419-
case PM_DEVICE_STATE_ACTIVE:
418+
switch (action) {
419+
case PM_DEVICE_ACTION_RESUME:
420420
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
421421
APDS9960_ENABLE_REG,
422422
APDS9960_ENABLE_PON,
423423
APDS9960_ENABLE_PON)) {
424424
ret = -EIO;
425425
}
426426
break;
427-
case PM_DEVICE_STATE_SUSPENDED:
427+
case PM_DEVICE_ACTION_SUSPEND:
428428
if (i2c_reg_update_byte(data->i2c, config->i2c_address,
429429
APDS9960_ENABLE_REG,
430430
APDS9960_ENABLE_PON, 0)) {

drivers/sensor/bme280/bme280.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -410,16 +410,16 @@ static int bme280_chip_init(const struct device *dev)
410410
}
411411

412412
#ifdef CONFIG_PM_DEVICE
413-
int bme280_pm_ctrl(const struct device *dev, enum pm_device_state state)
413+
int bme280_pm_ctrl(const struct device *dev, enum pm_device_action action)
414414
{
415415
int ret = 0;
416416

417-
switch (state) {
418-
case PM_DEVICE_STATE_ACTIVE:
417+
switch (action) {
418+
case PM_DEVICE_ACTION_RESUME:
419419
/* Re-initialize the chip */
420420
ret = bme280_chip_init(dev);
421421
break;
422-
case PM_DEVICE_STATE_SUSPENDED:
422+
case PM_DEVICE_ACTION_SUSPEND:
423423
/* Put the chip into sleep mode */
424424
ret = bme280_reg_write(dev,
425425
BME280_REG_CTRL_MEAS,

0 commit comments

Comments
 (0)