xref: /linux/drivers/pinctrl/mediatek/mtk-eint.h (revision eafd95ea74846eda3e3eac6b2bb7f34619d8a6f8)
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 
56 struct mtk_eint;
57 
58 struct mtk_eint_xt {
59 	int (*get_gpio_n)(void *data, unsigned long eint_n,
60 			  unsigned int *gpio_n,
61 			  struct gpio_chip **gpio_chip);
62 	int (*get_gpio_state)(void *data, unsigned long eint_n);
63 	int (*set_gpio_as_eint)(void *data, unsigned long eint_n);
64 };
65 
66 struct mtk_eint {
67 	struct device *dev;
68 	void __iomem **base;
69 	int nbase;
70 	u16 *base_pin_num;
71 	struct irq_domain *domain;
72 	int irq;
73 
74 	int *dual_edge;
75 	u16 **pin_list;
76 	u32 **wake_mask;
77 	u32 **cur_mask;
78 
79 	/* Used to fit into various EINT device */
80 	const struct mtk_eint_hw *hw;
81 	const struct mtk_eint_regs *regs;
82 	struct mtk_eint_pin *pins;
83 	u16 num_db_time;
84 
85 	/* Used to fit into various pinctrl device */
86 	void *pctl;
87 	const struct mtk_eint_xt *gpio_xlate;
88 };
89 
90 #if IS_ENABLED(CONFIG_EINT_MTK)
91 int mtk_eint_do_init(struct mtk_eint *eint, struct mtk_eint_pin *eint_pin);
92 int mtk_eint_do_suspend(struct mtk_eint *eint);
93 int mtk_eint_do_resume(struct mtk_eint *eint);
94 int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
95 			  unsigned int debounce);
96 int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n);
97 
98 #else
mtk_eint_do_init(struct mtk_eint * eint,struct mtk_eint_pin * eint_pin)99 static inline int mtk_eint_do_init(struct mtk_eint *eint,
100 				   struct mtk_eint_pin *eint_pin)
101 {
102 	return -EOPNOTSUPP;
103 }
104 
mtk_eint_do_suspend(struct mtk_eint * eint)105 static inline int mtk_eint_do_suspend(struct mtk_eint *eint)
106 {
107 	return -EOPNOTSUPP;
108 }
109 
mtk_eint_do_resume(struct mtk_eint * eint)110 static inline int mtk_eint_do_resume(struct mtk_eint *eint)
111 {
112 	return -EOPNOTSUPP;
113 }
114 
mtk_eint_set_debounce(struct mtk_eint * eint,unsigned long eint_n,unsigned int debounce)115 static inline int mtk_eint_set_debounce(struct mtk_eint *eint, unsigned long eint_n,
116 			  unsigned int debounce)
117 {
118 	return -EOPNOTSUPP;
119 }
120 
mtk_eint_find_irq(struct mtk_eint * eint,unsigned long eint_n)121 static inline int mtk_eint_find_irq(struct mtk_eint *eint, unsigned long eint_n)
122 {
123 	return -EOPNOTSUPP;
124 }
125 #endif
126 #endif /* __MTK_EINT_H */
127