Commit | Line | Data |
---|---|---|
fae43399 MD |
1 | /* |
2 | * SuperH Pin Function Controller Support | |
3 | * | |
4 | * Copyright (c) 2008 Magnus Damm | |
5 | * | |
6 | * This file is subject to the terms and conditions of the GNU General Public | |
7 | * License. See the file "COPYING" in the main directory of this archive | |
8 | * for more details. | |
9 | */ | |
10 | ||
11 | #ifndef __SH_PFC_H | |
12 | #define __SH_PFC_H | |
13 | ||
bf9f0674 | 14 | #include <linux/bug.h> |
5b9eaa56 | 15 | #include <linux/pinctrl/pinconf-generic.h> |
72c7afa1 | 16 | #include <linux/stringify.h> |
fae43399 | 17 | |
06d5631f PM |
18 | enum { |
19 | PINMUX_TYPE_NONE, | |
06d5631f PM |
20 | PINMUX_TYPE_FUNCTION, |
21 | PINMUX_TYPE_GPIO, | |
22 | PINMUX_TYPE_OUTPUT, | |
23 | PINMUX_TYPE_INPUT, | |
06d5631f | 24 | }; |
fae43399 | 25 | |
c58d9c1b LP |
26 | #define SH_PFC_PIN_CFG_INPUT (1 << 0) |
27 | #define SH_PFC_PIN_CFG_OUTPUT (1 << 1) | |
28 | #define SH_PFC_PIN_CFG_PULL_UP (1 << 2) | |
29 | #define SH_PFC_PIN_CFG_PULL_DOWN (1 << 3) | |
5b9eaa56 | 30 | #define SH_PFC_PIN_CFG_IO_VOLTAGE (1 << 4) |
4f82e3ee | 31 | #define SH_PFC_PIN_CFG_NO_GPIO (1 << 31) |
c58d9c1b | 32 | |
a3db40a6 | 33 | struct sh_pfc_pin { |
9689896c | 34 | u16 pin; |
533743dc | 35 | u16 enum_id; |
72c7afa1 | 36 | const char *name; |
c58d9c1b | 37 | unsigned int configs; |
fae43399 MD |
38 | }; |
39 | ||
3d8d9f1d LP |
40 | #define SH_PFC_PIN_GROUP(n) \ |
41 | { \ | |
42 | .name = #n, \ | |
43 | .pins = n##_pins, \ | |
44 | .mux = n##_mux, \ | |
45 | .nr_pins = ARRAY_SIZE(n##_pins), \ | |
46 | } | |
47 | ||
48 | struct sh_pfc_pin_group { | |
49 | const char *name; | |
50 | const unsigned int *pins; | |
51 | const unsigned int *mux; | |
52 | unsigned int nr_pins; | |
53 | }; | |
54 | ||
423caa52 SS |
55 | /* |
56 | * Using union vin_data saves memory occupied by the VIN data pins. | |
57 | * VIN_DATA_PIN_GROUP() is a macro used to describe the VIN pin groups | |
58 | * in this case. | |
59 | */ | |
60 | #define VIN_DATA_PIN_GROUP(n, s) \ | |
61 | { \ | |
62 | .name = #n#s, \ | |
63 | .pins = n##_pins.data##s, \ | |
64 | .mux = n##_mux.data##s, \ | |
65 | .nr_pins = ARRAY_SIZE(n##_pins.data##s), \ | |
66 | } | |
67 | ||
68 | union vin_data { | |
69 | unsigned int data24[24]; | |
70 | unsigned int data20[20]; | |
71 | unsigned int data16[16]; | |
72 | unsigned int data12[12]; | |
73 | unsigned int data10[10]; | |
74 | unsigned int data8[8]; | |
75 | unsigned int data4[4]; | |
76 | }; | |
77 | ||
3d8d9f1d LP |
78 | #define SH_PFC_FUNCTION(n) \ |
79 | { \ | |
80 | .name = #n, \ | |
81 | .groups = n##_groups, \ | |
82 | .nr_groups = ARRAY_SIZE(n##_groups), \ | |
83 | } | |
84 | ||
85 | struct sh_pfc_function { | |
86 | const char *name; | |
87 | const char * const *groups; | |
88 | unsigned int nr_groups; | |
89 | }; | |
90 | ||
a373ed0a | 91 | struct pinmux_func { |
533743dc | 92 | u16 enum_id; |
a373ed0a LP |
93 | const char *name; |
94 | }; | |
95 | ||
fae43399 | 96 | struct pinmux_cfg_reg { |
1f34de05 | 97 | u32 reg; |
dc700715 | 98 | u8 reg_width, field_width; |
533743dc | 99 | const u16 *enum_ids; |
dc700715 | 100 | const u8 *var_field_width; |
fae43399 MD |
101 | }; |
102 | ||
103 | #define PINMUX_CFG_REG(name, r, r_width, f_width) \ | |
104 | .reg = r, .reg_width = r_width, .field_width = f_width, \ | |
9aecff58 | 105 | .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)]) |
f78a26f5 MD |
106 | |
107 | #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \ | |
108 | .reg = r, .reg_width = r_width, \ | |
dc700715 | 109 | .var_field_width = (const u8 [r_width]) \ |
9aecff58 LP |
110 | { var_fw0, var_fwn, 0 }, \ |
111 | .enum_ids = (const u16 []) | |
fae43399 MD |
112 | |
113 | struct pinmux_data_reg { | |
1f34de05 | 114 | u32 reg; |
dc700715 | 115 | u8 reg_width; |
533743dc | 116 | const u16 *enum_ids; |
fae43399 MD |
117 | }; |
118 | ||
119 | #define PINMUX_DATA_REG(name, r, r_width) \ | |
120 | .reg = r, .reg_width = r_width, \ | |
9aecff58 | 121 | .enum_ids = (const u16 [r_width]) \ |
fae43399 | 122 | |
ad2a8e7e | 123 | struct pinmux_irq { |
6d5bddd5 | 124 | const short *gpios; |
ad2a8e7e MD |
125 | }; |
126 | ||
4adeabd0 | 127 | #define PINMUX_IRQ(ids...) \ |
0e26e8df | 128 | { .gpios = (const short []) { ids, -1 } } |
ad2a8e7e | 129 | |
fae43399 | 130 | struct pinmux_range { |
533743dc LP |
131 | u16 begin; |
132 | u16 end; | |
133 | u16 force; | |
fae43399 MD |
134 | }; |
135 | ||
c58d9c1b LP |
136 | struct sh_pfc; |
137 | ||
138 | struct sh_pfc_soc_operations { | |
0c151062 | 139 | int (*init)(struct sh_pfc *pfc); |
c58d9c1b LP |
140 | unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin); |
141 | void (*set_bias)(struct sh_pfc *pfc, unsigned int pin, | |
142 | unsigned int bias); | |
5b9eaa56 BH |
143 | int (*get_io_voltage)(struct sh_pfc *pfc, unsigned int pin); |
144 | int (*set_io_voltage)(struct sh_pfc *pfc, unsigned int pin, | |
145 | u16 voltage_mV); | |
c58d9c1b LP |
146 | }; |
147 | ||
19bb7fe3 | 148 | struct sh_pfc_soc_info { |
cd3c1bee | 149 | const char *name; |
c58d9c1b LP |
150 | const struct sh_pfc_soc_operations *ops; |
151 | ||
fae43399 | 152 | struct pinmux_range input; |
fae43399 | 153 | struct pinmux_range output; |
fae43399 MD |
154 | struct pinmux_range function; |
155 | ||
cd3c1bee | 156 | const struct sh_pfc_pin *pins; |
caa5bac3 | 157 | unsigned int nr_pins; |
3d8d9f1d LP |
158 | const struct sh_pfc_pin_group *groups; |
159 | unsigned int nr_groups; | |
160 | const struct sh_pfc_function *functions; | |
161 | unsigned int nr_functions; | |
162 | ||
56f891b4 | 163 | #ifdef CONFIG_SUPERH |
cd3c1bee | 164 | const struct pinmux_func *func_gpios; |
a373ed0a | 165 | unsigned int nr_func_gpios; |
56f891b4 | 166 | #endif |
d7a7ca57 | 167 | |
cd3c1bee LP |
168 | const struct pinmux_cfg_reg *cfg_regs; |
169 | const struct pinmux_data_reg *data_regs; | |
fae43399 | 170 | |
533743dc | 171 | const u16 *gpio_data; |
fae43399 MD |
172 | unsigned int gpio_data_size; |
173 | ||
cd3c1bee | 174 | const struct pinmux_irq *gpio_irq; |
ad2a8e7e MD |
175 | unsigned int gpio_irq_size; |
176 | ||
1f34de05 | 177 | u32 unlock_reg; |
fae43399 MD |
178 | }; |
179 | ||
e3d93b46 LP |
180 | /* ----------------------------------------------------------------------------- |
181 | * Helper macros to create pin and port lists | |
182 | */ | |
183 | ||
184 | /* | |
185 | * sh_pfc_soc_info gpio_data array macros | |
186 | */ | |
187 | ||
188 | #define PINMUX_DATA(data_or_mark, ids...) data_or_mark, ids, 0 | |
189 | ||
190 | #define PINMUX_IPSR_NOGP(ispr, fn) \ | |
191 | PINMUX_DATA(fn##_MARK, FN_##fn) | |
192 | #define PINMUX_IPSR_DATA(ipsr, fn) \ | |
193 | PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr) | |
194 | #define PINMUX_IPSR_NOGM(ispr, fn, ms) \ | |
195 | PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ms) | |
4c9e4735 NS |
196 | #define PINMUX_IPSR_NOFN(ipsr, fn, ms) \ |
197 | PINMUX_DATA(fn##_MARK, FN_##ipsr, FN_##ms) | |
e3d93b46 | 198 | #define PINMUX_IPSR_MSEL(ipsr, fn, ms) \ |
2b67bccb | 199 | PINMUX_DATA(fn##_MARK, FN_##ms, FN_##ipsr, FN_##fn) |
e3d93b46 LP |
200 | |
201 | /* | |
202 | * GP port style (32 ports banks) | |
203 | */ | |
204 | ||
205 | #define PORT_GP_1(bank, pin, fn, sfx) fn(bank, pin, GP_##bank##_##pin, sfx) | |
206 | ||
207 | #define PORT_GP_32(bank, fn, sfx) \ | |
208 | PORT_GP_1(bank, 0, fn, sfx), PORT_GP_1(bank, 1, fn, sfx), \ | |
209 | PORT_GP_1(bank, 2, fn, sfx), PORT_GP_1(bank, 3, fn, sfx), \ | |
210 | PORT_GP_1(bank, 4, fn, sfx), PORT_GP_1(bank, 5, fn, sfx), \ | |
211 | PORT_GP_1(bank, 6, fn, sfx), PORT_GP_1(bank, 7, fn, sfx), \ | |
212 | PORT_GP_1(bank, 8, fn, sfx), PORT_GP_1(bank, 9, fn, sfx), \ | |
213 | PORT_GP_1(bank, 10, fn, sfx), PORT_GP_1(bank, 11, fn, sfx), \ | |
214 | PORT_GP_1(bank, 12, fn, sfx), PORT_GP_1(bank, 13, fn, sfx), \ | |
215 | PORT_GP_1(bank, 14, fn, sfx), PORT_GP_1(bank, 15, fn, sfx), \ | |
216 | PORT_GP_1(bank, 16, fn, sfx), PORT_GP_1(bank, 17, fn, sfx), \ | |
217 | PORT_GP_1(bank, 18, fn, sfx), PORT_GP_1(bank, 19, fn, sfx), \ | |
218 | PORT_GP_1(bank, 20, fn, sfx), PORT_GP_1(bank, 21, fn, sfx), \ | |
219 | PORT_GP_1(bank, 22, fn, sfx), PORT_GP_1(bank, 23, fn, sfx), \ | |
220 | PORT_GP_1(bank, 24, fn, sfx), PORT_GP_1(bank, 25, fn, sfx), \ | |
221 | PORT_GP_1(bank, 26, fn, sfx), PORT_GP_1(bank, 27, fn, sfx), \ | |
222 | PORT_GP_1(bank, 28, fn, sfx), PORT_GP_1(bank, 29, fn, sfx), \ | |
223 | PORT_GP_1(bank, 30, fn, sfx), PORT_GP_1(bank, 31, fn, sfx) | |
224 | ||
225 | #define PORT_GP_32_REV(bank, fn, sfx) \ | |
226 | PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx), \ | |
227 | PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx), \ | |
228 | PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx), \ | |
229 | PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx), \ | |
230 | PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx), \ | |
231 | PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx), \ | |
232 | PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx), \ | |
233 | PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx), \ | |
234 | PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx), \ | |
235 | PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx), \ | |
236 | PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx), \ | |
237 | PORT_GP_1(bank, 9, fn, sfx), PORT_GP_1(bank, 8, fn, sfx), \ | |
238 | PORT_GP_1(bank, 7, fn, sfx), PORT_GP_1(bank, 6, fn, sfx), \ | |
239 | PORT_GP_1(bank, 5, fn, sfx), PORT_GP_1(bank, 4, fn, sfx), \ | |
240 | PORT_GP_1(bank, 3, fn, sfx), PORT_GP_1(bank, 2, fn, sfx), \ | |
241 | PORT_GP_1(bank, 1, fn, sfx), PORT_GP_1(bank, 0, fn, sfx) | |
242 | ||
243 | /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */ | |
244 | #define _GP_ALL(bank, pin, name, sfx) name##_##sfx | |
245 | #define GP_ALL(str) CPU_ALL_PORT(_GP_ALL, str) | |
246 | ||
247 | /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */ | |
9689896c | 248 | #define _GP_GPIO(bank, _pin, _name, sfx) \ |
61bb3aef | 249 | { \ |
9689896c | 250 | .pin = (bank * 32) + _pin, \ |
e3d93b46 LP |
251 | .name = __stringify(_name), \ |
252 | .enum_id = _name##_DATA, \ | |
253 | } | |
254 | #define PINMUX_GPIO_GP_ALL() CPU_ALL_PORT(_GP_GPIO, unused) | |
255 | ||
256 | /* PINMUX_DATA_GP_ALL - Expand to a list of name_DATA, name_FN marks */ | |
257 | #define _GP_DATA(bank, pin, name, sfx) PINMUX_DATA(name##_DATA, name##_FN) | |
258 | #define PINMUX_DATA_GP_ALL() CPU_ALL_PORT(_GP_DATA, unused) | |
259 | ||
260 | /* | |
261 | * PORT style (linear pin space) | |
262 | */ | |
263 | ||
3ce0d7eb | 264 | #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx) |
16b915e4 LP |
265 | |
266 | #define PORT_10(pn, fn, pfx, sfx) \ | |
267 | PORT_1(pn, fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx), \ | |
268 | PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx), \ | |
269 | PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx), \ | |
270 | PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx), \ | |
271 | PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx) | |
272 | ||
273 | #define PORT_90(pn, fn, pfx, sfx) \ | |
274 | PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \ | |
275 | PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \ | |
276 | PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \ | |
277 | PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \ | |
278 | PORT_10(pn+90, fn, pfx##9, sfx) | |
972c3fb6 | 279 | |
e3d93b46 | 280 | /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */ |
3ce0d7eb | 281 | #define _PORT_ALL(pn, pfx, sfx) pfx##_##sfx |
e3d93b46 | 282 | #define PORT_ALL(str) CPU_ALL_PORT(_PORT_ALL, PORT, str) |
972c3fb6 | 283 | |
e3d93b46 | 284 | /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */ |
9689896c LP |
285 | #define PINMUX_GPIO(_pin) \ |
286 | [GPIO_##_pin] = { \ | |
287 | .pin = (u16)-1, \ | |
8620f394 | 288 | .name = __stringify(GPIO_##_pin), \ |
9689896c | 289 | .enum_id = _pin##_DATA, \ |
e3d93b46 LP |
290 | } |
291 | ||
df020272 | 292 | /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */ |
9689896c | 293 | #define SH_PFC_PIN_CFG(_pin, cfgs) \ |
df020272 | 294 | { \ |
9689896c LP |
295 | .pin = _pin, \ |
296 | .name = __stringify(PORT##_pin), \ | |
297 | .enum_id = PORT##_pin##_DATA, \ | |
df020272 LP |
298 | .configs = cfgs, \ |
299 | } | |
300 | ||
4f82e3ee LP |
301 | /* SH_PFC_PIN_NAMED - Expand to a sh_pfc_pin entry with the given name */ |
302 | #define SH_PFC_PIN_NAMED(row, col, _name) \ | |
303 | { \ | |
304 | .pin = PIN_NUMBER(row, col), \ | |
305 | .name = __stringify(PIN_##_name), \ | |
306 | .configs = SH_PFC_PIN_CFG_NO_GPIO, \ | |
307 | } | |
308 | ||
e3d93b46 LP |
309 | /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0, |
310 | * PORT_name_OUT, PORT_name_IN marks | |
311 | */ | |
3ce0d7eb | 312 | #define _PORT_DATA(pn, pfx, sfx) \ |
e3d93b46 LP |
313 | PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0, \ |
314 | PORT##pfx##_OUT, PORT##pfx##_IN) | |
315 | #define PINMUX_DATA_ALL() CPU_ALL_PORT(_PORT_DATA, , unused) | |
316 | ||
317 | /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */ | |
318 | #define PINMUX_GPIO_FN(gpio, base, data_or_mark) \ | |
319 | [gpio - (base)] = { \ | |
320 | .name = __stringify(gpio), \ | |
321 | .enum_id = data_or_mark, \ | |
322 | } | |
323 | #define GPIO_FN(str) \ | |
324 | PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK) | |
bd8d0cba | 325 | |
e3d93b46 LP |
326 | /* |
327 | * PORTnCR macro | |
328 | */ | |
9b49139b KM |
329 | #define PORTCR(nr, reg) \ |
330 | { \ | |
05c5f265 GU |
331 | PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, 2, 2, 1, 3) {\ |
332 | /* PULMD[1:0], handled by .set_bias() */ \ | |
333 | 0, 0, 0, 0, \ | |
334 | /* IE and OE */ \ | |
335 | 0, PORT##nr##_OUT, PORT##nr##_IN, 0, \ | |
336 | /* SEC, not supported */ \ | |
337 | 0, 0, \ | |
338 | /* PTMD[2:0] */ \ | |
339 | PORT##nr##_FN0, PORT##nr##_FN1, \ | |
340 | PORT##nr##_FN2, PORT##nr##_FN3, \ | |
341 | PORT##nr##_FN4, PORT##nr##_FN5, \ | |
342 | PORT##nr##_FN6, PORT##nr##_FN7 \ | |
343 | } \ | |
9b49139b | 344 | } |
bd8d0cba | 345 | |
fae43399 | 346 | #endif /* __SH_PFC_H */ |