@@ -525,6 +525,143 @@ static int espi_promt0_setup(const struct device *dev)
525525
526526#endif /* CONFIG_ESPI_PERIPHERAL_EC_HOST_CMD */
527527
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+
528665/*
529666 * =========================================================================
530667 * ESPI Peripheral Debug Port 80
@@ -2075,6 +2212,10 @@ static DEVICE_API(espi, espi_rts5912_driver_api) = {
20752212 .config = espi_rts5912_configure ,
20762213 .get_channel_status = espi_rts5912_channel_ready ,
20772214 .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
20782219#ifdef CONFIG_ESPI_VWIRE_CHANNEL
20792220 .send_vwire = espi_rts5912_send_vwire ,
20802221 .receive_vwire = espi_rts5912_receive_vwire ,
@@ -2225,6 +2366,11 @@ static int espi_rts5912_init(const struct device *dev)
22252366 }
22262367#endif
22272368
2369+ #ifdef CONFIG_ESPI_PERIPHERAL_CHANNEL
2370+ /* Setup eSPI peripheral channel */
2371+ espi_periph_ch_setup (dev );
2372+ #endif
2373+
22282374#ifdef CONFIG_ESPI_VWIRE_CHANNEL
22292375 /* Setup eSPI virtual-wire channel */
22302376 espi_vw_ch_setup (dev );
0 commit comments