Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pinctrl: allow to mark pin functions as requestable GPIOs

The name of the pin function has no real meaning to pinctrl core and is
there only for human readability of device properties. Some pins are
muxed as GPIOs but for "strict" pinmuxers it's impossible to request
them as GPIOs if they're bound to a devide - even if their function name
explicitly says "gpio". Add a new field to struct pinfunction that
allows to pass additional flags to pinctrl core. While we could go with
a boolean "is_gpio" field, a flags field is more future-proof.

If the PINFUNCTION_FLAG_GPIO is set for a given function, the pin muxed
to it can be requested as GPIO even on strict pin controllers. Add a new
callback to struct pinmux_ops - function_is_gpio() - that allows pinmux
core to inspect a function and see if it's a GPIO one. Provide a generic
implementation of this callback.

Tested-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

authored by

Bartosz Golaszewski and committed by
Linus Walleij
11aa02d6 6f6835be

+62 -3
+43 -3
drivers/pinctrl/pinmux.c
··· 89 89 { 90 90 struct pin_desc *desc = pin_desc_get(pctldev, pin); 91 91 const struct pinmux_ops *ops = pctldev->desc->pmxops; 92 + const struct pinctrl_setting_mux *mux_setting; 93 + bool func_is_gpio = false; 92 94 93 95 /* Can't inspect pin, assume it can be used */ 94 96 if (!desc || !ops) 95 97 return true; 96 98 99 + mux_setting = desc->mux_setting; 100 + 97 101 guard(mutex)(&desc->mux_lock); 98 - if (ops->strict && desc->mux_usecount) 102 + if (mux_setting && ops->function_is_gpio) 103 + func_is_gpio = ops->function_is_gpio(pctldev, mux_setting->func); 104 + 105 + if (ops->strict && desc->mux_usecount && !func_is_gpio) 99 106 return false; 100 107 101 108 return !(ops->strict && !!desc->gpio_owner); ··· 123 116 { 124 117 struct pin_desc *desc; 125 118 const struct pinmux_ops *ops = pctldev->desc->pmxops; 119 + const struct pinctrl_setting_mux *mux_setting; 126 120 int status = -EINVAL; 121 + bool gpio_ok = false; 127 122 128 123 desc = pin_desc_get(pctldev, pin); 129 124 if (desc == NULL) { ··· 135 126 goto out; 136 127 } 137 128 129 + mux_setting = desc->mux_setting; 130 + 138 131 dev_dbg(pctldev->dev, "request pin %d (%s) for %s\n", 139 132 pin, desc->name, owner); 140 133 141 134 scoped_guard(mutex, &desc->mux_lock) { 142 - if ((!gpio_range || ops->strict) && 135 + if (mux_setting) { 136 + if (ops->function_is_gpio) 137 + gpio_ok = ops->function_is_gpio(pctldev, 138 + mux_setting->func); 139 + } else { 140 + gpio_ok = true; 141 + } 142 + 143 + if ((!gpio_range || ops->strict) && !gpio_ok && 143 144 desc->mux_usecount && strcmp(desc->mux_owner, owner)) { 144 145 dev_err(pctldev->dev, 145 146 "pin %s already requested by %s; cannot claim for %s\n", ··· 157 138 goto out; 158 139 } 159 140 160 - if ((gpio_range || ops->strict) && desc->gpio_owner) { 141 + if ((gpio_range || ops->strict) && !gpio_ok && desc->gpio_owner) { 161 142 dev_err(pctldev->dev, 162 143 "pin %s already requested by %s; cannot claim for %s\n", 163 144 desc->name, desc->gpio_owner, owner); ··· 879 860 return function; 880 861 } 881 862 EXPORT_SYMBOL_GPL(pinmux_generic_get_function); 863 + 864 + /** 865 + * pinmux_generic_function_is_gpio() - returns true if given function is a GPIO 866 + * @pctldev: pin controller device 867 + * @selector: function number 868 + * 869 + * Returns: 870 + * True if given function is a GPIO, false otherwise. 871 + */ 872 + bool pinmux_generic_function_is_gpio(struct pinctrl_dev *pctldev, 873 + unsigned int selector) 874 + { 875 + struct function_desc *function; 876 + 877 + function = radix_tree_lookup(&pctldev->pin_function_tree, selector); 878 + if (!function) 879 + return false; 880 + 881 + return function->func->flags & PINFUNCTION_FLAG_GPIO; 882 + } 883 + EXPORT_SYMBOL_GPL(pinmux_generic_function_is_gpio); 882 884 883 885 /** 884 886 * pinmux_generic_add_function() - adds a function group
+3
drivers/pinctrl/pinmux.h
··· 169 169 170 170 void pinmux_generic_free_functions(struct pinctrl_dev *pctldev); 171 171 172 + bool pinmux_generic_function_is_gpio(struct pinctrl_dev *pctldev, 173 + unsigned int selector); 174 + 172 175 #else 173 176 174 177 static inline void pinmux_generic_free_functions(struct pinctrl_dev *pctldev)
+14
include/linux/pinctrl/pinctrl.h
··· 11 11 #ifndef __LINUX_PINCTRL_PINCTRL_H 12 12 #define __LINUX_PINCTRL_PINCTRL_H 13 13 14 + #include <linux/bits.h> 14 15 #include <linux/types.h> 15 16 16 17 struct device; ··· 207 206 const char *pin_group, const unsigned int **pins, 208 207 unsigned int *num_pins); 209 208 209 + #define PINFUNCTION_FLAG_GPIO BIT(0) 210 + 210 211 /** 211 212 * struct pinfunction - Description about a function 212 213 * @name: Name of the function 213 214 * @groups: An array of groups for this function 214 215 * @ngroups: Number of groups in @groups 216 + * @flags: Additional pin function flags 215 217 */ 216 218 struct pinfunction { 217 219 const char *name; 218 220 const char * const *groups; 219 221 size_t ngroups; 222 + unsigned long flags; 220 223 }; 221 224 222 225 /* Convenience macro to define a single named pinfunction */ ··· 229 224 .name = (_name), \ 230 225 .groups = (_groups), \ 231 226 .ngroups = (_ngroups), \ 227 + } 228 + 229 + /* Same as PINCTRL_PINFUNCTION() but for the GPIO category of functions */ 230 + #define PINCTRL_GPIO_PINFUNCTION(_name, _groups, _ngroups) \ 231 + (struct pinfunction) { \ 232 + .name = (_name), \ 233 + .groups = (_groups), \ 234 + .ngroups = (_ngroups), \ 235 + .flags = PINFUNCTION_FLAG_GPIO, \ 232 236 } 233 237 234 238 #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL)
+2
include/linux/pinctrl/pinmux.h
··· 66 66 unsigned int selector, 67 67 const char * const **groups, 68 68 unsigned int *num_groups); 69 + bool (*function_is_gpio) (struct pinctrl_dev *pctldev, 70 + unsigned int selector); 69 71 int (*set_mux) (struct pinctrl_dev *pctldev, unsigned int func_selector, 70 72 unsigned int group_selector); 71 73 int (*gpio_request_enable) (struct pinctrl_dev *pctldev,