2 * Copyright (c) 2014 MediaTek Inc.
3 * Author: Hongzhou.Yang <hongzhou.yang@mediatek.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #ifndef __PINCTRL_MTK_COMMON_H
16 #define __PINCTRL_MTK_COMMON_H
18 #include <linux/pinctrl/pinctrl.h>
19 #include <linux/regmap.h>
20 #include <linux/pinctrl/pinconf-generic.h>
24 #define NO_EINT_SUPPORT 255
25 #define MT_EDGE_SENSITIVE 0
26 #define MT_LEVEL_SENSITIVE 1
27 #define EINT_DBNC_SET_DBNC_BITS 4
28 #define EINT_DBNC_RST_BIT (0x1 << 1)
29 #define EINT_DBNC_SET_EN (0x1 << 0)
31 #define MTK_PINCTRL_NOT_SUPPORT (0xffff)
33 struct mtk_desc_function {
38 struct mtk_desc_eint {
39 unsigned char eintmux;
40 unsigned char eintnum;
44 struct pinctrl_pin_desc pin;
45 const struct mtk_desc_eint eint;
46 const struct mtk_desc_function *functions;
49 #define MTK_PIN(_pin, _pad, _chip, _eint, ...) \
53 .functions = (struct mtk_desc_function[]){ \
57 #define MTK_EINT_FUNCTION(_eintmux, _eintnum) \
59 .eintmux = _eintmux, \
60 .eintnum = _eintnum, \
63 #define MTK_FUNCTION(_val, _name) \
69 #define SET_ADDR(x, y) (x + (y->devdata->port_align))
70 #define CLR_ADDR(x, y) (x + (y->devdata->port_align << 1))
72 struct mtk_pinctrl_group {
79 * struct mtk_drv_group_desc - Provide driving group data.
80 * @max_drv: The maximum current of this group.
81 * @min_drv: The minimum current of this group.
82 * @low_bit: The lowest bit of this group.
83 * @high_bit: The highest bit of this group.
84 * @step: The step current of this group.
86 struct mtk_drv_group_desc {
87 unsigned char min_drv;
88 unsigned char max_drv;
89 unsigned char low_bit;
90 unsigned char high_bit;
94 #define MTK_DRV_GRP(_min, _max, _low, _high, _step) \
104 * struct mtk_pin_drv_grp - Provide each pin driving info.
105 * @pin: The pin number.
106 * @offset: The offset of driving register for this pin.
107 * @bit: The bit of driving register for this pin.
108 * @grp: The group for this pin belongs to.
110 struct mtk_pin_drv_grp {
112 unsigned short offset;
117 #define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp) \
126 * struct mtk_pin_spec_pupd_set_samereg
127 * - For special pins' pull up/down setting which resides in same register
128 * @pin: The pin number.
129 * @offset: The offset of special pull up/down setting register.
130 * @pupd_bit: The pull up/down bit in this register.
131 * @r0_bit: The r0 bit of pull resistor.
132 * @r1_bit: The r1 bit of pull resistor.
134 struct mtk_pin_spec_pupd_set_samereg {
136 unsigned short offset;
137 unsigned char pupd_bit;
138 unsigned char r1_bit;
139 unsigned char r0_bit;
142 #define MTK_PIN_PUPD_SPEC_SR(_pin, _offset, _pupd, _r1, _r0) \
152 * struct mtk_pin_ies_set - For special pins' ies and smt setting.
153 * @start: The start pin number of those special pins.
154 * @end: The end pin number of those special pins.
155 * @offset: The offset of special setting register.
156 * @bit: The bit of special setting register.
158 struct mtk_pin_ies_smt_set {
159 unsigned short start;
161 unsigned short offset;
165 #define MTK_PIN_IES_SMT_SPEC(_start, _end, _offset, _bit) \
173 struct mtk_eint_offsets {
178 unsigned int mask_set;
179 unsigned int mask_clr;
181 unsigned int sens_set;
182 unsigned int sens_clr;
184 unsigned int soft_set;
185 unsigned int soft_clr;
187 unsigned int pol_set;
188 unsigned int pol_clr;
190 unsigned int dbnc_ctrl;
191 unsigned int dbnc_set;
192 unsigned int dbnc_clr;
198 * struct mtk_pinctrl_devdata - Provide HW GPIO related data.
199 * @pins: An array describing all pins the pin controller affects.
200 * @npins: The number of entries in @pins.
202 * @grp_desc: The driving group info.
203 * @pin_drv_grp: The driving group for all pins.
204 * @spec_pull_set: Each SoC may have special pins for pull up/down setting,
205 * these pins' pull setting are very different, they have separate pull
206 * up/down bit, R0 and R1 resistor bit, so they need special pull setting.
207 * If special setting is success, this should return 0, otherwise it should
208 * return non-zero value.
209 * @spec_ies_smt_set: Some pins are irregular, their input enable and smt
210 * control register are discontinuous, but they are mapping together. That
211 * means when user set smt, input enable is set at the same time. So they
212 * also need special control. If special control is success, this should
213 * return 0, otherwise return non-zero value.
214 * @spec_pinmux_set: In some cases, there are two pinmux functions share
215 * the same value in the same segment of pinmux control register. If user
216 * want to use one of the two functions, they need an extra bit setting to
217 * select the right one.
218 * @spec_dir_set: In very few SoCs, direction control registers are not
219 * arranged continuously, they may be cut to parts. So they need special
222 * @dir_offset: The direction register offset.
223 * @pullen_offset: The pull-up/pull-down enable register offset.
224 * @pinmux_offset: The pinmux register offset.
226 * @type1_start: Some chips have two base addresses for pull select register,
227 * that means some pins use the first address and others use the second. This
228 * member record the start of pin number to use the second address.
229 * @type1_end: The end of pin number to use the second address.
231 * @port_shf: The shift between two registers.
232 * @port_mask: The mask of register.
233 * @port_align: Provide clear register and set register step.
235 struct mtk_pinctrl_devdata {
236 const struct mtk_desc_pin *pins;
238 const struct mtk_drv_group_desc *grp_desc;
239 unsigned int n_grp_cls;
240 const struct mtk_pin_drv_grp *pin_drv_grp;
241 unsigned int n_pin_drv_grps;
242 int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
243 unsigned char align, bool isup, unsigned int arg);
244 int (*spec_ies_smt_set)(struct regmap *reg, unsigned int pin,
245 unsigned char align, int value, enum pin_config_param arg);
246 void (*spec_pinmux_set)(struct regmap *reg, unsigned int pin,
248 void (*spec_dir_set)(unsigned int *reg_addr, unsigned int pin);
249 unsigned int dir_offset;
250 unsigned int ies_offset;
251 unsigned int smt_offset;
252 unsigned int pullen_offset;
253 unsigned int pullsel_offset;
254 unsigned int drv_offset;
255 unsigned int dout_offset;
256 unsigned int din_offset;
257 unsigned int pinmux_offset;
258 unsigned short type1_start;
259 unsigned short type1_end;
260 unsigned char port_shf;
261 unsigned char port_mask;
262 unsigned char port_align;
263 struct mtk_eint_hw eint_hw;
264 struct mtk_eint_regs eint_regs;
268 struct regmap *regmap1;
269 struct regmap *regmap2;
270 struct pinctrl_desc pctl_desc;
272 struct gpio_chip *chip;
273 struct mtk_pinctrl_group *groups;
275 const char **grp_names;
276 struct pinctrl_dev *pctl_dev;
277 const struct mtk_pinctrl_devdata *devdata;
278 struct mtk_eint *eint;
281 int mtk_pctrl_init(struct platform_device *pdev,
282 const struct mtk_pinctrl_devdata *data,
283 struct regmap *regmap);
285 int mtk_pctrl_spec_pull_set_samereg(struct regmap *regmap,
286 const struct mtk_pin_spec_pupd_set_samereg *pupd_infos,
287 unsigned int info_num, unsigned int pin,
288 unsigned char align, bool isup, unsigned int r1r0);
290 int mtk_pconf_spec_set_ies_smt_range(struct regmap *regmap,
291 const struct mtk_pin_ies_smt_set *ies_smt_infos, unsigned int info_num,
292 unsigned int pin, unsigned char align, int value);
294 extern const struct dev_pm_ops mtk_eint_pm_ops;
296 #endif /* __PINCTRL_MTK_COMMON_H */