[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <DB7M5DTXEACR.3N7DO1DM0PZB1@kernel.org>
Date: Wed, 09 Jul 2025 17:01:38 +0200
From: "Michael Walle" <mwalle@...nel.org>
To: "Ioana Ciornei" <ioana.ciornei@....com>, <devicetree@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <linux-gpio@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>
Cc: "Rob Herring" <robh@...nel.org>, "Krzysztof Kozlowski"
<krzk+dt@...nel.org>, "Conor Dooley" <conor+dt@...nel.org>, "Linus Walleij"
<linus.walleij@...aro.org>, "Bartosz Golaszewski" <brgl@...ev.pl>, "Shawn
Guo" <shawnguo@...nel.org>, "Lee Jones" <lee@...nel.org>, "Frank Li"
<Frank.Li@....com>
Subject: Re: [PATCH 4/9] gpio: regmap: add the .get_direction() callback
Hi Ioana,
great to see another user of gpio-regmap.
On Wed Jul 9, 2025 at 1:26 PM CEST, Ioana Ciornei wrote:
> There are GPIO controllers such as the one present in the LX2160ARDB
> QIXIS CPLD which are single register fixed-direction. This cannot be
> modeled using the gpio-regmap as-is since there is no way to
> present the true direction of a GPIO line.
You mean input and output mixed together in one register? At least
to me, that wasn't so obvious by the commit message, I had to look
at the actual driver.
> In order to make this use case possible, add a new callback to the
> gpio_config structure - .get_direction() - which can be used by user
> drivers to provide the fixed direction per GPIO line.
>
> Signed-off-by: Ioana Ciornei <ioana.ciornei@....com>
> ---
> drivers/gpio/gpio-regmap.c | 17 ++++++++++++++++-
> include/linux/gpio/regmap.h | 3 +++
> 2 files changed, 19 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> index 87c4225784cf..dac2acb26655 100644
> --- a/drivers/gpio/gpio-regmap.c
> +++ b/drivers/gpio/gpio-regmap.c
> @@ -32,6 +32,8 @@ struct gpio_regmap {
> unsigned int reg_dir_in_base;
> unsigned int reg_dir_out_base;
>
> + int (*get_direction)(struct gpio_regmap *gpio, unsigned int offset);
> +
> int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
> unsigned int offset, unsigned int *reg,
> unsigned int *mask);
> @@ -129,6 +131,9 @@ static int gpio_regmap_get_direction(struct gpio_chip *chip,
> unsigned int base, val, reg, mask;
> int invert, ret;
>
> + if (gpio->get_direction)
> + return gpio->get_direction(gpio, offset);
> +
> if (gpio->reg_dat_base && !gpio->reg_set_base)
> return GPIO_LINE_DIRECTION_IN;
> if (gpio->reg_set_base && !gpio->reg_dat_base)
> @@ -163,7 +168,16 @@ static int gpio_regmap_set_direction(struct gpio_chip *chip,
> {
> struct gpio_regmap *gpio = gpiochip_get_data(chip);
> unsigned int base, val, reg, mask;
> - int invert, ret;
> + int invert, ret, dir;
> +
> + if (gpio->get_direction) {
> + dir = gpio->get_direction(gpio, offset);
> + if (dir == GPIO_LINE_DIRECTION_IN && output)
> + return -EOPNOTSUPP;
> + if (dir == GPIO_LINE_DIRECTION_OUT && !output)
> + return -EOPNOTSUPP;
> + return 0;
> + }
What is the intention here? Shouldn't there be just a .set_direction
op and if there isn't one, return EOPNOTSUPP?
In any case, that is unused code for your driver as far as I see,
because you neither set .reg_dir_in_base nor .reg_dir_out_base and
thus, .direction_input nor .direction_output are set within the
gpio_chip struct (see gpio_regmap_register()).
> if (gpio->reg_dir_out_base) {
> base = gpio_regmap_addr(gpio->reg_dir_out_base);
> @@ -247,6 +261,7 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
> gpio->reg_clr_base = config->reg_clr_base;
> gpio->reg_dir_in_base = config->reg_dir_in_base;
> gpio->reg_dir_out_base = config->reg_dir_out_base;
> + gpio->get_direction = config->get_direction;
>
> chip = &gpio->gpio_chip;
> chip->parent = config->parent;
> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
> index c722c67668c6..99fd973e61fa 100644
> --- a/include/linux/gpio/regmap.h
> +++ b/include/linux/gpio/regmap.h
> @@ -37,6 +37,8 @@ struct regmap;
> * offset to a register/bitmask pair. If not
> * given the default gpio_regmap_simple_xlate()
> * is used.
> + * @get_direction: (Optional) Callback to the user driver to return the
> + * fixed direction of the GPIO line
> * @drvdata: (Optional) Pointer to driver specific data which is
> * not used by gpio-remap but is provided "as is" to the
> * driver callback(s).
> @@ -81,6 +83,7 @@ struct gpio_regmap_config {
> int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
> unsigned int offset, unsigned int *reg,
> unsigned int *mask);
> + int (*get_direction)(struct gpio_regmap *gpio, unsigned int offset);
>
> void *drvdata;
> };
Powered by blists - more mailing lists