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
20 #define MTK_PULL_PU_PD_TYPE BIT(0)
21 #define MTK_PULL_PULLSEL_TYPE BIT(1)
22 #define MTK_PULL_PUPD_R1R0_TYPE BIT(2)
23 /* MTK_PULL_RSEL_TYPE can select resistance and can be
24 * turned on/off itself. But it can't be selected pull up/down
26 #define MTK_PULL_RSEL_TYPE BIT(3)
27 /* MTK_PULL_PU_PD_RSEL_TYPE is a type which is controlled by
28 * MTK_PULL_PU_PD_TYPE and MTK_PULL_RSEL_TYPE.
30 #define MTK_PULL_PU_PD_RSEL_TYPE (MTK_PULL_PU_PD_TYPE \
32 #define MTK_PULL_TYPE_MASK (MTK_PULL_PU_PD_TYPE |\
33 MTK_PULL_PULLSEL_TYPE |\
34 MTK_PULL_PUPD_R1R0_TYPE |\
37 #define EINT_NA U16_MAX
38 #define NO_EINT_SUPPORT EINT_NA
40 #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, \
41 _s_bit, _x_bits, _sz_reg, _fixed) { \
46 .x_addrs = _x_addrs, \
53 #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
54 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
57 #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
58 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
61 #define PIN_RSEL(_s_pin, _e_pin, _rsel_index, _up_resl, _down_rsel) { \
64 .rsel_index = _rsel_index, \
65 .up_rsel = _up_resl, \
66 .down_rsel = _down_rsel, \
69 /* List these attributes which could be modified for the pin */
81 PINCTRL_PIN_REG_TDSEL
,
82 PINCTRL_PIN_REG_RDSEL
,
88 PINCTRL_PIN_REG_PULLEN
,
89 PINCTRL_PIN_REG_PULLSEL
,
90 PINCTRL_PIN_REG_DRV_EN
,
91 PINCTRL_PIN_REG_DRV_E0
,
92 PINCTRL_PIN_REG_DRV_E1
,
93 PINCTRL_PIN_REG_DRV_ADV
,
98 /* Group the pins by the driving current */
109 static const char * const mtk_default_register_base_names
[] __maybe_unused
= {
113 /* struct mtk_pin_field - the structure that holds the information of the field
114 * used to describe the attribute for the pin
115 * @base: the index pointing to the entry in base address list
116 * @offset: the register offset relative to the base address
117 * @mask: the mask used to filter out the field from the register
118 * @bitpos: the start bit relative to the register
119 * @next: the indication that the field would be extended to the
122 struct mtk_pin_field
{
130 /* struct mtk_pin_field_calc - the structure that holds the range providing
131 * the guide used to look up the relevant field
132 * @s_pin: the start pin within the range
133 * @e_pin: the end pin within the range
134 * @i_base: the index pointing to the entry in base address list
135 * @s_addr: the start address for the range
136 * @x_addrs: the address distance between two consecutive registers
138 * @s_bit: the start bit for the first register within the range
139 * @x_bits: the bit distance between two consecutive pins within
141 * @sz_reg: the size of bits in a register
142 * @fixed: the consecutive pins share the same bits with the 1st
145 struct mtk_pin_field_calc
{
158 * struct mtk_pin_rsel - the structure that provides bias resistance selection.
159 * @s_pin: the start pin within the rsel range
160 * @e_pin: the end pin within the rsel range
161 * @rsel_index: the rsel bias resistance index
162 * @up_rsel: the pullup rsel bias resistance value
163 * @down_rsel: the pulldown rsel bias resistance value
165 struct mtk_pin_rsel
{
173 /* struct mtk_pin_reg_calc - the structure that holds all ranges used to
174 * determine which register the pin would make use of
175 * for certain pin attribute.
176 * @range: the start address for the range
177 * @nranges: the number of items in the range
179 struct mtk_pin_reg_calc
{
180 const struct mtk_pin_field_calc
*range
;
181 unsigned int nranges
;
185 * struct mtk_func_desc - the structure that providing information
186 * all the funcs for this pin
187 * @name: the name of function
188 * @muxval: the mux to the function
190 struct mtk_func_desc
{
196 * struct mtk_eint_desc - the structure that providing information
197 * for eint data per pin
198 * @eint_m: the eint mux for this pin
199 * @eitn_n: the eint number for this pin
201 struct mtk_eint_desc
{
207 * struct mtk_pin_desc - the structure that providing information
208 * for each pin of chips
209 * @number: unique pin number from the global pin number space
210 * @name: name for this pin
211 * @eint: the eint data for this pin
212 * @drv_n: the index with the driving group
213 * @funcs: all available functions for this pins (only used in
214 * those drivers compatible to pinctrl-mtk-common.c-like
217 struct mtk_pin_desc
{
220 struct mtk_eint_desc eint
;
222 struct mtk_func_desc
*funcs
;
225 struct mtk_pinctrl_group
{
227 unsigned long config
;
233 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
235 const struct mtk_pin_reg_calc
*reg_cal
;
236 const struct mtk_pin_desc
*pins
;
238 const struct group_desc
*grps
;
240 const struct function_desc
*funcs
;
242 const struct mtk_eint_regs
*eint_regs
;
243 const struct mtk_eint_hw
*eint_hw
;
245 /* Specific parameters per SoC */
248 const char * const *base_names
;
249 unsigned int nbase_names
;
250 const unsigned int *pull_type
;
251 const struct mtk_pin_rsel
*pin_rsel
;
252 unsigned int npin_rsel
;
254 /* Specific pinconfig operations */
255 int (*bias_disable_set
)(struct mtk_pinctrl
*hw
,
256 const struct mtk_pin_desc
*desc
);
257 int (*bias_disable_get
)(struct mtk_pinctrl
*hw
,
258 const struct mtk_pin_desc
*desc
, int *res
);
259 int (*bias_set
)(struct mtk_pinctrl
*hw
,
260 const struct mtk_pin_desc
*desc
, bool pullup
);
261 int (*bias_get
)(struct mtk_pinctrl
*hw
,
262 const struct mtk_pin_desc
*desc
, bool pullup
, int *res
);
264 int (*bias_set_combo
)(struct mtk_pinctrl
*hw
,
265 const struct mtk_pin_desc
*desc
, u32 pullup
, u32 arg
);
266 int (*bias_get_combo
)(struct mtk_pinctrl
*hw
,
267 const struct mtk_pin_desc
*desc
, u32
*pullup
, u32
*arg
);
269 int (*drive_set
)(struct mtk_pinctrl
*hw
,
270 const struct mtk_pin_desc
*desc
, u32 arg
);
271 int (*drive_get
)(struct mtk_pinctrl
*hw
,
272 const struct mtk_pin_desc
*desc
, int *val
);
274 int (*adv_pull_set
)(struct mtk_pinctrl
*hw
,
275 const struct mtk_pin_desc
*desc
, bool pullup
,
277 int (*adv_pull_get
)(struct mtk_pinctrl
*hw
,
278 const struct mtk_pin_desc
*desc
, bool pullup
,
280 int (*adv_drive_set
)(struct mtk_pinctrl
*hw
,
281 const struct mtk_pin_desc
*desc
, u32 arg
);
282 int (*adv_drive_get
)(struct mtk_pinctrl
*hw
,
283 const struct mtk_pin_desc
*desc
, u32
*val
);
285 /* Specific driver data */
290 struct pinctrl_dev
*pctrl
;
294 struct gpio_chip chip
;
295 const struct mtk_pin_soc
*soc
;
296 struct mtk_eint
*eint
;
297 struct mtk_pinctrl_group
*groups
;
298 const char **grp_names
;
299 /* lock pin's register resource to avoid multiple threads issue*/
301 /* identify rsel setting by si unit or rsel define in dts node */
305 void mtk_rmw(struct mtk_pinctrl
*pctl
, u8 i
, u32 reg
, u32 mask
, u32 set
);
307 int mtk_hw_set_value(struct mtk_pinctrl
*hw
, const struct mtk_pin_desc
*desc
,
308 int field
, int value
);
309 int mtk_hw_get_value(struct mtk_pinctrl
*hw
, const struct mtk_pin_desc
*desc
,
310 int field
, int *value
);
312 int mtk_build_eint(struct mtk_pinctrl
*hw
, struct platform_device
*pdev
);
314 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl
*hw
,
315 const struct mtk_pin_desc
*desc
);
316 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl
*hw
,
317 const struct mtk_pin_desc
*desc
, int *res
);
318 int mtk_pinconf_bias_set(struct mtk_pinctrl
*hw
,
319 const struct mtk_pin_desc
*desc
, bool pullup
);
320 int mtk_pinconf_bias_get(struct mtk_pinctrl
*hw
,
321 const struct mtk_pin_desc
*desc
, bool pullup
,
324 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl
*hw
,
325 const struct mtk_pin_desc
*desc
);
326 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl
*hw
,
327 const struct mtk_pin_desc
*desc
,
329 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl
*hw
,
330 const struct mtk_pin_desc
*desc
, bool pullup
);
331 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl
*hw
,
332 const struct mtk_pin_desc
*desc
, bool pullup
,
334 int mtk_pinconf_bias_set_combo(struct mtk_pinctrl
*hw
,
335 const struct mtk_pin_desc
*desc
,
336 u32 pullup
, u32 enable
);
337 int mtk_pinconf_bias_get_combo(struct mtk_pinctrl
*hw
,
338 const struct mtk_pin_desc
*desc
,
339 u32
*pullup
, u32
*enable
);
341 int mtk_pinconf_drive_set(struct mtk_pinctrl
*hw
,
342 const struct mtk_pin_desc
*desc
, u32 arg
);
343 int mtk_pinconf_drive_get(struct mtk_pinctrl
*hw
,
344 const struct mtk_pin_desc
*desc
, int *val
);
346 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl
*hw
,
347 const struct mtk_pin_desc
*desc
, u32 arg
);
348 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl
*hw
,
349 const struct mtk_pin_desc
*desc
, int *val
);
351 int mtk_pinconf_drive_set_raw(struct mtk_pinctrl
*hw
,
352 const struct mtk_pin_desc
*desc
, u32 arg
);
353 int mtk_pinconf_drive_get_raw(struct mtk_pinctrl
*hw
,
354 const struct mtk_pin_desc
*desc
, int *val
);
356 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl
*hw
,
357 const struct mtk_pin_desc
*desc
, bool pullup
,
359 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl
*hw
,
360 const struct mtk_pin_desc
*desc
, bool pullup
,
362 int mtk_pinconf_adv_drive_set(struct mtk_pinctrl
*hw
,
363 const struct mtk_pin_desc
*desc
, u32 arg
);
364 int mtk_pinconf_adv_drive_get(struct mtk_pinctrl
*hw
,
365 const struct mtk_pin_desc
*desc
, u32
*val
);
366 int mtk_pinconf_adv_drive_set_raw(struct mtk_pinctrl
*hw
,
367 const struct mtk_pin_desc
*desc
, u32 arg
);
368 int mtk_pinconf_adv_drive_get_raw(struct mtk_pinctrl
*hw
,
369 const struct mtk_pin_desc
*desc
, u32
*val
);
371 bool mtk_is_virt_gpio(struct mtk_pinctrl
*hw
, unsigned int gpio_n
);
372 #endif /* __PINCTRL_MTK_COMMON_V2_H */