Skip to content

Commit 96b76f7

Browse files
AKASHI Takahirolinusw
authored andcommitted
pinctrl: introduce pinctrl_gpio_get_config()
This is a counterpart of pinctrl_gpio_set_config(), which will be used to implement the ->get() interface in a GPIO driver for SCMI. This also requires that we create a stub so pin_config_get_for_pin() can build when CONFIG_PINCONF is disabled. Signed-off-by: AKASHI Takahiro <takahiro.akashi@linaro.org> Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Reviewed-by: Linus Walleij <linusw@kernel.org> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Linus Walleij <linusw@kernel.org>
1 parent 6de23f8 commit 96b76f7

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

drivers/pinctrl/core.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <linux/pinctrl/consumer.h>
3131
#include <linux/pinctrl/devinfo.h>
3232
#include <linux/pinctrl/machine.h>
33+
#include <linux/pinctrl/pinconf.h>
3334
#include <linux/pinctrl/pinctrl.h>
3435

3536
#include "core.h"
@@ -938,6 +939,36 @@ int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
938939
}
939940
EXPORT_SYMBOL_GPL(pinctrl_gpio_set_config);
940941

942+
/**
943+
* pinctrl_gpio_get_config() - Get the config for a given GPIO pin
944+
* @gc: GPIO chip structure from the GPIO subsystem
945+
* @offset: hardware offset of the GPIO relative to the controller
946+
* @config: the configuration to query. On success it holds the result
947+
* Return: 0 on success, negative errno otherwise
948+
*/
949+
int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset, unsigned long *config)
950+
{
951+
struct pinctrl_gpio_range *range;
952+
struct pinctrl_dev *pctldev;
953+
int ret, pin;
954+
955+
ret = pinctrl_get_device_gpio_range(gc, offset, &pctldev, &range);
956+
if (ret)
957+
return ret;
958+
959+
mutex_lock(&pctldev->mutex);
960+
pin = gpio_to_pin(range, gc, offset);
961+
ret = pin_config_get_for_pin(pctldev, pin, config);
962+
mutex_unlock(&pctldev->mutex);
963+
964+
if (ret)
965+
return ret;
966+
967+
*config = pinconf_to_config_argument(*config);
968+
return 0;
969+
}
970+
EXPORT_SYMBOL_GPL(pinctrl_gpio_get_config);
971+
941972
static struct pinctrl_state *find_state(struct pinctrl *p,
942973
const char *name)
943974
{

drivers/pinctrl/pinconf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ static inline int pinconf_set_config(struct pinctrl_dev *pctldev, unsigned int p
7474
return -ENOTSUPP;
7575
}
7676

77+
static inline int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned int pin,
78+
unsigned long *config)
79+
{
80+
return -ENOTSUPP;
81+
}
82+
7783
#endif
7884

7985
#if defined(CONFIG_PINCONF) && defined(CONFIG_DEBUG_FS)

include/linux/pinctrl/consumer.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ int pinctrl_gpio_direction_output(struct gpio_chip *gc,
3535
unsigned int offset);
3636
int pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
3737
unsigned long config);
38+
int pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset,
39+
unsigned long *config);
3840

3941
struct pinctrl * __must_check pinctrl_get(struct device *dev);
4042
void pinctrl_put(struct pinctrl *p);
@@ -101,6 +103,13 @@ pinctrl_gpio_direction_output(struct gpio_chip *gc, unsigned int offset)
101103
return 0;
102104
}
103105

106+
static inline int
107+
pinctrl_gpio_get_config(struct gpio_chip *gc, unsigned int offset,
108+
unsigned long *config)
109+
{
110+
return 0;
111+
}
112+
104113
static inline int
105114
pinctrl_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
106115
unsigned long config)

0 commit comments

Comments
 (0)