Re: [PATCH v6 5/8] gpio: regmap: Add gpio_regmap_operation and value_xlate support
From: Michael Walle
Date: Tue Jul 21 2026 - 03:15:43 EST
Hi
Thanks! Looks very good, a few comments below.
On Tue Jul 21, 2026 at 8:57 AM CEST, Yu-Chun Lin wrote:
> Extend the reg_mask_xlate callback with an operation type parameter
> (enum gpio_regmap_operation) to allow drivers to return different
> register/mask combinations depending on the specific GPIO operation.
>
> In addition, introduce a new optional 'value_xlate' callback. This routine
> allows drivers to translate or modify the register value and mask
> immediately before a write operation. It is particularly useful for
> hardware that requires additional control bits, such as a write-enable bit,
> to be appended to the data dynamically.
Please split that into two patches.
> Consequently, update all existing drivers utilizing the gpio-regmap
> framework (across drivers/gpio, drivers/iio, and drivers/pinctrl)
> to accommodate the new reg_mask_xlate function signature.
>
> Suggested-by: Linus Walleij <linusw@xxxxxxxxxx>
> Signed-off-by: Yu-Chun Lin <eleanor.lin@xxxxxxxxxxx>
> ---
> Changes in v6:
> - Remove removed the hardcoded write-enable workarounds.
> - Retain the necessary prototype updates in every driver using custom
> reg_mask_xlate
> - Add value_xlate to dynamically adjust the register mask and value right
> before the actual register write operation.
> ---
> drivers/gpio/gpio-104-idi-48.c | 7 +--
> drivers/gpio/gpio-i8255.c | 4 +-
> drivers/gpio/gpio-idio-16.c | 6 +--
> drivers/gpio/gpio-max7360.c | 1 +
> drivers/gpio/gpio-pcie-idio-24.c | 6 +--
> drivers/gpio/gpio-regmap.c | 62 ++++++++++++++++++++++-----
> drivers/iio/adc/ad7173.c | 8 ++--
> drivers/iio/addac/stx104.c | 6 +--
> drivers/pinctrl/bcm/pinctrl-bcm63xx.c | 1 +
> drivers/pinctrl/pinctrl-tps6594.c | 1 +
> include/linux/gpio/regmap.h | 44 +++++++++++++++++--
> 11 files changed, 115 insertions(+), 31 deletions(-)
>
..
> diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
> index a3ba8242c353..45a30f50043f 100644
> --- a/include/linux/gpio/regmap.h
> +++ b/include/linux/gpio/regmap.h
> @@ -13,6 +13,36 @@ struct regmap;
> #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
> #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
>
> +/**
> + * enum gpio_regmap_operation - Operation type for reg_mask_xlate callback
> + *
> + * This enum is used to distinguish between different types of GPIO operations
> + * so that the reg_mask_xlate callback can return the appropriate mask for each
> + * operation type.
"Traditionally it was inferred from the base regsister. But that
might not always work, for example if all the control bits of one
GPIO lives in the same register. The user is free to choose which
method they'll use."
> + *
> + * Value operations:
> + * @GPIO_REGMAP_GET_OP: Mask for reading direction to detect if GPIO is input or output.
> + * Used in gpio_regmap_get() to determine the GPIO direction.
> + * @GPIO_REGMAP_IN: Mask for reading input value. Used when GPIO is configured as input.
> + * @GPIO_REGMAP_OUT: Mask for reading output value. Used when GPIO is configured as output.
> + *
> + * Output operations:
> + * @GPIO_REGMAP_SET_OP: Mask for setting GPIO output value.
> + *
> + * Direction operations:
> + * @GPIO_REGMAP_GET_DIR_OP: Mask for reading GPIO direction (input/output).
> + * @GPIO_REGMAP_SET_DIR_OP: Mask for setting GPIO direction (input/output).
> + *
> + */
> +enum gpio_regmap_operation {
> + GPIO_REGMAP_GET_OP,
> + GPIO_REGMAP_SET_OP,
> + GPIO_REGMAP_GET_DIR_OP,
> + GPIO_REGMAP_SET_DIR_OP,
> + GPIO_REGMAP_IN,
> + GPIO_REGMAP_OUT,
> +};
> +
> /**
> * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
> * @parent: The parent device
> @@ -55,6 +85,10 @@ struct regmap;
> * is used.
> * @init_valid_mask: (Optional) Routine to initialize @valid_mask, to be used
> * if not all GPIOs are valid.
> + * @value_xlate: (Optional) Routine to translate the register value and
> + * mask before writing. This allows driver-specific logic
> + * to append additional bits (like write-enable masks)
> + * dynamically based on the current operation.
> * @drvdata: (Optional) Pointer to driver specific data which is
> * not used by gpio-remap but is provided "as is" to the
> * driver callback(s).
> @@ -104,14 +138,18 @@ struct gpio_regmap_config {
> unsigned long regmap_irq_flags;
> #endif
>
> - int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
> - unsigned int offset, unsigned int *reg,
> - unsigned int *mask);
> + int (*reg_mask_xlate)(struct gpio_regmap *gpio, enum gpio_regmap_operation,
> + unsigned int base, unsigned int offset,
> + unsigned int *reg, unsigned int *mask);
>
> int (*init_valid_mask)(struct gpio_chip *gc,
> unsigned long *valid_mask,
> unsigned int ngpios);
>
> + int (*value_xlate)(struct gpio_regmap *gpio, enum gpio_regmap_operation,
> + unsigned int base, unsigned int offset, unsigned int reg,
> + unsigned int *mask, unsigned int *val);
> +
> void *drvdata;
> };
>
Attachment:
signature.asc
Description: PGP signature