1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef __PINCTRL_MTK_COMMON_H
16#define __PINCTRL_MTK_COMMON_H
17
18#include <linux/pinctrl/pinctrl.h>
19#include <linux/regmap.h>
20
21#define NO_EINT_SUPPORT 255
22#define MTK_CHIP_TYPE_BASE 0
23#define MTK_CHIP_TYPE_PMIC 1
24#define MT_EDGE_SENSITIVE 0
25#define MT_LEVEL_SENSITIVE 1
26#define EINT_DBNC_SET_DBNC_BITS 4
27#define EINT_DBNC_RST_BIT (0x1 << 1)
28#define EINT_DBNC_SET_EN (0x1 << 0)
29
30struct mtk_desc_function {
31 const char *name;
32 unsigned char muxval;
33};
34
35struct mtk_desc_eint {
36 unsigned char eintmux;
37 unsigned char eintnum;
38};
39
40struct mtk_desc_pin {
41 struct pinctrl_pin_desc pin;
42 const char *chip;
43 const struct mtk_desc_eint eint;
44 const struct mtk_desc_function *functions;
45};
46
47#define MTK_PIN(_pin, _pad, _chip, _eint, ...) \
48 { \
49 .pin = _pin, \
50 .chip = _chip, \
51 .eint = _eint, \
52 .functions = (struct mtk_desc_function[]){ \
53 __VA_ARGS__, { } }, \
54 }
55
56#define MTK_EINT_FUNCTION(_eintmux, _eintnum) \
57 { \
58 .eintmux = _eintmux, \
59 .eintnum = _eintnum, \
60 }
61
62#define MTK_FUNCTION(_val, _name) \
63 { \
64 .muxval = _val, \
65 .name = _name, \
66 }
67
68#define SET_ADDR(x, y) (x + (y->devdata->port_align))
69#define CLR_ADDR(x, y) (x + (y->devdata->port_align << 1))
70
71struct mtk_pinctrl_group {
72 const char *name;
73 unsigned long config;
74 unsigned pin;
75};
76
77
78
79
80
81
82
83
84
85struct mtk_drv_group_desc {
86 unsigned char min_drv;
87 unsigned char max_drv;
88 unsigned char low_bit;
89 unsigned char high_bit;
90 unsigned char step;
91};
92
93#define MTK_DRV_GRP(_min, _max, _low, _high, _step) \
94 { \
95 .min_drv = _min, \
96 .max_drv = _max, \
97 .low_bit = _low, \
98 .high_bit = _high, \
99 .step = _step, \
100 }
101
102
103
104
105
106
107
108
109struct mtk_pin_drv_grp {
110 unsigned int pin;
111 unsigned int offset;
112 unsigned char bit;
113 unsigned char grp;
114};
115
116#define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp) \
117 { \
118 .pin = _pin, \
119 .offset = _offset, \
120 .bit = _bit, \
121 .grp = _grp, \
122 }
123
124struct mtk_eint_offsets {
125 const char *name;
126 unsigned int stat;
127 unsigned int ack;
128 unsigned int mask;
129 unsigned int mask_set;
130 unsigned int mask_clr;
131 unsigned int sens;
132 unsigned int sens_set;
133 unsigned int sens_clr;
134 unsigned int soft;
135 unsigned int soft_set;
136 unsigned int soft_clr;
137 unsigned int pol;
138 unsigned int pol_set;
139 unsigned int pol_clr;
140 unsigned int dom_en;
141 unsigned int dbnc_ctrl;
142 unsigned int dbnc_set;
143 unsigned int dbnc_clr;
144 u8 port_mask;
145 u8 ports;
146};
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179struct mtk_pinctrl_devdata {
180 const struct mtk_desc_pin *pins;
181 unsigned int npins;
182 const struct mtk_drv_group_desc *grp_desc;
183 unsigned int n_grp_cls;
184 const struct mtk_pin_drv_grp *pin_drv_grp;
185 unsigned int n_pin_drv_grps;
186 int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
187 unsigned char align, bool isup, unsigned int arg);
188 int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
189 unsigned char align, int value);
190 unsigned int dir_offset;
191 unsigned int ies_offset;
192 unsigned int smt_offset;
193 unsigned int pullen_offset;
194 unsigned int pullsel_offset;
195 unsigned int drv_offset;
196 unsigned int invser_offset;
197 unsigned int dout_offset;
198 unsigned int din_offset;
199 unsigned int pinmux_offset;
200 unsigned short type1_start;
201 unsigned short type1_end;
202 unsigned char port_shf;
203 unsigned char port_mask;
204 unsigned char port_align;
205 unsigned char chip_type;
206 struct mtk_eint_offsets eint_offsets;
207 unsigned int ap_num;
208 unsigned int db_cnt;
209};
210
211struct mtk_pinctrl {
212 struct regmap *regmap1;
213 struct regmap *regmap2;
214 struct device *dev;
215 struct gpio_chip *chip;
216 struct mtk_pinctrl_group *groups;
217 unsigned ngroups;
218 const char **grp_names;
219 struct pinctrl_dev *pctl_dev;
220 const struct mtk_pinctrl_devdata *devdata;
221 void __iomem *eint_reg_base;
222 struct irq_domain *domain;
223 int *eint_dual_edges;
224};
225
226int mtk_pctrl_init(struct platform_device *pdev,
227 const struct mtk_pinctrl_devdata *data);
228
229#endif
230