1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2016 - Beniamino Galvani <b.galvani@gmail.com>
4  */
5 
6 #ifndef __PINCTRL_MESON_H__
7 #define __PINCTRL_MESON_H__
8 
9 #include <linux/types.h>
10 
11 struct meson_pmx_group {
12 	const char *name;
13 	const unsigned int *pins;
14 	unsigned int num_pins;
15 	const void *data;
16 };
17 
18 struct meson_pmx_func {
19 	const char *name;
20 	const char * const *groups;
21 	unsigned int num_groups;
22 };
23 
24 struct meson_pinctrl_data {
25 	const char *name;
26 	struct meson_pmx_group *groups;
27 	struct meson_pmx_func *funcs;
28 	struct meson_bank *banks;
29 	unsigned int pin_base;
30 	unsigned int num_pins;
31 	unsigned int num_groups;
32 	unsigned int num_funcs;
33 	unsigned int num_banks;
34 	const struct driver *gpio_driver;
35 	void *pmx_data;
36 };
37 
38 struct meson_pinctrl {
39 	struct meson_pinctrl_data *data;
40 	void __iomem *reg_mux;
41 	void __iomem *reg_gpio;
42 };
43 
44 /**
45  * struct meson_reg_desc - a register descriptor
46  *
47  * @reg:	register offset in the regmap
48  * @bit:	bit index in register
49  *
50  * The structure describes the information needed to control pull,
51  * pull-enable, direction, etc. for a single pin
52  */
53 struct meson_reg_desc {
54 	unsigned int reg;
55 	unsigned int bit;
56 };
57 
58 /**
59  * enum meson_reg_type - type of registers encoded in @meson_reg_desc
60  */
61 enum meson_reg_type {
62 	REG_PULLEN,
63 	REG_PULL,
64 	REG_DIR,
65 	REG_OUT,
66 	REG_IN,
67 	NUM_REG,
68 };
69 
70 /**
71  * struct meson bank
72  *
73  * @name:	bank name
74  * @first:	first pin of the bank
75  * @last:	last pin of the bank
76  * @regs:	array of register descriptors
77  *
78  * A bank represents a set of pins controlled by a contiguous set of
79  * bits in the domain registers. The structure specifies which bits in
80  * the regmap control the different functionalities. Each member of
81  * the @regs array refers to the first pin of the bank.
82  */
83 struct meson_bank {
84 	const char *name;
85 	unsigned int first;
86 	unsigned int last;
87 	struct meson_reg_desc regs[NUM_REG];
88 };
89 
90 #define PIN(x, b)	(b + x)
91 
92 #define FUNCTION(fn)							\
93 	{								\
94 		.name = #fn,						\
95 		.groups = fn ## _groups,				\
96 		.num_groups = ARRAY_SIZE(fn ## _groups),		\
97 	}
98 
99 #define BANK(n, f, l, per, peb, pr, pb, dr, db, or, ob, ir, ib)		\
100 	{								\
101 		.name	= n,						\
102 		.first	= f,						\
103 		.last	= l,						\
104 		.regs	= {						\
105 			[REG_PULLEN]	= { per, peb },			\
106 			[REG_PULL]	= { pr, pb },			\
107 			[REG_DIR]	= { dr, db },			\
108 			[REG_OUT]	= { or, ob },			\
109 			[REG_IN]	= { ir, ib },			\
110 		},							\
111 	 }
112 
113 #define MESON_PIN(x, b) PINCTRL_PIN(PIN(x, b), #x)
114 
115 extern const struct pinctrl_ops meson_pinctrl_ops;
116 
117 int meson_pinctrl_get_groups_count(struct udevice *dev);
118 const char *meson_pinctrl_get_group_name(struct udevice *dev,
119 					 unsigned int selector);
120 int meson_pinmux_get_functions_count(struct udevice *dev);
121 const char *meson_pinmux_get_function_name(struct udevice *dev,
122 					   unsigned int selector);
123 int meson_pinctrl_probe(struct udevice *dev);
124 
125 int meson_gpio_get(struct udevice *dev, unsigned int offset);
126 int meson_gpio_set(struct udevice *dev, unsigned int offset, int value);
127 int meson_gpio_get_direction(struct udevice *dev, unsigned int offset);
128 int meson_gpio_direction_input(struct udevice *dev, unsigned int offset);
129 int meson_gpio_direction_output(struct udevice *dev, unsigned int offset,
130 				int value);
131 int meson_gpio_probe(struct udevice *dev);
132 
133 #endif /* __PINCTRL_MESON_H__ */
134