@@ -1403,6 +1403,64 @@ static inline bool spi_stm32_is_subghzspi(const struct device *dev)
1403
1403
#endif /* st_stm32_spi_subghz */
1404
1404
}
1405
1405
1406
+ #ifdef CONFIG_PM_DEVICE
1407
+ static int spi_stm32_pm_action (const struct device * dev ,
1408
+ enum pm_device_action action )
1409
+ {
1410
+ const struct spi_stm32_config * config = dev -> config ;
1411
+ const struct device * const clk = DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE );
1412
+ int err ;
1413
+
1414
+
1415
+ switch (action ) {
1416
+ case PM_DEVICE_ACTION_RESUME :
1417
+ if (!spi_stm32_is_subghzspi (dev )) {
1418
+ /* Set pins to active state */
1419
+ err = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_DEFAULT );
1420
+ if (err < 0 ) {
1421
+ return err ;
1422
+ }
1423
+ }
1424
+
1425
+ /* enable clock */
1426
+ err = clock_control_on (clk , (clock_control_subsys_t )& config -> pclken [0 ]);
1427
+ if (err != 0 ) {
1428
+ LOG_ERR ("Could not enable SPI clock" );
1429
+ return err ;
1430
+ }
1431
+ break ;
1432
+ case PM_DEVICE_ACTION_SUSPEND :
1433
+ /* Stop device clock. */
1434
+ err = clock_control_off (clk , (clock_control_subsys_t )& config -> pclken [0 ]);
1435
+ if (err != 0 ) {
1436
+ LOG_ERR ("Could not disable SPI clock" );
1437
+ return err ;
1438
+ }
1439
+
1440
+ if (!spi_stm32_is_subghzspi (dev )) {
1441
+ /* Move pins to sleep state */
1442
+ err = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_SLEEP );
1443
+ if ((err < 0 ) && (err != - ENOENT )) {
1444
+ /*
1445
+ * If returning -ENOENT, no pins where defined for sleep mode :
1446
+ * Do not output on console (might sleep already) when going to
1447
+ * sleep,
1448
+ * "SPI pinctrl sleep state not available"
1449
+ * and don't block PM suspend.
1450
+ * Else return the error.
1451
+ */
1452
+ return err ;
1453
+ }
1454
+ }
1455
+ break ;
1456
+ default :
1457
+ return - ENOTSUP ;
1458
+ }
1459
+
1460
+ return 0 ;
1461
+ }
1462
+ #endif /* CONFIG_PM_DEVICE */
1463
+
1406
1464
static int spi_stm32_init (const struct device * dev )
1407
1465
{
1408
1466
struct spi_stm32_data * data __attribute__((unused )) = dev -> data ;
@@ -1471,64 +1529,6 @@ static int spi_stm32_init(const struct device *dev)
1471
1529
return pm_device_runtime_enable (dev );
1472
1530
}
1473
1531
1474
- #ifdef CONFIG_PM_DEVICE
1475
- static int spi_stm32_pm_action (const struct device * dev ,
1476
- enum pm_device_action action )
1477
- {
1478
- const struct spi_stm32_config * config = dev -> config ;
1479
- const struct device * const clk = DEVICE_DT_GET (STM32_CLOCK_CONTROL_NODE );
1480
- int err ;
1481
-
1482
-
1483
- switch (action ) {
1484
- case PM_DEVICE_ACTION_RESUME :
1485
- if (!spi_stm32_is_subghzspi (dev )) {
1486
- /* Set pins to active state */
1487
- err = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_DEFAULT );
1488
- if (err < 0 ) {
1489
- return err ;
1490
- }
1491
- }
1492
-
1493
- /* enable clock */
1494
- err = clock_control_on (clk , (clock_control_subsys_t )& config -> pclken [0 ]);
1495
- if (err != 0 ) {
1496
- LOG_ERR ("Could not enable SPI clock" );
1497
- return err ;
1498
- }
1499
- break ;
1500
- case PM_DEVICE_ACTION_SUSPEND :
1501
- /* Stop device clock. */
1502
- err = clock_control_off (clk , (clock_control_subsys_t )& config -> pclken [0 ]);
1503
- if (err != 0 ) {
1504
- LOG_ERR ("Could not disable SPI clock" );
1505
- return err ;
1506
- }
1507
-
1508
- if (!spi_stm32_is_subghzspi (dev )) {
1509
- /* Move pins to sleep state */
1510
- err = pinctrl_apply_state (config -> pcfg , PINCTRL_STATE_SLEEP );
1511
- if ((err < 0 ) && (err != - ENOENT )) {
1512
- /*
1513
- * If returning -ENOENT, no pins where defined for sleep mode :
1514
- * Do not output on console (might sleep already) when going to
1515
- * sleep,
1516
- * "SPI pinctrl sleep state not available"
1517
- * and don't block PM suspend.
1518
- * Else return the error.
1519
- */
1520
- return err ;
1521
- }
1522
- }
1523
- break ;
1524
- default :
1525
- return - ENOTSUP ;
1526
- }
1527
-
1528
- return 0 ;
1529
- }
1530
- #endif /* CONFIG_PM_DEVICE */
1531
-
1532
1532
#ifdef CONFIG_SPI_STM32_INTERRUPT
1533
1533
#define STM32_SPI_IRQ_HANDLER_DECL (id ) \
1534
1534
static void spi_stm32_irq_config_func_##id(const struct device *dev)
0 commit comments