1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef PINCTRL_PINCTRL_NOMADIK_H
3 #define PINCTRL_PINCTRL_NOMADIK_H
4 
5 /* Package definitions */
6 #define PINCTRL_NMK_STN8815	0
7 #define PINCTRL_NMK_DB8500	1
8 
9 /* Alternate functions: function C is set in hw by setting both A and B */
10 #define NMK_GPIO_ALT_GPIO	0
11 #define NMK_GPIO_ALT_A	1
12 #define NMK_GPIO_ALT_B	2
13 #define NMK_GPIO_ALT_C	(NMK_GPIO_ALT_A | NMK_GPIO_ALT_B)
14 
15 #define NMK_GPIO_ALT_CX_SHIFT 2
16 #define NMK_GPIO_ALT_C1	((1<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
17 #define NMK_GPIO_ALT_C2	((2<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
18 #define NMK_GPIO_ALT_C3	((3<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
19 #define NMK_GPIO_ALT_C4	((4<<NMK_GPIO_ALT_CX_SHIFT) | NMK_GPIO_ALT_C)
20 
21 #define PRCM_GPIOCR_ALTCX(pin_num,\
22 	altc1_used, altc1_ri, altc1_cb,\
23 	altc2_used, altc2_ri, altc2_cb,\
24 	altc3_used, altc3_ri, altc3_cb,\
25 	altc4_used, altc4_ri, altc4_cb)\
26 {\
27 	.pin = pin_num,\
28 	.altcx[PRCM_IDX_GPIOCR_ALTC1] = {\
29 		.used = altc1_used,\
30 		.reg_index = altc1_ri,\
31 		.control_bit = altc1_cb\
32 	},\
33 	.altcx[PRCM_IDX_GPIOCR_ALTC2] = {\
34 		.used = altc2_used,\
35 		.reg_index = altc2_ri,\
36 		.control_bit = altc2_cb\
37 	},\
38 	.altcx[PRCM_IDX_GPIOCR_ALTC3] = {\
39 		.used = altc3_used,\
40 		.reg_index = altc3_ri,\
41 		.control_bit = altc3_cb\
42 	},\
43 	.altcx[PRCM_IDX_GPIOCR_ALTC4] = {\
44 		.used = altc4_used,\
45 		.reg_index = altc4_ri,\
46 		.control_bit = altc4_cb\
47 	},\
48 }
49 
50 /**
51  * enum prcm_gpiocr_reg_index
52  * Used to reference an PRCM GPIOCR register address.
53  */
54 enum prcm_gpiocr_reg_index {
55 	PRCM_IDX_GPIOCR1,
56 	PRCM_IDX_GPIOCR2,
57 	PRCM_IDX_GPIOCR3
58 };
59 /**
60  * enum prcm_gpiocr_altcx_index
61  * Used to reference an Other alternate-C function.
62  */
63 enum prcm_gpiocr_altcx_index {
64 	PRCM_IDX_GPIOCR_ALTC1,
65 	PRCM_IDX_GPIOCR_ALTC2,
66 	PRCM_IDX_GPIOCR_ALTC3,
67 	PRCM_IDX_GPIOCR_ALTC4,
68 	PRCM_IDX_GPIOCR_ALTC_MAX,
69 };
70 
71 /**
72  * struct prcm_gpio_altcx - Other alternate-C function
73  * @used: other alternate-C function availability
74  * @reg_index: PRCM GPIOCR register index used to control the function
75  * @control_bit: PRCM GPIOCR bit used to control the function
76  */
77 struct prcm_gpiocr_altcx {
78 	bool used:1;
79 	u8 reg_index:2;
80 	u8 control_bit:5;
81 } __packed;
82 
83 /**
84  * struct prcm_gpio_altcx_pin_desc - Other alternate-C pin
85  * @pin: The pin number
86  * @altcx: array of other alternate-C[1-4] functions
87  */
88 struct prcm_gpiocr_altcx_pin_desc {
89 	unsigned short pin;
90 	struct prcm_gpiocr_altcx altcx[PRCM_IDX_GPIOCR_ALTC_MAX];
91 };
92 
93 /**
94  * struct nmk_function - Nomadik pinctrl mux function
95  * @name: The name of the function, exported to pinctrl core.
96  * @groups: An array of pin groups that may select this function.
97  * @ngroups: The number of entries in @groups.
98  */
99 struct nmk_function {
100 	const char *name;
101 	const char * const *groups;
102 	unsigned ngroups;
103 };
104 
105 /**
106  * struct nmk_pingroup - describes a Nomadik pin group
107  * @grp: Generic data of the pin group (name and pins)
108  * @altsetting: the altsetting to apply to all pins in this group to
109  *	configure them to be used by a function
110  */
111 struct nmk_pingroup {
112 	struct pingroup grp;
113 	int altsetting;
114 };
115 
116 #define NMK_PIN_GROUP(a, b)							\
117 	{									\
118 		.grp = PINCTRL_PINGROUP(#a, a##_pins, ARRAY_SIZE(a##_pins)),	\
119 		.altsetting = b,						\
120 	}
121 
122 /**
123  * struct nmk_pinctrl_soc_data - Nomadik pin controller per-SoC configuration
124  * @pins:	An array describing all pins the pin controller affects.
125  *		All pins which are also GPIOs must be listed first within the
126  *		array, and be numbered identically to the GPIO controller's
127  *		numbering.
128  * @npins:	The number of entries in @pins.
129  * @functions:	The functions supported on this SoC.
130  * @nfunction:	The number of entries in @functions.
131  * @groups:	An array describing all pin groups the pin SoC supports.
132  * @ngroups:	The number of entries in @groups.
133  * @altcx_pins:	The pins that support Other alternate-C function on this SoC
134  * @npins_altcx: The number of Other alternate-C pins
135  * @prcm_gpiocr_registers: The array of PRCM GPIOCR registers on this SoC
136  */
137 struct nmk_pinctrl_soc_data {
138 	const struct pinctrl_pin_desc *pins;
139 	unsigned npins;
140 	const struct nmk_function *functions;
141 	unsigned nfunctions;
142 	const struct nmk_pingroup *groups;
143 	unsigned ngroups;
144 	const struct prcm_gpiocr_altcx_pin_desc *altcx_pins;
145 	unsigned npins_altcx;
146 	const u16 *prcm_gpiocr_registers;
147 };
148 
149 #ifdef CONFIG_PINCTRL_STN8815
150 
151 void nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data **soc);
152 
153 #else
154 
155 static inline void
nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data ** soc)156 nmk_pinctrl_stn8815_init(const struct nmk_pinctrl_soc_data **soc)
157 {
158 }
159 
160 #endif
161 
162 #ifdef CONFIG_PINCTRL_DB8500
163 
164 void nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data **soc);
165 
166 #else
167 
168 static inline void
nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data ** soc)169 nmk_pinctrl_db8500_init(const struct nmk_pinctrl_soc_data **soc)
170 {
171 }
172 
173 #endif
174 
175 #endif /* PINCTRL_PINCTRL_NOMADIK_H */
176