]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
10d33ecaf456286b0751848345b287b77c52a98c
[linux.git] / drivers / pinctrl / mediatek / pinctrl-mtk-common-v2.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2018 MediaTek Inc.
4  *
5  * Author: Sean Wang <sean.wang@mediatek.com>
6  *
7  */
8
9 #ifndef __PINCTRL_MTK_COMMON_V2_H
10 #define __PINCTRL_MTK_COMMON_V2_H
11
12 #include <linux/gpio/driver.h>
13
14 #define MTK_INPUT      0
15 #define MTK_OUTPUT     1
16 #define MTK_DISABLE    0
17 #define MTK_ENABLE     1
18 #define MTK_PULLDOWN   0
19 #define MTK_PULLUP     1
20
21 #define EINT_NA -1
22
23 #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs,      \
24                        _s_bit, _x_bits, _sz_reg, _fixed) {              \
25                 .s_pin = _s_pin,                                        \
26                 .e_pin = _e_pin,                                        \
27                 .i_base = _i_base,                                      \
28                 .s_addr = _s_addr,                                      \
29                 .x_addrs = _x_addrs,                                    \
30                 .s_bit = _s_bit,                                        \
31                 .x_bits = _x_bits,                                      \
32                 .sz_reg = _sz_reg,                                      \
33                 .fixed = _fixed,                                        \
34         }
35
36 #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)   \
37         PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit,    \
38                        _x_bits, 32, 0)
39
40 #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)  \
41         PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit,    \
42                        _x_bits, 32, 1)
43
44 /* List these attributes which could be modified for the pin */
45 enum {
46         PINCTRL_PIN_REG_MODE,
47         PINCTRL_PIN_REG_DIR,
48         PINCTRL_PIN_REG_DI,
49         PINCTRL_PIN_REG_DO,
50         PINCTRL_PIN_REG_SR,
51         PINCTRL_PIN_REG_SMT,
52         PINCTRL_PIN_REG_PD,
53         PINCTRL_PIN_REG_PU,
54         PINCTRL_PIN_REG_E4,
55         PINCTRL_PIN_REG_E8,
56         PINCTRL_PIN_REG_TDSEL,
57         PINCTRL_PIN_REG_RDSEL,
58         PINCTRL_PIN_REG_DRV,
59         PINCTRL_PIN_REG_PUPD,
60         PINCTRL_PIN_REG_R0,
61         PINCTRL_PIN_REG_R1,
62         PINCTRL_PIN_REG_IES,
63         PINCTRL_PIN_REG_PULLEN,
64         PINCTRL_PIN_REG_PULLSEL,
65         PINCTRL_PIN_REG_MAX,
66 };
67
68 /* Group the pins by the driving current */
69 enum {
70         DRV_FIXED,
71         DRV_GRP0,
72         DRV_GRP1,
73         DRV_GRP2,
74         DRV_GRP3,
75         DRV_GRP4,
76         DRV_GRP_MAX,
77 };
78
79 static const char * const mtk_default_register_base_names[] = {
80         "base",
81 };
82
83 /* struct mtk_pin_field - the structure that holds the information of the field
84  *                        used to describe the attribute for the pin
85  * @base:               the index pointing to the entry in base address list
86  * @offset:             the register offset relative to the base address
87  * @mask:               the mask used to filter out the field from the register
88  * @bitpos:             the start bit relative to the register
89  * @next:               the indication that the field would be extended to the
90                         next register
91  */
92 struct mtk_pin_field {
93         u8  index;
94         u32 offset;
95         u32 mask;
96         u8  bitpos;
97         u8  next;
98 };
99
100 /* struct mtk_pin_field_calc - the structure that holds the range providing
101  *                             the guide used to look up the relevant field
102  * @s_pin:              the start pin within the range
103  * @e_pin:              the end pin within the range
104  * @i_base:             the index pointing to the entry in base address list
105  * @s_addr:             the start address for the range
106  * @x_addrs:            the address distance between two consecutive registers
107  *                      within the range
108  * @s_bit:              the start bit for the first register within the range
109  * @x_bits:             the bit distance between two consecutive pins within
110  *                      the range
111  * @sz_reg:             the size of bits in a register
112  * @fixed:              the consecutive pins share the same bits with the 1st
113  *                      pin
114  */
115 struct mtk_pin_field_calc {
116         u16 s_pin;
117         u16 e_pin;
118         u8  i_base;
119         u32 s_addr;
120         u8  x_addrs;
121         u8  s_bit;
122         u8  x_bits;
123         u8  sz_reg;
124         u8  fixed;
125 };
126
127 /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
128  *                           determine which register the pin would make use of
129  *                           for certain pin attribute.
130  * @range:                   the start address for the range
131  * @nranges:                 the number of items in the range
132  */
133 struct mtk_pin_reg_calc {
134         const struct mtk_pin_field_calc *range;
135         unsigned int nranges;
136 };
137
138 /**
139  * struct mtk_func_desc - the structure that providing information
140  *                        all the funcs for this pin
141  * @name:               the name of function
142  * @muxval:             the mux to the function
143  */
144 struct mtk_func_desc {
145         const char *name;
146         u8 muxval;
147 };
148
149 /**
150  * struct mtk_eint_desc - the structure that providing information
151  *                             for eint data per pin
152  * @eint_m:             the eint mux for this pin
153  * @eitn_n:             the eint number for this pin
154  */
155 struct mtk_eint_desc {
156         u8 eint_m;
157         u16 eint_n;
158 };
159
160 /**
161  * struct mtk_pin_desc - the structure that providing information
162  *                             for each pin of chips
163  * @number:             unique pin number from the global pin number space
164  * @name:               name for this pin
165  * @eint:               the eint data for this pin
166  * @drv_n:              the index with the driving group
167  * @funcs:              all available functions for this pins (only used in
168  *                      those drivers compatible to pinctrl-mtk-common.c-like
169  *                      ones)
170  */
171 struct mtk_pin_desc {
172         unsigned int number;
173         const char *name;
174         struct mtk_eint_desc eint;
175         u8 drv_n;
176         struct mtk_func_desc *funcs;
177 };
178
179 struct mtk_pinctrl_group {
180         const char      *name;
181         unsigned long   config;
182         unsigned        pin;
183 };
184
185 struct mtk_pinctrl;
186
187 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
188 struct mtk_pin_soc {
189         const struct mtk_pin_reg_calc   *reg_cal;
190         const struct mtk_pin_desc       *pins;
191         unsigned int                    npins;
192         const struct group_desc         *grps;
193         unsigned int                    ngrps;
194         const struct function_desc      *funcs;
195         unsigned int                    nfuncs;
196         const struct mtk_eint_regs      *eint_regs;
197         const struct mtk_eint_hw        *eint_hw;
198
199         /* Specific parameters per SoC */
200         u8                              gpio_m;
201         bool                            ies_present;
202         const char * const              *base_names;
203         unsigned int                    nbase_names;
204
205         /* Specific pinconfig operations */
206         int (*bias_disable_set)(struct mtk_pinctrl *hw,
207                                 const struct mtk_pin_desc *desc);
208         int (*bias_disable_get)(struct mtk_pinctrl *hw,
209                                 const struct mtk_pin_desc *desc, int *res);
210         int (*bias_set)(struct mtk_pinctrl *hw,
211                         const struct mtk_pin_desc *desc, bool pullup);
212         int (*bias_get)(struct mtk_pinctrl *hw,
213                         const struct mtk_pin_desc *desc, bool pullup, int *res);
214
215         int (*drive_set)(struct mtk_pinctrl *hw,
216                          const struct mtk_pin_desc *desc, u32 arg);
217         int (*drive_get)(struct mtk_pinctrl *hw,
218                          const struct mtk_pin_desc *desc, int *val);
219
220         int (*adv_pull_set)(struct mtk_pinctrl *hw,
221                             const struct mtk_pin_desc *desc, bool pullup,
222                             u32 arg);
223         int (*adv_pull_get)(struct mtk_pinctrl *hw,
224                             const struct mtk_pin_desc *desc, bool pullup,
225                             u32 *val);
226
227         /* Specific driver data */
228         void                            *driver_data;
229 };
230
231 struct mtk_pinctrl {
232         struct pinctrl_dev              *pctrl;
233         void __iomem                    **base;
234         u8                              nbase;
235         struct device                   *dev;
236         struct gpio_chip                chip;
237         const struct mtk_pin_soc        *soc;
238         struct mtk_eint                 *eint;
239         struct mtk_pinctrl_group        *groups;
240         const char          **grp_names;
241 };
242
243 void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
244
245 int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
246                      int field, int value);
247 int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
248                      int field, int *value);
249
250 int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev);
251
252 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
253                                  const struct mtk_pin_desc *desc);
254 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
255                                  const struct mtk_pin_desc *desc, int *res);
256 int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
257                          const struct mtk_pin_desc *desc, bool pullup);
258 int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
259                          const struct mtk_pin_desc *desc, bool pullup,
260                          int *res);
261
262 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
263                                       const struct mtk_pin_desc *desc);
264 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
265                                       const struct mtk_pin_desc *desc,
266                                       int *res);
267 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
268                               const struct mtk_pin_desc *desc, bool pullup);
269 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
270                               const struct mtk_pin_desc *desc, bool pullup,
271                               int *res);
272
273 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
274                           const struct mtk_pin_desc *desc, u32 arg);
275 int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
276                           const struct mtk_pin_desc *desc, int *val);
277
278 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
279                                const struct mtk_pin_desc *desc, u32 arg);
280 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
281                                const struct mtk_pin_desc *desc, int *val);
282
283 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
284                              const struct mtk_pin_desc *desc, bool pullup,
285                              u32 arg);
286 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
287                              const struct mtk_pin_desc *desc, bool pullup,
288                              u32 *val);
289
290 #endif /* __PINCTRL_MTK_COMMON_V2_H */