]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/pinctrl/mediatek/pinctrl-mtk-common.h
pinctrl: mediatek: Add EINT support to MTK pinctrl driver.
[karo-tx-linux.git] / drivers / pinctrl / mediatek / pinctrl-mtk-common.h
1 /*
2  * Copyright (c) 2014 MediaTek Inc.
3  * Author: Hongzhou.Yang <hongzhou.yang@mediatek.com>
4  *
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.
8  *
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.
13  */
14
15 #ifndef __PINCTRL_MTK_COMMON_H
16 #define __PINCTRL_MTK_COMMON_H
17
18 #include <linux/pinctrl/pinctrl.h>
19 #include <linux/regmap.h>
20
21 #define NO_EINT_SUPPORT    255
22 #define MTK_CHIP_TYPE_BASE     0
23 #define MTK_CHIP_TYPE_PMIC     1
24 #define MT_EDGE_SENSITIVE           0
25 #define MT_LEVEL_SENSITIVE          1
26 #define EINT_DBNC_SET_DBNC_BITS     4
27 #define EINT_DBNC_RST_BIT           (0x1 << 1)
28 #define EINT_DBNC_SET_EN            (0x1 << 0)
29
30 struct mtk_desc_function {
31         const char *name;
32         unsigned char muxval;
33 };
34
35 struct mtk_desc_eint {
36         unsigned char eintmux;
37         unsigned char eintnum;
38 };
39
40 struct mtk_desc_pin {
41         struct pinctrl_pin_desc pin;
42         const char *chip;
43         const struct mtk_desc_eint eint;
44         const struct mtk_desc_function  *functions;
45 };
46
47 #define MTK_PIN(_pin, _pad, _chip, _eint, ...)          \
48         {                                                       \
49                 .pin = _pin,                                    \
50                 .chip = _chip,                                  \
51                 .eint = _eint,                                  \
52                 .functions = (struct mtk_desc_function[]){      \
53                         __VA_ARGS__, { } },                     \
54         }
55
56 #define MTK_EINT_FUNCTION(_eintmux, _eintnum)                           \
57         {                                                       \
58                 .eintmux = _eintmux,                                    \
59                 .eintnum = _eintnum,                                    \
60         }
61
62 #define MTK_FUNCTION(_val, _name)                               \
63         {                                                       \
64                 .muxval = _val,                                 \
65                 .name = _name,                                  \
66         }
67
68 #define SET_ADDR(x, y)  (x + (y->devdata->port_align))
69 #define CLR_ADDR(x, y)  (x + (y->devdata->port_align << 1))
70
71 struct mtk_pinctrl_group {
72         const char      *name;
73         unsigned long   config;
74         unsigned        pin;
75 };
76
77 /**
78  * struct mtk_drv_group_desc - Provide driving group data.
79  * @max_drv: The maximum current of this group.
80  * @min_drv: The minimum current of this group.
81  * @low_bit: The lowest bit of this group.
82  * @high_bit: The highest bit of this group.
83  * @step: The step current of this group.
84  */
85 struct mtk_drv_group_desc {
86         unsigned char min_drv;
87         unsigned char max_drv;
88         unsigned char low_bit;
89         unsigned char high_bit;
90         unsigned char step;
91 };
92
93 #define MTK_DRV_GRP(_min, _max, _low, _high, _step)     \
94         {       \
95                 .min_drv = _min,        \
96                 .max_drv = _max,        \
97                 .low_bit = _low,        \
98                 .high_bit = _high,      \
99                 .step = _step,          \
100         }
101
102 /**
103  * struct mtk_pin_drv_grp - Provide each pin driving info.
104  * @pin: The pin number.
105  * @offset: The offset of driving register for this pin.
106  * @bit: The bit of driving register for this pin.
107  * @grp: The group for this pin belongs to.
108  */
109 struct mtk_pin_drv_grp {
110         unsigned int pin;
111         unsigned int offset;
112         unsigned char bit;
113         unsigned char grp;
114 };
115
116 #define MTK_PIN_DRV_GRP(_pin, _offset, _bit, _grp)      \
117         {       \
118                 .pin = _pin,    \
119                 .offset = _offset,      \
120                 .bit = _bit,    \
121                 .grp = _grp,    \
122         }
123
124 struct mtk_eint_offsets {
125         const char *name;
126         unsigned int  stat;
127         unsigned int  ack;
128         unsigned int  mask;
129         unsigned int  mask_set;
130         unsigned int  mask_clr;
131         unsigned int  sens;
132         unsigned int  sens_set;
133         unsigned int  sens_clr;
134         unsigned int  pol;
135         unsigned int  pol_set;
136         unsigned int  pol_clr;
137         unsigned int  dom_en;
138         unsigned int  dbnc_ctrl;
139         unsigned int  dbnc_set;
140         unsigned int  dbnc_clr;
141         u8  port_mask;
142         u8  ports;
143 };
144
145 /**
146  * struct mtk_pinctrl_devdata - Provide HW GPIO related data.
147  * @pins: An array describing all pins the pin controller affects.
148  * @npins: The number of entries in @pins.
149  *
150  * @grp_desc: The driving group info.
151  * @pin_drv_grp: The driving group for all pins.
152  * @spec_pull_set: Each SoC may have special pins for pull up/down setting,
153  *  these pins' pull setting are very different, they have separate pull
154  *  up/down bit, R0 and R1 resistor bit, so they need special pull setting.
155  *  If special setting is success, this should return 0, otherwise it should
156  *  return non-zero value.
157  *
158  * @dir_offset: The direction register offset.
159  * @pullen_offset: The pull-up/pull-down enable register offset.
160  * @pinmux_offset: The pinmux register offset.
161  *
162  * @type1_start: Some chips have two base addresses for pull select register,
163  *  that means some pins use the first address and others use the second. This
164  *  member record the start of pin number to use the second address.
165  * @type1_end: The end of pin number to use the second address.
166  *
167  * @port_shf: The shift between two registers.
168  * @port_mask: The mask of register.
169  * @port_align: Provide clear register and set register step.
170  */
171 struct mtk_pinctrl_devdata {
172         const struct mtk_desc_pin       *pins;
173         unsigned int                            npins;
174         const struct mtk_drv_group_desc *grp_desc;
175         unsigned int    n_grp_cls;
176         const struct mtk_pin_drv_grp    *pin_drv_grp;
177         unsigned int    n_pin_drv_grps;
178         int (*spec_pull_set)(struct regmap *reg, unsigned int pin,
179                         unsigned char align, bool isup, unsigned int arg);
180         unsigned int dir_offset;
181         unsigned int ies_offset;
182         unsigned int smt_offset;
183         unsigned int pullen_offset;
184         unsigned int pullsel_offset;
185         unsigned int drv_offset;
186         unsigned int invser_offset;
187         unsigned int dout_offset;
188         unsigned int din_offset;
189         unsigned int pinmux_offset;
190         unsigned short type1_start;
191         unsigned short type1_end;
192         unsigned char  port_shf;
193         unsigned char  port_mask;
194         unsigned char  port_align;
195         unsigned char   chip_type;
196         struct mtk_eint_offsets eint_offsets;
197         unsigned int    ap_num;
198         unsigned int    db_cnt;
199 };
200
201 struct mtk_pinctrl {
202         struct regmap   *regmap1;
203         struct regmap   *regmap2;
204         struct device           *dev;
205         struct gpio_chip        *chip;
206         struct mtk_pinctrl_group        *groups;
207         unsigned                        ngroups;
208         const char          **grp_names;
209         struct pinctrl_dev      *pctl_dev;
210         const struct mtk_pinctrl_devdata  *devdata;
211         void __iomem            *eint_reg_base;
212         struct irq_domain       *domain;
213 };
214
215 int mtk_pctrl_init(struct platform_device *pdev,
216                 const struct mtk_pinctrl_devdata *data);
217
218 #endif /* __PINCTRL_MTK_COMMON_H */