Skip to content

Commit bb64ab5

Browse files
nzmichaelhDhiru Kholia
authored andcommitted
drivers: add the pfic interrupt controller
This commit adds the pfic interrupt controller driver for WCH CH32V003. Signed-off-by: Michael Hope <[email protected]> Signed-off-by: Dhiru Kholia <[email protected]>
1 parent f8bc6df commit bb64ab5

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

drivers/interrupt_controller/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ zephyr_library_sources_ifdef(CONFIG_NXP_PINT intc_nxp_pint.c)
4343
zephyr_library_sources_ifdef(CONFIG_RENESAS_RA_ICU intc_renesas_ra_icu.c)
4444
zephyr_library_sources_ifdef(CONFIG_NXP_IRQSTEER intc_nxp_irqsteer.c)
4545
zephyr_library_sources_ifdef(CONFIG_INTC_MTK_ADSP intc_mtk_adsp.c)
46+
zephyr_library_sources_ifdef(CONFIG_WCH_PFIC intc_wch_pfic.c)
4647

4748
if(CONFIG_INTEL_VTD_ICTL)
4849
zephyr_library_include_directories(${ZEPHYR_BASE}/arch/x86/include)

drivers/interrupt_controller/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,6 @@ source "drivers/interrupt_controller/Kconfig.nxp_irqsteer"
108108

109109
source "drivers/interrupt_controller/Kconfig.mtk_adsp"
110110

111+
source "drivers/interrupt_controller/Kconfig.wch_pfic"
112+
111113
endmenu
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024 Michael Hope
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config WCH_PFIC
5+
bool "WCH Programmable Fast Interrupt Controller (PFIC)"
6+
default y
7+
depends on DT_HAS_WCH_PFIC_ENABLED
8+
help
9+
Interrupt controller for WCH PFIC.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2024 Michael Hope
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT wch_pfic
8+
9+
#include <ch32_pfic.h>
10+
11+
#include <zephyr/arch/cpu.h>
12+
#include <zephyr/init.h>
13+
#include <zephyr/irq.h>
14+
#include <zephyr/kernel.h>
15+
16+
#define SEVONPEND (1 << 4)
17+
#define WFITOWFE (1 << 3)
18+
19+
void arch_irq_enable(unsigned int irq)
20+
{
21+
PFIC->IENR[irq / 32] = 1 << (irq % 32);
22+
}
23+
24+
void arch_irq_disable(unsigned int irq)
25+
{
26+
PFIC->IRER[irq / 32] |= 1 << (irq % 32);
27+
}
28+
29+
int arch_irq_is_enabled(unsigned int irq)
30+
{
31+
return ((PFIC->ISR[irq >> 5] & (1 << (irq & 0x1F))) != 0);
32+
}
33+
34+
static int pfic_init(void)
35+
{
36+
/* `wfi` is called with interrupts disabled. Configure the PFIC to wake up on any event,
37+
* including any interrupt.
38+
*/
39+
PFIC->SCTLR = SEVONPEND | WFITOWFE;
40+
return 0;
41+
}
42+
43+
SYS_INIT(pfic_init, PRE_KERNEL_1, CONFIG_INTC_INIT_PRIORITY);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2024 Michael Hope
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: WCH CH32V00x Programmable Fast Interrupt Controller (PFIC)
5+
6+
compatible: "wch,pfic"
7+
8+
include: [interrupt-controller.yaml, base.yaml]
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
"#interrupt-cells":
15+
const: 1
16+
17+
interrupt-cells:
18+
- irq

modules/hal_wch/ch32_pfic.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2024 Dhiru Kholia
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef _CH32_PFIC_H
8+
#define _CH32_PFIC_H
9+
10+
#ifdef CONFIG_SOC_CH32V003
11+
#include <ch32v003fun.h>
12+
#else
13+
#error "SoC not supported!"
14+
#endif
15+
16+
#endif

0 commit comments

Comments
 (0)