1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 #ifndef __PINCTRL_MTK_COMMON_V2_H
  10 #define __PINCTRL_MTK_COMMON_V2_H
  11 
  12 #include <linux/gpio/driver.h>
  13 
  14 #define MTK_INPUT      0
  15 #define MTK_OUTPUT     1
  16 #define MTK_DISABLE    0
  17 #define MTK_ENABLE     1
  18 #define MTK_PULLDOWN   0
  19 #define MTK_PULLUP     1
  20 
  21 #define EINT_NA U16_MAX
  22 #define NO_EINT_SUPPORT EINT_NA
  23 
  24 #define PIN_FIELD_CALC(_s_pin, _e_pin, _i_base, _s_addr, _x_addrs,      \
  25                        _s_bit, _x_bits, _sz_reg, _fixed) {              \
  26                 .s_pin = _s_pin,                                        \
  27                 .e_pin = _e_pin,                                        \
  28                 .i_base = _i_base,                                      \
  29                 .s_addr = _s_addr,                                      \
  30                 .x_addrs = _x_addrs,                                    \
  31                 .s_bit = _s_bit,                                        \
  32                 .x_bits = _x_bits,                                      \
  33                 .sz_reg = _sz_reg,                                      \
  34                 .fixed = _fixed,                                        \
  35         }
  36 
  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,    \
  39                        _x_bits, 32, 0)
  40 
  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,    \
  43                        _x_bits, 32, 1)
  44 
  45 
  46 enum {
  47         PINCTRL_PIN_REG_MODE,
  48         PINCTRL_PIN_REG_DIR,
  49         PINCTRL_PIN_REG_DI,
  50         PINCTRL_PIN_REG_DO,
  51         PINCTRL_PIN_REG_SR,
  52         PINCTRL_PIN_REG_SMT,
  53         PINCTRL_PIN_REG_PD,
  54         PINCTRL_PIN_REG_PU,
  55         PINCTRL_PIN_REG_E4,
  56         PINCTRL_PIN_REG_E8,
  57         PINCTRL_PIN_REG_TDSEL,
  58         PINCTRL_PIN_REG_RDSEL,
  59         PINCTRL_PIN_REG_DRV,
  60         PINCTRL_PIN_REG_PUPD,
  61         PINCTRL_PIN_REG_R0,
  62         PINCTRL_PIN_REG_R1,
  63         PINCTRL_PIN_REG_IES,
  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,
  69         PINCTRL_PIN_REG_MAX,
  70 };
  71 
  72 
  73 enum {
  74         DRV_FIXED,
  75         DRV_GRP0,
  76         DRV_GRP1,
  77         DRV_GRP2,
  78         DRV_GRP3,
  79         DRV_GRP4,
  80         DRV_GRP_MAX,
  81 };
  82 
  83 static const char * const mtk_default_register_base_names[] = {
  84         "base",
  85 };
  86 
  87 
  88 
  89 
  90 
  91 
  92 
  93 
  94 
  95 
  96 struct mtk_pin_field {
  97         u8  index;
  98         u32 offset;
  99         u32 mask;
 100         u8  bitpos;
 101         u8  next;
 102 };
 103 
 104 
 105 
 106 
 107 
 108 
 109 
 110 
 111 
 112 
 113 
 114 
 115 
 116 
 117 
 118 
 119 struct mtk_pin_field_calc {
 120         u16 s_pin;
 121         u16 e_pin;
 122         u8  i_base;
 123         u32 s_addr;
 124         u8  x_addrs;
 125         u8  s_bit;
 126         u8  x_bits;
 127         u8  sz_reg;
 128         u8  fixed;
 129 };
 130 
 131 
 132 
 133 
 134 
 135 
 136 
 137 struct mtk_pin_reg_calc {
 138         const struct mtk_pin_field_calc *range;
 139         unsigned int nranges;
 140 };
 141 
 142 
 143 
 144 
 145 
 146 
 147 
 148 struct mtk_func_desc {
 149         const char *name;
 150         u8 muxval;
 151 };
 152 
 153 
 154 
 155 
 156 
 157 
 158 
 159 struct mtk_eint_desc {
 160         u16 eint_m;
 161         u16 eint_n;
 162 };
 163 
 164 
 165 
 166 
 167 
 168 
 169 
 170 
 171 
 172 
 173 
 174 
 175 struct mtk_pin_desc {
 176         unsigned int number;
 177         const char *name;
 178         struct mtk_eint_desc eint;
 179         u8 drv_n;
 180         struct mtk_func_desc *funcs;
 181 };
 182 
 183 struct mtk_pinctrl_group {
 184         const char      *name;
 185         unsigned long   config;
 186         unsigned        pin;
 187 };
 188 
 189 struct mtk_pinctrl;
 190 
 191 
 192 struct mtk_pin_soc {
 193         const struct mtk_pin_reg_calc   *reg_cal;
 194         const struct mtk_pin_desc       *pins;
 195         unsigned int                    npins;
 196         const struct group_desc         *grps;
 197         unsigned int                    ngrps;
 198         const struct function_desc      *funcs;
 199         unsigned int                    nfuncs;
 200         const struct mtk_eint_regs      *eint_regs;
 201         const struct mtk_eint_hw        *eint_hw;
 202 
 203         
 204         u8                              gpio_m;
 205         bool                            ies_present;
 206         const char * const              *base_names;
 207         unsigned int                    nbase_names;
 208 
 209         
 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);
 218 
 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);
 223 
 224         int (*adv_pull_set)(struct mtk_pinctrl *hw,
 225                             const struct mtk_pin_desc *desc, bool pullup,
 226                             u32 arg);
 227         int (*adv_pull_get)(struct mtk_pinctrl *hw,
 228                             const struct mtk_pin_desc *desc, bool pullup,
 229                             u32 *val);
 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);
 234 
 235         
 236         void                            *driver_data;
 237 };
 238 
 239 struct mtk_pinctrl {
 240         struct pinctrl_dev              *pctrl;
 241         void __iomem                    **base;
 242         u8                              nbase;
 243         struct device                   *dev;
 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;
 249 };
 250 
 251 void mtk_rmw(struct mtk_pinctrl *pctl, u8 i, u32 reg, u32 mask, u32 set);
 252 
 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);
 257 
 258 int mtk_build_eint(struct mtk_pinctrl *hw, struct platform_device *pdev);
 259 
 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,
 268                          int *res);
 269 
 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,
 274                                       int *res);
 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,
 279                               int *res);
 280 
 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);
 285 
 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);
 290 
 291 int mtk_pinconf_adv_pull_set(struct mtk_pinctrl *hw,
 292                              const struct mtk_pin_desc *desc, bool pullup,
 293                              u32 arg);
 294 int mtk_pinconf_adv_pull_get(struct mtk_pinctrl *hw,
 295                              const struct mtk_pin_desc *desc, bool pullup,
 296                              u32 *val);
 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);
 301 
 302 #endif