0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/gpio/driver.h>
0009 #include <linux/pinctrl/pinctrl.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/regmap.h>
0012 #include <linux/types.h>
0013 #include <linux/module.h>
0014
0015 struct meson_pinctrl;
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 struct meson_pmx_group {
0029 const char *name;
0030 const unsigned int *pins;
0031 unsigned int num_pins;
0032 const void *data;
0033 };
0034
0035
0036
0037
0038
0039
0040
0041
0042 struct meson_pmx_func {
0043 const char *name;
0044 const char * const *groups;
0045 unsigned int num_groups;
0046 };
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057 struct meson_reg_desc {
0058 unsigned int reg;
0059 unsigned int bit;
0060 };
0061
0062
0063
0064
0065 enum meson_reg_type {
0066 MESON_REG_PULLEN,
0067 MESON_REG_PULL,
0068 MESON_REG_DIR,
0069 MESON_REG_OUT,
0070 MESON_REG_IN,
0071 MESON_REG_DS,
0072 MESON_NUM_REG,
0073 };
0074
0075
0076
0077
0078 enum meson_pinconf_drv {
0079 MESON_PINCONF_DRV_500UA,
0080 MESON_PINCONF_DRV_2500UA,
0081 MESON_PINCONF_DRV_3000UA,
0082 MESON_PINCONF_DRV_4000UA,
0083 };
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099 struct meson_bank {
0100 const char *name;
0101 unsigned int first;
0102 unsigned int last;
0103 int irq_first;
0104 int irq_last;
0105 struct meson_reg_desc regs[MESON_NUM_REG];
0106 };
0107
0108 struct meson_pinctrl_data {
0109 const char *name;
0110 const struct pinctrl_pin_desc *pins;
0111 struct meson_pmx_group *groups;
0112 struct meson_pmx_func *funcs;
0113 unsigned int num_pins;
0114 unsigned int num_groups;
0115 unsigned int num_funcs;
0116 struct meson_bank *banks;
0117 unsigned int num_banks;
0118 const struct pinmux_ops *pmx_ops;
0119 void *pmx_data;
0120 int (*parse_dt)(struct meson_pinctrl *pc);
0121 };
0122
0123 struct meson_pinctrl {
0124 struct device *dev;
0125 struct pinctrl_dev *pcdev;
0126 struct pinctrl_desc desc;
0127 struct meson_pinctrl_data *data;
0128 struct regmap *reg_mux;
0129 struct regmap *reg_pullen;
0130 struct regmap *reg_pull;
0131 struct regmap *reg_gpio;
0132 struct regmap *reg_ds;
0133 struct gpio_chip chip;
0134 struct device_node *of_node;
0135 };
0136
0137 #define FUNCTION(fn) \
0138 { \
0139 .name = #fn, \
0140 .groups = fn ## _groups, \
0141 .num_groups = ARRAY_SIZE(fn ## _groups), \
0142 }
0143
0144 #define BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, \
0145 dsr, dsb) \
0146 { \
0147 .name = n, \
0148 .first = f, \
0149 .last = l, \
0150 .irq_first = fi, \
0151 .irq_last = li, \
0152 .regs = { \
0153 [MESON_REG_PULLEN] = { per, peb }, \
0154 [MESON_REG_PULL] = { pr, pb }, \
0155 [MESON_REG_DIR] = { dr, db }, \
0156 [MESON_REG_OUT] = { or, ob }, \
0157 [MESON_REG_IN] = { ir, ib }, \
0158 [MESON_REG_DS] = { dsr, dsb }, \
0159 }, \
0160 }
0161
0162 #define BANK(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib) \
0163 BANK_DS(n, f, l, fi, li, per, peb, pr, pb, dr, db, or, ob, ir, ib, 0, 0)
0164
0165 #define MESON_PIN(x) PINCTRL_PIN(x, #x)
0166
0167
0168 int meson_pmx_get_funcs_count(struct pinctrl_dev *pcdev);
0169 const char *meson_pmx_get_func_name(struct pinctrl_dev *pcdev,
0170 unsigned selector);
0171 int meson_pmx_get_groups(struct pinctrl_dev *pcdev,
0172 unsigned selector,
0173 const char * const **groups,
0174 unsigned * const num_groups);
0175
0176
0177 int meson_pinctrl_probe(struct platform_device *pdev);
0178
0179 int meson8_aobus_parse_dt_extra(struct meson_pinctrl *pc);
0180
0181 int meson_a1_parse_dt_extra(struct meson_pinctrl *pc);