Skip to content

Commit cc2f0e9

Browse files
gmarullnashif
authored andcommitted
pm: use enum for device PM states
Move all PM_DEVICE_STATE_* definitions to an enum. The PM_DEVICE_STATE_SET and PM_DEVICE_STATE_GET definitions have been kept out of the enum since they do not represent any state. However, their name has not been changed since they will be removed soon. All drivers and tests have been adjusted accordingly. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent 59d07b0 commit cc2f0e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+214
-231
lines changed

drivers/display/display_st7735r.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ struct st7735r_data {
6868
uint16_t x_offset;
6969
uint16_t y_offset;
7070
#ifdef CONFIG_PM_DEVICE
71-
uint32_t pm_state;
71+
enum pm_device_state pm_state;
7272
#endif
7373
};
7474

@@ -520,14 +520,15 @@ static int st7735r_enter_sleep(struct st7735r_data *data)
520520
}
521521

522522
static int st7735r_pm_control(const struct device *dev, uint32_t ctrl_command,
523-
uint32_t *state, pm_device_cb cb, void *arg)
523+
enum pm_device_state *state,
524+
pm_device_cb cb, void *arg)
524525
{
525526
int ret = 0;
526527
struct st7735r_data *data = (struct st7735r_data *)dev->data;
527528

528529
switch (ctrl_command) {
529530
case PM_DEVICE_STATE_SET:
530-
if (*((uint32_t *)context) == PM_DEVICE_STATE_ACTIVE) {
531+
if (*state == PM_DEVICE_STATE_ACTIVE) {
531532
ret = st7735r_exit_sleep(data);
532533
if (ret < 0) {
533534
return ret;

drivers/display/display_st7789v.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct st7789v_data {
5353
uint16_t x_offset;
5454
uint16_t y_offset;
5555
#ifdef CONFIG_PM_DEVICE
56-
uint32_t pm_state;
56+
enum pm_device_state pm_state;
5757
#endif
5858
};
5959

@@ -409,7 +409,7 @@ static void st7789v_enter_sleep(struct st7789v_data *data)
409409
}
410410

411411
static int st7789v_pm_control(const struct device *dev, uint32_t ctrl_command,
412-
uint32_t *state, pm_device_cb cb, void *arg)
412+
enum pm_device_state *state, pm_device_cb cb, void *arg)
413413
{
414414
int ret = 0;
415415
struct st7789v_data *data = (struct st7789v_data *)dev->data;

drivers/entropy/entropy_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct entropy_cc13xx_cc26xx_data {
3737
bool constrained;
3838
#endif
3939
#ifdef CONFIG_PM_DEVICE
40-
uint32_t pm_state;
40+
enum device_pm_state pm_state;
4141
#endif
4242
};
4343

@@ -268,7 +268,7 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
268268

269269
#ifdef CONFIG_PM_DEVICE
270270
static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
271-
uint32_t new_state)
271+
enum pm_device_state new_state)
272272
{
273273
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
274274
int ret = 0;
@@ -294,14 +294,14 @@ static int entropy_cc13xx_cc26xx_set_power_state(const struct device *dev,
294294

295295
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
296296
uint32_t ctrl_command,
297-
uint32_t *state, pm_device_cb cb,
297+
enum pm_device_state *state, pm_device_cb cb,
298298
void *arg)
299299
{
300300
struct entropy_cc13xx_cc26xx_data *data = get_dev_data(dev);
301301
int ret = 0;
302302

303303
if (ctrl_command == PM_DEVICE_STATE_SET) {
304-
uint32_t new_state = *state;
304+
enum pm_device_state new_state = *state;
305305

306306
if (new_state != data->pm_state) {
307307
ret = entropy_cc13xx_cc26xx_set_power_state(dev,

drivers/ethernet/eth_mcux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ void eth_mcux_phy_stop(struct eth_context *context);
186186

187187
static int eth_mcux_device_pm_control(const struct device *dev,
188188
uint32_t command,
189-
uint32_t *state, pm_device_cb cb,
189+
enum pm_device_state *state, pm_device_cb cb,
190190
void *arg)
191191
{
192192
struct eth_context *eth_ctx = (struct eth_context *)dev->data;

drivers/flash/spi_flash_at45.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct spi_flash_at45_data {
6161
struct spi_cs_control spi_cs;
6262
struct k_sem lock;
6363
#if IS_ENABLED(CONFIG_PM_DEVICE)
64-
uint32_t pm_state;
64+
enum pm_device_state pm_state;
6565
#endif
6666
};
6767

@@ -629,15 +629,15 @@ static int spi_flash_at45_init(const struct device *dev)
629629
#if IS_ENABLED(CONFIG_PM_DEVICE)
630630
static int spi_flash_at45_pm_control(const struct device *dev,
631631
uint32_t ctrl_command,
632-
uint32_t *state, pm_device_cb cb,
632+
enum pm_device_state *state, pm_device_cb cb,
633633
void *arg)
634634
{
635635
struct spi_flash_at45_data *dev_data = get_dev_data(dev);
636636
const struct spi_flash_at45_config *dev_config = get_dev_config(dev);
637637
int err = 0;
638638

639639
if (ctrl_command == PM_DEVICE_STATE_SET) {
640-
uint32_t new_state = *state;
640+
enum pm_device_state new_state = *state;
641641

642642
if (new_state != dev_data->pm_state) {
643643
switch (new_state) {

drivers/gpio/gpio_dw.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ static inline int gpio_dw_resume_from_suspend_port(const struct device *port)
461461
*/
462462
static int gpio_dw_device_ctrl(const struct device *port,
463463
uint32_t ctrl_command,
464-
uint32_t *state, pm_device_cb cb, void *arg)
464+
enum pm_device_state *state, pm_device_cb cb, void *arg)
465465
{
466466
int ret = 0;
467467

drivers/gpio/gpio_dw.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct gpio_dw_runtime {
4242
#endif
4343
sys_slist_t callbacks;
4444
#ifdef CONFIG_PM_DEVICE
45-
uint32_t device_power_state;
45+
enum pm_device_state device_power_state;
4646
#endif
4747
};
4848

drivers/gpio/gpio_stm32.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ static uint32_t gpio_stm32_get_power_state(const struct device *dev)
581581
}
582582

583583
static int gpio_stm32_set_power_state(const struct device *dev,
584-
uint32_t new_state)
584+
enum pm_device_state new_state)
585585
{
586586
struct gpio_stm32_data *data = dev->data;
587587
int ret = 0;
@@ -605,7 +605,7 @@ static int gpio_stm32_set_power_state(const struct device *dev,
605605

606606
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
607607
uint32_t ctrl_command,
608-
uint32_t *state, pm_device_cb cb, void *arg)
608+
enum pm_device_state *state, pm_device_cb cb, void *arg)
609609
{
610610
struct gpio_stm32_data *data = dev->data;
611611
uint32_t new_state;

drivers/gpio/gpio_stm32.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ struct gpio_stm32_data {
231231
sys_slist_t cb;
232232
#ifdef CONFIG_PM_DEVICE
233233
/* device power state */
234-
uint32_t power_state;
234+
enum pm_device_state power_state;
235235
#endif
236236
};
237237

drivers/i2c/i2c_cc13xx_cc26xx.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct i2c_cc13xx_cc26xx_data {
3333
uint32_t dev_config;
3434
#endif
3535
#ifdef CONFIG_PM_DEVICE
36-
uint32_t pm_state;
36+
enum pm_device_state pm_state;
3737
#endif
3838
};
3939

@@ -330,7 +330,7 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
330330

331331
#ifdef CONFIG_PM_DEVICE
332332
static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
333-
uint32_t new_state)
333+
enum pm_device_state new_state)
334334
{
335335
int ret = 0;
336336

@@ -369,13 +369,13 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
369369

370370
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
371371
uint32_t ctrl_command,
372-
uint32_t *state, pm_device_cb cb,
372+
enum pm_device_state *state, pm_device_cb cb,
373373
void *arg)
374374
{
375375
int ret = 0;
376376

377377
if (ctrl_command == PM_DEVICE_STATE_SET) {
378-
uint32_t new_state = *state;
378+
enum pm_device_state new_state = *state;
379379

380380
if (new_state != get_dev_data(dev)->pm_state) {
381381
ret = i2c_cc13xx_cc26xx_set_power_state(dev,

drivers/i2c/i2c_nrfx_twi.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct i2c_nrfx_twi_data {
2020
volatile nrfx_err_t res;
2121
uint32_t dev_config;
2222
#ifdef CONFIG_PM_DEVICE
23-
uint32_t pm_state;
23+
enum pm_device_state pm_state;
2424
#endif
2525
};
2626

@@ -224,13 +224,13 @@ static int init_twi(const struct device *dev)
224224
#ifdef CONFIG_PM_DEVICE
225225
static int twi_nrfx_pm_control(const struct device *dev,
226226
uint32_t ctrl_command,
227-
uint32_t *state, pm_device_cb cb, void *arg)
227+
enum pm_device_state *state, pm_device_cb cb, void *arg)
228228
{
229229
int ret = 0;
230-
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
230+
enum pm_device_state pm_current_state = get_dev_data(dev)->pm_state;
231231

232232
if (ctrl_command == PM_DEVICE_STATE_SET) {
233-
uint32_t new_state = *state;
233+
enum pm_device_state new_state = *state;
234234

235235
if (new_state != pm_current_state) {
236236
switch (new_state) {

drivers/i2c/i2c_nrfx_twim.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct i2c_nrfx_twim_data {
2323
uint16_t concat_buf_size;
2424
uint8_t *concat_buf;
2525
#ifdef CONFIG_PM_DEVICE
26-
uint32_t pm_state;
26+
enum pm_device_state pm_state;
2727
#endif
2828
};
2929

@@ -263,13 +263,13 @@ static int init_twim(const struct device *dev)
263263
#ifdef CONFIG_PM_DEVICE
264264
static int twim_nrfx_pm_control(const struct device *dev,
265265
uint32_t ctrl_command,
266-
uint32_t *state, pm_device_cb cb, void *arg)
266+
enum pm_device_state *state, pm_device_cb cb, void *arg)
267267
{
268268
int ret = 0;
269-
uint32_t pm_current_state = get_dev_data(dev)->pm_state;
269+
enum pm_device_state pm_current_state = get_dev_data(dev)->pm_state;
270270

271271
if (ctrl_command == PM_DEVICE_STATE_SET) {
272-
uint32_t new_state = *state;
272+
enum pm_device_state new_state = *state;
273273

274274
if (new_state != pm_current_state) {
275275
switch (new_state) {

drivers/interrupt_controller/intc_arcv2_irq_unit.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,17 @@ static int arc_v2_irq_unit_get_state(const struct device *dev)
192192
* @return operation result
193193
*/
194194
static int arc_v2_irq_unit_device_ctrl(const struct device *dev,
195-
uint32_t ctrl_command, uint32_t *context,
195+
uint32_t ctrl_command,
196+
enum pm_device_state *state,
196197
pm_device_cb cb, void *arg)
197198
{
198199
int ret = 0;
199200
unsigned int key = arch_irq_lock();
200201

201202
if (ctrl_command == PM_DEVICE_STATE_SET) {
202-
if (*((uint32_t *)context) == PM_DEVICE_STATE_SUSPEND) {
203+
if (*state == PM_DEVICE_STATE_SUSPEND) {
203204
ret = arc_v2_irq_unit_suspend(dev);
204-
} else if (*((uint32_t *)context) == PM_DEVICE_STATE_ACTIVE) {
205+
} else if (*state == PM_DEVICE_STATE_ACTIVE) {
205206
ret = arc_v2_irq_unit_resume(dev);
206207
}
207208
} else if (ctrl_command == PM_DEVICE_STATE_GET) {

drivers/interrupt_controller/intc_ioapic.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -315,14 +315,13 @@ int ioapic_resume_from_suspend(const struct device *port)
315315
__pinned_func
316316
static int ioapic_device_ctrl(const struct device *dev,
317317
uint32_t ctrl_command,
318-
uint32_t *context, pm_device_cb cb, void *arg)
318+
enum pm_device_state *state,
319+
pm_device_cb cb, void *arg)
319320
{
320321
int ret = 0;
321322

322323
if (ctrl_command == PM_DEVICE_STATE_SET) {
323-
uint32_t new_state = *((uint32_t *)context);
324-
325-
switch (new_state) {
324+
switch (*state) {
326325
case PM_DEVICE_STATE_LOW_POWER:
327326
break;
328327
case PM_DEVICE_STATE_ACTIVE:
@@ -341,14 +340,14 @@ static int ioapic_device_ctrl(const struct device *dev,
341340
}
342341

343342
if (ret == 0) {
344-
ioapic_device_power_state = new_state;
343+
ioapic_device_power_state = *state;
345344
}
346345
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
347-
*((uint32_t *)context) = ioapic_device_power_state;
346+
*state = ioapic_device_power_state;
348347
}
349348

350349
if (cb) {
351-
cb(dev, ret, context, arg);
350+
cb(dev, ret, state, arg);
352351
}
353352

354353
return ret;

drivers/interrupt_controller/intc_loapic.c

+6-5
Original file line numberDiff line numberDiff line change
@@ -414,22 +414,23 @@ int loapic_resume(const struct device *port)
414414
__pinned_func
415415
static int loapic_device_ctrl(const struct device *port,
416416
uint32_t ctrl_command,
417-
uint32_t *context, pm_device_cb cb, void *arg)
417+
enum pm_device_state *state, pm_device_cb cb,
418+
void *arg)
418419
{
419420
int ret = 0;
420421

421422
if (ctrl_command == PM_DEVICE_STATE_SET) {
422-
if (*context == PM_DEVICE_STATE_SUSPEND) {
423+
if (*state == PM_DEVICE_STATE_SUSPEND) {
423424
ret = loapic_suspend(port);
424-
} else if (*context == PM_DEVICE_STATE_ACTIVE) {
425+
} else if (*state == PM_DEVICE_STATE_ACTIVE) {
425426
ret = loapic_resume(port);
426427
}
427428
} else if (ctrl_command == PM_DEVICE_STATE_GET) {
428-
*context = loapic_device_power_state;
429+
*state = loapic_device_power_state;
429430
}
430431

431432
if (cb) {
432-
cb(port, ret, context, arg);
433+
cb(port, ret, state, arg);
433434
}
434435

435436
return ret;

drivers/led/led_pwm.c

+7-5
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct led_pwm_config {
3737

3838
struct led_pwm_data {
3939
#ifdef CONFIG_PM_DEVICE
40-
uint32_t pm_state;
40+
enum pm_device_state pm_state;
4141
#endif
4242
};
4343

@@ -128,7 +128,8 @@ static int led_pwm_init(const struct device *dev)
128128

129129
#ifdef CONFIG_PM_DEVICE
130130

131-
static int led_pwm_pm_get_state(const struct device *dev, uint32_t *state)
131+
static int led_pwm_pm_get_state(const struct device *dev,
132+
enum pm_device_state *state)
132133
{
133134
struct led_pwm_data *data = DEV_DATA(dev);
134135

@@ -139,11 +140,12 @@ static int led_pwm_pm_get_state(const struct device *dev, uint32_t *state)
139140
return 0;
140141
}
141142

142-
static int led_pwm_pm_set_state(const struct device *dev, uint32_t new_state)
143+
static int led_pwm_pm_set_state(const struct device *dev,
144+
enum pm_device_state new_state)
143145
{
144146
const struct led_pwm_config *config = DEV_CFG(dev);
145147
struct led_pwm_data *data = DEV_DATA(dev);
146-
uint32_t old_state;
148+
enum pm_device_state old_state;
147149
unsigned int key;
148150

149151
key = irq_lock();
@@ -176,7 +178,7 @@ static int led_pwm_pm_set_state(const struct device *dev, uint32_t new_state)
176178
}
177179

178180
static int led_pwm_pm_control(const struct device *dev, uint32_t ctrl_command,
179-
uint32_t *state, pm_device_cb cb, void *arg)
181+
enum pm_device_state *state, pm_device_cb cb, void *arg)
180182
{
181183
int err;
182184

0 commit comments

Comments
 (0)