^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Copyright (C) 2019 IBM Corp. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) /* Pieces to enable drivers to implement the .set callback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #include "pinmux-aspeed.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) static const char *const aspeed_pinmux_ips[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) [ASPEED_IP_SCU] = "SCU",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) [ASPEED_IP_GFX] = "GFX",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) [ASPEED_IP_LPC] = "LPC",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) static inline void aspeed_sig_desc_print_val(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) const struct aspeed_sig_desc *desc, bool enable, u32 rv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) pr_debug("Want %s%X[0x%08X]=0x%X, got 0x%X from 0x%08X\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) aspeed_pinmux_ips[desc->ip], desc->reg,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) desc->mask, enable ? desc->enable : desc->disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) (rv & desc->mask) >> __ffs(desc->mask), rv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * Query the enabled or disabled state of a signal descriptor
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * @desc: The signal descriptor of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @enabled: True to query the enabled state, false to query disabled state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @map: The IP block's regmap instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Return: 1 if the descriptor's bitfield is configured to the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * selected by @enabled, 0 if not, and less than zero if an unrecoverable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * failure occurred
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * Evaluation of descriptor state is non-trivial in that it is not a binary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * outcome: The bitfields can be greater than one bit in size and thus can take
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * a value that is neither the enabled nor disabled state recorded in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * descriptor (typically this means a different function to the one of interest
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * is enabled). Thus we must explicitly test for either condition as required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int aspeed_sig_desc_eval(const struct aspeed_sig_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool enabled, struct regmap *map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) unsigned int raw;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) u32 want;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (!map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ret = regmap_read(map, desc->reg, &raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) aspeed_sig_desc_print_val(desc, enabled, raw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) want = enabled ? desc->enable : desc->disable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return ((raw & desc->mask) >> __ffs(desc->mask)) == want;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * Query the enabled or disabled state for a mux function's signal on a pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * @ctx: The driver context for the pinctrl IP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) * @expr: An expression controlling the signal for a mux function on a pin
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * @enabled: True to query the enabled state, false to query disabled state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) * Return: 1 if the expression composed by @enabled evaluates true, 0 if not,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) * and less than zero if an unrecoverable failure occurred.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * A mux function is enabled or disabled if the function's signal expression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) * for each pin in the function's pin group evaluates true for the desired
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * state. An signal expression evaluates true if all of its associated signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * descriptors evaluate true for the desired state.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * If an expression's state is described by more than one bit, either through
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) * multi-bit bitfields in a single signal descriptor or through multiple signal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * descriptors of a single bit then it is possible for the expression to be in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * neither the enabled nor disabled state. Thus we must explicitly test for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * either condition as required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) int aspeed_sig_expr_eval(struct aspeed_pinmux_data *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) const struct aspeed_sig_expr *expr, bool enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (ctx->ops->eval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return ctx->ops->eval(ctx, expr, enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) for (i = 0; i < expr->ndescs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) const struct aspeed_sig_desc *desc = &expr->descs[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) ret = aspeed_sig_desc_eval(desc, enabled, ctx->maps[desc->ip]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) if (ret <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }