.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2016 IBM Corp. |
---|
3 | | - * |
---|
4 | | - * This program is free software; you can redistribute it and/or modify |
---|
5 | | - * it under the terms of the GNU General Public License as published by |
---|
6 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
7 | | - * (at your option) any later version. |
---|
8 | 4 | */ |
---|
9 | 5 | |
---|
10 | 6 | #include <linux/mfd/syscon.h> |
---|
.. | .. |
---|
14 | 10 | #include "../core.h" |
---|
15 | 11 | #include "pinctrl-aspeed.h" |
---|
16 | 12 | |
---|
17 | | -static const char *const aspeed_pinmux_ips[] = { |
---|
18 | | - [ASPEED_IP_SCU] = "SCU", |
---|
19 | | - [ASPEED_IP_GFX] = "GFX", |
---|
20 | | - [ASPEED_IP_LPC] = "LPC", |
---|
21 | | -}; |
---|
22 | | - |
---|
23 | 13 | int aspeed_pinctrl_get_groups_count(struct pinctrl_dev *pctldev) |
---|
24 | 14 | { |
---|
25 | 15 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
26 | 16 | |
---|
27 | | - return pdata->ngroups; |
---|
| 17 | + return pdata->pinmux.ngroups; |
---|
28 | 18 | } |
---|
29 | 19 | |
---|
30 | 20 | const char *aspeed_pinctrl_get_group_name(struct pinctrl_dev *pctldev, |
---|
.. | .. |
---|
32 | 22 | { |
---|
33 | 23 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
34 | 24 | |
---|
35 | | - return pdata->groups[group].name; |
---|
| 25 | + return pdata->pinmux.groups[group].name; |
---|
36 | 26 | } |
---|
37 | 27 | |
---|
38 | 28 | int aspeed_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, |
---|
.. | .. |
---|
41 | 31 | { |
---|
42 | 32 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
43 | 33 | |
---|
44 | | - *pins = &pdata->groups[group].pins[0]; |
---|
45 | | - *npins = pdata->groups[group].npins; |
---|
| 34 | + *pins = &pdata->pinmux.groups[group].pins[0]; |
---|
| 35 | + *npins = pdata->pinmux.groups[group].npins; |
---|
46 | 36 | |
---|
47 | 37 | return 0; |
---|
48 | 38 | } |
---|
.. | .. |
---|
57 | 47 | { |
---|
58 | 48 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
59 | 49 | |
---|
60 | | - return pdata->nfunctions; |
---|
| 50 | + return pdata->pinmux.nfunctions; |
---|
61 | 51 | } |
---|
62 | 52 | |
---|
63 | 53 | const char *aspeed_pinmux_get_fn_name(struct pinctrl_dev *pctldev, |
---|
.. | .. |
---|
65 | 55 | { |
---|
66 | 56 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
67 | 57 | |
---|
68 | | - return pdata->functions[function].name; |
---|
| 58 | + return pdata->pinmux.functions[function].name; |
---|
69 | 59 | } |
---|
70 | 60 | |
---|
71 | 61 | int aspeed_pinmux_get_fn_groups(struct pinctrl_dev *pctldev, |
---|
.. | .. |
---|
75 | 65 | { |
---|
76 | 66 | struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
77 | 67 | |
---|
78 | | - *groups = pdata->functions[function].groups; |
---|
79 | | - *num_groups = pdata->functions[function].ngroups; |
---|
| 68 | + *groups = pdata->pinmux.functions[function].groups; |
---|
| 69 | + *num_groups = pdata->pinmux.functions[function].ngroups; |
---|
80 | 70 | |
---|
81 | 71 | return 0; |
---|
82 | 72 | } |
---|
83 | 73 | |
---|
84 | | -static inline void aspeed_sig_desc_print_val( |
---|
85 | | - const struct aspeed_sig_desc *desc, bool enable, u32 rv) |
---|
86 | | -{ |
---|
87 | | - pr_debug("Want %s%X[0x%08X]=0x%X, got 0x%X from 0x%08X\n", |
---|
88 | | - aspeed_pinmux_ips[desc->ip], desc->reg, |
---|
89 | | - desc->mask, enable ? desc->enable : desc->disable, |
---|
90 | | - (rv & desc->mask) >> __ffs(desc->mask), rv); |
---|
91 | | -} |
---|
92 | | - |
---|
93 | | -/** |
---|
94 | | - * Query the enabled or disabled state of a signal descriptor |
---|
95 | | - * |
---|
96 | | - * @desc: The signal descriptor of interest |
---|
97 | | - * @enabled: True to query the enabled state, false to query disabled state |
---|
98 | | - * @map: The IP block's regmap instance |
---|
99 | | - * |
---|
100 | | - * Return: 1 if the descriptor's bitfield is configured to the state |
---|
101 | | - * selected by @enabled, 0 if not, and less than zero if an unrecoverable |
---|
102 | | - * failure occurred |
---|
103 | | - * |
---|
104 | | - * Evaluation of descriptor state is non-trivial in that it is not a binary |
---|
105 | | - * outcome: The bitfields can be greater than one bit in size and thus can take |
---|
106 | | - * a value that is neither the enabled nor disabled state recorded in the |
---|
107 | | - * descriptor (typically this means a different function to the one of interest |
---|
108 | | - * is enabled). Thus we must explicitly test for either condition as required. |
---|
109 | | - */ |
---|
110 | | -static int aspeed_sig_desc_eval(const struct aspeed_sig_desc *desc, |
---|
111 | | - bool enabled, struct regmap *map) |
---|
| 74 | +static int aspeed_sig_expr_enable(struct aspeed_pinmux_data *ctx, |
---|
| 75 | + const struct aspeed_sig_expr *expr) |
---|
112 | 76 | { |
---|
113 | 77 | int ret; |
---|
114 | | - unsigned int raw; |
---|
115 | | - u32 want; |
---|
116 | 78 | |
---|
117 | | - if (!map) |
---|
118 | | - return -ENODEV; |
---|
| 79 | + pr_debug("Enabling signal %s for %s\n", expr->signal, |
---|
| 80 | + expr->function); |
---|
119 | 81 | |
---|
120 | | - ret = regmap_read(map, desc->reg, &raw); |
---|
121 | | - if (ret) |
---|
122 | | - return ret; |
---|
123 | | - |
---|
124 | | - aspeed_sig_desc_print_val(desc, enabled, raw); |
---|
125 | | - want = enabled ? desc->enable : desc->disable; |
---|
126 | | - |
---|
127 | | - return ((raw & desc->mask) >> __ffs(desc->mask)) == want; |
---|
128 | | -} |
---|
129 | | - |
---|
130 | | -/** |
---|
131 | | - * Query the enabled or disabled state for a mux function's signal on a pin |
---|
132 | | - * |
---|
133 | | - * @expr: An expression controlling the signal for a mux function on a pin |
---|
134 | | - * @enabled: True to query the enabled state, false to query disabled state |
---|
135 | | - * @maps: The list of regmap instances |
---|
136 | | - * |
---|
137 | | - * Return: 1 if the expression composed by @enabled evaluates true, 0 if not, |
---|
138 | | - * and less than zero if an unrecoverable failure occurred. |
---|
139 | | - * |
---|
140 | | - * A mux function is enabled or disabled if the function's signal expression |
---|
141 | | - * for each pin in the function's pin group evaluates true for the desired |
---|
142 | | - * state. An signal expression evaluates true if all of its associated signal |
---|
143 | | - * descriptors evaluate true for the desired state. |
---|
144 | | - * |
---|
145 | | - * If an expression's state is described by more than one bit, either through |
---|
146 | | - * multi-bit bitfields in a single signal descriptor or through multiple signal |
---|
147 | | - * descriptors of a single bit then it is possible for the expression to be in |
---|
148 | | - * neither the enabled nor disabled state. Thus we must explicitly test for |
---|
149 | | - * either condition as required. |
---|
150 | | - */ |
---|
151 | | -static int aspeed_sig_expr_eval(const struct aspeed_sig_expr *expr, |
---|
152 | | - bool enabled, struct regmap * const *maps) |
---|
153 | | -{ |
---|
154 | | - int i; |
---|
155 | | - int ret; |
---|
156 | | - |
---|
157 | | - for (i = 0; i < expr->ndescs; i++) { |
---|
158 | | - const struct aspeed_sig_desc *desc = &expr->descs[i]; |
---|
159 | | - |
---|
160 | | - ret = aspeed_sig_desc_eval(desc, enabled, maps[desc->ip]); |
---|
161 | | - if (ret <= 0) |
---|
162 | | - return ret; |
---|
163 | | - } |
---|
164 | | - |
---|
165 | | - return 1; |
---|
166 | | -} |
---|
167 | | - |
---|
168 | | -/** |
---|
169 | | - * Configure a pin's signal by applying an expression's descriptor state for |
---|
170 | | - * all descriptors in the expression. |
---|
171 | | - * |
---|
172 | | - * @expr: The expression associated with the function whose signal is to be |
---|
173 | | - * configured |
---|
174 | | - * @enable: true to enable an function's signal through a pin's signal |
---|
175 | | - * expression, false to disable the function's signal |
---|
176 | | - * @maps: The list of regmap instances for pinmux register access. |
---|
177 | | - * |
---|
178 | | - * Return: 0 if the expression is configured as requested and a negative error |
---|
179 | | - * code otherwise |
---|
180 | | - */ |
---|
181 | | -static int aspeed_sig_expr_set(const struct aspeed_sig_expr *expr, |
---|
182 | | - bool enable, struct regmap * const *maps) |
---|
183 | | -{ |
---|
184 | | - int ret; |
---|
185 | | - int i; |
---|
186 | | - |
---|
187 | | - for (i = 0; i < expr->ndescs; i++) { |
---|
188 | | - const struct aspeed_sig_desc *desc = &expr->descs[i]; |
---|
189 | | - u32 pattern = enable ? desc->enable : desc->disable; |
---|
190 | | - u32 val = (pattern << __ffs(desc->mask)); |
---|
191 | | - |
---|
192 | | - if (!maps[desc->ip]) |
---|
193 | | - return -ENODEV; |
---|
194 | | - |
---|
195 | | - /* |
---|
196 | | - * Strap registers are configured in hardware or by early-boot |
---|
197 | | - * firmware. Treat them as read-only despite that we can write |
---|
198 | | - * them. This may mean that certain functions cannot be |
---|
199 | | - * deconfigured and is the reason we re-evaluate after writing |
---|
200 | | - * all descriptor bits. |
---|
201 | | - * |
---|
202 | | - * Port D and port E GPIO loopback modes are the only exception |
---|
203 | | - * as those are commonly used with front-panel buttons to allow |
---|
204 | | - * normal operation of the host when the BMC is powered off or |
---|
205 | | - * fails to boot. Once the BMC has booted, the loopback mode |
---|
206 | | - * must be disabled for the BMC to control host power-on and |
---|
207 | | - * reset. |
---|
208 | | - */ |
---|
209 | | - if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP1 && |
---|
210 | | - !(desc->mask & (BIT(21) | BIT(22)))) |
---|
211 | | - continue; |
---|
212 | | - |
---|
213 | | - if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP2) |
---|
214 | | - continue; |
---|
215 | | - |
---|
216 | | - /* On AST2500, Set bits in SCU7C are cleared from SCU70 */ |
---|
217 | | - if (desc->ip == ASPEED_IP_SCU && desc->reg == HW_STRAP1) { |
---|
218 | | - unsigned int rev_id; |
---|
219 | | - |
---|
220 | | - ret = regmap_read(maps[ASPEED_IP_SCU], |
---|
221 | | - HW_REVISION_ID, &rev_id); |
---|
222 | | - if (ret < 0) |
---|
223 | | - return ret; |
---|
224 | | - |
---|
225 | | - if (0x04 == (rev_id >> 24)) { |
---|
226 | | - u32 value = ~val & desc->mask; |
---|
227 | | - |
---|
228 | | - if (value) { |
---|
229 | | - ret = regmap_write(maps[desc->ip], |
---|
230 | | - HW_REVISION_ID, value); |
---|
231 | | - if (ret < 0) |
---|
232 | | - return ret; |
---|
233 | | - } |
---|
234 | | - } |
---|
235 | | - } |
---|
236 | | - |
---|
237 | | - ret = regmap_update_bits(maps[desc->ip], desc->reg, |
---|
238 | | - desc->mask, val); |
---|
239 | | - |
---|
240 | | - if (ret) |
---|
241 | | - return ret; |
---|
242 | | - } |
---|
243 | | - |
---|
244 | | - ret = aspeed_sig_expr_eval(expr, enable, maps); |
---|
| 82 | + ret = aspeed_sig_expr_eval(ctx, expr, true); |
---|
245 | 83 | if (ret < 0) |
---|
246 | 84 | return ret; |
---|
247 | 85 | |
---|
248 | 86 | if (!ret) |
---|
249 | | - return -EPERM; |
---|
| 87 | + return aspeed_sig_expr_set(ctx, expr, true); |
---|
250 | 88 | |
---|
251 | 89 | return 0; |
---|
252 | 90 | } |
---|
253 | 91 | |
---|
254 | | -static int aspeed_sig_expr_enable(const struct aspeed_sig_expr *expr, |
---|
255 | | - struct regmap * const *maps) |
---|
| 92 | +static int aspeed_sig_expr_disable(struct aspeed_pinmux_data *ctx, |
---|
| 93 | + const struct aspeed_sig_expr *expr) |
---|
256 | 94 | { |
---|
257 | 95 | int ret; |
---|
258 | 96 | |
---|
259 | | - ret = aspeed_sig_expr_eval(expr, true, maps); |
---|
260 | | - if (ret < 0) |
---|
261 | | - return ret; |
---|
| 97 | + pr_debug("Disabling signal %s for %s\n", expr->signal, |
---|
| 98 | + expr->function); |
---|
262 | 99 | |
---|
263 | | - if (!ret) |
---|
264 | | - return aspeed_sig_expr_set(expr, true, maps); |
---|
265 | | - |
---|
266 | | - return 0; |
---|
267 | | -} |
---|
268 | | - |
---|
269 | | -static int aspeed_sig_expr_disable(const struct aspeed_sig_expr *expr, |
---|
270 | | - struct regmap * const *maps) |
---|
271 | | -{ |
---|
272 | | - int ret; |
---|
273 | | - |
---|
274 | | - ret = aspeed_sig_expr_eval(expr, true, maps); |
---|
| 100 | + ret = aspeed_sig_expr_eval(ctx, expr, true); |
---|
275 | 101 | if (ret < 0) |
---|
276 | 102 | return ret; |
---|
277 | 103 | |
---|
278 | 104 | if (ret) |
---|
279 | | - return aspeed_sig_expr_set(expr, false, maps); |
---|
| 105 | + return aspeed_sig_expr_set(ctx, expr, false); |
---|
280 | 106 | |
---|
281 | 107 | return 0; |
---|
282 | 108 | } |
---|
.. | .. |
---|
284 | 110 | /** |
---|
285 | 111 | * Disable a signal on a pin by disabling all provided signal expressions. |
---|
286 | 112 | * |
---|
| 113 | + * @ctx: The pinmux context |
---|
287 | 114 | * @exprs: The list of signal expressions (from a priority level on a pin) |
---|
288 | | - * @maps: The list of regmap instances for pinmux register access. |
---|
289 | 115 | * |
---|
290 | 116 | * Return: 0 if all expressions are disabled, otherwise a negative error code |
---|
291 | 117 | */ |
---|
292 | | -static int aspeed_disable_sig(const struct aspeed_sig_expr **exprs, |
---|
293 | | - struct regmap * const *maps) |
---|
| 118 | +static int aspeed_disable_sig(struct aspeed_pinmux_data *ctx, |
---|
| 119 | + const struct aspeed_sig_expr **exprs) |
---|
294 | 120 | { |
---|
295 | 121 | int ret = 0; |
---|
296 | 122 | |
---|
297 | 123 | if (!exprs) |
---|
298 | | - return true; |
---|
| 124 | + return -EINVAL; |
---|
299 | 125 | |
---|
300 | 126 | while (*exprs && !ret) { |
---|
301 | | - ret = aspeed_sig_expr_disable(*exprs, maps); |
---|
| 127 | + ret = aspeed_sig_expr_disable(ctx, *exprs); |
---|
302 | 128 | exprs++; |
---|
303 | 129 | } |
---|
304 | 130 | |
---|
.. | .. |
---|
397 | 223 | { |
---|
398 | 224 | int i; |
---|
399 | 225 | int ret; |
---|
400 | | - const struct aspeed_pinctrl_data *pdata = |
---|
401 | | - pinctrl_dev_get_drvdata(pctldev); |
---|
402 | | - const struct aspeed_pin_group *pgroup = &pdata->groups[group]; |
---|
| 226 | + struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
| 227 | + const struct aspeed_pin_group *pgroup = &pdata->pinmux.groups[group]; |
---|
403 | 228 | const struct aspeed_pin_function *pfunc = |
---|
404 | | - &pdata->functions[function]; |
---|
| 229 | + &pdata->pinmux.functions[function]; |
---|
405 | 230 | |
---|
406 | 231 | for (i = 0; i < pgroup->npins; i++) { |
---|
407 | 232 | int pin = pgroup->pins[i]; |
---|
.. | .. |
---|
410 | 235 | const struct aspeed_sig_expr **funcs; |
---|
411 | 236 | const struct aspeed_sig_expr ***prios; |
---|
412 | 237 | |
---|
413 | | - pr_debug("Muxing pin %d for %s\n", pin, pfunc->name); |
---|
414 | | - |
---|
415 | 238 | if (!pdesc) |
---|
416 | 239 | return -EINVAL; |
---|
| 240 | + |
---|
| 241 | + pr_debug("Muxing pin %s for %s\n", pdesc->name, pfunc->name); |
---|
417 | 242 | |
---|
418 | 243 | prios = pdesc->prios; |
---|
419 | 244 | |
---|
.. | .. |
---|
427 | 252 | if (expr) |
---|
428 | 253 | break; |
---|
429 | 254 | |
---|
430 | | - ret = aspeed_disable_sig(funcs, pdata->maps); |
---|
| 255 | + ret = aspeed_disable_sig(&pdata->pinmux, funcs); |
---|
431 | 256 | if (ret) |
---|
432 | 257 | return ret; |
---|
433 | 258 | |
---|
.. | .. |
---|
447 | 272 | return -ENXIO; |
---|
448 | 273 | } |
---|
449 | 274 | |
---|
450 | | - ret = aspeed_sig_expr_enable(expr, pdata->maps); |
---|
| 275 | + ret = aspeed_sig_expr_enable(&pdata->pinmux, expr); |
---|
451 | 276 | if (ret) |
---|
452 | 277 | return ret; |
---|
| 278 | + |
---|
| 279 | + pr_debug("Muxed pin %s as %s for %s\n", pdesc->name, expr->signal, |
---|
| 280 | + expr->function); |
---|
453 | 281 | } |
---|
454 | 282 | |
---|
455 | 283 | return 0; |
---|
.. | .. |
---|
458 | 286 | static bool aspeed_expr_is_gpio(const struct aspeed_sig_expr *expr) |
---|
459 | 287 | { |
---|
460 | 288 | /* |
---|
461 | | - * The signal type is GPIO if the signal name has "GPI" as a prefix. |
---|
462 | | - * strncmp (rather than strcmp) is used to implement the prefix |
---|
463 | | - * requirement. |
---|
| 289 | + * We need to differentiate between GPIO and non-GPIO signals to |
---|
| 290 | + * implement the gpio_request_enable() interface. For better or worse |
---|
| 291 | + * the ASPEED pinctrl driver uses the expression names to determine |
---|
| 292 | + * whether an expression will mux a pin for GPIO. |
---|
464 | 293 | * |
---|
465 | | - * expr->signal might look like "GPIOB1" in the GPIO case. |
---|
466 | | - * expr->signal might look like "GPIT0" in the GPI case. |
---|
| 294 | + * Generally we have the following - A GPIO such as B1 has: |
---|
| 295 | + * |
---|
| 296 | + * - expr->signal set to "GPIOB1" |
---|
| 297 | + * - expr->function set to "GPIOB1" |
---|
| 298 | + * |
---|
| 299 | + * Using this fact we can determine whether the provided expression is |
---|
| 300 | + * a GPIO expression by testing the signal name for the string prefix |
---|
| 301 | + * "GPIO". |
---|
| 302 | + * |
---|
| 303 | + * However, some GPIOs are input-only, and the ASPEED datasheets name |
---|
| 304 | + * them differently. An input-only GPIO such as T0 has: |
---|
| 305 | + * |
---|
| 306 | + * - expr->signal set to "GPIT0" |
---|
| 307 | + * - expr->function set to "GPIT0" |
---|
| 308 | + * |
---|
| 309 | + * It's tempting to generalise the prefix test from "GPIO" to "GPI" to |
---|
| 310 | + * account for both GPIOs and GPIs, but in doing so we run aground on |
---|
| 311 | + * another feature: |
---|
| 312 | + * |
---|
| 313 | + * Some pins in the ASPEED BMC SoCs have a "pass-through" GPIO |
---|
| 314 | + * function where the input state of one pin is replicated as the |
---|
| 315 | + * output state of another (as if they were shorted together - a mux |
---|
| 316 | + * configuration that is typically enabled by hardware strapping). |
---|
| 317 | + * This feature allows the BMC to pass e.g. power button state through |
---|
| 318 | + * to the host while the BMC is yet to boot, but take control of the |
---|
| 319 | + * button state once the BMC has booted by muxing each pin as a |
---|
| 320 | + * separate, pin-specific GPIO. |
---|
| 321 | + * |
---|
| 322 | + * Conceptually this pass-through mode is a form of GPIO and is named |
---|
| 323 | + * as such in the datasheets, e.g. "GPID0". This naming similarity |
---|
| 324 | + * trips us up with the simple GPI-prefixed-signal-name scheme |
---|
| 325 | + * discussed above, as the pass-through configuration is not what we |
---|
| 326 | + * want when muxing a pin as GPIO for the GPIO subsystem. |
---|
| 327 | + * |
---|
| 328 | + * On e.g. the AST2400, a pass-through function "GPID0" is grouped on |
---|
| 329 | + * balls A18 and D16, where we have: |
---|
| 330 | + * |
---|
| 331 | + * For ball A18: |
---|
| 332 | + * - expr->signal set to "GPID0IN" |
---|
| 333 | + * - expr->function set to "GPID0" |
---|
| 334 | + * |
---|
| 335 | + * For ball D16: |
---|
| 336 | + * - expr->signal set to "GPID0OUT" |
---|
| 337 | + * - expr->function set to "GPID0" |
---|
| 338 | + * |
---|
| 339 | + * By contrast, the pin-specific GPIO expressions for the same pins are |
---|
| 340 | + * as follows: |
---|
| 341 | + * |
---|
| 342 | + * For ball A18: |
---|
| 343 | + * - expr->signal looks like "GPIOD0" |
---|
| 344 | + * - expr->function looks like "GPIOD0" |
---|
| 345 | + * |
---|
| 346 | + * For ball D16: |
---|
| 347 | + * - expr->signal looks like "GPIOD1" |
---|
| 348 | + * - expr->function looks like "GPIOD1" |
---|
| 349 | + * |
---|
| 350 | + * Testing both the signal _and_ function names gives us the means |
---|
| 351 | + * differentiate the pass-through GPIO pinmux configuration from the |
---|
| 352 | + * pin-specific configuration that the GPIO subsystem is after: An |
---|
| 353 | + * expression is a pin-specific (non-pass-through) GPIO configuration |
---|
| 354 | + * if the signal prefix is "GPI" and the signal name matches the |
---|
| 355 | + * function name. |
---|
467 | 356 | */ |
---|
468 | | - return strncmp(expr->signal, "GPI", 3) == 0; |
---|
| 357 | + return !strncmp(expr->signal, "GPI", 3) && |
---|
| 358 | + !strcmp(expr->signal, expr->function); |
---|
469 | 359 | } |
---|
470 | 360 | |
---|
471 | 361 | static bool aspeed_gpio_in_exprs(const struct aspeed_sig_expr **exprs) |
---|
.. | .. |
---|
487 | 377 | unsigned int offset) |
---|
488 | 378 | { |
---|
489 | 379 | int ret; |
---|
490 | | - const struct aspeed_pinctrl_data *pdata = |
---|
491 | | - pinctrl_dev_get_drvdata(pctldev); |
---|
| 380 | + struct aspeed_pinctrl_data *pdata = pinctrl_dev_get_drvdata(pctldev); |
---|
492 | 381 | const struct aspeed_pin_desc *pdesc = pdata->pins[offset].drv_data; |
---|
493 | 382 | const struct aspeed_sig_expr ***prios, **funcs, *expr; |
---|
494 | 383 | |
---|
.. | .. |
---|
500 | 389 | if (!prios) |
---|
501 | 390 | return -ENXIO; |
---|
502 | 391 | |
---|
| 392 | + pr_debug("Muxing pin %s for GPIO\n", pdesc->name); |
---|
| 393 | + |
---|
503 | 394 | /* Disable any functions of higher priority than GPIO */ |
---|
504 | 395 | while ((funcs = *prios)) { |
---|
505 | 396 | if (aspeed_gpio_in_exprs(funcs)) |
---|
506 | 397 | break; |
---|
507 | 398 | |
---|
508 | | - ret = aspeed_disable_sig(funcs, pdata->maps); |
---|
| 399 | + ret = aspeed_disable_sig(&pdata->pinmux, funcs); |
---|
509 | 400 | if (ret) |
---|
510 | 401 | return ret; |
---|
511 | 402 | |
---|
.. | .. |
---|
529 | 420 | * lowest-priority signal type. As such it has no associated |
---|
530 | 421 | * expression. |
---|
531 | 422 | */ |
---|
532 | | - if (!expr) |
---|
| 423 | + if (!expr) { |
---|
| 424 | + pr_debug("Muxed pin %s as GPIO\n", pdesc->name); |
---|
533 | 425 | return 0; |
---|
| 426 | + } |
---|
534 | 427 | |
---|
535 | 428 | /* |
---|
536 | 429 | * If GPIO is not the lowest priority signal type, assume there is only |
---|
537 | 430 | * one expression defined to enable the GPIO function |
---|
538 | 431 | */ |
---|
539 | | - return aspeed_sig_expr_enable(expr, pdata->maps); |
---|
| 432 | + ret = aspeed_sig_expr_enable(&pdata->pinmux, expr); |
---|
| 433 | + if (ret) |
---|
| 434 | + return ret; |
---|
| 435 | + |
---|
| 436 | + pr_debug("Muxed pin %s as %s\n", pdesc->name, expr->signal); |
---|
| 437 | + |
---|
| 438 | + return 0; |
---|
540 | 439 | } |
---|
541 | 440 | |
---|
542 | 441 | int aspeed_pinctrl_probe(struct platform_device *pdev, |
---|
.. | .. |
---|
552 | 451 | return -ENODEV; |
---|
553 | 452 | } |
---|
554 | 453 | |
---|
555 | | - pdata->maps[ASPEED_IP_SCU] = syscon_node_to_regmap(parent->of_node); |
---|
556 | | - if (IS_ERR(pdata->maps[ASPEED_IP_SCU])) { |
---|
| 454 | + pdata->scu = syscon_node_to_regmap(parent->of_node); |
---|
| 455 | + if (IS_ERR(pdata->scu)) { |
---|
557 | 456 | dev_err(&pdev->dev, "No regmap for syscon pincontroller parent\n"); |
---|
558 | | - return PTR_ERR(pdata->maps[ASPEED_IP_SCU]); |
---|
| 457 | + return PTR_ERR(pdata->scu); |
---|
559 | 458 | } |
---|
| 459 | + |
---|
| 460 | + pdata->pinmux.maps[ASPEED_IP_SCU] = pdata->scu; |
---|
560 | 461 | |
---|
561 | 462 | pctl = pinctrl_register(pdesc, &pdev->dev, pdata); |
---|
562 | 463 | |
---|
.. | .. |
---|
592 | 493 | return NULL; |
---|
593 | 494 | } |
---|
594 | 495 | |
---|
595 | | -/** |
---|
596 | | - * @param: pinconf configuration parameter |
---|
597 | | - * @arg: The supported argument for @param, or -1 if any value is supported |
---|
598 | | - * @val: The register value to write to configure @arg for @param |
---|
599 | | - * |
---|
600 | | - * The map is to be used in conjunction with the configuration array supplied |
---|
601 | | - * by the driver implementation. |
---|
602 | | - */ |
---|
603 | | -struct aspeed_pin_config_map { |
---|
604 | | - enum pin_config_param param; |
---|
605 | | - s32 arg; |
---|
606 | | - u32 val; |
---|
607 | | -}; |
---|
608 | | - |
---|
609 | 496 | enum aspeed_pin_config_map_type { MAP_TYPE_ARG, MAP_TYPE_VAL }; |
---|
610 | 497 | |
---|
611 | | -/* Aspeed consistently both: |
---|
612 | | - * |
---|
613 | | - * 1. Defines "disable bits" for internal pull-downs |
---|
614 | | - * 2. Uses 8mA or 16mA drive strengths |
---|
615 | | - */ |
---|
616 | | -static const struct aspeed_pin_config_map pin_config_map[] = { |
---|
617 | | - { PIN_CONFIG_BIAS_PULL_DOWN, 0, 1 }, |
---|
618 | | - { PIN_CONFIG_BIAS_PULL_DOWN, -1, 0 }, |
---|
619 | | - { PIN_CONFIG_BIAS_DISABLE, -1, 1 }, |
---|
620 | | - { PIN_CONFIG_DRIVE_STRENGTH, 8, 0 }, |
---|
621 | | - { PIN_CONFIG_DRIVE_STRENGTH, 16, 1 }, |
---|
622 | | -}; |
---|
623 | | - |
---|
624 | 498 | static const struct aspeed_pin_config_map *find_pinconf_map( |
---|
| 499 | + const struct aspeed_pinctrl_data *pdata, |
---|
625 | 500 | enum pin_config_param param, |
---|
626 | 501 | enum aspeed_pin_config_map_type type, |
---|
627 | 502 | s64 value) |
---|
628 | 503 | { |
---|
629 | 504 | int i; |
---|
630 | 505 | |
---|
631 | | - for (i = 0; i < ARRAY_SIZE(pin_config_map); i++) { |
---|
| 506 | + for (i = 0; i < pdata->nconfmaps; i++) { |
---|
632 | 507 | const struct aspeed_pin_config_map *elem; |
---|
633 | 508 | bool match; |
---|
634 | 509 | |
---|
635 | | - elem = &pin_config_map[i]; |
---|
| 510 | + elem = &pdata->confmaps[i]; |
---|
636 | 511 | |
---|
637 | 512 | switch (type) { |
---|
638 | 513 | case MAP_TYPE_ARG: |
---|
.. | .. |
---|
666 | 541 | if (!pconf) |
---|
667 | 542 | return -ENOTSUPP; |
---|
668 | 543 | |
---|
669 | | - rc = regmap_read(pdata->maps[ASPEED_IP_SCU], pconf->reg, &val); |
---|
| 544 | + rc = regmap_read(pdata->scu, pconf->reg, &val); |
---|
670 | 545 | if (rc < 0) |
---|
671 | 546 | return rc; |
---|
672 | 547 | |
---|
673 | | - pmap = find_pinconf_map(param, MAP_TYPE_VAL, |
---|
674 | | - (val & BIT(pconf->bit)) >> pconf->bit); |
---|
| 548 | + pmap = find_pinconf_map(pdata, param, MAP_TYPE_VAL, |
---|
| 549 | + (val & pconf->mask) >> __ffs(pconf->mask)); |
---|
675 | 550 | |
---|
676 | 551 | if (!pmap) |
---|
677 | 552 | return -EINVAL; |
---|
.. | .. |
---|
714 | 589 | if (!pconf) |
---|
715 | 590 | return -ENOTSUPP; |
---|
716 | 591 | |
---|
717 | | - pmap = find_pinconf_map(param, MAP_TYPE_ARG, arg); |
---|
| 592 | + pmap = find_pinconf_map(pdata, param, MAP_TYPE_ARG, arg); |
---|
718 | 593 | |
---|
719 | | - if (unlikely(WARN_ON(!pmap))) |
---|
| 594 | + if (WARN_ON(!pmap)) |
---|
720 | 595 | return -EINVAL; |
---|
721 | 596 | |
---|
722 | | - val = pmap->val << pconf->bit; |
---|
| 597 | + val = pmap->val << __ffs(pconf->mask); |
---|
723 | 598 | |
---|
724 | | - rc = regmap_update_bits(pdata->maps[ASPEED_IP_SCU], pconf->reg, |
---|
725 | | - BIT(pconf->bit), val); |
---|
| 599 | + rc = regmap_update_bits(pdata->scu, pconf->reg, |
---|
| 600 | + pconf->mask, val); |
---|
726 | 601 | |
---|
727 | 602 | if (rc < 0) |
---|
728 | 603 | return rc; |
---|
729 | 604 | |
---|
730 | | - pr_debug("%s: Set SCU%02X[%d]=%d for param %d(=%d) on pin %d\n", |
---|
731 | | - __func__, pconf->reg, pconf->bit, pmap->val, |
---|
732 | | - param, arg, offset); |
---|
| 605 | + pr_debug("%s: Set SCU%02X[0x%08X]=0x%X for param %d(=%d) on pin %d\n", |
---|
| 606 | + __func__, pconf->reg, pconf->mask, |
---|
| 607 | + val, param, arg, offset); |
---|
733 | 608 | } |
---|
734 | 609 | |
---|
735 | 610 | return 0; |
---|