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