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