/** * pinctrl_group_name_to_selector() - return the group selector for a group * * @dev: pin controller device * @group: the pin group name to look up * @return: pin group selector, or negative error code on failure */ static int pinctrl_group_name_to_selector(struct udevice *dev, const char *group) { const struct pinctrl_ops *ops = pinctrl_get_ops(dev); unsigned ngroups, selector; if (!ops->get_groups_count || !ops->get_group_name) { dev_dbg(dev, "get_groups_count or get_group_name missing\n"); return -ENOSYS; } ngroups = ops->get_groups_count(dev); /* See if this pctldev has this group */ for (selector = 0; selector < ngroups; selector++) { const char *gname = ops->get_group_name(dev, selector); if (!strcmp(group, gname)) return selector; } return -ENOSYS; }
/** * pinctrl_select_state_simple() - simple implementation of pinctrl_select_state * * @dev: peripheral device * @return: 0 on success, or negative error code on failure */ static int pinctrl_select_state_simple(struct udevice *dev) { struct udevice *pctldev; struct pinctrl_ops *ops; int ret; /* * For simplicity, assume the first device of PINCTRL uclass * is the correct one. This is most likely OK as there is * usually only one pinctrl device on the system. */ ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev); if (ret) return ret; ops = pinctrl_get_ops(pctldev); if (!ops->set_state_simple) { dev_dbg(dev, "set_state_simple op missing\n"); return -ENOSYS; } return ops->set_state_simple(pctldev, dev); }
/** * pinmux_func_name_to_selector() - return the function selector for a function * * @dev: pin controller device * @function: the function name to look up * @return: function selector, or negative error code on failure */ static int pinmux_func_name_to_selector(struct udevice *dev, const char *function) { const struct pinctrl_ops *ops = pinctrl_get_ops(dev); unsigned nfuncs, selector = 0; if (!ops->get_functions_count || !ops->get_function_name) { dev_dbg(dev, "get_functions_count or get_function_name missing\n"); return -ENOSYS; } nfuncs = ops->get_functions_count(dev); /* See if this pctldev has this function */ for (selector = 0; selector < nfuncs; selector++) { const char *fname = ops->get_function_name(dev, selector); if (!strcmp(function, fname)) return selector; } return -ENOSYS; }
/** * pinconf_prop_name_to_param() - return parameter ID for a property name * * @dev: pin controller device * @property: property name in DTS, such as "bias-pull-up", "slew-rate", etc. * @default_value: return default value in case no value is specified in DTS * @return: return pamater ID, or negative error code on failure */ static int pinconf_prop_name_to_param(struct udevice *dev, const char *property, u32 *default_value) { const struct pinctrl_ops *ops = pinctrl_get_ops(dev); const struct pinconf_param *p, *end; if (!ops->pinconf_num_params || !ops->pinconf_params) { dev_dbg(dev, "pinconf_num_params or pinconf_params missing\n"); return -ENOSYS; } p = ops->pinconf_params; end = p + ops->pinconf_num_params; /* See if this pctldev supports this parameter */ for (; p < end; p++) { if (!strcmp(property, p->property)) { *default_value = p->default_value; return p->param; } } return -ENOSYS; }