0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __PINCTRL_MTK_COMMON_V2_H
0010 #define __PINCTRL_MTK_COMMON_V2_H
0011
0012 #include <linux/gpio/driver.h>
0013
0014 #define MTK_INPUT 0
0015 #define MTK_OUTPUT 1
0016 #define MTK_DISABLE 0
0017 #define MTK_ENABLE 1
0018 #define MTK_PULLDOWN 0
0019 #define MTK_PULLUP 1
0020 #define MTK_PULL_PU_PD_TYPE BIT(0)
0021 #define MTK_PULL_PULLSEL_TYPE BIT(1)
0022 #define MTK_PULL_PUPD_R1R0_TYPE BIT(2)
0023
0024
0025
0026 #define MTK_PULL_RSEL_TYPE BIT(3)
0027
0028
0029
0030 #define MTK_PULL_PU_PD_RSEL_TYPE (MTK_PULL_PU_PD_TYPE \
0031 | MTK_PULL_RSEL_TYPE)
0032 #define MTK_PULL_TYPE_MASK (MTK_PULL_PU_PD_TYPE |\
0033 MTK_PULL_PULLSEL_TYPE |\
0034 MTK_PULL_PUPD_R1R0_TYPE |\
0035 MTK_PULL_RSEL_TYPE)
0036
0037 #define EINT_NA U16_MAX
0038 #define NO_EINT_SUPPORT EINT_NA
0039
0040 #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs, \
0041 _s_bit, _x_bits, _sz_reg, _fixed) { \
0042 .s_pin = _s_pin, \
0043 .e_pin = _e_pin, \
0044 .i_base = _i_base, \
0045 .s_addr = _s_addr, \
0046 .x_addrs = _x_addrs, \
0047 .s_bit = _s_bit, \
0048 .x_bits = _x_bits, \
0049 .sz_reg = _sz_reg, \
0050 .fixed = _fixed, \
0051 }
0052
0053 #define PIN_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
0054 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
0055 _x_bits, 32, 0)
0056
0057 #define PINS_FIELD(_s_pin, _e_pin, _s_addr, _x_addrs, _s_bit, _x_bits) \
0058 PIN_FIELD_CALC(_s_pin, _e_pin, 0, _s_addr, _x_addrs, _s_bit, \
0059 _x_bits, 32, 1)
0060
0061 #define PIN_RSEL(_s_pin, _e_pin, _rsel_index, _up_resl, _down_rsel) { \
0062 .s_pin = _s_pin, \
0063 .e_pin = _e_pin, \
0064 .rsel_index = _rsel_index, \
0065 .up_rsel = _up_resl, \
0066 .down_rsel = _down_rsel, \
0067 }
0068
0069
0070 enum {
0071 PINCTRL_PIN_REG_MODE,
0072 PINCTRL_PIN_REG_DIR,
0073 PINCTRL_PIN_REG_DI,
0074 PINCTRL_PIN_REG_DO,
0075 PINCTRL_PIN_REG_SR,
0076 PINCTRL_PIN_REG_SMT,
0077 PINCTRL_PIN_REG_PD,
0078 PINCTRL_PIN_REG_PU,
0079 PINCTRL_PIN_REG_E4,
0080 PINCTRL_PIN_REG_E8,
0081 PINCTRL_PIN_REG_TDSEL,
0082 PINCTRL_PIN_REG_RDSEL,
0083 PINCTRL_PIN_REG_DRV,
0084 PINCTRL_PIN_REG_PUPD,
0085 PINCTRL_PIN_REG_R0,
0086 PINCTRL_PIN_REG_R1,
0087 PINCTRL_PIN_REG_IES,
0088 PINCTRL_PIN_REG_PULLEN,
0089 PINCTRL_PIN_REG_PULLSEL,
0090 PINCTRL_PIN_REG_DRV_EN,
0091 PINCTRL_PIN_REG_DRV_E0,
0092 PINCTRL_PIN_REG_DRV_E1,
0093 PINCTRL_PIN_REG_DRV_ADV,
0094 PINCTRL_PIN_REG_RSEL,
0095 PINCTRL_PIN_REG_MAX,
0096 };
0097
0098
0099 enum {
0100 DRV_FIXED,
0101 DRV_GRP0,
0102 DRV_GRP1,
0103 DRV_GRP2,
0104 DRV_GRP3,
0105 DRV_GRP4,
0106 DRV_GRP_MAX,
0107 };
0108
0109 static const char * const mtk_default_register_base_names[] __maybe_unused = {
0110 "base",
0111 };
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122 struct mtk_pin_field {
0123 u8 index;
0124 u32 offset;
0125 u32 mask;
0126 u8 bitpos;
0127 u8 next;
0128 };
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145 struct mtk_pin_field_calc {
0146 u16 s_pin;
0147 u16 e_pin;
0148 u8 i_base;
0149 u32 s_addr;
0150 u8 x_addrs;
0151 u8 s_bit;
0152 u8 x_bits;
0153 u8 sz_reg;
0154 u8 fixed;
0155 };
0156
0157
0158
0159
0160
0161
0162
0163
0164
0165 struct mtk_pin_rsel {
0166 u16 s_pin;
0167 u16 e_pin;
0168 u16 rsel_index;
0169 u32 up_rsel;
0170 u32 down_rsel;
0171 };
0172
0173
0174
0175
0176
0177
0178
0179 struct mtk_pin_reg_calc {
0180 const struct mtk_pin_field_calc *range;
0181 unsigned int nranges;
0182 };
0183
0184
0185
0186
0187
0188
0189
0190 struct mtk_func_desc {
0191 const char *name;
0192 u8 muxval;
0193 };
0194
0195
0196
0197
0198
0199
0200
0201 struct mtk_eint_desc {
0202 u16 eint_m;
0203 u16 eint_n;
0204 };
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217 struct mtk_pin_desc {
0218 unsigned int number;
0219 const char *name;
0220 struct mtk_eint_desc eint;
0221 u8 drv_n;
0222 struct mtk_func_desc *funcs;
0223 };
0224
0225 struct mtk_pinctrl_group {
0226 const char *name;
0227 unsigned long config;
0228 unsigned pin;
0229 };
0230
0231 struct mtk_pinctrl;
0232
0233
0234 struct mtk_pin_soc {
0235 const struct mtk_pin_reg_calc *reg_cal;
0236 const struct mtk_pin_desc *pins;
0237 unsigned int npins;
0238 const struct group_desc *grps;
0239 unsigned int ngrps;
0240 const struct function_desc *funcs;
0241 unsigned int nfuncs;
0242 const struct mtk_eint_regs *eint_regs;
0243 const struct mtk_eint_hw *eint_hw;
0244
0245
0246 u8 gpio_m;
0247 bool ies_present;
0248 const char * const *base_names;
0249 unsigned int nbase_names;
0250 const unsigned int *pull_type;
0251 const struct mtk_pin_rsel *pin_rsel;
0252 unsigned int npin_rsel;
0253
0254
0255 int (*bias_disable_set)(struct mtk_pinctrl *hw,
0256 const struct mtk_pin_desc *desc);
0257 int (*bias_disable_get)(struct mtk_pinctrl *hw,
0258 const struct mtk_pin_desc *desc, int *res);
0259 int (*bias_set)(struct mtk_pinctrl *hw,
0260 const struct mtk_pin_desc *desc, bool pullup);
0261 int (*bias_get)(struct mtk_pinctrl *hw,
0262 const struct mtk_pin_desc *desc, bool pullup, int *res);
0263
0264 int (*bias_set_combo)(struct mtk_pinctrl *hw,
0265 const struct mtk_pin_desc *desc, u32 pullup, u32 arg);
0266 int (*bias_get_combo)(struct mtk_pinctrl *hw,
0267 const struct mtk_pin_desc *desc, u32 *pullup, u32 *arg);
0268
0269 int (*drive_set)(struct mtk_pinctrl *hw,
0270 const struct mtk_pin_desc *desc, u32 arg);
0271 int (*drive_get)(struct mtk_pinctrl *hw,
0272 const struct mtk_pin_desc *desc, int *val);
0273
0274 int (*adv_pull_set)(struct mtk_pinctrl *hw,
0275 const struct mtk_pin_desc *desc, bool pullup,
0276 u32 arg);
0277 int (*adv_pull_get)(struct mtk_pinctrl *hw,
0278 const struct mtk_pin_desc *desc, bool pullup,
0279 u32 *val);
0280 int (*adv_drive_set)(struct mtk_pinctrl *hw,
0281 const struct mtk_pin_desc *desc, u32 arg);
0282 int (*adv_drive_get)(struct mtk_pinctrl *hw,
0283 const struct mtk_pin_desc *desc, u32 *val);
0284
0285
0286 void *driver_data;
0287 };
0288
0289 struct mtk_pinctrl {
0290 struct pinctrl_dev *pctrl;
0291 void __iomem **base;
0292 u8 nbase;
0293 struct device *dev;
0294 struct gpio_chip chip;
0295 const struct mtk_pin_soc *soc;
0296 struct mtk_eint *eint;
0297 struct mtk_pinctrl_group *groups;
0298 const char **grp_names;
0299
0300 spinlock_t lock;
0301
0302 bool rsel_si_unit;
0303 };
0304
0305 void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
0306
0307 int mtk_hw_set_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
0308 int field, int value);
0309 int mtk_hw_get_value(struct mtk_pinctrl *hw, const struct mtk_pin_desc *desc,
0310 int field, int *value);
0311
0312 int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev);
0313
0314 int mtk_pinconf_bias_disable_set(struct mtk_pinctrl *hw,
0315 const struct mtk_pin_desc *desc);
0316 int mtk_pinconf_bias_disable_get(struct mtk_pinctrl *hw,
0317 const struct mtk_pin_desc *desc, int *res);
0318 int mtk_pinconf_bias_set(struct mtk_pinctrl *hw,
0319 const struct mtk_pin_desc *desc, bool pullup);
0320 int mtk_pinconf_bias_get(struct mtk_pinctrl *hw,
0321 const struct mtk_pin_desc *desc, bool pullup,
0322 int *res);
0323
0324 int mtk_pinconf_bias_disable_set_rev1(struct mtk_pinctrl *hw,
0325 const struct mtk_pin_desc *desc);
0326 int mtk_pinconf_bias_disable_get_rev1(struct mtk_pinctrl *hw,
0327 const struct mtk_pin_desc *desc,
0328 int *res);
0329 int mtk_pinconf_bias_set_rev1(struct mtk_pinctrl *hw,
0330 const struct mtk_pin_desc *desc, bool pullup);
0331 int mtk_pinconf_bias_get_rev1(struct mtk_pinctrl *hw,
0332 const struct mtk_pin_desc *desc, bool pullup,
0333 int *res);
0334 int mtk_pinconf_bias_set_combo(struct mtk_pinctrl *hw,
0335 const struct mtk_pin_desc *desc,
0336 u32 pullup, u32 enable);
0337 int mtk_pinconf_bias_get_combo(struct mtk_pinctrl *hw,
0338 const struct mtk_pin_desc *desc,
0339 u32 *pullup, u32 *enable);
0340
0341 int mtk_pinconf_drive_set(struct mtk_pinctrl *hw,
0342 const struct mtk_pin_desc *desc, u32 arg);
0343 int mtk_pinconf_drive_get(struct mtk_pinctrl *hw,
0344 const struct mtk_pin_desc *desc, int *val);
0345
0346 int mtk_pinconf_drive_set_rev1(struct mtk_pinctrl *hw,
0347 const struct mtk_pin_desc *desc, u32 arg);
0348 int mtk_pinconf_drive_get_rev1(struct mtk_pinctrl *hw,
0349 const struct mtk_pin_desc *desc, int *val);
0350
0351 int mtk_pinconf_drive_set_raw(struct mtk_pinctrl *hw,
0352 const struct mtk_pin_desc *desc, u32 arg);
0353 int mtk_pinconf_drive_get_raw(struct mtk_pinctrl *hw,
0354 const struct mtk_pin_desc *desc, int *val);
0355
0356 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
0357 const struct mtk_pin_desc *desc, bool pullup,
0358 u32 arg);
0359 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
0360 const struct mtk_pin_desc *desc, bool pullup,
0361 u32 *val);
0362 int mtk_pinconf_adv_drive_set(struct mtk_pinctrl *hw,
0363 const struct mtk_pin_desc *desc, u32 arg);
0364 int mtk_pinconf_adv_drive_get(struct mtk_pinctrl *hw,
0365 const struct mtk_pin_desc *desc, u32 *val);
0366 int mtk_pinconf_adv_drive_set_raw(struct mtk_pinctrl *hw,
0367 const struct mtk_pin_desc *desc, u32 arg);
0368 int mtk_pinconf_adv_drive_get_raw(struct mtk_pinctrl *hw,
0369 const struct mtk_pin_desc *desc, u32 *val);
0370
0371 bool mtk_is_virt_gpio(struct mtk_pinctrl *hw, unsigned int gpio_n);
0372 #endif