1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2014-2025 MediaTek Inc.
4 *
5 * Author: Maoguang Meng <maoguang.meng@mediatek.com>
6 * Sean Wang <sean.wang@mediatek.com>
7 * Hao Chang <ot_chhao.chang@mediatek.com>
8 * Qingliang Li <qingliang.li@mediatek.com>
9 */
10 #ifndef __MTK_EINT_H
11 #define __MTK_EINT_H
12
13 #include <linux/irqdomain.h>
14
15 struct mtk_eint_regs {
16 unsigned int stat;
17 unsigned int ack;
18 unsigned int mask;
19 unsigned int mask_set;
20 unsigned int mask_clr;
21 unsigned int sens;
22 unsigned int sens_set;
23 unsigned int sens_clr;
24 unsigned int soft;
25 unsigned int soft_set;
26 unsigned int soft_clr;
27 unsigned int pol;
28 unsigned int pol_set;
29 unsigned int pol_clr;
30 unsigned int dom_en;
31 unsigned int dbnc_ctrl;
32 unsigned int dbnc_set;
33 unsigned int dbnc_clr;
34 };
35
36 struct mtk_eint_hw {
37 u8 port_mask;
38 u8 ports;
39 unsigned int ap_num;
40 unsigned int db_cnt;
41 const unsigned int *db_time;
42 };
43
44 struct mtk_eint_pin {
45 u16 number;
46 u8 instance;
47 u8 index;
48 bool debounce;
49 bool dual_edge;
50 };
51
52 extern const unsigned int debounce_time_mt2701[];
53 extern const unsigned int debounce_time_mt6765[];
54 extern const unsigned int debounce_time_mt6795[];
55 extern const unsigned int debounce_time_mt6878[];
56
57 struct mtk_eint;
58
59 struct mtk_eint_xt {
60 int (*get_gpio_n)(void *data, unsigned long eint_n,
61 unsigned int *gpio_n,
62 struct gpio_chip **gpio_chip);
63 int (*get_gpio_state)(void *data, unsigned long eint_n);
64 int (*set_gpio_as_eint)(void *data, unsigned long eint_n);
65 };
66
67 struct mtk_eint {
68 struct device *dev;
69 void __iomem **base;
70 int nbase;
71 u16 *base_pin_num;
72 struct irq_domain *domain;
73 int irq;
74
75 int *dual_edge;
76 u16 **pin_list;
77 u32 **wake_mask;
78 u32 **cur_mask;
79
80 /* Used to fit into various EINT device */
81 const struct mtk_eint_hw *hw;
82 const struct mtk_eint_regs *regs;
83 struct mtk_eint_pin *pins;
84 u16 num_db_time;
85
86 /* Used to fit into various pinctrl device */
87 void *pctl;
88 const struct mtk_eint_xt *gpio_xlate;
89 };
90
91 #if IS_ENABLED(CONFIG_EINT_MTK)
92 int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin);
93 int mtk_eint_do_suspend(struct mtk_eint *eint);
94 int mtk_eint_do_resume(struct mtk_eint *eint);
95 int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
96 unsigned int debounce);
97 int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n);
98
99 #else
mtk_eint_do_init(struct mtk_eint * eint,struct mtk_eint_pin * eint_pin)100 static inline int mtk_eint_do_init(struct mtk_eint *eint,
101 struct mtk_eint_pin *eint_pin)
102 {
103 return -EOPNOTSUPP;
104 }
105
mtk_eint_do_suspend(struct mtk_eint * eint)106 static inline int mtk_eint_do_suspend(struct mtk_eint *eint)
107 {
108 return -EOPNOTSUPP;
109 }
110
mtk_eint_do_resume(struct mtk_eint * eint)111 static inline int mtk_eint_do_resume(struct mtk_eint *eint)
112 {
113 return -EOPNOTSUPP;
114 }
115
mtk_eint_set_debounce(struct mtk_eint * eint,unsigned long eint_n,unsigned int debounce)116 static inline int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
117 unsigned int debounce)
118 {
119 return -EOPNOTSUPP;
120 }
121
mtk_eint_find_irq(struct mtk_eint * eint,unsigned long eint_n)122 static inline int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n)
123 {
124 return -EOPNOTSUPP;
125 }
126 #endif
127 #endif /* __MTK_EINT_H */
128