xref: /linux/drivers/pinctrl/visconti/pinctrl-common.h (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2020 TOSHIBA CORPORATION
4  * Copyright (c) 2020 Toshiba Electronic Devices & Storage Corporation
5  * Copyright (c) 2020 Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
6  */
7 
8 #ifndef __VISCONTI_PINCTRL_COMMON_H__
9 #define __VISCONTI_PINCTRL_COMMON_H__
10 
11 struct pinctrl_pin_desc;
12 
13 /* PIN */
14 #define VISCONTI_PINS(pins_name, ...)  \
15 	static const unsigned int pins_name ## _pins[] = { __VA_ARGS__ }
16 
17 struct visconti_desc_pin {
18 	struct pinctrl_pin_desc pin;
19 	unsigned int dsel_offset;
20 	unsigned int dsel_shift;
21 	unsigned int pude_offset;
22 	unsigned int pudsel_offset;
23 	unsigned int pud_shift;
24 };
25 
26 #define VISCONTI_PIN(_pin, dsel, d_sh, pude, pudsel, p_sh)	\
27 {								\
28 	.pin = _pin,						\
29 	.dsel_offset = dsel,					\
30 	.dsel_shift = d_sh,					\
31 	.pude_offset = pude,					\
32 	.pudsel_offset = pudsel,				\
33 	.pud_shift = p_sh,					\
34 }
35 
36 /* Group */
37 #define VISCONTI_GROUPS(groups_name, ...)	\
38 	static const char * const groups_name ## _grps[] = { __VA_ARGS__ }
39 
40 struct visconti_mux {
41 	unsigned int offset;
42 	unsigned int mask;
43 	unsigned int val;
44 };
45 
46 struct visconti_pin_group {
47 	const char *name;
48 	const unsigned int *pins;
49 	unsigned int nr_pins;
50 	struct visconti_mux mux;
51 };
52 
53 #define VISCONTI_PIN_GROUP(group_name, off, msk, v)	\
54 {							\
55 	.name = __stringify(group_name) "_grp",		\
56 	.pins = group_name ## _pins,			\
57 	.nr_pins = ARRAY_SIZE(group_name ## _pins),	\
58 	.mux = {					\
59 		.offset = off,				\
60 		.mask = msk,				\
61 		.val = v,				\
62 	}						\
63 }
64 
65 /* MUX */
66 struct visconti_pin_function {
67 	const char *name;
68 	const char * const *groups;
69 	unsigned int nr_groups;
70 };
71 
72 #define VISCONTI_PIN_FUNCTION(func)		\
73 {						\
74 	.name = #func,				\
75 	.groups = func ## _grps,		\
76 	.nr_groups = ARRAY_SIZE(func ## _grps),	\
77 }
78 
79 /* chip dependent data */
80 struct visconti_pinctrl_devdata {
81 	const struct visconti_desc_pin *pins;
82 	unsigned int nr_pins;
83 	const struct visconti_pin_group *groups;
84 	unsigned int nr_groups;
85 	const struct visconti_pin_function *functions;
86 	unsigned int nr_functions;
87 
88 	const struct visconti_mux *gpio_mux;
89 
90 	void (*unlock)(void __iomem *base);
91 };
92 
93 int visconti_pinctrl_probe(struct platform_device *pdev,
94 			   const struct visconti_pinctrl_devdata *devdata);
95 
96 #endif /* __VISCONTI_PINCTRL_COMMON_H__ */
97