xref: /rk3399_ARM-atf/plat/mediatek/drivers/cirq/mt_cirq.h (revision cc76896d9e416b15548b2d6bf068e5d3f9b4064a)
1*cc76896dSRex-BC Chen /*
2*cc76896dSRex-BC Chen  * Copyright (c) 2020-2022, MediaTek Inc. All rights reserved.
3*cc76896dSRex-BC Chen  *
4*cc76896dSRex-BC Chen  * SPDX-License-Identifier: BSD-3-Clause
5*cc76896dSRex-BC Chen  */
6*cc76896dSRex-BC Chen 
7*cc76896dSRex-BC Chen #ifndef PLAT_MT_CIRQ_H
8*cc76896dSRex-BC Chen #define PLAT_MT_CIRQ_H
9*cc76896dSRex-BC Chen 
10*cc76896dSRex-BC Chen #include <stdint.h>
11*cc76896dSRex-BC Chen #include <platform_def.h>
12*cc76896dSRex-BC Chen 
13*cc76896dSRex-BC Chen enum {
14*cc76896dSRex-BC Chen 	IRQ_MASK_HEADER = 0xF1F1F1F1,
15*cc76896dSRex-BC Chen 	IRQ_MASK_FOOTER = 0xF2F2F2F2
16*cc76896dSRex-BC Chen };
17*cc76896dSRex-BC Chen 
18*cc76896dSRex-BC Chen struct mtk_irq_mask {
19*cc76896dSRex-BC Chen 	uint32_t header;	/* for error checking */
20*cc76896dSRex-BC Chen 	uint32_t mask0;
21*cc76896dSRex-BC Chen 	uint32_t mask1;
22*cc76896dSRex-BC Chen 	uint32_t mask2;
23*cc76896dSRex-BC Chen 	uint32_t mask3;
24*cc76896dSRex-BC Chen 	uint32_t mask4;
25*cc76896dSRex-BC Chen 	uint32_t mask5;
26*cc76896dSRex-BC Chen 	uint32_t mask6;
27*cc76896dSRex-BC Chen 	uint32_t mask7;
28*cc76896dSRex-BC Chen 	uint32_t mask8;
29*cc76896dSRex-BC Chen 	uint32_t mask9;
30*cc76896dSRex-BC Chen 	uint32_t mask10;
31*cc76896dSRex-BC Chen 	uint32_t mask11;
32*cc76896dSRex-BC Chen 	uint32_t mask12;
33*cc76896dSRex-BC Chen 	uint32_t footer;	/* for error checking */
34*cc76896dSRex-BC Chen };
35*cc76896dSRex-BC Chen 
36*cc76896dSRex-BC Chen /*
37*cc76896dSRex-BC Chen  * Define hardware register
38*cc76896dSRex-BC Chen  */
39*cc76896dSRex-BC Chen #define  CIRQ_STA_BASE         (SYS_CIRQ_BASE + U(0x000))
40*cc76896dSRex-BC Chen #define  CIRQ_ACK_BASE         (SYS_CIRQ_BASE + U(0x080))
41*cc76896dSRex-BC Chen #define  CIRQ_MASK_BASE        (SYS_CIRQ_BASE + U(0x100))
42*cc76896dSRex-BC Chen #define  CIRQ_MASK_SET_BASE    (SYS_CIRQ_BASE + U(0x180))
43*cc76896dSRex-BC Chen #define  CIRQ_MASK_CLR_BASE    (SYS_CIRQ_BASE + U(0x200))
44*cc76896dSRex-BC Chen #define  CIRQ_SENS_BASE        (SYS_CIRQ_BASE + U(0x280))
45*cc76896dSRex-BC Chen #define  CIRQ_SENS_SET_BASE    (SYS_CIRQ_BASE + U(0x300))
46*cc76896dSRex-BC Chen #define  CIRQ_SENS_CLR_BASE    (SYS_CIRQ_BASE + U(0x380))
47*cc76896dSRex-BC Chen #define  CIRQ_POL_BASE         (SYS_CIRQ_BASE + U(0x400))
48*cc76896dSRex-BC Chen #define  CIRQ_POL_SET_BASE     (SYS_CIRQ_BASE + U(0x480))
49*cc76896dSRex-BC Chen #define  CIRQ_POL_CLR_BASE     (SYS_CIRQ_BASE + U(0x500))
50*cc76896dSRex-BC Chen #define  CIRQ_CON              (SYS_CIRQ_BASE + U(0x600))
51*cc76896dSRex-BC Chen 
52*cc76896dSRex-BC Chen /*
53*cc76896dSRex-BC Chen  * Register placement
54*cc76896dSRex-BC Chen  */
55*cc76896dSRex-BC Chen #define  CIRQ_CON_EN_BITS           U(0)
56*cc76896dSRex-BC Chen #define  CIRQ_CON_EDGE_ONLY_BITS    U(1)
57*cc76896dSRex-BC Chen #define  CIRQ_CON_FLUSH_BITS        U(2)
58*cc76896dSRex-BC Chen #define  CIRQ_CON_SW_RST_BITS       U(20)
59*cc76896dSRex-BC Chen #define  CIRQ_CON_EVENT_BITS        U(31)
60*cc76896dSRex-BC Chen #define  CIRQ_CON_BITS_MASK         U(0x7)
61*cc76896dSRex-BC Chen 
62*cc76896dSRex-BC Chen /*
63*cc76896dSRex-BC Chen  * Register setting
64*cc76896dSRex-BC Chen  */
65*cc76896dSRex-BC Chen #define  CIRQ_CON_EN            U(0x1)
66*cc76896dSRex-BC Chen #define  CIRQ_CON_EDGE_ONLY     U(0x1)
67*cc76896dSRex-BC Chen #define  CIRQ_CON_FLUSH         U(0x1)
68*cc76896dSRex-BC Chen #define  CIRQ_SW_RESET          U(0x1)
69*cc76896dSRex-BC Chen 
70*cc76896dSRex-BC Chen /*
71*cc76896dSRex-BC Chen  * Define constant
72*cc76896dSRex-BC Chen  */
73*cc76896dSRex-BC Chen #define  CIRQ_CTRL_REG_NUM      ((CIRQ_IRQ_NUM + 31U) / 32U)
74*cc76896dSRex-BC Chen 
75*cc76896dSRex-BC Chen #define  MT_CIRQ_POL_NEG        U(0)
76*cc76896dSRex-BC Chen #define  MT_CIRQ_POL_POS        U(1)
77*cc76896dSRex-BC Chen 
78*cc76896dSRex-BC Chen #define IRQ_TO_CIRQ_NUM(irq)  ((irq) - (32U + CIRQ_SPI_START))
79*cc76896dSRex-BC Chen #define CIRQ_TO_IRQ_NUM(cirq) ((cirq) + (32U + CIRQ_SPI_START))
80*cc76896dSRex-BC Chen 
81*cc76896dSRex-BC Chen /* GIC sensitive */
82*cc76896dSRex-BC Chen #define SENS_EDGE	U(0x2)
83*cc76896dSRex-BC Chen #define SENS_LEVEL	U(0x1)
84*cc76896dSRex-BC Chen 
85*cc76896dSRex-BC Chen 
86*cc76896dSRex-BC Chen /*
87*cc76896dSRex-BC Chen  * Define function prototypes.
88*cc76896dSRex-BC Chen  */
89*cc76896dSRex-BC Chen int mt_cirq_test(void);
90*cc76896dSRex-BC Chen void mt_cirq_dump_reg(void);
91*cc76896dSRex-BC Chen int mt_irq_mask_restore(struct mtk_irq_mask *mask);
92*cc76896dSRex-BC Chen int mt_irq_mask_all(struct mtk_irq_mask *mask);
93*cc76896dSRex-BC Chen void mt_cirq_clone_gic(void);
94*cc76896dSRex-BC Chen void mt_cirq_enable(void);
95*cc76896dSRex-BC Chen void mt_cirq_flush(void);
96*cc76896dSRex-BC Chen void mt_cirq_disable(void);
97*cc76896dSRex-BC Chen void mt_irq_unmask_for_sleep_ex(uint32_t irq);
98*cc76896dSRex-BC Chen void set_wakeup_sources(uint32_t *list, uint32_t num_of_events);
99*cc76896dSRex-BC Chen void mt_cirq_sw_reset(void);
100*cc76896dSRex-BC Chen 
101*cc76896dSRex-BC Chen struct cirq_reg {
102*cc76896dSRex-BC Chen 	uint32_t reg_num;
103*cc76896dSRex-BC Chen 	uint32_t used;
104*cc76896dSRex-BC Chen 	uint32_t mask;
105*cc76896dSRex-BC Chen 	uint32_t pol;
106*cc76896dSRex-BC Chen 	uint32_t sen;
107*cc76896dSRex-BC Chen 	uint32_t pending;
108*cc76896dSRex-BC Chen 	uint32_t the_link;
109*cc76896dSRex-BC Chen };
110*cc76896dSRex-BC Chen 
111*cc76896dSRex-BC Chen struct cirq_events {
112*cc76896dSRex-BC Chen 	uint32_t num_reg;
113*cc76896dSRex-BC Chen 	uint32_t spi_start;
114*cc76896dSRex-BC Chen 	uint32_t num_of_events;
115*cc76896dSRex-BC Chen 	uint32_t *wakeup_events;
116*cc76896dSRex-BC Chen 	struct cirq_reg table[CIRQ_REG_NUM];
117*cc76896dSRex-BC Chen 	uint32_t dist_base;
118*cc76896dSRex-BC Chen 	uint32_t cirq_base;
119*cc76896dSRex-BC Chen 	uint32_t used_reg_head;
120*cc76896dSRex-BC Chen };
121*cc76896dSRex-BC Chen 
122*cc76896dSRex-BC Chen #endif /* PLAT_MT_CIRQ_H */
123