From: "Yu-Chun Lin [林祐君]" <eleanor.lin@realtek.com>
To: Jonathan Cameron <jic23@kernel.org>,
"linusw@kernel.org" <linusw@kernel.org>
Cc: "brgl@kernel.org" <brgl@kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"afaerber@suse.com" <afaerber@suse.com>,
"wbg@kernel.org" <wbg@kernel.org>,
"mathieu.dubois-briand@bootlin.com"
<mathieu.dubois-briand@bootlin.com>,
"mwalle@kernel.org" <mwalle@kernel.org>,
"lars@metafoo.de" <lars@metafoo.de>,
"Michael.Hennerich@analog.com" <Michael.Hennerich@analog.com>,
"nuno.sa@analog.com" <nuno.sa@analog.com>,
"andy@kernel.org" <andy@kernel.org>,
"dlechner@baylibre.com" <dlechner@baylibre.com>,
"TY_Chang[張子逸]" <tychang@realtek.com>,
"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>,
"linux-realtek-soc@lists.infradead.org"
<linux-realtek-soc@lists.infradead.org>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"CY_Huang[黃鉦晏]" <cy.huang@realtek.com>,
"Stanley Chang[昌育德]" <stanley_chang@realtek.com>,
"James Tai [戴志峰]" <james.tai@realtek.com>,
"Linus Walleij" <linus.walleij@linaro.org>
Subject: RE: [PATCH v3 3/7] gpio: regmap: Add gpio_regmap_operation and write-enable support
Date: Thu, 9 Jul 2026 17:21:09 +0000 [thread overview]
Message-ID: <d301ba0cd45d49d59e6a014188306ec9@realtek.com> (raw)
In-Reply-To: <20260512153745.3ec68675@jic23-huawei>
Hi Jonathan and Linus,
It's been a while since this thread, sorry for the delay.
I abandoned the v4/v5 approaches and decided to go back to the v3 design,
so I am returning here to fix the problems you pointed out back then.
> On Tue, 12 May 2026 11:33:13 +0800
> Yu-Chun Lin <eleanor.lin@realtek.com> wrote:
>
> > Extend the reg_mask_xlate callback with an operation type parameter
> > (gpio_regmap_operation) to allow drivers to return different
> > register/mask combinations for different GPIO operations.
> >
> > Also add write-enable mechanism for hardware that requires setting a
> > write-enable bit before modifying GPIO control registers.
> >
> > 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.
>
> What is the reasoning behind setting *mask = 0 for unsupported operations?
> If it is a special value why not just return an error code to indicate not
> supported? This seems to come from the assumption that you will want to |
> that with masks for another operation.
>
> I'm coming into this late but to me there look to be a bunch of undocumented
> assumptions. Why do the operations have to share a register for example?
>
> Perhaps an interface where you provide a single operation for write_enable
> and whatever else and hence t here is only one 'reg' would work better?
>
> >
> > Suggested-by: Linus Walleij <linus.walleij@linaro.org>
> > Signed-off-by: Yu-Chun Lin <eleanor.lin@realtek.com>
>
> > diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> > index deb9eebb58de..c76eef20e412 100644
> > --- a/drivers/gpio/gpio-regmap.c
> > +++ b/drivers/gpio/gpio-regmap.c
(...)
> >
> > @@ -185,7 +218,7 @@ static int gpio_regmap_set_direction(struct
> gpio_chip *chip,
> > unsigned int offset, bool output)
> > {
> > struct gpio_regmap *gpio = gpiochip_get_data(chip);
> > - unsigned int base, val, reg, mask;
> > + unsigned int base, val, reg, mask, wren_mask;
> > int invert, ret;
> >
> > if (gpio->reg_dir_out_base) {
> > @@ -198,7 +231,12 @@ static int gpio_regmap_set_direction(struct
> gpio_chip *chip,
> > return -ENOTSUPP;
> > }
> >
> > - ret = gpio->reg_mask_xlate(gpio, base, offset, ®, &mask);
> > + ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_DIR_OP, base,
> offset, ®, &mask);
> > + if (ret)
> > + return ret;
> > +
> > + ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_DIR_WREN_OP,
> base, offset, ®,
> > + &wren_mask);
>
> What constrains these two to provide the same value back for reg?
> To me it seems like the write enable might well be in a different register.
>
> > if (ret)
> > return ret;
> >
> > @@ -207,7 +245,7 @@ static int gpio_regmap_set_direction(struct
> gpio_chip *chip,
> > else
> > val = output ? mask : 0;
> >
> > - return regmap_update_bits(gpio->regmap, reg, mask, val);
> > + return regmap_update_bits(gpio->regmap, reg, mask | wren_mask,
> > + val | wren_mask);
> > }
> >
> > static int gpio_regmap_direction_input(struct gpio_chip *chip,
My initial design indeed assumed that the WREN mask and Data mask reside in
the same register.
Regarding WREN support, especially if WREN and Data use separate registers, I
came up with three ideas. Which direction do you prefer?
Approach 1: Provide Custom Callbacks in config (Let consumer driver handle it)
We can add '.set' and '.set_direction' function pointers in
'struct gpio_regmap_config'. If a driver requires WREN, it can implement these
callbacks itself.
static void gpio_regmap_set(struct gpio_chip *chip, unsigned int offset, int val)
{
struct gpio_regmap *gpio = gpiochip_get_data(chip);
/* If the driver provides a custom set (to handle WREN), delegate to it */
if (gpio->set) {
gpio->set(chip, offset, val);
return;
}
/* ... existing generic regmap logic ... */
}
Pros: Clean core, no need to touch existing drivers' xlate signature. The consumer
driver handles its own locking for different registers.
Cons: It feels a bit strange and inconsistent to expose only '.set' and
'.set_direction' overrides while keeping other operations entirely abstracted.
Approach 2: Handle separate WREN register in the core (with locking concerns)
We keep the 'XX_WREN_OP' in 'xlate'. If someone needs WREN and 'wren_reg != reg',
we write to both.
static int gpio_regmap_set(struct gpio_chip *chip, unsigned int offset,
int val)
{
/* skip */
ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_WREN_OP, base, offset, &wren_reg,
&wren_mask);
if (ret == -ENOTSUPP)
has_wren = false;
else if (ret)
return ret;
ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_OP, base, offset, ®, &mask);
if (has_wren && reg == wren_reg) {
mask |= wren_mask;
mask_val |= wren_mask;
has_wren = false;
}
if (has_wren)
ret = regmap_set_bits(gpio->regmap, wren_reg, wren_mask);
/* ignore input values which shadow the old output value */
if (gpio->reg_dat_base == gpio->reg_set_base)
ret = regmap_write_bits(gpio->regmap, reg, mask, mask_val);
else
ret = regmap_update_bits(gpio->regmap, reg, mask, mask_val);
return ret;
}
Pros: Keeps all WREN logic unified inside the core framework.
Cons: Introduces a locking issue. writing to 'wren_reg' and then 'reg' requires an
external lock to be atomic, which seems to defeat the purpose of relying on regmap's
internal lock.
Approach 3: Assume WREN and Data always share the same register
static int gpio_regmap_set(struct gpio_chip *chip, unsigned int offset, int val)
{
/* ... */
ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_WREN_OP, base, offset, ®, &wren_mask);
if (ret == -ENOTSUPP)
wren_mask = 0;
else if (ret)
return ret;
ret = gpio->reg_mask_xlate(gpio, GPIO_REGMAP_SET_OP, base, offset, ®, &mask);
ret = regmap_update_bits(gpio->regmap, reg, mask | wren_mask, mask_val | wren_mask);
return ret;
}
Regarding this approach, I would like to ask from your experience: Is it
actually common for hardware designs to place WREN and Data bits in completely
different registers for GPIO operations?
If they practically always share the same register, this simpler approach might
suffice.
Best Regards,
Yu Chun Lin
next prev parent reply other threads:[~2026-07-09 17:22 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 3:33 [PATCH v3 0/7] gpio: realtek: Add support for Realtek DHC RTD1625 Yu-Chun Lin
2026-05-12 3:33 ` [PATCH v3 1/7] gpio: Replace "default y" with "default ARCH_REALTEK" in Kconfig Yu-Chun Lin
2026-05-12 3:33 ` [PATCH v3 2/7] gpio: regmap: add gpio_regmap_get_gpiochip() accessor Yu-Chun Lin
2026-05-12 11:20 ` Andy Shevchenko
2026-05-25 12:04 ` Yu-Chun Lin [林祐君]
2026-06-03 0:34 ` Andy Shevchenko
2026-06-08 14:10 ` Bartosz Golaszewski
2026-06-08 14:41 ` Michael Walle
2026-06-17 8:36 ` Yu-Chun Lin [林祐君]
2026-06-17 8:44 ` Michael Walle
2026-06-17 9:54 ` Yu-Chun Lin [林祐君]
2026-06-17 11:19 ` Michael Walle
2026-06-19 21:08 ` Linus Walleij
2026-06-22 10:35 ` Andy Shevchenko
2026-06-30 13:21 ` Linus Walleij
2026-07-01 8:44 ` Michael Walle
2026-07-01 10:01 ` Andy Shevchenko
2026-07-01 10:55 ` Andy Shevchenko
2026-07-01 11:38 ` Andy Shevchenko
2026-07-01 11:42 ` Michael Walle
2026-07-01 12:03 ` Andy Shevchenko
2026-07-01 11:38 ` Michael Walle
2026-07-01 12:08 ` Andy Shevchenko
2026-05-12 3:33 ` [PATCH v3 3/7] gpio: regmap: Add gpio_regmap_operation and write-enable support Yu-Chun Lin
2026-05-12 11:26 ` Andy Shevchenko
2026-05-12 14:37 ` Jonathan Cameron
2026-07-09 17:21 ` Yu-Chun Lin [林祐君] [this message]
2026-05-13 7:40 ` Linus Walleij
2026-05-12 3:33 ` [PATCH v3 4/7] gpio: regmap: Add set_config callback Yu-Chun Lin
2026-05-12 18:12 ` Andy Shevchenko
2026-05-12 3:33 ` [PATCH v3 5/7] dt-bindings: gpio: realtek: Add realtek,rtd1625-gpio Yu-Chun Lin
2026-05-12 3:33 ` [PATCH v3 6/7] gpio: realtek: Add driver for Realtek DHC RTD1625 SoC Yu-Chun Lin
2026-05-12 18:50 ` Andy Shevchenko
2026-05-12 3:33 ` [PATCH v3 7/7] arm64: dts: realtek: Add GPIO support for RTD1625 Yu-Chun Lin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d301ba0cd45d49d59e6a014188306ec9@realtek.com \
--to=eleanor.lin@realtek.com \
--cc=Michael.Hennerich@analog.com \
--cc=afaerber@suse.com \
--cc=andy@kernel.org \
--cc=brgl@kernel.org \
--cc=conor+dt@kernel.org \
--cc=cy.huang@realtek.com \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=james.tai@realtek.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linus.walleij@linaro.org \
--cc=linusw@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-realtek-soc@lists.infradead.org \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=mwalle@kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=stanley_chang@realtek.com \
--cc=tychang@realtek.com \
--cc=wbg@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox