[RFC,2/4] pinctrl: add pinctrl_gpio_get_config()
Commit Message
This is a counterpart of pinctrl_gpio_set_config(), which will initially
be used to implement gpio_get interface in SCMI pinctrl based GPIO driver.
Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
---
drivers/pinctrl/core.c | 19 +++++++++++++++++++
include/linux/pinctrl/consumer.h | 8 ++++++++
2 files changed, 27 insertions(+)
Comments
On Mon, Oct 2, 2023 at 4:17 AM AKASHI Takahiro
<takahiro.akashi@linaro.org> wrote:
> This is a counterpart of pinctrl_gpio_set_config(), which will initially
> be used to implement gpio_get interface in SCMI pinctrl based GPIO driver.
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org>
Makes perfect sense for what you are trying to do.
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Yours,
Linus Walleij
@@ -926,6 +926,25 @@ int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
}
EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
+int pinctrl_gpio_get_config(unsigned int gpio, unsigned long *config)
+{
+ struct pinctrl_gpio_range *range;
+ struct pinctrl_dev *pctldev;
+ int ret, pin;
+
+ ret = pinctrl_get_device_gpio_range(gpio, &pctldev, &range);
+ if (ret)
+ return ret;
+
+ mutex_lock(&pctldev->mutex);
+ pin = gpio_to_pin(range, gpio);
+ ret = pin_config_get_for_pin(pctldev, pin, config);
+ mutex_unlock(&pctldev->mutex);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(pinctrl_gpio_get_config);
+
static struct pinctrl_state *find_state(struct pinctrl *p,
const char *name)
{
@@ -31,6 +31,8 @@ extern void pinctrl_gpio_free(unsigned gpio);
extern int pinctrl_gpio_direction_input(unsigned gpio);
extern int pinctrl_gpio_direction_output(unsigned gpio);
extern int pinctrl_gpio_set_config(unsigned gpio, unsigned long config);
+extern int pinctrl_gpio_get_config(unsigned int gpio,
+ unsigned long *config);
extern struct pinctrl * __must_check pinctrl_get(struct device *dev);
extern void pinctrl_put(struct pinctrl *p);
@@ -92,6 +94,12 @@ static inline int pinctrl_gpio_set_config(unsigned gpio, unsigned long config)
return 0;
}
+static inline int pinctrl_gpio_get_config(unsigned int gpio,
+ unsigned long *config)
+{
+ return 0;
+}
+
static inline struct pinctrl * __must_check pinctrl_get(struct device *dev)
{
return NULL;