1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2018 MediaTek Inc.
4 * Author: Ryder Lee <ryder.lee@mediatek.com>
6 #ifndef __PINCTRL_MEDIATEK_H__
7 #define __PINCTRL_MEDIATEK_H__
9 #define MTK_PINCTRL_V0 0x0
10 #define MTK_PINCTRL_V1 0x1
12 #define MTK_RANGE(_a) { .range = (_a), .nranges = ARRAY_SIZE(_a), }
13 #define MTK_PIN(_number, _name, _drv_n) { \
19 #define PINCTRL_PIN_GROUP(name, id) \
23 ARRAY_SIZE(id##_pins), \
27 #define PIN_FIELD_CALC(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, \
28 _x_bits, _sz_reg, _fixed) { \
32 .x_addrs = _x_addrs, \
39 /* List these attributes which could be modified for the pin */
51 PINCTRL_PIN_REG_PULLEN,
52 PINCTRL_PIN_REG_PULLSEL,
60 /* Group the pins by the driving current */
71 * struct mtk_pin_field - the structure that holds the information of the field
72 * used to describe the attribute for the pin
73 * @offset: the register offset relative to the base address
74 * @mask: the mask used to filter out the field from the register
75 * @bitpos: the start bit relative to the register
76 * @next: the indication that the field would be extended to the
79 struct mtk_pin_field {
87 * struct mtk_pin_field_calc - the structure that holds the range providing
88 * the guide used to look up the relevant field
89 * @s_pin: the start pin within the range
90 * @e_pin: the end pin within the range
91 * @s_addr: the start address for the range
92 * @x_addrs: the address distance between two consecutive registers
94 * @s_bit: the start bit for the first register within the range
95 * @x_bits: the bit distance between two consecutive pins within
97 * @sz_reg: the size of bits in a register
98 * @fixed: the consecutive pins share the same bits with the 1st
101 struct mtk_pin_field_calc {
113 * struct mtk_pin_reg_calc - the structure that holds all ranges used to
114 * determine which register the pin would make use of
115 * for certain pin attribute.
116 * @range: the start address for the range
117 * @nranges: the number of items in the range
119 struct mtk_pin_reg_calc {
120 const struct mtk_pin_field_calc *range;
121 unsigned int nranges;
125 * struct mtk_pin_desc - the structure that providing information
126 * for each pin of chips
127 * @number: unique pin number from the global pin number space
128 * @name: name for this pin
129 * @drv_n: the index with the driving group
131 struct mtk_pin_desc {
138 * struct mtk_group_desc - generic pin group descriptor
139 * @name: name of the pin group
140 * @pins: array of pins that belong to the group
141 * @num_pins: number of pins in the group
142 * @data: pin controller driver specific data
144 struct mtk_group_desc {
152 * struct mtk_function_desc - generic function descriptor
153 * @name: name of the function
154 * @group_names: array of pin group names
155 * @num_group_names: number of pin group names
157 struct mtk_function_desc {
159 const char * const *group_names;
163 /* struct mtk_pin_soc - the structure that holds SoC-specific data */
164 struct mtk_pinctrl_soc {
166 const struct mtk_pin_reg_calc *reg_cal;
167 const struct mtk_pin_desc *pins;
169 const struct mtk_group_desc *grps;
171 const struct mtk_function_desc *funcs;
178 * struct mtk_pinctrl_priv - private data for MTK pinctrl driver
180 * @base: base address of the pinctrl device
181 * @soc: SoC specific data
183 struct mtk_pinctrl_priv {
185 struct mtk_pinctrl_soc *soc;
188 extern const struct pinctrl_ops mtk_pinctrl_ops;
190 /* A common read-modify-write helper for MediaTek chips */
191 void mtk_rmw(struct udevice *dev, u32 reg, u32 mask, u32 set);
192 int mtk_pinctrl_common_probe(struct udevice *dev,
193 struct mtk_pinctrl_soc *soc);
195 #if CONFIG_IS_ENABLED(PINCONF)
197 int mtk_pinconf_bias_set_pu_pd(struct udevice *dev, u32 pin, bool disable,
198 bool pullup, u32 val);
199 int mtk_pinconf_bias_set_pullen_pullsel(struct udevice *dev, u32 pin,
200 bool disable, bool pullup, u32 val);
201 int mtk_pinconf_bias_set_pupd_r1_r0(struct udevice *dev, u32 pin, bool disable,
202 bool pullup, u32 val);
203 int mtk_pinconf_bias_set_v0(struct udevice *dev, u32 pin, bool disable,
204 bool pullup, u32 val);
205 int mtk_pinconf_bias_set_v1(struct udevice *dev, u32 pin, bool disable,
206 bool pullup, u32 val);
207 int mtk_pinconf_input_enable_v1(struct udevice *dev, u32 pin, u32 arg);
208 int mtk_pinconf_drive_set_v0(struct udevice *dev, u32 pin, u32 arg);
209 int mtk_pinconf_drive_set_v1(struct udevice *dev, u32 pin, u32 arg);
213 #endif /* __PINCTRL_MEDIATEK_H__ */