xref: /openbmc/linux/drivers/pinctrl/renesas/sh_pfc.h (revision b67fc1c66732ff08380ea8a4abb3d061ac097d35)
1077365a9SGeert Uytterhoeven /* SPDX-License-Identifier: GPL-2.0
2077365a9SGeert Uytterhoeven  *
3077365a9SGeert Uytterhoeven  * SuperH Pin Function Controller Support
4077365a9SGeert Uytterhoeven  *
5077365a9SGeert Uytterhoeven  * Copyright (c) 2008 Magnus Damm
6077365a9SGeert Uytterhoeven  */
7077365a9SGeert Uytterhoeven 
8077365a9SGeert Uytterhoeven #ifndef __SH_PFC_H
9077365a9SGeert Uytterhoeven #define __SH_PFC_H
10077365a9SGeert Uytterhoeven 
11077365a9SGeert Uytterhoeven #include <linux/bug.h>
12077365a9SGeert Uytterhoeven #include <linux/pinctrl/pinconf-generic.h>
13077365a9SGeert Uytterhoeven #include <linux/spinlock.h>
14077365a9SGeert Uytterhoeven #include <linux/stringify.h>
15077365a9SGeert Uytterhoeven 
16077365a9SGeert Uytterhoeven enum {
17077365a9SGeert Uytterhoeven 	PINMUX_TYPE_NONE,
18077365a9SGeert Uytterhoeven 	PINMUX_TYPE_FUNCTION,
19077365a9SGeert Uytterhoeven 	PINMUX_TYPE_GPIO,
20077365a9SGeert Uytterhoeven 	PINMUX_TYPE_OUTPUT,
21077365a9SGeert Uytterhoeven 	PINMUX_TYPE_INPUT,
22077365a9SGeert Uytterhoeven };
23077365a9SGeert Uytterhoeven 
24077365a9SGeert Uytterhoeven #define SH_PFC_PIN_NONE			U16_MAX
25077365a9SGeert Uytterhoeven 
26077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_INPUT		(1 << 0)
27077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_OUTPUT		(1 << 1)
28077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_PULL_UP		(1 << 2)
29077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_PULL_DOWN	(1 << 3)
30077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_PULL_UP_DOWN	(SH_PFC_PIN_CFG_PULL_UP | \
31077365a9SGeert Uytterhoeven 					 SH_PFC_PIN_CFG_PULL_DOWN)
32077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_IO_VOLTAGE	(1 << 4)
33077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_DRIVE_STRENGTH	(1 << 5)
34537db25cSUlrich Hecht 
35537db25cSUlrich Hecht #define SH_PFC_PIN_VOLTAGE_18_33	(0 << 6)
36537db25cSUlrich Hecht #define SH_PFC_PIN_VOLTAGE_25_33	(1 << 6)
37537db25cSUlrich Hecht 
38537db25cSUlrich Hecht #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_33	(SH_PFC_PIN_CFG_IO_VOLTAGE | \
39537db25cSUlrich Hecht 					 SH_PFC_PIN_VOLTAGE_18_33)
40537db25cSUlrich Hecht #define SH_PFC_PIN_CFG_IO_VOLTAGE_25_33	(SH_PFC_PIN_CFG_IO_VOLTAGE | \
41537db25cSUlrich Hecht 					 SH_PFC_PIN_VOLTAGE_25_33)
42537db25cSUlrich Hecht 
43077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_NO_GPIO		(1 << 31)
44077365a9SGeert Uytterhoeven 
45077365a9SGeert Uytterhoeven struct sh_pfc_pin {
46077365a9SGeert Uytterhoeven 	const char *name;
47077365a9SGeert Uytterhoeven 	unsigned int configs;
48eb9d673fSGeert Uytterhoeven 	u16 pin;
49eb9d673fSGeert Uytterhoeven 	u16 enum_id;
50077365a9SGeert Uytterhoeven };
51077365a9SGeert Uytterhoeven 
52a0894be3SGeert Uytterhoeven #define SH_PFC_PIN_GROUP_ALIAS(alias, _name) {				\
53077365a9SGeert Uytterhoeven 	.name = #alias,							\
54a0894be3SGeert Uytterhoeven 	.pins = _name##_pins,						\
55a0894be3SGeert Uytterhoeven 	.mux = _name##_mux,						\
56a0894be3SGeert Uytterhoeven 	.nr_pins = ARRAY_SIZE(_name##_pins) +				\
57a0894be3SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof(_name##_pins) != sizeof(_name##_mux)),	\
58077365a9SGeert Uytterhoeven }
59a0894be3SGeert Uytterhoeven #define SH_PFC_PIN_GROUP(name)	SH_PFC_PIN_GROUP_ALIAS(name, name)
60077365a9SGeert Uytterhoeven 
6149a7a274SGeert Uytterhoeven /*
6249a7a274SGeert Uytterhoeven  * Define a pin group referring to a subset of an array of pins.
6349a7a274SGeert Uytterhoeven  */
6449a7a274SGeert Uytterhoeven #define SH_PFC_PIN_GROUP_SUBSET(_name, data, first, n) {		\
6549a7a274SGeert Uytterhoeven 	.name = #_name,							\
6649a7a274SGeert Uytterhoeven 	.pins = data##_pins + first,					\
6749a7a274SGeert Uytterhoeven 	.mux = data##_mux + first,					\
6849a7a274SGeert Uytterhoeven 	.nr_pins = n +							\
6949a7a274SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_pins)) +	\
7049a7a274SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_mux)),		\
7149a7a274SGeert Uytterhoeven }
7249a7a274SGeert Uytterhoeven 
73496da100SGeert Uytterhoeven /*
74496da100SGeert Uytterhoeven  * Define a pin group for the data pins of a resizable bus.
75496da100SGeert Uytterhoeven  * An optional 'suffix' argument is accepted, to be used when the same group
76496da100SGeert Uytterhoeven  * can appear on a different set of pins.
77496da100SGeert Uytterhoeven  */
78496da100SGeert Uytterhoeven #define BUS_DATA_PIN_GROUP(base, n, ...)				\
79496da100SGeert Uytterhoeven 	SH_PFC_PIN_GROUP_SUBSET(base##n##__VA_ARGS__, base##__VA_ARGS__, 0, n)
80496da100SGeert Uytterhoeven 
81077365a9SGeert Uytterhoeven struct sh_pfc_pin_group {
82077365a9SGeert Uytterhoeven 	const char *name;
83077365a9SGeert Uytterhoeven 	const unsigned int *pins;
84077365a9SGeert Uytterhoeven 	const unsigned int *mux;
85077365a9SGeert Uytterhoeven 	unsigned int nr_pins;
86077365a9SGeert Uytterhoeven };
87077365a9SGeert Uytterhoeven 
888d880552SGeert Uytterhoeven #define SH_PFC_FUNCTION(n) {						\
89077365a9SGeert Uytterhoeven 	.name = #n,							\
90077365a9SGeert Uytterhoeven 	.groups = n##_groups,						\
91077365a9SGeert Uytterhoeven 	.nr_groups = ARRAY_SIZE(n##_groups),				\
92077365a9SGeert Uytterhoeven }
93077365a9SGeert Uytterhoeven 
94077365a9SGeert Uytterhoeven struct sh_pfc_function {
95077365a9SGeert Uytterhoeven 	const char *name;
96077365a9SGeert Uytterhoeven 	const char * const *groups;
97077365a9SGeert Uytterhoeven 	unsigned int nr_groups;
98077365a9SGeert Uytterhoeven };
99077365a9SGeert Uytterhoeven 
100077365a9SGeert Uytterhoeven struct pinmux_func {
101077365a9SGeert Uytterhoeven 	u16 enum_id;
102077365a9SGeert Uytterhoeven 	const char *name;
103077365a9SGeert Uytterhoeven };
104077365a9SGeert Uytterhoeven 
105077365a9SGeert Uytterhoeven struct pinmux_cfg_reg {
106077365a9SGeert Uytterhoeven 	u32 reg;
107077365a9SGeert Uytterhoeven 	u8 reg_width, field_width;
108077365a9SGeert Uytterhoeven #ifdef DEBUG
109077365a9SGeert Uytterhoeven 	u16 nr_enum_ids;	/* for variable width regs only */
110077365a9SGeert Uytterhoeven #define SET_NR_ENUM_IDS(n)	.nr_enum_ids = n,
111077365a9SGeert Uytterhoeven #else
112077365a9SGeert Uytterhoeven #define SET_NR_ENUM_IDS(n)
113077365a9SGeert Uytterhoeven #endif
114077365a9SGeert Uytterhoeven 	const u16 *enum_ids;
115077365a9SGeert Uytterhoeven 	const u8 *var_field_width;
116077365a9SGeert Uytterhoeven };
117077365a9SGeert Uytterhoeven 
118077365a9SGeert Uytterhoeven #define GROUP(...)	__VA_ARGS__
119077365a9SGeert Uytterhoeven 
120077365a9SGeert Uytterhoeven /*
121077365a9SGeert Uytterhoeven  * Describe a config register consisting of several fields of the same width
122077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
123077365a9SGeert Uytterhoeven  *   - r: Physical register address
124077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
125077365a9SGeert Uytterhoeven  *   - f_width: Width of the fixed-width register fields (in bits)
126077365a9SGeert Uytterhoeven  *   - ids: For each register field (from left to right, i.e. MSB to LSB),
127077365a9SGeert Uytterhoeven  *          2^f_width enum IDs must be specified, one for each possible
128077365a9SGeert Uytterhoeven  *          combination of the register field bit values, all wrapped using
129077365a9SGeert Uytterhoeven  *          the GROUP() macro.
130077365a9SGeert Uytterhoeven  */
131077365a9SGeert Uytterhoeven #define PINMUX_CFG_REG(name, r, r_width, f_width, ids)			\
132077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width,					\
133077365a9SGeert Uytterhoeven 	.field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) +	\
134077365a9SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
135077365a9SGeert Uytterhoeven 			  (r_width / f_width) * (1 << f_width)),	\
136077365a9SGeert Uytterhoeven 	.enum_ids = (const u16 [(r_width / f_width) * (1 << f_width)])	\
137077365a9SGeert Uytterhoeven 		{ ids }
138077365a9SGeert Uytterhoeven 
139077365a9SGeert Uytterhoeven /*
140077365a9SGeert Uytterhoeven  * Describe a config register consisting of several fields of different widths
141077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
142077365a9SGeert Uytterhoeven  *   - r: Physical register address
143077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
144077365a9SGeert Uytterhoeven  *   - f_widths: List of widths of the register fields (in bits), from left
145077365a9SGeert Uytterhoeven  *               to right (i.e. MSB to LSB), wrapped using the GROUP() macro.
146077365a9SGeert Uytterhoeven  *   - ids: For each register field (from left to right, i.e. MSB to LSB),
147077365a9SGeert Uytterhoeven  *          2^f_widths[i] enum IDs must be specified, one for each possible
148077365a9SGeert Uytterhoeven  *          combination of the register field bit values, all wrapped using
149077365a9SGeert Uytterhoeven  *          the GROUP() macro.
150077365a9SGeert Uytterhoeven  */
151077365a9SGeert Uytterhoeven #define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids)		\
152077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width,					\
153077365a9SGeert Uytterhoeven 	.var_field_width = (const u8 []) { f_widths, 0 },		\
154077365a9SGeert Uytterhoeven 	SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16))	\
155077365a9SGeert Uytterhoeven 	.enum_ids = (const u16 []) { ids }
156077365a9SGeert Uytterhoeven 
157077365a9SGeert Uytterhoeven struct pinmux_drive_reg_field {
158077365a9SGeert Uytterhoeven 	u16 pin;
159077365a9SGeert Uytterhoeven 	u8 offset;
160077365a9SGeert Uytterhoeven 	u8 size;
161077365a9SGeert Uytterhoeven };
162077365a9SGeert Uytterhoeven 
163077365a9SGeert Uytterhoeven struct pinmux_drive_reg {
164077365a9SGeert Uytterhoeven 	u32 reg;
165077365a9SGeert Uytterhoeven 	const struct pinmux_drive_reg_field fields[8];
166077365a9SGeert Uytterhoeven };
167077365a9SGeert Uytterhoeven 
168077365a9SGeert Uytterhoeven #define PINMUX_DRIVE_REG(name, r) \
169077365a9SGeert Uytterhoeven 	.reg = r, \
170077365a9SGeert Uytterhoeven 	.fields =
171077365a9SGeert Uytterhoeven 
1721d3928a3SGeert Uytterhoeven struct pinmux_bias_reg {	/* At least one of puen/pud must exist */
173077365a9SGeert Uytterhoeven 	u32 puen;		/* Pull-enable or pull-up control register */
1741d3928a3SGeert Uytterhoeven 	u32 pud;		/* Pull-up/down or pull-down control register */
175077365a9SGeert Uytterhoeven 	const u16 pins[32];
176077365a9SGeert Uytterhoeven };
177077365a9SGeert Uytterhoeven 
178077365a9SGeert Uytterhoeven #define PINMUX_BIAS_REG(name1, r1, name2, r2) \
179077365a9SGeert Uytterhoeven 	.puen = r1,	\
180077365a9SGeert Uytterhoeven 	.pud = r2,	\
181077365a9SGeert Uytterhoeven 	.pins =
182077365a9SGeert Uytterhoeven 
183077365a9SGeert Uytterhoeven struct pinmux_ioctrl_reg {
184077365a9SGeert Uytterhoeven 	u32 reg;
185077365a9SGeert Uytterhoeven };
186077365a9SGeert Uytterhoeven 
187077365a9SGeert Uytterhoeven struct pinmux_data_reg {
188077365a9SGeert Uytterhoeven 	u32 reg;
189077365a9SGeert Uytterhoeven 	u8 reg_width;
190077365a9SGeert Uytterhoeven 	const u16 *enum_ids;
191077365a9SGeert Uytterhoeven };
192077365a9SGeert Uytterhoeven 
193077365a9SGeert Uytterhoeven /*
194077365a9SGeert Uytterhoeven  * Describe a data register
195077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
196077365a9SGeert Uytterhoeven  *   - r: Physical register address
197077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
198077365a9SGeert Uytterhoeven  *   - ids: For each register bit (from left to right, i.e. MSB to LSB), one
199077365a9SGeert Uytterhoeven  *          enum ID must be specified, all wrapped using the GROUP() macro.
200077365a9SGeert Uytterhoeven  */
201077365a9SGeert Uytterhoeven #define PINMUX_DATA_REG(name, r, r_width, ids)				\
202077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width +				\
203077365a9SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
204077365a9SGeert Uytterhoeven 			  r_width),					\
205077365a9SGeert Uytterhoeven 	.enum_ids = (const u16 [r_width]) { ids }
206077365a9SGeert Uytterhoeven 
207077365a9SGeert Uytterhoeven struct pinmux_irq {
208077365a9SGeert Uytterhoeven 	const short *gpios;
209077365a9SGeert Uytterhoeven };
210077365a9SGeert Uytterhoeven 
211077365a9SGeert Uytterhoeven /*
212077365a9SGeert Uytterhoeven  * Describe the mapping from GPIOs to a single IRQ
213077365a9SGeert Uytterhoeven  *   - ids...: List of GPIOs that are mapped to the same IRQ
214077365a9SGeert Uytterhoeven  */
2158d880552SGeert Uytterhoeven #define PINMUX_IRQ(ids...) {						\
2168d880552SGeert Uytterhoeven 	.gpios = (const short []) { ids, -1 }				\
2178d880552SGeert Uytterhoeven }
218077365a9SGeert Uytterhoeven 
219077365a9SGeert Uytterhoeven struct pinmux_range {
220077365a9SGeert Uytterhoeven 	u16 begin;
221077365a9SGeert Uytterhoeven 	u16 end;
222077365a9SGeert Uytterhoeven 	u16 force;
223077365a9SGeert Uytterhoeven };
224077365a9SGeert Uytterhoeven 
225077365a9SGeert Uytterhoeven struct sh_pfc_window {
226077365a9SGeert Uytterhoeven 	phys_addr_t phys;
227077365a9SGeert Uytterhoeven 	void __iomem *virt;
228077365a9SGeert Uytterhoeven 	unsigned long size;
229077365a9SGeert Uytterhoeven };
230077365a9SGeert Uytterhoeven 
231077365a9SGeert Uytterhoeven struct sh_pfc_pin_range;
232077365a9SGeert Uytterhoeven 
233077365a9SGeert Uytterhoeven struct sh_pfc {
234077365a9SGeert Uytterhoeven 	struct device *dev;
235077365a9SGeert Uytterhoeven 	const struct sh_pfc_soc_info *info;
236077365a9SGeert Uytterhoeven 	spinlock_t lock;
237077365a9SGeert Uytterhoeven 
238077365a9SGeert Uytterhoeven 	unsigned int num_windows;
239077365a9SGeert Uytterhoeven 	struct sh_pfc_window *windows;
240077365a9SGeert Uytterhoeven 	unsigned int num_irqs;
241077365a9SGeert Uytterhoeven 	unsigned int *irqs;
242077365a9SGeert Uytterhoeven 
243077365a9SGeert Uytterhoeven 	struct sh_pfc_pin_range *ranges;
244077365a9SGeert Uytterhoeven 	unsigned int nr_ranges;
245077365a9SGeert Uytterhoeven 
246077365a9SGeert Uytterhoeven 	unsigned int nr_gpio_pins;
247077365a9SGeert Uytterhoeven 
248077365a9SGeert Uytterhoeven 	struct sh_pfc_chip *gpio;
249077365a9SGeert Uytterhoeven 	u32 *saved_regs;
250077365a9SGeert Uytterhoeven };
251077365a9SGeert Uytterhoeven 
252077365a9SGeert Uytterhoeven struct sh_pfc_soc_operations {
253077365a9SGeert Uytterhoeven 	int (*init)(struct sh_pfc *pfc);
254077365a9SGeert Uytterhoeven 	unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
255077365a9SGeert Uytterhoeven 	void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
256077365a9SGeert Uytterhoeven 			 unsigned int bias);
257*b67fc1c6SGeert Uytterhoeven 	int (*pin_to_pocctrl)(unsigned int pin, u32 *pocctrl);
258ec0794a1SGeert Uytterhoeven 	void __iomem * (*pin_to_portcr)(struct sh_pfc *pfc, unsigned int pin);
259077365a9SGeert Uytterhoeven };
260077365a9SGeert Uytterhoeven 
261077365a9SGeert Uytterhoeven struct sh_pfc_soc_info {
262077365a9SGeert Uytterhoeven 	const char *name;
263077365a9SGeert Uytterhoeven 	const struct sh_pfc_soc_operations *ops;
264077365a9SGeert Uytterhoeven 
2657b1425f0SGeert Uytterhoeven #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
266077365a9SGeert Uytterhoeven 	struct pinmux_range input;
267077365a9SGeert Uytterhoeven 	struct pinmux_range output;
2687b1425f0SGeert Uytterhoeven 	const struct pinmux_irq *gpio_irq;
2697b1425f0SGeert Uytterhoeven 	unsigned int gpio_irq_size;
2707b1425f0SGeert Uytterhoeven #endif
2717b1425f0SGeert Uytterhoeven 
272077365a9SGeert Uytterhoeven 	struct pinmux_range function;
273077365a9SGeert Uytterhoeven 
274077365a9SGeert Uytterhoeven 	const struct sh_pfc_pin *pins;
275077365a9SGeert Uytterhoeven 	unsigned int nr_pins;
276077365a9SGeert Uytterhoeven 	const struct sh_pfc_pin_group *groups;
277077365a9SGeert Uytterhoeven 	unsigned int nr_groups;
278077365a9SGeert Uytterhoeven 	const struct sh_pfc_function *functions;
279077365a9SGeert Uytterhoeven 	unsigned int nr_functions;
280077365a9SGeert Uytterhoeven 
281077365a9SGeert Uytterhoeven #ifdef CONFIG_PINCTRL_SH_FUNC_GPIO
282077365a9SGeert Uytterhoeven 	const struct pinmux_func *func_gpios;
283077365a9SGeert Uytterhoeven 	unsigned int nr_func_gpios;
284077365a9SGeert Uytterhoeven #endif
285077365a9SGeert Uytterhoeven 
286077365a9SGeert Uytterhoeven 	const struct pinmux_cfg_reg *cfg_regs;
287077365a9SGeert Uytterhoeven 	const struct pinmux_drive_reg *drive_regs;
288077365a9SGeert Uytterhoeven 	const struct pinmux_bias_reg *bias_regs;
289077365a9SGeert Uytterhoeven 	const struct pinmux_ioctrl_reg *ioctrl_regs;
290077365a9SGeert Uytterhoeven 	const struct pinmux_data_reg *data_regs;
291077365a9SGeert Uytterhoeven 
292077365a9SGeert Uytterhoeven 	const u16 *pinmux_data;
293077365a9SGeert Uytterhoeven 	unsigned int pinmux_data_size;
294077365a9SGeert Uytterhoeven 
295e127ef2eSUlrich Hecht 	u32 unlock_reg;		/* can be literal address or mask */
296077365a9SGeert Uytterhoeven };
297077365a9SGeert Uytterhoeven 
298077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info emev2_pinmux_info;
299077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a73a4_pinmux_info;
300077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7740_pinmux_info;
301077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7742_pinmux_info;
302077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7743_pinmux_info;
303077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7744_pinmux_info;
304077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7745_pinmux_info;
305077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77470_pinmux_info;
306077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774a1_pinmux_info;
307077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774b1_pinmux_info;
308077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774c0_pinmux_info;
309077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774e1_pinmux_info;
310077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7778_pinmux_info;
311077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7779_pinmux_info;
312077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
313077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
314077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
315077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
316077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7794_pinmux_info;
31791d1be9fSGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77950_pinmux_info;
31891d1be9fSGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77951_pinmux_info;
319077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77960_pinmux_info;
320077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77961_pinmux_info;
321077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77965_pinmux_info;
322077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
323077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77980_pinmux_info;
324077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77990_pinmux_info;
325077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
326741a7370SUlrich Hecht extern const struct sh_pfc_soc_info r8a779a0_pinmux_info;
327077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7203_pinmux_info;
328077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7264_pinmux_info;
329077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7269_pinmux_info;
330077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh73a0_pinmux_info;
331077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7720_pinmux_info;
332077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7722_pinmux_info;
333077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7723_pinmux_info;
334077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7724_pinmux_info;
335077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7734_pinmux_info;
336077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7757_pinmux_info;
337077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7785_pinmux_info;
338077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7786_pinmux_info;
339077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info shx3_pinmux_info;
340077365a9SGeert Uytterhoeven 
341077365a9SGeert Uytterhoeven /* -----------------------------------------------------------------------------
342077365a9SGeert Uytterhoeven  * Helper macros to create pin and port lists
343077365a9SGeert Uytterhoeven  */
344077365a9SGeert Uytterhoeven 
345077365a9SGeert Uytterhoeven /*
346077365a9SGeert Uytterhoeven  * sh_pfc_soc_info pinmux_data array macros
347077365a9SGeert Uytterhoeven  */
348077365a9SGeert Uytterhoeven 
349077365a9SGeert Uytterhoeven /*
350077365a9SGeert Uytterhoeven  * Describe generic pinmux data
351077365a9SGeert Uytterhoeven  *   - data_or_mark: *_DATA or *_MARK enum ID
352077365a9SGeert Uytterhoeven  *   - ids...: List of enum IDs to associate with data_or_mark
353077365a9SGeert Uytterhoeven  */
354077365a9SGeert Uytterhoeven #define PINMUX_DATA(data_or_mark, ids...)	data_or_mark, ids, 0
355077365a9SGeert Uytterhoeven 
356077365a9SGeert Uytterhoeven /*
357077365a9SGeert Uytterhoeven  * Describe a pinmux configuration without GPIO function that needs
358077365a9SGeert Uytterhoeven  * configuration in a Peripheral Function Select Register (IPSR)
359077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field (unused, for documentation purposes only)
360077365a9SGeert Uytterhoeven  *   - fn: Function name, referring to a field in the IPSR
361077365a9SGeert Uytterhoeven  */
362077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOGP(ipsr, fn)					\
363077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn)
364077365a9SGeert Uytterhoeven 
365077365a9SGeert Uytterhoeven /*
366077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function that needs configuration
367077365a9SGeert Uytterhoeven  * in both a Peripheral Function Select Register (IPSR) and in a
368077365a9SGeert Uytterhoeven  * GPIO/Peripheral Function Select Register (GPSR)
369077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
370077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
371077365a9SGeert Uytterhoeven  */
372077365a9SGeert Uytterhoeven #define PINMUX_IPSR_GPSR(ipsr, fn)					\
373077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
374077365a9SGeert Uytterhoeven 
375077365a9SGeert Uytterhoeven /*
376077365a9SGeert Uytterhoeven  * Describe a pinmux configuration without GPIO function that needs
377077365a9SGeert Uytterhoeven  * configuration in a Peripheral Function Select Register (IPSR), and where the
378077365a9SGeert Uytterhoeven  * pinmux function has a representation in a Module Select Register (MOD_SEL).
379077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field (unused, for documentation purposes only)
380077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
381077365a9SGeert Uytterhoeven  *   - msel: Module selector
382077365a9SGeert Uytterhoeven  */
383077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOGM(ipsr, fn, msel)				\
384077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
385077365a9SGeert Uytterhoeven 
386077365a9SGeert Uytterhoeven /*
387077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function where the pinmux function
388077365a9SGeert Uytterhoeven  * has no representation in a Peripheral Function Select Register (IPSR), but
389077365a9SGeert Uytterhoeven  * instead solely depends on a group selection.
390077365a9SGeert Uytterhoeven  *   - gpsr: GPSR field
391077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the GPSR field
392077365a9SGeert Uytterhoeven  *   - gsel: Group selector
393077365a9SGeert Uytterhoeven  */
394077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOFN(gpsr, fn, gsel)				\
395077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
396077365a9SGeert Uytterhoeven 
397077365a9SGeert Uytterhoeven /*
398077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function that needs configuration
399077365a9SGeert Uytterhoeven  * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral
400077365a9SGeert Uytterhoeven  * Function Select Register (GPSR), and where the pinmux function has a
401077365a9SGeert Uytterhoeven  * representation in a Module Select Register (MOD_SEL).
402077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
403077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
404077365a9SGeert Uytterhoeven  *   - msel: Module selector
405077365a9SGeert Uytterhoeven  */
406077365a9SGeert Uytterhoeven #define PINMUX_IPSR_MSEL(ipsr, fn, msel)				\
407077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
408077365a9SGeert Uytterhoeven 
409077365a9SGeert Uytterhoeven /*
410077365a9SGeert Uytterhoeven  * Describe a pinmux configuration similar to PINMUX_IPSR_MSEL, but with
411077365a9SGeert Uytterhoeven  * an additional select register that controls physical multiplexing
412077365a9SGeert Uytterhoeven  * with another pin.
413077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
414077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
415077365a9SGeert Uytterhoeven  *   - psel: Physical multiplexing selector
416077365a9SGeert Uytterhoeven  *   - msel: Module selector
417077365a9SGeert Uytterhoeven  */
418077365a9SGeert Uytterhoeven #define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \
419077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr)
420077365a9SGeert Uytterhoeven 
421077365a9SGeert Uytterhoeven /*
422077365a9SGeert Uytterhoeven  * Describe a pinmux configuration in which a pin is physically multiplexed
423077365a9SGeert Uytterhoeven  * with other pins.
424077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
425077365a9SGeert Uytterhoeven  *   - fn: Function name
426077365a9SGeert Uytterhoeven  *   - psel: Physical multiplexing selector
427077365a9SGeert Uytterhoeven  */
428077365a9SGeert Uytterhoeven #define PINMUX_IPSR_PHYS(ipsr, fn, psel) \
429077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr)
430077365a9SGeert Uytterhoeven 
431077365a9SGeert Uytterhoeven /*
432077365a9SGeert Uytterhoeven  * Describe a pinmux configuration for a single-function pin with GPIO
433077365a9SGeert Uytterhoeven  * capability.
434077365a9SGeert Uytterhoeven  *   - fn: Function name
435077365a9SGeert Uytterhoeven  */
436077365a9SGeert Uytterhoeven #define PINMUX_SINGLE(fn)						\
437077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn)
438077365a9SGeert Uytterhoeven 
439077365a9SGeert Uytterhoeven /*
440077365a9SGeert Uytterhoeven  * GP port style (32 ports banks)
441077365a9SGeert Uytterhoeven  */
442077365a9SGeert Uytterhoeven 
443077365a9SGeert Uytterhoeven #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg)				\
444077365a9SGeert Uytterhoeven 	fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
445077365a9SGeert Uytterhoeven #define PORT_GP_1(bank, pin, fn, sfx)	PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
446077365a9SGeert Uytterhoeven 
4479f2af9e5SUlrich Hecht #define PORT_GP_CFG_2(bank, fn, sfx, cfg)				\
448077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 0,  fn, sfx, cfg),				\
4499f2af9e5SUlrich Hecht 	PORT_GP_CFG_1(bank, 1,  fn, sfx, cfg)
4509f2af9e5SUlrich Hecht #define PORT_GP_2(bank, fn, sfx)	PORT_GP_CFG_2(bank, fn, sfx, 0)
4519f2af9e5SUlrich Hecht 
4529f2af9e5SUlrich Hecht #define PORT_GP_CFG_4(bank, fn, sfx, cfg)				\
4539f2af9e5SUlrich Hecht 	PORT_GP_CFG_2(bank, fn, sfx, cfg),				\
454077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 2,  fn, sfx, cfg),				\
455077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 3,  fn, sfx, cfg)
456077365a9SGeert Uytterhoeven #define PORT_GP_4(bank, fn, sfx)	PORT_GP_CFG_4(bank, fn, sfx, 0)
457077365a9SGeert Uytterhoeven 
458077365a9SGeert Uytterhoeven #define PORT_GP_CFG_6(bank, fn, sfx, cfg)				\
459077365a9SGeert Uytterhoeven 	PORT_GP_CFG_4(bank, fn, sfx, cfg),				\
460077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 4,  fn, sfx, cfg),				\
461077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 5,  fn, sfx, cfg)
462077365a9SGeert Uytterhoeven #define PORT_GP_6(bank, fn, sfx)	PORT_GP_CFG_6(bank, fn, sfx, 0)
463077365a9SGeert Uytterhoeven 
46493d6c7d6SGeert Uytterhoeven #define PORT_GP_CFG_7(bank, fn, sfx, cfg)				\
465077365a9SGeert Uytterhoeven 	PORT_GP_CFG_6(bank, fn, sfx, cfg),				\
46693d6c7d6SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 6,  fn, sfx, cfg)
46793d6c7d6SGeert Uytterhoeven #define PORT_GP_7(bank, fn, sfx)	PORT_GP_CFG_7(bank, fn, sfx, 0)
46893d6c7d6SGeert Uytterhoeven 
46993d6c7d6SGeert Uytterhoeven #define PORT_GP_CFG_8(bank, fn, sfx, cfg)				\
47093d6c7d6SGeert Uytterhoeven 	PORT_GP_CFG_7(bank, fn, sfx, cfg),				\
471077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 7,  fn, sfx, cfg)
472077365a9SGeert Uytterhoeven #define PORT_GP_8(bank, fn, sfx)	PORT_GP_CFG_8(bank, fn, sfx, 0)
473077365a9SGeert Uytterhoeven 
474077365a9SGeert Uytterhoeven #define PORT_GP_CFG_9(bank, fn, sfx, cfg)				\
475077365a9SGeert Uytterhoeven 	PORT_GP_CFG_8(bank, fn, sfx, cfg),				\
476077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 8,  fn, sfx, cfg)
477077365a9SGeert Uytterhoeven #define PORT_GP_9(bank, fn, sfx)	PORT_GP_CFG_9(bank, fn, sfx, 0)
478077365a9SGeert Uytterhoeven 
479077365a9SGeert Uytterhoeven #define PORT_GP_CFG_10(bank, fn, sfx, cfg)				\
480077365a9SGeert Uytterhoeven 	PORT_GP_CFG_9(bank, fn, sfx, cfg),				\
481077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 9,  fn, sfx, cfg)
482077365a9SGeert Uytterhoeven #define PORT_GP_10(bank, fn, sfx)	PORT_GP_CFG_10(bank, fn, sfx, 0)
483077365a9SGeert Uytterhoeven 
484077365a9SGeert Uytterhoeven #define PORT_GP_CFG_11(bank, fn, sfx, cfg)				\
485077365a9SGeert Uytterhoeven 	PORT_GP_CFG_10(bank, fn, sfx, cfg),				\
486077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 10, fn, sfx, cfg)
487077365a9SGeert Uytterhoeven #define PORT_GP_11(bank, fn, sfx)	PORT_GP_CFG_11(bank, fn, sfx, 0)
488077365a9SGeert Uytterhoeven 
489077365a9SGeert Uytterhoeven #define PORT_GP_CFG_12(bank, fn, sfx, cfg)				\
490077365a9SGeert Uytterhoeven 	PORT_GP_CFG_11(bank, fn, sfx, cfg),				\
491077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
492077365a9SGeert Uytterhoeven #define PORT_GP_12(bank, fn, sfx)	PORT_GP_CFG_12(bank, fn, sfx, 0)
493077365a9SGeert Uytterhoeven 
494077365a9SGeert Uytterhoeven #define PORT_GP_CFG_14(bank, fn, sfx, cfg)				\
495077365a9SGeert Uytterhoeven 	PORT_GP_CFG_12(bank, fn, sfx, cfg),				\
496077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 12, fn, sfx, cfg),				\
497077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
498077365a9SGeert Uytterhoeven #define PORT_GP_14(bank, fn, sfx)	PORT_GP_CFG_14(bank, fn, sfx, 0)
499077365a9SGeert Uytterhoeven 
500077365a9SGeert Uytterhoeven #define PORT_GP_CFG_15(bank, fn, sfx, cfg)				\
501077365a9SGeert Uytterhoeven 	PORT_GP_CFG_14(bank, fn, sfx, cfg),				\
502077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
503077365a9SGeert Uytterhoeven #define PORT_GP_15(bank, fn, sfx)	PORT_GP_CFG_15(bank, fn, sfx, 0)
504077365a9SGeert Uytterhoeven 
505077365a9SGeert Uytterhoeven #define PORT_GP_CFG_16(bank, fn, sfx, cfg)				\
506077365a9SGeert Uytterhoeven 	PORT_GP_CFG_15(bank, fn, sfx, cfg),				\
507077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
508077365a9SGeert Uytterhoeven #define PORT_GP_16(bank, fn, sfx)	PORT_GP_CFG_16(bank, fn, sfx, 0)
509077365a9SGeert Uytterhoeven 
510077365a9SGeert Uytterhoeven #define PORT_GP_CFG_17(bank, fn, sfx, cfg)				\
511077365a9SGeert Uytterhoeven 	PORT_GP_CFG_16(bank, fn, sfx, cfg),				\
512077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
513077365a9SGeert Uytterhoeven #define PORT_GP_17(bank, fn, sfx)	PORT_GP_CFG_17(bank, fn, sfx, 0)
514077365a9SGeert Uytterhoeven 
515077365a9SGeert Uytterhoeven #define PORT_GP_CFG_18(bank, fn, sfx, cfg)				\
516077365a9SGeert Uytterhoeven 	PORT_GP_CFG_17(bank, fn, sfx, cfg),				\
517077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
518077365a9SGeert Uytterhoeven #define PORT_GP_18(bank, fn, sfx)	PORT_GP_CFG_18(bank, fn, sfx, 0)
519077365a9SGeert Uytterhoeven 
520077365a9SGeert Uytterhoeven #define PORT_GP_CFG_20(bank, fn, sfx, cfg)				\
521077365a9SGeert Uytterhoeven 	PORT_GP_CFG_18(bank, fn, sfx, cfg),				\
522077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 18, fn, sfx, cfg),				\
523077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
524077365a9SGeert Uytterhoeven #define PORT_GP_20(bank, fn, sfx)	PORT_GP_CFG_20(bank, fn, sfx, 0)
525077365a9SGeert Uytterhoeven 
526077365a9SGeert Uytterhoeven #define PORT_GP_CFG_21(bank, fn, sfx, cfg)				\
527077365a9SGeert Uytterhoeven 	PORT_GP_CFG_20(bank, fn, sfx, cfg),				\
528077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
529077365a9SGeert Uytterhoeven #define PORT_GP_21(bank, fn, sfx)	PORT_GP_CFG_21(bank, fn, sfx, 0)
530077365a9SGeert Uytterhoeven 
531077365a9SGeert Uytterhoeven #define PORT_GP_CFG_22(bank, fn, sfx, cfg)				\
532077365a9SGeert Uytterhoeven 	PORT_GP_CFG_21(bank, fn, sfx, cfg),				\
533077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
534077365a9SGeert Uytterhoeven #define PORT_GP_22(bank, fn, sfx)	PORT_GP_CFG_22(bank, fn, sfx, 0)
535077365a9SGeert Uytterhoeven 
536077365a9SGeert Uytterhoeven #define PORT_GP_CFG_23(bank, fn, sfx, cfg)				\
537077365a9SGeert Uytterhoeven 	PORT_GP_CFG_22(bank, fn, sfx, cfg),				\
538077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
539077365a9SGeert Uytterhoeven #define PORT_GP_23(bank, fn, sfx)	PORT_GP_CFG_23(bank, fn, sfx, 0)
540077365a9SGeert Uytterhoeven 
541077365a9SGeert Uytterhoeven #define PORT_GP_CFG_24(bank, fn, sfx, cfg)				\
542077365a9SGeert Uytterhoeven 	PORT_GP_CFG_23(bank, fn, sfx, cfg),				\
543077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
544077365a9SGeert Uytterhoeven #define PORT_GP_24(bank, fn, sfx)	PORT_GP_CFG_24(bank, fn, sfx, 0)
545077365a9SGeert Uytterhoeven 
546077365a9SGeert Uytterhoeven #define PORT_GP_CFG_25(bank, fn, sfx, cfg)				\
547077365a9SGeert Uytterhoeven 	PORT_GP_CFG_24(bank, fn, sfx, cfg),				\
548077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 24, fn, sfx, cfg)
549077365a9SGeert Uytterhoeven #define PORT_GP_25(bank, fn, sfx)	PORT_GP_CFG_25(bank, fn, sfx, 0)
550077365a9SGeert Uytterhoeven 
551077365a9SGeert Uytterhoeven #define PORT_GP_CFG_26(bank, fn, sfx, cfg)				\
552077365a9SGeert Uytterhoeven 	PORT_GP_CFG_25(bank, fn, sfx, cfg),				\
553077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
554077365a9SGeert Uytterhoeven #define PORT_GP_26(bank, fn, sfx)	PORT_GP_CFG_26(bank, fn, sfx, 0)
555077365a9SGeert Uytterhoeven 
556077365a9SGeert Uytterhoeven #define PORT_GP_CFG_27(bank, fn, sfx, cfg)				\
557077365a9SGeert Uytterhoeven 	PORT_GP_CFG_26(bank, fn, sfx, cfg),				\
558077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 26, fn, sfx, cfg)
559077365a9SGeert Uytterhoeven #define PORT_GP_27(bank, fn, sfx)	PORT_GP_CFG_27(bank, fn, sfx, 0)
560077365a9SGeert Uytterhoeven 
561077365a9SGeert Uytterhoeven #define PORT_GP_CFG_28(bank, fn, sfx, cfg)				\
562077365a9SGeert Uytterhoeven 	PORT_GP_CFG_27(bank, fn, sfx, cfg),				\
563077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
564077365a9SGeert Uytterhoeven #define PORT_GP_28(bank, fn, sfx)	PORT_GP_CFG_28(bank, fn, sfx, 0)
565077365a9SGeert Uytterhoeven 
566077365a9SGeert Uytterhoeven #define PORT_GP_CFG_29(bank, fn, sfx, cfg)				\
567077365a9SGeert Uytterhoeven 	PORT_GP_CFG_28(bank, fn, sfx, cfg),				\
568077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
569077365a9SGeert Uytterhoeven #define PORT_GP_29(bank, fn, sfx)	PORT_GP_CFG_29(bank, fn, sfx, 0)
570077365a9SGeert Uytterhoeven 
571077365a9SGeert Uytterhoeven #define PORT_GP_CFG_30(bank, fn, sfx, cfg)				\
572077365a9SGeert Uytterhoeven 	PORT_GP_CFG_29(bank, fn, sfx, cfg),				\
573077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
574077365a9SGeert Uytterhoeven #define PORT_GP_30(bank, fn, sfx)	PORT_GP_CFG_30(bank, fn, sfx, 0)
575077365a9SGeert Uytterhoeven 
5769f2af9e5SUlrich Hecht #define PORT_GP_CFG_31(bank, fn, sfx, cfg)				\
577077365a9SGeert Uytterhoeven 	PORT_GP_CFG_30(bank, fn, sfx, cfg),				\
5789f2af9e5SUlrich Hecht 	PORT_GP_CFG_1(bank, 30, fn, sfx, cfg)
5799f2af9e5SUlrich Hecht #define PORT_GP_31(bank, fn, sfx)	PORT_GP_CFG_31(bank, fn, sfx, 0)
5809f2af9e5SUlrich Hecht 
5819f2af9e5SUlrich Hecht #define PORT_GP_CFG_32(bank, fn, sfx, cfg)				\
5829f2af9e5SUlrich Hecht 	PORT_GP_CFG_31(bank, fn, sfx, cfg),				\
583077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
584077365a9SGeert Uytterhoeven #define PORT_GP_32(bank, fn, sfx)	PORT_GP_CFG_32(bank, fn, sfx, 0)
585077365a9SGeert Uytterhoeven 
586077365a9SGeert Uytterhoeven #define PORT_GP_32_REV(bank, fn, sfx)					\
587077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx),	\
588077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx),	\
589077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx),	\
590077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx),	\
591077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx),	\
592077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx),	\
593077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx),	\
594077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx),	\
595077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx),	\
596077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx),	\
597077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx),	\
598077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 9,  fn, sfx), PORT_GP_1(bank, 8,  fn, sfx),	\
599077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 7,  fn, sfx), PORT_GP_1(bank, 6,  fn, sfx),	\
600077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 5,  fn, sfx), PORT_GP_1(bank, 4,  fn, sfx),	\
601077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 3,  fn, sfx), PORT_GP_1(bank, 2,  fn, sfx),	\
602077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 1,  fn, sfx), PORT_GP_1(bank, 0,  fn, sfx)
603077365a9SGeert Uytterhoeven 
604077365a9SGeert Uytterhoeven /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
605077365a9SGeert Uytterhoeven #define _GP_ALL(bank, pin, name, sfx, cfg)	name##_##sfx
606077365a9SGeert Uytterhoeven #define GP_ALL(str)			CPU_ALL_GP(_GP_ALL, str)
607077365a9SGeert Uytterhoeven 
608077365a9SGeert Uytterhoeven /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
6098d880552SGeert Uytterhoeven #define _GP_GPIO(bank, _pin, _name, sfx, cfg) {				\
610077365a9SGeert Uytterhoeven 	.pin = (bank * 32) + _pin,					\
611077365a9SGeert Uytterhoeven 	.name = __stringify(_name),					\
612077365a9SGeert Uytterhoeven 	.enum_id = _name##_DATA,					\
613077365a9SGeert Uytterhoeven 	.configs = cfg,							\
614077365a9SGeert Uytterhoeven }
615077365a9SGeert Uytterhoeven #define PINMUX_GPIO_GP_ALL()		CPU_ALL_GP(_GP_GPIO, unused)
616077365a9SGeert Uytterhoeven 
617077365a9SGeert Uytterhoeven /* PINMUX_DATA_GP_ALL -  Expand to a list of name_DATA, name_FN marks */
618077365a9SGeert Uytterhoeven #define _GP_DATA(bank, pin, name, sfx, cfg)	PINMUX_DATA(name##_DATA, name##_FN)
619077365a9SGeert Uytterhoeven #define PINMUX_DATA_GP_ALL()		CPU_ALL_GP(_GP_DATA, unused)
620077365a9SGeert Uytterhoeven 
621077365a9SGeert Uytterhoeven /*
622077365a9SGeert Uytterhoeven  * GP_ASSIGN_LAST() - Expand to an enum definition for the last GP pin
623077365a9SGeert Uytterhoeven  *
624077365a9SGeert Uytterhoeven  * The largest GP pin index is obtained by taking the size of a union,
625077365a9SGeert Uytterhoeven  * containing one array per GP pin, sized by the corresponding pin index.
626077365a9SGeert Uytterhoeven  * As the fields in the CPU_ALL_GP() macro definition are separated by commas,
627077365a9SGeert Uytterhoeven  * while the members of a union must be terminated by semicolons, the commas
628077365a9SGeert Uytterhoeven  * are absorbed by wrapping them inside dummy attributes.
629077365a9SGeert Uytterhoeven  */
630077365a9SGeert Uytterhoeven #define _GP_ENTRY(bank, pin, name, sfx, cfg)				\
631077365a9SGeert Uytterhoeven 	deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated
632077365a9SGeert Uytterhoeven #define GP_ASSIGN_LAST()						\
633077365a9SGeert Uytterhoeven 	GP_LAST = sizeof(union {					\
634077365a9SGeert Uytterhoeven 		char dummy[0] __attribute__((deprecated,		\
635077365a9SGeert Uytterhoeven 		CPU_ALL_GP(_GP_ENTRY, unused),				\
636077365a9SGeert Uytterhoeven 		deprecated));						\
637077365a9SGeert Uytterhoeven 	})
638077365a9SGeert Uytterhoeven 
639077365a9SGeert Uytterhoeven /*
640077365a9SGeert Uytterhoeven  * PORT style (linear pin space)
641077365a9SGeert Uytterhoeven  */
642077365a9SGeert Uytterhoeven 
643077365a9SGeert Uytterhoeven #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
644077365a9SGeert Uytterhoeven 
645077365a9SGeert Uytterhoeven #define PORT_10(pn, fn, pfx, sfx)					  \
646077365a9SGeert Uytterhoeven 	PORT_1(pn,   fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx),	  \
647077365a9SGeert Uytterhoeven 	PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx),	  \
648077365a9SGeert Uytterhoeven 	PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx),	  \
649077365a9SGeert Uytterhoeven 	PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx),	  \
650077365a9SGeert Uytterhoeven 	PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
651077365a9SGeert Uytterhoeven 
652077365a9SGeert Uytterhoeven #define PORT_90(pn, fn, pfx, sfx)					  \
653077365a9SGeert Uytterhoeven 	PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
654077365a9SGeert Uytterhoeven 	PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
655077365a9SGeert Uytterhoeven 	PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
656077365a9SGeert Uytterhoeven 	PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
657077365a9SGeert Uytterhoeven 	PORT_10(pn+90, fn, pfx##9, sfx)
658077365a9SGeert Uytterhoeven 
659077365a9SGeert Uytterhoeven /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
660077365a9SGeert Uytterhoeven #define _PORT_ALL(pn, pfx, sfx)		pfx##_##sfx
661077365a9SGeert Uytterhoeven #define PORT_ALL(str)			CPU_ALL_PORT(_PORT_ALL, PORT, str)
662077365a9SGeert Uytterhoeven 
663077365a9SGeert Uytterhoeven /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
664077365a9SGeert Uytterhoeven #define PINMUX_GPIO(_pin)						\
665077365a9SGeert Uytterhoeven 	[GPIO_##_pin] = {						\
666077365a9SGeert Uytterhoeven 		.pin = (u16)-1,						\
667077365a9SGeert Uytterhoeven 		.name = __stringify(GPIO_##_pin),			\
668077365a9SGeert Uytterhoeven 		.enum_id = _pin##_DATA,					\
669077365a9SGeert Uytterhoeven 	}
670077365a9SGeert Uytterhoeven 
671077365a9SGeert Uytterhoeven /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
6728d880552SGeert Uytterhoeven #define SH_PFC_PIN_CFG(_pin, cfgs) {					\
673077365a9SGeert Uytterhoeven 	.pin = _pin,							\
674077365a9SGeert Uytterhoeven 	.name = __stringify(PORT##_pin),				\
675077365a9SGeert Uytterhoeven 	.enum_id = PORT##_pin##_DATA,					\
676077365a9SGeert Uytterhoeven 	.configs = cfgs,						\
677077365a9SGeert Uytterhoeven }
678077365a9SGeert Uytterhoeven 
679077365a9SGeert Uytterhoeven /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
680077365a9SGeert Uytterhoeven  *		     PORT_name_OUT, PORT_name_IN marks
681077365a9SGeert Uytterhoeven  */
682077365a9SGeert Uytterhoeven #define _PORT_DATA(pn, pfx, sfx)					\
683077365a9SGeert Uytterhoeven 	PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0,			\
684077365a9SGeert Uytterhoeven 		    PORT##pfx##_OUT, PORT##pfx##_IN)
685077365a9SGeert Uytterhoeven #define PINMUX_DATA_ALL()		CPU_ALL_PORT(_PORT_DATA, , unused)
686077365a9SGeert Uytterhoeven 
687077365a9SGeert Uytterhoeven /*
688077365a9SGeert Uytterhoeven  * PORT_ASSIGN_LAST() - Expand to an enum definition for the last PORT pin
689077365a9SGeert Uytterhoeven  *
690077365a9SGeert Uytterhoeven  * The largest PORT pin index is obtained by taking the size of a union,
691077365a9SGeert Uytterhoeven  * containing one array per PORT pin, sized by the corresponding pin index.
692077365a9SGeert Uytterhoeven  * As the fields in the CPU_ALL_PORT() macro definition are separated by
693077365a9SGeert Uytterhoeven  * commas, while the members of a union must be terminated by semicolons, the
694077365a9SGeert Uytterhoeven  * commas are absorbed by wrapping them inside dummy attributes.
695077365a9SGeert Uytterhoeven  */
696077365a9SGeert Uytterhoeven #define _PORT_ENTRY(pn, pfx, sfx)					\
697077365a9SGeert Uytterhoeven 	deprecated)); char pfx[pn] __attribute__((deprecated
698077365a9SGeert Uytterhoeven #define PORT_ASSIGN_LAST()						\
699077365a9SGeert Uytterhoeven 	PORT_LAST = sizeof(union {					\
700077365a9SGeert Uytterhoeven 		char dummy[0] __attribute__((deprecated,		\
701077365a9SGeert Uytterhoeven 		CPU_ALL_PORT(_PORT_ENTRY, PORT, unused),		\
702077365a9SGeert Uytterhoeven 		deprecated));						\
703077365a9SGeert Uytterhoeven 	})
704077365a9SGeert Uytterhoeven 
705077365a9SGeert Uytterhoeven /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
706077365a9SGeert Uytterhoeven #define PINMUX_GPIO_FN(gpio, base, data_or_mark)			\
707077365a9SGeert Uytterhoeven 	[gpio - (base)] = {						\
708077365a9SGeert Uytterhoeven 		.name = __stringify(gpio),				\
709077365a9SGeert Uytterhoeven 		.enum_id = data_or_mark,				\
710077365a9SGeert Uytterhoeven 	}
711077365a9SGeert Uytterhoeven #define GPIO_FN(str)							\
712077365a9SGeert Uytterhoeven 	PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
713077365a9SGeert Uytterhoeven 
714077365a9SGeert Uytterhoeven /*
715077365a9SGeert Uytterhoeven  * Pins not associated with a GPIO port
716077365a9SGeert Uytterhoeven  */
717077365a9SGeert Uytterhoeven 
718077365a9SGeert Uytterhoeven #define PIN_NOGP_CFG(pin, name, fn, cfg)	fn(pin, name, cfg)
719077365a9SGeert Uytterhoeven #define PIN_NOGP(pin, name, fn)			fn(pin, name, 0)
720077365a9SGeert Uytterhoeven 
721077365a9SGeert Uytterhoeven /* NOGP_ALL - Expand to a list of PIN_id */
722077365a9SGeert Uytterhoeven #define _NOGP_ALL(pin, name, cfg)		PIN_##pin
723077365a9SGeert Uytterhoeven #define NOGP_ALL()				CPU_ALL_NOGP(_NOGP_ALL)
724077365a9SGeert Uytterhoeven 
725077365a9SGeert Uytterhoeven /* PINMUX_NOGP_ALL - Expand to a list of sh_pfc_pin entries */
7268d880552SGeert Uytterhoeven #define _NOGP_PINMUX(_pin, _name, cfg) {				\
727077365a9SGeert Uytterhoeven 	.pin = PIN_##_pin,						\
728077365a9SGeert Uytterhoeven 	.name = "PIN_" _name,						\
729077365a9SGeert Uytterhoeven 	.configs = SH_PFC_PIN_CFG_NO_GPIO | cfg,			\
730077365a9SGeert Uytterhoeven }
731077365a9SGeert Uytterhoeven #define PINMUX_NOGP_ALL()		CPU_ALL_NOGP(_NOGP_PINMUX)
732077365a9SGeert Uytterhoeven 
733077365a9SGeert Uytterhoeven /*
734077365a9SGeert Uytterhoeven  * PORTnCR helper macro for SH-Mobile/R-Mobile
735077365a9SGeert Uytterhoeven  */
7368d880552SGeert Uytterhoeven #define PORTCR(nr, reg) {						\
7378d880552SGeert Uytterhoeven 	PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, GROUP(2, 2, 1, 3),	\
738077365a9SGeert Uytterhoeven 			   GROUP(					\
739077365a9SGeert Uytterhoeven 		/* PULMD[1:0], handled by .set_bias() */		\
740077365a9SGeert Uytterhoeven 		0, 0, 0, 0,						\
741077365a9SGeert Uytterhoeven 		/* IE and OE */						\
742077365a9SGeert Uytterhoeven 		0, PORT##nr##_OUT, PORT##nr##_IN, 0,			\
743077365a9SGeert Uytterhoeven 		/* SEC, not supported */				\
744077365a9SGeert Uytterhoeven 		0, 0,							\
745077365a9SGeert Uytterhoeven 		/* PTMD[2:0] */						\
746077365a9SGeert Uytterhoeven 		PORT##nr##_FN0, PORT##nr##_FN1,				\
747077365a9SGeert Uytterhoeven 		PORT##nr##_FN2, PORT##nr##_FN3,				\
748077365a9SGeert Uytterhoeven 		PORT##nr##_FN4, PORT##nr##_FN5,				\
749077365a9SGeert Uytterhoeven 		PORT##nr##_FN6, PORT##nr##_FN7				\
750077365a9SGeert Uytterhoeven 	))								\
751077365a9SGeert Uytterhoeven }
752077365a9SGeert Uytterhoeven 
753077365a9SGeert Uytterhoeven /*
754077365a9SGeert Uytterhoeven  * GPIO number helper macro for R-Car
755077365a9SGeert Uytterhoeven  */
756077365a9SGeert Uytterhoeven #define RCAR_GP_PIN(bank, pin)		(((bank) * 32) + (pin))
757077365a9SGeert Uytterhoeven 
7584b6e6c19SGeert Uytterhoeven /*
7594b6e6c19SGeert Uytterhoeven  * Bias helpers
7604b6e6c19SGeert Uytterhoeven  */
761e9d66bdbSGeert Uytterhoeven const struct pinmux_bias_reg *
762e9d66bdbSGeert Uytterhoeven rcar_pin_to_bias_reg(const struct sh_pfc *pfc, unsigned int pin,
763e9d66bdbSGeert Uytterhoeven 		     unsigned int *bit);
7644b6e6c19SGeert Uytterhoeven unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
7654b6e6c19SGeert Uytterhoeven void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
7664b6e6c19SGeert Uytterhoeven 			  unsigned int bias);
7674b6e6c19SGeert Uytterhoeven 
768ec0794a1SGeert Uytterhoeven unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
769ec0794a1SGeert Uytterhoeven void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
770ec0794a1SGeert Uytterhoeven 			     unsigned int bias);
771ec0794a1SGeert Uytterhoeven 
772077365a9SGeert Uytterhoeven #endif /* __SH_PFC_H */
773