Skip to content

Commit 495672a

Browse files
gmarullnashif
authored andcommitted
pm: cleanup pm control callback implementations
- Return -ENOTSUP if the requested state is not supported - Remove redundant "noop style" functions. - Use switch everywhere to handle requested state (not necessary in all drivers, but better take off with consistency in place after current changes). Signed-off-by: Gerard Marull-Paretas <[email protected]>
1 parent d41dadc commit 495672a

File tree

33 files changed

+255
-326
lines changed

33 files changed

+255
-326
lines changed

drivers/display/display_st7735r.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -494,27 +494,22 @@ static int st7735r_init(const struct device *dev)
494494
}
495495

496496
#ifdef CONFIG_PM_DEVICE
497-
static int st7735r_enter_sleep(struct st7735r_data *data)
498-
{
499-
return st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0);
500-
}
501-
502497
static int st7735r_pm_control(const struct device *dev,
503498
enum pm_device_state state)
504499
{
505500
int ret = 0;
506501
struct st7735r_data *data = (struct st7735r_data *)dev->data;
507502

508-
if (state == PM_DEVICE_STATE_ACTIVE) {
503+
switch (state) {
504+
case PM_DEVICE_STATE_ACTIVE:
509505
ret = st7735r_exit_sleep(data);
510-
if (ret < 0) {
511-
return ret;
512-
}
513-
} else {
514-
ret = st7735r_enter_sleep(data);
515-
if (ret < 0) {
516-
return ret;
517-
}
506+
break;
507+
case PM_DEVICE_STATE_SUSPENDED:
508+
ret = st7735r_transmit(data, ST7735R_CMD_SLEEP_IN, NULL, 0);
509+
break;
510+
default:
511+
ret = -ENOTSUP;
512+
break;
518513
}
519514

520515
return ret;

drivers/display/display_st7789v.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -396,23 +396,25 @@ static int st7789v_init(const struct device *dev)
396396
}
397397

398398
#ifdef CONFIG_PM_DEVICE
399-
static void st7789v_enter_sleep(struct st7789v_data *data)
400-
{
401-
st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0);
402-
}
403-
404399
static int st7789v_pm_control(const struct device *dev,
405400
enum pm_device_state state)
406401
{
407402
struct st7789v_data *data = (struct st7789v_data *)dev->data;
403+
int ret = 0;
408404

409-
if (state == PM_DEVICE_STATE_ACTIVE) {
405+
switch (state) {
406+
case PM_DEVICE_STATE_ACTIVE:
410407
st7789v_exit_sleep(data);
411-
} else {
412-
st7789v_enter_sleep(data);
408+
break;
409+
case PM_DEVICE_STATE_SUSPENDED:
410+
ret = st7789v_transmit(data, ST7789V_CMD_SLEEP_IN, NULL, 0);
411+
break;
412+
default:
413+
ret = -ENOTSUP;
414+
break;
413415
}
414416

415-
return 0;
417+
return ret;
416418
}
417419
#endif /* CONFIG_PM_DEVICE */
418420

drivers/entropy/entropy_cc13xx_cc26xx.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,27 +264,26 @@ static int post_notify_fxn(unsigned int eventType, uintptr_t eventArg,
264264
#endif
265265

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

272-
if (state == PM_DEVICE_STATE_ACTIVE) {
272+
switch (state) {
273+
case PM_DEVICE_STATE_ACTIVE:
273274
Power_setDependency(PowerCC26XX_PERIPH_TRNG);
274275
start_trng(data);
275-
} else {
276+
break;
277+
case PM_DEVICE_STATE_SUSPENDED:
276278
stop_trng(data);
277279
Power_releaseDependency(PowerCC26XX_PERIPH_TRNG);
280+
break;
281+
default:
282+
return -ENOTSUP;
278283
}
279284

280285
return 0;
281286
}
282-
283-
static int entropy_cc13xx_cc26xx_pm_control(const struct device *dev,
284-
enum pm_device_state state)
285-
{
286-
return entropy_cc13xx_cc26xx_set_power_state(dev, state);
287-
}
288287
#endif /* CONFIG_PM_DEVICE */
289288

290289
static int entropy_cc13xx_cc26xx_init(const struct device *dev)

drivers/ethernet/eth_mcux.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ static int eth_mcux_device_pm_control(const struct device *dev,
197197
goto out;
198198
}
199199

200-
if (state == PM_DEVICE_STATE_SUSPENDED) {
200+
switch (state) {
201+
case PM_DEVICE_STATE_SUSPENDED:
201202
LOG_DBG("Suspending");
202203

203204
ret = net_if_suspend(eth_ctx->iface);
@@ -212,13 +213,18 @@ static int eth_mcux_device_pm_control(const struct device *dev,
212213
ENET_Deinit(eth_ctx->base);
213214
clock_control_off(eth_ctx->clock_dev,
214215
(clock_control_subsys_t)eth_ctx->clock);
215-
} else if (state == PM_DEVICE_STATE_ACTIVE) {
216+
break;
217+
case PM_DEVICE_STATE_ACTIVE:
216218
LOG_DBG("Resuming");
217219

218220
clock_control_on(eth_ctx->clock_dev,
219221
(clock_control_subsys_t)eth_ctx->clock);
220222
eth_mcux_init(dev);
221223
net_if_resume(eth_ctx->iface);
224+
break;
225+
default:
226+
ret = -ENOTSUP;
227+
break;
222228
}
223229

224230
out:

drivers/flash/spi_flash_at45.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ static int spi_flash_at45_pm_control(const struct device *dev,
637637
break;
638638

639639
case PM_DEVICE_STATE_SUSPENDED:
640+
__fallthrough;
640641
case PM_DEVICE_STATE_OFF:
641642
acquire(dev);
642643
power_down_op(dev,

drivers/gpio/gpio_dw.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -425,34 +425,25 @@ static inline int gpio_dw_manage_callback(const struct device *port,
425425
}
426426

427427
#ifdef CONFIG_PM_DEVICE
428-
static inline int gpio_dw_suspend_port(const struct device *port)
429-
{
430-
gpio_dw_clock_off(port);
431-
return 0;
432-
}
433-
434-
static inline int gpio_dw_resume_from_suspend_port(const struct device *port)
435-
{
436-
gpio_dw_clock_on(port);
437-
return 0;
438-
}
439-
440428
/*
441429
* Implements the driver control management functionality
442430
* the *context may include IN data or/and OUT data
443431
*/
444-
static int gpio_dw_device_ctrl(const struct device *port,
432+
static int gpio_dw_device_ctrl(const struct device *dev,
445433
enum pm_device_state state)
446434
{
447-
int ret = 0;
448-
449-
if (state == PM_DEVICE_STATE_SUSPENDED) {
450-
ret = gpio_dw_suspend_port(port);
451-
} else if (state == PM_DEVICE_STATE_ACTIVE) {
452-
ret = gpio_dw_resume_from_suspend_port(port);
435+
switch (state) {
436+
case PM_DEVICE_STATE_SUSPENDED:
437+
gpio_dw_clock_off(dev);
438+
break;
439+
case PM_DEVICE_STATE_ACTIVE:
440+
gpio_dw_clock_on(dev);
441+
break;
442+
default:
443+
return -ENOTSUP;
453444
}
454445

455-
return ret;
446+
return 0;
456447
}
457448
#endif
458449

drivers/gpio/gpio_stm32.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -574,29 +574,20 @@ static const struct gpio_driver_api gpio_stm32_driver = {
574574
};
575575

576576
#ifdef CONFIG_PM_DEVICE
577-
static int gpio_stm32_set_power_state(const struct device *dev,
578-
enum pm_device_state state)
577+
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
578+
enum pm_device_state state)
579579
{
580-
int ret = 0;
581-
582-
if (state == PM_DEVICE_STATE_ACTIVE) {
583-
ret = gpio_stm32_clock_request(dev, true);
584-
} else if (state == PM_DEVICE_STATE_SUSPENDED) {
585-
ret = gpio_stm32_clock_request(dev, false);
586-
}
587-
588-
if (ret < 0) {
589-
return ret;
580+
switch (state) {
581+
case PM_DEVICE_STATE_ACTIVE:
582+
return gpio_stm32_clock_request(dev, true);
583+
case PM_DEVICE_STATE_SUSPENDED:
584+
return gpio_stm32_clock_request(dev, false);
585+
default:
586+
return -ENOTSUP;
590587
}
591588

592589
return 0;
593590
}
594-
595-
static int gpio_stm32_pm_device_ctrl(const struct device *dev,
596-
enum pm_device_state state)
597-
{
598-
return gpio_stm32_set_power_state(dev, state);
599-
}
600591
#endif /* CONFIG_PM_DEVICE */
601592

602593

drivers/i2c/i2c_cc13xx_cc26xx.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,13 @@ static int postNotifyFxn(unsigned int eventType, uintptr_t eventArg,
326326
#endif
327327

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

334-
if (state == PM_DEVICE_STATE_ACTIVE) {
334+
switch (state) {
335+
case PM_DEVICE_STATE_ACTIVE:
335336
Power_setDependency(PowerCC26XX_PERIPH_I2C0);
336337
IOCPinTypeI2c(get_dev_config(dev)->base,
337338
get_dev_config(dev)->sda_pin,
@@ -341,7 +342,8 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
341342
if (ret == 0) {
342343
I2CMasterIntEnable(get_dev_config(dev)->base);
343344
}
344-
} else {
345+
break;
346+
case PM_DEVICE_STATE_SUSPENDED:
345347
I2CMasterIntDisable(get_dev_config(dev)->base);
346348
I2CMasterDisable(get_dev_config(dev)->base);
347349
/* Reset pin type to default GPIO configuration */
@@ -350,16 +352,13 @@ static int i2c_cc13xx_cc26xx_set_power_state(const struct device *dev,
350352
IOCPortConfigureSet(get_dev_config(dev)->sda_pin,
351353
IOC_PORT_GPIO, IOC_STD_OUTPUT);
352354
Power_releaseDependency(PowerCC26XX_PERIPH_I2C0);
355+
break;
356+
default:
357+
return -ENOTSUP;
353358
}
354359

355360
return ret;
356361
}
357-
358-
static int i2c_cc13xx_cc26xx_pm_control(const struct device *dev,
359-
enum pm_device_state state)
360-
{
361-
return i2c_cc13xx_cc26xx_set_power_state(dev, state);
362-
}
363362
#endif /* CONFIG_PM_DEVICE */
364363

365364
static int i2c_cc13xx_cc26xx_init(const struct device *dev)

drivers/i2c/i2c_nrfx_twi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static int twi_nrfx_pm_control(const struct device *dev,
231231
break;
232232

233233
case PM_DEVICE_STATE_SUSPENDED:
234+
__fallthrough;
234235
case PM_DEVICE_STATE_OFF:
235236
nrfx_twi_uninit(&get_dev_config(dev)->twi);
236237
break;

drivers/i2c/i2c_nrfx_twim.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ static int twim_nrfx_pm_control(const struct device *dev,
269269
break;
270270

271271
case PM_DEVICE_STATE_SUSPENDED:
272+
__fallthrough;
272273
case PM_DEVICE_STATE_OFF:
273274
nrfx_twim_uninit(&get_dev_config(dev)->twim);
274275
break;

0 commit comments

Comments
 (0)