![]() |
|
|||
0001 // SPDX-License-Identifier: GPL-2.0-or-later 0002 /* Copyright (C) 2019 IBM Corp. */ 0003 0004 /* Pieces to enable drivers to implement the .set callback */ 0005 0006 #include "pinmux-aspeed.h" 0007 0008 static const char *const aspeed_pinmux_ips[] = { 0009 [ASPEED_IP_SCU] = "SCU", 0010 [ASPEED_IP_GFX] = "GFX", 0011 [ASPEED_IP_LPC] = "LPC", 0012 }; 0013 0014 static inline void aspeed_sig_desc_print_val( 0015 const struct aspeed_sig_desc *desc, bool enable, u32 rv) 0016 { 0017 pr_debug("Want %s%X[0x%08X]=0x%X, got 0x%X from 0x%08X\n", 0018 aspeed_pinmux_ips[desc->ip], desc->reg, 0019 desc->mask, enable ? desc->enable : desc->disable, 0020 (rv & desc->mask) >> __ffs(desc->mask), rv); 0021 } 0022 0023 /** 0024 * aspeed_sig_desc_eval() - Query the enabled or disabled state of a signal 0025 * descriptor. 0026 * 0027 * @desc: The signal descriptor of interest 0028 * @enabled: True to query the enabled state, false to query disabled state 0029 * @map: The IP block's regmap instance 0030 * 0031 * Return: 1 if the descriptor's bitfield is configured to the state 0032 * selected by @enabled, 0 if not, and less than zero if an unrecoverable 0033 * failure occurred 0034 * 0035 * Evaluation of descriptor state is non-trivial in that it is not a binary 0036 * outcome: The bitfields can be greater than one bit in size and thus can take 0037 * a value that is neither the enabled nor disabled state recorded in the 0038 * descriptor (typically this means a different function to the one of interest 0039 * is enabled). Thus we must explicitly test for either condition as required. 0040 */ 0041 int aspeed_sig_desc_eval(const struct aspeed_sig_desc *desc, 0042 bool enabled, struct regmap *map) 0043 { 0044 int ret; 0045 unsigned int raw; 0046 u32 want; 0047 0048 if (!map) 0049 return -ENODEV; 0050 0051 ret = regmap_read(map, desc->reg, &raw); 0052 if (ret) 0053 return ret; 0054 0055 aspeed_sig_desc_print_val(desc, enabled, raw); 0056 want = enabled ? desc->enable : desc->disable; 0057 0058 return ((raw & desc->mask) >> __ffs(desc->mask)) == want; 0059 } 0060 0061 /** 0062 * aspeed_sig_expr_eval - Query the enabled or disabled state for a 0063 * mux function's signal on a pin 0064 * 0065 * @ctx: The driver context for the pinctrl IP 0066 * @expr: An expression controlling the signal for a mux function on a pin 0067 * @enabled: True to query the enabled state, false to query disabled state 0068 * 0069 * Return: 1 if the expression composed by @enabled evaluates true, 0 if not, 0070 * and less than zero if an unrecoverable failure occurred. 0071 * 0072 * A mux function is enabled or disabled if the function's signal expression 0073 * for each pin in the function's pin group evaluates true for the desired 0074 * state. An signal expression evaluates true if all of its associated signal 0075 * descriptors evaluate true for the desired state. 0076 * 0077 * If an expression's state is described by more than one bit, either through 0078 * multi-bit bitfields in a single signal descriptor or through multiple signal 0079 * descriptors of a single bit then it is possible for the expression to be in 0080 * neither the enabled nor disabled state. Thus we must explicitly test for 0081 * either condition as required. 0082 */ 0083 int aspeed_sig_expr_eval(struct aspeed_pinmux_data *ctx, 0084 const struct aspeed_sig_expr *expr, bool enabled) 0085 { 0086 int ret; 0087 int i; 0088 0089 if (ctx->ops->eval) 0090 return ctx->ops->eval(ctx, expr, enabled); 0091 0092 for (i = 0; i < expr->ndescs; i++) { 0093 const struct aspeed_sig_desc *desc = &expr->descs[i]; 0094 0095 ret = aspeed_sig_desc_eval(desc, enabled, ctx->maps[desc->ip]); 0096 if (ret <= 0) 0097 return ret; 0098 } 0099 0100 return 1; 0101 }
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |