pinctrl: renesas: Add R8A77965 pin control tables
[platform/kernel/u-boot.git] / drivers / pinctrl / renesas / sh_pfc.h
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
14 #include <linux/stringify.h>
15
16 enum {
17         PINMUX_TYPE_NONE,
18         PINMUX_TYPE_FUNCTION,
19         PINMUX_TYPE_GPIO,
20         PINMUX_TYPE_OUTPUT,
21         PINMUX_TYPE_INPUT,
22 };
23
24 #define SH_PFC_PIN_CFG_INPUT            (1 << 0)
25 #define SH_PFC_PIN_CFG_OUTPUT           (1 << 1)
26 #define SH_PFC_PIN_CFG_PULL_UP          (1 << 2)
27 #define SH_PFC_PIN_CFG_PULL_DOWN        (1 << 3)
28 #define SH_PFC_PIN_CFG_IO_VOLTAGE       (1 << 4)
29 #define SH_PFC_PIN_CFG_DRIVE_STRENGTH   (1 << 5)
30 #define SH_PFC_PIN_CFG_NO_GPIO          (1 << 31)
31
32 struct sh_pfc_pin {
33         u16 pin;
34         u16 enum_id;
35         const char *name;
36         unsigned int configs;
37 };
38
39 #define SH_PFC_PIN_GROUP_ALIAS(alias, n)                \
40         {                                               \
41                 .name = #alias,                         \
42                 .pins = n##_pins,                       \
43                 .mux = n##_mux,                         \
44                 .nr_pins = ARRAY_SIZE(n##_pins),        \
45         }
46 #define SH_PFC_PIN_GROUP(n)     SH_PFC_PIN_GROUP_ALIAS(n, n)
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
55 /*
56  * Using union vin_data{,12,16} 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. It accepts an optional 'version' argument used when the
59  * same group can appear on a different set of pins.
60  */
61 #define VIN_DATA_PIN_GROUP(n, s, ...)                                   \
62         {                                                               \
63                 .name = #n#s#__VA_ARGS__,                               \
64                 .pins = n##__VA_ARGS__##_pins.data##s,                  \
65                 .mux = n##__VA_ARGS__##_mux.data##s,                    \
66                 .nr_pins = ARRAY_SIZE(n##__VA_ARGS__##_pins.data##s),   \
67         }
68
69 union vin_data16 {
70         unsigned int data16[16];
71         unsigned int data12[12];
72         unsigned int data10[10];
73         unsigned int data8[8];
74 };
75
76 union vin_data {
77         unsigned int data24[24];
78         unsigned int data20[20];
79         unsigned int data16[16];
80         unsigned int data12[12];
81         unsigned int data10[10];
82         unsigned int data8[8];
83         unsigned int data4[4];
84 };
85
86 #define SH_PFC_FUNCTION(n)                              \
87         {                                               \
88                 .name = #n,                             \
89                 .groups = n##_groups,                   \
90                 .nr_groups = ARRAY_SIZE(n##_groups),    \
91         }
92
93 struct sh_pfc_function {
94         const char *name;
95         const char * const *groups;
96         unsigned int nr_groups;
97 };
98
99 struct pinmux_func {
100         u16 enum_id;
101         const char *name;
102 };
103
104 struct pinmux_cfg_reg {
105         u32 reg;
106         u8 reg_width, field_width;
107         const u16 *enum_ids;
108         const u8 *var_field_width;
109 };
110
111 /*
112  * Describe a config register consisting of several fields of the same width
113  *   - name: Register name (unused, for documentation purposes only)
114  *   - r: Physical register address
115  *   - r_width: Width of the register (in bits)
116  *   - f_width: Width of the fixed-width register fields (in bits)
117  * This macro must be followed by initialization data: For each register field
118  * (from left to right, i.e. MSB to LSB), 2^f_width enum IDs must be specified,
119  * one for each possible combination of the register field bit values.
120  */
121 #define PINMUX_CFG_REG(name, r, r_width, f_width) \
122         .reg = r, .reg_width = r_width, .field_width = f_width,         \
123         .enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])
124
125 /*
126  * Describe a config register consisting of several fields of different widths
127  *   - name: Register name (unused, for documentation purposes only)
128  *   - r: Physical register address
129  *   - r_width: Width of the register (in bits)
130  *   - var_fw0, var_fwn...: List of widths of the register fields (in bits),
131  *                          From left to right (i.e. MSB to LSB)
132  * This macro must be followed by initialization data: For each register field
133  * (from left to right, i.e. MSB to LSB), 2^var_fwi enum IDs must be specified,
134  * one for each possible combination of the register field bit values.
135  */
136 #define PINMUX_CFG_REG_VAR(name, r, r_width, var_fw0, var_fwn...) \
137         .reg = r, .reg_width = r_width, \
138         .var_field_width = (const u8 [r_width]) \
139                 { var_fw0, var_fwn, 0 }, \
140         .enum_ids = (const u16 [])
141
142 struct pinmux_drive_reg_field {
143         u16 pin;
144         u8 offset;
145         u8 size;
146 };
147
148 struct pinmux_drive_reg {
149         u32 reg;
150         const struct pinmux_drive_reg_field fields[8];
151 };
152
153 #define PINMUX_DRIVE_REG(name, r) \
154         .reg = r, \
155         .fields =
156
157 struct pinmux_bias_reg {
158         u32 puen;               /* Pull-enable or pull-up control register */
159         u32 pud;                /* Pull-up/down control register (optional) */
160         const u16 pins[32];
161 };
162
163 #define PINMUX_BIAS_REG(name1, r1, name2, r2) \
164         .puen = r1,     \
165         .pud = r2,      \
166         .pins =
167
168 struct pinmux_ioctrl_reg {
169         u32 reg;
170 };
171
172 struct pinmux_data_reg {
173         u32 reg;
174         u8 reg_width;
175         const u16 *enum_ids;
176 };
177
178 /*
179  * Describe a data register
180  *   - name: Register name (unused, for documentation purposes only)
181  *   - r: Physical register address
182  *   - r_width: Width of the register (in bits)
183  * This macro must be followed by initialization data: For each register bit
184  * (from left to right, i.e. MSB to LSB), one enum ID must be specified.
185  */
186 #define PINMUX_DATA_REG(name, r, r_width) \
187         .reg = r, .reg_width = r_width, \
188         .enum_ids = (const u16 [r_width]) \
189
190 struct pinmux_irq {
191         const short *gpios;
192 };
193
194 /*
195  * Describe the mapping from GPIOs to a single IRQ
196  *   - ids...: List of GPIOs that are mapped to the same IRQ
197  */
198 #define PINMUX_IRQ(ids...)                         \
199         { .gpios = (const short []) { ids, -1 } }
200
201 struct pinmux_range {
202         u16 begin;
203         u16 end;
204         u16 force;
205 };
206
207 struct sh_pfc_window {
208         phys_addr_t phys;
209         void __iomem *virt;
210         unsigned long size;
211 };
212
213 struct sh_pfc_pin_range;
214
215 struct sh_pfc {
216         struct device *dev;
217         const struct sh_pfc_soc_info *info;
218
219         void *regs;
220
221         struct sh_pfc_pin_range *ranges;
222         unsigned int nr_ranges;
223
224         unsigned int nr_gpio_pins;
225
226         struct sh_pfc_chip *gpio;
227 };
228
229 struct sh_pfc_soc_operations {
230         int (*init)(struct sh_pfc *pfc);
231         unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
232         void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
233                          unsigned int bias);
234         int (*pin_to_pocctrl)(struct sh_pfc *pfc, unsigned int pin, u32 *pocctrl);
235 };
236
237 struct sh_pfc_soc_info {
238         const char *name;
239         const struct sh_pfc_soc_operations *ops;
240
241         struct pinmux_range input;
242         struct pinmux_range output;
243         struct pinmux_range function;
244
245         const struct sh_pfc_pin *pins;
246         unsigned int nr_pins;
247         const struct sh_pfc_pin_group *groups;
248         unsigned int nr_groups;
249         const struct sh_pfc_function *functions;
250         unsigned int nr_functions;
251
252         const struct pinmux_cfg_reg *cfg_regs;
253         const struct pinmux_drive_reg *drive_regs;
254         const struct pinmux_bias_reg *bias_regs;
255         const struct pinmux_ioctrl_reg *ioctrl_regs;
256         const struct pinmux_data_reg *data_regs;
257
258         const u16 *pinmux_data;
259         unsigned int pinmux_data_size;
260
261         const struct pinmux_irq *gpio_irq;
262         unsigned int gpio_irq_size;
263
264         u32 unlock_reg;
265 };
266
267 u32 sh_pfc_read(struct sh_pfc *pfc, u32 reg);
268 void sh_pfc_write(struct sh_pfc *pfc, u32 reg, u32 data);
269 const struct pinmux_bias_reg *
270 sh_pfc_pin_to_bias_reg(const struct sh_pfc *pfc, unsigned int pin,
271                        unsigned int *bit);
272 int sh_pfc_config_mux_for_gpio(struct udevice *dev, unsigned pin_selector);
273
274 extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
275 extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
276 extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
277 extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
278 extern const struct sh_pfc_soc_info r8a7794_pinmux_info;
279 extern const struct sh_pfc_soc_info r8a7795_pinmux_info;
280 extern const struct sh_pfc_soc_info r8a7796_pinmux_info;
281 extern const struct sh_pfc_soc_info r8a77965_pinmux_info;
282 extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
283 extern const struct sh_pfc_soc_info r8a77990_pinmux_info;
284 extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
285 /* -----------------------------------------------------------------------------
286  * Helper macros to create pin and port lists
287  */
288
289 /*
290  * sh_pfc_soc_info pinmux_data array macros
291  */
292
293 /*
294  * Describe generic pinmux data
295  *   - data_or_mark: *_DATA or *_MARK enum ID
296  *   - ids...: List of enum IDs to associate with data_or_mark
297  */
298 #define PINMUX_DATA(data_or_mark, ids...)       data_or_mark, ids, 0
299
300 /*
301  * Describe a pinmux configuration without GPIO function that needs
302  * configuration in a Peripheral Function Select Register (IPSR)
303  *   - ipsr: IPSR field (unused, for documentation purposes only)
304  *   - fn: Function name, referring to a field in the IPSR
305  */
306 #define PINMUX_IPSR_NOGP(ipsr, fn)                                      \
307         PINMUX_DATA(fn##_MARK, FN_##fn)
308
309 /*
310  * Describe a pinmux configuration with GPIO function that needs configuration
311  * in both a Peripheral Function Select Register (IPSR) and in a
312  * GPIO/Peripheral Function Select Register (GPSR)
313  *   - ipsr: IPSR field
314  *   - fn: Function name, also referring to the IPSR field
315  */
316 #define PINMUX_IPSR_GPSR(ipsr, fn)                                      \
317         PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
318
319 /*
320  * Describe a pinmux configuration without GPIO function that needs
321  * configuration in a Peripheral Function Select Register (IPSR), and where the
322  * pinmux function has a representation in a Module Select Register (MOD_SEL).
323  *   - ipsr: IPSR field (unused, for documentation purposes only)
324  *   - fn: Function name, also referring to the IPSR field
325  *   - msel: Module selector
326  */
327 #define PINMUX_IPSR_NOGM(ipsr, fn, msel)                                \
328         PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
329
330 /*
331  * Describe a pinmux configuration with GPIO function where the pinmux function
332  * has no representation in a Peripheral Function Select Register (IPSR), but
333  * instead solely depends on a group selection.
334  *   - gpsr: GPSR field
335  *   - fn: Function name, also referring to the GPSR field
336  *   - gsel: Group selector
337  */
338 #define PINMUX_IPSR_NOFN(gpsr, fn, gsel)                                \
339         PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
340
341 /*
342  * Describe a pinmux configuration with GPIO function that needs configuration
343  * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral
344  * Function Select Register (GPSR), and where the pinmux function has a
345  * representation in a Module Select Register (MOD_SEL).
346  *   - ipsr: IPSR field
347  *   - fn: Function name, also referring to the IPSR field
348  *   - msel: Module selector
349  */
350 #define PINMUX_IPSR_MSEL(ipsr, fn, msel)                                \
351         PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
352
353 /*
354  * Describe a pinmux configuration for a single-function pin with GPIO
355  * capability.
356  *   - fn: Function name
357  */
358 #define PINMUX_SINGLE(fn)                                               \
359         PINMUX_DATA(fn##_MARK, FN_##fn)
360
361 /*
362  * GP port style (32 ports banks)
363  */
364
365 #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg)                          \
366         fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
367 #define PORT_GP_1(bank, pin, fn, sfx)   PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
368
369 #define PORT_GP_CFG_4(bank, fn, sfx, cfg)                               \
370         PORT_GP_CFG_1(bank, 0,  fn, sfx, cfg),                          \
371         PORT_GP_CFG_1(bank, 1,  fn, sfx, cfg),                          \
372         PORT_GP_CFG_1(bank, 2,  fn, sfx, cfg),                          \
373         PORT_GP_CFG_1(bank, 3,  fn, sfx, cfg)
374 #define PORT_GP_4(bank, fn, sfx)        PORT_GP_CFG_4(bank, fn, sfx, 0)
375
376 #define PORT_GP_CFG_6(bank, fn, sfx, cfg)                               \
377         PORT_GP_CFG_4(bank, fn, sfx, cfg),                              \
378         PORT_GP_CFG_1(bank, 4,  fn, sfx, cfg),                          \
379         PORT_GP_CFG_1(bank, 5,  fn, sfx, cfg)
380 #define PORT_GP_6(bank, fn, sfx)        PORT_GP_CFG_6(bank, fn, sfx, 0)
381
382 #define PORT_GP_CFG_8(bank, fn, sfx, cfg)                               \
383         PORT_GP_CFG_6(bank, fn, sfx, cfg),                              \
384         PORT_GP_CFG_1(bank, 6,  fn, sfx, cfg),                          \
385         PORT_GP_CFG_1(bank, 7,  fn, sfx, cfg)
386 #define PORT_GP_8(bank, fn, sfx)        PORT_GP_CFG_8(bank, fn, sfx, 0)
387
388 #define PORT_GP_CFG_9(bank, fn, sfx, cfg)                               \
389         PORT_GP_CFG_8(bank, fn, sfx, cfg),                              \
390         PORT_GP_CFG_1(bank, 8,  fn, sfx, cfg)
391 #define PORT_GP_9(bank, fn, sfx)        PORT_GP_CFG_9(bank, fn, sfx, 0)
392
393 #define PORT_GP_CFG_10(bank, fn, sfx, cfg)                              \
394         PORT_GP_CFG_9(bank, fn, sfx, cfg),                              \
395         PORT_GP_CFG_1(bank, 9,  fn, sfx, cfg)
396 #define PORT_GP_10(bank, fn, sfx)       PORT_GP_CFG_10(bank, fn, sfx, 0)
397
398 #define PORT_GP_CFG_11(bank, fn, sfx, cfg)                              \
399         PORT_GP_CFG_10(bank, fn, sfx, cfg),                             \
400         PORT_GP_CFG_1(bank, 10,  fn, sfx, cfg)
401 #define PORT_GP_11(bank, fn, sfx)       PORT_GP_CFG_11(bank, fn, sfx, 0)
402
403 #define PORT_GP_CFG_12(bank, fn, sfx, cfg)                              \
404         PORT_GP_CFG_10(bank, fn, sfx, cfg),                             \
405         PORT_GP_CFG_1(bank, 10, fn, sfx, cfg),                          \
406         PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
407 #define PORT_GP_12(bank, fn, sfx)       PORT_GP_CFG_12(bank, fn, sfx, 0)
408
409 #define PORT_GP_CFG_14(bank, fn, sfx, cfg)                              \
410         PORT_GP_CFG_12(bank, fn, sfx, cfg),                             \
411         PORT_GP_CFG_1(bank, 12, fn, sfx, cfg),                          \
412         PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
413 #define PORT_GP_14(bank, fn, sfx)       PORT_GP_CFG_14(bank, fn, sfx, 0)
414
415 #define PORT_GP_CFG_15(bank, fn, sfx, cfg)                              \
416         PORT_GP_CFG_14(bank, fn, sfx, cfg),                             \
417         PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
418 #define PORT_GP_15(bank, fn, sfx)       PORT_GP_CFG_15(bank, fn, sfx, 0)
419
420 #define PORT_GP_CFG_16(bank, fn, sfx, cfg)                              \
421         PORT_GP_CFG_15(bank, fn, sfx, cfg),                             \
422         PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
423 #define PORT_GP_16(bank, fn, sfx)       PORT_GP_CFG_16(bank, fn, sfx, 0)
424
425 #define PORT_GP_CFG_17(bank, fn, sfx, cfg)                              \
426         PORT_GP_CFG_16(bank, fn, sfx, cfg),                             \
427         PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
428 #define PORT_GP_17(bank, fn, sfx)       PORT_GP_CFG_17(bank, fn, sfx, 0)
429
430 #define PORT_GP_CFG_18(bank, fn, sfx, cfg)                              \
431         PORT_GP_CFG_17(bank, fn, sfx, cfg),                             \
432         PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
433 #define PORT_GP_18(bank, fn, sfx)       PORT_GP_CFG_18(bank, fn, sfx, 0)
434
435 #define PORT_GP_CFG_20(bank, fn, sfx, cfg)                              \
436         PORT_GP_CFG_18(bank, fn, sfx, cfg),                             \
437         PORT_GP_CFG_1(bank, 18, fn, sfx, cfg),                          \
438         PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
439 #define PORT_GP_20(bank, fn, sfx)       PORT_GP_CFG_20(bank, fn, sfx, 0)
440
441 #define PORT_GP_CFG_21(bank, fn, sfx, cfg)                              \
442         PORT_GP_CFG_20(bank, fn, sfx, cfg),                             \
443         PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
444 #define PORT_GP_21(bank, fn, sfx)       PORT_GP_CFG_21(bank, fn, sfx, 0)
445
446 #define PORT_GP_CFG_22(bank, fn, sfx, cfg)                              \
447         PORT_GP_CFG_21(bank, fn, sfx, cfg),                             \
448         PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
449 #define PORT_GP_22(bank, fn, sfx)       PORT_GP_CFG_22(bank, fn, sfx, 0)
450
451 #define PORT_GP_CFG_23(bank, fn, sfx, cfg)                              \
452         PORT_GP_CFG_22(bank, fn, sfx, cfg),                             \
453         PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
454 #define PORT_GP_23(bank, fn, sfx)       PORT_GP_CFG_23(bank, fn, sfx, 0)
455
456 #define PORT_GP_CFG_24(bank, fn, sfx, cfg)                              \
457         PORT_GP_CFG_23(bank, fn, sfx, cfg),                             \
458         PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
459 #define PORT_GP_24(bank, fn, sfx)       PORT_GP_CFG_24(bank, fn, sfx, 0)
460
461 #define PORT_GP_CFG_25(bank, fn, sfx, cfg)                              \
462         PORT_GP_CFG_24(bank, fn, sfx, cfg),                             \
463         PORT_GP_CFG_1(bank, 24, fn, sfx, cfg)
464 #define PORT_GP_25(bank, fn, sfx)       PORT_GP_CFG_25(bank, fn, sfx, 0)
465
466 #define PORT_GP_CFG_26(bank, fn, sfx, cfg)                              \
467         PORT_GP_CFG_25(bank, fn, sfx, cfg),                             \
468         PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
469 #define PORT_GP_26(bank, fn, sfx)       PORT_GP_CFG_26(bank, fn, sfx, 0)
470
471 #define PORT_GP_CFG_28(bank, fn, sfx, cfg)                              \
472         PORT_GP_CFG_26(bank, fn, sfx, cfg),                             \
473         PORT_GP_CFG_1(bank, 26, fn, sfx, cfg),                          \
474         PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
475 #define PORT_GP_28(bank, fn, sfx)       PORT_GP_CFG_28(bank, fn, sfx, 0)
476
477 #define PORT_GP_CFG_29(bank, fn, sfx, cfg)                              \
478         PORT_GP_CFG_28(bank, fn, sfx, cfg),                             \
479         PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
480 #define PORT_GP_29(bank, fn, sfx)       PORT_GP_CFG_29(bank, fn, sfx, 0)
481
482 #define PORT_GP_CFG_30(bank, fn, sfx, cfg)                              \
483         PORT_GP_CFG_29(bank, fn, sfx, cfg),                             \
484         PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
485 #define PORT_GP_30(bank, fn, sfx)       PORT_GP_CFG_30(bank, fn, sfx, 0)
486
487 #define PORT_GP_CFG_32(bank, fn, sfx, cfg)                              \
488         PORT_GP_CFG_30(bank, fn, sfx, cfg),                             \
489         PORT_GP_CFG_1(bank, 30, fn, sfx, cfg),                          \
490         PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
491 #define PORT_GP_32(bank, fn, sfx)       PORT_GP_CFG_32(bank, fn, sfx, 0)
492
493 #define PORT_GP_32_REV(bank, fn, sfx)                                   \
494         PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx),     \
495         PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx),     \
496         PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx),     \
497         PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx),     \
498         PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx),     \
499         PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx),     \
500         PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx),     \
501         PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx),     \
502         PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx),     \
503         PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx),     \
504         PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx),     \
505         PORT_GP_1(bank, 9,  fn, sfx), PORT_GP_1(bank, 8,  fn, sfx),     \
506         PORT_GP_1(bank, 7,  fn, sfx), PORT_GP_1(bank, 6,  fn, sfx),     \
507         PORT_GP_1(bank, 5,  fn, sfx), PORT_GP_1(bank, 4,  fn, sfx),     \
508         PORT_GP_1(bank, 3,  fn, sfx), PORT_GP_1(bank, 2,  fn, sfx),     \
509         PORT_GP_1(bank, 1,  fn, sfx), PORT_GP_1(bank, 0,  fn, sfx)
510
511 /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
512 #define _GP_ALL(bank, pin, name, sfx, cfg)      name##_##sfx
513 #define GP_ALL(str)                     CPU_ALL_PORT(_GP_ALL, str)
514
515 /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
516 #define _GP_GPIO(bank, _pin, _name, sfx, cfg)                           \
517         {                                                               \
518                 .pin = (bank * 32) + _pin,                              \
519                 .name = __stringify(_name),                             \
520                 .enum_id = _name##_DATA,                                \
521                 .configs = cfg,                                         \
522         }
523 #define PINMUX_GPIO_GP_ALL()            CPU_ALL_PORT(_GP_GPIO, unused)
524
525 /* PINMUX_DATA_GP_ALL -  Expand to a list of name_DATA, name_FN marks */
526 #define _GP_DATA(bank, pin, name, sfx, cfg)     PINMUX_DATA(name##_DATA, name##_FN)
527 #define PINMUX_DATA_GP_ALL()            CPU_ALL_PORT(_GP_DATA, unused)
528
529 /*
530  * PORT style (linear pin space)
531  */
532
533 #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
534
535 #define PORT_10(pn, fn, pfx, sfx)                                         \
536         PORT_1(pn,   fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx),     \
537         PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx),     \
538         PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx),     \
539         PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx),     \
540         PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
541
542 #define PORT_90(pn, fn, pfx, sfx)                                         \
543         PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
544         PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
545         PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
546         PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
547         PORT_10(pn+90, fn, pfx##9, sfx)
548
549 /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
550 #define _PORT_ALL(pn, pfx, sfx)         pfx##_##sfx
551 #define PORT_ALL(str)                   CPU_ALL_PORT(_PORT_ALL, PORT, str)
552
553 /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
554 #define PINMUX_GPIO(_pin)                                               \
555         [GPIO_##_pin] = {                                               \
556                 .pin = (u16)-1,                                         \
557                 .name = __stringify(GPIO_##_pin),                       \
558                 .enum_id = _pin##_DATA,                                 \
559         }
560
561 /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
562 #define SH_PFC_PIN_CFG(_pin, cfgs)                                      \
563         {                                                               \
564                 .pin = _pin,                                            \
565                 .name = __stringify(PORT##_pin),                        \
566                 .enum_id = PORT##_pin##_DATA,                           \
567                 .configs = cfgs,                                        \
568         }
569
570 /* SH_PFC_PIN_NAMED - Expand to a sh_pfc_pin entry with the given name */
571 #define SH_PFC_PIN_NAMED(row, col, _name)                               \
572         {                                                               \
573                 .pin = PIN_NUMBER(row, col),                            \
574                 .name = __stringify(PIN_##_name),                       \
575                 .configs = SH_PFC_PIN_CFG_NO_GPIO,                      \
576         }
577
578 /* SH_PFC_PIN_NAMED_CFG - Expand to a sh_pfc_pin entry with the given name */
579 #define SH_PFC_PIN_NAMED_CFG(row, col, _name, cfgs)                     \
580         {                                                               \
581                 .pin = PIN_NUMBER(row, col),                            \
582                 .name = __stringify(PIN_##_name),                       \
583                 .configs = SH_PFC_PIN_CFG_NO_GPIO | cfgs,               \
584         }
585
586 /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
587  *                   PORT_name_OUT, PORT_name_IN marks
588  */
589 #define _PORT_DATA(pn, pfx, sfx)                                        \
590         PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0,                  \
591                     PORT##pfx##_OUT, PORT##pfx##_IN)
592 #define PINMUX_DATA_ALL()               CPU_ALL_PORT(_PORT_DATA, , unused)
593
594 /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
595 #define PINMUX_GPIO_FN(gpio, base, data_or_mark)                        \
596         [gpio - (base)] = {                                             \
597                 .name = __stringify(gpio),                              \
598                 .enum_id = data_or_mark,                                \
599         }
600 #define GPIO_FN(str)                                                    \
601         PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
602
603 /*
604  * PORTnCR helper macro for SH-Mobile/R-Mobile
605  */
606 #define PORTCR(nr, reg)                                                 \
607         {                                                               \
608                 PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, 2, 2, 1, 3) {\
609                         /* PULMD[1:0], handled by .set_bias() */        \
610                         0, 0, 0, 0,                                     \
611                         /* IE and OE */                                 \
612                         0, PORT##nr##_OUT, PORT##nr##_IN, 0,            \
613                         /* SEC, not supported */                        \
614                         0, 0,                                           \
615                         /* PTMD[2:0] */                                 \
616                         PORT##nr##_FN0, PORT##nr##_FN1,                 \
617                         PORT##nr##_FN2, PORT##nr##_FN3,                 \
618                         PORT##nr##_FN4, PORT##nr##_FN5,                 \
619                         PORT##nr##_FN6, PORT##nr##_FN7                  \
620                 }                                                       \
621         }
622
623 /*
624  * GPIO number helper macro for R-Car
625  */
626 #define RCAR_GP_PIN(bank, pin)          (((bank) * 32) + (pin))
627
628 #endif /* __SH_PFC_H */