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