public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
From: "Michael Walle" <mwalle@kernel.org>
To: "Linus Walleij" <linusw@kernel.org>,
	"Yu-Chun Lin [林祐君]" <eleanor.lin@realtek.com>
Cc: "Bartosz Golaszewski" <brgl@kernel.org>,
	"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>,
	"CY_Huang[黃鉦晏]" <cy.huang@realtek.com>,
	"Stanley Chang[昌育德]" <stanley_chang@realtek.com>,
	"James Tai [戴志峰]" <james.tai@realtek.com>,
	"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>,
	"TY_Chang[張子逸]" <tychang@realtek.com>
Subject: Re: [PATCH v2 3/4] gpio: realtek: Add driver for Realtek DHC RTD1625 SoC
Date: Mon, 20 Apr 2026 09:22:13 +0200	[thread overview]
Message-ID: <DHXSUW3NJU22.1RUYUHQZSZ53S@kernel.org> (raw)
In-Reply-To: <CAD++jLkpS-T9yK=ctSwpLvXkj7s7ivmwu1KKwzy4KS40LVYeyA@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 3744 bytes --]

Hi,

On Sun Apr 19, 2026 at 11:19 PM CEST, Linus Walleij wrote:
> Hi Yu-Chun,
>
> On Fri, Apr 10, 2026 at 11:39 AM Yu-Chun Lin [林祐君]
> <eleanor.lin@realtek.com> wrote:
>
>> We did look into gpio-mmio and gpio-regmap, but they are not quite suitable for
>> our platform due to the specific hardware design:
>>
>> 1. Per-GPIO Dedicated Registers: Unlike typical GPIO controllers that pack 32 pins
>> into a single 32-bit register (1 bit per pin), our hardware uses a dedicated 32-bit
>> register for each individual GPIO. This single register controls the
>> input/output state, direction, and interrupt trigger type for that specific pin.
>
> Isn't that attainable by:
>
> - setting .ngpio_per_reg to 1 in struct gpio_regmap_config

Which is just used by the gpio_regmap_simple_xlate() anyway. So it
doesn't really matter. But yeah, 1 would be the correct value here,
assuming that the registers are consecutive.

> - extend .reg_mask_xlate callback with an enum for each operation
>   (need to change all users of the .reg_mask_xlate callback but
>   who cares, they are not many):
>
> e.g.
>
> enum gpio_regmap_operation {
>     GPIO_REGMAP_GET_OP,
>     GPIO_REGMAP_SET_OP,
>     GPIO_REGMAP_SET_WITH_CLEAR_OP,
>     GPIO_REGMAP_GET_DIR_OP,
>     GPIO_REGMAP_SET_DIR_OP,
> };
>
>  int (*reg_mask_xlate)(struct gpio_regmap *gpio,
>                               enum_gpio_regmap_operation op,
>                               unsigned int base,
>                               unsigned int offset, unsigned int *reg,
>                               unsigned int *mask);
>
> This way .reg_mask_xlate() can hit different bits in the returned
> *mask depending on operation and it will be find to pack all of
> the bits into one 32bit register.
>
> Added Michael Walle to the the thread, he will know if this is a
> good idea.

Nice idea, though the information is then redundant in the usual
case, i.e. drivers which need to translate specific registers
will do a "switch (base)" at the moment. These should be converted
to "switch (op)" just to keep all the drivers aligned and prevent
new drivers from using the old method. You'd need to touch them
anyway.

I was briefly thinking about making it somewhat possible to embed
the op into the base, if it would otherwise be all the same. That
way, you could gpio-regmap as is. A special case like
GPIO_REGMAP_ADDR_ZERO, that could be used by these kind of drivers,
but that is probably too hacky.

I'm fine with either way.

>> 2. Write-Enable (WREN) Mask Mechanism: Our hardware requires a specific Write-Enable
>> mask to be written simultaneously when updating the register values.
>
> Which is to just set bit 31.
>
> With the above scheme your .reg_mask_xlate callback can just set bit 31
> no matter what operating you're doing. Piece of cake.

Keep in mind, that this will make reading and writing somewhat
different. reading assumes there is only one bit set in mask,
because of the "!!(val & mask)" op, which is hardcoded. I'm not
against using the write like that though.

-michael

>> 3. Hardware Debounce: We also need to support hardware debounce settings per pin,
>> which requires custom configuration via set_config mapped to these specific per-pin
>> registers.
>
> Just add a version of an optional .set_config() call to gpio-regmap.c
> to handle this using .reg_mask_xlate() per above and add a new
> GPIO_REGMAP_CONFIG_OP to the above enum, problem solved.
>
> If it seems too hard I can write patch 1 & 2 adding this infrastructure
> but I bet you can easily see what can be done with gpio-regmap.c
> here provided Michael W approves the idea.
>
> Yours,
> Linus Walleij


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 297 bytes --]

  reply	other threads:[~2026-04-20  7:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-08  2:52 [PATCH v2 0/4] gpio: realtek: Add support for Realtek DHC RTD1625 Yu-Chun Lin
2026-04-08  2:52 ` [PATCH v2 1/4] gpio: Remove "default y" in Kconfig Yu-Chun Lin
2026-04-08  2:52 ` [PATCH v2 2/4] dt-bindings: gpio: realtek: Add realtek,rtd1625-gpio Yu-Chun Lin
2026-04-09  7:43   ` Krzysztof Kozlowski
2026-04-08  2:52 ` [PATCH v2 3/4] gpio: realtek: Add driver for Realtek DHC RTD1625 SoC Yu-Chun Lin
2026-04-08  7:31   ` Bartosz Golaszewski
2026-04-10  9:39     ` Yu-Chun Lin [林祐君]
2026-04-19 21:19       ` Linus Walleij
2026-04-20  7:22         ` Michael Walle [this message]
2026-04-08  2:52 ` [PATCH v2 4/4] arm64: dts: realtek: Add GPIO support for RTD1625 Yu-Chun Lin
2026-04-08  7:28   ` Bartosz Golaszewski

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=DHXSUW3NJU22.1RUYUHQZSZ53S@kernel.org \
    --to=mwalle@kernel.org \
    --cc=afaerber@suse.com \
    --cc=brgl@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cy.huang@realtek.com \
    --cc=devicetree@vger.kernel.org \
    --cc=eleanor.lin@realtek.com \
    --cc=james.tai@realtek.com \
    --cc=krzk+dt@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-realtek-soc@lists.infradead.org \
    --cc=robh@kernel.org \
    --cc=stanley_chang@realtek.com \
    --cc=tychang@realtek.com \
    /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