]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/pinctrl/mediatek/pinctrl-mtk-common-v2.h
pinctrl: mediatek: use pin descriptor all in pinctrl-mtk-common-v2.c
[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 #define MTK_INPUT      0
13 #define MTK_OUTPUT     1
14 #define MTK_DISABLE    0
15 #define MTK_ENABLE     1
16 #define MTK_PULLDOWN   0
17 #define MTK_PULLUP     1
18
19 #define EINT_NA -1
20
21 #define PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit,       \
22                         _x_bits, _sz_reg, _fixed) {                     \
23                 .s_pin = _s_pin,                                        \
24                 .e_pin = _e_pin,                                        \
25                 .s_addr = _s_addr,                                      \
26                 .x_addrs = _x_addrs,                                    \
27                 .s_bit = _s_bit,                                        \
28                 .x_bits = _x_bits,                                      \
29                 .sz_reg = _sz_reg,                                      \
30                 .fixed = _fixed,                                        \
31         }
32
33 #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)   \
34         PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit,       \
35                        _x_bits, 32, 0)
36
37 #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits)  \
38         PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit,       \
39                        _x_bits, 32, 1)
40
41 /* List these attributes which could be modified for the pin */
42 enum {
43         PINCTRL_PIN_REG_MODE,
44         PINCTRL_PIN_REG_DIR,
45         PINCTRL_PIN_REG_DI,
46         PINCTRL_PIN_REG_DO,
47         PINCTRL_PIN_REG_SR,
48         PINCTRL_PIN_REG_SMT,
49         PINCTRL_PIN_REG_PD,
50         PINCTRL_PIN_REG_PU,
51         PINCTRL_PIN_REG_E4,
52         PINCTRL_PIN_REG_E8,
53         PINCTRL_PIN_REG_TDSEL,
54         PINCTRL_PIN_REG_RDSEL,
55         PINCTRL_PIN_REG_DRV,
56         PINCTRL_PIN_REG_PUPD,
57         PINCTRL_PIN_REG_R0,
58         PINCTRL_PIN_REG_R1,
59         PINCTRL_PIN_REG_IES,
60         PINCTRL_PIN_REG_PULLEN,
61         PINCTRL_PIN_REG_PULLSEL,
62         PINCTRL_PIN_REG_MAX,
63 };
64
65 /* Group the pins by the driving current */
66 enum {
67         DRV_FIXED,
68         DRV_GRP0,
69         DRV_GRP1,
70         DRV_GRP2,
71         DRV_GRP3,
72         DRV_GRP4,
73         DRV_GRP_MAX,
74 };
75
76 /* struct mtk_pin_field - the structure that holds the information of the field
77  *                        used to describe the attribute for the pin
78  * @offset:             the register offset relative to the base address
79  * @mask:               the mask used to filter out the field from the register
80  * @bitpos:             the start bit relative to the register
81  * @next:               the indication that the field would be extended to the
82                         next register
83  */
84 struct mtk_pin_field {
85         u32 offset;
86         u32 mask;
87         u8  bitpos;
88         u8  next;
89 };
90
91 /* struct mtk_pin_field_calc - the structure that holds the range providing
92  *                             the guide used to look up the relevant field
93  * @s_pin:              the start pin within the range
94  * @e_pin:              the end pin within the range
95  * @s_addr:             the start address for the range
96  * @x_addrs:            the address distance between two consecutive registers
97  *                      within the range
98  * @s_bit:              the start bit for the first register within the range
99  * @x_bits:             the bit distance between two consecutive pins within
100  *                      the range
101  * @sz_reg:             the size of bits in a register
102  * @fixed:              the consecutive pins share the same bits with the 1st
103  *                      pin
104  */
105 struct mtk_pin_field_calc {
106         u16 s_pin;
107         u16 e_pin;
108         u32 s_addr;
109         u8  x_addrs;
110         u8  s_bit;
111         u8  x_bits;
112         u8  sz_reg;
113         u8  fixed;
114 };
115
116 /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
117  *                           determine which register the pin would make use of
118  *                           for certain pin attribute.
119  * @range:                   the start address for the range
120  * @nranges:                 the number of items in the range
121  */
122 struct mtk_pin_reg_calc {
123         const struct mtk_pin_field_calc *range;
124         unsigned int nranges;
125 };
126
127 /**
128  * struct mtk_pin_desc - the structure that providing information
129  *                             for each pin of chips
130  * @number:             unique pin number from the global pin number space
131  * @name:               name for this pin
132  * @eint_n:             the eint number for this pin
133  * @drv_n:              the index with the driving group
134  */
135 struct mtk_pin_desc {
136         unsigned int number;
137         const char *name;
138         u16 eint_n;
139         u8 drv_n;
140 };
141
142 struct mtk_pinctrl;
143
144 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
145 struct mtk_pin_soc {
146         const struct mtk_pin_reg_calc   *reg_cal;
147         const struct pinctrl_pin_desc   *pins;
148         unsigned int                    npins;
149         const struct group_desc         *grps;
150         unsigned int                    ngrps;
151         const struct function_desc      *funcs;
152         unsigned int                    nfuncs;
153         const struct mtk_eint_regs      *eint_regs;
154         const struct mtk_eint_hw        *eint_hw;
155
156         /* Specific parameters per SoC */
157         u8                              gpio_m;
158         u8                              eint_m;
159         bool                            ies_present;
160
161         /* Specific pinconfig operations */
162         int (*bias_disable_set)(struct mtk_pinctrl *hw,
163                                 const struct mtk_pin_desc *desc);
164         int (*bias_disable_get)(struct mtk_pinctrl *hw,
165                                 const struct mtk_pin_desc *desc, int *res);
166         int (*bias_set)(struct mtk_pinctrl *hw,
167                         const struct mtk_pin_desc *desc, bool pullup);
168         int (*bias_get)(struct mtk_pinctrl *hw,
169                         const struct mtk_pin_desc *desc, bool pullup, int *res);
170
171         int (*drive_set)(struct mtk_pinctrl *hw,
172                          const struct mtk_pin_desc *desc, u32 arg);
173         int (*drive_get)(struct mtk_pinctrl *hw,
174                          const struct mtk_pin_desc *desc, int *val);
175
176         int (*adv_pull_set)(struct mtk_pinctrl *hw,
177                             const struct mtk_pin_desc *desc, bool pullup,
178                             u32 arg);
179         int (*adv_pull_get)(struct mtk_pinctrl *hw,
180                             const struct mtk_pin_desc *desc, bool pullup,
181                             u32 *val);
182 };
183
184 struct mtk_pinctrl {
185         struct pinctrl_dev              *pctrl;
186         void __iomem                    *base;
187         struct device                   *dev;
188         struct gpio_chip                chip;
189         const struct mtk_pin_soc        *soc;
190         struct mtk_eint                 *eint;
191 };
192
193 void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
194
195 int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
196                      int field, int value);
197 int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
198                      int field, int *value);
199
200 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
201                                  const struct mtk_pin_desc *desc);
202 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
203                                  const struct mtk_pin_desc *desc, int *res);
204 int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
205                          const struct mtk_pin_desc *desc, bool pullup);
206 int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
207                          const struct mtk_pin_desc *desc, bool pullup,
208                          int *res);
209
210 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
211                                       const struct mtk_pin_desc *desc);
212 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
213                                       const struct mtk_pin_desc *desc,
214                                       int *res);
215 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
216                               const struct mtk_pin_desc *desc, bool pullup);
217 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
218                               const struct mtk_pin_desc *desc, bool pullup,
219                               int *res);
220
221 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
222                           const struct mtk_pin_desc *desc, u32 arg);
223 int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
224                           const struct mtk_pin_desc *desc, int *val);
225
226 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
227                                const struct mtk_pin_desc *desc, u32 arg);
228 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
229                                const struct mtk_pin_desc *desc, int *val);
230
231 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
232                              const struct mtk_pin_desc *desc, bool pullup,
233                              u32 arg);
234 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
235                              const struct mtk_pin_desc *desc, bool pullup,
236                              u32 *val);
237
238 #endif /* __PINCTRL_MTK_COMMON_V2_H */