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
16 #define MTK_PULLDOWN 0
21 #define PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, \
22 _x_bits, _sz_reg, _fixed) { \
26 .x_addrs = _x_addrs, \
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, \
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, \
41 /* List these attributes which could be modified for the pin */
53 PINCTRL_PIN_REG_TDSEL,
54 PINCTRL_PIN_REG_RDSEL,
60 PINCTRL_PIN_REG_PULLEN,
61 PINCTRL_PIN_REG_PULLSEL,
65 /* Group the pins by the driving current */
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
84 struct mtk_pin_field {
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
98 * @s_bit: the start bit for the first register within the range
99 * @x_bits: the bit distance between two consecutive pins within
101 * @sz_reg: the size of bits in a register
102 * @fixed: the consecutive pins share the same bits with the 1st
105 struct mtk_pin_field_calc {
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
122 struct mtk_pin_reg_calc {
123 const struct mtk_pin_field_calc *range;
124 unsigned int nranges;
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
135 struct mtk_pin_desc {
144 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
146 const struct mtk_pin_reg_calc *reg_cal;
147 const struct pinctrl_pin_desc *pins;
149 const struct group_desc *grps;
151 const struct function_desc *funcs;
153 const struct mtk_eint_regs *eint_regs;
154 const struct mtk_eint_hw *eint_hw;
156 /* Specific parameters per SoC */
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);
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);
176 int (*adv_pull_set)(struct mtk_pinctrl *hw,
177 const struct mtk_pin_desc *desc, bool pullup,
179 int (*adv_pull_get)(struct mtk_pinctrl *hw,
180 const struct mtk_pin_desc *desc, bool pullup,
185 struct pinctrl_dev *pctrl;
188 struct gpio_chip chip;
189 const struct mtk_pin_soc *soc;
190 struct mtk_eint *eint;
193 void mtk_rmw(struct mtk_pinctrl *pctl, u32 reg, u32 mask, u32 set);
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);
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,
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,
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,
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);
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);
231 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
232 const struct mtk_pin_desc *desc, bool pullup,
234 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
235 const struct mtk_pin_desc *desc, bool pullup,
238 #endif /* __PINCTRL_MTK_COMMON_V2_H */