xref: /openbmc/linux/drivers/pinctrl/renesas/sh_pfc.h (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
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)
32537db25cSUlrich Hecht 
33*b88e733aSGeert Uytterhoeven #define SH_PFC_PIN_CFG_IO_VOLTAGE_MASK	GENMASK(5, 4)
34*b88e733aSGeert Uytterhoeven #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_25	(1 << 4)
35*b88e733aSGeert Uytterhoeven #define SH_PFC_PIN_CFG_IO_VOLTAGE_18_33	(2 << 4)
36*b88e733aSGeert Uytterhoeven #define SH_PFC_PIN_CFG_IO_VOLTAGE_25_33	(3 << 4)
37537db25cSUlrich Hecht 
38*b88e733aSGeert Uytterhoeven #define SH_PFC_PIN_CFG_DRIVE_STRENGTH	(1 << 6)
39537db25cSUlrich Hecht 
40077365a9SGeert Uytterhoeven #define SH_PFC_PIN_CFG_NO_GPIO		(1 << 31)
41077365a9SGeert Uytterhoeven 
42077365a9SGeert Uytterhoeven struct sh_pfc_pin {
43077365a9SGeert Uytterhoeven 	const char *name;
44077365a9SGeert Uytterhoeven 	unsigned int configs;
45eb9d673fSGeert Uytterhoeven 	u16 pin;
46eb9d673fSGeert Uytterhoeven 	u16 enum_id;
47077365a9SGeert Uytterhoeven };
48077365a9SGeert Uytterhoeven 
49a0894be3SGeert Uytterhoeven #define SH_PFC_PIN_GROUP_ALIAS(alias, _name) {				\
50077365a9SGeert Uytterhoeven 	.name = #alias,							\
51a0894be3SGeert Uytterhoeven 	.pins = _name##_pins,						\
52a0894be3SGeert Uytterhoeven 	.mux = _name##_mux,						\
53a0894be3SGeert Uytterhoeven 	.nr_pins = ARRAY_SIZE(_name##_pins) +				\
54a0894be3SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof(_name##_pins) != sizeof(_name##_mux)),	\
55077365a9SGeert Uytterhoeven }
56a0894be3SGeert Uytterhoeven #define SH_PFC_PIN_GROUP(name)	SH_PFC_PIN_GROUP_ALIAS(name, name)
57077365a9SGeert Uytterhoeven 
5849a7a274SGeert Uytterhoeven /*
5949a7a274SGeert Uytterhoeven  * Define a pin group referring to a subset of an array of pins.
6049a7a274SGeert Uytterhoeven  */
6149a7a274SGeert Uytterhoeven #define SH_PFC_PIN_GROUP_SUBSET(_name, data, first, n) {		\
6249a7a274SGeert Uytterhoeven 	.name = #_name,							\
6349a7a274SGeert Uytterhoeven 	.pins = data##_pins + first,					\
6449a7a274SGeert Uytterhoeven 	.mux = data##_mux + first,					\
6549a7a274SGeert Uytterhoeven 	.nr_pins = n +							\
6649a7a274SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_pins)) +	\
6749a7a274SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(first + n > ARRAY_SIZE(data##_mux)),		\
6849a7a274SGeert Uytterhoeven }
6949a7a274SGeert Uytterhoeven 
70496da100SGeert Uytterhoeven /*
71496da100SGeert Uytterhoeven  * Define a pin group for the data pins of a resizable bus.
72496da100SGeert Uytterhoeven  * An optional 'suffix' argument is accepted, to be used when the same group
73496da100SGeert Uytterhoeven  * can appear on a different set of pins.
74496da100SGeert Uytterhoeven  */
75496da100SGeert Uytterhoeven #define BUS_DATA_PIN_GROUP(base, n, ...)				\
76496da100SGeert Uytterhoeven 	SH_PFC_PIN_GROUP_SUBSET(base##n##__VA_ARGS__, base##__VA_ARGS__, 0, n)
77496da100SGeert Uytterhoeven 
78077365a9SGeert Uytterhoeven struct sh_pfc_pin_group {
79077365a9SGeert Uytterhoeven 	const char *name;
80077365a9SGeert Uytterhoeven 	const unsigned int *pins;
81077365a9SGeert Uytterhoeven 	const unsigned int *mux;
82077365a9SGeert Uytterhoeven 	unsigned int nr_pins;
83077365a9SGeert Uytterhoeven };
84077365a9SGeert Uytterhoeven 
858d880552SGeert Uytterhoeven #define SH_PFC_FUNCTION(n) {						\
86077365a9SGeert Uytterhoeven 	.name = #n,							\
87077365a9SGeert Uytterhoeven 	.groups = n##_groups,						\
88077365a9SGeert Uytterhoeven 	.nr_groups = ARRAY_SIZE(n##_groups),				\
89077365a9SGeert Uytterhoeven }
90077365a9SGeert Uytterhoeven 
91077365a9SGeert Uytterhoeven struct sh_pfc_function {
92077365a9SGeert Uytterhoeven 	const char *name;
93077365a9SGeert Uytterhoeven 	const char * const *groups;
94077365a9SGeert Uytterhoeven 	unsigned int nr_groups;
95077365a9SGeert Uytterhoeven };
96077365a9SGeert Uytterhoeven 
97077365a9SGeert Uytterhoeven struct pinmux_func {
98077365a9SGeert Uytterhoeven 	u16 enum_id;
99077365a9SGeert Uytterhoeven 	const char *name;
100077365a9SGeert Uytterhoeven };
101077365a9SGeert Uytterhoeven 
102077365a9SGeert Uytterhoeven struct pinmux_cfg_reg {
103077365a9SGeert Uytterhoeven 	u32 reg;
104077365a9SGeert Uytterhoeven 	u8 reg_width, field_width;
105077365a9SGeert Uytterhoeven #ifdef DEBUG
106077365a9SGeert Uytterhoeven 	u16 nr_enum_ids;	/* for variable width regs only */
107077365a9SGeert Uytterhoeven #define SET_NR_ENUM_IDS(n)	.nr_enum_ids = n,
108077365a9SGeert Uytterhoeven #else
109077365a9SGeert Uytterhoeven #define SET_NR_ENUM_IDS(n)
110077365a9SGeert Uytterhoeven #endif
111077365a9SGeert Uytterhoeven 	const u16 *enum_ids;
11262109055SGeert Uytterhoeven 	const s8 *var_field_width;
113077365a9SGeert Uytterhoeven };
114077365a9SGeert Uytterhoeven 
115077365a9SGeert Uytterhoeven #define GROUP(...)	__VA_ARGS__
116077365a9SGeert Uytterhoeven 
117077365a9SGeert Uytterhoeven /*
118077365a9SGeert Uytterhoeven  * Describe a config register consisting of several fields of the same width
119077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
120077365a9SGeert Uytterhoeven  *   - r: Physical register address
121077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
122077365a9SGeert Uytterhoeven  *   - f_width: Width of the fixed-width register fields (in bits)
123077365a9SGeert Uytterhoeven  *   - ids: For each register field (from left to right, i.e. MSB to LSB),
124077365a9SGeert Uytterhoeven  *          2^f_width enum IDs must be specified, one for each possible
125077365a9SGeert Uytterhoeven  *          combination of the register field bit values, all wrapped using
126077365a9SGeert Uytterhoeven  *          the GROUP() macro.
127077365a9SGeert Uytterhoeven  */
128077365a9SGeert Uytterhoeven #define PINMUX_CFG_REG(name, r, r_width, f_width, ids)			\
129077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width,					\
130077365a9SGeert Uytterhoeven 	.field_width = f_width + BUILD_BUG_ON_ZERO(r_width % f_width) +	\
131077365a9SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
13229af6344SGeert Uytterhoeven 			  (r_width / f_width) << f_width),		\
13329af6344SGeert Uytterhoeven 	.enum_ids = (const u16 [(r_width / f_width) << f_width]) { ids }
134077365a9SGeert Uytterhoeven 
135077365a9SGeert Uytterhoeven /*
136077365a9SGeert Uytterhoeven  * Describe a config register consisting of several fields of different widths
137077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
138077365a9SGeert Uytterhoeven  *   - r: Physical register address
139077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
140077365a9SGeert Uytterhoeven  *   - f_widths: List of widths of the register fields (in bits), from left
141077365a9SGeert Uytterhoeven  *               to right (i.e. MSB to LSB), wrapped using the GROUP() macro.
14262109055SGeert Uytterhoeven  *               Reserved fields are indicated by negating the field width.
14362109055SGeert Uytterhoeven  *   - ids: For each non-reserved register field (from left to right, i.e. MSB
14462109055SGeert Uytterhoeven  *          to LSB), 2^f_widths[i] enum IDs must be specified, one for each
14562109055SGeert Uytterhoeven  *          possible combination of the register field bit values, all wrapped
14662109055SGeert Uytterhoeven  *          using the GROUP() macro.
147077365a9SGeert Uytterhoeven  */
148077365a9SGeert Uytterhoeven #define PINMUX_CFG_REG_VAR(name, r, r_width, f_widths, ids)		\
149077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width,					\
15062109055SGeert Uytterhoeven 	.var_field_width = (const s8 []) { f_widths, 0 },		\
151077365a9SGeert Uytterhoeven 	SET_NR_ENUM_IDS(sizeof((const u16 []) { ids }) / sizeof(u16))	\
152077365a9SGeert Uytterhoeven 	.enum_ids = (const u16 []) { ids }
153077365a9SGeert Uytterhoeven 
154077365a9SGeert Uytterhoeven struct pinmux_drive_reg_field {
155077365a9SGeert Uytterhoeven 	u16 pin;
156077365a9SGeert Uytterhoeven 	u8 offset;
157077365a9SGeert Uytterhoeven 	u8 size;
158077365a9SGeert Uytterhoeven };
159077365a9SGeert Uytterhoeven 
160077365a9SGeert Uytterhoeven struct pinmux_drive_reg {
161077365a9SGeert Uytterhoeven 	u32 reg;
1622130ac18SWolfram Sang 	const struct pinmux_drive_reg_field fields[10];
163077365a9SGeert Uytterhoeven };
164077365a9SGeert Uytterhoeven 
165077365a9SGeert Uytterhoeven #define PINMUX_DRIVE_REG(name, r) \
166077365a9SGeert Uytterhoeven 	.reg = r, \
167077365a9SGeert Uytterhoeven 	.fields =
168077365a9SGeert Uytterhoeven 
1691d3928a3SGeert Uytterhoeven struct pinmux_bias_reg {	/* At least one of puen/pud must exist */
170077365a9SGeert Uytterhoeven 	u32 puen;		/* Pull-enable or pull-up control register */
1711d3928a3SGeert Uytterhoeven 	u32 pud;		/* Pull-up/down or pull-down control register */
172077365a9SGeert Uytterhoeven 	const u16 pins[32];
173077365a9SGeert Uytterhoeven };
174077365a9SGeert Uytterhoeven 
175077365a9SGeert Uytterhoeven #define PINMUX_BIAS_REG(name1, r1, name2, r2) \
176077365a9SGeert Uytterhoeven 	.puen = r1,	\
177077365a9SGeert Uytterhoeven 	.pud = r2,	\
178077365a9SGeert Uytterhoeven 	.pins =
179077365a9SGeert Uytterhoeven 
180077365a9SGeert Uytterhoeven struct pinmux_ioctrl_reg {
181077365a9SGeert Uytterhoeven 	u32 reg;
182077365a9SGeert Uytterhoeven };
183077365a9SGeert Uytterhoeven 
184077365a9SGeert Uytterhoeven struct pinmux_data_reg {
185077365a9SGeert Uytterhoeven 	u32 reg;
186077365a9SGeert Uytterhoeven 	u8 reg_width;
187077365a9SGeert Uytterhoeven 	const u16 *enum_ids;
188077365a9SGeert Uytterhoeven };
189077365a9SGeert Uytterhoeven 
190077365a9SGeert Uytterhoeven /*
191077365a9SGeert Uytterhoeven  * Describe a data register
192077365a9SGeert Uytterhoeven  *   - name: Register name (unused, for documentation purposes only)
193077365a9SGeert Uytterhoeven  *   - r: Physical register address
194077365a9SGeert Uytterhoeven  *   - r_width: Width of the register (in bits)
195077365a9SGeert Uytterhoeven  *   - ids: For each register bit (from left to right, i.e. MSB to LSB), one
196077365a9SGeert Uytterhoeven  *          enum ID must be specified, all wrapped using the GROUP() macro.
197077365a9SGeert Uytterhoeven  */
198077365a9SGeert Uytterhoeven #define PINMUX_DATA_REG(name, r, r_width, ids)				\
199077365a9SGeert Uytterhoeven 	.reg = r, .reg_width = r_width +				\
200077365a9SGeert Uytterhoeven 	BUILD_BUG_ON_ZERO(sizeof((const u16 []) { ids }) / sizeof(u16) != \
201077365a9SGeert Uytterhoeven 			  r_width),					\
202077365a9SGeert Uytterhoeven 	.enum_ids = (const u16 [r_width]) { ids }
203077365a9SGeert Uytterhoeven 
204077365a9SGeert Uytterhoeven struct pinmux_irq {
205077365a9SGeert Uytterhoeven 	const short *gpios;
206077365a9SGeert Uytterhoeven };
207077365a9SGeert Uytterhoeven 
208077365a9SGeert Uytterhoeven /*
209077365a9SGeert Uytterhoeven  * Describe the mapping from GPIOs to a single IRQ
210077365a9SGeert Uytterhoeven  *   - ids...: List of GPIOs that are mapped to the same IRQ
211077365a9SGeert Uytterhoeven  */
2128d880552SGeert Uytterhoeven #define PINMUX_IRQ(ids...) {						\
2138d880552SGeert Uytterhoeven 	.gpios = (const short []) { ids, -1 }				\
2148d880552SGeert Uytterhoeven }
215077365a9SGeert Uytterhoeven 
216077365a9SGeert Uytterhoeven struct pinmux_range {
217077365a9SGeert Uytterhoeven 	u16 begin;
218077365a9SGeert Uytterhoeven 	u16 end;
219077365a9SGeert Uytterhoeven 	u16 force;
220077365a9SGeert Uytterhoeven };
221077365a9SGeert Uytterhoeven 
222077365a9SGeert Uytterhoeven struct sh_pfc_window {
223077365a9SGeert Uytterhoeven 	phys_addr_t phys;
224077365a9SGeert Uytterhoeven 	void __iomem *virt;
225077365a9SGeert Uytterhoeven 	unsigned long size;
226077365a9SGeert Uytterhoeven };
227077365a9SGeert Uytterhoeven 
228077365a9SGeert Uytterhoeven struct sh_pfc_pin_range;
229077365a9SGeert Uytterhoeven 
230077365a9SGeert Uytterhoeven struct sh_pfc {
231077365a9SGeert Uytterhoeven 	struct device *dev;
232077365a9SGeert Uytterhoeven 	const struct sh_pfc_soc_info *info;
233077365a9SGeert Uytterhoeven 	spinlock_t lock;
234077365a9SGeert Uytterhoeven 
235077365a9SGeert Uytterhoeven 	unsigned int num_windows;
236077365a9SGeert Uytterhoeven 	struct sh_pfc_window *windows;
237077365a9SGeert Uytterhoeven 	unsigned int num_irqs;
238077365a9SGeert Uytterhoeven 	unsigned int *irqs;
239077365a9SGeert Uytterhoeven 
240077365a9SGeert Uytterhoeven 	struct sh_pfc_pin_range *ranges;
241077365a9SGeert Uytterhoeven 	unsigned int nr_ranges;
242077365a9SGeert Uytterhoeven 
243077365a9SGeert Uytterhoeven 	unsigned int nr_gpio_pins;
244077365a9SGeert Uytterhoeven 
245077365a9SGeert Uytterhoeven 	struct sh_pfc_chip *gpio;
246077365a9SGeert Uytterhoeven 	u32 *saved_regs;
247077365a9SGeert Uytterhoeven };
248077365a9SGeert Uytterhoeven 
249077365a9SGeert Uytterhoeven struct sh_pfc_soc_operations {
250077365a9SGeert Uytterhoeven 	int (*init)(struct sh_pfc *pfc);
251077365a9SGeert Uytterhoeven 	unsigned int (*get_bias)(struct sh_pfc *pfc, unsigned int pin);
252077365a9SGeert Uytterhoeven 	void (*set_bias)(struct sh_pfc *pfc, unsigned int pin,
253077365a9SGeert Uytterhoeven 			 unsigned int bias);
254b67fc1c6SGeert Uytterhoeven 	int (*pin_to_pocctrl)(unsigned int pin, u32 *pocctrl);
255ceb8d2acSGeert Uytterhoeven 	int (*pin_to_portcr)(unsigned int pin);
256077365a9SGeert Uytterhoeven };
257077365a9SGeert Uytterhoeven 
258077365a9SGeert Uytterhoeven struct sh_pfc_soc_info {
259077365a9SGeert Uytterhoeven 	const char *name;
260077365a9SGeert Uytterhoeven 	const struct sh_pfc_soc_operations *ops;
261077365a9SGeert Uytterhoeven 
2627b1425f0SGeert Uytterhoeven #ifdef CONFIG_PINCTRL_SH_PFC_GPIO
263077365a9SGeert Uytterhoeven 	struct pinmux_range input;
264077365a9SGeert Uytterhoeven 	struct pinmux_range output;
2657b1425f0SGeert Uytterhoeven 	const struct pinmux_irq *gpio_irq;
2667b1425f0SGeert Uytterhoeven 	unsigned int gpio_irq_size;
2677b1425f0SGeert Uytterhoeven #endif
2687b1425f0SGeert Uytterhoeven 
269077365a9SGeert Uytterhoeven 	struct pinmux_range function;
270077365a9SGeert Uytterhoeven 
271077365a9SGeert Uytterhoeven 	const struct sh_pfc_pin *pins;
272077365a9SGeert Uytterhoeven 	unsigned int nr_pins;
273077365a9SGeert Uytterhoeven 	const struct sh_pfc_pin_group *groups;
274077365a9SGeert Uytterhoeven 	unsigned int nr_groups;
275077365a9SGeert Uytterhoeven 	const struct sh_pfc_function *functions;
276077365a9SGeert Uytterhoeven 	unsigned int nr_functions;
277077365a9SGeert Uytterhoeven 
278077365a9SGeert Uytterhoeven #ifdef CONFIG_PINCTRL_SH_FUNC_GPIO
279077365a9SGeert Uytterhoeven 	const struct pinmux_func *func_gpios;
280077365a9SGeert Uytterhoeven 	unsigned int nr_func_gpios;
281077365a9SGeert Uytterhoeven #endif
282077365a9SGeert Uytterhoeven 
283077365a9SGeert Uytterhoeven 	const struct pinmux_cfg_reg *cfg_regs;
284077365a9SGeert Uytterhoeven 	const struct pinmux_drive_reg *drive_regs;
285077365a9SGeert Uytterhoeven 	const struct pinmux_bias_reg *bias_regs;
286077365a9SGeert Uytterhoeven 	const struct pinmux_ioctrl_reg *ioctrl_regs;
287077365a9SGeert Uytterhoeven 	const struct pinmux_data_reg *data_regs;
288077365a9SGeert Uytterhoeven 
289077365a9SGeert Uytterhoeven 	const u16 *pinmux_data;
290077365a9SGeert Uytterhoeven 	unsigned int pinmux_data_size;
291077365a9SGeert Uytterhoeven 
292e127ef2eSUlrich Hecht 	u32 unlock_reg;		/* can be literal address or mask */
293077365a9SGeert Uytterhoeven };
294077365a9SGeert Uytterhoeven 
295077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info emev2_pinmux_info;
296077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a73a4_pinmux_info;
297077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7740_pinmux_info;
298077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7742_pinmux_info;
299077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7743_pinmux_info;
300077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7744_pinmux_info;
301077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7745_pinmux_info;
302077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77470_pinmux_info;
303077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774a1_pinmux_info;
304077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774b1_pinmux_info;
305077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774c0_pinmux_info;
306077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a774e1_pinmux_info;
307077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7778_pinmux_info;
308077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7779_pinmux_info;
309077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7790_pinmux_info;
310077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7791_pinmux_info;
311077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7792_pinmux_info;
312077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7793_pinmux_info;
313077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a7794_pinmux_info;
31491d1be9fSGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77951_pinmux_info;
315077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77960_pinmux_info;
316077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77961_pinmux_info;
317077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77965_pinmux_info;
318077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77970_pinmux_info;
319077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77980_pinmux_info;
320077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77990_pinmux_info;
321077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a77995_pinmux_info;
322741a7370SUlrich Hecht extern const struct sh_pfc_soc_info r8a779a0_pinmux_info;
323030ac6d7SGeert Uytterhoeven extern const struct sh_pfc_soc_info r8a779f0_pinmux_info;
324ad9bb2feSLUU HOAI extern const struct sh_pfc_soc_info r8a779g0_pinmux_info;
325077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7203_pinmux_info;
326077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7264_pinmux_info;
327077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7269_pinmux_info;
328077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh73a0_pinmux_info;
329077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7720_pinmux_info;
330077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7722_pinmux_info;
331077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7723_pinmux_info;
332077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7724_pinmux_info;
333077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7734_pinmux_info;
334077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7757_pinmux_info;
335077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7785_pinmux_info;
336077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info sh7786_pinmux_info;
337077365a9SGeert Uytterhoeven extern const struct sh_pfc_soc_info shx3_pinmux_info;
338077365a9SGeert Uytterhoeven 
339077365a9SGeert Uytterhoeven /* -----------------------------------------------------------------------------
340077365a9SGeert Uytterhoeven  * Helper macros to create pin and port lists
341077365a9SGeert Uytterhoeven  */
342077365a9SGeert Uytterhoeven 
343077365a9SGeert Uytterhoeven /*
344077365a9SGeert Uytterhoeven  * sh_pfc_soc_info pinmux_data array macros
345077365a9SGeert Uytterhoeven  */
346077365a9SGeert Uytterhoeven 
347077365a9SGeert Uytterhoeven /*
348077365a9SGeert Uytterhoeven  * Describe generic pinmux data
349077365a9SGeert Uytterhoeven  *   - data_or_mark: *_DATA or *_MARK enum ID
350077365a9SGeert Uytterhoeven  *   - ids...: List of enum IDs to associate with data_or_mark
351077365a9SGeert Uytterhoeven  */
352077365a9SGeert Uytterhoeven #define PINMUX_DATA(data_or_mark, ids...)	data_or_mark, ids, 0
353077365a9SGeert Uytterhoeven 
354077365a9SGeert Uytterhoeven /*
355077365a9SGeert Uytterhoeven  * Describe a pinmux configuration without GPIO function that needs
356077365a9SGeert Uytterhoeven  * configuration in a Peripheral Function Select Register (IPSR)
357077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field (unused, for documentation purposes only)
358077365a9SGeert Uytterhoeven  *   - fn: Function name, referring to a field in the IPSR
359077365a9SGeert Uytterhoeven  */
360077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOGP(ipsr, fn)					\
361077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn)
362077365a9SGeert Uytterhoeven 
363077365a9SGeert Uytterhoeven /*
364077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function that needs configuration
365077365a9SGeert Uytterhoeven  * in both a Peripheral Function Select Register (IPSR) and in a
366077365a9SGeert Uytterhoeven  * GPIO/Peripheral Function Select Register (GPSR)
367077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
368077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
369077365a9SGeert Uytterhoeven  */
370077365a9SGeert Uytterhoeven #define PINMUX_IPSR_GPSR(ipsr, fn)					\
371077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn, FN_##ipsr)
372077365a9SGeert Uytterhoeven 
373077365a9SGeert Uytterhoeven /*
374077365a9SGeert Uytterhoeven  * Describe a pinmux configuration without GPIO function that needs
375077365a9SGeert Uytterhoeven  * configuration in a Peripheral Function Select Register (IPSR), and where the
376077365a9SGeert Uytterhoeven  * pinmux function has a representation in a Module Select Register (MOD_SEL).
377077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field (unused, for documentation purposes only)
378077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
379077365a9SGeert Uytterhoeven  *   - msel: Module selector
380077365a9SGeert Uytterhoeven  */
381077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOGM(ipsr, fn, msel)				\
382077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn, FN_##msel)
383077365a9SGeert Uytterhoeven 
384077365a9SGeert Uytterhoeven /*
385077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function where the pinmux function
386077365a9SGeert Uytterhoeven  * has no representation in a Peripheral Function Select Register (IPSR), but
387077365a9SGeert Uytterhoeven  * instead solely depends on a group selection.
388077365a9SGeert Uytterhoeven  *   - gpsr: GPSR field
389077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the GPSR field
390077365a9SGeert Uytterhoeven  *   - gsel: Group selector
391077365a9SGeert Uytterhoeven  */
392077365a9SGeert Uytterhoeven #define PINMUX_IPSR_NOFN(gpsr, fn, gsel)				\
393077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##gpsr, FN_##gsel)
394077365a9SGeert Uytterhoeven 
395077365a9SGeert Uytterhoeven /*
396077365a9SGeert Uytterhoeven  * Describe a pinmux configuration with GPIO function that needs configuration
397077365a9SGeert Uytterhoeven  * in both a Peripheral Function Select Register (IPSR) and a GPIO/Peripheral
398077365a9SGeert Uytterhoeven  * Function Select Register (GPSR), and where the pinmux function has a
399077365a9SGeert Uytterhoeven  * representation in a Module Select Register (MOD_SEL).
400077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
401077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
402077365a9SGeert Uytterhoeven  *   - msel: Module selector
403077365a9SGeert Uytterhoeven  */
404077365a9SGeert Uytterhoeven #define PINMUX_IPSR_MSEL(ipsr, fn, msel)				\
405077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##msel, FN_##fn, FN_##ipsr)
406077365a9SGeert Uytterhoeven 
407077365a9SGeert Uytterhoeven /*
408077365a9SGeert Uytterhoeven  * Describe a pinmux configuration similar to PINMUX_IPSR_MSEL, but with
409077365a9SGeert Uytterhoeven  * an additional select register that controls physical multiplexing
410077365a9SGeert Uytterhoeven  * with another pin.
411077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
412077365a9SGeert Uytterhoeven  *   - fn: Function name, also referring to the IPSR field
413077365a9SGeert Uytterhoeven  *   - psel: Physical multiplexing selector
414077365a9SGeert Uytterhoeven  *   - msel: Module selector
415077365a9SGeert Uytterhoeven  */
416077365a9SGeert Uytterhoeven #define PINMUX_IPSR_PHYS_MSEL(ipsr, fn, psel, msel) \
417077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##psel, FN_##msel, FN_##fn, FN_##ipsr)
418077365a9SGeert Uytterhoeven 
419077365a9SGeert Uytterhoeven /*
420077365a9SGeert Uytterhoeven  * Describe a pinmux configuration in which a pin is physically multiplexed
421077365a9SGeert Uytterhoeven  * with other pins.
422077365a9SGeert Uytterhoeven  *   - ipsr: IPSR field
423077365a9SGeert Uytterhoeven  *   - fn: Function name
424077365a9SGeert Uytterhoeven  *   - psel: Physical multiplexing selector
425077365a9SGeert Uytterhoeven  */
426077365a9SGeert Uytterhoeven #define PINMUX_IPSR_PHYS(ipsr, fn, psel) \
427077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##psel, FN_##ipsr)
428077365a9SGeert Uytterhoeven 
429077365a9SGeert Uytterhoeven /*
430077365a9SGeert Uytterhoeven  * Describe a pinmux configuration for a single-function pin with GPIO
431077365a9SGeert Uytterhoeven  * capability.
432077365a9SGeert Uytterhoeven  *   - fn: Function name
433077365a9SGeert Uytterhoeven  */
434077365a9SGeert Uytterhoeven #define PINMUX_SINGLE(fn)						\
435077365a9SGeert Uytterhoeven 	PINMUX_DATA(fn##_MARK, FN_##fn)
436077365a9SGeert Uytterhoeven 
437077365a9SGeert Uytterhoeven /*
438077365a9SGeert Uytterhoeven  * GP port style (32 ports banks)
439077365a9SGeert Uytterhoeven  */
440077365a9SGeert Uytterhoeven 
441077365a9SGeert Uytterhoeven #define PORT_GP_CFG_1(bank, pin, fn, sfx, cfg)				\
442077365a9SGeert Uytterhoeven 	fn(bank, pin, GP_##bank##_##pin, sfx, cfg)
443077365a9SGeert Uytterhoeven #define PORT_GP_1(bank, pin, fn, sfx)	PORT_GP_CFG_1(bank, pin, fn, sfx, 0)
444077365a9SGeert Uytterhoeven 
4459f2af9e5SUlrich Hecht #define PORT_GP_CFG_2(bank, fn, sfx, cfg)				\
446077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 0,  fn, sfx, cfg),				\
4479f2af9e5SUlrich Hecht 	PORT_GP_CFG_1(bank, 1,  fn, sfx, cfg)
4489f2af9e5SUlrich Hecht #define PORT_GP_2(bank, fn, sfx)	PORT_GP_CFG_2(bank, fn, sfx, 0)
4499f2af9e5SUlrich Hecht 
4509f2af9e5SUlrich Hecht #define PORT_GP_CFG_4(bank, fn, sfx, cfg)				\
4519f2af9e5SUlrich Hecht 	PORT_GP_CFG_2(bank, fn, sfx, cfg),				\
452077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 2,  fn, sfx, cfg),				\
453077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 3,  fn, sfx, cfg)
454077365a9SGeert Uytterhoeven #define PORT_GP_4(bank, fn, sfx)	PORT_GP_CFG_4(bank, fn, sfx, 0)
455077365a9SGeert Uytterhoeven 
456077365a9SGeert Uytterhoeven #define PORT_GP_CFG_6(bank, fn, sfx, cfg)				\
457077365a9SGeert Uytterhoeven 	PORT_GP_CFG_4(bank, fn, sfx, cfg),				\
458077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 4,  fn, sfx, cfg),				\
459077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 5,  fn, sfx, cfg)
460077365a9SGeert Uytterhoeven #define PORT_GP_6(bank, fn, sfx)	PORT_GP_CFG_6(bank, fn, sfx, 0)
461077365a9SGeert Uytterhoeven 
46293d6c7d6SGeert Uytterhoeven #define PORT_GP_CFG_7(bank, fn, sfx, cfg)				\
463077365a9SGeert Uytterhoeven 	PORT_GP_CFG_6(bank, fn, sfx, cfg),				\
46493d6c7d6SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 6,  fn, sfx, cfg)
46593d6c7d6SGeert Uytterhoeven #define PORT_GP_7(bank, fn, sfx)	PORT_GP_CFG_7(bank, fn, sfx, 0)
46693d6c7d6SGeert Uytterhoeven 
46793d6c7d6SGeert Uytterhoeven #define PORT_GP_CFG_8(bank, fn, sfx, cfg)				\
46893d6c7d6SGeert Uytterhoeven 	PORT_GP_CFG_7(bank, fn, sfx, cfg),				\
469077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 7,  fn, sfx, cfg)
470077365a9SGeert Uytterhoeven #define PORT_GP_8(bank, fn, sfx)	PORT_GP_CFG_8(bank, fn, sfx, 0)
471077365a9SGeert Uytterhoeven 
472077365a9SGeert Uytterhoeven #define PORT_GP_CFG_9(bank, fn, sfx, cfg)				\
473077365a9SGeert Uytterhoeven 	PORT_GP_CFG_8(bank, fn, sfx, cfg),				\
474077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 8,  fn, sfx, cfg)
475077365a9SGeert Uytterhoeven #define PORT_GP_9(bank, fn, sfx)	PORT_GP_CFG_9(bank, fn, sfx, 0)
476077365a9SGeert Uytterhoeven 
477077365a9SGeert Uytterhoeven #define PORT_GP_CFG_10(bank, fn, sfx, cfg)				\
478077365a9SGeert Uytterhoeven 	PORT_GP_CFG_9(bank, fn, sfx, cfg),				\
479077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 9,  fn, sfx, cfg)
480077365a9SGeert Uytterhoeven #define PORT_GP_10(bank, fn, sfx)	PORT_GP_CFG_10(bank, fn, sfx, 0)
481077365a9SGeert Uytterhoeven 
482077365a9SGeert Uytterhoeven #define PORT_GP_CFG_11(bank, fn, sfx, cfg)				\
483077365a9SGeert Uytterhoeven 	PORT_GP_CFG_10(bank, fn, sfx, cfg),				\
484077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 10, fn, sfx, cfg)
485077365a9SGeert Uytterhoeven #define PORT_GP_11(bank, fn, sfx)	PORT_GP_CFG_11(bank, fn, sfx, 0)
486077365a9SGeert Uytterhoeven 
487077365a9SGeert Uytterhoeven #define PORT_GP_CFG_12(bank, fn, sfx, cfg)				\
488077365a9SGeert Uytterhoeven 	PORT_GP_CFG_11(bank, fn, sfx, cfg),				\
489077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 11, fn, sfx, cfg)
490077365a9SGeert Uytterhoeven #define PORT_GP_12(bank, fn, sfx)	PORT_GP_CFG_12(bank, fn, sfx, 0)
491077365a9SGeert Uytterhoeven 
492665f77ebSKuninori Morimoto #define PORT_GP_CFG_13(bank, fn, sfx, cfg)				\
493077365a9SGeert Uytterhoeven 	PORT_GP_CFG_12(bank, fn, sfx, cfg),				\
494665f77ebSKuninori Morimoto 	PORT_GP_CFG_1(bank, 12, fn, sfx, cfg)
495665f77ebSKuninori Morimoto #define PORT_GP_13(bank, fn, sfx)	PORT_GP_CFG_13(bank, fn, sfx, 0)
496665f77ebSKuninori Morimoto 
497665f77ebSKuninori Morimoto #define PORT_GP_CFG_14(bank, fn, sfx, cfg)				\
498665f77ebSKuninori Morimoto 	PORT_GP_CFG_13(bank, fn, sfx, cfg),				\
499077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 13, fn, sfx, cfg)
500077365a9SGeert Uytterhoeven #define PORT_GP_14(bank, fn, sfx)	PORT_GP_CFG_14(bank, fn, sfx, 0)
501077365a9SGeert Uytterhoeven 
502077365a9SGeert Uytterhoeven #define PORT_GP_CFG_15(bank, fn, sfx, cfg)				\
503077365a9SGeert Uytterhoeven 	PORT_GP_CFG_14(bank, fn, sfx, cfg),				\
504077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 14, fn, sfx, cfg)
505077365a9SGeert Uytterhoeven #define PORT_GP_15(bank, fn, sfx)	PORT_GP_CFG_15(bank, fn, sfx, 0)
506077365a9SGeert Uytterhoeven 
507077365a9SGeert Uytterhoeven #define PORT_GP_CFG_16(bank, fn, sfx, cfg)				\
508077365a9SGeert Uytterhoeven 	PORT_GP_CFG_15(bank, fn, sfx, cfg),				\
509077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 15, fn, sfx, cfg)
510077365a9SGeert Uytterhoeven #define PORT_GP_16(bank, fn, sfx)	PORT_GP_CFG_16(bank, fn, sfx, 0)
511077365a9SGeert Uytterhoeven 
512077365a9SGeert Uytterhoeven #define PORT_GP_CFG_17(bank, fn, sfx, cfg)				\
513077365a9SGeert Uytterhoeven 	PORT_GP_CFG_16(bank, fn, sfx, cfg),				\
514077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 16, fn, sfx, cfg)
515077365a9SGeert Uytterhoeven #define PORT_GP_17(bank, fn, sfx)	PORT_GP_CFG_17(bank, fn, sfx, 0)
516077365a9SGeert Uytterhoeven 
517077365a9SGeert Uytterhoeven #define PORT_GP_CFG_18(bank, fn, sfx, cfg)				\
518077365a9SGeert Uytterhoeven 	PORT_GP_CFG_17(bank, fn, sfx, cfg),				\
519077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 17, fn, sfx, cfg)
520077365a9SGeert Uytterhoeven #define PORT_GP_18(bank, fn, sfx)	PORT_GP_CFG_18(bank, fn, sfx, 0)
521077365a9SGeert Uytterhoeven 
522acdc4b98SGeert Uytterhoeven #define PORT_GP_CFG_19(bank, fn, sfx, cfg)				\
523077365a9SGeert Uytterhoeven 	PORT_GP_CFG_18(bank, fn, sfx, cfg),				\
524acdc4b98SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 18, fn, sfx, cfg)
525acdc4b98SGeert Uytterhoeven #define PORT_GP_19(bank, fn, sfx)	PORT_GP_CFG_19(bank, fn, sfx, 0)
526acdc4b98SGeert Uytterhoeven 
527acdc4b98SGeert Uytterhoeven #define PORT_GP_CFG_20(bank, fn, sfx, cfg)				\
528acdc4b98SGeert Uytterhoeven 	PORT_GP_CFG_19(bank, fn, sfx, cfg),				\
529077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 19, fn, sfx, cfg)
530077365a9SGeert Uytterhoeven #define PORT_GP_20(bank, fn, sfx)	PORT_GP_CFG_20(bank, fn, sfx, 0)
531077365a9SGeert Uytterhoeven 
532077365a9SGeert Uytterhoeven #define PORT_GP_CFG_21(bank, fn, sfx, cfg)				\
533077365a9SGeert Uytterhoeven 	PORT_GP_CFG_20(bank, fn, sfx, cfg),				\
534077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 20, fn, sfx, cfg)
535077365a9SGeert Uytterhoeven #define PORT_GP_21(bank, fn, sfx)	PORT_GP_CFG_21(bank, fn, sfx, 0)
536077365a9SGeert Uytterhoeven 
537077365a9SGeert Uytterhoeven #define PORT_GP_CFG_22(bank, fn, sfx, cfg)				\
538077365a9SGeert Uytterhoeven 	PORT_GP_CFG_21(bank, fn, sfx, cfg),				\
539077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 21, fn, sfx, cfg)
540077365a9SGeert Uytterhoeven #define PORT_GP_22(bank, fn, sfx)	PORT_GP_CFG_22(bank, fn, sfx, 0)
541077365a9SGeert Uytterhoeven 
542077365a9SGeert Uytterhoeven #define PORT_GP_CFG_23(bank, fn, sfx, cfg)				\
543077365a9SGeert Uytterhoeven 	PORT_GP_CFG_22(bank, fn, sfx, cfg),				\
544077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 22, fn, sfx, cfg)
545077365a9SGeert Uytterhoeven #define PORT_GP_23(bank, fn, sfx)	PORT_GP_CFG_23(bank, fn, sfx, 0)
546077365a9SGeert Uytterhoeven 
547077365a9SGeert Uytterhoeven #define PORT_GP_CFG_24(bank, fn, sfx, cfg)				\
548077365a9SGeert Uytterhoeven 	PORT_GP_CFG_23(bank, fn, sfx, cfg),				\
549077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 23, fn, sfx, cfg)
550077365a9SGeert Uytterhoeven #define PORT_GP_24(bank, fn, sfx)	PORT_GP_CFG_24(bank, fn, sfx, 0)
551077365a9SGeert Uytterhoeven 
552077365a9SGeert Uytterhoeven #define PORT_GP_CFG_25(bank, fn, sfx, cfg)				\
553077365a9SGeert Uytterhoeven 	PORT_GP_CFG_24(bank, fn, sfx, cfg),				\
554077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 24, fn, sfx, cfg)
555077365a9SGeert Uytterhoeven #define PORT_GP_25(bank, fn, sfx)	PORT_GP_CFG_25(bank, fn, sfx, 0)
556077365a9SGeert Uytterhoeven 
557077365a9SGeert Uytterhoeven #define PORT_GP_CFG_26(bank, fn, sfx, cfg)				\
558077365a9SGeert Uytterhoeven 	PORT_GP_CFG_25(bank, fn, sfx, cfg),				\
559077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 25, fn, sfx, cfg)
560077365a9SGeert Uytterhoeven #define PORT_GP_26(bank, fn, sfx)	PORT_GP_CFG_26(bank, fn, sfx, 0)
561077365a9SGeert Uytterhoeven 
562077365a9SGeert Uytterhoeven #define PORT_GP_CFG_27(bank, fn, sfx, cfg)				\
563077365a9SGeert Uytterhoeven 	PORT_GP_CFG_26(bank, fn, sfx, cfg),				\
564077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 26, fn, sfx, cfg)
565077365a9SGeert Uytterhoeven #define PORT_GP_27(bank, fn, sfx)	PORT_GP_CFG_27(bank, fn, sfx, 0)
566077365a9SGeert Uytterhoeven 
567077365a9SGeert Uytterhoeven #define PORT_GP_CFG_28(bank, fn, sfx, cfg)				\
568077365a9SGeert Uytterhoeven 	PORT_GP_CFG_27(bank, fn, sfx, cfg),				\
569077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 27, fn, sfx, cfg)
570077365a9SGeert Uytterhoeven #define PORT_GP_28(bank, fn, sfx)	PORT_GP_CFG_28(bank, fn, sfx, 0)
571077365a9SGeert Uytterhoeven 
572077365a9SGeert Uytterhoeven #define PORT_GP_CFG_29(bank, fn, sfx, cfg)				\
573077365a9SGeert Uytterhoeven 	PORT_GP_CFG_28(bank, fn, sfx, cfg),				\
574077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 28, fn, sfx, cfg)
575077365a9SGeert Uytterhoeven #define PORT_GP_29(bank, fn, sfx)	PORT_GP_CFG_29(bank, fn, sfx, 0)
576077365a9SGeert Uytterhoeven 
577077365a9SGeert Uytterhoeven #define PORT_GP_CFG_30(bank, fn, sfx, cfg)				\
578077365a9SGeert Uytterhoeven 	PORT_GP_CFG_29(bank, fn, sfx, cfg),				\
579077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 29, fn, sfx, cfg)
580077365a9SGeert Uytterhoeven #define PORT_GP_30(bank, fn, sfx)	PORT_GP_CFG_30(bank, fn, sfx, 0)
581077365a9SGeert Uytterhoeven 
5829f2af9e5SUlrich Hecht #define PORT_GP_CFG_31(bank, fn, sfx, cfg)				\
583077365a9SGeert Uytterhoeven 	PORT_GP_CFG_30(bank, fn, sfx, cfg),				\
5849f2af9e5SUlrich Hecht 	PORT_GP_CFG_1(bank, 30, fn, sfx, cfg)
5859f2af9e5SUlrich Hecht #define PORT_GP_31(bank, fn, sfx)	PORT_GP_CFG_31(bank, fn, sfx, 0)
5869f2af9e5SUlrich Hecht 
5879f2af9e5SUlrich Hecht #define PORT_GP_CFG_32(bank, fn, sfx, cfg)				\
5889f2af9e5SUlrich Hecht 	PORT_GP_CFG_31(bank, fn, sfx, cfg),				\
589077365a9SGeert Uytterhoeven 	PORT_GP_CFG_1(bank, 31, fn, sfx, cfg)
590077365a9SGeert Uytterhoeven #define PORT_GP_32(bank, fn, sfx)	PORT_GP_CFG_32(bank, fn, sfx, 0)
591077365a9SGeert Uytterhoeven 
592077365a9SGeert Uytterhoeven #define PORT_GP_32_REV(bank, fn, sfx)					\
593077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 31, fn, sfx), PORT_GP_1(bank, 30, fn, sfx),	\
594077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 29, fn, sfx), PORT_GP_1(bank, 28, fn, sfx),	\
595077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 27, fn, sfx), PORT_GP_1(bank, 26, fn, sfx),	\
596077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 25, fn, sfx), PORT_GP_1(bank, 24, fn, sfx),	\
597077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 23, fn, sfx), PORT_GP_1(bank, 22, fn, sfx),	\
598077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 21, fn, sfx), PORT_GP_1(bank, 20, fn, sfx),	\
599077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 19, fn, sfx), PORT_GP_1(bank, 18, fn, sfx),	\
600077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 17, fn, sfx), PORT_GP_1(bank, 16, fn, sfx),	\
601077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 15, fn, sfx), PORT_GP_1(bank, 14, fn, sfx),	\
602077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 13, fn, sfx), PORT_GP_1(bank, 12, fn, sfx),	\
603077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 11, fn, sfx), PORT_GP_1(bank, 10, fn, sfx),	\
604077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 9,  fn, sfx), PORT_GP_1(bank, 8,  fn, sfx),	\
605077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 7,  fn, sfx), PORT_GP_1(bank, 6,  fn, sfx),	\
606077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 5,  fn, sfx), PORT_GP_1(bank, 4,  fn, sfx),	\
607077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 3,  fn, sfx), PORT_GP_1(bank, 2,  fn, sfx),	\
608077365a9SGeert Uytterhoeven 	PORT_GP_1(bank, 1,  fn, sfx), PORT_GP_1(bank, 0,  fn, sfx)
609077365a9SGeert Uytterhoeven 
610077365a9SGeert Uytterhoeven /* GP_ALL(suffix) - Expand to a list of GP_#_#_suffix */
611077365a9SGeert Uytterhoeven #define _GP_ALL(bank, pin, name, sfx, cfg)	name##_##sfx
612077365a9SGeert Uytterhoeven #define GP_ALL(str)			CPU_ALL_GP(_GP_ALL, str)
613077365a9SGeert Uytterhoeven 
614077365a9SGeert Uytterhoeven /* PINMUX_GPIO_GP_ALL - Expand to a list of sh_pfc_pin entries */
6158d880552SGeert Uytterhoeven #define _GP_GPIO(bank, _pin, _name, sfx, cfg) {				\
616077365a9SGeert Uytterhoeven 	.pin = (bank * 32) + _pin,					\
617077365a9SGeert Uytterhoeven 	.name = __stringify(_name),					\
618077365a9SGeert Uytterhoeven 	.enum_id = _name##_DATA,					\
619077365a9SGeert Uytterhoeven 	.configs = cfg,							\
620077365a9SGeert Uytterhoeven }
621077365a9SGeert Uytterhoeven #define PINMUX_GPIO_GP_ALL()		CPU_ALL_GP(_GP_GPIO, unused)
622077365a9SGeert Uytterhoeven 
623077365a9SGeert Uytterhoeven /* PINMUX_DATA_GP_ALL -  Expand to a list of name_DATA, name_FN marks */
624077365a9SGeert Uytterhoeven #define _GP_DATA(bank, pin, name, sfx, cfg)	PINMUX_DATA(name##_DATA, name##_FN)
625077365a9SGeert Uytterhoeven #define PINMUX_DATA_GP_ALL()		CPU_ALL_GP(_GP_DATA, unused)
626077365a9SGeert Uytterhoeven 
627077365a9SGeert Uytterhoeven /*
628077365a9SGeert Uytterhoeven  * GP_ASSIGN_LAST() - Expand to an enum definition for the last GP pin
629077365a9SGeert Uytterhoeven  *
630077365a9SGeert Uytterhoeven  * The largest GP pin index is obtained by taking the size of a union,
631077365a9SGeert Uytterhoeven  * containing one array per GP pin, sized by the corresponding pin index.
632077365a9SGeert Uytterhoeven  * As the fields in the CPU_ALL_GP() macro definition are separated by commas,
633077365a9SGeert Uytterhoeven  * while the members of a union must be terminated by semicolons, the commas
634077365a9SGeert Uytterhoeven  * are absorbed by wrapping them inside dummy attributes.
635077365a9SGeert Uytterhoeven  */
636077365a9SGeert Uytterhoeven #define _GP_ENTRY(bank, pin, name, sfx, cfg)				\
637077365a9SGeert Uytterhoeven 	deprecated)); char name[(bank * 32) + pin] __attribute__((deprecated
638077365a9SGeert Uytterhoeven #define GP_ASSIGN_LAST()						\
639077365a9SGeert Uytterhoeven 	GP_LAST = sizeof(union {					\
640077365a9SGeert Uytterhoeven 		char dummy[0] __attribute__((deprecated,		\
641077365a9SGeert Uytterhoeven 		CPU_ALL_GP(_GP_ENTRY, unused),				\
642077365a9SGeert Uytterhoeven 		deprecated));						\
643077365a9SGeert Uytterhoeven 	})
644077365a9SGeert Uytterhoeven 
645077365a9SGeert Uytterhoeven /*
646077365a9SGeert Uytterhoeven  * PORT style (linear pin space)
647077365a9SGeert Uytterhoeven  */
648077365a9SGeert Uytterhoeven 
649077365a9SGeert Uytterhoeven #define PORT_1(pn, fn, pfx, sfx) fn(pn, pfx, sfx)
650077365a9SGeert Uytterhoeven 
651077365a9SGeert Uytterhoeven #define PORT_10(pn, fn, pfx, sfx)					  \
652077365a9SGeert Uytterhoeven 	PORT_1(pn,   fn, pfx##0, sfx), PORT_1(pn+1, fn, pfx##1, sfx),	  \
653077365a9SGeert Uytterhoeven 	PORT_1(pn+2, fn, pfx##2, sfx), PORT_1(pn+3, fn, pfx##3, sfx),	  \
654077365a9SGeert Uytterhoeven 	PORT_1(pn+4, fn, pfx##4, sfx), PORT_1(pn+5, fn, pfx##5, sfx),	  \
655077365a9SGeert Uytterhoeven 	PORT_1(pn+6, fn, pfx##6, sfx), PORT_1(pn+7, fn, pfx##7, sfx),	  \
656077365a9SGeert Uytterhoeven 	PORT_1(pn+8, fn, pfx##8, sfx), PORT_1(pn+9, fn, pfx##9, sfx)
657077365a9SGeert Uytterhoeven 
658077365a9SGeert Uytterhoeven #define PORT_90(pn, fn, pfx, sfx)					  \
659077365a9SGeert Uytterhoeven 	PORT_10(pn+10, fn, pfx##1, sfx), PORT_10(pn+20, fn, pfx##2, sfx), \
660077365a9SGeert Uytterhoeven 	PORT_10(pn+30, fn, pfx##3, sfx), PORT_10(pn+40, fn, pfx##4, sfx), \
661077365a9SGeert Uytterhoeven 	PORT_10(pn+50, fn, pfx##5, sfx), PORT_10(pn+60, fn, pfx##6, sfx), \
662077365a9SGeert Uytterhoeven 	PORT_10(pn+70, fn, pfx##7, sfx), PORT_10(pn+80, fn, pfx##8, sfx), \
663077365a9SGeert Uytterhoeven 	PORT_10(pn+90, fn, pfx##9, sfx)
664077365a9SGeert Uytterhoeven 
665077365a9SGeert Uytterhoeven /* PORT_ALL(suffix) - Expand to a list of PORT_#_suffix */
666077365a9SGeert Uytterhoeven #define _PORT_ALL(pn, pfx, sfx)		pfx##_##sfx
667077365a9SGeert Uytterhoeven #define PORT_ALL(str)			CPU_ALL_PORT(_PORT_ALL, PORT, str)
668077365a9SGeert Uytterhoeven 
669077365a9SGeert Uytterhoeven /* PINMUX_GPIO - Expand to a sh_pfc_pin entry */
670077365a9SGeert Uytterhoeven #define PINMUX_GPIO(_pin)						\
671077365a9SGeert Uytterhoeven 	[GPIO_##_pin] = {						\
672077365a9SGeert Uytterhoeven 		.pin = (u16)-1,						\
673077365a9SGeert Uytterhoeven 		.name = __stringify(GPIO_##_pin),			\
674077365a9SGeert Uytterhoeven 		.enum_id = _pin##_DATA,					\
675077365a9SGeert Uytterhoeven 	}
676077365a9SGeert Uytterhoeven 
677077365a9SGeert Uytterhoeven /* SH_PFC_PIN_CFG - Expand to a sh_pfc_pin entry (named PORT#) with config */
6788d880552SGeert Uytterhoeven #define SH_PFC_PIN_CFG(_pin, cfgs) {					\
679077365a9SGeert Uytterhoeven 	.pin = _pin,							\
680077365a9SGeert Uytterhoeven 	.name = __stringify(PORT##_pin),				\
681077365a9SGeert Uytterhoeven 	.enum_id = PORT##_pin##_DATA,					\
682077365a9SGeert Uytterhoeven 	.configs = cfgs,						\
683077365a9SGeert Uytterhoeven }
684077365a9SGeert Uytterhoeven 
685077365a9SGeert Uytterhoeven /* PINMUX_DATA_ALL - Expand to a list of PORT_name_DATA, PORT_name_FN0,
686077365a9SGeert Uytterhoeven  *		     PORT_name_OUT, PORT_name_IN marks
687077365a9SGeert Uytterhoeven  */
688077365a9SGeert Uytterhoeven #define _PORT_DATA(pn, pfx, sfx)					\
689077365a9SGeert Uytterhoeven 	PINMUX_DATA(PORT##pfx##_DATA, PORT##pfx##_FN0,			\
690077365a9SGeert Uytterhoeven 		    PORT##pfx##_OUT, PORT##pfx##_IN)
691077365a9SGeert Uytterhoeven #define PINMUX_DATA_ALL()		CPU_ALL_PORT(_PORT_DATA, , unused)
692077365a9SGeert Uytterhoeven 
693077365a9SGeert Uytterhoeven /*
694077365a9SGeert Uytterhoeven  * PORT_ASSIGN_LAST() - Expand to an enum definition for the last PORT pin
695077365a9SGeert Uytterhoeven  *
696077365a9SGeert Uytterhoeven  * The largest PORT pin index is obtained by taking the size of a union,
697077365a9SGeert Uytterhoeven  * containing one array per PORT pin, sized by the corresponding pin index.
698077365a9SGeert Uytterhoeven  * As the fields in the CPU_ALL_PORT() macro definition are separated by
699077365a9SGeert Uytterhoeven  * commas, while the members of a union must be terminated by semicolons, the
700077365a9SGeert Uytterhoeven  * commas are absorbed by wrapping them inside dummy attributes.
701077365a9SGeert Uytterhoeven  */
702077365a9SGeert Uytterhoeven #define _PORT_ENTRY(pn, pfx, sfx)					\
703077365a9SGeert Uytterhoeven 	deprecated)); char pfx[pn] __attribute__((deprecated
704077365a9SGeert Uytterhoeven #define PORT_ASSIGN_LAST()						\
705077365a9SGeert Uytterhoeven 	PORT_LAST = sizeof(union {					\
706077365a9SGeert Uytterhoeven 		char dummy[0] __attribute__((deprecated,		\
707077365a9SGeert Uytterhoeven 		CPU_ALL_PORT(_PORT_ENTRY, PORT, unused),		\
708077365a9SGeert Uytterhoeven 		deprecated));						\
709077365a9SGeert Uytterhoeven 	})
710077365a9SGeert Uytterhoeven 
711077365a9SGeert Uytterhoeven /* GPIO_FN(name) - Expand to a sh_pfc_pin entry for a function GPIO */
712077365a9SGeert Uytterhoeven #define PINMUX_GPIO_FN(gpio, base, data_or_mark)			\
713077365a9SGeert Uytterhoeven 	[gpio - (base)] = {						\
714077365a9SGeert Uytterhoeven 		.name = __stringify(gpio),				\
715077365a9SGeert Uytterhoeven 		.enum_id = data_or_mark,				\
716077365a9SGeert Uytterhoeven 	}
717077365a9SGeert Uytterhoeven #define GPIO_FN(str)							\
718077365a9SGeert Uytterhoeven 	PINMUX_GPIO_FN(GPIO_FN_##str, PINMUX_FN_BASE, str##_MARK)
719077365a9SGeert Uytterhoeven 
720077365a9SGeert Uytterhoeven /*
721077365a9SGeert Uytterhoeven  * Pins not associated with a GPIO port
722077365a9SGeert Uytterhoeven  */
723077365a9SGeert Uytterhoeven 
724077365a9SGeert Uytterhoeven #define PIN_NOGP_CFG(pin, name, fn, cfg)	fn(pin, name, cfg)
725077365a9SGeert Uytterhoeven #define PIN_NOGP(pin, name, fn)			fn(pin, name, 0)
726077365a9SGeert Uytterhoeven 
727077365a9SGeert Uytterhoeven /* NOGP_ALL - Expand to a list of PIN_id */
728077365a9SGeert Uytterhoeven #define _NOGP_ALL(pin, name, cfg)		PIN_##pin
729077365a9SGeert Uytterhoeven #define NOGP_ALL()				CPU_ALL_NOGP(_NOGP_ALL)
730077365a9SGeert Uytterhoeven 
731077365a9SGeert Uytterhoeven /* PINMUX_NOGP_ALL - Expand to a list of sh_pfc_pin entries */
7328d880552SGeert Uytterhoeven #define _NOGP_PINMUX(_pin, _name, cfg) {				\
733077365a9SGeert Uytterhoeven 	.pin = PIN_##_pin,						\
734077365a9SGeert Uytterhoeven 	.name = "PIN_" _name,						\
735077365a9SGeert Uytterhoeven 	.configs = SH_PFC_PIN_CFG_NO_GPIO | cfg,			\
736077365a9SGeert Uytterhoeven }
737077365a9SGeert Uytterhoeven #define PINMUX_NOGP_ALL()		CPU_ALL_NOGP(_NOGP_PINMUX)
738077365a9SGeert Uytterhoeven 
739077365a9SGeert Uytterhoeven /*
740077365a9SGeert Uytterhoeven  * PORTnCR helper macro for SH-Mobile/R-Mobile
741077365a9SGeert Uytterhoeven  */
7428d880552SGeert Uytterhoeven #define PORTCR(nr, reg) {						\
74344778aecSGeert Uytterhoeven 	PINMUX_CFG_REG_VAR("PORT" nr "CR", reg, 8, GROUP(-2, 2, -1, 3),	\
744077365a9SGeert Uytterhoeven 			   GROUP(					\
745077365a9SGeert Uytterhoeven 		/* PULMD[1:0], handled by .set_bias() */		\
746077365a9SGeert Uytterhoeven 		/* IE and OE */						\
747077365a9SGeert Uytterhoeven 		0, PORT##nr##_OUT, PORT##nr##_IN, 0,			\
748077365a9SGeert Uytterhoeven 		/* SEC, not supported */				\
749077365a9SGeert Uytterhoeven 		/* PTMD[2:0] */						\
750077365a9SGeert Uytterhoeven 		PORT##nr##_FN0, PORT##nr##_FN1,				\
751077365a9SGeert Uytterhoeven 		PORT##nr##_FN2, PORT##nr##_FN3,				\
752077365a9SGeert Uytterhoeven 		PORT##nr##_FN4, PORT##nr##_FN5,				\
753077365a9SGeert Uytterhoeven 		PORT##nr##_FN6, PORT##nr##_FN7				\
754077365a9SGeert Uytterhoeven 	))								\
755077365a9SGeert Uytterhoeven }
756077365a9SGeert Uytterhoeven 
757077365a9SGeert Uytterhoeven /*
758077365a9SGeert Uytterhoeven  * GPIO number helper macro for R-Car
759077365a9SGeert Uytterhoeven  */
760077365a9SGeert Uytterhoeven #define RCAR_GP_PIN(bank, pin)		(((bank) * 32) + (pin))
761077365a9SGeert Uytterhoeven 
7624b6e6c19SGeert Uytterhoeven /*
7634b6e6c19SGeert Uytterhoeven  * Bias helpers
7644b6e6c19SGeert Uytterhoeven  */
765e9d66bdbSGeert Uytterhoeven const struct pinmux_bias_reg *
766410ba4adSGeert Uytterhoeven rcar_pin_to_bias_reg(const struct sh_pfc_soc_info *info, unsigned int pin,
767e9d66bdbSGeert Uytterhoeven 		     unsigned int *bit);
7684b6e6c19SGeert Uytterhoeven unsigned int rcar_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
7694b6e6c19SGeert Uytterhoeven void rcar_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
7704b6e6c19SGeert Uytterhoeven 			  unsigned int bias);
7714b6e6c19SGeert Uytterhoeven 
772ec0794a1SGeert Uytterhoeven unsigned int rmobile_pinmux_get_bias(struct sh_pfc *pfc, unsigned int pin);
773ec0794a1SGeert Uytterhoeven void rmobile_pinmux_set_bias(struct sh_pfc *pfc, unsigned int pin,
774ec0794a1SGeert Uytterhoeven 			     unsigned int bias);
775ec0794a1SGeert Uytterhoeven 
776077365a9SGeert Uytterhoeven #endif /* __SH_PFC_H */
777