1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2018 MediaTek Inc.
5 * Author: Sean Wang <sean.wang@mediatek.com>
9 #ifndef __PINCTRL_MTK_COMMON_V2_H
10 #define __PINCTRL_MTK_COMMON_V2_H
12 #include <linux/gpio/driver.h>
18 #define MTK_PULLDOWN 0
21 #define EINT_NA U16_MAX
22 #define NO_EINT_SUPPORT EINT_NA
24 #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, \
25 _s_bit, _x_bits, _sz_reg, _fixed) { \
30 .x_addrs = _x_addrs, \
37 #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
38 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
41 #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
42 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
45 /* List these attributes which could be modified for the pin */
57 PINCTRL_PIN_REG_TDSEL,
58 PINCTRL_PIN_REG_RDSEL,
64 PINCTRL_PIN_REG_PULLEN,
65 PINCTRL_PIN_REG_PULLSEL,
66 PINCTRL_PIN_REG_DRV_EN,
67 PINCTRL_PIN_REG_DRV_E0,
68 PINCTRL_PIN_REG_DRV_E1,
69 PINCTRL_PIN_REG_DRV_ADV,
73 /* Group the pins by the driving current */
84 static const char * const mtk_default_register_base_names[] __maybe_unused = {
88 /* struct mtk_pin_field - the structure that holds the information of the field
89 * used to describe the attribute for the pin
90 * @base: the index pointing to the entry in base address list
91 * @offset: the register offset relative to the base address
92 * @mask: the mask used to filter out the field from the register
93 * @bitpos: the start bit relative to the register
94 * @next: the indication that the field would be extended to the
97 struct mtk_pin_field {
105 /* struct mtk_pin_field_calc - the structure that holds the range providing
106 * the guide used to look up the relevant field
107 * @s_pin: the start pin within the range
108 * @e_pin: the end pin within the range
109 * @i_base: the index pointing to the entry in base address list
110 * @s_addr: the start address for the range
111 * @x_addrs: the address distance between two consecutive registers
113 * @s_bit: the start bit for the first register within the range
114 * @x_bits: the bit distance between two consecutive pins within
116 * @sz_reg: the size of bits in a register
117 * @fixed: the consecutive pins share the same bits with the 1st
120 struct mtk_pin_field_calc {
132 /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
133 * determine which register the pin would make use of
134 * for certain pin attribute.
135 * @range: the start address for the range
136 * @nranges: the number of items in the range
138 struct mtk_pin_reg_calc {
139 const struct mtk_pin_field_calc *range;
140 unsigned int nranges;
144 * struct mtk_func_desc - the structure that providing information
145 * all the funcs for this pin
146 * @name: the name of function
147 * @muxval: the mux to the function
149 struct mtk_func_desc {
155 * struct mtk_eint_desc - the structure that providing information
156 * for eint data per pin
157 * @eint_m: the eint mux for this pin
158 * @eitn_n: the eint number for this pin
160 struct mtk_eint_desc {
166 * struct mtk_pin_desc - the structure that providing information
167 * for each pin of chips
168 * @number: unique pin number from the global pin number space
169 * @name: name for this pin
170 * @eint: the eint data for this pin
171 * @drv_n: the index with the driving group
172 * @funcs: all available functions for this pins (only used in
173 * those drivers compatible to pinctrl-mtk-common.c-like
176 struct mtk_pin_desc {
179 struct mtk_eint_desc eint;
181 struct mtk_func_desc *funcs;
184 struct mtk_pinctrl_group {
186 unsigned long config;
192 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
194 const struct mtk_pin_reg_calc *reg_cal;
195 const struct mtk_pin_desc *pins;
197 const struct group_desc *grps;
199 const struct function_desc *funcs;
201 const struct mtk_eint_regs *eint_regs;
202 const struct mtk_eint_hw *eint_hw;
204 /* Specific parameters per SoC */
207 const char * const *base_names;
208 unsigned int nbase_names;
210 /* Specific pinconfig operations */
211 int (*bias_disable_set)(struct mtk_pinctrl *hw,
212 const struct mtk_pin_desc *desc);
213 int (*bias_disable_get)(struct mtk_pinctrl *hw,
214 const struct mtk_pin_desc *desc, int *res);
215 int (*bias_set)(struct mtk_pinctrl *hw,
216 const struct mtk_pin_desc *desc, bool pullup);
217 int (*bias_get)(struct mtk_pinctrl *hw,
218 const struct mtk_pin_desc *desc, bool pullup, int *res);
220 int (*bias_set_combo)(struct mtk_pinctrl *hw,
221 const struct mtk_pin_desc *desc, u32 pullup, u32 arg);
222 int (*bias_get_combo)(struct mtk_pinctrl *hw,
223 const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg);
225 int (*drive_set)(struct mtk_pinctrl *hw,
226 const struct mtk_pin_desc *desc, u32 arg);
227 int (*drive_get)(struct mtk_pinctrl *hw,
228 const struct mtk_pin_desc *desc, int *val);
230 int (*adv_pull_set)(struct mtk_pinctrl *hw,
231 const struct mtk_pin_desc *desc, bool pullup,
233 int (*adv_pull_get)(struct mtk_pinctrl *hw,
234 const struct mtk_pin_desc *desc, bool pullup,
236 int (*adv_drive_set)(struct mtk_pinctrl *hw,
237 const struct mtk_pin_desc *desc, u32 arg);
238 int (*adv_drive_get)(struct mtk_pinctrl *hw,
239 const struct mtk_pin_desc *desc, u32 *val);
241 /* Specific driver data */
246 struct pinctrl_dev *pctrl;
250 struct gpio_chip chip;
251 const struct mtk_pin_soc *soc;
252 struct mtk_eint *eint;
253 struct mtk_pinctrl_group *groups;
254 const char **grp_names;
255 /* lock pin's register resource to avoid multiple threads issue*/
259 void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
261 int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
262 int field, int value);
263 int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
264 int field, int *value);
266 int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev);
268 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
269 const struct mtk_pin_desc *desc);
270 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
271 const struct mtk_pin_desc *desc, int *res);
272 int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
273 const struct mtk_pin_desc *desc, bool pullup);
274 int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
275 const struct mtk_pin_desc *desc, bool pullup,
278 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
279 const struct mtk_pin_desc *desc);
280 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
281 const struct mtk_pin_desc *desc,
283 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
284 const struct mtk_pin_desc *desc, bool pullup);
285 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
286 const struct mtk_pin_desc *desc, bool pullup,
288 int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
289 const struct mtk_pin_desc *desc,
290 u32 pullup, u32 enable);
291 int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
292 const struct mtk_pin_desc *desc,
293 u32 *pullup, u32 *enable);
295 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
296 const struct mtk_pin_desc *desc, u32 arg);
297 int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
298 const struct mtk_pin_desc *desc, int *val);
300 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
301 const struct mtk_pin_desc *desc, u32 arg);
302 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
303 const struct mtk_pin_desc *desc, int *val);
305 int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw,
306 const struct mtk_pin_desc *desc, u32 arg);
307 int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw,
308 const struct mtk_pin_desc *desc, int *val);
310 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
311 const struct mtk_pin_desc *desc, bool pullup,
313 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
314 const struct mtk_pin_desc *desc, bool pullup,
316 int mtk_pinconf_adv_drive_set(struct mtk_pinctrl *hw,
317 const struct mtk_pin_desc *desc, u32 arg);
318 int mtk_pinconf_adv_drive_get(struct mtk_pinctrl *hw,
319 const struct mtk_pin_desc *desc, u32 *val);
320 int mtk_pinconf_adv_drive_set_raw(struct mtk_pinctrl *hw,
321 const struct mtk_pin_desc *desc, u32 arg);
322 int mtk_pinconf_adv_drive_get_raw(struct mtk_pinctrl *hw,
323 const struct mtk_pin_desc *desc, u32 *val);
325 bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n);
326 #endif /* __PINCTRL_MTK_COMMON_V2_H */