1
2
3
4
5
6
7 #ifndef __PINCTRL_MTK_COMMON_H
8 #define __PINCTRL_MTK_COMMON_H
9
10 #include <linux/pinctrl/pinctrl.h>
11 #include <linux/regmap.h>
12 #include <linux/pinctrl/pinconf-generic.h>
13
14 #include "mtk-eint.h"
15
16 #define NO_EINT_SUPPORT 255
17 #define MT_EDGE_SENSITIVE 0
18 #define MT_LEVEL_SENSITIVE 1
19 #define EINT_DBNC_SET_DBNC_BITS 4
20 #define EINT_DBNC_RST_BIT (0x1 << 1)
21 #define EINT_DBNC_SET_EN (0x1 << 0)
22
23 #define MTK_PINCTRL_NOT_SUPPORT (0xffff)
24
25 struct mtk_desc_function {
26 const char *name;
27 unsigned char muxval;
28 };
29
30 struct mtk_desc_eint {
31 unsigned char eintmux;
32 unsigned char eintnum;
33 };
34
35 struct mtk_desc_pin {
36 struct pinctrl_pin_desc pin;
37 const struct mtk_desc_eint eint;
38 const struct mtk_desc_function *functions;
39 };
40
41 #define MTK_PIN(_pin, _pad, _chip, _eint, ...) \
42 { \
43 .pin = _pin, \
44 .eint = _eint, \
45 .functions = (struct mtk_desc_function[]){ \
46 __VA_ARGS__, { } }, \
47 }
48
49 #define MTK_EINT_FUNCTION(_eintmux, _eintnum) \
50 { \
51 .eintmux = _eintmux, \
52 .eintnum = _eintnum, \
53 }
54
55 #define MTK_FUNCTION(_val, _name) \
56 { \
57 .muxval = _val, \
58 .name = _name, \
59 }
60
61 #define SET_ADDR(x, y) (x + (y->devdata->port_align))
62 #define CLR_ADDR(x, y) (x + (y->devdata->port_align << 1))
63
64 struct mtk_pinctrl_group {
65 const char *name;
66 unsigned long config;
67 unsigned pin;
68 };
69
70
71
72
73
74
75
76
77
78 struct mtk_drv_group_desc {
79 unsigned char min_drv;
80 unsigned char max_drv;
81 unsigned char low_bit;
82 unsigned char high_bit;
83 unsigned char step;
84 };
85
86 #define MTK_DRV_GRP(_min, _max, _low, _high, _step) \
87 { \
88 .min_drv = _min, \
89 .max_drv = _max, \
90 .low_bit = _low, \
91 .high_bit = _high, \
92 .step = _step, \
93 }
94
95
96
97
98
99
100
101
102 struct mtk_pin_drv_grp {
103 unsigned short pin;
104 unsigned short offset;
105 unsigned char bit;
106 unsigned char grp;
107 };
108
109 #define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp) \
110 { \
111 .pin = _pin, \
112 .offset = _offset, \
113 .bit = _bit, \
114 .grp = _grp, \
115 }
116
117
118
119
120
121
122
123
124
125
126 struct mtk_pin_spec_pupd_set_samereg {
127 unsigned short pin;
128 unsigned short offset;
129 unsigned char pupd_bit;
130 unsigned char r1_bit;
131 unsigned char r0_bit;
132 };
133
134 #define MTK_PIN_PUPD_SPEC_SR(_pin, _offset, _pupd, _r1, _r0) \
135 { \
136 .pin = _pin, \
137 .offset = _offset, \
138 .pupd_bit = _pupd, \
139 .r1_bit = _r1, \
140 .r0_bit = _r0, \
141 }
142
143
144
145
146
147
148
149
150 struct mtk_pin_ies_smt_set {
151 unsigned short start;
152 unsigned short end;
153 unsigned short offset;
154 unsigned char bit;
155 };
156
157 #define MTK_PIN_IES_SMT_SPEC(_start, _end, _offset, _bit) \
158 { \
159 .start = _start, \
160 .end = _end, \
161 .bit = _bit, \
162 .offset = _offset, \
163 }
164
165 struct mtk_eint_offsets {
166 const char *name;
167 unsigned int stat;
168 unsigned int ack;
169 unsigned int mask;
170 unsigned int mask_set;
171 unsigned int mask_clr;
172 unsigned int sens;
173 unsigned int sens_set;
174 unsigned int sens_clr;
175 unsigned int soft;
176 unsigned int soft_set;
177 unsigned int soft_clr;
178 unsigned int pol;
179 unsigned int pol_set;
180 unsigned int pol_clr;
181 unsigned int dom_en;
182 unsigned int dbnc_ctrl;
183 unsigned int dbnc_set;
184 unsigned int dbnc_clr;
185 u8 port_mask;
186 u8 ports;
187 };
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227 struct mtk_pinctrl_devdata {
228 const struct mtk_desc_pin *pins;
229 unsigned int npins;
230 const struct mtk_drv_group_desc *grp_desc;
231 unsigned int n_grp_cls;
232 const struct mtk_pin_drv_grp *pin_drv_grp;
233 unsigned int n_pin_drv_grps;
234 int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
235 unsigned char align, bool isup, unsigned int arg);
236 int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
237 unsigned char align, int value, enum pin_config_param arg);
238 void (*spec_pinmux_set)(struct regmap *reg, unsigned int pin,
239 unsigned int mode);
240 void (*spec_dir_set)(unsigned int *reg_addr, unsigned int pin);
241 unsigned int dir_offset;
242 unsigned int ies_offset;
243 unsigned int smt_offset;
244 unsigned int pullen_offset;
245 unsigned int pullsel_offset;
246 unsigned int drv_offset;
247 unsigned int dout_offset;
248 unsigned int din_offset;
249 unsigned int pinmux_offset;
250 unsigned short type1_start;
251 unsigned short type1_end;
252 unsigned char port_shf;
253 unsigned char port_mask;
254 unsigned char port_align;
255 struct mtk_eint_hw eint_hw;
256 struct mtk_eint_regs *eint_regs;
257 };
258
259 struct mtk_pinctrl {
260 struct regmap *regmap1;
261 struct regmap *regmap2;
262 struct pinctrl_desc pctl_desc;
263 struct device *dev;
264 struct gpio_chip *chip;
265 struct mtk_pinctrl_group *groups;
266 unsigned ngroups;
267 const char **grp_names;
268 struct pinctrl_dev *pctl_dev;
269 const struct mtk_pinctrl_devdata *devdata;
270 struct mtk_eint *eint;
271 };
272
273 int mtk_pctrl_init(struct platform_device *pdev,
274 const struct mtk_pinctrl_devdata *data,
275 struct regmap *regmap);
276
277 int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
278 const struct mtk_pin_spec_pupd_set_samereg *pupd_infos,
279 unsigned int info_num, unsigned int pin,
280 unsigned char align, bool isup, unsigned int r1r0);
281
282 int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
283 const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
284 unsigned int pin, unsigned char align, int value);
285
286 extern const struct dev_pm_ops mtk_eint_pm_ops;
287
288 #endif