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