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
,
72 /* Group the pins by the driving current */
83 static const char * const mtk_default_register_base_names
[] = {
87 /* struct mtk_pin_field - the structure that holds the information of the field
88 * used to describe the attribute for the pin
89 * @base: the index pointing to the entry in base address list
90 * @offset: the register offset relative to the base address
91 * @mask: the mask used to filter out the field from the register
92 * @bitpos: the start bit relative to the register
93 * @next: the indication that the field would be extended to the
96 struct mtk_pin_field
{
104 /* struct mtk_pin_field_calc - the structure that holds the range providing
105 * the guide used to look up the relevant field
106 * @s_pin: the start pin within the range
107 * @e_pin: the end pin within the range
108 * @i_base: the index pointing to the entry in base address list
109 * @s_addr: the start address for the range
110 * @x_addrs: the address distance between two consecutive registers
112 * @s_bit: the start bit for the first register within the range
113 * @x_bits: the bit distance between two consecutive pins within
115 * @sz_reg: the size of bits in a register
116 * @fixed: the consecutive pins share the same bits with the 1st
119 struct mtk_pin_field_calc
{
131 /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
132 * determine which register the pin would make use of
133 * for certain pin attribute.
134 * @range: the start address for the range
135 * @nranges: the number of items in the range
137 struct mtk_pin_reg_calc
{
138 const struct mtk_pin_field_calc
*range
;
139 unsigned int nranges
;
143 * struct mtk_func_desc - the structure that providing information
144 * all the funcs for this pin
145 * @name: the name of function
146 * @muxval: the mux to the function
148 struct mtk_func_desc
{
154 * struct mtk_eint_desc - the structure that providing information
155 * for eint data per pin
156 * @eint_m: the eint mux for this pin
157 * @eitn_n: the eint number for this pin
159 struct mtk_eint_desc
{
165 * struct mtk_pin_desc - the structure that providing information
166 * for each pin of chips
167 * @number: unique pin number from the global pin number space
168 * @name: name for this pin
169 * @eint: the eint data for this pin
170 * @drv_n: the index with the driving group
171 * @funcs: all available functions for this pins (only used in
172 * those drivers compatible to pinctrl-mtk-common.c-like
175 struct mtk_pin_desc
{
178 struct mtk_eint_desc eint
;
180 struct mtk_func_desc
*funcs
;
183 struct mtk_pinctrl_group
{
185 unsigned long config
;
191 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
193 const struct mtk_pin_reg_calc
*reg_cal
;
194 const struct mtk_pin_desc
*pins
;
196 const struct group_desc
*grps
;
198 const struct function_desc
*funcs
;
200 const struct mtk_eint_regs
*eint_regs
;
201 const struct mtk_eint_hw
*eint_hw
;
203 /* Specific parameters per SoC */
206 const char * const *base_names
;
207 unsigned int nbase_names
;
209 /* Specific pinconfig operations */
210 int (*bias_disable_set
)(struct mtk_pinctrl
*hw
,
211 const struct mtk_pin_desc
*desc
);
212 int (*bias_disable_get
)(struct mtk_pinctrl
*hw
,
213 const struct mtk_pin_desc
*desc
, int *res
);
214 int (*bias_set
)(struct mtk_pinctrl
*hw
,
215 const struct mtk_pin_desc
*desc
, bool pullup
);
216 int (*bias_get
)(struct mtk_pinctrl
*hw
,
217 const struct mtk_pin_desc
*desc
, bool pullup
, int *res
);
219 int (*drive_set
)(struct mtk_pinctrl
*hw
,
220 const struct mtk_pin_desc
*desc
, u32 arg
);
221 int (*drive_get
)(struct mtk_pinctrl
*hw
,
222 const struct mtk_pin_desc
*desc
, int *val
);
224 int (*adv_pull_set
)(struct mtk_pinctrl
*hw
,
225 const struct mtk_pin_desc
*desc
, bool pullup
,
227 int (*adv_pull_get
)(struct mtk_pinctrl
*hw
,
228 const struct mtk_pin_desc
*desc
, bool pullup
,
230 int (*adv_drive_set
)(struct mtk_pinctrl
*hw
,
231 const struct mtk_pin_desc
*desc
, u32 arg
);
232 int (*adv_drive_get
)(struct mtk_pinctrl
*hw
,
233 const struct mtk_pin_desc
*desc
, u32
*val
);
235 /* Specific driver data */
240 struct pinctrl_dev
*pctrl
;
244 struct gpio_chip chip
;
245 const struct mtk_pin_soc
*soc
;
246 struct mtk_eint
*eint
;
247 struct mtk_pinctrl_group
*groups
;
248 const char **grp_names
;
251 void mtk_rmw(struct mtk_pinctrl
*pctl
, u8 i
, u32 reg
, u32 mask
, u32 set
);
253 int mtk_hw_set_value(struct mtk_pinctrl
*hw
, const struct mtk_pin_desc
*desc
,
254 int field
, int value
);
255 int mtk_hw_get_value(struct mtk_pinctrl
*hw
, const struct mtk_pin_desc
*desc
,
256 int field
, int *value
);
258 int mtk_build_eint(struct mtk_pinctrl
*hw
, struct platform_device
*pdev
);
260 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl
*hw
,
261 const struct mtk_pin_desc
*desc
);
262 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl
*hw
,
263 const struct mtk_pin_desc
*desc
, int *res
);
264 int mtk_pinconf_bias_set(struct mtk_pinctrl
*hw
,
265 const struct mtk_pin_desc
*desc
, bool pullup
);
266 int mtk_pinconf_bias_get(struct mtk_pinctrl
*hw
,
267 const struct mtk_pin_desc
*desc
, bool pullup
,
270 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl
*hw
,
271 const struct mtk_pin_desc
*desc
);
272 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl
*hw
,
273 const struct mtk_pin_desc
*desc
,
275 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl
*hw
,
276 const struct mtk_pin_desc
*desc
, bool pullup
);
277 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl
*hw
,
278 const struct mtk_pin_desc
*desc
, bool pullup
,
281 int mtk_pinconf_drive_set(struct mtk_pinctrl
*hw
,
282 const struct mtk_pin_desc
*desc
, u32 arg
);
283 int mtk_pinconf_drive_get(struct mtk_pinctrl
*hw
,
284 const struct mtk_pin_desc
*desc
, int *val
);
286 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl
*hw
,
287 const struct mtk_pin_desc
*desc
, u32 arg
);
288 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl
*hw
,
289 const struct mtk_pin_desc
*desc
, int *val
);
291 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl
*hw
,
292 const struct mtk_pin_desc
*desc
, bool pullup
,
294 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl
*hw
,
295 const struct mtk_pin_desc
*desc
, bool pullup
,
297 int mtk_pinconf_adv_drive_set(struct mtk_pinctrl
*hw
,
298 const struct mtk_pin_desc
*desc
, u32 arg
);
299 int mtk_pinconf_adv_drive_get(struct mtk_pinctrl
*hw
,
300 const struct mtk_pin_desc
*desc
, u32
*val
);
302 #endif /* __PINCTRL_MTK_COMMON_V2_H */