@@ -525,6 +525,143 @@ static int espi_promt0_setup(const struct device *dev)
525
525
526
526
#endif /* CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD */
527
527
528
+ /*
529
+ * =========================================================================
530
+ * ESPI Peripheral Channel Read/Write API
531
+ * =========================================================================
532
+ */
533
+
534
+ #ifdef CONFIG_ESPI_PERIPHERAL_CHANNEL
535
+
536
+ static void espi_periph_ch_isr (const struct device * dev )
537
+ {
538
+ const struct espi_rts5912_config * const espi_config = dev -> config ;
539
+ struct espi_rts5912_data * data = dev -> data ;
540
+
541
+ struct espi_event evt = {.evt_type = ESPI_BUS_EVENT_CHANNEL_READY ,
542
+ .evt_details = ESPI_CHANNEL_PERIPHERAL ,
543
+ .evt_data = 0 };
544
+
545
+ volatile struct espi_reg * const espi_reg = espi_config -> espi_reg ;
546
+
547
+ uint32_t status = espi_reg -> EPSTS ;
548
+ uint32_t config = espi_reg -> EPCFG ;
549
+
550
+ if (status & ESPI_EPSTS_CLRSTS ) {
551
+ evt .evt_data = config & ESPI_EPCFG_CHEN ? 1 : 0 ;
552
+ espi_send_callbacks (& data -> callbacks , dev , evt );
553
+
554
+ espi_reg -> EPSTS = ESPI_EPSTS_CLRSTS ;
555
+ }
556
+ }
557
+
558
+ static int lpc_request_read_custom (const struct espi_rts5912_config * const espi_config ,
559
+ enum lpc_peripheral_opcode op , uint32_t * data )
560
+ {
561
+ #ifdef CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE
562
+ switch (op ) {
563
+ case ECUSTOM_HOST_CMD_GET_PARAM_MEMORY :
564
+ * data = (uint32_t )ec_host_cmd_sram ;
565
+ break ;
566
+ case ECUSTOM_HOST_CMD_GET_PARAM_MEMORY_SIZE :
567
+ * data = ESPI_RTK_PERIPHERAL_HOST_CMD_PARAM_SIZE ;
568
+ break ;
569
+ default :
570
+ return - EINVAL ;
571
+ }
572
+
573
+ return 0 ;
574
+ #else
575
+ return - ENOTSUP ;
576
+ #endif
577
+ }
578
+
579
+ static int espi_rts5912_read_lpc_request (const struct device * dev , enum lpc_peripheral_opcode op ,
580
+ uint32_t * data )
581
+ {
582
+ const struct espi_rts5912_config * const espi_config = dev -> config ;
583
+
584
+ if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE ) {
585
+ return lpc_request_read_8042 (dev , op , data );
586
+ } else if (op >= EACPI_START_OPCODE && op <= EACPI_MAX_OPCODE ) {
587
+ return lpc_request_read_acpi (espi_config , op , data );
588
+ } else if (op >= ECUSTOM_START_OPCODE && op <= ECUSTOM_MAX_OPCODE ) {
589
+ return lpc_request_read_custom (espi_config , op , data );
590
+ } else {
591
+ return - ENOTSUP ;
592
+ }
593
+ }
594
+
595
+ static int lpc_request_write_custom (const struct espi_rts5912_config * const espi_config ,
596
+ enum lpc_peripheral_opcode op , uint32_t * data )
597
+ {
598
+ #ifdef CONFIG_ESPI_PERIPHERAL_CUSTOM_OPCODE
599
+ volatile struct acpi_reg * const promt0_reg = espi_config -> promt0_reg ;
600
+
601
+ switch (op ) {
602
+ case ECUSTOM_HOST_SUBS_INTERRUPT_EN :
603
+ if (* data == 0 ) {
604
+ NVIC_DisableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), promt0_ibf , irq )));
605
+ NVIC_DisableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), acpi_ibf , irq )));
606
+ NVIC_DisableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), port80 , irq )));
607
+ NVIC_DisableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), kbc_ibf , irq )));
608
+ NVIC_DisableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), kbc_obe , irq )));
609
+
610
+ } else {
611
+ NVIC_EnableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), promt0_ibf , irq )));
612
+ NVIC_EnableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), acpi_ibf , irq )));
613
+ NVIC_EnableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), port80 , irq )));
614
+ NVIC_EnableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), kbc_ibf , irq )));
615
+ NVIC_EnableIRQ ((DT_IRQ_BY_NAME (DT_DRV_INST (0 ), kbc_obe , irq )));
616
+ }
617
+ break ;
618
+ case ECUSTOM_HOST_CMD_SEND_RESULT :
619
+ promt0_reg -> STS &= ~ACPI_STS_STS0 ;
620
+ promt0_reg -> OB = * data & 0xff ;
621
+ break ;
622
+ default :
623
+ return - EINVAL ;
624
+ }
625
+
626
+ return 0 ;
627
+ #else
628
+ return - ENOTSUP ;
629
+ #endif
630
+ }
631
+
632
+ static int espi_rts5912_write_lpc_request (const struct device * dev , enum lpc_peripheral_opcode op ,
633
+ uint32_t * data )
634
+ {
635
+ const struct espi_rts5912_config * const espi_config = dev -> config ;
636
+
637
+ if (op >= E8042_START_OPCODE && op <= E8042_MAX_OPCODE ) {
638
+ return lpc_request_write_8042 (dev , op , data );
639
+ } else if (op >= EACPI_START_OPCODE && op <= EACPI_MAX_OPCODE ) {
640
+ return lpc_request_write_acpi (espi_config , op , data );
641
+ } else if (op >= ECUSTOM_START_OPCODE && op <= ECUSTOM_MAX_OPCODE ) {
642
+ return lpc_request_write_custom (espi_config , op , data );
643
+ } else {
644
+ return - ENOTSUP ;
645
+ }
646
+ }
647
+
648
+ static void espi_periph_ch_setup (const struct device * dev )
649
+ {
650
+ const struct espi_rts5912_config * const espi_config = dev -> config ;
651
+ volatile struct espi_reg * const espi_reg = espi_config -> espi_reg ;
652
+
653
+ espi_reg -> EPINTEN = ESPI_EPINTEN_CFGCHGEN | ESPI_EPINTEN_MEMWREN | ESPI_EPINTEN_MEMRDEN ;
654
+
655
+ NVIC_ClearPendingIRQ (DT_IRQ_BY_NAME (DT_DRV_INST (0 ), periph_ch , irq ));
656
+
657
+ IRQ_CONNECT (DT_IRQ_BY_NAME (DT_DRV_INST (0 ), periph_ch , irq ),
658
+ DT_IRQ_BY_NAME (DT_DRV_INST (0 ), periph_ch , priority ), espi_periph_ch_isr ,
659
+ DEVICE_DT_GET (DT_DRV_INST (0 )), 0 );
660
+ irq_enable (DT_IRQ_BY_NAME (DT_DRV_INST (0 ), periph_ch , irq ));
661
+ }
662
+
663
+ #endif /* CONFIG_ESPI_PERIPHERAL_CHANNEL */
664
+
528
665
/*
529
666
* =========================================================================
530
667
* ESPI Peripheral Debug Port 80
@@ -2075,6 +2212,10 @@ static DEVICE_API(espi, espi_rts5912_driver_api) = {
2075
2212
.config = espi_rts5912_configure ,
2076
2213
.get_channel_status = espi_rts5912_channel_ready ,
2077
2214
.manage_callback = espi_rts5912_manage_callback ,
2215
+ #ifdef CONFIG_ESPI_PERIPHERAL_CHANNEL
2216
+ .read_lpc_request = espi_rts5912_read_lpc_request ,
2217
+ .write_lpc_request = espi_rts5912_write_lpc_request ,
2218
+ #endif
2078
2219
#ifdef CONFIG_ESPI_VWIRE_CHANNEL
2079
2220
.send_vwire = espi_rts5912_send_vwire ,
2080
2221
.receive_vwire = espi_rts5912_receive_vwire ,
@@ -2225,6 +2366,11 @@ static int espi_rts5912_init(const struct device *dev)
2225
2366
}
2226
2367
#endif
2227
2368
2369
+ #ifdef CONFIG_ESPI_PERIPHERAL_CHANNEL
2370
+ /* Setup eSPI peripheral channel */
2371
+ espi_periph_ch_setup (dev );
2372
+ #endif
2373
+
2228
2374
#ifdef CONFIG_ESPI_VWIRE_CHANNEL
2229
2375
/* Setup eSPI virtual-wire channel */
2230
2376
espi_vw_ch_setup (dev );
0 commit comments