@@ -23,6 +23,13 @@ LOG_MODULE_REGISTER(espi, CONFIG_ESPI_LOG_LEVEL);
23
23
#include "reg/reg_kbc.h"
24
24
#include "reg/reg_port80.h"
25
25
26
+ #ifdef CONFIG_PM
27
+ #include "reg/reg_gpio.h"
28
+ #include <zephyr/pm/device.h>
29
+ #include <zephyr/pm/policy.h>
30
+ #include "reg/reg_system.h"
31
+ #endif
32
+
26
33
BUILD_ASSERT (DT_NUM_INST_STATUS_OKAY (DT_DRV_COMPAT ) == 1 , "support only one espi compatible node" );
27
34
28
35
struct espi_rts5912_config {
@@ -56,6 +63,9 @@ struct espi_rts5912_config {
56
63
volatile struct port80_reg * const port80_reg ;
57
64
uint32_t port80_clk_grp ;
58
65
uint32_t port80_clk_idx ;
66
+ #endif
67
+ #ifdef CONFIG_PM
68
+ struct gpio_dt_spec cs_pin ;
59
69
#endif
60
70
const struct device * clk_dev ;
61
71
const struct pinctrl_dev_config * pcfg ;
@@ -1197,7 +1207,6 @@ static void notify_host_warning(const struct device *dev, enum espi_vwire_signal
1197
1207
uint8_t status = 0 ;
1198
1208
1199
1209
espi_rts5912_receive_vwire (dev , signal , & status );
1200
- k_busy_wait (200 );
1201
1210
1202
1211
switch (signal ) {
1203
1212
case ESPI_VWIRE_SIGNAL_SUS_WARN :
@@ -1394,8 +1403,6 @@ static int espi_rts5912_send_vwire(const struct device *dev, enum espi_vwire_sig
1394
1403
static int espi_rts5912_receive_vwire (const struct device * dev , enum espi_vwire_signal signal ,
1395
1404
uint8_t * level )
1396
1405
{
1397
- const struct espi_rts5912_config * const espi_config = dev -> config ;
1398
- volatile struct espi_reg * const espi_reg = espi_config -> espi_reg ;
1399
1406
uint8_t vw_idx , lev_msk , valid_msk ;
1400
1407
uint8_t vw_data ;
1401
1408
@@ -1412,9 +1419,6 @@ static int espi_rts5912_receive_vwire(const struct device *dev, enum espi_vwire_
1412
1419
vw_data = espi_vw_ch_cached_data .idx2 ;
1413
1420
break ;
1414
1421
case VW_CH_IDX3 :
1415
- if (espi_vw_ch_cached_data .idx3 != espi_reg -> EVIDX3 ) {
1416
- espi_vw_ch_cached_data .idx3 = espi_reg -> EVIDX3 ;
1417
- }
1418
1422
vw_data = espi_vw_ch_cached_data .idx3 ;
1419
1423
break ;
1420
1424
case VW_CH_IDX4 :
@@ -1427,60 +1431,33 @@ static int espi_rts5912_receive_vwire(const struct device *dev, enum espi_vwire_
1427
1431
vw_data = espi_vw_tx_cached_data .idx6 ;
1428
1432
break ;
1429
1433
case VW_CH_IDX7 :
1430
- if (espi_vw_ch_cached_data .idx7 != espi_reg -> EVIDX7 ) {
1431
- espi_vw_ch_cached_data .idx7 = espi_reg -> EVIDX7 ;
1432
- }
1433
1434
vw_data = espi_vw_ch_cached_data .idx7 ;
1434
1435
break ;
1435
1436
case VW_CH_IDX40 :
1436
1437
vw_data = espi_vw_tx_cached_data .idx40 ;
1437
1438
break ;
1438
1439
case VW_CH_IDX41 :
1439
- if (espi_vw_ch_cached_data .idx41 != espi_reg -> EVIDX41 ) {
1440
- espi_vw_ch_cached_data .idx41 = espi_reg -> EVIDX41 ;
1441
- }
1442
1440
vw_data = espi_vw_ch_cached_data .idx41 ;
1443
1441
break ;
1444
1442
case VW_CH_IDX42 :
1445
- if (espi_vw_ch_cached_data .idx42 != espi_reg -> EVIDX42 ) {
1446
- espi_vw_ch_cached_data .idx42 = espi_reg -> EVIDX42 ;
1447
- }
1448
1443
vw_data = espi_vw_ch_cached_data .idx42 ;
1449
1444
break ;
1450
1445
case VW_CH_IDX43 :
1451
- if (espi_vw_ch_cached_data .idx43 != espi_reg -> EVIDX43 ) {
1452
- espi_vw_ch_cached_data .idx43 = espi_reg -> EVIDX43 ;
1453
- }
1454
1446
vw_data = espi_vw_ch_cached_data .idx43 ;
1455
1447
break ;
1456
1448
case VW_CH_IDX44 :
1457
- if (espi_vw_ch_cached_data .idx44 != espi_reg -> EVIDX44 ) {
1458
- espi_vw_ch_cached_data .idx44 = espi_reg -> EVIDX44 ;
1459
- }
1460
1449
vw_data = espi_vw_ch_cached_data .idx44 ;
1461
1450
break ;
1462
1451
case VW_CH_IDX47 :
1463
- if (espi_vw_ch_cached_data .idx47 != espi_reg -> EVIDX47 ) {
1464
- espi_vw_ch_cached_data .idx47 = espi_reg -> EVIDX47 ;
1465
- }
1466
1452
vw_data = espi_vw_ch_cached_data .idx47 ;
1467
1453
break ;
1468
1454
case VW_CH_IDX4A :
1469
- if (espi_vw_ch_cached_data .idx4a != espi_reg -> EVIDX4A ) {
1470
- espi_vw_ch_cached_data .idx4a = espi_reg -> EVIDX4A ;
1471
- }
1472
1455
vw_data = espi_vw_ch_cached_data .idx4a ;
1473
1456
break ;
1474
1457
case VW_CH_IDX51 :
1475
- if (espi_vw_ch_cached_data .idx51 != espi_reg -> EVIDX51 ) {
1476
- espi_vw_ch_cached_data .idx51 = espi_reg -> EVIDX51 ;
1477
- }
1478
1458
vw_data = espi_vw_ch_cached_data .idx51 ;
1479
1459
break ;
1480
1460
case VW_CH_IDX61 :
1481
- if (espi_vw_ch_cached_data .idx61 != espi_reg -> EVIDX61 ) {
1482
- espi_vw_ch_cached_data .idx61 = espi_reg -> EVIDX61 ;
1483
- }
1484
1461
vw_data = espi_vw_ch_cached_data .idx61 ;
1485
1462
break ;
1486
1463
default :
@@ -2293,7 +2270,18 @@ static void espi_bus_reset_setup(const struct device *dev)
2293
2270
DEVICE_DT_GET (DT_DRV_INST (0 )), 0 );
2294
2271
irq_enable (DT_IRQ_BY_NAME (DT_DRV_INST (0 ), bus_rst , irq ));
2295
2272
}
2273
+ #ifdef CONFIG_PM
2274
+ void espi_cs_low_isr (const struct device * port , struct gpio_callback * cb , gpio_port_pins_t pins )
2275
+ {
2276
+ gpio_flags_t cs_pin_config ;
2296
2277
2278
+ gpio_pin_get_config (port , pins , & cs_pin_config );
2279
+ if (cs_pin_config & GPIO_INT_ENABLE ) {
2280
+ gpio_pin_interrupt_configure (port , (find_msb_set (pins ) - 1 ),
2281
+ GPIO_INT_MODE_DISABLED );
2282
+ }
2283
+ }
2284
+ #endif
2297
2285
static int espi_rts5912_init (const struct device * dev )
2298
2286
{
2299
2287
const struct espi_rts5912_config * const espi_config = dev -> config ;
@@ -2393,13 +2381,44 @@ static int espi_rts5912_init(const struct device *dev)
2393
2381
goto exit ;
2394
2382
}
2395
2383
#endif
2396
-
2384
+ #ifdef CONFIG_PM
2385
+ static struct gpio_callback cb ;
2386
+ uint32_t cs_irq_nun = DT_IRQ_BY_NAME (DT_DRV_INST (0 ), cs_low , irq );
2387
+
2388
+ NVIC_ClearPendingIRQ (cs_irq_nun );
2389
+ gpio_init_callback (& cb , espi_cs_low_isr , BIT (espi_config -> cs_pin .pin ));
2390
+ gpio_add_callback (espi_config -> cs_pin .port , & cb );
2391
+ irq_enable (cs_irq_nun );
2392
+ #endif
2397
2393
exit :
2398
2394
return rc ;
2399
2395
}
2396
+ #ifdef CONFIG_PM
2397
+ static inline int espi_rts5912_pm_action (const struct device * dev , enum pm_device_action action )
2398
+ {
2399
+ const struct espi_rts5912_config * const espi_config = dev -> config ;
2400
+ SYSTEM_Type * sys_reg = RTS5912_SCCON_REG_BASE ;
2400
2401
2401
- PINCTRL_DT_INST_DEFINE (0 );
2402
+ switch (action ) {
2403
+ case PM_DEVICE_ACTION_RESUME :
2404
+ sys_reg -> SLPCTRL &= ~SYSTEM_SLPCTRL_GPIOWKEN_Msk ;
2405
+ gpio_pin_interrupt_configure_dt (& espi_config -> cs_pin , GPIO_INT_MODE_DISABLED );
2406
+ break ;
2407
+ case PM_DEVICE_ACTION_SUSPEND :
2408
+ sys_reg -> SLPCTRL |= SYSTEM_SLPCTRL_GPIOWKEN_Msk ;
2409
+ gpio_pin_interrupt_configure_dt (& espi_config -> cs_pin ,
2410
+ GPIO_INT_MODE_EDGE | GPIO_INT_TRIG_LOW );
2411
+ break ;
2412
+ default :
2413
+ return - ENOTSUP ;
2414
+ }
2402
2415
2416
+ return 0 ;
2417
+ }
2418
+ PM_DEVICE_DT_INST_DEFINE (0 , espi_rts5912_pm_action );
2419
+ #endif
2420
+
2421
+ PINCTRL_DT_INST_DEFINE (0 );
2403
2422
static struct espi_rts5912_data espi_rts5912_data_0 ;
2404
2423
2405
2424
static const struct espi_rts5912_config espi_rts5912_config = {
@@ -2434,10 +2453,18 @@ static const struct espi_rts5912_config espi_rts5912_config = {
2434
2453
.port80_reg = (volatile struct port80_reg * const )DT_INST_REG_ADDR_BY_NAME (0 , port80 ),
2435
2454
.port80_clk_grp = DT_CLOCKS_CELL_BY_NAME (DT_DRV_INST (0 ), port80 , clk_grp ),
2436
2455
.port80_clk_idx = DT_CLOCKS_CELL_BY_NAME (DT_DRV_INST (0 ), port80 , clk_idx ),
2456
+ #endif
2457
+ #ifdef CONFIG_PM
2458
+ .cs_pin = GPIO_DT_SPEC_INST_GET (0 , cs_gpios ),
2437
2459
#endif
2438
2460
.clk_dev = DEVICE_DT_GET (DT_INST_CLOCKS_CTLR (0 )),
2439
2461
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET (0 ),
2440
2462
};
2441
-
2463
+ #ifdef CONFIG_PM
2464
+ DEVICE_DT_INST_DEFINE (0 , & espi_rts5912_init , PM_DEVICE_DT_INST_GET (0 ), & espi_rts5912_data_0 ,
2465
+ & espi_rts5912_config , PRE_KERNEL_2 , CONFIG_ESPI_INIT_PRIORITY ,
2466
+ & espi_rts5912_driver_api );
2467
+ #else
2442
2468
DEVICE_DT_INST_DEFINE (0 , & espi_rts5912_init , NULL , & espi_rts5912_data_0 , & espi_rts5912_config ,
2443
2469
PRE_KERNEL_2 , CONFIG_ESPI_INIT_PRIORITY , & espi_rts5912_driver_api );
2470
+ #endif
0 commit comments